Bug 1549732 - Use ReferrerInfo instead of ReferrerURI when loading URI r=geckoview-reviewers,snorp
authorEmily Toop <etoop@mozilla.com>
Fri, 10 May 2019 18:00:28 +0000
changeset 532417 f9170a14e63672ffff429d81c76ffd5c49f9936f
parent 532416 c2c7d0b11f1365b96292f925ba1a24270d0b819c
child 532418 85c3b0c31659658d731f96e974183d28bcdec9db
push id11268
push usercsabou@mozilla.com
push dateTue, 14 May 2019 15:24:22 +0000
treeherdermozilla-beta@5fb7fcd568d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1549732
milestone68.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 1549732 - Use ReferrerInfo instead of ReferrerURI when loading URI r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D30524
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -291,16 +291,36 @@ function resolveGeckoURI(aURI) {
     return registry.convertChromeURL(Services.io.newURI(aURI)).spec;
   } else if (aURI.startsWith("resource://")) {
     let handler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
     return handler.resolveURI(Services.io.newURI(aURI));
   }
   return aURI;
 }
 
+XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
+  Components.Constructor(
+    "@mozilla.org/referrer-info;1",
+    "nsIReferrerInfo",
+    "init"));
+
+function createReferrerInfo(aReferrer) {
+  let referrerUri;
+  try {
+    referrerUri = Services.io.newURI(aReferrer);
+  } catch (ignored) {
+  }
+
+  return new ReferrerInfo(
+    Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
+    true,
+    referrerUri
+  );
+}
+
 /**
  * Cache of commonly used string bundles.
  */
 var Strings = {
   init: function() {
     XPCOMUtils.defineLazyGetter(Strings, "brand", () => Services.strings.createBundle("chrome://branding/locale/brand.properties"));
     XPCOMUtils.defineLazyGetter(Strings, "browser", () => Services.strings.createBundle("chrome://browser/locale/browser.properties"));
     XPCOMUtils.defineLazyGetter(Strings, "reader", () => Services.strings.createBundle("chrome://global/locale/aboutReader.properties"));
@@ -1174,31 +1194,31 @@ var BrowserApp = {
     aBrowser = aBrowser || this.selectedBrowser;
     if (!aBrowser)
       return;
 
     aParams = aParams || {};
 
     let flags = "flags" in aParams ? aParams.flags : Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
     let postData = ("postData" in aParams && aParams.postData) ? aParams.postData : null;
-    let referrerURI = "referrerURI" in aParams ? aParams.referrerURI : null;
+    let referrerInfo = "referrerURI" in aParams ? createReferrerInfo(aParams.referrerURI) : null;
     let charset = "charset" in aParams ? aParams.charset : null;
 
     let tab = this.getTabForBrowser(aBrowser);
     if (tab) {
       if ("userRequested" in aParams) tab.userRequested = aParams.userRequested;
       tab.isSearch = ("isSearch" in aParams) ? aParams.isSearch : false;
     }
     // Don't fall back to System here Bug 1474619
     let triggeringPrincipal = "triggeringPrincipal" in aParams ? aParams.triggeringPrincipal : Services.scriptSecurityManager.getSystemPrincipal();
 
     try {
       aBrowser.loadURI(aURI, {
         flags,
-        referrerURI,
+        referrerInfo,
         charset,
         postData,
         triggeringPrincipal,
       });
     } catch (e) {
       if (tab) {
         let message = {
           type: "Content:LoadError",
@@ -3460,17 +3480,17 @@ nsBrowserAccess.prototype = {
       return tab.browser;
     }
 
     // OPEN_CURRENTWINDOW and illegal values
     let browser = BrowserApp.selectedBrowser;
     if (aURI && browser) {
       browser.loadURI(aURI.spec, {
         flags: loadflags,
-        referrerURI: referrer,
+        referrerInfo: createReferrerInfo(referrer),
         triggeringPrincipal: aTriggeringPrincipal,
       });
     }
 
     return browser;
   },
 
   openURI: function browser_openURI(aURI, aOpener, aWhere, aFlags,
@@ -3754,27 +3774,27 @@ Tab.prototype = {
       this.browser.setAttribute("pending", "true");
     } else {
       let flags = "flags" in aParams ? aParams.flags : Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
       if (aParams.disallowInheritPrincipal) {
         flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL;
       }
 
       let postData = ("postData" in aParams && aParams.postData) ? aParams.postData.value : null;
-      let referrerURI = "referrerURI" in aParams ? aParams.referrerURI : null;
+      let referrerInfo = "referrerURI" in aParams ? createReferrerInfo(aParams.referrerURI) : null;
       let charset = "charset" in aParams ? aParams.charset : null;
 
       // The search term the user entered to load the current URL
       this.userRequested = "userRequested" in aParams ? aParams.userRequested : "";
       this.isSearch = "isSearch" in aParams ? aParams.isSearch : false;
 
       try {
         this.browser.loadURI(aURL, {
           flags,
-          referrerURI,
+          referrerInfo,
           charset,
           postData,
           triggeringPrincipal: aParams.triggeringPrincipal,
         });
       } catch (e) {
         let message = {
           type: "Content:LoadError",
           tabID: this.id,