Question

I have a swing application which I'm re-working into a WebStart [launchable] configuration. My JNLP is nearly there, but what I'm puzzling over is the next step: that of linking into Chrome context menus.

The application is a JSON viewer/manipulator which at the moment takes a URL to a JSON file, pulls it into a JFrame and parses the JSON tree, allowing you to navigate it. As mentioned you currently have to provide the URL to retrieve and format.

What I'd really love to be able to do is navigate to the json file in, say, Chrome and right-click "view in JSON Viewer". For the example Proof Of Concept, [getting the jnlp file to load] I'm using the Oracle 'notepad' jnlp that they provide as an example.

I've created my basic manifest.json file and javascript entry and then tried to crib some of the "deployJava.js" file

Manifest file:

{
  "name": "JSON Viewer",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Launch JSON viewer.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": [ "contextMenus" ],
  "background": {
    "scripts": ["jsonview.js"]
  }
}

Javascript file:

var title = "Edit JSON";
var id = chrome.contextMenus.create({"title": title, "contexts": ["page"],
    "onclick": loadJsonViewer });
console.log("'" + context + "' item:" + id);

function loadJsonViewer(info, tab) {
  //info is OnLoadData
  alert(info.pageUrl);
  var url = "http://java.sun.com/javase/technologies/desktop/javawebstart/apps/notepad.jnlp";
  launchWebStartApplication(url);
}

// launch the specified JNLP application using the passed in jnlp file
// the jnlp file does not need to have a codebase
// this requires JRE 7 or above to work
// if machine has no JRE 7 or above, we will try to auto-install and then launch
/ (function will return false if JRE auto-install failed)
function launchWebStartApplication (jnlp) {
  var jnlpDocbase = null;

  // use document.documentURI for docbase
  if (document.documentURI) {
    jnlpDocbase = document.documentURI;
  }

  // fallback to document.URL if documentURI not available
  if (jnlpDocbase == null) {
    jnlpDocbase = document.URL;
  }

  document.location = jnlp;
  return true;
}

So far I've been very unsuccessful in my attempts :(

My thought pattern was that I'd try to pull out the actual lines that launch the JNLP given that I'm not embedding or creating any 'embedded' launch buttons (as is normally the way) but I'mstill a fair way off.

My main question as I plough down this route is: Could this even work? And if so, what's the best way to 'bypass' the embedd tags as seemingly it needs then in order to call out and create an applet.

Was it helpful?

Solution

The URL you are trying to access seems to have been removed.
According to this tutorial page, the new URL for the JNLP version of Oracle's demo 'Notepad' application is http://docs.oracle.com/javase/tutorialJWS/deployment/webstart/examples/Notepad.jnlp.

Additonaly, you are trying to change the location of the auto-generated background-page, which is doomed to fail (as it is not possible).

Try this instead:

var title = "Edit JSON";
var url = 'http://docs.oracle.com/javase/tutorialJWS/deployment/webstart/examples/Notepad.jnlp';
var id = chrome.contextMenus.create({
    title: title,
    contexts: ["page"],
    onclick: function(info, tab) {
        window.open(url);
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top