Extending Firefox and Thunderbird
Written by Mike James   
Saturday, 20 June 2009
Article Index
Extending Firefox and Thunderbird
Getting started
Hello Toolbar
Trying it out



Mozilla Firefox and Thunderbird are an open source browser and email client respectively. They offer an alternative to Internet Explorer and Outlook Express and, given that Microsoft has stated that no new versions of Outlook Express will be produced in the future, they are a combination that looks particularly attractive. They are both free to download and use and they automatically migrate any existing Internet Explorer and Outlook Express settings and data.

From a programmer's point of view they have even more to offer. A standard layout engine "Gecko" is used in both applications and this allows you to customise and extend them. Firefox uses a subset of "Gecko" called Chrome. Once you understand the way that it works, it also provides a framework for building your own web or desktop applications - and it's all based on XML and JavaScript. Best of all is that it is all "platform" independent and will work in the same way with Windows. Linux or Mac.
This project creates a simple extension for Firefox but the same techniques work with Thunderbird and other Gecko-based applications.

The great idea

There are two major components to a Firefox extension: XUL, pronounced "zool", which defines the user interface and XPCOM, a JavaScript API that provides access to the internal components. Most accounts of how to get started building extensions focus almost exclusively on the XUL part of the team, perhaps because this is the more impressive. However, to get anything done you need to know about XPCOM and the library of components it provides access to. So here we will examine how both work. If you know how ASP .NET or WPF work it might help to compare XUL with HTML or XAML and XPCOM with the .NET Framework classes.
XUL is an XML based markup language that extends HTML, or more accurately XHTML. This has a huge and initially unexpected advantage in that it blurs the distinction between the data that the application is displaying and the application's user interface. For example, in Firefox you can access the HTML page being displayed from script via the DOM - Document Object Model. What comes as something of a surprise is that you can also access the entire user interface - status bar, toolbar, menus etc - in exactly the same way. This means that knowing how to use the DOM gives you access not only to the web page on display but the user interface of the entire application.
This seems even more surprising, but is no less true, for an apparently non-browser application like Thunderbird. In this case the DOM includes all the emails on display, they are simply HTML documents, and the entire user interface. Again, once you learn how to use the DOM in Firefox the same concepts and skills generalise to Thunderbird.

Last Updated ( Saturday, 27 June 2009 )