Bug 1345583 - Move code for startup and shutdown handling of preferences to ExtensionPreferencesManager, r=aswan

MozReview-Commit-ID: 8EILFeFjvnd

--HG--
extra : rebase_source : e63dbff3bea99feba8b217f515c48dfb702c1f49
This commit is contained in:
Bob Silverberg 2017-03-08 14:47:26 -05:00
Родитель 70631ff92d
Коммит b59b137167
2 изменённых файлов: 23 добавлений и 22 удалений

Просмотреть файл

@ -22,6 +22,7 @@
this.EXPORTED_SYMBOLS = ["ExtensionPreferencesManager"];
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const {Management} = Cu.import("resource://gre/modules/Extension.jsm", {});
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@ -34,6 +35,28 @@ XPCOMUtils.defineLazyGetter(this, "defaultPreferences", function() {
return new Preferences({defaultBranch: true});
});
/* eslint-disable mozilla/balanced-listeners */
Management.on("shutdown", (type, extension) => {
switch (extension.shutdownReason) {
case "ADDON_DISABLE":
case "ADDON_DOWNGRADE":
case "ADDON_UPGRADE":
this.ExtensionPreferencesManager.disableAll(extension);
break;
case "ADDON_UNINSTALL":
this.ExtensionPreferencesManager.removeAll(extension);
break;
}
});
Management.on("startup", (type, extension) => {
if (["ADDON_ENABLE", "ADDON_UPGRADE", "ADDON_DOWNGRADE"].includes(extension.startupReason)) {
this.ExtensionPreferencesManager.enableAll(extension);
}
});
/* eslint-enable mozilla/balanced-listeners */
const STORE_TYPE = "prefs";
// Definitions of settings, each of which correspond to a different API.

Просмотреть файл

@ -13,28 +13,6 @@ const {
ExtensionError,
} = ExtensionUtils;
/* eslint-disable mozilla/balanced-listeners */
extensions.on("startup", async (type, extension) => {
if (["ADDON_ENABLE", "ADDON_UPGRADE", "ADDON_DOWNGRADE"].includes(extension.startupReason)) {
await ExtensionPreferencesManager.enableAll(extension);
}
});
extensions.on("shutdown", async (type, extension) => {
switch (extension.shutdownReason) {
case "ADDON_DISABLE":
case "ADDON_DOWNGRADE":
case "ADDON_UPGRADE":
await ExtensionPreferencesManager.disableAll(extension);
break;
case "ADDON_UNINSTALL":
await ExtensionPreferencesManager.removeAll(extension);
break;
}
});
/* eslint-enable mozilla/balanced-listeners */
function checkScope(scope) {
if (scope && scope !== "regular") {
throw new ExtensionError(