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
--- 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);
}