Bug 1368470 - Count search suggestions notification impressions only when the popup is really shown. r=past
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 07 Jun 2017 11:35:30 +0200
changeset 413478 a9e45f56795b5c5cc64da28b64fdf72d45b8cce0
parent 413477 47f43b453c2d66958de80486d851ea85d31c0756
child 413479 189df493159bb85b1bfe566ce609ceb0ed254c43
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1368470
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
           }