mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-27 18:01:44 -10:00
Unifies the methods we have to check that bootstrap add-ons are correctly loaded and makes it easier to make changes to them all in the future without needing to re-sign add-ons etc. This code allows a bootstrap script to use a shared script in a single line of code. The shared scripts sends out all the relevant info over the observer service, the add-ons manager test harness receives and retains the current state for every add-on also performing sanity checks like making sure an "install" method is always called before any "startup" method etc. It also provides simple functions to check the state of a given add-on.
29 lines
844 B
JavaScript
29 lines
844 B
JavaScript
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
this.EXPORTED_SYMBOLS = [ "monitor" ];
|
|
|
|
function notify(event, originalMethod, data, reason) {
|
|
let info = {
|
|
event,
|
|
data: Object.assign({}, data, {
|
|
installPath: data.installPath.path,
|
|
resourceURI: data.resourceURI.spec,
|
|
}),
|
|
reason
|
|
};
|
|
|
|
Services.obs.notifyObservers(null, "bootstrapmonitor-event", JSON.stringify(info));
|
|
|
|
// If the bootstrap scope already declares a method call it
|
|
if (originalMethod)
|
|
originalMethod(data, reason);
|
|
}
|
|
|
|
// Allows a simple one-line bootstrap script:
|
|
// Components.utils.import("resource://xpcshelldata/bootstrapmonitor.jsm").monitor(this);
|
|
this.monitor = function(scope) {
|
|
for (let event of ["install", "startup", "shutdown", "uninstall"]) {
|
|
scope[event] = notify.bind(null, event, scope[event]);
|
|
}
|
|
}
|