canmove, Confirmed users
1,567
edits
(Created page with 'Bootstrapped extensions exist as a means of restricting what is available to an extension in order to allow it to be loaded and unloaded with restarting the application. ==Ratio…') |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__Bootstrapped add-ons exist as a means of restricting what is available to an add-on in order to allow it to be loaded and unloaded with restarting the application. | |||
==Rationale== | ==Rationale== | ||
Current XPI | Current XPI add-ons cannot be unloaded without restarting the application. This is because the features that we give them (XPCOM components, chrome registration and overlays etc.) cannot be removed in a managed fashion. Loading without a restart could possibly be implemented however that really only solves a small part of the problem as updates etc. would still require restarts. | ||
The approach taken here is to simplify what it means to be an | The approach taken here is to simplify what it means to be an add-on. Instead of registering XPCOM components and chrome in bootstrapped add-ons we instead do nothing except execute a bootstrap script when the add-on is loaded and call some functions on it. The add-on can do whatever it likes at that point however it must undo anything it has done when we call the bootstrap script to tell it to unload. | ||
==Declaring an | ==Declaring an Add-on as Bootstrappable== | ||
Add-ons are declared as being bootstrappable using the special em:bootstrap="true" property in the install manifest. Although any type of add-on can include this, for now it only makes sense for add-ons with em:type="2" (the default extension type) to include it. They should also include a bootstrap.js file alongside the install.rdf. | |||
==Bootstrap Events== | ==Bootstrap Events== | ||
When an | When an add-on is loaded the bootstrap.js file is executed in a privileged sandbox which is cached until the add-on is unloaded. The scripts should contain a number of functions that will be called to notify the add-on of certain events: | ||
===Startup=== | |||
Whenever an add-on needs to be loaded the platform will call a function named <code>startup</code> in the bootstrap script. It will be passed the following arguments: | |||
;data :A JS object containing basic information about the add-on, <code>id</code>, <code>version</code> and <code>installPath</code>. | |||
;reason :A number representing the reason for loading the add-on. This may be APP_STARTUP or ADDON_ENABLE. | |||
===Shutdown=== | |||
Whenever an add-on needs to be unloaded the platform will call a function named <code>shutdown</code> in the bootstrap script. It will be passed the following arguments: | |||
;data :A JS object containing basic information about the add-on, <code>id</code>, <code>version</code> and <code>installPath</code>. | |||
;reason :A number representing the reason for unloading the add-on. This may be APP_SHUTDOWN or ADDON_DISABLE. | |||
===Install=== | |||
The bootstrap script may include an <code>install</code> method and if so it will be called before the first call to <code>startup</code> after a particular version of an add-on is installed. It will be passed the following arguments: | |||
;data :A JS object containing basic information about the add-on, <code>id</code>, <code>version</code> and <code>installPath</code>. | |||
;reason :A number representing the reason for installing the add-on. This may be ADDON_INSTALLED, ADDON_UPGRADED or ADDON_DOWNGRADED. | |||
Note that <code>install</code> will never be called if the add-on is never loaded. | |||
===Uninstall=== | |||
The bootstrap script may include an <code>uninstall</code> method and if so it will be called after the last call to <code>shutdown</code> before a particular version of an add-on is uninstalled. It will be passed the following arguments: | |||
;data :A JS object containing basic information about the add-on, <code>id</code>, <code>version</code> and <code>installPath</code>. | |||
;reason :A number representing the reason for installing the add-on. This may be ADDON_UNINSTALLED, ADDON_UPGRADED or ADDON_DOWNGRADED. | |||
Note that <code>uninstall</code> may be called even when add-ons are disabled or incompatible with the current application. It is important that the <code>uninstall</code> script be carefully written to handle APIs that may no longer be present in the application. | |||
In some cases <code>uninstall</code> may never be called for an add-on. This happens when a third-party application removes the add-on while Firefox is not running. |