Hack 90. Identify Reusable Toolkits
Don't code everything from scratch: reuse bits and pieces of Firefox.
8.8.1. Poking Around Inside toolkit.jar
In the install area, inside the chrome directory, lies the toolkit.jar archive. This is the starting point for all XUL pages and therefore for all extensions and chrome applications. It consists of a number of pieces.
This toolkit.jar file changed a small amount when it was updated from the Mozilla Application Suite (1.x) to Firefox. Because that change involved renaming and was advertised in a number of influential places, some people assumed that there would be significant compatibility issues. This is not the case. The most important files in toolkit.jar have changed very little, so there is substantial and extensive compatibility with other Mozilla-based products. There is 100 percent compatibility with Thunderbird and Nvu, at least. Furthermore, the toolkit.jar file is just a file, and it is easy for extensions to specialize or override portions of it with their own tailored files. There is therefore no reason to consider this file an immovable requirement. It is just a well-tested and convenient starting point.
188.8.131.52 The global package
The global package has special status in the chrome. It provides default functionality that XUL pages can pick up, regardless of which theme or locale is the current one. Each new theme that is created must implement a skin for the special global package.
184.108.40.206 The xul.css master XBL stylesheet
A special part of toolkit.jar is the xul.css file. This is the place to look for any and all details about the definition and behavior of XUL tags. This stylesheet is applied to every XUL document that Firefox displays. It uses the -moz-binding style property [Hack #69] to define every XUL tag (and therefore the whole XUL vocabulary).
This file is therefore used in place of a DTD, an XML Schema definition, or a hardcoded solution (there is also a little bit of XUL hardcoding). It is therefore the ultimate authority and reference on XUL. All of the XBL bindings attached to tags using this stylesheet are also located in toolkit.jar.
Modifying xul.css modifies the look and/or behavior of all XUL-based extensions and applications. Don't modify this file directly; extend or override it with your own if you need to make changes.
220.127.116.11 The mozapps package
Another source of common dialog boxes appears in the mozapps package, which is also located in toolkit.jar. Rather than contain generic dialog boxes, this package contains functionality that represents "The Mozilla Way." If your chrome application wants to offer an extension interface, a themes interface, an update manager, or XPInstall functionality, then you'll find some generic pieces you can reuse.
8.8.2. Scavenging Application Pieces
The toolkit.jar archive is not the only place to find useful application pieces. Firefox's browser.jar chrome archive also contains some reusable bits. These include the Bookmark Manager and the Cookie Viewer. There's also the Help system, which is stored separately in help.jar. In general, any and all chrome content can contain gems that you can reuse, but as your application becomes more specific and more specialized, reusable pieces are harder to find.
8.8.3. Finding Embedded Components
Separate from the chrome proper are the XPCOM components that are used extensively in chrome scripts. It's not so easy to determine from scratch which components support which interfaces.
The cview extension (http://www.hacksrus.com/~rginda/) goes a little way toward listing all these components and their interfaces. For a complete set of reports, try the downloadable files from the book Rapid Application Development with Mozilla (Prentice Hall PTR). You can find them at the author's web site, http://www.nigelmcfarlane.com/books/radmoz_support.html.
8.8.4. Reusing Script Libraries