Changes

Jump to: navigation, search

Dive into Mozilla Modifying Firefox using an Extension Lab

1,346 bytes added, 23:28, 13 March 2007
no edit summary
Extensions allow third-party developers (and Mozilla, for that matter) to write add-on packages that users can install to extend or modify the standard browser. By rewriting our earlier code as an extension, we can give users an extension to install, which will have the same effect as our custom build. For all but the most universal of changes, extensions are the best way for developers to write code that targets the browser.
==Planning the extension==
Having decided to rewrite the code as an extension and remove our changes from the tree, a logical first thought would be: "how can I modify my existing code to create an extension." While we learned some useful things modifying the browser directly, our extension will require a completely new approach to solving the same problem.
Having already successfully made this Instead of searching for existing code to change once before, we have to take the browser as a logical first thought would begiven and find ways to work with it. Here are some interesting pieces of [http: "How can I modify my existing code to create an extension//lxr.mozilla.org/seamonkey/source/toolkit/content/widgets/tabbrowser.xml#1122 tabbrowser." xml's addTab] method:
var t = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "tab");
...
this.mTabContainer.appendChild(t);
...
// Dispatch a new tab notification. We do this once we're
// entirely done, so that things are in a consistent state
// even if the event listener opens or closes tabs.
var evt = document.createEvent("Events");
evt.initEvent("TabOpen", true, false);
t.dispatchEvent(evt);
return t;
 
After the tab is created and appended to the end of the list, an '''event''' is '''dispatched'''. The developers of tabbrowser.xml wanted their code to be extensible; that is, they wanted to provide other developers a hook on which to hang their code. Their foresight makes our job much easier.
 
Now we have a The name of the event is significant, as we'll have to write co'''TabOpen''', which is important for us.
Start by creating a new extension, either by hand, or using Ted Mielczarek's wonderful wizard:

Navigation menu