Backed out changeset c49af70f1a94 (bug 1378882) for eslint failures in ext-chrome-settings-overrides.js a=backout CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Tue, 18 Jul 2017 22:44:06 -0700
changeset 418254 51aaede1a000fbf0e2914f3e2f572089a758e36a
parent 418253 1aa1c1bd2a658856e1a906e789f9d771730e1070
child 418255 fdce816e6cc663aa94b7b90b5495c8b4b6696947
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)
reviewersbackout
bugs1378882
milestone56.0a1
backs outc49af70f1a94750f90cc5259916a5955e97b512c
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
Backed out changeset c49af70f1a94 (bug 1378882) for eslint failures in ext-chrome-settings-overrides.js a=backout CLOSED TREE MozReview-Commit-ID: DAuBI2jFzG3
browser/components/extensions/ext-chrome-settings-overrides.js
browser/components/extensions/schemas/chrome_settings_overrides.json
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_settings_overrides_default_search.js
--- a/browser/components/extensions/ext-chrome-settings-overrides.js
+++ b/browser/components/extensions/ext-chrome-settings-overrides.js
@@ -1,38 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-const {Management} = Cu.import("resource://gre/modules/Extension.jsm", {});
-
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionPreferencesManager",
                                   "resource://gre/modules/ExtensionPreferencesManager.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "ExtensionSettingsStore",
-                                  "resource://gre/modules/ExtensionSettingsStore.jsm");
-
-const LOCAL_STORE_TYPE = "dynamic_values";
-const DEFAULT_SEARCH_SETTING_NAME = "defaultSearch";
-
-const processDefaultSearchSetting = (extension, action) => {
-  let item = ExtensionSettingsStore[action](extension, LOCAL_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME);
-  if (["disable", "removeSetting"].includes(action) && item) {
-    try {
-      let engine = Services.search.getEngineByName(item.value || item.initialValue);
-      if (engine && Services.search.getDefaultEngines().includes(engine)) {
-        Services.search.currentEngine = engine;
-      }
-    } catch (e) {
-      Components.utils.reportError(e);
-    }
-  }
-};
 
 const searchInitialized = () => {
   return new Promise(resolve => {
     if (Services.search.isInitialized) {
       resolve();
     }
     const SEARCH_SERVICE_TOPIC = "browser-search-service";
     Services.obs.addObserver(function observer(subject, topic, data) {
@@ -41,113 +19,59 @@ const searchInitialized = () => {
       }
 
       Services.obs.removeObserver(observer, SEARCH_SERVICE_TOPIC);
       resolve();
     }, SEARCH_SERVICE_TOPIC);
   });
 };
 
-/* eslint-disable mozilla/balanced-listeners */
-Management.on("shutdown", async (type, extension) => {
-  switch (extension.shutdownReason) {
-    case "ADDON_DISABLE":
-    case "ADDON_DOWNGRADE":
-    case "ADDON_UPGRADE":
-      await searchInitialized();
-      processDefaultSearchSetting(extension, "disable");
-      break;
-
-    case "ADDON_UNINSTALL":
-      await searchInitialized();
-      processDefaultSearchSetting(extension, "removeSetting");
-      break;
-  }
-});
-
-Management.on("startup", async (type, extension) => {
-  if (["ADDON_ENABLE", "ADDON_UPGRADE", "ADDON_DOWNGRADE"].includes(extension.startupReason)) {
-    await searchInitialized();
-    processDefaultSearchSetting(extension, "enable");
-  }
-});
-/* eslint-enable mozilla/balanced-listeners */
-
 this.chrome_settings_overrides = class extends ExtensionAPI {
   async onManifestEntry(entryName) {
     let {extension} = this;
     let {manifest} = extension;
 
     if (manifest.chrome_settings_overrides.homepage) {
       ExtensionPreferencesManager.setSetting(extension, "homepage_override",
                                              manifest.chrome_settings_overrides.homepage);
     }
     if (manifest.chrome_settings_overrides.search_provider) {
-      let setDefault = false;
       await searchInitialized();
       let searchProvider = manifest.chrome_settings_overrides.search_provider;
-      if (searchProvider.is_default) {
-        let engineName = searchProvider.name.trim();
-        let engine = Services.search.getEngineByName(engineName);
-        if (engine && Services.search.getDefaultEngines().includes(engine)) {
-          await ExtensionSettingsStore.addSetting(
-            extension, LOCAL_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME, engineName, () => {
-              return Services.search.currentEngine.name;
-            });
-          setDefault = true;
-        } else {
-          Components.utils.reportError("is_default can only be used for built-in engines.")
+      let isCurrent = false;
+      let index = -1;
+      if (extension.startupReason === "ADDON_UPGRADE") {
+        let engines = Services.search.getEnginesByExtensionID(extension.id);
+        if (engines.length > 0) {
+          // There can be only one engine right now
+          isCurrent = Services.search.currentEngine == engines[0];
+          // Get position of engine and store it
+          index = Services.search.getEngines().indexOf(engines[0]);
+          Services.search.removeEngine(engines[0]);
         }
-      // If the setting exists for the extension, but is missing from the manifest,
-      // remove it
-      } else if (ExtensionSettingsStore.hasSetting(
-                 extension, LOCAL_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME)) {
-        await searchInitialized();
-        processDefaultSearchSetting(extension, "removeSetting");
       }
-      // We only process the rest of search_provider if we did not set
-      // the default engine
-      if (!setDefault) {
-        let isCurrent = false;
-        let index = -1;
+      try {
+        Services.search.addEngineWithDetails(searchProvider.name.trim(),
+                                             searchProvider.favicon_url,
+                                             searchProvider.keyword, null,
+                                             "GET", searchProvider.search_url,
+                                             extension.id);
         if (extension.startupReason === "ADDON_UPGRADE") {
-          let engines = Services.search.getEnginesByExtensionID(extension.id);
-          if (engines.length > 0) {
-            // There can be only one engine right now
-            isCurrent = Services.search.currentEngine == engines[0];
-            // Get position of engine and store it
-            index = Services.search.getEngines().indexOf(engines[0]);
-            Services.search.removeEngine(engines[0]);
+          let engine = Services.search.getEngineByName(searchProvider.name.trim());
+          if (isCurrent) {
+            Services.search.currentEngine = engine;
+          }
+          if (index != -1) {
+            Services.search.moveEngine(engine, index);
           }
         }
-        try {
-          Services.search.addEngineWithDetails(searchProvider.name.trim(),
-                                               searchProvider.favicon_url,
-                                               searchProvider.keyword, null,
-                                               "GET", searchProvider.search_url,
-                                               extension.id);
-          if (extension.startupReason === "ADDON_UPGRADE") {
-            let engine = Services.search.getEngineByName(searchProvider.name.trim());
-            if (isCurrent) {
-              Services.search.currentEngine = engine;
-            }
-            if (index != -1) {
-              Services.search.moveEngine(engine, index);
-            }
-          }
-        } catch (e) {
-          Components.utils.reportError(e);
-        }
+      } catch (e) {
+        Components.utils.reportError(e);
       }
     }
-    let item = ExtensionSettingsStore.getSetting(LOCAL_STORE_TYPE, DEFAULT_SEARCH_SETTING_NAME);
-    if (item) {
-      await searchInitialized();
-      Services.search.currentEngine = Services.search.getEngineByName(item.value || item.initialValue);
-    }
   }
   async onShutdown(reason) {
     let {extension} = this;
     if (reason == "ADDON_DISABLE" ||
         reason == "ADDON_UNINSTALL") {
       if (extension.manifest.chrome_settings_overrides.search_provider) {
         await searchInitialized();
         let engines = Services.search.getEnginesByExtensionID(extension.id);
--- a/browser/components/extensions/schemas/chrome_settings_overrides.json
+++ b/browser/components/extensions/schemas/chrome_settings_overrides.json
@@ -94,17 +94,17 @@
                   "prepopulated_id": {
                     "type": "integer",
                     "optional": true,
                     "deprecated": "Unsupported on Firefox."
                   },
                   "is_default": {
                     "type": "boolean",
                     "optional": true,
-                    "description": "Sets the default engine to a built-in engine only."
+                    "deprecated": "Unsupported on Firefox at this time."
                   }
                 }
               }
             }
           }
         }
       }
     ]
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -96,17 +96,16 @@ skip-if = debug || asan # Bug 1354681
 [browser_ext_runtime_openOptionsPage_uninstall.js]
 [browser_ext_runtime_setUninstallURL.js]
 [browser_ext_sessions_forgetClosedTab.js]
 [browser_ext_sessions_forgetClosedWindow.js]
 [browser_ext_sessions_getRecentlyClosed.js]
 [browser_ext_sessions_getRecentlyClosed_private.js]
 [browser_ext_sessions_getRecentlyClosed_tabs.js]
 [browser_ext_sessions_restore.js]
-[browser_ext_settings_overrides_default_search.js]
 [browser_ext_settings_overrides_search.js]
 [browser_ext_sidebarAction.js]
 [browser_ext_sidebarAction_browser_style.js]
 [browser_ext_sidebarAction_context.js]
 [browser_ext_sidebarAction_contextMenu.js]
 [browser_ext_sidebarAction_tabs.js]
 [browser_ext_sidebarAction_windows.js]
 [browser_ext_simple.js]
deleted file mode 100644
--- a/browser/components/extensions/test/browser/browser_ext_settings_overrides_default_search.js
+++ /dev/null
@@ -1,147 +0,0 @@
-/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set sts=2 sw=2 et tw=80: */
-
-"use strict";
-
-add_task(async function test_extension_setting_default_engine() {
-  let defaultEngineName = Services.search.currentEngine.name;
-
-  let ext1 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "DuckDuckGo",
-          "search_url": "https://example.com/?q={searchTerms}",
-          "is_default": true,
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  await ext1.startup();
-
-  is(Services.search.currentEngine.name, "DuckDuckGo", "Default engine should be DuckDuckGo");
-
-  await ext1.unload();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-});
-
-add_task(async function test_extension_setting_invalid_name_default_engine() {
-  let defaultEngineName = Services.search.currentEngine.name;
-
-  let ext1 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "InvalidName",
-          "search_url": "https://example.com/?q={searchTerms}",
-          "is_default": true,
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  await ext1.startup();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-
-  await ext1.unload();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-});
-
-add_task(async function test_extension_setting_multiple_default_engine() {
-  let defaultEngineName = Services.search.currentEngine.name;
-  let ext1 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "DuckDuckGo",
-          "search_url": "https://example.com/?q={searchTerms}",
-          "is_default": true,
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  let ext2 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "Twitter",
-          "search_url": "https://example.com/?q={searchTerms}",
-          "is_default": true,
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  await ext1.startup();
-
-  is(Services.search.currentEngine.name, "DuckDuckGo", "Default engine should be DuckDuckGo");
-
-  await ext2.startup();
-
-  is(Services.search.currentEngine.name, "Twitter", "Default engine should be Twitter");
-
-  await ext2.unload();
-
-  is(Services.search.currentEngine.name, "DuckDuckGo", "Default engine should be DuckDuckGo");
-
-  await ext1.unload();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-});
-
-add_task(async function test_extension_setting_invalid_default_engine() {
-  let defaultEngineName = Services.search.currentEngine.name;
-  let ext1 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "MozSearch",
-          "keyword": "MozSearch",
-          "search_url": "https://example.com/?q={searchTerms}",
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  let ext2 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      "chrome_settings_overrides": {
-        "search_provider": {
-          "name": "MozSearch",
-          "search_url": "https://example.com/?q={searchTerms}",
-          "is_default": true,
-        },
-      },
-    },
-    useAddonManager: "temporary",
-  });
-
-  await ext1.startup();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-
-  let engine = Services.search.getEngineByName("MozSearch");
-  ok(engine, "Engine should exist.");
-
-  await ext2.startup();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-
-  await ext2.unload();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-
-  await ext1.unload();
-
-  is(Services.search.currentEngine.name, defaultEngineName, "Default engine should be " + defaultEngineName);
-});