Bug 1435862 - Default search mitigation. r=florian
authorMichael Kaply <mozilla@kaply.com>
Mon, 05 Mar 2018 08:47:32 -0600
changeset 461600 740b5c4f4cd3e7112a754d9326a2a0cd25908242
parent 461562 7de2bea66b04c4b7a784e48010299d925b71f203
child 461601 f26ab4fb6ab185c7223eabe96606a51c33ec8453
child 461612 0ef34a9ec4fbfccd03ee0cfb26b182c03e28133a
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1435862
milestone60.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 1435862 - Default search mitigation. r=florian
browser/components/nsBrowserGlue.js
extensions/pref/autoconfig/src/nsReadConfig.cpp
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2312,16 +2312,44 @@ BrowserGlue.prototype = {
                       "TabsToolbar", "toolbar-menubar"];
       for (let resourceName of ["mode", "iconsize"]) {
         for (let toolbarId of toolbars) {
           xulStore.removeValue(BROWSER_DOCURL, toolbarId, resourceName);
         }
       }
     }
 
+    if (currentUIVersion < 63 &&
+        Services.prefs.getCharPref("general.config.filename", "") == "dsengine.cfg") {
+      let searchInitializedPromise = new Promise(resolve => {
+        if (Services.search.isInitialized) {
+          resolve();
+        }
+        const SEARCH_SERVICE_TOPIC = "browser-search-service";
+        Services.obs.addObserver(function observer(subject, topic, data) {
+          if (data != "init-complete") {
+            return;
+          }
+          Services.obs.removeObserver(observer, SEARCH_SERVICE_TOPIC);
+          resolve();
+        }, SEARCH_SERVICE_TOPIC);
+      });
+      searchInitializedPromise.then(() => {
+        let engineNames = ["Bing Search Engine",
+                           "Yahoo Search Engine",
+                           "Yandex Search Engine"];
+        for (let engineName of engineNames) {
+          let engine = Services.search.getEngineByName(engineName);
+          if (engine) {
+            Services.search.removeEngine(engine);
+          }
+        }
+      });
+    }
+
     if (currentUIVersion < 64) {
       OS.File.remove(OS.Path.join(OS.Constants.Path.profileDir,
                                   "directoryLinks.json"), {ignoreAbsent: true});
     }
 
     // Update the migration version.
     Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
   },
--- a/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -106,16 +106,22 @@ NS_IMETHODIMP nsReadConfig::Observe(nsIS
                 do_GetService(NS_APPSTARTUP_CONTRACTID);
             if (appStartup)
                 appStartup->Quit(nsIAppStartup::eAttemptQuit);
         }
     }
     return rv;
 }
 
+/**
+ * This is the blocklist for known bad autoconfig files.
+ */
+static const char *gBlockedConfigs[] = {
+  "dsengine.cfg"
+};
 
 nsresult nsReadConfig::readConfigFile()
 {
     nsresult rv = NS_OK;
     nsAutoCString lockFileName;
     nsAutoCString lockVendor;
     uint32_t fileNameLen = 0;
 
@@ -130,21 +136,28 @@ nsresult nsReadConfig::readConfigFile()
         return rv;
 
     // This preference is set in the all.js or all-ns.js (depending whether
     // running mozilla or netscp6)
 
     rv = defaultPrefBranch->GetCharPref("general.config.filename",
                                         lockFileName);
 
-
     MOZ_LOG(MCD, LogLevel::Debug, ("general.config.filename = %s\n", lockFileName.get()));
     if (NS_FAILED(rv))
         return rv;
 
+    for (size_t index = 0, len = mozilla::ArrayLength(gBlockedConfigs); index < len;
+         ++index) {
+      if (lockFileName == gBlockedConfigs[index]) {
+        // This is NS_OK because we don't want to show an error to the user
+        return rv;
+      }
+    }
+
     // This needs to be read only once.
     //
     if (!mRead) {
         // Initiate the new JS Context for Preference management
 
         rv = CentralizedAdminPrefManagerInit();
         if (NS_FAILED(rv))
             return rv;