By Mel Reyes
John Wiley & Sons ISBN: 0-7645-9650-0
Chapter One Boot Camp
in this chapter
* Installing the Document Inspector
* Editing text tools
* Your profile explained
* Backing up before hacking
Gearing up to hack Mozilla Firefox is as simple as understanding some basic Internet browser features, installing some tools, and being able to find files on your computer system. Then it gets just a tad more complicated. This chapter starts things off by discussing the different methods for hacking Firefox that are covered in this book and how things will progress. Try not to get bogged down with the onslaught of topics that are covered here, because many of them are covered in depth throughout the book.
Installing the Document Inspector Gadget
Out of the box, the Firefox Installer has two installation modes: Standard and Custom. If you have already done a Standard installation, you will be missing a key hacking and programming component: the Document Inspector, or DOM Inspector.
The Document Inspector extension is a development tool used to analyze the Document Object Model (DOM) of web pages or the Firefox interface, and is very useful in digging deeper into the core structure of web pages, the Firefox browser window, and browser elements. Currently, this browser development tool is available only from Firefox's main installation process. Later in this chapter and throughout the book, you will begin to see how web page document model standards fit into Firefox's interface customization.
So you want to install the Document Inspector (also called the DOM Inspector), but you already have Firefox installed? No problem. Simply reinstall Firefox, but instead of choosing the Standard installation type, choose the Custom installation type.
Follow the prompts until you get to the Select Components screen. Select Developer Tools, by clicking the checkbox as shown in Figure 1-1, to install the Document Inspector tool.
Once you have completed this installation or reinstallation, you will notice the DOM Inspector in your Tools menu is now available to all profiles on the system. You can use this tool as a resource for dissecting bits and pieces of web pages and the Firefox interface. Figure 1-2 shows the DOM Inspector view of a web page that is currently loaded in the main browser. Note that the hierarchy for the currently loaded web page is displayed in the left-hand panel, with each level or node grouped by the HTML-defined hierarchy and code. Additionally, details on the currently selected node are displayed in the right-hand panel; this panel becomes useful when hacking the Firefox interface.
Occasionally, I have noticed that running the DOM Inspector on a fresh install or reinstall did not yield the desired results or did not work at all. To correct this, I have tried either uninstalling Firefox and then reinstalling with the Developer Tools option enabled, or creating a new Firefox profile. Unless you are running an older version of Firefox that prompts you if you want to delete all the program files, the Firefox uninstaller retains all the supporting plugins and other files that it might need. If prompted to delete all Firefox program files, do not confirm this prompt; doing so will require reinstallation of plugin support for features such as Macromedia Flash, Shockwave, QuickTime and/or RealPlayer. Historically, uninstalling and reinstalling and/or creating a new profile have been the two methods that I have used to resolve mysterious Firefox issues when I could not consistently reproduce them.
For information on how to use the Profile Manager to create a new Firefox profile, visit the incredibly useful MozillaZine Knowledge Base at kb.mozillazine.org/Profile_ Manager.
While having a pretty hierarchy tree of your HTML is nice, the real benefit of the DOM Inspector is using it to hack Firefox itself. Firefox is built on a cross-platform extensible user interface language called XUL, which is based on XML standards and was created to support Mozilla applications. The user interfaces for the Mozilla Suite, Firefox, Thunderbird, and Sunbird all use XUL to create and display the user interface. This interface foundation is the core element that helps all these programs run on different operating systems. The interface is a collection of object definitions used to create each of the elements on the screen.
Using the DOM Inspector can easily help you walk through the hierarchy used to create the actual windows displayed by Firefox. To load the browser window's XUL hierarchy, just follow these steps:
1. In the main browser window navigate to any external web site, such as mrtech.com.
2. Open the DOM Inspector from the Tools menu. At this point, the web site opened in the previous step will be parsed.
3. From the File menu, choose the entry from the Inspect a Window menu option that corresponds with the site opened in the first step, in this case, "MRTech.com - Mozilla Firefox."
After following these steps, the nodes or page elements for the main browser window are loaded and available for visual inspection, as shown in the left-hand Document - DOM Nodes panel of Figure 1-3. For future reference, you can use the following location or URL for the main Firefox browser window to quickly browse the node tree: chrome://browser/ content/browser.xul.
After you have the nodes listed in the left panel for the browser.xul page, just click on Inspect to the right of the location bar to open a window to browse the actual page on the bottom half of the screen (also shown in Figure 1-3).
To find the internal name or id of a specific Firefox window element, I like to use the Select Element By Click option from the Search menu. Once you have selected this, you can click on any of the screen elements on the bottom half of the window and the DOM Inspector jumps to the actual definition for that element within the hierarchy. There you can easily access the internal id associated with the element and use that for future coding or manipulation.
The Select Element By Click option works only after you have clicked on Inspect next to the location bar.
Using the DOM Inspector and Figure 1-3, I will now explain how XUL is used to build the main Firefox browser window. As you see from this figure, there is a XUL object or node called toolbox with an id of navigator-toolbox. This object defines the top-level toolbar container on the main browser window. This container holds the three individual toolbar objects that are visible in the main window. They are toolbar-menubar, nav-bar, and PersonalToolbar. Digging deeper, the nav-bar toolbar object has a toolbarbutton object defined as back-button. This object holds the object information for the Back button, which is displayed on the browser window's navigation toolbar, and the fun continues from there with the rest of the interface XUL definitions.
All in all, the DOM Inspector is the most useful tool to begin digging around and understanding the interface elements that make up the Firefox windows.
Editing and Programming Text Tools
Another tool you will need is a good text-file editor. While the basic text editor that comes with the operating system works for some people, I have found that more functionality is desirable when working with web or Firefox files. Choose an editor with good code syntax highlighting or with other advanced options.
Key attributes to look for in a good programming editor or interface include the following:
* Is it actively developed?
* Can it support Windows, UNIX, Mac OS, and Unicode text-file formats?
* Does it have customizable tab stops or multi- or tabbed-file support?
* Is it free?
Using the editor provided by your operating system may work for you for now, but you may find yourself being a little more productive if you opt for a more up-to-date editor. Several good freeware text editors are actively developed and contain features that even the most diehard vi expert could grow to appreciate and love. Additional coverage on better programming editors is available in Chapter 16. One text editor that I have used in the past is EditPad, which works on Windows and Linux-based systems. I have also used the following Windows-based editors: Notepad++, PSPad, and the quick and simple Win32Pad.
You also have a few options for Linux distributions, including KDevelop, Nedit, Kate for KDE, or GEdit for GNOME. Apple Mac users have a lot of options for editors, including BBEdit, jEdit, and Mellel.
In addition to these editors, you can download and install the chromeEdit extension, featured in Chapter 2, for basic editing of the user.js, userChrome.css, and userContent.css files. For more information or to download chromeEdit, visit cdn.mozdev.org/chromedit/.
To download any of the aforementioned editors, just visit their sites:
* BBEdit: barebones.com/products/bbedit/
* EditPad: just-great-software.com/
* jEdit: jedit.org/
* Kdevelop: kdevelop.org/
* Mellel: redlers.com/
* Nedit: nedit.org/
* Notepad++: notepad-plus.sourceforge.net/uk/site.htm
* PSPad: pspad.com/en/
* Win32Pad: gena01.com/win32pad/
For more options and information on programming editors and software, visit thefreecountry.com/programming/editors.shtml.
A key feature of the console is its ability to jump to the offending code if you click the Source File: link just below the error message. Doing so opens the View Source window directly to the line number referenced in the message, as shown in Figure 1-5.
What and Where Is My Profile?
Your settings are stored in a Firefox directory or profile, which Firefox creates right after your first install. Your profile contains all your Firefox-specific settings, including but not limited to the following:
* Saved form values
* Saved passwords
Additionally, your profile contains any imported settings from Internet Explorer, Netscape 6/7, or Mozilla browsers.
Losing any part of your profile can be extremely annoying; Chapter 2 covers how to hack settings in your Firefox profile.
To work with your current profile manually, you first need to find the root directory where your personal settings are stored. To do this, you must follow the directions specific to your operating system, shown in the next section. This operating system-dependent "settings" directory is referred to as your %UserPath% as we continue. From there, you will be able to find the path and directory structure in which Firefox has stored your user profile.
Finding Your User Path
Each operating system has a different directory to which it saves your user settings. Most applications take advantage of this operating system "user path" to store their settings, so as not to collide with other users who might log into the same computer. Firefox does the same; it uses this directory to create the user's profile. The challenge is that each operating system uses a different naming and directory structure to store these files and settings. Making life even more complicated, different versions of the same operating system (for example, Windows) use different structures. Peruse the following subsections to find the operating system you are currently using, and read how to find your user path.
If you are using Windows, your user directory should look similar to this:
* Windows 2000/XP: C:\Documents and Settings\\Application Data\
* Windows NT: c:\Windows\Profiles\\
* Windows 9x/ME: C:\Windows\Application Data\Mozilla\Firefox
The drive (C:\ above) and location of the default Windows directory may vary based on your custom installation.
If Linux/UNIX is your modus operandi, you should expect to find your Firefox profile in a directory similar to ~/.mozilla/firefox.
Using Mac OS?
Finally, for all you Apple aficionados, your directory structure should be something similar to ~/Library/Application Support/Firefox.
Now that you have found your user directory, this will now be referred to as %UserPath% and will be used to track down where Firefox has stored your profile.
For official information on locating your Firefox profile, visit mozilla.org/ support/firefox/edit#profile.
Express Pass to Your Profile Path
One nice feature that Firefox finally enabled is human-readable settings for the profile.ini file with the direct or relative path to the current profile(s). Prior to this, profile information was stored in binary format only, and automating and scripting Firefox profiles was difficult to do. The profiles.ini file lives in the now common path for Firefox Profiles, which is as follows: %UserPath%\Mozilla\Firefox\.
The profiles.ini file will look similar to the following if this was the first time you installed Firefox:
[Profile0] Name=default IsRelative=1 Path=default\zsryldfv.slt
In this first example, notice that the IsRelative setting is equal to 1, which is a Boolean toggle for true. This means that the path is relative to the common Mozilla Firefox path of %UserPath%\Mozilla\Firefox\, so the full directory path would look something like %UserPath%\Mozilla\Firefox\default\zsryldfv.slt.
Note that zsryldfv in the path is a randomly generated directory name and varies from system to system. If you had previously installed earlier builds of Firefox that stored the profiles in other places, the profiles.ini file might look something like this:
[Profile0] Name=default IsRelative=0 Path=%UserPath%\Firefox\Profiles\default\zsryldfv.slt
Moreover, you will notice that IsRelative is zero or false, so the Path entry in the file reads as-is, or absolute, and that is where you will find your current profile.
Excerpted from Hacking Firefox by Mel Reyes Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.