Bug 1558917 - Referrer no longer sent for new tab links r=thecount a=jcristau
authorEd Lee <edilee@mozilla.com>
Fri, 14 Jun 2019 20:10:29 +0000
changeset 537009 a78204125055376cc805fdfb330dfb2ad35bd411
parent 537008 8dd6c8c8a610719913e9738daae139e003b45d1d
child 537010 e43bd705a68157592c615ab408d00c02076d993d
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersthecount, jcristau
bugs1558917
milestone68.0
Bug 1558917 - Referrer no longer sent for new tab links r=thecount a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D35073
browser/components/newtab/lib/PlacesFeed.jsm
browser/components/newtab/test/unit/lib/PlacesFeed.test.js
browser/components/newtab/test/unit/unit-entry.js
--- a/browser/components/newtab/lib/PlacesFeed.jsm
+++ b/browser/components/newtab/lib/PlacesFeed.jsm
@@ -243,18 +243,26 @@ class PlacesFeed {
     const params = {
       private: isPrivate,
       triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
     };
 
     // Always include the referrer (even for http links) if we have one
     const {event, referrer, typedBonus} = action.data;
     if (referrer) {
-      params.referrerPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL;
-      params.referrerURI = Services.io.newURI(referrer);
+      const ReferrerInfo = Components.Constructor(
+        "@mozilla.org/referrer-info;1",
+        "nsIReferrerInfo",
+        "init"
+      );
+      params.referrerInfo = new ReferrerInfo(
+        Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
+        true,
+        Services.io.newURI(referrer)
+      );
     }
 
     // Pocket gives us a special reader URL to open their stories in
     const urlToOpen = action.data.type === "pocket" ? action.data.open_url : action.data.url;
 
     // Mark the page as typed for frecency bonus before opening the link
     if (typedBonus) {
       PlacesUtils.history.markPageAsTyped(Services.io.newURI(urlToOpen));
--- a/browser/components/newtab/test/unit/lib/PlacesFeed.test.js
+++ b/browser/components/newtab/test/unit/lib/PlacesFeed.test.js
@@ -188,18 +188,22 @@ describe("PlacesFeed", () => {
         type: at.OPEN_LINK,
         data: {url: "foo.com", referrer: "foo.com/ref"},
         _target: {browser: {ownerGlobal: {openLinkIn, whereToOpenLink: e => "tab"}}},
       };
 
       feed.onAction(openLinkAction);
 
       const [, , params] = openLinkIn.firstCall.args;
-      assert.propertyVal(params, "referrerPolicy", 5);
-      assert.propertyVal(params.referrerURI, "spec", "foo.com/ref");
+      assert.nestedPropertyVal(params, "referrerInfo.referrerPolicy", 5);
+      assert.nestedPropertyVal(
+        params,
+        "referrerInfo.originalReferrer.spec",
+        "foo.com/ref"
+      );
     });
     it("should mark link with typed bonus as typed before opening OPEN_LINK", () => {
       const callOrder = [];
       sinon.stub(global.PlacesUtils.history, "markPageAsTyped").callsFake(() => {
         callOrder.push("markPageAsTyped");
       });
       const openLinkIn = sinon.stub().callsFake(() => {
         callOrder.push("openLinkIn");
--- a/browser/components/newtab/test/unit/unit-entry.js
+++ b/browser/components/newtab/test/unit/unit-entry.js
@@ -38,17 +38,30 @@ const TEST_GLOBAL = {
   ChromeUtils: {
     defineModuleGetter() {},
     generateQI() { return {}; },
     import() { return global; },
   },
   ClientEnvironment: {
     get userId() { return "foo123"; },
   },
-  Components: {isSuccessCode: () => true},
+  Components: {
+    Constructor(classId) {
+      switch (classId) {
+        case "@mozilla.org/referrer-info;1":
+          return function(referrerPolicy, sendReferrer, originalReferrer) {
+            this.referrerPolicy = referrerPolicy;
+            this.sendReferrer = sendReferrer;
+            this.originalReferrer = originalReferrer;
+          };
+      }
+      return function() {};
+    },
+    isSuccessCode: () => true,
+  },
   // eslint-disable-next-line object-shorthand
   ContentSearchUIController: function() {}, // NB: This is a function/constructor
   Cc: {
     "@mozilla.org/browser/nav-bookmarks-service;1": {
       addObserver() {},
       getService() {
         return this;
       },