From 74858918fa2445f7e4ebc4b615ec073d528039f1 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Mon, 30 Apr 2018 22:57:23 +0200 Subject: Bug 1329032 - Extend loadURIWithOptions by a triggeringPrincipal (without an hard e10s) --- browser/components/sessionstore/ContentRestore.jsm | 5 ++++- .../responsive.html/browser/web-navigation.js | 8 ++++++-- docshell/base/nsDocShell.cpp | 8 +++++--- docshell/base/nsIWebNavigation.idl | 23 ++++++++++++++-------- docshell/shistory/nsSHistory.cpp | 3 ++- dom/base/nsContentUtils.cpp | 6 +++++- embedding/browser/nsIWebBrowserChrome3.idl | 9 +++++++-- embedding/browser/nsWebBrowser.cpp | 5 +++-- xpfe/appshell/nsContentTreeOwner.cpp | 5 ++++- xpfe/appshell/nsIXULBrowserWindow.idl | 6 +++++- 10 files changed, 56 insertions(+), 22 deletions(-) diff --git a/browser/components/sessionstore/ContentRestore.jsm b/browser/components/sessionstore/ContentRestore.jsm index 976016770..d4972bcaf 100644 --- a/browser/components/sessionstore/ContentRestore.jsm +++ b/browser/components/sessionstore/ContentRestore.jsm @@ -204,6 +204,9 @@ ContentRestoreInternal.prototype = { : Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT); let postData = loadArguments.postData ? Utils.makeInputStream(loadArguments.postData) : null; + let triggeringPrincipal = loadArguments.triggeringPrincipal + ? Utils.deserializePrincipal(loadArguments.triggeringPrincipal) + : null; if (loadArguments.userContextId) { webNavigation.setOriginAttributesBeforeLoading({ userContextId: loadArguments.userContextId }); @@ -211,7 +214,7 @@ ContentRestoreInternal.prototype = { webNavigation.loadURIWithOptions(loadArguments.uri, loadArguments.flags, referrer, referrerPolicy, postData, - null, null); + null, null, triggeringPrincipal); } else if (tabData.userTypedValue && tabData.userTypedClear) { // If the user typed a URL into the URL bar and hit enter right before // we crashed, we want to start loading that page again. A non-zero diff --git a/devtools/client/responsive.html/browser/web-navigation.js b/devtools/client/responsive.html/browser/web-navigation.js index 4519df0bd..eee24993a 100644 --- a/devtools/client/responsive.html/browser/web-navigation.js +++ b/devtools/client/responsive.html/browser/web-navigation.js @@ -8,6 +8,7 @@ const { Ci, Cu, Cr } = require("chrome"); const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); const Services = require("Services"); const { NetUtil } = require("resource://gre/modules/NetUtil.jsm"); +const { Utils } = require("resource://gre/modules/sessionstore/Utils.jsm"); function readInputStreamToString(stream) { return NetUtil.readInputStreamToString(stream, stream.available()); @@ -61,11 +62,11 @@ BrowserElementWebNavigation.prototype = { // No equivalent in the current BrowserElement API this.loadURIWithOptions(uri, flags, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT, - postData, headers, null); + postData, headers, null, null); }, loadURIWithOptions(uri, flags, referrer, referrerPolicy, postData, headers, - baseURI) { + baseURI, triggeringPrincipal) { // No equivalent in the current BrowserElement API this._sendMessage("WebNavigation:LoadURI", { uri, @@ -75,6 +76,9 @@ BrowserElementWebNavigation.prototype = { postData: postData ? readInputStreamToString(postData) : null, headers: headers ? readInputStreamToString(headers) : null, baseURI: baseURI ? baseURI.spec : null, + triggeringPrincipal: triggeringPrincipal + ? Utils.serializePrincipal(triggeringPrincipal) + : null, }); }, diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d67941620..d7cb557ab 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4732,7 +4732,7 @@ nsDocShell::LoadURI(const char16_t* aURI, { return LoadURIWithOptions(aURI, aLoadFlags, aReferringURI, mozilla::net::RP_Default, aPostStream, - aHeaderStream, nullptr); + aHeaderStream, nullptr, nullptr); } NS_IMETHODIMP @@ -4742,7 +4742,8 @@ nsDocShell::LoadURIWithOptions(const char16_t* aURI, uint32_t aReferrerPolicy, nsIInputStream* aPostStream, nsIInputStream* aHeaderStream, - nsIURI* aBaseURI) + nsIURI* aBaseURI, + nsIPrincipal* aTriggeringPrincipal) { NS_ASSERTION((aLoadFlags & 0xf) == 0, "Unexpected flags"); @@ -4861,6 +4862,7 @@ nsDocShell::LoadURIWithOptions(const char16_t* aURI, loadInfo->SetReferrerPolicy(aReferrerPolicy); loadInfo->SetHeadersStream(aHeaderStream); loadInfo->SetBaseURI(aBaseURI); + loadInfo->SetTriggeringPrincipal(aTriggeringPrincipal); loadInfo->SetForceAllowDataURI(forceAllowDataURI); if (fixupInfo) { @@ -10606,7 +10608,7 @@ nsDocShell::InternalLoad(nsIURI* aURI, } bool shouldLoad; rv = browserChrome3->ShouldLoadURI(this, uriForShouldLoadCheck, aReferrer, - &shouldLoad); + aTriggeringPrincipal, &shouldLoad); if (NS_SUCCEEDED(rv) && !shouldLoad) { return NS_OK; } diff --git a/docshell/base/nsIWebNavigation.idl b/docshell/base/nsIWebNavigation.idl index 241d0731c..c3e2fc550 100644 --- a/docshell/base/nsIWebNavigation.idl +++ b/docshell/base/nsIWebNavigation.idl @@ -9,6 +9,7 @@ interface nsIDOMDocument; interface nsIInputStream; interface nsISHistory; interface nsIURI; +interface nsIPrincipal; /** * The nsIWebNavigation interface defines an interface for navigating the web. @@ -288,14 +289,20 @@ interface nsIWebNavigation : nsISupports * that at present this argument is only used with view-source aURIs * and cannot be used to resolve aURI. * This parameter is optional and may be null. - */ - void loadURIWithOptions(in wstring aURI, - in unsigned long aLoadFlags, - in nsIURI aReferrer, - in unsigned long aReferrerPolicy, - in nsIInputStream aPostData, - in nsIInputStream aHeaders, - in nsIURI aBaseURI); + * @param aTriggeringPrincipal + * The principal that initiated the load of aURI. If omitted docShell + * tries to create a codeBasePrincipal from aReferrer if not null. If + * aReferrer is also null docShell peforms a load using the + * SystemPrincipal as the triggeringPrincipal. + */ + void loadURIWithOptions(in wstring aURI, + in unsigned long aLoadFlags, + in nsIURI aReferrer, + in unsigned long aReferrerPolicy, + in nsIInputStream aPostData, + in nsIInputStream aHeaders, + in nsIURI aBaseURI, + [optional] in nsIPrincipal aTriggeringPrincipal); /** * Tells the Object to reload the current page. There may be cases where the diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index 7c148ffcc..9443b92bc 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -1582,7 +1582,8 @@ nsSHistory::LoadURIWithOptions(const char16_t* aURI, uint32_t aReferrerPolicy, nsIInputStream* aPostStream, nsIInputStream* aExtraHeaderStream, - nsIURI* aBaseURI) + nsIURI* aBaseURI, + nsIPrincipal* aTriggeringPrincipal) { return NS_OK; } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 76463df16..34c7d23b8 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -9776,9 +9776,13 @@ nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel) rv = aChannel->GetReferrer(getter_AddRefs(referrer)); NS_ENSURE_SUCCESS(rv, false); + nsCOMPtr loadInfo = aChannel->GetLoadInfo(); + nsCOMPtr triggeringPrincipal = loadInfo->TriggeringPrincipal(); + // Actually perform the cross process load bool reloadSucceeded = false; - rv = wbc3->ReloadInFreshProcess(docShell, uri, referrer, &reloadSucceeded); + rv = wbc3->ReloadInFreshProcess(docShell, uri, referrer, + triggeringPrincipal, &reloadSucceeded); NS_ENSURE_SUCCESS(rv, false); return reloadSucceeded; diff --git a/embedding/browser/nsIWebBrowserChrome3.idl b/embedding/browser/nsIWebBrowserChrome3.idl index a95cab911..d78a1d63b 100644 --- a/embedding/browser/nsIWebBrowserChrome3.idl +++ b/embedding/browser/nsIWebBrowserChrome3.idl @@ -8,6 +8,7 @@ interface nsIDocShell; interface nsIInputStream; +interface nsIPrincipal; /** * nsIWebBrowserChrome3 is an extension to nsIWebBrowserChrome2. @@ -43,10 +44,13 @@ interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2 * The URI being loaded. * @param aReferrer * The referrer of the load. + * @param aTriggeringPrincipal + * The principal that initiated the load of aURI. */ bool shouldLoadURI(in nsIDocShell aDocShell, in nsIURI aURI, - in nsIURI aReferrer); + in nsIURI aReferrer, + in nsIPrincipal aTriggeringPrincipal); /** * Attempts to load the currently loaded page into a fresh process to increase @@ -57,5 +61,6 @@ interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2 */ bool reloadInFreshProcess(in nsIDocShell aDocShell, in nsIURI aURI, - in nsIURI aReferrer); + in nsIURI aReferrer, + in nsIPrincipal aTriggeringPrincipal); }; diff --git a/embedding/browser/nsWebBrowser.cpp b/embedding/browser/nsWebBrowser.cpp index 655aa1e43..c034fc03e 100644 --- a/embedding/browser/nsWebBrowser.cpp +++ b/embedding/browser/nsWebBrowser.cpp @@ -654,13 +654,14 @@ nsWebBrowser::LoadURIWithOptions(const char16_t* aURI, uint32_t aLoadFlags, uint32_t aReferrerPolicy, nsIInputStream* aPostDataStream, nsIInputStream* aExtraHeaderStream, - nsIURI* aBaseURI) + nsIURI* aBaseURI, + nsIPrincipal* aTriggeringPrincipal) { NS_ENSURE_STATE(mDocShell); return mDocShellAsNav->LoadURIWithOptions( aURI, aLoadFlags, aReferringURI, aReferrerPolicy, aPostDataStream, - aExtraHeaderStream, aBaseURI); + aExtraHeaderStream, aBaseURI, aTriggeringPrincipal); } NS_IMETHODIMP diff --git a/xpfe/appshell/nsContentTreeOwner.cpp b/xpfe/appshell/nsContentTreeOwner.cpp index b39b7610f..f0fcdef9a 100644 --- a/xpfe/appshell/nsContentTreeOwner.cpp +++ b/xpfe/appshell/nsContentTreeOwner.cpp @@ -390,6 +390,7 @@ NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &origina NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell, nsIURI *aURI, nsIURI *aReferrer, + nsIPrincipal* aTriggeringPrincipal, bool *_retval) { NS_ENSURE_STATE(mXULWindow); @@ -398,7 +399,8 @@ NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell, mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); if (xulBrowserWindow) - return xulBrowserWindow->ShouldLoadURI(aDocShell, aURI, aReferrer, _retval); + return xulBrowserWindow->ShouldLoadURI(aDocShell, aURI, aReferrer, + aTriggeringPrincipal, _retval); *_retval = true; return NS_OK; @@ -407,6 +409,7 @@ NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell, NS_IMETHODIMP nsContentTreeOwner::ReloadInFreshProcess(nsIDocShell* aDocShell, nsIURI* aURI, nsIURI* aReferrer, + nsIPrincipal* aTriggeringPrincipal, bool* aRetVal) { NS_WARNING("Cannot reload in fresh process from a nsContentTreeOwner!"); diff --git a/xpfe/appshell/nsIXULBrowserWindow.idl b/xpfe/appshell/nsIXULBrowserWindow.idl index 40f1898c8..5dbc2d409 100644 --- a/xpfe/appshell/nsIXULBrowserWindow.idl +++ b/xpfe/appshell/nsIXULBrowserWindow.idl @@ -13,6 +13,7 @@ interface nsIDOMElement; interface nsIInputStream; interface nsIDocShell; interface nsITabParent; +interface nsIPrincipal; interface mozIDOMWindowProxy; /** @@ -60,10 +61,13 @@ interface nsIXULBrowserWindow : nsISupports * The URI being loaded. * @param aReferrer * The referrer of the load. + * @param aTriggeringPrincipal + * The principal that initiated the load of aURI. */ bool shouldLoadURI(in nsIDocShell aDocShell, in nsIURI aURI, - in nsIURI aReferrer); + in nsIURI aReferrer, + in nsIPrincipal aTriggeringPrincipal); /** * Show/hide a tooltip (when the user mouses over a link, say). */ -- cgit v1.2.3