My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

gwt-firefox-extension

gwt-firefox-extension is a set of bindings, generated from the IDL that ships with Firefox, that allow you to easily create extensions for Firefox and other xulrunner-based products.

Current Status

We use code that this library is derived from at DotSpots to generate our Firefox extension. We hope to improve documentation and the build process over time to make it more usable for developers.

As Mozilla Jetpack matures and begins shipping with Firefox, we hope to migrate our API to match.

Completed:

  • Basic tab API

Coming soon:

  • Extension toolbar icon support
  • Popup and other menu integration

Getting Started

From an existing GWT project, run the following shell script:

extensionCreator my-extension@example.com

Inherit from the FirefoxExtension module from your existing entry point's module:

<inherits name='com.dotspots.FirefoxExtension' />

Change your existing entry point so it inherits from ExtensionEntryPoint and implement onExtensionStart:

public class ExampleExtension extends ExtensionEntryPoint {
	public ExampleExtension() {
	}

	@Override
	public void onExtensionStart() {
	}
}

Add a system property "xpi.dir" to your developer mode launch targets and under the "Advanced" section of the GWT Compile action:

-Dxpi.dir=xpi

Examples

The tab API allows you to detect when a tab is open, closed or navigated. This API is initialized at startup time and available from the getTabs() method of an ExtensionEntryPoint:

		getTabs().addCreatedListener(new TabCreatedHandler() {
			@Override
			public void onTabCreated(Tab tab) {
				log("Received tab created event: " + getBrowserLocation(tab));
			}
		});

The bindings generated by the framework are strongly typed and include the original documentation from the IDL:

  /**
     * @param file          - file to write to (must QI to nsILocalFile)
     * @param ioFlags       - file open flags listed in prio.h
     * @param perm          - file mode bits listed in prio.h
     * @param behaviorFlags flags specifying various behaviors of the class
     *        (currently none supported)
     */
  public final native void init(nsIFile file, int ioFlags, int perm, int behaviorFlags) /*-{
    return this.init(file, ioFlags, perm, behaviorFlags);
  }-*/;

Here's an example of using nsIFile to create a logfile in a temporary directory:

protected nsIFile createTempFile() {
    nsIFile file = nsIProperties.getService("@mozilla.org/file/directory_service;1")
        .get("TmpD", nsIFile.iid());
    file.append("logs");
    if (!file.exists()) {
        file.create(nsIFile.DIRECTORY_TYPE, 0777);
    }

    file.append("log.txt");
    file.createUnique(nsIFile.NORMAL_FILE_TYPE, 0666);

    return file;
};

protected void write(String value, nsIFile file) {
    nsIFileOutputStream foStream = nsIFileOutputStream.createInstance("@mozilla.org/network/file-output-stream;1");
    foStream.init(file, 0x02 | 0x08 | 0x10, 0666, 0);
    foStream.write(value, value.length());
    foStream.close();
};
Powered by Google Project Hosting