Team LiB
Previous Section Next Section

Hack 77. Customize Firefox's Interface

Tweak and modify the browser's interface to suit your needs.

Firefox is generally hailed as having an excellent user interface (UI). The art of user-interface design is one of making compromises, where each feature must be carefully weighed and evaluated before inclusion. While this strategy of catering to the lowest common denominator leads to the greatest amount of satisfaction for the largest number of users, it generally fails to maximize utility for individual users. There will inevitably be parts of the browser that some will find useless, unpleasant, or downright intrusive. Locked-down kiosks or other specialized uses of the browser also require a more customized interface. This hack explores how to make Firefox's UI more closely match your own needs and desires. As an example, we'll remove the links to the default email client from the Tools menu. These are only available in the Windows port, so by removing them, we actually make Firefox more portable.

Since we'll be in the neighborhood, we'll also disable the key binding (Ctrl-M or Command-M) responsible for opening a new email composition; it's all too easy to hit M instead of N when trying to open a new window, and the second or two delay while the mail window opens can be disruptive. We could also do a little nip/tuck work on the context menu, but that is left as an exercise for the reader.

You can apply this hack's logic to any menu item that you care to examine. It's the process that's important here, not the details.

7.4.1. Identifying the Objective

The first goal of this hack is simply to figure out what it is that needs to be removed. Figure 7-3 shows the Tools menu with the target menu items highlighted.

Figure 7-3. Unwanted menu items


There are actually three pieces that we want to remove: the Read Mail and New Message... menu items, plus one of the surrounding menu separators (so that we don't get two adjacent separators when we're done). In order to allow Firefox to be translated into many languages, text strings such as Read Mail and New Message are kept separate from the code that creates the menu items, so we can't simply search for them, but the keyword mail will probably lead us in the right direction.

7.4.2. Ready...

It is always a good idea to close Firefox before editing any files that it uses while running. Once that's done, our next task is to find the file that contains those menu items. We'll be modifying the browser code itself (this is, after all, "Hacking the Chrome Ugly"), so we'll start our search from the Firefox executable. In Windows, this is likely to be located in C:\Program Files\Mozilla Firefox\.

Sure enough, inside lies a promising-looking folder named chrome. This folder in turn contains another promising-looking item named browser.jar. As used by Mozilla, JAR files are simply ZIP files renamed; they can be opened with any ZIP-capable program. Use one to extract browser.jar's contents into a new folder named browser. Later, we'll rezip this folder back to browser.jar, but instead of deleting the original, it's a good idea to rename it to something like brower_original.jar in case something should go wrong with your modified version.

7.4.3. Aim...

Inside the new browser folder is a content folder that contains another browser folder. Within this innermost browser folder lies the target of our search: a hefty (approximately 72 KB) file named browser.xul. If the Gecko rendering engine is the heart of Firefox, this file is the epidermis. It contains the XUL (XML User-interface Language) declarations that create the toolbars, menus, and context menus that surround the web pages Firefox displays.

We could manually search through the entire file to find the right lines, but it would be much easier to simply search for the relevant bits. As mentioned earlier, the word mail should be a good starting point for our search. The first occurrences of mail are on lines 93 through 97 and are commandsXUL that links GUI elements to the JavaScript code that makes them worknot what we want. The next appearances are on lines 321 through 324 and are for a context menu itemcloser, but again, not what we're looking for.

The next occurrence, however, is exactly what we're looking for. The following code begins on line 844:

 <menu label="&toolsMenu.label;" accesskey="&toolsMenu.accesskey;">
   <menupopup id="menu_ToolsPopup"
              onpopupshowing="MailIntegration.updateUnreadCount( );"
   >
     <menuitem label="&search.label;" accesskey="&search.accesskey;" 
               key="key_search" command="Tools:Search"/>
     <menuseparator/>
     <menuitem label="&mailButton.readMail.label;" 
               accesskey="&mailButton.readMail.accesskey;"
               command="Browser:ReadMail"/>
     <menuitem label="&mailButton.newMessage.label;" 
               accesskey="&mailButton.newMessage.accesskey;"
               key="key_newMessage" command="Browser:NewMessage"/>
     <menuseparator/>

We'll just comment out one menuseparator and the two menuitems. The onpopupshowing then becomes unnecessary, but be careful; XML does not allow attributes to be commented out, so the attribute/value string must be moved from the menupopup element to the comment, like this:

<menu label="&toolsMenu.label;" accesskey="&toolsMenu.accesskey;">
   <menupopup id="menu_ToolsPopup">
     <menuitem label="&search.label;" accesskey="&search.accesskey;" 
               key="key_search" command="Tools:Search"/>
<!--
        *** from menupopup: 
             onpopupshowing="MailIntegration.updateUnreadCount( );"
        ***
     <menuseparator/>
     <menuitem label="&mailButton.readMail.label;" 
               accesskey="&mailButton.readMail.accesskey;"
               command="Browser:ReadMail"/>
     <menuitem label="&mailButton.newMessage.label;" 
               accesskey="&mailButton.newMessage.accesskey;"
               key="key_newMessage" command="Browser:NewMessage"/>
-->
     <menuseparator/>

This is a good start, but we're not quite done. At this point, if we press the system accelerator key (Control on Windows and Linux; Command on Mac) and M, Firefox will open the default mail program and begin composing a new message. Searching browser.xul for other instances of command="Browser:NewMessage" shows the culprit on line 250:

<key id="key_newMessage"
         key="&sendMessage.commandkey;"
         command="Browser:NewMessage"
         modifiers="accel"/>

Simply comment out the entire element, and...

7.4.4. Firefox!

That's all the editing we'll be doing for this hack; now, we'll get Firefox back up and running. The process should be simple. Navigate back to the top-level chrome directory and then into the browser folder. Zip up the content folder with whatever tool you have at your disposal and rename the newly zipped folder to browser.jar. Then, move the new JAR file up to the chrome folder. You can leave the browser directory alone; it won't interfere with Firefox's operation. Start up Firefox, and it should now look like Figure 7-4.

Figure 7-4. The slimmed-down Tools menu


Ben Karel

    Team LiB
    Previous Section Next Section