Skip to content

Commit

Permalink
Bug 1483033 - EmbeddedExtension should pass string startup and shutdo…
Browse files Browse the repository at this point in the history
…wn reasons to the embedded webextension, not numeric reasons. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D5820

--HG--
extra : moz-landing-system : lando
  • Loading branch information
0c0w3 committed Sep 13, 2018
1 parent e9c38d0 commit 956bb2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
23 changes: 4 additions & 19 deletions toolkit/components/extensions/Extension.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1211,44 +1211,29 @@ class BootstrapScope {

startup(data, reason) {
// eslint-disable-next-line no-use-before-define
this.extension = new Extension(data, this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.extension = new Extension(data, AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
return this.extension.startup();
}

shutdown(data, reason) {
let result = this.extension.shutdown(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
let result = this.extension.shutdown(AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.extension = null;
return result;
}
}

XPCOMUtils.defineLazyGetter(BootstrapScope.prototype, "BOOTSTRAP_REASON_TO_STRING_MAP", () => {
const {BOOTSTRAP_REASONS} = AddonManagerPrivate;

return Object.freeze({
[BOOTSTRAP_REASONS.APP_STARTUP]: "APP_STARTUP",
[BOOTSTRAP_REASONS.APP_SHUTDOWN]: "APP_SHUTDOWN",
[BOOTSTRAP_REASONS.ADDON_ENABLE]: "ADDON_ENABLE",
[BOOTSTRAP_REASONS.ADDON_DISABLE]: "ADDON_DISABLE",
[BOOTSTRAP_REASONS.ADDON_INSTALL]: "ADDON_INSTALL",
[BOOTSTRAP_REASONS.ADDON_UNINSTALL]: "ADDON_UNINSTALL",
[BOOTSTRAP_REASONS.ADDON_UPGRADE]: "ADDON_UPGRADE",
[BOOTSTRAP_REASONS.ADDON_DOWNGRADE]: "ADDON_DOWNGRADE",
});
});

class DictionaryBootstrapScope extends BootstrapScope {
install(data, reason) {}
uninstall(data, reason) {}

startup(data, reason) {
// eslint-disable-next-line no-use-before-define
this.dictionary = new Dictionary(data);
return this.dictionary.startup(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
return this.dictionary.startup(AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
}

shutdown(data, reason) {
this.dictionary.shutdown(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.dictionary.shutdown(AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.dictionary = null;
}
}
Expand Down
8 changes: 5 additions & 3 deletions toolkit/components/extensions/LegacyExtensionsUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var EXPORTED_SYMBOLS = ["LegacyExtensionsUtils"];
* and exchange messages with the embedded WebExtension.
*/

ChromeUtils.defineModuleGetter(this, "AddonManagerPrivate",
"resource://gre/modules/AddonManager.jsm");
ChromeUtils.defineModuleGetter(this, "Extension",
"resource://gre/modules/Extension.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionChild",
Expand Down Expand Up @@ -188,9 +190,9 @@ class EmbeddedExtension {

this.extension.on("startup", onBeforeStarted);

// Run ambedded extension startup and catch any error during embedded extension
// Run embedded extension startup and catch any error during embedded extension
// startup.
this.extension.startup(reason).catch((err) => {
this.extension.startup(AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]).catch((err) => {
this.started = false;
this.startupPromise = null;
this.extension.off("startup", onBeforeStarted);
Expand All @@ -217,7 +219,7 @@ class EmbeddedExtension {
let {extension} = this;
this.extension = null;

await extension.shutdown(reason);
await extension.shutdown(AddonManagerPrivate.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
}
return undefined;
}
Expand Down
19 changes: 18 additions & 1 deletion toolkit/mozapps/extensions/AddonManager.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -2803,6 +2803,20 @@ var AddonManagerInternal = {
},
};

XPCOMUtils.defineLazyGetter(AddonManagerInternal, "BOOTSTRAP_REASON_TO_STRING_MAP", () => {
const {BOOTSTRAP_REASONS} = AddonManagerPrivate;
return Object.freeze({
[BOOTSTRAP_REASONS.APP_STARTUP]: "APP_STARTUP",
[BOOTSTRAP_REASONS.APP_SHUTDOWN]: "APP_SHUTDOWN",
[BOOTSTRAP_REASONS.ADDON_ENABLE]: "ADDON_ENABLE",
[BOOTSTRAP_REASONS.ADDON_DISABLE]: "ADDON_DISABLE",
[BOOTSTRAP_REASONS.ADDON_INSTALL]: "ADDON_INSTALL",
[BOOTSTRAP_REASONS.ADDON_UNINSTALL]: "ADDON_UNINSTALL",
[BOOTSTRAP_REASONS.ADDON_UPGRADE]: "ADDON_UPGRADE",
[BOOTSTRAP_REASONS.ADDON_DOWNGRADE]: "ADDON_DOWNGRADE",
});
});

/**
* Should not be used outside of core Mozilla code. This is a private API for
* the startup and platform integration code to use. Refer to the methods on
Expand Down Expand Up @@ -2897,6 +2911,10 @@ var AddonManagerPrivate = {
.BOOTSTRAP_REASONS;
},

get BOOTSTRAP_REASON_TO_STRING_MAP() {
return AddonManagerInternal.BOOTSTRAP_REASON_TO_STRING_MAP;
},

recordTimestamp(name, value) {
AddonManagerInternal.recordTimestamp(name, value);
},
Expand Down Expand Up @@ -3503,6 +3521,5 @@ this.AddonManager.init();

// load the timestamps module into AddonManagerInternal
ChromeUtils.import("resource://gre/modules/TelemetryTimestamps.jsm", AddonManagerInternal);
Object.freeze(AddonManagerInternal);
Object.freeze(AddonManagerPrivate);
Object.freeze(AddonManager);

0 comments on commit 956bb2d

Please sign in to comment.