O'Reilly logo

Firefox Hacks by Nigel McFarlane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #87. Make a Bottom-Up Overlay

Bottom-up (RDF-driven) overlays allow existing Firefox GUIs to be enhanced.

In the context of Mozilla, an overlay is a hunk of user-interface (UI) data, most commonly XUL, that is extracted to separate files and pulled in at runtime to parts of the UI that include it. Think of it as a reusable widget or set of widgets.

In general, there are two types of overlays. One is a directly specified overlay that you put in your extension. These are used to keep your code modular or to reuse in multiple places in the extension. The second type is something that you want to appear in the Firefox default application, perhaps to carry out a particular function of your extension. For example, you might want to add a menu item to the Tools menu to launch your extension. In a sense, in that case, you are adding to the default UI for Firefox.

This hack focuses on the latter approach, with instructions on which type of overlays you can have, how to make them, and some general insight into how Firefox handles the overlays.

Adding an Item

For the overlay puzzle to fall into place, you need three parts of the puzzle:

  • Entries in contents.rdf to register the overlay

  • The name of file that is the target of the overlay

  • The code that will be pulled in from the overlay to its destination

The best way to understand each piece is by walking through an example. Here, we are going to add a menu item to the Firefox Tools menu to launch the chromeEdit application.

Register the overlay

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required