Bug 1182571: Fix nsILoadInfo->GetContentPolicyType API to be less ambigious. Audit and fix all users of it. r=ckerschb

This commit is contained in:
Jonas Sicking 2015-10-15 12:18:20 -07:00
parent b6743e865b
commit 81a15a3362
13 changed files with 63 additions and 55 deletions

View File

@ -486,7 +486,7 @@ TabParent::ShouldSwitchProcess(nsIChannel* aChannel)
nsCOMPtr<nsIURI> uri;
aChannel->GetURI(getter_AddRefs(uri));
LogChannelRelevantInfo(uri, loadingPrincipal, resultPrincipal,
loadInfo->GetContentPolicyType());
loadInfo->InternalContentPolicyType());
// Check if the signed package is loaded from the same origin.
bool sameOrigin = false;
@ -497,7 +497,7 @@ TabParent::ShouldSwitchProcess(nsIChannel* aChannel)
}
// If this is not a top level document, there's no need to switch process.
if (nsIContentPolicy::TYPE_DOCUMENT != loadInfo->GetContentPolicyType()) {
if (nsIContentPolicy::TYPE_DOCUMENT != loadInfo->InternalContentPolicyType()) {
LOG("Subresource of a document. No need to switch process.\n");
return false;
}

View File

@ -313,8 +313,7 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel,
nsCOMPtr<nsIURI> originalUri;
rv = oldChannel->GetOriginalURI(getter_AddRefs(originalUri));
NS_ENSURE_SUCCESS(rv, rv);
nsContentPolicyType policyType =
nsContentUtils::InternalContentPolicyTypeToExternal(loadInfo->GetContentPolicyType());
nsContentPolicyType policyType = loadInfo->GetExternalContentPolicyType();
int16_t aDecision = nsIContentPolicy::ACCEPT;
csp->ShouldLoad(policyType, // load type per nsIContentPolicy (uint32_t)

View File

@ -111,11 +111,12 @@ DoCORSChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo,
nsresult
DoContentSecurityChecks(nsIURI* aURI, nsILoadInfo* aLoadInfo)
{
nsContentPolicyType contentPolicyType = aLoadInfo->GetContentPolicyType();
nsCString mimeTypeGuess;
nsCOMPtr<nsINode> requestingContext = nullptr;
nsContentPolicyType contentPolicyType =
aLoadInfo->GetExternalContentPolicyType();
nsContentPolicyType internalContentPolicyType =
aLoadInfo->InternalContentPolicyType();
nsCString mimeTypeGuess;
nsCOMPtr<nsINode> requestingContext = nullptr;
switch(contentPolicyType) {
case nsIContentPolicy::TYPE_OTHER: {

View File

@ -235,7 +235,7 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
requestingPrincipalInfo,
triggeringPrincipalInfo,
aLoadInfo->GetSecurityFlags(),
aLoadInfo->GetContentPolicyType(),
aLoadInfo->InternalContentPolicyType(),
aLoadInfo->GetUpgradeInsecureRequests(),
aLoadInfo->GetInnerWindowID(),
aLoadInfo->GetOuterWindowID(),

View File

@ -30,7 +30,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
aTriggeringPrincipal : mLoadingPrincipal.get())
, mLoadingContext(do_GetWeakReference(aLoadingContext))
, mSecurityFlags(aSecurityFlags)
, mContentPolicyType(aContentPolicyType)
, mInternalContentPolicyType(aContentPolicyType)
, mUpgradeInsecureRequests(false)
, mInnerWindowID(0)
, mOuterWindowID(0)
@ -88,7 +88,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mTriggeringPrincipal(rhs.mTriggeringPrincipal)
, mLoadingContext(rhs.mLoadingContext)
, mSecurityFlags(rhs.mSecurityFlags)
, mContentPolicyType(rhs.mContentPolicyType)
, mInternalContentPolicyType(rhs.mInternalContentPolicyType)
, mUpgradeInsecureRequests(rhs.mUpgradeInsecureRequests)
, mInnerWindowID(rhs.mInnerWindowID)
, mOuterWindowID(rhs.mOuterWindowID)
@ -112,7 +112,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
: mLoadingPrincipal(aLoadingPrincipal)
, mTriggeringPrincipal(aTriggeringPrincipal)
, mSecurityFlags(aSecurityFlags)
, mContentPolicyType(aContentPolicyType)
, mInternalContentPolicyType(aContentPolicyType)
, mUpgradeInsecureRequests(aUpgradeInsecureRequests)
, mInnerWindowID(aInnerWindowID)
, mOuterWindowID(aOuterWindowID)
@ -242,16 +242,16 @@ LoadInfo::GetAllowChrome(bool* aResult)
}
NS_IMETHODIMP
LoadInfo::GetContentPolicyType(nsContentPolicyType* aResult)
LoadInfo::GetExternalContentPolicyType(nsContentPolicyType* aResult)
{
*aResult = nsContentUtils::InternalContentPolicyTypeToExternal(mContentPolicyType);
*aResult = nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
return NS_OK;
}
nsContentPolicyType
LoadInfo::InternalContentPolicyType()
{
return mContentPolicyType;
return mInternalContentPolicyType;
}
NS_IMETHODIMP

View File

@ -81,7 +81,7 @@ private:
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsWeakPtr mLoadingContext;
nsSecurityFlags mSecurityFlags;
nsContentPolicyType mContentPolicyType;
nsContentPolicyType mInternalContentPolicyType;
bool mUpgradeInsecureRequests;
uint64_t mInnerWindowID;
uint64_t mOuterWindowID;

View File

@ -22,7 +22,7 @@ typedef unsigned long nsSecurityFlags;
/**
* An nsILoadOwner represents per-load information about who started the load.
*/
[scriptable, builtinclass, uuid(ef0080f3-33f5-475f-a3d6-9fd3be0612e3)]
[scriptable, builtinclass, uuid(07f52282-ab00-4888-b45a-48675ce4a4f5)]
interface nsILoadInfo : nsISupports
{
/**
@ -255,13 +255,13 @@ interface nsILoadInfo : nsISupports
* Specifically, content policy types with _INTERNAL_ in their name will
* never get returned from this attribute.
*/
readonly attribute nsContentPolicyType contentPolicyType;
readonly attribute nsContentPolicyType externalContentPolicyType;
%{ C++
inline nsContentPolicyType GetContentPolicyType()
inline nsContentPolicyType GetExternalContentPolicyType()
{
nsContentPolicyType result;
mozilla::DebugOnly<nsresult> rv = GetContentPolicyType(&result);
mozilla::DebugOnly<nsresult> rv = GetExternalContentPolicyType(&result);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return result;
}

View File

@ -200,34 +200,38 @@ NS_NewChannelInternal(nsIChannel **outChannel,
// NS_NewChannelInternal is mostly called for channel redirects. We should allow
// the creation of a channel even if the original channel did not have a loadinfo
// attached.
if (!aLoadInfo) {
return NS_NewChannelInternal(outChannel,
aUri,
nullptr, // aLoadingNode
nullptr, // aLoadingPrincipal
nullptr, // aTriggeringPrincipal
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
}
nsresult rv = NS_NewChannelInternal(outChannel,
aUri,
aLoadInfo->LoadingNode(),
aLoadInfo->LoadingPrincipal(),
aLoadInfo->TriggeringPrincipal(),
aLoadInfo->GetSecurityFlags(),
aLoadInfo->GetContentPolicyType(),
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
NS_ENSURE_ARG_POINTER(outChannel);
nsCOMPtr<nsIIOService> grip;
nsresult rv = net_EnsureIOService(&aIoService, grip);
NS_ENSURE_SUCCESS(rv, rv);
// Please note that we still call SetLoadInfo on the channel because
// we want the same instance of the loadInfo to be set on the channel.
(*outChannel)->SetLoadInfo(aLoadInfo);
nsCOMPtr<nsIChannel> channel;
rv = aIoService->NewChannelFromURIWithLoadInfo(
aUri,
aLoadInfo,
getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv);
if (aLoadGroup) {
rv = channel->SetLoadGroup(aLoadGroup);
NS_ENSURE_SUCCESS(rv, rv);
}
if (aCallbacks) {
rv = channel->SetNotificationCallbacks(aCallbacks);
NS_ENSURE_SUCCESS(rv, rv);
}
if (aLoadFlags != nsIRequest::LOAD_NORMAL) {
// Retain the LOAD_REPLACE load flag if set.
nsLoadFlags normalLoadFlags = 0;
channel->GetLoadFlags(&normalLoadFlags);
rv = channel->SetLoadFlags(aLoadFlags | (normalLoadFlags & nsIChannel::LOAD_REPLACE));
NS_ENSURE_SUCCESS(rv, rv);
}
channel.forget(outChannel);
return NS_OK;
}

View File

@ -343,7 +343,7 @@ nsHttpChannel::Connect()
nsContentUtils::GetSecurityManager()->
GetChannelResultPrincipal(this, getter_AddRefs(resultPrincipal));
bool crossOriginNavigation =
(mLoadInfo->GetContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) &&
(mLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) &&
(!resultPrincipal->Equals(mLoadInfo->LoadingPrincipal()));
if (!crossOriginNavigation) {

View File

@ -824,7 +824,7 @@ nsHttpChannelAuthProvider::BlockPrompt()
}
if (gHttpHandler->IsTelemetryEnabled()) {
if (loadInfo->GetContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) {
if (loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) {
Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS,
HTTP_AUTH_DIALOG_TOP_LEVEL_DOC);
} else {
@ -842,8 +842,8 @@ nsHttpChannelAuthProvider::BlockPrompt()
}
// Allow if it is the top-level document or xhr.
if ((loadInfo->GetContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) ||
(loadInfo->GetContentPolicyType() == nsIContentPolicy::TYPE_XMLHTTPREQUEST)) {
if ((loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) ||
(loadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_XMLHTTPREQUEST)) {
return false;
}

View File

@ -3244,6 +3244,8 @@ WebSocketChannel::AsyncOpen(nsIURI *aURI,
return rv;
}
// Ideally we'd call newChannelFromURIWithLoadInfo here, but that doesn't
// allow setting proxy uri/flags
rv = io2->NewChannelFromURIWithProxyFlags2(
localURI,
mURI,
@ -3254,7 +3256,7 @@ WebSocketChannel::AsyncOpen(nsIURI *aURI,
mLoadInfo->LoadingPrincipal(),
mLoadInfo->TriggeringPrincipal(),
mLoadInfo->GetSecurityFlags(),
mLoadInfo->GetContentPolicyType(),
mLoadInfo->InternalContentPolicyType(),
getter_AddRefs(localChannel));
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -104,7 +104,7 @@ WyciwygChannelChild::Init(nsIURI* uri)
mozilla::ipc::PrincipalToPrincipalInfo(mLoadInfo->TriggeringPrincipal(),
&triggeringPrincipalInfo);
securityFlags = mLoadInfo->GetSecurityFlags();
policyType = mLoadInfo->GetContentPolicyType();
policyType = mLoadInfo->InternalContentPolicyType();
}
else {
// use default values if no loadInfo is provided

View File

@ -250,7 +250,9 @@ var HttpObserverManager = {
let listeners = this.listeners[kind];
let browser = loadContext ? loadContext.topFrameElement : null;
let loadInfo = channel.loadInfo;
let policyType = loadInfo.contentPolicyType;
let policyType = loadInfo ?
loadInfo.externalContentPolicyType :
Ci.nsIContentPolicy.TYPE_OTHER;
let requestHeaders;
let responseHeaders;
@ -267,8 +269,8 @@ var HttpObserverManager = {
method: channel.requestMethod,
browser: browser,
type: WebRequestCommon.typeForPolicyType(policyType),
windowId: loadInfo.outerWindowID,
parentWindowId: loadInfo.parentOuterWindowID,
windowId: loadInfo ? loadInfo.outerWindowID : 0,
parentWindowId: loadInfo ? loadInfo.parentOuterWindowID : 0,
};
if (opts.requestHeaders) {
if (!requestHeaders) {