Bug 1578067 - Part 2: Update openLinkIn() and use more - update openLinkIn(). r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 13 Oct 2019 13:21:01 +0200
changeset 37140 aafc1fdafb54c5ae4cd9ae6034823d58dea85d98
parent 37139 cf230e323194115fc8f8a3f750ecfd67cb500d2d
child 37141 8f6a7dd3996f3db7a990a7faab70f34d13a6e0ff
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersfrg
bugs1578067
Bug 1578067 - Part 2: Update openLinkIn() and use more - update openLinkIn(). r=frg
suite/base/content/utilityOverlay.js
--- a/suite/base/content/utilityOverlay.js
+++ b/suite/base/content/utilityOverlay.js
@@ -1499,51 +1499,52 @@ function openUILinkIn(url, where, aAllow
     params = {
       allowThirdPartyFixup: aAllowThirdPartyFixup,
       postData: aPostData,
       referrerURI: aReferrerURI,
       referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
     };
   }
 
+  if (where == "private") {
+    where = "window";
+    params.private = true;
+  }
+
   params.fromChrome = true;
 
   return openLinkIn(url, where, params);
 }
 
 function openLinkIn(url, where, params)
 {
   if (!where || !url)
     return null;
 
+  var aFromChrome           = params.fromChrome;
   var aAllowThirdPartyFixup = params.allowThirdPartyFixup;
   var aPostData             = params.postData;
+  var aCharset              = params.charset;
   var aReferrerURI          = params.referrerURI;
+  var aReferrerPolicy       = ("referrerPolicy" in params ?
+        params.referrerPolicy : Ci.nsIHttpChannel.REFERRER_POLICY_UNSET);
   var aRelatedToCurrent     = params.relatedToCurrent;
+  var aInBackground         = params.inBackground;
+  var aDisallowInheritPrincipal = params.disallowInheritPrincipal;
   var aInitiatingDoc = params.initiatingDoc ? params.initiatingDoc : document;
   var aIsPrivate            = params.private;
-
-  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;
   }
 
-  // TODO fix this properly with pricipals and referrers intact
-  if (where == "private") {
-    window.openDialog(getBrowserURL(), "_blank", "private,chrome,all,dialog=no",
-                      url, null, null, aPostData, aAllowThirdPartyFixup);
-    return null;
-  }
-
   // Establish which window we'll load the link in.
   var w = getTopWin();
   // We don't want to open tabs in popups, so try to find a non-popup window in
   // that case.
   if ((where == "tab" || where == "tabshifted") && w && !w.toolbar.visible) {
     w = getTopWin(true);
     aRelatedToCurrent = false;
   }
@@ -1575,16 +1576,23 @@ function openLinkIn(url, where, params)
     // This propagates to window.arguments.
     var sa = Cc["@mozilla.org/array;1"].
              createInstance(Ci.nsIMutableArray);
 
     var wuri = Cc["@mozilla.org/supports-string;1"].
                createInstance(Ci.nsISupportsString);
     wuri.data = url;
 
+    let charset = null;
+    if (aCharset) {
+      charset = Cc["@mozilla.org/supports-string;1"]
+                  .createInstance(Ci.nsISupportsString);
+      charset.data = "charset=" + aCharset;
+    }
+
     var allowThirdPartyFixupSupports = Cc["@mozilla.org/supports-PRBool;1"].
                                        createInstance(Ci.nsISupportsPRBool);
     allowThirdPartyFixupSupports.data = aAllowThirdPartyFixup;
 
     var referrerURISupports = null;
     if (aReferrerURI) {
       referrerURISupports = Cc["@mozilla.org/supports-string;1"].
                             createInstance(Ci.nsISupportsString);
@@ -1595,45 +1603,52 @@ function openLinkIn(url, where, params)
                                  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(charset);
     sa.appendElement(referrerURISupports);
     sa.appendElement(aPostData);
     sa.appendElement(allowThirdPartyFixupSupports);
     sa.appendElement(referrerPolicySupports);
     sa.appendElement(userContextIdSupports);
     sa.appendElement(aPrincipal);
     sa.appendElement(aTriggeringPrincipal);
 
     const sourceWindow = (w || window);
     Services.ww.openWindow(sourceWindow, getBrowserURL(), null, features, sa);
     return;
   }
 
-  var loadInBackground =
-    Services.prefs.getBoolPref("browser.tabs.loadInBackground");
+  let loadInBackground = aInBackground;
+  if (loadInBackground == null) {
+    loadInBackground =
+      aFromChrome ? false :
+                    Services.prefs.getBoolPref("browser.tabs.loadInBackground");
+  }
 
   // reuse the browser if its current tab is empty
   if (isBrowserEmpty(w.getBrowser()))
     where = "current";
 
   switch (where) {
   case "current":
     let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
 
     if (aAllowThirdPartyFixup) {
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
     }
-
+    if (aDisallowInheritPrincipal) {
+      flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
+    }
     w.getBrowser().loadURIWithFlags(url, {
       triggeringPrincipal: aTriggeringPrincipal,
       flags,
       referrerURI: aReferrerURI,
       referrerPolicy: aReferrerPolicy,
       postData: aPostData,
       userContextId: aUserContextId
     });
@@ -1647,16 +1662,17 @@ function openLinkIn(url, where, params)
   case "tabshifted":
     loadInBackground = !loadInBackground;
     // fall through
   case "tab":
     var browser = w.getBrowser();
     var tab = browser.addTab(url, {
                 referrerURI: aReferrerURI,
                 referrerPolicy: aReferrerPolicy,
+                charset: aCharset,
                 postData: aPostData,
                 allowThirdPartyFixup: aAllowThirdPartyFixup,
                 relatedToCurrent: aRelatedToCurrent,
                 userContextId: aUserContextId,
                 originPrincipal: aPrincipal,
                 triggeringPrincipal: aTriggeringPrincipal,
               });
     if (!loadInBackground) {