Bug 1368470 - Count search suggestions notification impressions only when the popup is really shown. r=past draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 07 Jun 2017 11:35:30 +0200
changeset 590261 cb8f0848cd53788b0603430ea4db5fc2ea5d9c03
parent 589544 4dd1d17ba22660b8f5869a707f2e4e9f9dd5be5b
child 632152 33f298dbdf28b13d298af579870007da5008025d
push id62661
push usermak77@bonardo.net
push dateWed, 07 Jun 2017 12:50:15 +0000
reviewerspast
bugs1368470
milestone55.0a1
Bug 1368470 - Count search suggestions notification impressions only when the popup is really shown. r=past Sometimes the platform doesn't open the autocomplete popup even if we openPopup and reach the xul popup manager. This ensures we only count real impressions. MozReview-Commit-ID: LadswltSv9V
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1850,17 +1850,24 @@ file, You can obtain one at http://mozil
             // Reset the alignment so that the site icons are positioned
             // according to whatever's in the CSS.
             this.siteIconStart = undefined;
           }
 
           try {
             let whichNotification = aInput.whichSearchSuggestionsNotification;
             if (whichNotification != "none") {
-              aInput.updateSearchSuggestionsNotificationImpressions(whichNotification);
+              // Update the impressions count on real popupshown, since there's
+              // no guarantee openPopup will be respected by the platform.
+              // Though, we must ensure the handled event is the expected one.
+              let impressionId = this._searchSuggestionsImpressionId = {};
+              this.addEventListener("popupshown", () => {
+                if (this._searchSuggestionsImpressionId == impressionId)
+                  aInput.updateSearchSuggestionsNotificationImpressions(whichNotification);
+              }, {once: true});
               this._showSearchSuggestionsNotification(whichNotification, popupDirection);
             } else if (this.classList.contains("showSearchSuggestionsNotification")) {
               this._hideSearchSuggestionsNotification();
             }
           } catch (ex) {
             // Not critical for the urlbar functionality, just report the error.
             Components.utils.reportError(ex);
           }