From 0ea778f8c322ede8b1126ecf2423c6aeaec22326 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Fri, 31 Jul 2015 08:58:14 -0700 Subject: [PATCH] Bug 1182539 - Use channel->ascynOpen2 in dom/base/nsDocument.cpp (r=sicking) --- dom/base/nsDocument.cpp | 47 +++-------------------- dom/security/nsContentSecurityManager.cpp | 7 +++- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 10c1abc0825..aa483881439 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1289,57 +1289,22 @@ nsExternalResourceMap::PendingLoad::StartLoad(nsIURI* aURI, NS_PRECONDITION(aURI, "Must have a URI"); NS_PRECONDITION(aRequestingNode, "Must have a node"); - // Time to start a load. First, the security checks. + nsCOMPtr loadGroup = + aRequestingNode->OwnerDoc()->GetDocumentLoadGroup(); - nsIPrincipal* requestingPrincipal = aRequestingNode->NodePrincipal(); - - nsresult rv = nsContentUtils::GetSecurityManager()-> - CheckLoadURIWithPrincipal(requestingPrincipal, aURI, - nsIScriptSecurityManager::STANDARD); - NS_ENSURE_SUCCESS(rv, rv); - - // Allow data URIs and other URI's that inherit their principal by passing - // true as the 3rd argument of CheckMayLoad, since we want - // to allow external resources from data URIs regardless of the difference - // in URI scheme. - rv = requestingPrincipal->CheckMayLoad(aURI, true, true); - NS_ENSURE_SUCCESS(rv, rv); - - int16_t shouldLoad = nsIContentPolicy::ACCEPT; - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER, - aURI, - requestingPrincipal, - aRequestingNode, - EmptyCString(), //mime guess - nullptr, //extra - &shouldLoad, - nsContentUtils::GetContentPolicy(), - nsContentUtils::GetSecurityManager()); - if (NS_FAILED(rv)) return rv; - if (NS_CP_REJECTED(shouldLoad)) { - // Disallowed by content policy - return NS_ERROR_CONTENT_BLOCKED; - } - - nsIDocument* doc = aRequestingNode->OwnerDoc(); - - nsCOMPtr req = nsContentUtils::SameOriginChecker(); - - nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); + nsresult rv = NS_OK; nsCOMPtr channel; rv = NS_NewChannel(getter_AddRefs(channel), aURI, aRequestingNode, - nsILoadInfo::SEC_NORMAL, + nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS, nsIContentPolicy::TYPE_OTHER, - loadGroup, - req); // aCallbacks - + loadGroup); NS_ENSURE_SUCCESS(rv, rv); mURI = aURI; - return channel->AsyncOpen(this, nullptr); + return channel->AsyncOpen2(this); } NS_IMPL_ISUPPORTS(nsExternalResourceMap::LoadgroupCallbacks, diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index e3f465f4db0..5862816fd81 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -118,7 +118,12 @@ DoContentSecurityChecks(nsIURI* aURI, nsILoadInfo* aLoadInfo) nsCOMPtr requestingContext = nullptr; switch(contentPolicyType) { - case nsIContentPolicy::TYPE_OTHER: + case nsIContentPolicy::TYPE_OTHER: { + mimeTypeGuess = EmptyCString(); + requestingContext = aLoadInfo->LoadingNode(); + break; + } + case nsIContentPolicy::TYPE_SCRIPT: case nsIContentPolicy::TYPE_IMAGE: case nsIContentPolicy::TYPE_STYLESHEET: