Bug 1119302 - Implement nsIContentPolicy.shouldProcess for plugin subresource loads, r=bz

--HG--
extra : rebase_source : 6df300a4ce73dfdd4940d3ae36a8bcf9e05b3044
This commit is contained in:
Benjamin Smedberg 2015-01-08 12:23:27 -05:00
Родитель 09d5b914b7
Коммит af5901232a
1 изменённых файлов: 42 добавлений и 11 удалений

Просмотреть файл

@ -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<nsIChannel> 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<nsPluginInstanceOwner> owner;
if (mPluginInstance) {
owner = mPluginInstance->GetOwner();
}
nsCOMPtr<nsIDOMElement> element;
nsCOMPtr<nsIDocument> doc;
if (owner) {
owner->GetDOMElement(getter_AddRefs(element));
owner->GetDocument(getter_AddRefs(doc));
}
nsCOMPtr<nsIPrincipal> 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<nsIChannel> 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<nsIHttpChannel> 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<nsIURI> 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