# HG changeset patch
# User Bill Gianopoulos <wgianopoulos@gmail.com>
# Date 1615744683 14400
#      Sun Mar 14 13:58:03 2021 -0400
# Parent  ba518af476fa403dc80525761479b11cbdb0e0f1
Bug 1639866 - Part 2: Observe search service initialization after bug 1437942. r=frg a=frg

diff --git a/suite/components/search/content/search.xml b/suite/components/search/content/search.xml
--- a/suite/components/search/content/search.xml
+++ b/suite/components/search/content/search.xml
@@ -74,25 +74,27 @@
       <constructor><![CDATA[
         if (this.parentNode.parentNode.localName == "toolbarpaletteitem")
           return;
 
         if (this.usePrivateBrowsing)
           this._textbox.searchParam += "|private";
 
         Services.obs.addObserver(this, "browser-search-engine-modified");
+        Services.obs.addObserver(this, "browser-search-service");
         this._initialized = true;
 
         Services.search.init(this);
       ]]></constructor>
 
       <destructor><![CDATA[
         if (this._initialized) {
           this._initialized = false;
           Services.obs.removeObserver(this, "browser-search-engine-modified");
+          Services.obs.removeObserver(this, "browser-search-service");
         }
 
         // 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)
@@ -191,17 +193,18 @@
         ]]></body>
       </method>
 
       <method name="observe">
         <parameter name="aEngine"/>
         <parameter name="aTopic"/>
         <parameter name="aVerb"/>
         <body><![CDATA[
-          if (aTopic == "browser-search-engine-modified") {
+          if (aTopic == "browser-search-engine-modified" ||
+             (aTopic == "browser-search-service" && aVerb == "init-complete")) {
             switch (aVerb) {
             case "engine-removed":
               this.offerNewEngine(aEngine);
               break;
             case "engine-added":
               this.hideNewEngine(aEngine);
               break;
             case "engine-current":
