Bug 1501656 - Prevent CFR impression pings being sent twice because of redirect events. r=ursula, a=pascalc FIREFOX_63_0_1_BUILD3 FIREFOX_63_0_1_BUILD4 FIREFOX_63_0_1_RELEASE
authork88hudson <k88hudson@gmail.com>
Mon, 29 Oct 2018 19:47:55 +0000
changeset 492959 6d5e52718c0092c7cc8c5d07b01803debc1cb2f2
parent 492958 57ecd86334a5be4ada8f24d8bdb82880f5172264
child 492960 713992e8e2ae2c19e0a5373a9c359795d6b9cfa6
push id1838
push userryanvm@gmail.com
push dateTue, 30 Oct 2018 16:56:43 +0000
treeherdermozilla-release@6d5e52718c00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersursula, pascalc
bugs1501656
milestone63.0.1
Bug 1501656 - Prevent CFR impression pings being sent twice because of redirect events. r=ursula, a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D10115
browser/components/newtab/lib/ASRouterTriggerListeners.jsm
browser/components/newtab/test/unit/unit-entry.js
--- a/browser/components/newtab/lib/ASRouterTriggerListeners.jsm
+++ b/browser/components/newtab/lib/ASRouterTriggerListeners.jsm
@@ -68,17 +68,21 @@ this.ASRouterTriggerListeners = new Map(
         this._initialized = false;
         this._triggerHandler = null;
         this._hosts = null;
       }
     },
 
     onLocationChange(aBrowser, aWebProgress, aRequest, aLocationURI, aFlags) {
       const location = aLocationURI ? aLocationURI.spec : "";
-      if (location && aWebProgress.isTopLevel) {
+      // Some websites trigger redirect events after they finish loading even
+      // though the location remains the same. This results in onLocationChange
+      // events to be fired twice.
+      const isSameDocument = !!(aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT);
+      if (location && aWebProgress.isTopLevel && !isSameDocument) {
         try {
           const host = (new URL(location)).hostname;
           if (this._hosts.has(host)) {
             this._triggerHandler(aBrowser, {id: "openURL", param: host});
           }
         } catch (e) {} // Couldn't parse location URL
       }
     },
--- a/browser/components/newtab/test/unit/unit-entry.js
+++ b/browser/components/newtab/test/unit/unit-entry.js
@@ -76,16 +76,17 @@ const TEST_GLOBAL = {
       insert() {},
       markPageAsTyped() {},
       removeObserver() {}
     }
   },
   Ci: {
     nsIHttpChannel: {REFERRER_POLICY_UNSAFE_URL: 5},
     nsITimer: {TYPE_ONE_SHOT: 1}
+    nsIWebProgressListener: {LOCATION_CHANGE_SAME_DOCUMENT: 1},
   },
   Cu: {
     importGlobalProperties() {},
     now: () => window.performance.now(),
     reportError() {}
   },
   dump() {},
   fetch() {},