Bug 1356828: Don't call getAddonById from the Pocket bootstrap scope. r=rhelmer

MozReview-Commit-ID: DJM1dOIA7X4

--HG--
extra : source : c39985abd71ceaa90fef9c438cc7627667d2e024
extra : amend_source : 26f1aa9c2d2d7604b056ca88a1071ff5fb490dd8
This commit is contained in:
Kris Maglione 2017-04-15 16:23:54 -07:00
parent 7ec8783134
commit b91438bf36
4 changed files with 40 additions and 17 deletions

View File

@ -16,7 +16,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
"resource:///modules/RecentWindow.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
"resource:///modules/CustomizableUI.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
"resource://gre/modules/AddonManager.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode",
"resource://gre/modules/ReaderMode.jsm");
@ -477,21 +477,20 @@ function prefObserver(aSubject, aTopic, aData) {
}
function startup(data, reason) {
AddonManager.getAddonByID("isreaditlater@ideashower.com", addon => {
if (addon && addon.isActive)
return;
setDefaultPrefs();
// migrate enabled pref
if (Services.prefs.prefHasUserValue("browser.pocket.enabled")) {
Services.prefs.setBoolPref("extensions.pocket.enabled", Services.prefs.getBoolPref("browser.pocket.enabled"));
Services.prefs.clearUserPref("browser.pocket.enabled");
}
// watch pref change and enable/disable if necessary
Services.prefs.addObserver("extensions.pocket.enabled", prefObserver);
if (!Services.prefs.getBoolPref("extensions.pocket.enabled"))
return;
PocketOverlay.startup(reason);
});
if (AddonManagerPrivate.addonIsActive("isreaditlater@ideashower.com"))
return;
setDefaultPrefs();
// migrate enabled pref
if (Services.prefs.prefHasUserValue("browser.pocket.enabled")) {
Services.prefs.setBoolPref("extensions.pocket.enabled", Services.prefs.getBoolPref("browser.pocket.enabled"));
Services.prefs.clearUserPref("browser.pocket.enabled");
}
// watch pref change and enable/disable if necessary
Services.prefs.addObserver("extensions.pocket.enabled", prefObserver);
if (!Services.prefs.getBoolPref("extensions.pocket.enabled"))
return;
PocketOverlay.startup(reason);
}
function shutdown(data, reason) {

View File

@ -3081,6 +3081,11 @@ this.AddonManagerPrivate = {
AddonManagerInternal.startup();
},
addonIsActive(addonId) {
return AddonManagerInternal._getProviderByName("XPIProvider")
.addonIsActive(addonId);
},
get browserUpdated() {
return gBrowserUpdated;
},

View File

@ -2467,6 +2467,8 @@ this.XPIStates = {
},
};
const hasOwnProperty = Function.call.bind({}.hasOwnProperty);
this.XPIProvider = {
get name() {
return "XPIProvider";
@ -2515,6 +2517,23 @@ this.XPIProvider = {
// Have we started shutting down bootstrap add-ons?
_closing: false,
/**
* Returns true if the add-on with the given ID is currently active,
* without forcing the add-ons database to load.
*
* @param {string} addonId
* The ID of the add-on to check.
* @returns {boolean}
*/
addonIsActive(addonId) {
if (hasOwnProperty(this.bootstrappedAddons, addonId)) {
return true;
}
let [, state] = XPIStates.findAddon(addonId);
return state && state.enabled;
},
/**
* Returns an array of the add-on values in `bootstrappedAddons`,
* sorted so that all of an add-on's dependencies appear in the array

View File

@ -16,7 +16,7 @@ const IGNORE = ["getPreferredIconURL", "escapeAddonURI",
const IGNORE_PRIVATE = ["AddonAuthor", "AddonCompatibilityOverride",
"AddonScreenshot", "AddonType", "startup", "shutdown",
"registerProvider", "unregisterProvider",
"addonIsActive", "registerProvider", "unregisterProvider",
"addStartupChange", "removeStartupChange",
"recordTimestamp", "recordSimpleMeasure",
"recordException", "getSimpleMeasures", "simpleTimer",