Java Applets in XUL

Java applets from a extension directly embedded in a XUL document (via a HTML-Namespace) seem to be a difficult thing to achieve. They are not only close to impossible to reference (Java plugin obviously doesn’t know chrome://-URIs) but also seem to be restricted to 300x300px. Not good. As our project depends strongly on data exchange between an applet and XUL code I searched the dark alleys of old forum entries and found a different approach yesterday and implemented it:

  • The applet is embedded not in XUL but in a HTML page that is contained in an iframe
  • The applet may access the embedding HTML by mayscript parameter
  • In HTML a script generates a custom DOMElement, puts the data to hand over to the extension JSONified in an attribute x and finally fires a custom Event A, which is bubbling up through all parent nodes, …
  • … until the listening extension captures this custom Event A. Data is read from the attribute x, handled and return values are written in another attribute y of said DOMElement. Then the extension itself fires another custom Event B from the Element.
  • The script in the HTML listens to Event B, and — when fired — reads the returned value from attribute y and passes it to the applet.

Easy, isn’t it?

So much hoops to jump through to solve such a seemingly simple task! And that only because the Java / Firefox bridges are mostly ropeways…

Communication between HTML and extension works so far, source code will be posted tomorrow. When I finished tackling the applet-to-HTML-thingy I will update, promised.

3 Responses to “Java Applets in XUL”

  1. […] promised yesterday I post the source code for communicating between an unprivileged HTML-page and an privileged […]

  2. Hi,

    I am experiencing the same issue in one my project, do you have an example that you can share? I appreciate it Thx

  3. Actually, as it turned out when Firefox 3.6 came out, this doesn’t work anymore… I get some weird errors (applet panel is not displayed but runs, etc.). Right now I am trying to get it working again – when (if?) I succeed I will post some update…

Discussion Area - Leave a Comment