Bug 1584827 - Port some changes to search bar bindings to SeaMonkey. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 13 Oct 2019 13:29:49 +0200
changeset 37146 4f7c6fb76db0ea2a8e5194a2f211cd68edb9bc0e
parent 37145 de271481efc1a382c67e8bcbb18153167fd93950
child 37147 ed82c4b6b9ed998e7305547178506633414c214f
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersfrg
bugs1584827, 903274, 960864
Bug 1584827 - Port some changes to search bar bindings to SeaMonkey. r=frg Port |Bug 903274 - have the search bar binding's initialization callback bail out if the binding is destroyed| and |Bug 960864 - Implement the _initialized flag instead of _addedObserver and the half-broken _destroyed|
suite/components/search/content/search.xml
--- a/suite/components/search/content/search.xml
+++ b/suite/components/search/content/search.xml
@@ -73,25 +73,26 @@
     <implementation implements="nsIObserver, nsIBrowserSearchInitObserver, nsISearchInstallCallback">
       <constructor><![CDATA[
         if (this.parentNode.parentNode.localName == "toolbarpaletteitem")
           return;
 
         if (this.usePrivateBrowsing)
           this._textbox.searchParam += "|private";
 
+        Services.obs.addObserver(this, "browser-search-engine-modified");
+        this._initialized = true;
+
         this.searchService.init(this);
-        Services.obs.addObserver(this, "browser-search-engine-modified");
-        this._addedObserver = true;
       ]]></constructor>
 
       <destructor><![CDATA[
-        if (this._addedObserver) {
+        if (this._initialized) {
+          this._initialized = false;
           Services.obs.removeObserver(this, "browser-search-engine-modified");
-          this._addedObserver = false;
         }
 
         // Make sure to break the cycle from _textbox to us. Otherwise we leak
         // the world. But make sure it's actually pointing to us.
         // Also make sure the textbox has ever been constructed, otherwise the
         // _textbox getter will cause the textbox constructor to run, add an
         // observer, and leak the world too.
         if (this._textboxInitialized && this._textbox.mController.input == this)
@@ -112,17 +113,17 @@
           .getService(Ci.nsIBrowserSearchService);
       </field>
       <field name="usePrivateBrowsing" readonly="true">
         window.QueryInterface(Ci.nsIInterfaceRequestor)
               .getInterface(Ci.nsIWebNavigation)
               .QueryInterface(Ci.nsILoadContext)
               .usePrivateBrowsing
       </field>
-      <field name="_addedObserver">false</field>
+      <field name="_initialized">false</field>
       <field name="_engines">null</field>
       <field name="_needToBuildPopup">true</field>
       <field name="FormHistory" readonly="true"><![CDATA[
         (ChromeUtils.import("resource://gre/modules/FormHistory.jsm", {}))
                     .FormHistory;
         ]]>
       </field>
       <property name="engines" readonly="true">
@@ -169,16 +170,18 @@
         <body><![CDATA[
           this._textbox.select();
         ]]></body>
       </method>
 
       <method name="onInitComplete">
         <parameter name="aStatus"/>
         <body><![CDATA[
+          if (!this._initialized)
+            return;
           if (Components.isSuccessCode(aStatus)) {
             // Refresh the display (updating icon, etc)
             this.updateDisplay();
           } else {
             Cu.reportError("Cannot initialize search service, bailing out: " + aStatus);
           }
         ]]></body>
       </method>