Bug 1364002 - Store the user-made search suggestion choice along with userMadeSearchSuggestionChoice. r=past draft
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 11 May 2017 11:15:47 +0200
changeset 576408 a681cebc2ff2354502950a45828642f05f06f8b1
parent 576334 3b96f277325747fe668ca8cd896d2f581238e4ee
child 628202 e84a054754d16ca64a6bfb9c4e74682129731508
push id58367
push usermak77@bonardo.net
push dateThu, 11 May 2017 19:03:47 +0000
reviewerspast
bugs1364002
milestone55.0a1
Bug 1364002 - Store the user-made search suggestion choice along with userMadeSearchSuggestionChoice. r=past MozReview-Commit-ID: 46vXbafZvq9
browser/base/content/urlbarBindings.xml
browser/components/nsBrowserGlue.js
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -918,18 +918,23 @@ file, You can obtain one at http://mozil
                 this.completeDefaultIndex = this._prefs.getBoolPref(aData);
                 break;
               case "delay":
                 this.timeout = this._prefs.getIntPref(aData);
                 break;
               case "formatting.enabled":
                 this._formattingEnabled = this._prefs.getBoolPref(aData);
                 break;
+              case "suggest.searches":
+                // Mirror the value for future use, see the comment in the
+                // binding's constructor.
+                this._prefs.setBoolPref("searchSuggestionsChoice",
+                  this._prefs.getBoolPref("suggest.searches"));
+                // fall-through.
               case "userMadeSearchSuggestionsChoice":
-              case "suggest.searches":
                 this._cacheUserMadeSearchSuggestionsChoice();
                 if (this._userMadeSearchSuggestionsChoice) {
                   this.popup.searchSuggestionsNotificationWasDismissed(
                     this._prefs.getBoolPref("suggest.searches")
                   );
                 }
                 break;
               case "trimURLs":
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -593,16 +593,31 @@ BrowserGlue.prototype = {
 
     // apply distribution customizations
     // prefs are applied in _onAppDefaults()
     this._distributionCustomizer.applyCustomizations();
 
     // handle any UI migration
     this._migrateUI();
 
+    // This is support code for the location bar search suggestions; passing
+    // from opt-in to opt-out should respect the user's choice, thus we need
+    // to cache that choice in a pref for future use.
+    // Note: this is not in migrateUI because we need to uplift it. This
+    // code is also short-lived, since we can remove it as soon as opt-out
+    // search suggestions shipped in release (Bug 1344928).
+    try {
+      let urlbarPrefs = Services.prefs.getBranch("browser.urlbar.");
+      if (!urlbarPrefs.prefHasUserValue("searchSuggestionsChoice") &&
+          urlbarPrefs.getBoolPref("userMadeSearchSuggestionsChoice")) {
+        urlbarPrefs.setBoolPref("searchSuggestionsChoice",
+                                urlbarPrefs.getBoolPref("suggest.searches"));
+      }
+    } catch (ex) { /* missing any of the prefs is not critical */ }
+
     listeners.init();
 
     PageThumbs.init();
 
     DirectoryLinksProvider.init();
     NewTabUtils.init();
     NewTabUtils.links.addProvider(DirectoryLinksProvider);
     AboutNewTab.init();