views:

328

answers:

2

I'm trying to develop a firefox extension that inserts additional HTTP header fields into outgoing HTTP requests (to interface with an apache extension i'm concurrently developing).

While I understand the individual components of an extension and understand the basic tutorials that are presented on the web, I'm finding it difficult going from the "Hello World" tutorial extensions, into developing a full blown extension.

The sample code I am wanting to adapt for my purposes is presented at the bottom of Setting HTTP request headers.

I am wondering, where in the extension hierarchy should this code be placed and how is such code called/constructed/activated, will it run automatically when the extension is initialised?



Thanks in advance.

+1  A: 

For a basic extension, you would place your code in the chrome/content directory of the extension. You would hook this content into Firefox using an overlay. While overlays are usually xul content (buttons, etc) they can be anything. Including a script tag which would load fire off your Javascript code.

ng.mangine
A: 

That code is an XPCOM component and goes into a components/<some name>.js file.

You should read up on XPCOM components if you want to dig it, but yes, .js files in components are loaded at startup. Such files contain registration code (starts at the var myModule = { line in that example), which tells Firefox whether the component defined in the file is available upon request or should it be instantiated automatically.

In that example you can see the component getting registered to be notified of the application's startup:

catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);

and when handling the app-startup notification it registers itself for the http-on-modify-request notification:

os.addObserver(this, "http-on-modify-request", false);
Nickolay