Bug 1379369 - Part 4. Port part of Bug 1113431 [Propagate referrer policy throughout the UI] to SeaMonkey. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 10 Sep 2017 21:08:41 +0200
changeset 29678 a202c95f898c7e16805e61335ed10341135fb31b
parent 29677 7bdcbbdd0e1ffdb3dc7e4d9755cd903136d73b1c
child 29679 e91a8dac406d38b4b3f8846e39c396e9fa0cb126
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersIanN
bugs1379369, 1113431
Bug 1379369 - Part 4. Port part of Bug 1113431 [Propagate referrer policy throughout the UI] to SeaMonkey. r=IanN
suite/browser/navigator.js
suite/browser/tabbrowser.xml
suite/common/utilityOverlay.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -371,40 +371,42 @@ nsBrowserAccess.prototype = {
 
     if (aWhere == nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW) {
       if (isExternal)
         aWhere = Services.prefs.getIntPref("browser.link.open_external");
       else
         aWhere = Services.prefs.getIntPref("browser.link.open_newwindow");
     }
 
-    var referrer = aOpener ? aOpener.QueryInterface(nsIInterfaceRequestor)
+    let referrer = aOpener ? aOpener.QueryInterface(nsIInterfaceRequestor)
                                     .getInterface(nsIWebNavigation)
                                     .currentURI : null;
+    let referrerPolicy = Components.interfaces.nsIHttpChannel.REFERRER_POLICY_UNSET;
     var uri = aURI ? aURI.spec : "about:blank";
 
     switch (aWhere) {
       case nsIBrowserDOMWindow.OPEN_NEWWINDOW:
         return window.openDialog(getBrowserURL(), "_blank", "all,dialog=no",
-                                 uri, null, referrer);
+                                 uri, null, null);
       case nsIBrowserDOMWindow.OPEN_NEWTAB:
         var bgLoad = Services.prefs.getBoolPref("browser.tabs.loadDivertedInBackground");
         var isRelated = referrer ? true : false;
         // If we have an opener, that means that the caller is expecting access
         // to the nsIDOMWindow of the opened tab right away.
         let userContextId = aOpener && aOpener.document
                             ? aOpener.document.nodePrincipal.originAttributes.userContextId
                             : Components.interfaces.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
         let openerWindow = (aFlags & nsIBrowserDOMWindow.OPEN_NO_OPENER) ? null : aOpener;
 
         var newTab = gBrowser.loadOneTab(uri, {triggeringPrincipal: aTriggeringPrincipal,
+                                               referrerURI: referrer,
+                                               referrerPolicy,
                                                inBackground: bgLoad,
                                                fromExternal: isExternal,
                                                relatedToCurrent: isRelated,
-                                               referrerURI: referrer,
                                                userContextId: userContextId,
                                                opener: openerWindow,
                                               });
         var contentWin = gBrowser.getBrowserForTab(newTab).contentWindow;
         if (!bgLoad)
           contentWin.focus();
         return contentWin;
       default:
@@ -412,16 +414,17 @@ nsBrowserAccess.prototype = {
                         nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
                         nsIWebNavigation.LOAD_FLAGS_NONE;
 
         if (!aOpener) {
           if (aURI) {
             gBrowser.loadURIWithFlags(aURI.spec, {
                                                   flags: loadflags,
                                                   referrerURI: referrer,
+                                                  referrerPolicy,
                                                   userContextId: userContextId,
                                                   triggeringPrincipal: aTriggeringPrincipal,
                                                  });
           }
           return content;
         }
         aOpener = aOpener.top;
         if (aURI) {
@@ -651,22 +654,26 @@ function Startup()
       let referrerURI = window.arguments[2];
       if (typeof(referrerURI) == "string") {
         try {
           referrerURI = makeURI(referrerURI);
         } catch (e) {
           referrerURI = null;
         }
       }
+      let referrerPolicy = (window.arguments[5] != undefined ?
+          window.arguments[5] : Components.interfaces.nsIHttpChannel.REFERRER_POLICY_UNSET);
+
       let userContextId = (window.arguments[6] != undefined ?
           window.arguments[6] : Components.interfaces.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID);
 
       try {
         openLinkIn(uriToLoad, "current",
                    { referrerURI,
+                     referrerPolicy,
                      postData: window.arguments[3] || null,
                      allowThirdPartyFixup: window.arguments[4] || false,
                      userContextId,
                      // pass the origin principal (if any) and force its use to create
                      // an initial about:blank viewer if present:
                      originPrincipal: window.arguments[7],
                      triggeringPrincipal: window.arguments[8],
                    });
--- a/suite/browser/tabbrowser.xml
+++ b/suite/browser/tabbrowser.xml
@@ -1552,27 +1552,29 @@
         <parameter name="aReferrerURI"/>
         <parameter name="aCharset"/>
         <parameter name="aPostData"/>
         <parameter name="aFocusNewTab"/>
         <parameter name="aAllowThirdPartyFixup"/>
         <body>
           <![CDATA[
             var aTriggeringPrincipal;
+            var aReferrerPolicy;
             var aFromExternal;
             var aRelatedToCurrent;
             var aUserContextId;
             var aOpener;
             if (arguments.length == 2 &&
                 arguments[1] != null &&
                 typeof arguments[1] == "object" &&
                 !(arguments[1] instanceof Components.interfaces.nsIURI)) {
               let params = arguments[1];
               aTriggeringPrincipal  = params.triggeringPrincipal;
               aReferrerURI          = params.referrerURI;
+              aReferrerPolicy       = params.referrerPolicy;
               aCharset              = params.charset;
               aPostData             = params.postData;
               aFocusNewTab          = params.focusNewTab;
               aAllowThirdPartyFixup = params.allowThirdPartyFixup;
               aFromExternal         = params.fromExternal;
               aRelatedToCurrent     = params.relatedToCurrent;
               aUserContextId        = params.userContextId;
               aOpener               = params.opener;
@@ -1660,16 +1662,17 @@
               if (aFromExternal)
                 flags |= nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL;
               try {
                 b.loadURIWithFlags(aURI, {
                   flags,
                   triggeringPrincipal : aTriggeringPrincipal,
                   referrerURI: aReferrerURI,
                   charset: aCharset,
+                  referrerPolicy: aReferrerPolicy,
                   postData: aPostData,
                 });                
               }
               catch (ex) { }
             }
 
             t.dispatchEvent(new Event("TabOpen",
               { bubbles: true, cancelable: false }));
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -1500,16 +1500,17 @@ function openUILinkIn(url, where, aAllow
 
   if (arguments.length == 3 && typeof arguments[2] == "object") {
     params = aAllowThirdPartyFixup;
   } else {
     params = {
       allowThirdPartyFixup: aAllowThirdPartyFixup,
       postData: aPostData,
       referrerURI: aReferrerURI,
+      referrerPolicy: Components.interfaces.nsIHttpChannel.REFERRER_POLICY_UNSET,
     };
   }
 
   params.fromChrome = true;
 
   openLinkIn(url, where, params);
 }
 
@@ -1522,16 +1523,18 @@ function openLinkIn(url, where, params)
   const Ci = Components.interfaces;
 
   var aAllowThirdPartyFixup = params.allowThirdPartyFixup;
   var aPostData             = params.postData;
   var aReferrerURI          = params.referrerURI;
   var aRelatedToCurrent     = params.relatedToCurrent;
   var aInitiatingDoc = params.initiatingDoc ? params.initiatingDoc : document;
 
+  var aReferrerPolicy       = ("referrerPolicy" in params ?
+        params.referrerPolicy : Ci.nsIHttpChannel.REFERRER_POLICY_UNSET);
   var aUserContextId        = params.userContextId;
   var aPrincipal            = params.originPrincipal;
   var aTriggeringPrincipal  = params.triggeringPrincipal;
 
   if (where == "save") {
     saveURL(url, null, null, true, true, aReferrerURI, aInitiatingDoc);
     return null;
   }
@@ -1577,24 +1580,29 @@ function openLinkIn(url, where, params)
 
     var referrerURISupports = null;
     if (aReferrerURI) {
       referrerURISupports = Cc["@mozilla.org/supports-string;1"].
                             createInstance(Ci.nsISupportsString);
       referrerURISupports.data = aReferrerURI.spec;
     }
 
+    var referrerPolicySupports = Cc["@mozilla.org/supports-PRUint32;1"].
+                                 createInstance(Ci.nsISupportsPRUint32);
+    referrerPolicySupports.data = aReferrerPolicy;
+
     var userContextIdSupports = Cc["@mozilla.org/supports-PRUint32;1"].
                                  createInstance(Ci.nsISupportsPRUint32);
     userContextIdSupports.data = aUserContextId;
 
     sa.appendElement(wuri);
     sa.appendElement(referrerURISupports);
     sa.appendElement(aPostData);
     sa.appendElement(allowThirdPartyFixupSupports);
+    sa.appendElement(referrerPolicySupports);
     sa.appendElement(userContextIdSupports);
     sa.appendElement(aPrincipal);
     sa.appendElement(aTriggeringPrincipal);
 
     let features = "chrome,dialog=no,all";
 
     const sourceWindow = (w || window);
     Services.ww.openWindow(sourceWindow, getBrowserURL(), null, features, sa);
@@ -1615,16 +1623,17 @@ function openLinkIn(url, where, params)
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
     }
 
     w.getBrowser().loadURIWithFlags(url, {
       triggeringPrincipal: aTriggeringPrincipal,
       flags,
       referrerURI: aReferrerURI,
+      referrerPolicy: aReferrerPolicy,
       postData: aPostData,
       userContextId: aUserContextId
     });
     w.content.focus();
     break;
 
   case "tabfocused":
     // forces tab to be focused
@@ -1632,16 +1641,17 @@ function openLinkIn(url, where, params)
     // fall through
   case "tabshifted":
     loadInBackground = !loadInBackground;
     // fall through
   case "tab":
     var browser = w.getBrowser();
     var tab = browser.addTab(url, {
                 referrerURI: aReferrerURI,
+                referrerPolicy: aReferrerPolicy,
                 postData: aPostData,
                 allowThirdPartyFixup: aAllowThirdPartyFixup,
                 relatedToCurrent: aRelatedToCurrent,
                 userContextId: aUserContextId,
                 originPrincipal: aPrincipal,
                 triggeringPrincipal: aTriggeringPrincipal,
               });
     if (!loadInBackground) {