Bug 1381573 - Use callOnClose instead of onShutdown in ext-url-overrides.js, r=aswan
authorBob Silverberg <bsilverberg@mozilla.com>
Mon, 17 Jul 2017 14:01:04 -0400
changeset 419508 5227744e2508312d6c92f122efc9d171c58c07bb
parent 419507 44260a3e2218dc95c04eda70e9fb3c2e60a034b9
child 419509 23c6326dd926bb60c59c684b6c6304e2cb8af035
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1381573
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1381573 - Use callOnClose instead of onShutdown in ext-url-overrides.js, r=aswan Also replace onStartup with onManifestEntry MozReview-Commit-ID: GMrdzjvXZe5
browser/components/extensions/ext-browser.js
browser/components/extensions/ext-url-overrides.js
--- a/browser/components/extensions/ext-browser.js
+++ b/browser/components/extensions/ext-browser.js
@@ -218,17 +218,16 @@ extensions.registerModules({
     paths: [
       ["tabs"],
     ],
   },
   urlOverrides: {
     url: "chrome://browser/content/ext-url-overrides.js",
     schema: "chrome://browser/content/schemas/url_overrides.json",
     scopes: ["addon_parent"],
-    events: ["startup"],
     manifest: ["chrome_url_overrides"],
     paths: [
       ["urlOverrides"],
     ],
   },
   windows: {
     url: "chrome://browser/content/ext-windows.js",
     schema: "chrome://browser/content/schemas/windows.json",
--- a/browser/components/extensions/ext-url-overrides.js
+++ b/browser/components/extensions/ext-url-overrides.js
@@ -18,22 +18,41 @@ this.urlOverrides = class extends Extens
   processNewTabSetting(action) {
     let {extension} = this;
     let item = ExtensionSettingsStore[action](extension, STORE_TYPE, NEW_TAB_SETTING_NAME);
     if (item) {
       aboutNewTabService.newTabURL = item.value || item.initialValue;
     }
   }
 
-  async onStartup() {
+  async onManifestEntry(entryName) {
     let {extension} = this;
     let {manifest} = extension;
 
-    // Record the setting if it exists in the manifest.
-    if (manifest.chrome_url_overrides && manifest.chrome_url_overrides.newtab) {
+    if (manifest.chrome_url_overrides.newtab) {
+      // Set up the shutdown code for the setting.
+      extension.callOnClose({
+        close: () => {
+          switch (extension.shutdownReason) {
+            case "ADDON_DISABLE":
+              this.processNewTabSetting("disable");
+              break;
+
+            // We can remove the setting on upgrade or downgrade because it will be
+            // added back in when the manifest is re-read. This will cover the case
+            // where a new version of an add-on removes the manifest key.
+            case "ADDON_DOWNGRADE":
+            case "ADDON_UPGRADE":
+            case "ADDON_UNINSTALL":
+              this.processNewTabSetting("removeSetting");
+              break;
+          }
+        },
+      });
+
       let url = extension.baseURI.resolve(manifest.chrome_url_overrides.newtab);
 
       let item = await ExtensionSettingsStore.addSetting(
         extension, STORE_TYPE, NEW_TAB_SETTING_NAME, url,
         () => aboutNewTabService.newTabURL);
 
       // If the extension was just re-enabled, change the setting to enabled.
       // This is required because addSetting above is used for both add and update.
@@ -41,30 +60,11 @@ this.urlOverrides = class extends Extens
           .includes(extension.startupReason)) {
         item = ExtensionSettingsStore.enable(extension, STORE_TYPE, NEW_TAB_SETTING_NAME);
       }
 
       // Set the newTabURL to the current value of the setting.
       if (item) {
         aboutNewTabService.newTabURL = item.value || item.initialValue;
       }
-    // If the setting exists for the extension, but is missing from the manifest,
-    // remove it.
-    } else if (ExtensionSettingsStore.hasSetting(
-               extension, STORE_TYPE, NEW_TAB_SETTING_NAME)) {
-      this.processNewTabSetting("removeSetting");
-    }
-  }
-
-  onShutdown(shutdownReason) {
-    switch (shutdownReason) {
-      case "ADDON_DISABLE":
-      case "ADDON_DOWNGRADE":
-      case "ADDON_UPGRADE":
-        this.processNewTabSetting("disable");
-        break;
-
-      case "ADDON_UNINSTALL":
-        this.processNewTabSetting("removeSetting");
-        break;
     }
   }
 };