Bug 1385880: Part 2 - Store promise returned by bootstrap startup method. r?aswan
This is also the first step in moving async startup/shutdown tracking into the
add-on manager.
MozReview-Commit-ID: Uf4ecSW77S
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -753,17 +753,17 @@ const PROXIED_EVENTS = new Set(["test-ha
const shutdownPromises = new Map();
class BootstrapScope {
install(data, reason) {}
uninstall(data, reason) {}
startup(data, reason) {
this.extension = new Extension(data, this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
- this.extension.startup();
+ return this.extension.startup();
}
shutdown(data, reason) {
this.extension.shutdown(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.extension = null;
}
}
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -4387,21 +4387,28 @@ this.XPIProvider = {
}
}
if (!method) {
logger.warn("Add-on " + aAddon.id + " is missing bootstrap method " + aMethod);
} else {
logger.debug("Calling bootstrap method " + aMethod + " on " + aAddon.id + " version " +
aAddon.version);
+
+ let result;
try {
- method.call(scope, params, aReason);
+ result = method.call(scope, params, aReason);
} catch (e) {
logger.warn("Exception running bootstrap method " + aMethod + " on " + aAddon.id, e);
}
+
+ if (aMethod == "startup") {
+ activeAddon.startupPromise = Promise.resolve(result);
+ activeAddon.startupPromise.catch(Cu.reportError);
+ }
}
} finally {
// Extensions are automatically initialized in the correct order at startup.
if (aMethod == "startup" && aReason != BOOTSTRAP_REASONS.APP_STARTUP) {
for (let addon of this.getDependentAddons(aAddon))
this.updateAddonDisabledState(addon);
}
@@ -5439,16 +5446,27 @@ AddonWrapper.prototype = {
let addon = addonFor(this);
if (!addon.active)
return false;
if (!Services.appinfo.inSafeMode)
return true;
return addon.bootstrap && canRunInSafeMode(addon);
},
+ get startupPromise() {
+ let addon = addonFor(this);
+ if (!addon.bootstrap || !this.isActive)
+ return null;
+
+ let activeAddon = XPIProvider.activeAddons.get(addon.id);
+ if (activeAddon)
+ return activeAddon.startupPromise || null;
+ return null;
+ },
+
updateBlocklistState(applySoftBlock = true) {
addonFor(this).updateBlocklistState({applySoftBlock});
},
get userDisabled() {
let addon = addonFor(this);
return addon.softDisabled || addon.userDisabled;
},