Mozilla without the navigation toolbar

Summary

This document describes a small patch to Mozilla, the web browser, that adds small user interface features to allow disabling the navigation toolbar without loss of comfort.

In addition to the patch, the method used to do it may be useful as an example on how to change Mozilla. The method is not elegant, but the description is very straightforward because the patch is so small.

Description of the change: replacing the navigation toolbar

Mozilla, and many other web browsers, default to having a navigation toolbar with the 'Back' button, and a URL entry text field. I do not like this for several reasons: first the toolbar, remarkably huge in default mozilla themes, takes a lot of screen real estate. Secondly, programs with multiple focus zone are confusing (how often does text intended for a form go into the URL field and conversely?). It is the job of the window manager to manage different windows with distinct functions and focus (especially true in the case of window managers like Ion). Editing the URL outside the browser window is indeed no problem because the top Mozilla window can be changed by typing "mozilla <url>" in a shell. The 'Back' button is also not missed, because it is available from the context menu (right-click and menu selection is quicker than going to the corner of the window). Other more rarely used buttons are available from perfectly adequate menus. So far so good, the navigation toolbar can be disabled using Mozilla's 'View' menu.

Still, two functions of the navigation toolbar are missing: viewing the current URL of the document, and going to an URL which is a variant of the current one.

The current document URL issue is solved by displaying it in the status bar, when it is quiescent, instead of Mozilla's very informative "Document: Done". The status bar suddenly becomes more useful.

To edit the current URL on the command line, an item is added to the page context menu to copy the current URL to the clipboard from where it can be pasted into a shell. This function is seen in other browsers.

Now let's describe how both these changes have been implemented.

The patch

This patch is not elegant. It's actually quite ugly: it changes the javascript and XUL code in the standard chrome config giles. There is no compiled code involved, so no need to rebuild Mozilla (that seems challenging).

Note that all my knowledge of Mozilla's internals was gleaned during the execution of this patch, I am in no way a mozilla expert. It's interesting to see that the patch could be done in a few hours, without any previous knowledge of Mozilla's internals. Maybe that huge project is not as unapproachable as it seems from outside. Still, I have no idea if it's possible to implement this as a clean proper customisation.

The patch was done against Mozilla 0.9.8, as it comes in the Debian distribution (testing as of April 2002). It should be very similar in other versions.

comm.jar

All the patches are in the chrome/comm.jar ('comm' stands for Communicator I guess). A .jar file is just a .zip file (not using compression?). Making a copy of the original may be wise. In Debian, chrome is located in /usr/lib/mozilla/chrome.

To prepare the patch, just expand the .jar file (unzip comm.jar in a convenient director). Once the files have been edited, add them to the file: zip -u -0 comm.jar content/navigator/navigator.js for instance (-u to update a file, -0 not to compress).

The status bar

This is pretty simple, the Javascript function onStateChange of the status handler object, has already got the location handy, so all we need to do is replace the explicit bit that does "Document: Done":

File: {comm.jar}/content/navigator/nsBrowserStatusHandler.js

             msg = gNavigatorBundle.getString("nv_done");
             msg = msg.replace(/%elapsed%/, elapsed);

with:

             msg = location + " (" + elapsed + " s.)";

The context menu

First let add the function that implements the paste of the current address. After much grepping around, the file navigator.js was found to be a good location. An example of clipboard manipulation (and doc on mozilla.org) gave the clipboard manipulation routine. Let's add this BrowserCopyAddress (name inspired by existing ones):

File: {comm.jar}/content/navigator/navigator.js

function BrowserCopyAddress()
{
	// get current URL
	var url = getWebNavigation().currentURI.spec;

	// make unicode string    
	const kSuppWStringContractID = "@mozilla.org/supports-wstring;1";
	const kSuppWStringIID = Components.interfaces.nsISupportsWString;
	var unicodestring = Components.classes[kSuppWStringContractID].createInstance(kSuppWStringIID);

	// make transferable
	const kXferableContractID = "@mozilla.org/widget/transferable;1";
	const kXferableIID = Components.interfaces.nsITransferable;
	var xferable = Components.classes[kXferableContractID].createInstance(kXferableIID);

	// get clipboard service
	const kClipboardContractID = "@mozilla.org/widget/clipboard;1";
	const kClipboardIID = Components.interfaces.nsIClipboard;
	var clipboard = Components.classes[kClipboardContractID].getService(kClipboardIID);

	// fill transferable and paste
	unicodestring.data = url;
	xferable.addDataFlavor("text/unicode");
	xferable.setTransferData("text/unicode", unicodestring, url.length*2)

	// kSelectionClipboard is the primary X11 clipboard
	clipboard.emptyClipboard(clipboard.kSelectionClipboard);
	clipboard.setData(xferable, null, clipboard.kSelectionClipboard);
}

Now we need to bind a menu item. The context menu is declared in XUL code in contentAreaContextOverlay.xul, let's add an item, for instance before the first item in the "View" section, before "View page source".

	  <menuitem id="fa-copyurl"
	  			label="Copy Address"
				oncommand="BrowserCopyAddress();"/>

Apply

zip -u -0 /location/of/comm.jar \
	content/navigator/nsBrowserStatusHandler.js \
	content/navigator/navigator.js \
	content/communicator/contentAreaContextOverlay.xul

Restart Mozilla. The now redundant navigation toolbar can be hidden!

Open issues


Page author | last changed 2002-04-13