Recent Changes -

WhatMakesTheLizardRoar-ATourThroughMozillaArchitecture

Abstract

We'll tour Mozilla's source code and some of the ways to hack it, with an eye toward practical hackery. How the heck do you build this beast? What's that XPCOM and NSPR stuff? Which modules do what in the code ... and which ones are amenable to a quick grep-and-tweak, versus the ones that should have big signs plastered over them warning "Here there be dragons"? (Leaving aside for the moment the ever-important debate over whether Mozilla is a dinosaur or a dragon.)

Some programming knowledge is assumed, but we won't be spending a lot of time on the innards of the C++ core libraries -- a surprising amount of Firefox's code is fairly high level Javascript and XUL, and you can browse a lot of it without even downloading a source tree.

I'll discuss the difference between XUL and XBL, how the JAR files are organized (and easy ways to look at them), and where Javascript fits in. When should you create an extension instead of just hacking the source tree -- and what options are there in between? How do you get started writing an extension? What's this xulrunner thing and how do you use it to make standalone apps?

By the end of this tutorial you'll have a better idea as to what parts of Mozilla are easily hackable, and you'll know how to write a simple Firefox extension as well as how to tweak your local Firefox installation.

Preparation

No preparation is required, but if you want to follow along on a laptop, I'd recommend you install some software beforehand. What you need depends on what aspects of Firefox/Mozilla you're most interested in hacking.

To hack your installed Firefox:

All you need is firefox installed. Any version, distro versions okay; I'll be using the most recent 3.0.x from mozilla.org. If you prefer seamonkey, you'll probably be able to adapt all the techniques though exact filenames may be different.

You'll also want an unzip program, and/or an editor that can read jar files, e.g. emacs (which edits jars automatically) or vim (see editing jars with vim).

See the bottom of the page for a script for unjarring your chrome.

To write an extension:

Same requirements as the previous section.

To hack or explore the latest C++ source:

Install Mercurial
https://developer.mozilla.org/en/Installing_Mercurial
and choose a merge tool:
http://www.selenic.com/mercurial/wiki/index.cgi/MergeProgram

Pull (and build, if you like) the latest source:
https://developer.mozilla.org/en/Mozilla_Source_Code_(Mercurial)
(Warning: PmWiki doesn't highlight that whole URL. To go to the real URL, triple-click over "Mercurial" to select the whole line, then Ctrl-middleclick to open the URL in a new tab.)
Command to pull the latest repository:
hg clone http://hg.mozilla.org/mozilla-central/ src
(656 Mb pure source, 1.9G after building Firefox.)

Unjarring chrome

 #!/usr/bin/perl -w
 # Any copyright is dedicated to the Public Domain.
 # http://creativecommons.org/licenses/publicdomain/

 foreach (glob("*.jar"))
 {
   print $_ . "\n";

   # Unzip it into a directory named after the jar file.
   m/^(.*)\.jar$/;
   system("unzip -q $_ -d $1");
 }

 foreach (glob("*.manifest"))
 {
   local $^I = ".orig";
   local @ARGV = ($_);
   while (<>)
   {
     s/\.?jar[!:]//g;
     print;
   }
 }

 system("rm *.orig");
Page last modified on January 21, 2009, at 03:02 PM