mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1113196
- Pass a sane set of parameters to loadinfo for top-level loads in e10s. r=sicking
This commit is contained in:
parent
451223aa33
commit
456e54eb3b
@ -10570,11 +10570,39 @@ nsDocShell::DoURILoad(nsIURI* aURI,
|
||||
|
||||
bool isSrcdoc = !aSrcdoc.IsVoid();
|
||||
|
||||
// There are three cases we care about:
|
||||
// * Null mScriptGlobal: shouldn't happen but does (see bug 1240246). In this
|
||||
// case, we create a loadingPrincipal as for a top-level load, but we leave
|
||||
// requestingNode and requestingWindow null.
|
||||
// * Top-level load (GetFrameElementInternal returns null). In this case,
|
||||
// requestingNode is null, but requestingWindow is our mScriptGlobal.
|
||||
// TODO we want to pass null for loadingPrincipal in this case.
|
||||
// * Subframe load: requestingWindow is null, but requestingNode is the frame
|
||||
// element for the load. loadingPrincipal is the NodePrincipal of the frame
|
||||
// element.
|
||||
nsCOMPtr<nsINode> requestingNode;
|
||||
nsCOMPtr<nsPIDOMWindowOuter> requestingWindow;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> loadingPrincipal;
|
||||
if (mScriptGlobal) {
|
||||
requestingNode = mScriptGlobal->AsOuter()->GetFrameElementInternal();
|
||||
if (!requestingNode) {
|
||||
requestingNode = mScriptGlobal->GetExtantDoc();
|
||||
if (requestingNode) {
|
||||
// If we have a requesting node, then use that as our loadingPrincipal.
|
||||
loadingPrincipal = requestingNode->NodePrincipal();
|
||||
} else {
|
||||
MOZ_ASSERT(aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
|
||||
requestingWindow = mScriptGlobal->AsOuter();
|
||||
}
|
||||
}
|
||||
|
||||
if (!loadingPrincipal) {
|
||||
if (mItemType != typeChrome) {
|
||||
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
||||
ssm->GetDocShellCodebasePrincipal(aURI, this, getter_AddRefs(loadingPrincipal));
|
||||
} else {
|
||||
// This is a top-level chrome load, use a system principal for the
|
||||
// loadingPrincipal.
|
||||
loadingPrincipal = nsContentUtils::GetSystemPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
@ -10605,19 +10633,19 @@ nsDocShell::DoURILoad(nsIURI* aURI,
|
||||
securityFlags |= nsILoadInfo::SEC_SANDBOXED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo =
|
||||
requestingWindow ?
|
||||
new LoadInfo(requestingWindow, loadingPrincipal, triggeringPrincipal,
|
||||
securityFlags) :
|
||||
new LoadInfo(loadingPrincipal, triggeringPrincipal, requestingNode,
|
||||
securityFlags, aContentPolicyType);
|
||||
if (!isSrcdoc) {
|
||||
rv = NS_NewChannelInternal(getter_AddRefs(channel),
|
||||
aURI,
|
||||
requestingNode,
|
||||
requestingNode
|
||||
? requestingNode->NodePrincipal()
|
||||
: triggeringPrincipal.get(),
|
||||
triggeringPrincipal,
|
||||
securityFlags,
|
||||
aContentPolicyType,
|
||||
nullptr, // loadGroup
|
||||
static_cast<nsIInterfaceRequestor*>(this),
|
||||
loadFlags);
|
||||
loadInfo,
|
||||
nullptr, // loadGroup
|
||||
static_cast<nsIInterfaceRequestor*>(this),
|
||||
loadFlags);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
if (rv == NS_ERROR_UNKNOWN_PROTOCOL) {
|
||||
@ -10652,26 +10680,13 @@ nsDocShell::DoURILoad(nsIURI* aURI,
|
||||
NS_ENSURE_TRUE(vsh, NS_ERROR_FAILURE);
|
||||
|
||||
rv = vsh->NewSrcdocChannel(aURI, aBaseURI, aSrcdoc,
|
||||
requestingNode,
|
||||
requestingNode
|
||||
? requestingNode->NodePrincipal()
|
||||
: triggeringPrincipal.get(),
|
||||
triggeringPrincipal,
|
||||
securityFlags,
|
||||
aContentPolicyType,
|
||||
getter_AddRefs(channel));
|
||||
loadInfo, getter_AddRefs(channel));
|
||||
} else {
|
||||
rv = NS_NewInputStreamChannelInternal(getter_AddRefs(channel),
|
||||
aURI,
|
||||
aSrcdoc,
|
||||
NS_LITERAL_CSTRING("text/html"),
|
||||
requestingNode,
|
||||
requestingNode ?
|
||||
requestingNode->NodePrincipal() :
|
||||
triggeringPrincipal.get(),
|
||||
triggeringPrincipal,
|
||||
securityFlags,
|
||||
aContentPolicyType,
|
||||
loadInfo,
|
||||
true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIInputStreamChannel> isc = do_QueryInterface(channel);
|
||||
|
@ -24,6 +24,14 @@ using namespace mozilla::dom;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static void
|
||||
InheritOriginAttributes(nsIPrincipal* aLoadingPrincipal, NeckoOriginAttributes& aAttrs)
|
||||
{
|
||||
const PrincipalOriginAttributes attrs =
|
||||
BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
|
||||
aAttrs.InheritFromDocToNecko(attrs);
|
||||
}
|
||||
|
||||
LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
nsINode* aLoadingContext,
|
||||
@ -97,8 +105,46 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
|
||||
aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(true));
|
||||
}
|
||||
|
||||
const PrincipalOriginAttributes attrs = BasePrincipal::Cast(mLoadingPrincipal)->OriginAttributesRef();
|
||||
mOriginAttributes.InheritFromDocToNecko(attrs);
|
||||
InheritOriginAttributes(mLoadingPrincipal, mOriginAttributes);
|
||||
}
|
||||
|
||||
LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags)
|
||||
: mLoadingPrincipal(aLoadingPrincipal)
|
||||
, mTriggeringPrincipal(aTriggeringPrincipal)
|
||||
, mSecurityFlags(aSecurityFlags)
|
||||
, mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT)
|
||||
, mTainting(LoadTainting::Basic)
|
||||
, mUpgradeInsecureRequests(false)
|
||||
, mInnerWindowID(0)
|
||||
, mOuterWindowID(0)
|
||||
, mParentOuterWindowID(0)
|
||||
, mEnforceSecurity(false)
|
||||
, mInitialSecurityCheckDone(false)
|
||||
, mIsThirdPartyContext(false) // NB: TYPE_DOCUMENT implies not third-party.
|
||||
, mForcePreflight(false)
|
||||
, mIsPreflight(false)
|
||||
{
|
||||
// Top-level loads are never third-party
|
||||
// Grab the information we can out of the window.
|
||||
MOZ_ASSERT(aOuterWindow);
|
||||
|
||||
// if the load is sandboxed, we can not also inherit the principal
|
||||
if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) {
|
||||
mSecurityFlags ^= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
|
||||
}
|
||||
|
||||
// NB: Ignore the current inner window since we're navigating away from it.
|
||||
mOuterWindowID = aOuterWindow->WindowID();
|
||||
|
||||
// TODO We can have a parent without a frame element in some cases dealing
|
||||
// with the hidden window.
|
||||
nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent();
|
||||
mParentOuterWindowID = parent ? parent->WindowID() : 0;
|
||||
|
||||
InheritOriginAttributes(mLoadingPrincipal, mOriginAttributes);
|
||||
}
|
||||
|
||||
LoadInfo::LoadInfo(const LoadInfo& rhs)
|
||||
|
@ -54,6 +54,12 @@ public:
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType);
|
||||
|
||||
// Constructor used for TYPE_DOCUMENT loads with no reasonable loadingNode.
|
||||
LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
|
||||
nsIPrincipal* aLoadingPrincipal,
|
||||
nsIPrincipal* aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags);
|
||||
|
||||
// create an exact copy of the loadinfo
|
||||
already_AddRefed<nsILoadInfo> Clone() const;
|
||||
// creates a copy of the loadinfo which is appropriate to use for a
|
||||
|
@ -371,11 +371,7 @@ NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
nsIURI *aUri,
|
||||
const nsAString &aData,
|
||||
const nsACString &aContentType,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
nsILoadInfo *aLoadInfo,
|
||||
bool aIsSrcdocChannel /* = false */)
|
||||
{
|
||||
nsresult rv;
|
||||
@ -398,11 +394,7 @@ NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
stream,
|
||||
aContentType,
|
||||
NS_LITERAL_CSTRING("UTF-8"),
|
||||
aLoadingNode,
|
||||
aLoadingPrincipal,
|
||||
aTriggeringPrincipal,
|
||||
aSecurityFlags,
|
||||
aContentPolicyType);
|
||||
aLoadInfo);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@ -415,6 +407,25 @@ NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
nsIURI *aUri,
|
||||
const nsAString &aData,
|
||||
const nsACString &aContentType,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
bool aIsSrcdocChannel /* = false */)
|
||||
{
|
||||
nsCOMPtr<nsILoadInfo> loadInfo =
|
||||
new mozilla::LoadInfo(aLoadingPrincipal, aTriggeringPrincipal,
|
||||
aLoadingNode, aSecurityFlags, aContentPolicyType);
|
||||
return NS_NewInputStreamChannelInternal(outChannel, aUri, aData, aContentType,
|
||||
loadInfo, aIsSrcdocChannel);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewInputStreamChannel(nsIChannel **outChannel,
|
||||
nsIURI *aUri,
|
||||
|
@ -317,6 +317,14 @@ nsresult NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
bool aIsSrcdocChannel = false);
|
||||
|
||||
nsresult
|
||||
NS_NewInputStreamChannelInternal(nsIChannel **outChannel,
|
||||
nsIURI *aUri,
|
||||
const nsAString &aData,
|
||||
const nsACString &aContentType,
|
||||
nsILoadInfo *aLoadInfo,
|
||||
bool aIsSrcdocChannel = false);
|
||||
|
||||
nsresult NS_NewInputStreamChannel(nsIChannel **outChannel,
|
||||
nsIURI *aUri,
|
||||
const nsAString &aData,
|
||||
|
@ -98,11 +98,7 @@ nsresult
|
||||
nsViewSourceChannel::InitSrcdoc(nsIURI* aURI,
|
||||
nsIURI* aBaseURI,
|
||||
const nsAString &aSrcdoc,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType)
|
||||
nsILoadInfo* aLoadInfo)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -118,11 +114,7 @@ nsViewSourceChannel::InitSrcdoc(nsIURI* aURI,
|
||||
inStreamURI,
|
||||
aSrcdoc,
|
||||
NS_LITERAL_CSTRING("text/html"),
|
||||
aLoadingNode,
|
||||
aLoadingPrincipal,
|
||||
aTriggeringPrincipal,
|
||||
aSecurityFlags,
|
||||
aContentPolicyType,
|
||||
aLoadInfo,
|
||||
true);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -53,11 +53,7 @@ public:
|
||||
nsresult InitSrcdoc(nsIURI* aURI,
|
||||
nsIURI* aBaseURI,
|
||||
const nsAString &aSrcdoc,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType);
|
||||
nsILoadInfo* aLoadInfo);
|
||||
|
||||
protected:
|
||||
~nsViewSourceChannel() {}
|
||||
|
@ -127,30 +127,18 @@ nsresult
|
||||
nsViewSourceHandler::NewSrcdocChannel(nsIURI *aURI,
|
||||
nsIURI *aBaseURI,
|
||||
const nsAString &aSrcdoc,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
nsILoadInfo* aLoadInfo,
|
||||
nsIChannel** outChannel)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
nsViewSourceChannel *channel = new nsViewSourceChannel();
|
||||
if (!channel) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(channel);
|
||||
RefPtr<nsViewSourceChannel> channel = new nsViewSourceChannel();
|
||||
|
||||
nsresult rv = channel->InitSrcdoc(aURI, aBaseURI, aSrcdoc,
|
||||
aLoadingNode, aLoadingPrincipal,
|
||||
aTriggeringPrincipal, aSecurityFlags,
|
||||
aContentPolicyType);
|
||||
nsresult rv = channel->InitSrcdoc(aURI, aBaseURI, aSrcdoc, aLoadInfo);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*outChannel = static_cast<nsIViewSourceChannel*>(channel);
|
||||
*outChannel = static_cast<nsIViewSourceChannel*>(channel.forget().take());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,7 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIPrincipal;
|
||||
class nsILoadInfo;
|
||||
|
||||
class nsViewSourceHandler final : public nsIProtocolHandler
|
||||
{
|
||||
@ -26,11 +25,7 @@ public:
|
||||
nsresult NewSrcdocChannel(nsIURI *aURI,
|
||||
nsIURI *aBaseURI,
|
||||
const nsAString &aSrcdoc,
|
||||
nsINode *aLoadingNode,
|
||||
nsIPrincipal *aLoadingPrincipal,
|
||||
nsIPrincipal *aTriggeringPrincipal,
|
||||
nsSecurityFlags aSecurityFlags,
|
||||
nsContentPolicyType aContentPolicyType,
|
||||
nsILoadInfo *aLoadInfo,
|
||||
nsIChannel** outChannel);
|
||||
|
||||
static nsViewSourceHandler* GetInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user