Bug 1544273 - Ensure WebExtensionPolicy has started. r=aswan,Standard8
authorDale Harvey <dale@arandomurl.com>
Wed, 15 May 2019 14:00:14 +0000
changeset 532766 2cd499a2a7d92aa352bd6e51c58e3c74535fbab5
parent 532765 69c5ef5e60352efbfb03e562eb77c9f30ac32690
child 532767 6c6307b33331b070584d259ddefdc5439d56d759
push id11272
push userapavel@mozilla.com
push dateThu, 16 May 2019 15:28:22 +0000
treeherdermozilla-beta@2265bfc5920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, Standard8
bugs1544273
milestone68.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 1544273 - Ensure WebExtensionPolicy has started. r=aswan,Standard8 Differential Revision: https://phabricator.services.mozilla.com/D30651
toolkit/components/search/SearchService.jsm
--- a/toolkit/components/search/SearchService.jsm
+++ b/toolkit/components/search/SearchService.jsm
@@ -19,16 +19,20 @@ XPCOMUtils.defineLazyModuleGetters(this,
   RemoteSettings: "resource://services-settings/remote-settings.js",
   SearchEngine: "resource://gre/modules/SearchEngine.jsm",
   SearchStaticData: "resource://gre/modules/SearchStaticData.jsm",
   SearchUtils: "resource://gre/modules/SearchUtils.jsm",
   Services: "resource://gre/modules/Services.jsm",
   setTimeout: "resource://gre/modules/Timer.jsm",
 });
 
+XPCOMUtils.defineLazyServiceGetters(this, {
+  gEnvironment: ["@mozilla.org/process/environment;1", "nsIEnvironment"],
+});
+
 XPCOMUtils.defineLazyPreferenceGetter(this, "gGeoSpecificDefaultsEnabled",
   SearchUtils.BROWSER_SEARCH_PREF + "geoSpecificDefaults", false);
 
 // Can't use defineLazyPreferenceGetter because we want the value
 // from the default branch
 XPCOMUtils.defineLazyGetter(this, "distroID", () => {
   return Services.prefs.getDefaultBranch("distribution.").getCharPref("id", "");
 });
@@ -843,16 +847,17 @@ SearchService.prototype = {
    *
    * @returns {Promise} A promise, resolved successfully if loading data
    * succeeds.
    */
   async _loadEngines(cache, isReload) {
     SearchUtils.log("_loadEngines: start");
     Services.obs.notifyObservers(null, SearchUtils.TOPIC_SEARCH_SERVICE, "find-jar-engines");
     let engines = await this._findEngines();
+    SearchUtils.log("_loadEngines: loading - " + engines.join(","));
 
     // Get the non-empty distribution directories into distDirs...
     let distDirs = [];
     let locations;
     try {
       locations = Services.dirsvc.get(NS_APP_DISTRIBUTION_SEARCH_DIR_LIST,
                                       Ci.nsISimpleEnumerator);
     } catch (e) {
@@ -894,23 +899,26 @@ SearchService.prototype = {
       return [name, locale];
     }
 
     function extensionId(name) {
       return name + "@" + EXT_SIGNING_ADDRESS;
     }
 
     let buildID = Services.appinfo.platformBuildID;
-    let rebuildCache = !cache.engines ||
+    let rebuildCache = gEnvironment.get("RELOAD_ENGINES") ||
+                       !cache.engines ||
                        cache.version != CACHE_VERSION ||
                        cache.locale != Services.locale.requestedLocale ||
                        cache.buildID != buildID ||
                        cache.visibleDefaultEngines.length != this._visibleDefaultEngines.length ||
                        this._visibleDefaultEngines.some(notInCacheVisibleEngines);
 
+    await WebExtensionPolicy.readyPromise;
+
     // If we are reiniting, delete previously installed built in
     // extensions that arent in the current engine list.
     for (let id of this._extensions.keys()) {
       let policy = WebExtensionPolicy.getByID(id);
       if (!policy) {
         // If we are reiniting due to a remote settings update, we may have
         // removed all the engines and be rebuilding without the cache. In this
         // case, we won't have the cached engines loaded, so just skip this check.
@@ -966,21 +974,26 @@ SearchService.prototype = {
           // but if there wasnt an valid cache, mark as installing.
           for (let [locale, installed] of localeMap) {
             if (installed === true) {
               localeMap.set(locale, null);
             }
           }
           this._extensions.set(id, localeMap);
           let path = EXT_SEARCH_PREFIX + id.split("@")[0] + "/";
-          await AddonManager.installBuiltinAddon(path);
-          // The AddonManager will install the engine asynchronously
-          // We can manually wait on that happening here.
-          await ExtensionParent.apiManager.global.pendingSearchSetupTasks.get(id);
-          SearchUtils.log("_loadEngines: " + id + " installed");
+          try {
+            await AddonManager.installBuiltinAddon(path);
+            // The AddonManager will install the engine asynchronously
+            // We can manually wait on that happening here.
+            await ExtensionParent.apiManager.global.pendingSearchSetupTasks.get(id);
+            SearchUtils.log("_loadEngines: " + id + " installed");
+          } catch (err) {
+            this._extensions.delete(id);
+            Cu.reportError("Failed to install engine: " + err.message + "\n" + err.stack);
+          }
         }
       }
     }
 
     SearchUtils.log("_loadEngines: loading user-installed engines from the obsolete cache");
     this._loadEnginesFromCache(cache, true);
 
     this._loadEnginesMetadataFromCache(cache);
@@ -1810,16 +1823,17 @@ SearchService.prototype = {
       if (engine && (engine.alias == alias || engine._internalAliases.includes(alias))) {
         return engine;
       }
     }
     return null;
   },
 
   async addEngineWithDetails(name, iconURL, alias, description, method, template, extensionID) {
+    SearchUtils.log("addEngineWithDetails: Adding \"" + template + "\".");
     let isCurrent = false;
     var params;
 
     if (iconURL && typeof iconURL == "object") {
       params = iconURL;
     } else {
       params = {
         iconURL,