Extension Manager:Bootstrapped Extensions: Difference between revisions

no edit summary
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 started up and shutdown without restarting the application.
__NOTOC__Bootstrapped add-ons are a special kind of add-on that developers can choose to use instead of normal add-ons in order to allow users to install and use the add-on without needing to restart the application. In order to do this, rather than the application loading chrome and components from the add-on it is up to the add-on developer to do all of this manually.


Current XPI add-ons cannot be removed from memory 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. Adding an add-on 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.
All the application will do is execute a bootstrap script that the add-on provides, telling it to startup. 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 shutdown.
 
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 do nothing except execute a bootstrap script that the add-on provides, telling it to startup. 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 shutdown.


==Starting up and Shutting down==
==Starting up and Shutting down==


A key feature of bootstrapped add-ons is that they must be able to be started and shutdown on demand by the platform. When told to startup it is up to the add-on's bootstrap code to do anything necessary to inject UI and behaviour into the application. When told to shutdown it is required that the add-on remove anything it has added and removing all references to its objects. Some examples of when startup and shutdown happen:
A key feature of bootstrapped add-ons is that they must be able to be started and shutdown on demand by the application. When told to startup it is up to the add-on's bootstrap code to do anything necessary to inject UI and behaviour into the application. When told to shutdown it is required that the add-on remove anything it has added and removing all references to its objects. Some examples of when startup and shutdown happen:


* When first installed (if the add-on is compatible and enabled) the platform will tell the add-on to start up.
* When first installed (if the add-on is compatible and enabled) the application will tell the add-on to start up.
* When uninstalled (if the add-on is currently enabled) the platform will tell the add-on to shutdown.
* When uninstalled (if the add-on is currently enabled) the application will tell the add-on to shutdown.
* When enabled or disabled while the application is running the platform will tell the add-on to startup or shutdown as appropriate.
* When enabled or disabled while the application is running the application will tell the add-on to startup or shutdown as appropriate.
* When the application is started the platform will tell any enabled add-ons to startup.
* When the application is started the application will tell any enabled add-ons to startup.
* When the user quits the application the platform will tell any enabled add-ons to shutdown.
* When the user quits the application the application will tell any enabled add-ons to shutdown.


==Declaring an Add-on as Bootstrappable==
==Declaring an Add-on as Bootstrappable==
Line 25: Line 23:
==Bootstrap Events==
==Bootstrap Events==


Bootstrapped add-ons must provide a bootstrap.js file which defines main entry functions as defined below. When the platform needs to call a function the script will be executed in a privileged sandbox which is cached until the add-on is shutdown.
Bootstrapped add-ons must provide a bootstrap.js file which defines main entry functions as defined below. When the application needs to call a function the script will be executed in a privileged sandbox which is cached until the add-on is shutdown.


===Startup===
===Startup===


Whenever an add-on needs to be started the platform will call a function named <code>startup</code> in the bootstrap script. It will be passed the following arguments:
Whenever an add-on needs to be started the application will call a function named <code>startup</code> in the bootstrap script. <code>startup</code> may be called at any point during an application run. 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>.
;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 starting the add-on. This may be APP_STARTUP or ADDON_ENABLE.
;reason :A number representing the reason for starting the add-on. This may be APP_STARTUP or ADDON_ENABLE.


The add-on must at this point do anything necessary to make its functionality available, the platform will not execute any other part of the add-on.
The add-on must at this point do anything necessary to make its functionality available, the application will not execute any other part of the add-on.


===Shutdown===
===Shutdown===


Whenever an add-on needs to be shutdown the platform will call a function named <code>shutdown</code> in the bootstrap script. It will be passed the following arguments:
Whenever an add-on needs to be shutdown the application will call a function named <code>shutdown</code> in the bootstrap script. <code>shutdown</code> may be called at any point during an application run. 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>.
;data :A JS object containing basic information about the add-on, <code>id</code>, <code>version</code> and <code>installPath</code>.
canmove, Confirmed users
1,570

edits