Bug 1280381 - The prompt to enable search suggestions in the awesomebar panel should not be shown more than a few times, r=mak. a=sylvestre
authorFlorian Quèze <florian@queze.net>
Wed, 29 Jun 2016 19:49:40 +0200
changeset 339772 9f2b365e53bc915de34f0b8afceab1096d7c5b00
parent 339771 af55fb03c444b8a18e8b963781e50a1088075084
child 339773 c4d9753fc143a9e47d553bee75944b6746ea6662
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, sylvestre
bugs1280381
milestone49.0a2
Bug 1280381 - The prompt to enable search suggestions in the awesomebar panel should not be shown more than a few times, r=mak. a=sylvestre
browser/app/profile/firefox.js
browser/base/content/urlbarBindings.xml
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -287,16 +287,20 @@ pref("browser.urlbar.match.url", "@");
 
 // The default behavior for the urlbar can be configured to use any combination
 // of the match filters with each additional filter adding more results (union).
 pref("browser.urlbar.suggest.history",              true);
 pref("browser.urlbar.suggest.bookmark",             true);
 pref("browser.urlbar.suggest.openpage",             true);
 pref("browser.urlbar.suggest.searches",             false);
 pref("browser.urlbar.userMadeSearchSuggestionsChoice", false);
+// 4 here means the suggestion notification will be automatically
+// hidden the 4th day, so it will actually be shown on 3 different days.
+pref("browser.urlbar.daysBeforeHidingSuggestionsPrompt", 4);
+pref("browser.urlbar.lastSuggestionsPromptDate", 20160601);
 
 // Limit the number of characters sent to the current search engine to fetch
 // suggestions.
 pref("browser.urlbar.maxCharsForSearchSuggestions", 20);
 
 // Restrictions to current suggestions can also be applied (intersection).
 // Typed suggestion works only if history is set to true.
 pref("browser.urlbar.suggest.history.onlyTyped",    false);
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -956,17 +956,18 @@ file, You can obtain one at http://mozil
 
       <property name="shouldShowSearchSuggestionsNotification" readonly="true">
         <getter><![CDATA[
           return !this._userMadeSearchSuggestionsChoice &&
                  !this.inPrivateContext &&
                  // When _urlbarFocused is true, tabbrowser would close the
                  // popup if it's opened here, so don't show the notification.
                  !gBrowser.selectedBrowser._urlbarFocused &&
-                 Services.prefs.getBoolPref("browser.search.suggest.enabled");
+                 Services.prefs.getBoolPref("browser.search.suggest.enabled") &&
+                 this._prefs.getIntPref("daysBeforeHidingSuggestionsPrompt");
         ]]></getter>
       </property>
 
     </implementation>
 
     <handlers>
       <handler event="keydown"><![CDATA[
         if ((event.keyCode === KeyEvent.DOM_VK_ALT ||
@@ -1295,18 +1296,36 @@ file, You can obtain one at http://mozil
         <parameter name="aInput"/>
         <parameter name="aElement"/>
         <body>
           <![CDATA[
           // initially the panel is hidden
           // to avoid impacting startup / new window performance
           aInput.popup.hidden = false;
 
-          if (aInput.shouldShowSearchSuggestionsNotification) {
+          let showNotification = aInput.shouldShowSearchSuggestionsNotification;
+          if (showNotification) {
+            let prefs = aInput._prefs;
+            let date = parseInt((new Date()).toLocaleFormat("%Y%m%d"));
+            let previousDate = prefs.getIntPref("lastSuggestionsPromptDate");
+            if (previousDate < date) {
+              let remainingDays =
+                prefs.getIntPref("daysBeforeHidingSuggestionsPrompt") - 1;
+              prefs.setIntPref("daysBeforeHidingSuggestionsPrompt",
+                               remainingDays);
+              prefs.setIntPref("lastSuggestionsPromptDate", date);
+              if (!remainingDays)
+                showNotification = false;
+            }
+          }
+
+          if (showNotification) {
             this._showSearchSuggestionsNotification();
+          } else if (this.classList.contains("showSearchSuggestionsNotification")) {
+            this._hideSearchSuggestionsNotification();
           }
 
           this._openAutocompletePopup(aInput, aElement);
           ]]>
         </body>
       </method>
 
       <method name="_openAutocompletePopup">
@@ -1379,18 +1398,16 @@ file, You can obtain one at http://mozil
         <body>
           <![CDATA[
           this.footer.collapsed = this._matchCount == 0;
           ]]>
         </body>
       </method>
 
       <method name="_showSearchSuggestionsNotification">
-        <parameter name="aInput"/>
-        <parameter name="aElement"/>
         <body>
           <![CDATA[
           // With the notification shown, the listbox's height can sometimes be
           // too small when it's flexed, as it normally is.  Also, it can start
           // out slightly scrolled down.  Both problems appear together, most
           // often when the popup is very narrow and the notification's text
           // must wrap.  Work around them by removing the flex.
           //