Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Unified Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2022783002: Skeleton of the Safe Browsing Subresource Filter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
diff --git a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
index 167da90332473df36b56720b9977236babb20d40..72a1431ae98df4c966ae20122dce8f992f595474 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp
@@ -69,6 +69,7 @@
#include "platform/weborigin/SchemeRegistry.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "public/platform/WebCachePolicy.h"
+#include "public/platform/WebDocumentSubresourceFilter.h"
#include "public/platform/WebFrameScheduler.h"
#include <algorithm>
@@ -279,7 +280,7 @@ WebCachePolicy FrameFetchContext::resourceRequestCachePolicy(const ResourceReque
// |loader| can be null if the resource is loaded from imported document.
// This means inspector, which uses DocumentLoader as an grouping entity,
// cannot see imported documents.
-inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() const
+inline DocumentLoader* FrameFetchContext::effectiveDocumentLoader() const
{
return m_documentLoader ? m_documentLoader.get() : frame()->loader().documentLoader();
}
@@ -296,7 +297,7 @@ void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour
frame()->loader().applyUserAgent(request);
frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identifier, request, redirectResponse);
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceSendRequest", TRACE_EVENT_SCOPE_THREAD, "data", InspectorSendRequestEvent::data(identifier, frame(), request));
- InspectorInstrumentation::willSendRequest(frame(), identifier, ensureLoaderForNotifications(), request, redirectResponse, initiatorInfo);
+ InspectorInstrumentation::willSendRequest(frame(), identifier, effectiveDocumentLoader(), request, redirectResponse, initiatorInfo);
}
void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, const ResourceResponse& response, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext, ResourceLoader* resourceLoader)
@@ -319,7 +320,7 @@ void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, con
frame()->loader().progress().incrementProgress(identifier, response);
frame()->loader().client()->dispatchDidReceiveResponse(m_documentLoader, identifier, response);
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_EVENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame(), response));
- DocumentLoader* documentLoader = ensureLoaderForNotifications();
+ DocumentLoader* documentLoader = effectiveDocumentLoader();
InspectorInstrumentation::didReceiveResourceResponse(frame(), identifier, documentLoader, response, resourceLoader);
// It is essential that inspector gets resource response BEFORE console.
frame()->console().reportResourceResponseReceived(documentLoader, identifier, response);
@@ -452,7 +453,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r
ResourceRequestBlockedReason reason = canRequestInternal(type, resourceRequest, url, options, forPreload, originRestriction, redirectStatus);
if (reason != ResourceRequestBlockedReasonNone) {
if (!forPreload)
- InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo, reason);
+ InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, effectiveDocumentLoader(), options.initiatorInfo, reason);
return false;
}
return true;
@@ -462,7 +463,7 @@ bool FrameFetchContext::allowResponse(Resource::Type type, const ResourceRequest
{
ResourceRequestBlockedReason reason = canRequestInternal(type, resourceRequest, url, options, false, FetchRequest::UseDefaultOriginRestrictionForType, ContentSecurityPolicy::DidRedirect);
if (reason != ResourceRequestBlockedReasonNone) {
- InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo, reason);
+ InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, effectiveDocumentLoader(), options.initiatorInfo, reason);
return false;
}
return true;
@@ -573,14 +574,19 @@ ResourceRequestBlockedReason FrameFetchContext::canRequestInternal(Resource::Typ
UseCounter::count(frame()->document(), UseCounter::ResourceLoadedAfterRedirectWithCSP);
}
- // Last of all, check for mixed content. We do this last so that when
- // folks block mixed content with a CSP policy, they don't get a warning.
- // They'll still get a warning in the console about CSP blocking the load.
+ // Check for mixed content. We do this second-to-last so that when folks block
+ // mixed content with a CSP policy, they don't get a warning. They'll still
+ // get a warning in the console about CSP blocking the load.
MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ?
MixedContentChecker::SuppressReport : MixedContentChecker::SendReport;
if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mixedContentReporting))
return ResourceRequestBlockedReasonMixedContent;
+ // Let the client have the final say into whether or not the load should proceed.
+ DocumentLoader* documentLoader = effectiveDocumentLoader();
+ if (documentLoader && documentLoader->subresourceFilter() && type != Resource::MainResource && type != Resource::ImportResource && !documentLoader->subresourceFilter()->allowLoad(url, resourceRequest.requestContext()))
+ return ResourceRequestBlockedReasonClient;
+
return ResourceRequestBlockedReasonNone;
}

Powered by Google App Engine
This is Rietveld 408576698