From MozillaZine Knowledge Base
(Difference between revisions)
Revision as of 11:20, 19 August 2005
Extensions allow programmers to add new features to Mozilla applications or allow existing features to be modified. Typically, extensions modify the “chrome” of their target application—the user interface and the scripts that add functionalty to that interface. However, it is also possible for extensions to include compiled code in the form of XPCOM components.
You will almost certainly need to use the following technologies, although it is not necessary to be an expert in them. You may be able to pick up much of what you need just by examining the source code for other extensions.
- XUL (XML User-Interface Language). Used to define the onscreen layout of the UI and to attach scripts and style to the interface.
- DOM (Document Object Model). Used to manipulate XUL in real-time as well as any HTML documents loaded.
- CSS (Cascading Style Sheets). Used to style the interface and to attach XBL bindings to XUL documents.
More advanced extensions may require the following technologies.
Setting up your environment
- Please see Setting up extension development environment for development preferences you can set and extensions you can install. It also contains information about running a separate instance of Firefox using a development profile.
- Getting started with extension development contains tips on easily setting up extensions development environment in Firefox/Thunderbird 1.1a1+ (so that you no longer have to recreate the JAR and/or XPI files each time you make a change in your extension). It is also a quickstart guide containing useful links for beginners and the obligatory helloworld extension, which can be used as a basis of your extensions.
There is a variety of tutorials available which will help with general extension development or with learning specific technologies. You don't have to read all of them before starting hacking.
As well as web resources, there are a couple of books available describing Mozilla technologies and their usage. Both books cover a comprehensive range of Mozilla technologies. They are available both online and in a more user-friendly dead-tree format.
with .jar file
Mozilla.org provides the most comprehensive technical document on packaging extensions. It explains the format of the install.rdf file for those wishing to create one from scratch. However, there also are tools and templates for easier creation of the install.rdf file.
The Extension Manager—and hence the extension/theme packaging system—underwent a major revision with Firefox 0.9 and Thunderbird 0.7. If you wish to support earlier versions of these products, or the Mozilla Suite, you will need to provide the old-style install.js file as well as the new install.rdf.
The whole process for the new packaging system is made clear in both roachfiend’s tutorial and Jonah Bishop's toolbar tutorial. The tutorial on XulPlanet covers the old system (most of this tutorial also applies to new-style extensions too). Jed Brown also has a tutorial on repackaging old extensions in the new style.
There are also tools which will automatically package your extension files: a bash build script, Windows build script, Googlebar Lite Perl build script, a makefile.
without .jar file
While developing your Extension it can make sense not to .jar files but to use them directly instead. That way you can debug in the extensions directory of a usersprofile directly without re-packing and re-jaring. Creating a package without a .jar file is the same like described above with only some changes:
- Use a directory instead of a JAR:
Instead of packing your files into a file called chrome/myextension.jar you copy them into a directory called chrome/myextension
- Change the install.rdf:
Change it from:
- Change the install.js:
For Mozilla Suite there might be additional modifications in the install.js file necessary which reflect the install.rdf file changes which is replaced by the .js file. It is unknown if this applies to Firefox or Thunderbird, too.
More: Getting rid of JARs (Tip & Example). Please note, that it's recommended to package chrome files in a JAR, for better startup performance.
Releasing your extension
Once you have thoroughly tested your extension, you can release it to the rest of the world!
Making it better
Use DTDs for XUL and properties for scripts.
Themes apply CSS using ID and class attributes. Include these as much as possible to make theme development possible.
Try to follow the set of Extension guidelines. This can help to make all extensions act predictably, which increases usability.
- Example Code. Common development tasks and techniques.
- Example Extensions. Extensions that provide a clear demonstration of a particular technique or function.
- Chrome URLs. Discover the location within the installation folder of the chrome you wish to overlay.
- MozillaZine provides a Development forum which is the place for technical questions and an Extensions forum which occasionally has technical discussion but is more useful for releasing extensions to get testing and feedback.
- The netscape.public.mozilla newsgroups are the official location for code-related queries. They are particularly useful if you're implementing an XPCOM component or have a question that MozillaZine posters can't answer. See the developer forums page for a description of each newsgroup.
- IRC (see also this). Live Developers! Get satisfaction online from red hot developers! (Note: this is not a dating service.)
- Take a look at Dev : Project ideas to see the list of requested extensions.
- Help maintaining the Extension development Knowledge Base. Post your tips and code snippets for others to use. You may use the MozillaZine forums (preferably Development or Extensions) to discuss the tips.
- Contribute to existing extensions.