Bug 1364002 - Store the user-made search suggestion choice along with userMadeSearchSuggestionChoice. r=past a=gchang
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 11 May 2017 11:15:47 +0200
changeset 581839 a3bc13b60d416ad4a0dd42820ede5c0d69c288a0
parent 581838 0884adb687d1b4cf95820feae19939d931053ae7
child 581840 4f95bb8a858ddba0c994002467109b70b6344990
push id59898
push userfmarier@mozilla.com
push dateFri, 19 May 2017 23:56:54 +0000
reviewerspast, gchang
bugs1364002
milestone54.0
Bug 1364002 - Store the user-made search suggestion choice along with userMadeSearchSuggestionChoice. r=past a=gchang 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
@@ -913,18 +913,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
@@ -602,16 +602,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 */ }
+
     PageThumbs.init();
     webrtcUI.init();
     AboutHome.init();
 
     DirectoryLinksProvider.init();
     NewTabUtils.init();
     NewTabUtils.links.addProvider(DirectoryLinksProvider);
     AboutNewTab.init();