Chromium Code Reviews| Index: third_party/WebKit/Source/core/loader/SubresourceFilter.cpp |
| diff --git a/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp b/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp |
| index fe3c77e3abe26747c54b368c3344455a9011c1bf..8006568ad3f7f0d5ffe9eb36e129056b960e4281 100644 |
| --- a/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp |
| +++ b/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp |
| @@ -4,8 +4,11 @@ |
| #include "core/loader/SubresourceFilter.h" |
| +#include "core/dom/TaskRunnerHelper.h" |
| #include "core/loader/DocumentLoader.h" |
| -#include "public/platform/WebDocumentSubresourceFilter.h" |
| +#include "platform/WebTaskRunner.h" |
| +#include "platform/weborigin/KURL.h" |
| +#include "public/platform/WebTraceLocation.h" |
| namespace blink { |
| @@ -32,20 +35,46 @@ bool SubresourceFilter::allowLoad( |
| // Pair<url string, context> -> LoadPolicy. |
| WebDocumentSubresourceFilter::LoadPolicy loadPolicy = |
| m_subresourceFilter->getLoadPolicy(resourceUrl, requestContext); |
| - if (reportingPolicy == SecurityViolationReportingPolicy::Report) { |
| - switch (loadPolicy) { |
| - case WebDocumentSubresourceFilter::Allow: |
| - break; |
| - case WebDocumentSubresourceFilter::Disallow: |
| - m_subresourceFilter->reportDisallowedLoad(); |
| - // fall through |
| - case WebDocumentSubresourceFilter::WouldDisallow: |
| - m_documentLoader->didObserveLoadingBehavior( |
| - WebLoadingBehaviorSubresourceFilterMatch); |
| - break; |
| - } |
| - } |
| + if (reportingPolicy == SecurityViolationReportingPolicy::Report) |
| + notifyLoad(resourceUrl, loadPolicy); |
| + return loadPolicy != WebDocumentSubresourceFilter::Disallow; |
| +} |
| + |
| +bool SubresourceFilter::allowWebSocketConnection(const KURL& resourceUrl) { |
| + // TODO(csharrison): Should probably have a new API for this in |
| + // WebDocumentSubresourceFilter rather than sending subresource context. |
| + // Alternatively, could augment the filter API so that we send a |
| + // WebDocumentSubresourceFilterResourceType that matches |
| + // subresource_filter::proto::ElementType. |
| + WebDocumentSubresourceFilter::LoadPolicy loadPolicy = |
| + m_subresourceFilter->getLoadPolicy( |
| + resourceUrl, WebURLRequest::RequestContextSubresource); |
| + |
| + // Post a task to notify this load to avoid unduly blocking the worker |
| + // thread. Note that this unconditionally calls notifyLoad unlike allowLoad, |
| + // because there aren't developer-invisible connections (like speculative |
| + // preloads) happening here. |
| + TaskRunnerHelper::get(TaskType::Networking, m_documentLoader->frame()) |
| + ->postTask(BLINK_FROM_HERE, |
| + WTF::bind(&SubresourceFilter::notifyLoad, wrapPersistent(this), |
| + resourceUrl, loadPolicy)); |
| return loadPolicy != WebDocumentSubresourceFilter::Disallow; |
| } |
| +void SubresourceFilter::notifyLoad( |
|
engedy
2017/03/06 14:12:46
nit: WDYT about calling this `reportLoad`? At leas
Charlie Harrison
2017/03/06 14:48:23
Sure, changed to report load.
|
| + const KURL& resourceUrl, |
|
engedy
2017/03/06 14:12:46
nit: |resourceUrl| argument is never used
Charlie Harrison
2017/03/06 14:48:23
Removed :)
|
| + WebDocumentSubresourceFilter::LoadPolicy loadPolicy) { |
| + switch (loadPolicy) { |
| + case WebDocumentSubresourceFilter::Allow: |
| + break; |
| + case WebDocumentSubresourceFilter::Disallow: |
| + m_subresourceFilter->reportDisallowedLoad(); |
| + // fall through |
| + case WebDocumentSubresourceFilter::WouldDisallow: |
| + m_documentLoader->didObserveLoadingBehavior( |
| + WebLoadingBehaviorSubresourceFilterMatch); |
| + break; |
| + } |
| +} |
| + |
| } // namespace blink |