Anton
Anton

Reputation: 173

Details of the Firefox add-on installation procedure

I am curious about the inner workings of the Firefox add-on installation procedure. I have noticed that the following steps take place when user installs an add-on from addons.mozilla.org:

  1. The add-on is downloaded (probably in a temporary folder).
  2. An installation confirmation dialogue box pops up ("install add-ons from authors you trust").
  3. Upon clicking install, the add-on is stored in the /extensions/staged folder. Along with the add-on, there is also a JSON file like this: addon_id.json.
  4. Firefox prompts the user to restart the browser.
  5. After restart, the contents from the /extensions/staged/ folder are moved to the /extensions/ folder.

What I would like to know is:

Basically, I would like to alter some files after an add-on is downloaded at step 1, but before it becomes part of the browser (step 5). I want to add this functionality in the Firefox source code.

Upvotes: 3

Views: 1135

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57651

You analysis is mostly correct, it merely leaves out bootstrapped extensions. Bootstrapped extensions don't require a browser restart, they will be moved out of the staged directory and activated immediately.

The Add-on Manager is all JavaScript starting with Firefox 4. The important files are amWebInstallListener.js (the component handling add-on installations from the web), AddonManager.jsm (the generic add-on management API) and XPIProvider.jsm (the provider for XPI-packaged extensions).

  1. extWebInstallListener.onWebInstallRequested() gets called with a bunch of AddonInstall instances (defined in XPIInstall.jsm) and creates an Installer instance that calls AddonInstall.install() for each of the installs. The downloads go into a temp file determined by getTemporaryFile() in XPIProvider.jsm (tmp-foo.xpi in the OS-specific temp directory).
  2. Installer.checkAllDownloaded() determines that all downloads finished and displays a modal confirmation dialog (URI_XPINSTALL_DIALOG).
  3. AddonInstall.startInstall() moves the add-on into the staging directory. Bootstrapped add-ons will be immediately installed after that. For other add-ons it continues to step 4.
  4. onInstallEnded listeners are triggered - one of them shows the message that the browser needs to be restarted.
  5. After a browser restart XPIProvider.startup() calls XPIProvider.checkForChanges() calls XPIProvider.processPendingFileChanges().

Upvotes: 2

Related Questions