Bug 1329032 - Extend loadURIWithOptions by a triggeringPrincipal (without an hard e10s)

This commit is contained in:
janekptacijarabaci
2018-04-30 22:57:23 +02:00
parent 80edefc958
commit 74858918fa
10 changed files with 55 additions and 21 deletions
@@ -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
@@ -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,
});
},
+5 -3
View File
@@ -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;
}
+14 -7
View File
@@ -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.
* @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);
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
+2 -1
View File
@@ -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;
}
+5 -1
View File
@@ -9776,9 +9776,13 @@ nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel)
rv = aChannel->GetReferrer(getter_AddRefs(referrer));
NS_ENSURE_SUCCESS(rv, false);
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
nsCOMPtr<nsIPrincipal> 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;
+7 -2
View File
@@ -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);
};
+3 -2
View File
@@ -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
+4 -1
View File
@@ -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!");
+5 -1
View File
@@ -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).
*/