Java Firefox Extension

[[glossary definition:=A Firefox 0.9 or 1.x extension that demonstrates how you can use Java inside a Firefox extension. We have used this technique in our Piggy Bank extension. This extension distills the technique to a skeleton so that you can more easily comprehend.]]

This is intended for Firefox 0.9 or 1.x extension developers only.

Get the Code and Build It

You can browse the code online or you can follow these steps to download and build it yourself.

Here is a list of things you need to build Java Firefox Extension:

  • A compatible Java Virtual Machine (version 1.4 or later) to compile and execute the code (you need to have the environment variable JAVA_HOME in your shell set to the 'home' directory of where your java JVM is)
  • Apache Ant to drive the build.
  • A Subversion client to download the source code.

How to build it:

  1. cd where/you/want/it
  2. svn checkout http://simile.mit.edu/repository/java-firefox-extension/ java-firefox-extension
  3. cd java-firefox-extension
  4. ant

This will create a distribution in the ./dist directory that contains everything and a packaged version java-firefox-extension-[version].xpi in the same folder. This XPI package is a zip package that is recognized by firefox as an extension.

For some tips on extension development, refer to the Developers' Guide for Piggy Bank.

Play with The Extension

Once you install the extension in Firefox (and restart Firefox), you can open up Firefox's JavaScript console (from the Tools menu) and see the extension's messages:

   FooComponent.initialize {
   
   FooComponent._bootstrapClassLoader {
   
   } FooComponent._bootstrapClassLoader
   
   FooComponent._loadJava {
   
   } FooComponent._loadJava
   
   Greetings: Hello World!
   
   } FooComponent.initialize

This tells you that the extension has been successful at loading its own Java code. Then you can try to invoke Firefox's menu Tools → Java Firefox Extension: Do It!. You should get a dialog box displaying 43. Subsequent invocations increment that number.

Explore the Code

These are some steps enough for you to start exploring the code:

  • Look for the file java-firefox-extension/firefox/chrome/content/browser-overlay.xul
  • This file calls the JavaFirefoxExtension.initialize() function in java-firefox-extension/firefox/chrome/content/scripts/browser-overlay.js
  • This function connects with the XPCOM component called "@simile.mit.edu/java-firefox-extension;1"
  • This component is implemented by java-firefox-extension/firefox/components/FooComponent.js
  • This component loads the Java code.

Licensing & Legal Issues

Java Firefox Extension is open source software and is licensed under the BSD license.

Credits

This software is maintained by the SIMILE project and in particular: