Extension Manager:Bootstrapped Extensions
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.
Rationale
Current XPI extensions 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 extension. Instead of registering XPCOM components and chrome in bootstrapped extension we instead do nothing except call a bootstrap script when loading the extension. The extension 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 Extension as Bootstrappable
Extensions are declared as being bootstrappable using the special em:type property with a value of 64 in the install manifest. They should also include a bootstrap.js file alongside the install.rdf.
Bootstrap Events
When an extension is loaded the bootstrap.js file is loaded into a privileged sandbox which is cached until the extension is unloaded. One of the following functions will be called:
install
is called if the extension is installed while Firefox is running.startup
is called when Firefox starts up and the extension is enabled (occurs during profile-after-change currently).enable
is called if the user enables the extension.
If the install
or startup
functions do not exist then the enable
function will be called in their place.
Each function will be passed two arguments, the ID of the extension and the nsIFile of the directory the extension is installed in.
When an extension is unloaded one of the following functions will be called from the cached sandbox:
uninstall
is called if the extension is uninstalled while Firefox is running.shutdown
is called if Firefox shuts down while the extension is enabled (occurs during quit-application-granted currently).disable
is called if the user disables the extension.
If the uninstall
or shutdown
functions do not exist then the disable
function will be called in their place.
After the function has been called all references to the sandbox will be dropped allowing it to be garbage collected unless the extension has failed to unload any part of itself.