Bug 1493770 - Switch WebExt default search prompt away from promise. r=aswan
authorMichael Kaply <mozilla@kaply.com>
Fri, 18 Jan 2019 18:37:04 +0000
changeset 511573 6c39cc812c87cf6ac71f6af96b60b3754a636eee
parent 511572 2a3cb2c2431d84093ba8caae7444dd681c3a2c66
child 511574 0f73ecaf9f406f11d0a64a3194690aa67bc4bf60
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1493770
milestone66.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 1493770 - Switch WebExt default search prompt away from promise. r=aswan Differential Revision: https://phabricator.services.mozilla.com/D16263
browser/components/extensions/parent/ext-chrome-settings-overrides.js
--- a/browser/components/extensions/parent/ext-chrome-settings-overrides.js
+++ b/browser/components/extensions/parent/ext-chrome-settings-overrides.js
@@ -213,56 +213,56 @@ this.chrome_settings_overrides = class e
         }
       }
       await this.addSearchEngine();
       if (searchProvider.is_default) {
         if (extension.startupReason === "ADDON_INSTALL") {
           // Don't ask if it already the current engine
           let engine = Services.search.getEngineByName(engineName);
           if (Services.search.defaultEngine != engine) {
-            let allow = await new Promise(resolve => {
-              let subject = {
-                wrappedJSObject: {
-                  // This is a hack because we don't have the browser of
-                  // the actual install. This means the popup might show
-                  // in a different window. Will be addressed in a followup bug.
-                  browser: windowTracker.topWindow.gBrowser.selectedBrowser,
-                  name: this.extension.name,
-                  icon: this.extension.iconURL,
-                  currentEngine: Services.search.defaultEngine.name,
-                  newEngine: engineName,
-                  resolve,
+            let subject = {
+              wrappedJSObject: {
+                // This is a hack because we don't have the browser of
+                // the actual install. This means the popup might show
+                // in a different window. Will be addressed in a followup bug.
+                browser: windowTracker.topWindow.gBrowser.selectedBrowser,
+                name: this.extension.name,
+                icon: this.extension.iconURL,
+                currentEngine: Services.search.defaultEngine.name,
+                newEngine: engineName,
+                resolve(allow) {
+                  if (allow) {
+                    ExtensionSettingsStore.addSetting(
+                      extension.id, DEFAULT_SEARCH_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME, engineName, () => Services.search.defaultEngine.name);
+                    Services.search.defaultEngine = Services.search.getEngineByName(engineName);
+                  }
                 },
-              };
-              Services.obs.notifyObservers(subject, "webextension-defaultsearch-prompt");
-            });
-            if (!allow) {
-              return;
-            }
+              },
+            };
+            Services.obs.notifyObservers(subject, "webextension-defaultsearch-prompt");
           }
+        } else {
+          // Needs to be called every time to handle reenabling, but
+          // only sets default for install or enable.
+          this.setDefault(engineName);
         }
-        // Needs to be called every time to handle reenabling, but
-        // only sets default for install or enable.
-        await this.setDefault(engineName);
       } else if (ExtensionSettingsStore.hasSetting(extension.id,
                                                    DEFAULT_SEARCH_STORE_TYPE,
                                                    DEFAULT_SEARCH_SETTING_NAME)) {
         // is_default has been removed, but we still have a setting. Remove it.
         chrome_settings_overrides.processDefaultSearchSetting("removeSetting", extension.id);
       }
     }
   }
 
   async setDefault(engineName) {
     let {extension} = this;
     if (extension.startupReason === "ADDON_INSTALL") {
       let item = await ExtensionSettingsStore.addSetting(
-        extension.id, DEFAULT_SEARCH_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME, engineName, () => {
-          return Services.search.defaultEngine.name;
-        });
+        extension.id, DEFAULT_SEARCH_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME, engineName, () => Services.search.defaultEngine.name);
       Services.search.defaultEngine = Services.search.getEngineByName(item.value);
     } else if (extension.startupReason === "ADDON_ENABLE") {
       chrome_settings_overrides.processDefaultSearchSetting("enable", extension.id);
     }
   }
 
   async addSearchEngine() {
     let {extension} = this;