Bug 1213150 - Part 1: Add a nsContentUtils::IsNonSubresourceRequest helper; r=jdm

This commit is contained in:
Ehsan Akhgari 2015-10-06 22:35:12 -04:00
parent 40faae43d4
commit fbd4c8c55b
3 changed files with 18 additions and 12 deletions

View File

@ -14070,18 +14070,13 @@ nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel,
return NS_OK;
}
bool isNavigation = false;
nsresult rv = aChannel->GetIsNavigation(&isNavigation);
NS_ENSURE_SUCCESS(rv, rv);
nsContentPolicyType loadType;
rv = aChannel->GetInternalContentPolicyType(&loadType);
nsCOMPtr<nsIChannel> channel;
nsresult rv = aChannel->GetChannel(getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc;
bool isSubresourceLoad = !isNavigation &&
!nsContentUtils::IsWorkerLoad(loadType);
bool isSubresourceLoad = !nsContentUtils::IsNonSubresourceRequest(channel);
if (isSubresourceLoad) {
doc = GetDocument();
if (!doc) {

View File

@ -8101,10 +8101,21 @@ nsContentUtils::PushEnabled(JSContext* aCx, JSObject* aObj)
// static
bool
nsContentUtils::IsWorkerLoad(nsContentPolicyType aType)
nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel)
{
return aType == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
aType == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER;
nsLoadFlags loadFlags = 0;
aChannel->GetLoadFlags(&loadFlags);
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
return true;
}
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
if (!loadInfo) {
return false;
}
nsContentPolicyType type = loadInfo->InternalContentPolicyType();
return type == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
type == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER;
}
// static, public

View File

@ -2522,7 +2522,7 @@ public:
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
static bool IsWorkerLoad(nsContentPolicyType aLoadType);
static bool IsNonSubresourceRequest(nsIChannel* aChannel);
// The order of these entries matters, as we use std::min for total ordering
// of permissions. Private Browsing is considered to be more limiting