Extensions for Fennec

As I mentioned in the Fennec M7 release notes, the Add-ons Manager has been hooked up. Therefore, I decided to post some example add-ons for Fennec. Fennec is a XULRunner application and gives extension developers access to the same underlying XPCOM system that is used in Firefox. The process of building extensions is the same as for any other Mozilla based application.

However, there are some things a potential extension developer should know. Fennec is not Firefox. It is a completely different application. Fennec’s UI is also very different than Firefox. This means that you can’t just plop a Firefox (or Thunderbird or Songbird) extension into Fennec and expect anything to work. There are some basic things an extension developer will need to handle when making or porting extensions to Fennec:

  • Fennec uses a different application id: {a23983c0-fd0e-11dc-95ff-0800200c9a66}
  • Fennec has very different XUL UI. Many XUL elements found in Firefox do not exist in Fennec. Update your overlay XUL file accordingly.
  • Fennec uses different JavaScript objects and functions in it’s UI code. Functions and objects you have used in Firefox may not exist or may even represent different things in Fennec. For example, there is a Browser object that encapsulates some of the basic browser features, but there is a BrowerUI object that is the controller for the actual chrome. Also, there is no gBrowser object (yet) and the getBrowser() method does not return a as it does in Firefox.

The best way to figure out what’s available is to look at the source code. Also, jump on Mozilla IRC and ask questions in the #mobile channel. Ok, enough of that, let’s look at the sample extensions.

  • fennec-sample: A simple barebones add-on that shows the minimum needed to get an extension running in Fennec. Adds a button to the toolbar and displays an alert when clicked.
  • fennec-readit: A basic add-on that use flite on Maemo to turn text into speech. Toggle the text-to-speech (TTS) mode on and off using the toolbar button. When TTS is on, clicking (touching) text content will cause the text to be read aloud using flite.

Use Fennec M7 and click on the above links to install the extensions.

NOTE: In order to use fennec-readit, you must install flite first. I found a simple binary install for Maemo that seems to work OK. The binary of flite can be found in the Maemo Extras repository. After installing, you can test flite by opening a terminal and typing: flite -t "Hello World"

It might be cool to create an XPCOM version of flite (or use js-ctypes on a shared library version).

Extension Developers – Don’t Fear Firefox 3.1

Firefox 3 had some big changes (and little changes) that caused some grief for extension developers wanting to update add-ons to the newest version. There were some deep architectural changes (Places bookmarking API), numerous security changes (same-origin on file:// and restricting chrome:// from content), and large UI/Theme changes (URLbar, XP/Vista/Linux/Mac themes). Needless to say, getting lots of new greatness in Firefox 3 (XULRunner 1.9) came at a high maintenance/refactor cost to extension developers.

The good news is you made it! Overall, I think Mozilla did a good job keeping developers updated on changes and, along with a great developer community, provided lots of help to developers who were having trouble updating extensions.

So, you might have heard that Firefox 3.1 is coming out soon, probably before the end of the year. Firefox 3.1 alphas could start showing up in less than 2 months. If you have been reading some other posts on Planet Mozilla or watching some of the checkins landing in the source tree, you might be aware that Firefox 3.1 will add some serious, ass-kicking features. Many of these features are web-content facing and are based on web specifications.

Will all of these serious, ass-kicking features mean that updating extensions will be a major pain-in-the-ass, again?! No! There appear to be no plans to make extensions developer lives miserable. The new features (did I mention they kick-ass?) are not being added in a disruptive manner. Most of them layer onto existing features and technologies.

Just to be clear: Firefox 3.1 will not require a major update for add-ons. In fact, I’d go out on a limb and say updating to Firefox 3.1 will be easy. We’ll make sure the are no surprises along the way.

Extensions & XMLHttpRequest & eval – Oh My

Using eval() to decode JavaScript you downloaded from a remote website in your extension is just plain wrong. It’s not safe! Don’t do it!

Every now and then, an AMO reviewer will send me an email asking me to help an extension developer workaround the situation. Why? Because AMO will not allow add-ons that eva() JavaScript downloaded from a remote website to be moved out of the AMO sandbox. It’s not safe! Using eval() in an extension can give rogue JavaScript chrome privileges – the ability to do pretty much whatever it wants to the computer.

I finally made an MDC article with more details. The short version is:

  • If you’re downloading JSON, use a real JSON decoder, not eval().
  • If you’re downloading real JavaScript, use a JavaScript sandbox, not eval().

Mozilla Platform, Wizards and FizzyPop

Building things with the Mozilla Platform usually involves dealing with some boilerplate. Extensions have install and chrome manifests and overlays. XULRunner applications have application and chrome manifests and default preferences. XPCOM, even the simpler JavaScript XPCOM, has modules, factories and categories. It’s more than enough to slow developers down, especially new-to-Mozilla developers.

That’s why I have always been thankful to Ted Mielczarek for his Extension Wizard and JS XPCOM Wizard. Those tools have been helpful to me and countless other Mozilla developers.

Because of their great utility, I started to think that Mozilla should host, develop and extend the tools. Turns out, this pleases Ted 🙂 – Therefore, I’ve put together a plan for FizzyPop, a simple project to develop/extend tools that assist Mozilla developers.

I had done a similar project with XUL Explorer, template-driven wizards to create extensions and xul applications. Turns out the Web has a wider reach than a desktop tool, especially for these types of scaffolding projects. In any case, I am taking the templates I use in XUL Explorer and converting them for use in a PHP web application.

I plan to get an SVN repo, bugzilla support and a Mozilla hosted for the project. We want to turn this into a contributor-base project. I’ll let you know when the prototype is ready to start hacking.

Here We Go!

Mozilla just opened the new source repository (mozilla-central) meaning the next release features will start landing. David Baron posted about landing new CSS selectors. Robert O’Callahan posted about some kick-ass SVG-based CSS effects used to style HTML. This totally rocks and will help push SVG into more of a leading role on the Web.

Look for more cool features, big and small, to start landing with increasing frequency. Some will help chrome developers while others are focused on web developers.

Remote Debugging JavaScript

Shaver and I have been talking about getting a decent mechanism for remote debugging a JavaScript session. I have been looking at JSSH. It’s a bit dated, but a great little Firefox/Mozilla extension that adds a huge amount of external flexibility, control and extensibility. The Watir-based web testing system for Firefox (called FireWatir) uses JSSH to control the current Firefox browsing session. The big downside to JSSH is that it has binary components, so you need to build it across platforms and Gecko versions. Yuck!

I have been working on a pure JavaScript version in my spare time, but I can throw that away now that ActiveState’s Shane Caraveo has released an early alpha (called SD Connect) of the same concept. Actually, Shane has a bit more than I had planned, but that doesn’t bother me. Comment’s on Shane’s post pointed me to the MozRepl project as well. I had heard of MozRepl a while ago and I’m kicking myself for forgetting about it.

My goals for remote debugging are a bit different than Shane’s, but there is plenty of overlap. I want to use remote JavaScript debugging to aid in Mozilla’s mobile browser development. I also want to use remote debugging for extension and XUL application development. I realize I may be the anomaly, but a Firebug-like component is _not_ my ideal debugger for chrome (application) JavaScript. For web content JavaScript, sure, but I have Heisenberg uncertainty issues with using a debugger that is itself in the system I am debugging. Therefore, I am very eager to start playing around with SD Connect and MozRepl.

Also, Yay for OpenKomodo spin-offs!

Extension Developers – about:addons Newsletter

Mozilla is starting a new newsletter, about:addons, strictly for add-on related development and hosting. A lot of changes were made to the way extensions are built and hosted during the last Firefox / Mozilla release cycle. Many changes and new features have been happening on AMO as well. It can be hard to keep track of the add-on related changes with all the other types of information coming out of Mozilla, on MDC or blogged on Planet Mozilla. With that in mind, it was decided that a dedicated newsletter could be the best way to get add-on information to add-on developers.

Deb Richardson started the about:mozilla newsletter about seven months ago and it has been a great way for community members to keep informed about news in the Mozilla ecosystem. We’d like to create the same kind of success with about:addons.

Dave Townsend covered some of the details in his post. Use the sign up page to subscribe. The newsletter is primarily an email-based service, but we will post it on DevNews weblog too.

We hope to get the first newsletter out sometime next week. We’ll post more information about submitting news as we get things nailed down. For now, feel free to leave comments about what you want to see.

Update: It seems MailChimp, the service we’re using, is down for maintenance. I was hoping the subscription functionality would not go down during the upgrade maintenance window, but it did. Everything should be back online Monday morning (5/19 9am EST). Sorry for the inconvenience.

FUEL and Google SoC

Samer Ziadeh will be working on a Summer of Code project to enhance FUEL. He is looking at some feature requests found in bugzilla, bug 406974 and bug 409279 specifically. Samer has already done some work with FUEL. The past semester, he ported much of the code to work in Firefox 2. It wasn’t a perfect fit as Firefox 2 is missing some integral new functionality supported in Firefox 3. Without it, backporting to Firefox 2 became difficult.

Samer will be hanging out on IRC in #extdev, so be sure to give him some encouragement (and a feature request or two).

Extension Developers – Your Final MaxVersion Update

Extension Developers! Yeah, You!

AMO has flipped the switch to support MaxVersion “3.0.*” so make those final version updates now. Firefox 3 RC1 is releasing very, very soon. Yes, “3.0.*” is the final MaxVersion you’ll need for Firefox 3, so don’t delay.

Copied for your reading pleasure:

What this means for you as an add-on author is that after you test with the Firefox 3 release candidates, you can use the Developer Tools section on AMO to bump your version number without having to upload a new version of your add-on.

For completeness, if you want to support Firefox (and none of the alpha’s, betas and pre-releases), here are the recommended version ranges (minVersion – maxVersion) to use:

  • Firefox 2: 2.0 – 2.0.0.*
  • Firefox 3: 3.0 – 3.0.* (Note: that with Firefox 3, it’s a three part version number)

Yay! for the end of update madness! Now go and do it!

A Little XPCOM Magic – JavaScript Callbacks

XPCOM is, currently, a core Mozilla technology. Developers use XPCOM for a variety of reasons, many of which result in XPCOM components being accessed from JavaScript. XPCOM uses IDL to describe interfaces. This can make XPCOM components a bit rigid and not feel right in JavaScript. Recent support for optional parameters in IDL has helped a little. Another helpful concept is using JavaScript functions in place of an IDL callback interface. For example:


[scriptable, uuid(...)]
interface StringParserObserver {
  void onWord(string word);
};

[scriptable, uuid(...)]
interface StringParser {
  void parse(string data);
  void addObserver(StringParserObserver observer);
};

In order to use this interface from JavaScript, you would have to implement the StringParserObserver using JavaScript. A nicer approach would be to allow someone to pass in a JavaScript function to use as the callback. The good news is you can! Better news is that it is a one line change to your IDL!

Just add the “function” attribute to the interface and XPCOM will handle the rest.


[scriptable,function, uuid(...)]
interface StringParserObserver {
  void onWord(string word);
};

There is a new MDC article with more details here.