Sometimes it's necessary for XPCOM components to receive notifications as to the progress of the application's startup process, so they can start new services at appropriate times, for example.
In order to improve startup times, changes were made to the XPCOM startup process. See The startup process for details on how this now works, if you're interested in specifics.
The important thing to note is that now instead of registering with the Category Manager programmatically as was done in the past, you add lines to your chrome.manifest
to let the application handle it for you. For example:
category profile-after-change MyComponent @foobar/mycomponent;1
Additionally, the earliest startup time notification you can receive is now profile-after-change
. Your add-on will not receive
or xpcom-startup
app-startup
notifications.
During application startup, the application's manifest is used to get a list of the components it needs to register, and those components are loaded. This gets enough of XPCOM and the application loaded and running that the Extension Manager can then be loaded and handle installing, uninstalling, and updating any installed extensions.
Once that process is completed, extensions can then be loaded by simply reading their manifests, loading their components, and continuing with application startup, all without having to restart the browser.
To receive startup notifications, one needs to register with the "app-startup" category using nsICategoryManager
; having done so, the component will receive these startup notifications, including:
xpcom-startup
app-startup
final-ui-startup
To register with the Category Manager, simply call its nsICategoryManager.AddCategoryEntry()
method:
categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "mycomponentname", "contract-id", PR_TRUE, PR_TRUE, getter_Copies(previous));
This causes your component to be instantiated using nsIComponentManager.createInstance()
.
If you want your component to be started as a service, prepend "service," to the contract ID:
categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "mycomponentname", "service,contract-id", PR_TRUE, PR_TRUE, getter_Copies(previous));
With "service," specified, the component is instantiated using nsIComponentManager.getService()
.
In either case, there's no need to additionally register for the startup notifications. Simply registering with the Category Manager is enough.
Once you've registered with the Category Manager, at Mozilla startup time (or when the embedding application's NS_InitEmbedding()
function is called), the AppStartupNotifier component is instantiated, and its Observe()
method is called; this in turn enumerates all components in the app-startup
category and sends them the appropriate notifications.