Getting started with contributing patches to the Firefox preferences

  • Revision slug: Hacking_Firefox/Getting_started_with_contributing_patches_to_the_Firefox_preferences
  • Revision title: Getting started with contributing patches to the Firefox preferences
  • Revision id: 55481
  • Created:
  • Creator: Sheppy
  • Is current revision? Yes
  • Comment 20 words added, 6 words removed

Revision Content

Note: This article covers a feature that is not yet scheduled for a specific future release of Firefox.

The Firefox preferences serve as a tool for users to modify and personalize Firefox to their own, well, preference. This page should serve as a guide for people looking to get started with moving the current Preferences from the Window/Sheet implementation to being viewed within the content pane of the browser.

This page assumes you have already set up a build environment and have built Firefox. If you haven't set up a build environment or compiled Firefox yet, please follow the instructions in the Working with Mozilla Source Code and the Build Instructions first.

There's a lot of background knowledge that will have to be acquired over time. Nobody is expected to jump in to the Firefox code base, or any code base of similar size, and be successful in the first couple of tries.

Getting started

The first step of every front-end developer working on a Mozilla project is to install the DOM Inspector add-on. This add-on allows developers to dig in to the XUL/HTML/CSS/layout of the Firefox user interface. After installing DOM Inspector, press Ctrl+Shift+I (letter I, pronounced as eye) on Windows and Cmd+Shift+I on Mac OS X. Then choose File -> Inspect Chrome Document and choose the tab that is in the foreground. Now click on the button all the way to the left on the toolbar (it shows a cursor on top of a rounded rectangle) to pick an element for inspecting. You can now use the various tools of DOM Inspector and play around with the Firefox front-end.

Step one: Browsing through some code

There are already a few preference pages that are rendered in-content. The best example of this is about:permissions. Take a few minutes now and visit about:permissions in Firefox, using DOM Inspector to view the markup used within the page.

Step two: Reasoning about how XUL works

If you're curious as to why a certain XUL element was used or what each XUL element does, you can take a look at the XUL documentation or walk through the XUL tutorial.

Step three: Getting to know the XUL, JS, and CSS of about:permissions

Mozilla contributors can use MXR, the Mozilla Cross-Reference, to browse and search the Mozilla code base. The files used to display about:permissions can be viewed here:

The files located in /locales/ are used for generating language-specific builds of Firefox for use across the world. Changes made to Firefox usually only contain the en-US locale (English-United States). When the code moves out of trunk and in to the Aurora channel, localizers from across the world will add their own *.dtd file with their locale-specific languages.

Changes in /winstripe/ affect the Windows theme, changes in /pinstripe/ affect the Mac OS X theme, and changes in /gnomestripe/ affect the Linux theme of Firefox.

Now that you've seen the source code on MXR, open the files on your local build and make some changes. For some simple changes, you could try tweaking some of the CSS or XUL files.

Building Firefox can take a long time, but it doesn't need to. Since you've already built Firefox, (you have, haven't you?) you can now go to the object directory (located at /mozilla-central/obj-blah-blah-blah) and type make -s -C browser/components to rebuild just the components directory. If you make changes in one of the other directories, simply replace the components word with the relevant folder name, such as locales or themes. Note that if you are using Mac OS X, you will also need to run make -s -C browser/app.

To see your changes, change the working directory to /mozilla-central/obj-blah-blah-blah:

  • On Windows, run dist/bin/firefox.exe
  • On Mac OS X, run dist/NightlyDebug.app/Contents/MacOS/firefox-bin
  • On Linux, run dist/bin/firefox

If you already have Firefox running, you will get an error stating that, well, Firefox is already running. This is less than great, but there is a way to run multiple versions of Firefox simultaneously. For more information, see: Running multiple versions of Firefox simultaneously.

Step four: Making your own about: page

Now that you've gotten a little comfortable tweaking an existing in-content preference page, you can try creating a simple page of your own.

Update the files located here with an entry of about:omgmyownpage or something else that you think is cool:

To get a feel for what to do, try to simply copy what is done for "permissions". If you're having trouble here, ask a question in #fx-team or #developers on Mozilla's IRC network.

Now, add your own files in /browser/components/preferences/ with your own filename. To be consistent, you can name it aboutOmgMyOwnPage.xhtml. Note, how the filename ends in .xhtml, this is on purpose. Mozilla is trying to extend and build off of (X)HTML, so we're trying to use XUL less and less, and only fall back to XUL when HTML is lacking. So for this walk-through, we're going to try to start on the right foot.

After making your files, you will also need to add them to the jar.mn file. The jar.mn file is used to package up content files that are used by the browser. It is designed to make loading of content faster. The file for this example is located at browser/components/preferences/jar.mn

If you want to see how (X)HTML pages are similar or different from XUL pages, you can compare with /browser/components/sessionstore/content/aboutSessionRestore.xhtml.

After making your changes, you can now rebuild and see your changes. Make sure that your working directory is the object directory (/mozilla-central/obj-blah-blah-blah), and type make -s -C browser/components/ and also rebuild /browser/app if you're running on Mac OS X. After building, run the browser using the same tips from step three. Visit about:omgmyownpage to see, your new page.

Closing the connection

If you have any questions, please do not hesitate to visit the channels on Mozilla's IRC server. Don't ask if you can ask a question, just ask. And if nobody replies, don't take it personally (folks are really busy!), just ask again later.

Revision Source

<div class="note"><strong>Note:</strong> This article covers a feature that is not yet scheduled for a specific future release of Firefox.</div>
<p>The Firefox preferences serve as a tool for users to modify and personalize Firefox to their own, well, preference. This page should serve as a guide for people looking to get started with moving the current Preferences from the Window/Sheet implementation to being viewed within the content pane of the browser.</p>
<p>This page assumes you have already set up a build environment and have built Firefox. If you haven't set up a build environment or compiled Firefox yet, <strong>please follow the instructions in the <a href="/En/Developer_Guide/Source_Code" title="Working with Mozilla source code">Working with Mozilla Source Code</a> and the <a href="/En/Developer_Guide/Build_Instructions" title="Build Instructions">Build Instructions</a> first</strong>.</p>
<p>There's a lot of background knowledge that will have to be acquired over time. Nobody is expected to jump in to the Firefox code base, or any code base of similar size, and be successful in the first couple of tries.</p>
<h2 id="Getting_started">Getting started</h2>
<p>The first step of every front-end developer working on a Mozilla project is to install <a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/dom-inspector-6622/" title="https://addons.mozilla.org/en-US/firefox/addon/dom-inspector-6622/">the DOM Inspector add-on</a>. This add-on allows developers to dig in to the XUL/HTML/CSS/layout of the Firefox user interface. After installing DOM Inspector, press Ctrl+Shift+I (letter I, pronounced as eye) on Windows and Cmd+Shift+I on Mac OS X. Then choose <strong>File -&gt; Inspect Chrome Document</strong> and choose the tab that is in the foreground. Now click on the button all the way to the left on the toolbar (it shows a cursor on top of a rounded rectangle) to pick an element for inspecting. You can now use the various tools of DOM Inspector and play around with the Firefox front-end.</p>
<h3 id="Step_one:_Browsing_through_some_code">Step one: Browsing through some code</h3>
<p>There are already a few preference pages that are rendered in-content. The best example of this is <strong>about:permissions</strong>. Take a few minutes now and visit about:permissions in Firefox, using DOM Inspector to view the markup used within the page.</p>
<h3 id="Step_two:_Reasoning_about_how_XUL_works">Step two: Reasoning about how XUL works</h3>
<p>If you're curious as to why a certain XUL element was used or what each XUL element does, you can take a look at <a href="/en/XUL" title="XUL">the XUL documentation</a> or walk through <a href="/en/XUL_Tutorial" title="XUL Tutorial">the XUL tutorial</a>.</p>
<h3 id="Step_three:_Getting_to_know_the_XUL,_JS,_and_CSS_of_about:permissions">Step three: Getting to know the XUL, JS, and CSS of about:permissions</h3>
<p>Mozilla contributors can use MXR, the Mozilla Cross-Reference, to browse and search the Mozilla code base. The files used to display about:permissions can be viewed here:</p>
<ul> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/aboutPermissions.js">aboutPermissions.js</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/aboutPermissions.css">aboutPermissions.css</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/aboutPermissions.xml">aboutPermissions.xml</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/aboutPermissions.xul">aboutPermissions.xul</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/">locales</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/">en-US</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/">chrome</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/preferences/aboutPermissions.dtd">aboutPermissions.dtd</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/">locales</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/">en-US</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/">chrome</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/preferences/aboutPermissions.properties">aboutPermissions.properties</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/">themes</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/winstripe/">winstripe</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/winstripe/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/winstripe/preferences/aboutPermissions.css">aboutPermissions.css</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/">themes</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/pinstripe/">pinstripe</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/pinstripe/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/pinstripe/preferences/aboutPermissions.css">aboutPermissions.css</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/">themes</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/gnomestripe/">gnomestripe</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/gnomestripe/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/themes/gnomestripe/preferences/aboutPermissions.css">aboutPermissions.css</a></span></li>
</ul>
<p>The files located in <code>/locales/</code> are used for generating language-specific builds of Firefox for use across the world. Changes made to Firefox usually only contain the en-US locale (English-United States). When the code moves out of trunk and in to the Aurora channel, localizers from across the world will add their own <code>*.dtd</code> file with their locale-specific languages.</p>
<p>Changes in <code>/winstripe/</code> affect the Windows theme, changes in <code>/pinstripe/</code> affect the Mac OS X theme, and changes in <code>/gnomestripe/</code> affect the Linux theme of Firefox.</p>
<p>Now that you've seen the source code on MXR, open the files on your local build and make some changes. For some simple changes, you could try tweaking some of the CSS or XUL files.</p>
<p>Building Firefox can take a long time, but it doesn't need to. Since you've already built Firefox, (you have, haven't you?) you can now go to the object directory (located at <code>/mozilla-central/obj-<em>blah-blah-blah</em></code>) and type <code>make -s -C browser/components</code> to rebuild just the <code>components</code> directory. If you make changes in one of the other directories, simply replace the <code>components</code> word with the relevant folder name, such as <code>locales</code> or <code>themes</code>. Note that if you are using Mac OS X, you will also need to run <code>make -s -C browser/app</code>.</p>
<p>To see your changes, change the working directory to <code>/mozilla-central/obj-<em>blah-blah-blah</em></code>:</p>
<ul> <li>On Windows, run <code>dist/bin/firefox.exe</code></li> <li>On Mac OS X, run <code>dist/NightlyDebug.app/Contents/MacOS/firefox-bin</code></li> <li>On Linux, run <code>dist/bin/firefox</code></li>
</ul>
<p>If you already have Firefox running, you will get an error stating that, well, Firefox is already running. This is less than great, but there is a way to run multiple versions of Firefox simultaneously. For more information, see: <a class="external" href="http://msujaws.wordpress.com/2011/06/29/running-multiple-versions-of-firefox-simultaneously/" title="http://msujaws.wordpress.com/2011/06/29/running-multiple-versions-of-firefox-simultaneously/">Running multiple versions of Firefox simultaneously</a>.</p>
<h3 id="Step_four:_Making_your_own_about:_page">Step four: Making your own <strong>about:</strong> page</h3>
<p>Now that you've gotten a little comfortable tweaking an existing in-content preference page, you can try creating a simple page of your own.</p>
<p>Update the files located here with an entry of <code>about:omgmyownpage</code> or something else that you think is cool:</p>
<ul> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/about/">about</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/about/AboutRedirector.cpp">AboutRedirector.cpp</a></span></li> <li><span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/build/">build</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/build/nsModule.cpp">nsModule.cpp</a></span></li>
</ul>
<p>To get a feel for what to do, try to simply copy what is done for "permissions". If you're having trouble here, ask a question in <a class="external" href="http://chat.mibbit.com/?server=irc.mozilla.org&amp;channel=%23fx-team" title="http://chat.mibbit.com/?server=irc.mozilla.org&amp;channel=%23fx-team">#fx-team</a> or <a class="external" href="http://chat.mibbit.com/?server=irc.mozilla.org&amp;channel=%23developers" title="http://chat.mibbit.com/?server=irc.mozilla.org&amp;channel=%23developers">#developers</a> on <a class="external" href="http://chat.mibbit.com/?server=irc.mozilla.org" title="http://chat.mibbit.com/?server=irc.mozilla.org">Mozilla's IRC network</a>.</p>
<p>Now, add your own files in <code>/browser/components/preferences/</code> with your own filename. To be consistent, you can name it <code>aboutOmgMyOwnPage.xhtml</code>. Note, how the filename ends in <code>.xhtml</code>, this is on purpose. Mozilla is trying to extend and build off of (X)HTML, so we're trying to use XUL less and less, and only fall back to XUL when HTML is lacking. So for this walk-through, we're going to try to start on the right foot.</p>
<p>After making your files, you will also need to add them to the <code>jar.mn</code> file. The <code>jar.mn</code> file is used to package up content files that are used by the browser. It is designed to make loading of content faster. The file for this example is located at <a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/">preferences</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/jar.mn">jar.mn</a></p>
<p>If you want to see how (X)HTML pages are similar or different from XUL pages, you can compare with <span class="s0"><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/">/</a><a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/">browser</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/">components</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/sessionstore/">sessionstore</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/sessionstore/content/">content</a>/<a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/components/sessionstore/content/aboutSessionRestore.xhtml">aboutSessionRestore.xhtml</a>.</span></p>
<p><span class="s0">After making your changes, you can now rebuild and see your changes. Make sure that your working directory is the object directory (<code>/mozilla-central/obj-<em>blah-blah-blah</em></code>), and type <code>make -s -C browser/components/</code> and also rebuild <code>/browser/app</code> if you're running on Mac OS X. After building, run the browser using the same tips from step three.</span> Visit <code><span style="font-weight: bold;">about:omgmyownpage</span></code> to see, your new page.</p>
<h2 id="Closing_the_connection">Closing the connection</h2>
<p>If you have any questions, please do not hesitate to visit the channels on Mozilla's IRC server. Don't ask if you can ask a question, just ask. And if nobody replies, don't take it personally (folks are really busy!), just ask again later.</p>
Revert to this revision