A taste of Firefox Extensions, written in GWT
permalinkUPDATE: It’s live! The open-source project is up on Google Code and I’ve blogged a more about it.
I’m getting closer to having the GWT bindings that we wrote for Firefox ready for public release. What we’ve got is more than enough to write a complex extension. The bindings were even enough to write a prototype of an OOPHM server, itself written in GWT!
For now, just a taste of what extension development is like GWT, complete with strong typing, syntax checks, auto-completion and hosted mode support:
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();
};
The bindings are all generated from the xulrunner SDK’s IDL files and include documentation, parameter names and constants:
/**
* @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);
}-*/;
Read full post