FUELing the Firefox


If you’re ever spent time trying to grok Firefox Extension development (especially if you’re coming from a pure web development background). You’ll find that there’s a lot that you have to learn to get up to speed. To name a few: XPCOM, RDF, XUL, and XBL in addition to a huge number of custom APIs for the different aspects of Firefox (Bookmarks, File I/O, Adding Buttons, Menus).

My first major project at Mozilla is to work with Mark Finkle and develop a JavaScript Library for use by Extension developers. If you’re very new to extension development, then this will help you out, completely. We extrapolate out all the complex concepts into one, simple, package. The best part is that this whole thing is going to be available in the whole Mozilla platform (Firefox, Thunderbird, Seamonkey, XULRunner); and in multiple versions (for example FF 1.5-3.0).

We use very little of the actual underlying terminology and naming conventions present in the existing code base (this is bound to irk most established developers), and instead have adopted much of the terminology already present in JavaScript/DOM development. You can see evidence of this in our early API planning for versions 0.1 (Plan) and 0.2 (Plan).

In a nutshell, for 0.1, here’s what we’re tackling: Preferences, Events, Observers, Extensions, Toolbars, and Buttons; and the kind of improvement that you can expect:

Accessing a Boolean Preference

  1. // 'Old' XPCOM way
  2. var prefValue = false;
  3. try {
  4.    prefValue = gPrefService.getBoolPref(this.domain);
  5. } catch (e) {
  6. }
  7.  
  8. // 'New' FUEL way
  9. var prefValue = Preferences.get(this.domain, false);

Watching for a change in a preference (obvserver).

  1. // "Old" XPCOM way
  2. gPrefService
  3.     .QueryInterface(Components.interfaces.nsIPrefBranch2)
  4.     .addObserver(this.promptDomain, this, false);
  5.  
  6. // "New" FUEL way
  7. Preferences.addEvent( this.promptDomain, this );

Setting a unicode preference.

  1. // "Old" XPCOM way
  2. try {
  3.     var str = Components.classes["@mozilla.org/supports-string;1"]
  4.         .createInstance(Components.interfaces.nsISupportsString);
  5.     str.data = aURL;
  6.  
  7.     gPrefService.setComplexValue("browser.startup.homepage",
  8.         Components.interfaces.nsISupportsString, str);
  9. } catch (ex) {
  10.     dump("Failed to set the home page.\n"+ex+"\n");
  11. }
  12.  
  13. // "New" FUEL way
  14. Preferences.set("browser.startup.homepage", aURL);

We’re really excited about where this is going, and we’d love some feedback. Feel free to comment on the wiki, find us on irc, or drop us an email. Here’s Mark’s take on the project. I’m really excited to be working with him and the whole developer relations team.

Posted: January 9th, 2007


If you particularly enjoy my work, I appreciate donations given with Gittip.

7 Comments (Show Comments)



Comments are closed.
Comments are automatically turned off two weeks after the original post. If you have a question concerning the content of this post, please feel free to contact me.


Secrets of the JavaScript Ninja

Secrets of the JS Ninja

Secret techniques of top JavaScript programmers. Published by Manning.

Ukiyo-e Database and Search

Ukiyo-e.org

Japanese woodblock print database and search engine.


John Resig Twitter Updates

@jeresig

Infrequent, short, updates and links.