Bug 1633143 - Update urlbarBindings for Services and Observers - search init part. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sat, 25 Apr 2020 12:28:47 +0100
changeset 39185 de42d117bf8a486580ba0751cc30742f13cf7b74
parent 39184 b667fd22d4fb74638671e3ff427e2a9f574fb978
child 39186 e43591416144c5fe8f963768a867e8c7fdc8e446
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersfrg
bugs1633143
Bug 1633143 - Update urlbarBindings for Services and Observers - search init part. r=frg
suite/browser/urlbarBindings.xml
--- a/suite/browser/urlbarBindings.xml
+++ b/suite/browser/urlbarBindings.xml
@@ -342,29 +342,33 @@
           <xul:treecol class="autocomplete-treecol" id="treecolAutoCompleteValue" flex="2"/>
           <xul:treecol class="autocomplete-treecol" id="treecolAutoCompleteComment" flex="1" hidden="true"/>
         </xul:treecols>
         <xul:treechildren anonid="treebody" class="autocomplete-treebody" flex="1"/>
       </xul:tree>
       <xul:box role="search-box" class="autocomplete-search-box"/>
     </content>
 
-    <implementation implements="nsIObserver">
+    <implementation implements="nsIObserver, nsIBrowserSearchInitObserver">
       <constructor><![CDATA[
         // listen for changes to default search engine
         Services.prefs.addObserver("browser.search", this);
         Services.prefs.addObserver("browser.urlbar", this);
         Services.obs.addObserver(this, "browser-search-engine-modified");
-        this.updateEngines();
+        this._initialized = true;
+        Services.search.init(this);
       ]]></constructor>
 
       <destructor><![CDATA[
         Services.prefs.removeObserver("browser.search", this);
         Services.prefs.removeObserver("browser.urlbar", this);
-        Services.obs.removeObserver(this, "browser-search-engine-modified");
+        if (this._initialized) {
+          this._initialized = false;
+          Services.obs.removeObserver(this, "browser-search-engine-modified");
+        }
       ]]></destructor>
 
       <property name="showSearch" onget="return this.mShowSearch;">
         <setter><![CDATA[
           this.mShowSearch = val;
           if (val) {
             this.updateEngines();
             this.mSearchBox.removeAttribute("hidden");
@@ -394,16 +398,17 @@
 
       <field name="mInputTimeout"><![CDATA[
         (function(me) {
           me.popup.mSearchBox.searchValue = me.value;
           me.mSearchInputTO = 0;
         });
       ]]></field>
 
+      <field name="_initialized">false</field>
       <field name="mEnginesReady">false</field>
 
       <property name="overrideValue" readonly="true">
         <getter><![CDATA[
           if (this.mSearchBox.selectedIndex != -1) {
             return this.mSearchBox.overrideValue;
           }
           return null;
@@ -418,31 +423,45 @@
           switch (aTopic) {
             case "browser-search-engine-modified":
               if (aData == "engine-current") {
                 this.updateEngines();
               }
               break;
             case "nsPref:changed":
               if (/^browser\.search\./.test(aData))
-                this.updateEngines();
+                Services.search.init(this);
               else if (aData == "browser.urlbar.showSearch")
                 this.updateShowSearch();
               break;
             default:
           }
         ]]></body>
       </method>
 
       <method name="updateShowSearch">
         <body><![CDATA[
           this.showSearch = Services.prefs.getBoolPref("browser.urlbar.showSearch");
         ]]></body>
       </method>
 
+      <method name="onInitComplete">
+        <parameter name="aStatus"/>
+        <body><![CDATA[
+          if (!this._initialized)
+            return;
+          if (Components.isSuccessCode(aStatus)) {
+            // Refresh the engines.
+            this.updateEngines();
+          } else {
+            Cu.reportError("Cannot initialize search service, bailing out: " + aStatus);
+          }
+        ]]></body>
+      </method>
+
       <method name="addEngine">
         <parameter name="aName"/>
         <parameter name="aIcon"/>
         <parameter name="aSearchBarUrl"/>
         <body><![CDATA[
           var box = document.createElement("box");
           box.setAttribute("class", "autocomplete-search-engine");
           box.setAttribute("name", aName);