Bug 1528695 - Part 2 : Use referrerInfo in openWindow, contextmenu and openLinkIn r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D21911

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Nguyen 2019-03-15 05:10:17 +00:00
parent 33d78105b7
commit 26bd1e060c
12 changed files with 128 additions and 140 deletions

View File

@ -56,14 +56,23 @@ class ClickHandlerChild extends ActorChild {
csp = E10SUtils.serializeCSP(csp);
}
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
let referrerInfo = new ReferrerInfo(
referrerPolicy,
!BrowserUtils.linkHasNoReferrer(node),
ownerDoc.documentURIObject);
referrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
let frameOuterWindowID = WebNavigationFrames.getFrameId(ownerDoc.defaultView);
let json = { button: event.button, shiftKey: event.shiftKey,
ctrlKey: event.ctrlKey, metaKey: event.metaKey,
altKey: event.altKey, href: null, title: null,
frameOuterWindowID, referrerPolicy,
frameOuterWindowID,
triggeringPrincipal: principal,
csp,
referrerInfo,
originAttributes: principal ? principal.originAttributes : {},
isContentWindowPrivate: PrivateBrowsingUtils.isContentWindowPrivate(ownerDoc.defaultView)};
@ -78,7 +87,7 @@ class ClickHandlerChild extends ActorChild {
if (node) {
json.title = node.getAttribute("title");
}
json.noReferrer = BrowserUtils.linkHasNoReferrer(node);
// Check if the link needs to be opened with mixed content allowed.
// Only when the owner doc has |mixedContentChannel| and the same origin

View File

@ -265,6 +265,11 @@ XPCOMUtils.defineLazyPreferenceGetter(gURLBarHandler, "quantumbar",
"browser.urlbar.quantumbar", false,
gURLBarHandler.handlePrefChange.bind(gURLBarHandler));
XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init"));
// High priority notification bars shown at the top of the window.
XPCOMUtils.defineLazyGetter(this, "gHighPriorityNotificationBox", () => {
return new MozElements.NotificationBox(element => {
@ -1740,7 +1745,7 @@ var gBrowserInit = {
_handleURIToLoad() {
this._callWithURIToLoad(uriToLoad => {
if (!uriToLoad) {
// We don't check whether window.arguments[6] (userContextId) is set
// We don't check whether window.arguments[5] (userContextId) is set
// because tabbrowser.js takes care of that for the initial tab.
return;
}
@ -1755,44 +1760,33 @@ var gBrowserInit = {
inBackground: false,
replace: true,
// See below for the semantics of window.arguments. Only the minimum is supported.
userContextId: window.arguments[6],
triggeringPrincipal: window.arguments[8] || Services.scriptSecurityManager.getSystemPrincipal(),
allowInheritPrincipal: window.arguments[9],
csp: window.arguments[10],
userContextId: window.arguments[5],
triggeringPrincipal: window.arguments[7] || Services.scriptSecurityManager.getSystemPrincipal(),
allowInheritPrincipal: window.arguments[8],
csp: window.arguments[9],
fromExternal: true,
});
} catch (e) {}
} else if (window.arguments.length >= 3) {
// window.arguments[1]: unused (bug 871161)
// [2]: referrer (nsIURI | string)
// [2]: referrerInfo (nsIReferrerInfo)
// [3]: postData (nsIInputStream)
// [4]: allowThirdPartyFixup (bool)
// [5]: referrerPolicy (int)
// [6]: userContextId (int)
// [7]: originPrincipal (nsIPrincipal)
// [8]: triggeringPrincipal (nsIPrincipal)
// [9]: allowInheritPrincipal (bool)
// [10]: csp (nsIContentSecurityPolicy)
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] : Ci.nsIHttpChannel.REFERRER_POLICY_UNSET);
let userContextId = (window.arguments[6] != undefined ?
window.arguments[6] : Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID);
loadURI(uriToLoad, referrerURI, window.arguments[3] || null,
window.arguments[4] || false, referrerPolicy, userContextId,
// [5]: userContextId (int)
// [6]: originPrincipal (nsIPrincipal)
// [7]: triggeringPrincipal (nsIPrincipal)
// [8]: allowInheritPrincipal (bool)
// [9]: csp (nsIContentSecurityPolicy)
let userContextId = (window.arguments[5] != undefined ?
window.arguments[5] : Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID);
loadURI(uriToLoad, window.arguments[2] || null, window.arguments[3] || null,
window.arguments[4] || false, userContextId,
// pass the origin principal (if any) and force its use to create
// an initial about:blank viewer if present:
window.arguments[7], !!window.arguments[7], window.arguments[8],
window.arguments[6], !!window.arguments[6], window.arguments[7],
// TODO fix allowInheritPrincipal to default to false.
// Default to true unless explicitly set to false because of bug 1475201.
window.arguments[9] !== false, window.arguments[10]);
window.arguments[8] !== false, window.arguments[9]);
window.focus();
} else {
// Note: loadOneOrMoreURIs *must not* be called if window.arguments.length >= 3.
@ -2509,7 +2503,7 @@ function BrowserTryToCloseWindow() {
window.close(); // WindowIsClosing does all the necessary checks
}
function loadURI(uri, referrer, postData, allowThirdPartyFixup, referrerPolicy,
function loadURI(uri, referrerInfo, postData, allowThirdPartyFixup,
userContextId, originPrincipal, forceAboutBlankViewerInCurrent,
triggeringPrincipal, allowInheritPrincipal = false, csp = null) {
if (!triggeringPrincipal) {
@ -2518,8 +2512,7 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup, referrerPolicy,
try {
openLinkIn(uri, "current",
{ referrerURI: referrer,
referrerPolicy,
{ referrerInfo,
postData,
allowThirdPartyFixup,
userContextId,
@ -5543,7 +5536,7 @@ function nsBrowserAccess() { }
nsBrowserAccess.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIBrowserDOMWindow]),
_openURIInNewTab(aURI, aReferrer, aReferrerPolicy, aIsPrivate,
_openURIInNewTab(aURI, aReferrerInfo, aIsPrivate,
aIsExternal, aForceNotRemote = false,
aUserContextId = Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID,
aOpenerWindow = null, aOpenerBrowser = null,
@ -5573,8 +5566,7 @@ nsBrowserAccess.prototype = {
let tab = win.gBrowser.loadOneTab(aURI ? aURI.spec : "about:blank", {
triggeringPrincipal: aTriggeringPrincipal,
referrerURI: aReferrer,
referrerPolicy: aReferrerPolicy,
referrerInfo: aReferrerInfo,
userContextId: aUserContextId,
fromExternal: aIsExternal,
inBackground: loadInBackground,
@ -5638,10 +5630,10 @@ nsBrowserAccess.prototype = {
aWhere = Services.prefs.getIntPref("browser.link.open_newwindow");
}
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
let referrerPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_UNSET;
let referrerInfo = new ReferrerInfo(Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true,
aOpener ? makeURI(aOpener.location.href) : null);
if (aOpener && aOpener.document) {
referrerPolicy = aOpener.document.referrerPolicy;
referrerInfo.referrerPolicy = aOpener.document.referrerPolicy;
}
// Bug 965637, query the CSP from the doc instead of the Principal
let csp = aTriggeringPrincipal.csp;
@ -5663,7 +5655,7 @@ nsBrowserAccess.prototype = {
try {
newWindow = openDialog(AppConstants.BROWSER_CHROME_URL, "_blank", features,
// window.arguments
url, null, null, null, null, null, null, null, aTriggeringPrincipal);
url, null, null, null, null, null, null, aTriggeringPrincipal);
} catch (ex) {
Cu.reportError(ex);
}
@ -5680,7 +5672,7 @@ nsBrowserAccess.prototype = {
? aOpener.document.nodePrincipal.originAttributes.userContextId
: Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
let openerWindow = (aFlags & Ci.nsIBrowserDOMWindow.OPEN_NO_OPENER) ? null : aOpener;
let browser = this._openURIInNewTab(aURI, referrer, referrerPolicy,
let browser = this._openURIInNewTab(aURI, referrerInfo,
isPrivate, isExternal,
forceNotRemote, userContextId,
openerWindow, null, aTriggeringPrincipal,
@ -5698,8 +5690,7 @@ nsBrowserAccess.prototype = {
triggeringPrincipal: aTriggeringPrincipal,
csp,
flags: loadflags,
referrerURI: referrer,
referrerPolicy,
referrerInfo,
});
}
if (!Services.prefs.getBoolPref("browser.tabs.loadDivertedInBackground"))
@ -5737,9 +5728,8 @@ nsBrowserAccess.prototype = {
? aParams.openerOriginAttributes.userContextId
: Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
let referrer = aParams.referrer ? makeURI(aParams.referrer) : null;
return this._openURIInNewTab(aURI, referrer,
aParams.referrerPolicy,
return this._openURIInNewTab(aURI,
aParams.referrerInfo,
aParams.isPrivate,
isExternal, false,
userContextId, null, aParams.openerBrowser,
@ -6295,6 +6285,10 @@ function handleLinkClick(event, href, linkNode) {
}
let frameOuterWindowID = WebNavigationFrames.getFrameId(doc.defaultView);
let referrerInfo = new ReferrerInfo(
referrerPolicy,
!BrowserUtils.linkHasNoReferrer(linkNode),
referrerURI);
// Bug 965637, query the CSP from the doc instead of the Principal
let csp = doc.nodePrincipal.csp;
@ -6303,9 +6297,7 @@ function handleLinkClick(event, href, linkNode) {
let params = {
charset: doc.characterSet,
allowMixedContent: persistAllowMixedContentInChildTab,
referrerURI,
referrerPolicy,
noReferrer: BrowserUtils.linkHasNoReferrer(linkNode),
referrerInfo,
originPrincipal: doc.nodePrincipal,
triggeringPrincipal: doc.nodePrincipal,
csp,

View File

@ -45,6 +45,17 @@ function openContextMenu(aMessage) {
let documentURIObject = makeURI(data.docLocation,
data.charSet,
makeURI(data.baseURI));
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
let referrerInfo = new ReferrerInfo(
data.referrerPolicy,
!data.context.linkHasNoReferrer,
documentURIObject);
let frameReferrerInfo = new ReferrerInfo(
data.referrerPolicy,
!data.context.linkHasNoReferrer,
data.referrer ? makeURI(data.referrer) : null);
gContextMenuContentData = { context: data.context,
isRemote: data.isRemote,
popupNodeSelectors: data.popupNodeSelectors,
@ -56,8 +67,8 @@ function openContextMenu(aMessage) {
documentURIObject,
docLocation: data.docLocation,
charSet: data.charSet,
referrer: data.referrer,
referrerPolicy: data.referrerPolicy,
referrerInfo,
frameReferrerInfo,
contentType: data.contentType,
contentDisposition: data.contentDisposition,
frameOuterWindowID: data.frameOuterWindowID,
@ -194,7 +205,6 @@ nsContextMenu.prototype = {
this.link = context.link;
this.linkDownload = context.linkDownload;
this.linkHasNoReferrer = context.linkHasNoReferrer;
this.linkProtocol = context.linkProtocol;
this.linkTextStr = context.linkTextStr;
this.linkURL = context.linkURL;
@ -781,10 +791,7 @@ nsContextMenu.prototype = {
originPrincipal: this.principal,
triggeringPrincipal: this.principal,
csp: this.csp,
referrerURI: gContextMenuContentData.documentURIObject,
referrerPolicy: gContextMenuContentData.referrerPolicy,
frameOuterWindowID: gContextMenuContentData.frameOuterWindowID,
noReferrer: this.linkHasNoReferrer || this.onPlainTextLink };
frameOuterWindowID: gContextMenuContentData.frameOuterWindowID};
for (let p in extra) {
params[p] = extra[p];
}
@ -795,13 +802,16 @@ nsContextMenu.prototype = {
params.frameOuterWindowID = this.frameOuterWindowID;
}
let referrerInfo = gContextMenuContentData.referrerInfo;
// If we want to change userContextId, we must be sure that we don't
// propagate the referrer.
if ("userContextId" in params &&
params.userContextId != gContextMenuContentData.userContextId) {
params.noReferrer = true;
if (("userContextId" in params &&
params.userContextId != gContextMenuContentData.userContextId) ||
this.onPlainTextLink) {
referrerInfo.sendReferrer = false;
}
params.referrerInfo = referrerInfo;
return params;
},
@ -850,11 +860,10 @@ nsContextMenu.prototype = {
// Open frame in a new tab.
openFrameInTab() {
let referrer = gContextMenuContentData.referrer;
openLinkIn(gContextMenuContentData.docLocation, "tab",
{ charset: gContextMenuContentData.charSet,
triggeringPrincipal: this.browser.contentPrincipal,
referrerURI: referrer ? makeURI(referrer) : null });
referrerInfo: gContextMenuContentData.frameReferrerInfo });
},
// Reload clicked-in frame.
@ -866,11 +875,10 @@ nsContextMenu.prototype = {
// Open clicked-in frame in its own window.
openFrame() {
let referrer = gContextMenuContentData.referrer;
openLinkIn(gContextMenuContentData.docLocation, "window",
{ charset: gContextMenuContentData.charSet,
triggeringPrincipal: this.browser.contentPrincipal,
referrerURI: referrer ? makeURI(referrer) : null });
referrerInfo: gContextMenuContentData.frameReferrerInfo });
},
// Open clicked-in frame in the same window.
@ -878,9 +886,8 @@ nsContextMenu.prototype = {
urlSecurityCheck(gContextMenuContentData.docLocation,
this.browser.contentPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
let referrer = gContextMenuContentData.referrer;
openWebLinkIn(gContextMenuContentData.docLocation, "current", {
referrerURI: referrer ? makeURI(referrer) : null,
referrerInfo: gContextMenuContentData.frameReferrerInfo,
triggeringPrincipal: this.browser.contentPrincipal,
});
},
@ -933,7 +940,7 @@ nsContextMenu.prototype = {
urlSecurityCheck(this.imageDescURL,
this.principal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
openUILink(this.imageDescURL, e, { referrerURI: gContextMenuContentData.documentURIObject,
openUILink(this.imageDescURL, e, { referrerInfo: gContextMenuContentData.referrerInfo,
triggeringPrincipal: this.principal,
});
},
@ -967,18 +974,18 @@ nsContextMenu.prototype = {
// Change current window to the URL of the image, video, or audio.
viewMedia(e) {
let referrerURI = gContextMenuContentData.documentURIObject;
let referrerInfo = gContextMenuContentData.referrerInfo;
let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
if (this.onCanvas) {
this._canvasToBlobURL(this.target).then(function(blobURL) {
openUILink(blobURL, e, { referrerURI,
openUILink(blobURL, e, { referrerInfo,
triggeringPrincipal: systemPrincipal});
}, Cu.reportError);
} else {
urlSecurityCheck(this.mediaURL,
this.principal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
openUILink(this.mediaURL, e, { referrerURI,
openUILink(this.mediaURL, e, { referrerInfo,
forceAllowDataURI: true,
triggeringPrincipal: this.principal,
});
@ -1035,7 +1042,7 @@ nsContextMenu.prototype = {
this.principal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
openUILink(this.bgImageURL, e, { referrerURI: gContextMenuContentData.documentURIObject,
openUILink(this.bgImageURL, e, { referrerInfo: gContextMenuContentData.referrerInfo,
triggeringPrincipal: this.principal,
});
},

View File

@ -282,7 +282,7 @@ window._gBrowser = {
_setupInitialBrowserAndTab() {
// See browser.js for the meaning of window.arguments.
// Bug 1485961 covers making this more sane.
let userContextId = window.arguments && window.arguments[6];
let userContextId = window.arguments && window.arguments[5];
let tabArgument = gBrowserInit.getTabToAdopt();
@ -1386,9 +1386,9 @@ window._gBrowser = {
return true;
},
loadOneTab(aURI, aReferrerURI, aCharset, aPostData, aLoadInBackground, aAllowThirdPartyFixup) {
loadOneTab(aURI, aReferrerInfoOrParams, aCharset, aPostData, aLoadInBackground, aAllowThirdPartyFixup) {
var aTriggeringPrincipal;
var aReferrerPolicy;
var aReferrerInfo;
var aFromExternal;
var aRelatedToCurrent;
var aAllowInheritPrincipal;
@ -1396,7 +1396,6 @@ window._gBrowser = {
var aSkipAnimation;
var aForceNotRemote;
var aPreferredRemoteType;
var aNoReferrer;
var aUserContextId;
var aSameProcessAsFrameLoader;
var aOriginPrincipal;
@ -1412,8 +1411,7 @@ window._gBrowser = {
!(arguments[1] instanceof Ci.nsIURI)) {
let params = arguments[1];
aTriggeringPrincipal = params.triggeringPrincipal;
aReferrerURI = params.referrerURI;
aReferrerPolicy = params.referrerPolicy;
aReferrerInfo = params.referrerInfo;
aCharset = params.charset;
aPostData = params.postData;
aLoadInBackground = params.inBackground;
@ -1425,7 +1423,6 @@ window._gBrowser = {
aSkipAnimation = params.skipAnimation;
aForceNotRemote = params.forceNotRemote;
aPreferredRemoteType = params.preferredRemoteType;
aNoReferrer = params.noReferrer;
aUserContextId = params.userContextId;
aSameProcessAsFrameLoader = params.sameProcessAsFrameLoader;
aOriginPrincipal = params.originPrincipal;
@ -1449,8 +1446,7 @@ window._gBrowser = {
var tab = this.addTab(aURI, {
triggeringPrincipal: aTriggeringPrincipal,
referrerURI: aReferrerURI,
referrerPolicy: aReferrerPolicy,
referrerInfo: aReferrerInfo,
charset: aCharset,
postData: aPostData,
ownerTab: owner,
@ -1463,7 +1459,6 @@ window._gBrowser = {
forceNotRemote: aForceNotRemote,
createLazyBrowser: aCreateLazyBrowser,
preferredRemoteType: aPreferredRemoteType,
noReferrer: aNoReferrer,
userContextId: aUserContextId,
originPrincipal: aOriginPrincipal,
sameProcessAsFrameLoader: aSameProcessAsFrameLoader,
@ -2344,7 +2339,6 @@ window._gBrowser = {
name,
nextTabParentId,
noInitialLabel,
noReferrer,
opener,
openerBrowser,
originPrincipal,
@ -2352,8 +2346,7 @@ window._gBrowser = {
pinned,
postData,
preferredRemoteType,
referrerPolicy,
referrerURI,
referrerInfo,
relatedToCurrent,
sameProcessAsFrameLoader,
skipAnimation,
@ -2385,13 +2378,13 @@ window._gBrowser = {
//
// Otherwise, if the tab is related to the current tab (e.g.,
// because it was opened by a link click), use the selected tab as
// the owner. If referrerURI is set, and we don't have an
// the owner. If referrerInfo is set, and we don't have an
// explicit relatedToCurrent arg, we assume that the tab is
// related to the current tab, since referrerURI is null or
// undefined if the tab is opened from an external application or
// bookmark (i.e. somewhere other than an existing tab).
if (relatedToCurrent == null) {
relatedToCurrent = !!referrerURI;
relatedToCurrent = !!(referrerInfo && referrerInfo.originalReferrer);
}
let openerTab = ((openerBrowser && this.getTabForBrowser(openerBrowser)) ||
(relatedToCurrent && this.selectedTab));
@ -2537,9 +2530,11 @@ window._gBrowser = {
// If URI is about:blank and we don't have a preferred remote type,
// then we need to use the referrer, if we have one, to get the
// correct remote type for the new tab.
if (uriIsAboutBlank && !preferredRemoteType && referrerURI) {
if (uriIsAboutBlank && !preferredRemoteType && referrerInfo &&
referrerInfo.originalReferrer) {
preferredRemoteType =
E10SUtils.getRemoteTypeForURI(referrerURI.spec, gMultiProcessBrowser);
E10SUtils.getRemoteTypeForURI(referrerInfo.originalReferrer.spec,
gMultiProcessBrowser);
}
let remoteType =
@ -2667,16 +2662,11 @@ window._gBrowser = {
if (!allowInheritPrincipal) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL;
}
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
try {
b.loadURI(aURI, {
flags,
triggeringPrincipal,
referrerInfo: new ReferrerInfo(
referrerPolicy, !noReferrer, referrerURI),
referrerInfo,
charset,
postData,
csp,

View File

@ -10,8 +10,14 @@ add_task(async function() {
// returning a list of opened tabs for verifying the expected order.
// The new tab behaviour is documented in bug 465673
let tabs = [];
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
function addTab(aURL, aReferrer) {
let tab = BrowserTestUtils.addTab(gBrowser, aURL, {referrerURI: aReferrer});
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, aReferrer);
let tab = BrowserTestUtils.addTab(gBrowser, aURL, { referrerInfo });
tabs.push(tab);
return BrowserTestUtils.browserLoaded(tab.linkedBrowser);
}

View File

@ -102,10 +102,10 @@ function doGetProtocolFlags(aURI) {
* @param {Boolean} aIgnoreAlt
* @param {Boolean} aAllowThirdPartyFixup
* @param {Object} aPostData
* @param {nsIURI} aReferrerURI
* @param {Object} aReferrerInfo
*/
function openUILink(url, event, aIgnoreButton, aIgnoreAlt, aAllowThirdPartyFixup,
aPostData, aReferrerURI) {
aPostData, aReferrerInfo) {
event = getRootEvent(event);
let params;
@ -121,8 +121,7 @@ function openUILink(url, event, aIgnoreButton, aIgnoreAlt, aAllowThirdPartyFixup
params = {
allowThirdPartyFixup: aAllowThirdPartyFixup,
postData: aPostData,
referrerURI: aReferrerURI,
referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
referrerInfo: aReferrerInfo,
initiatingDoc: event ? event.target.ownerDocument : null,
};
}
@ -280,7 +279,7 @@ function openWebLinkIn(url, where, params) {
* these properties:
* allowThirdPartyFixup (boolean)
* postData (nsIInputStream)
* referrerURI (nsIURI)
* referrerInfo (nsIReferrerInfo)
* relatedToCurrent (boolean)
* skipTabAnimation (boolean)
* allowPinnedTabHostChange (boolean)
@ -288,7 +287,7 @@ function openWebLinkIn(url, where, params) {
* userContextId (unsigned int)
* targetBrowser (XUL browser)
*/
function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI) {
function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerInfo) {
var params;
if (arguments.length == 3 && typeof arguments[2] == "object") {
@ -307,14 +306,17 @@ function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI
function openLinkIn(url, where, params) {
if (!where || !url)
return;
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
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 aReferrerInfo = ("referrerInfo" in params)
? params.referrerInfo
: new ReferrerInfo(Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, null);
var aRelatedToCurrent = params.relatedToCurrent;
var aAllowInheritPrincipal = !!params.allowInheritPrincipal;
var aAllowMixedContent = params.allowMixedContent;
@ -324,7 +326,6 @@ function openLinkIn(url, where, params) {
var aIsPrivate = params.private;
var aSkipTabAnimation = params.skipTabAnimation;
var aAllowPinnedTabHostChange = !!params.allowPinnedTabHostChange;
var aNoReferrer = params.noReferrer;
var aAllowPopups = !!params.allowPopups;
var aUserContextId = params.userContextId;
var aIndicateErrorPageLoad = params.indicateErrorPageLoad;
@ -341,10 +342,9 @@ function openLinkIn(url, where, params) {
if (where == "save") {
// TODO(1073187): propagate referrerPolicy.
// ContentClick.jsm passes isContentWindowPrivate for saveURL instead of passing a CPOW initiatingDoc
if ("isContentWindowPrivate" in params) {
saveURL(url, null, null, true, true, aNoReferrer ? null : aReferrerURI,
saveURL(url, null, null, true, true, aReferrerInfo.sendReferrer ? aReferrerInfo.originalReferrer : null,
null, params.isContentWindowPrivate, aPrincipal);
} else {
if (!aInitiatingDoc) {
@ -352,7 +352,7 @@ function openLinkIn(url, where, params) {
"where == 'save' but without initiatingDoc. See bug 814264.");
return;
}
saveURL(url, null, null, true, true, aNoReferrer ? null : aReferrerURI, aInitiatingDoc);
saveURL(url, null, null, true, true, aReferrerInfo.sendReferrer ? aReferrerInfo.originalReferrer : null, aInitiatingDoc);
}
return;
}
@ -396,7 +396,7 @@ function openLinkIn(url, where, params) {
features += ",private";
// To prevent regular browsing data from leaking to private browsing sites,
// strip the referrer when opening a new private window. (See Bug: 1409226)
aNoReferrer = true;
aReferrerInfo.sendReferrer = false;
}
// This propagates to window.arguments.
@ -418,27 +418,15 @@ function openLinkIn(url, where, params) {
createInstance(Ci.nsISupportsPRBool);
allowThirdPartyFixupSupports.data = aAllowThirdPartyFixup;
var referrerURISupports = null;
if (aReferrerURI && !aNoReferrer) {
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(charset);
sa.appendElement(referrerURISupports);
sa.appendElement(aReferrerInfo);
sa.appendElement(aPostData);
sa.appendElement(allowThirdPartyFixupSupports);
sa.appendElement(referrerPolicySupports);
sa.appendElement(userContextIdSupports);
sa.appendElement(aPrincipal);
sa.appendElement(aTriggeringPrincipal);
@ -558,15 +546,11 @@ function openLinkIn(url, where, params) {
remoteType: E10SUtils.DEFAULT_REMOTE_TYPE });
}
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
targetBrowser.loadURI(url, {
triggeringPrincipal: aTriggeringPrincipal,
csp: aCsp,
referrerInfo: new ReferrerInfo(
aReferrerPolicy, !aNoReferrer, aReferrerURI),
flags,
referrerInfo: aReferrerInfo,
postData: aPostData,
userContextId: aUserContextId,
});
@ -584,8 +568,7 @@ function openLinkIn(url, where, params) {
&& !aboutNewTabService.willNotifyUser;
let tabUsedForLoad = w.gBrowser.loadOneTab(url, {
referrerURI: aReferrerURI,
referrerPolicy: aReferrerPolicy,
referrerInfo: aReferrerInfo,
charset: aCharset,
postData: aPostData,
inBackground: loadInBackground,
@ -593,7 +576,6 @@ function openLinkIn(url, where, params) {
relatedToCurrent: aRelatedToCurrent,
skipAnimation: aSkipTabAnimation,
allowMixedContent: aAllowMixedContent,
noReferrer: aNoReferrer,
userContextId: aUserContextId,
originPrincipal: aPrincipal,
triggeringPrincipal: aTriggeringPrincipal,

View File

@ -245,11 +245,10 @@ function openBrowserWindow(cmdLine, triggeringPrincipal, urlOrUrlList, postData
// Also, we need to pass the triggering principal.
args = [urlOrUrlList,
null, // charset
null, // referer
null, // refererInfo
postData,
undefined, // allowThirdPartyFixup; this would be `false` but that
// needs a conversion. Hopefully bug 1485961 will fix.
undefined, // referrer policy
undefined, // user context id
null, // origin principal
triggeringPrincipal];

View File

@ -6,6 +6,9 @@
add_task(async function() {
let tab = BrowserTestUtils.addTab(gBrowser, "about:blank", {userContextId: 1});
let ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init");
gBrowser.selectedTab = tab;
let relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {relatedToCurrent: true});
@ -18,12 +21,16 @@ add_task(async function() {
BrowserTestUtils.removeTab(relatedTab);
gBrowser.selectedTab = tab;
relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {referrerURI: gBrowser.currentURI});
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, gBrowser.currentURI);
relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", { referrerInfo });
is(relatedTab.getAttribute("usercontextid"), 1, "Related tab (referrer) inherits current tab's usercontextid");
BrowserTestUtils.removeTab(relatedTab);
gBrowser.selectedTab = tab;
relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {referrerURI: gBrowser.currentURI, userContextId: 2});
referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, gBrowser.currentURI);
relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", { referrerInfo, userContextId: 2});
is(relatedTab.getAttribute("usercontextid"), 2, "Related tab (referrer) with overridden usercontextid");
BrowserTestUtils.removeTab(relatedTab);

View File

@ -24,7 +24,6 @@ function openWindowWithUserContextId(userContextId, isPrivate) {
args.appendElement(null);
args.appendElement(null);
args.appendElement(null);
args.appendElement(null);
let userContextIdSupports = Cc["@mozilla.org/supports-PRUint32;1"].createInstance(Ci.nsISupportsPRUint32);
userContextIdSupports.data = userContextId;

View File

@ -204,10 +204,9 @@ this.windows = class extends ExtensionAPI {
}
args.appendElement(null); // unused
args.appendElement(null); // referrer
args.appendElement(null); // referrerInfo
args.appendElement(null); // postData
args.appendElement(null); // allowThirdPartyFixup
args.appendElement(null); // referrerPolicy
if (createData.cookieStoreId) {
let userContextIdSupports = Cc["@mozilla.org/supports-PRUint32;1"].createInstance(Ci.nsISupportsPRUint32);

View File

@ -71,9 +71,7 @@ var ContentClick = {
let params = {
charset: browser.characterSet,
referrerURI: browser.documentURI,
referrerPolicy: json.referrerPolicy,
noReferrer: json.noReferrer,
referrerInfo: E10SUtils.deserializeReferrerInfo(json.referrerInfo),
allowMixedContent: json.allowMixedContent,
isContentWindowPrivate: json.isContentWindowPrivate,
originPrincipal: json.originPrincipal,

View File

@ -99,7 +99,7 @@ function loadMochitest(e) {
// for mochitest-plain, navigating to the url is all we need
if (!IS_THUNDERBIRD) {
win.loadURI(url, null, null, null, null, null, null, null,
win.loadURI(url, null, null, null, null, null, null,
Services.scriptSecurityManager.getSystemPrincipal());
}
if (flavor == "mochitest") {