From af5901232a9862fa3b00f5c3e2d5c75d05eb55e2 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Thu, 8 Jan 2015 12:23:27 -0500 Subject: [PATCH] Bug 1119302 - Implement nsIContentPolicy.shouldProcess for plugin subresource loads, r=bz --HG-- extra : rebase_source : 6df300a4ce73dfdd4940d3ae36a8bcf9e05b3044 --- .../base/nsPluginStreamListenerPeer.cpp | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/dom/plugins/base/nsPluginStreamListenerPeer.cpp b/dom/plugins/base/nsPluginStreamListenerPeer.cpp index dc622cf0d179..bb9e69f13015 100644 --- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp +++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp @@ -4,6 +4,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsPluginStreamListenerPeer.h" +#include "nsIContentPolicy.h" +#include "nsContentPolicyUtils.h" #include "nsIDOMElement.h" #include "nsIStreamConverterService.h" #include "nsIHttpChannel.h" @@ -12,6 +14,7 @@ #include "nsMimeTypes.h" #include "nsISupportsPrimitives.h" #include "nsNetCID.h" +#include "nsPluginInstanceOwner.h" #include "nsPluginLogging.h" #include "nsIURI.h" #include "nsIURL.h" @@ -426,6 +429,42 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, PROFILER_LABEL("nsPluginStreamListenerPeer", "OnStartRequest", js::ProfileEntry::Category::OTHER); + nsCOMPtr channel = do_QueryInterface(request); + NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE); + + nsAutoCString contentType; + rv = channel->GetContentType(contentType); + if (NS_FAILED(rv)) + return rv; + + // Check ShouldProcess with content policy + nsRefPtr owner; + if (mPluginInstance) { + owner = mPluginInstance->GetOwner(); + } + nsCOMPtr element; + nsCOMPtr doc; + if (owner) { + owner->GetDOMElement(getter_AddRefs(element)); + owner->GetDocument(getter_AddRefs(doc)); + } + nsCOMPtr principal = doc ? doc->NodePrincipal() : nullptr; + + int16_t shouldLoad = nsIContentPolicy::ACCEPT; + rv = NS_CheckContentProcessPolicy(nsIContentPolicy::TYPE_OBJECT_SUBREQUEST, + mURL, + principal, + element, + contentType, + nullptr, + &shouldLoad); + if (NS_FAILED(rv)) { + return rv; + } + if (NS_CP_REJECTED(shouldLoad)) { + return NS_ERROR_CONTENT_BLOCKED; + } + if (mRequests.IndexOfObject(GetBaseRequest(request)) == -1) { NS_ASSERTION(mRequests.Count() == 0, "Only our initial stream should be unknown!"); @@ -438,9 +477,6 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, mHaveFiredOnStartRequest = true; - nsCOMPtr channel = do_QueryInterface(request); - NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE); - // deal with 404 (Not Found) HTTP response, // just return, this causes the request to be ignored. nsCOMPtr httpChannel(do_QueryInterface(channel)); @@ -509,11 +545,6 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, mLength = uint32_t(length); } - nsAutoCString aContentType; // XXX but we already got the type above! - rv = channel->GetContentType(aContentType); - if (NS_FAILED(rv)) - return rv; - nsCOMPtr aURL; rv = channel->GetURI(getter_AddRefs(aURL)); if (NS_FAILED(rv)) @@ -521,13 +552,13 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, aURL->GetSpec(mURLSpec); - if (!aContentType.IsEmpty()) - mContentType = aContentType; + if (!contentType.IsEmpty()) + mContentType = contentType; #ifdef PLUGIN_LOGGING PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnStartRequest this=%p request=%p mime=%s, url=%s\n", - this, request, aContentType.get(), mURLSpec.get())); + this, request, contentType.get(), mURLSpec.get())); PR_LogFlush(); #endif