Load a Java Applet JAR in XUL

Talk about add-ons and extension development.
Post Reply
firecalc
Posts: 42
Joined: December 19th, 2008, 8:43 am

Load a Java Applet JAR in XUL

Post by firecalc »

Hi,

Really hope someone can help me with this. Have been trawling the web and breaking my head over this. I basically want to load an Applet inside an XUL file. The Applet has been packaged into a JAR and signed. I tried using IFRAME with the applet in an HTML file. Tried APPLET, EMBED and OBJECT tags. Even tried getting the absolute path and dynamically building/setting the Applet properties. I have Java 6 installed. No go! Its the same error everytime ](*,) ...

Code: Select all

java.net.MalformedURLException: unknown protocol: chrome
   at java.net.URL.<init>(Unknown Source)
   at java.net.URL.<init>(Unknown Source)
   at java.net.URL.<init>(Unknown Source)
   at sun.plugin.AppletViewer.getDocumentBase(Unknown Source)
   at sun.plugin.AppletViewer.getCodeBase(Unknown Source)
   at sun.plugin.AppletViewer.createClassLoader(Unknown Source)
   at sun.plugin.AppletViewer.appletInit(Unknown Source)
   at sun.plugin.viewer.LifeCycleManager.initAppletPanel(Unknown Source)
   at sun.plugin.viewer.WNetscapePluginObject$Initer.run(Unknown Source)


Any help would be very much appreciated.
firecalc
Posts: 42
Joined: December 19th, 2008, 8:43 am

Re: Load a Java Applet JAR in XUL

Post by firecalc »

Actually is it possible in Firefox to make an Applet dynamically use the file:/// protocol instead of chrome://? Have been at it for days and looks more and more like its impossible.
User avatar
shootshootshoot
Posts: 2
Joined: December 20th, 2008, 10:12 am
Contact:

Re: Load a Java Applet JAR in XUL

Post by shootshootshoot »

hi
as far as i can see,XUL means Xml User Interface Language,it's just interface.So i don't think it's possible ?
firecalc
Posts: 42
Joined: December 19th, 2008, 8:43 am

Re: Load a Java Applet JAR in XUL

Post by firecalc »

How does Mozilla parse the <APPLET> tag and the corresponding attribute "codebase"? There should be some way to make the engine into using the "file" protocol instead of "chrome" just in this case. Is there a mapping which can be set somewhere which can map a particular chrome url to a relative path?
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Load a Java Applet JAR in XUL

Post by max1million »

From the errors it looks like java (<APPLET> tag) can't find the file using a chrome url.

Should be able to open a file: url from a local page (file:, chrome:) A web based page won't. Try use relative url for the applet (just file name) in the html, and put applet and html in a top level folder of .xpi. Then you can load the file: url of the html into the .contentDocument.location.href of the iframe.

Code: Select all

 // your extension's guid (change this)
   var guid = "sample@max.max";
 // name of folder to get (change this)
   var folderName = "sample";
// name of file to get (change this)
   var fileName = "sample.htm";

   var file = Components.classes["@mozilla.org/extensions/manager;1"]
                   .getService(Components.interfaces.nsIExtensionManager)
                   .getInstallLocation(guid)
                   .getItemLocation(guid);
   file.append( folderName);
   file.append(fileName);
   var url = makeFileURI(file).spec;

// load in current page
   content.document.location.href = url;
//  load in iframe page (your iframe)
//   iframe.contentDocument.location.href = url;
 
Last edited by max1million on December 30th, 2008, 11:39 pm, edited 1 time in total.
firecalc
Posts: 42
Joined: December 19th, 2008, 8:43 am

Re: Load a Java Applet JAR in XUL

Post by firecalc »

Brilliant! It worked! Thanks max1million. I had tried everything except dynamically loading the iframe src. I now use JSObject and chained calls to the parent javascript function. Heres my code now:

Code: Select all

var guid = "fc@fc.com";
var folderName = "chrome";
var fileName = "PP.html";
var appletFile = Components.classes["@mozilla.org/extensions/manager;1"]
      .getService(Components.interfaces.nsIExtensionManager)
      .getInstallLocation(guid)
      .getItemLocation(guid);
appletFile.append(folderName);
appletFile.append(fileName);
var fileUri = "file://"+appletFile.path;
document.getElementById("PPAppletFrame").src = fileUri;
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Load a Java Applet JAR in XUL

Post by max1million »

The file.path in Windows uses a \ for the path separator instead of / which isn't quite correct for a file:// url, although it loads.
Post Reply