OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/loader/SubresourceFilter.h" | 5 #include "core/loader/SubresourceFilter.h" |
6 | 6 |
7 #include "core/dom/TaskRunnerHelper.h" | |
7 #include "core/loader/DocumentLoader.h" | 8 #include "core/loader/DocumentLoader.h" |
8 #include "public/platform/WebDocumentSubresourceFilter.h" | 9 #include "platform/WebTaskRunner.h" |
10 #include "platform/weborigin/KURL.h" | |
11 #include "public/platform/WebTraceLocation.h" | |
9 | 12 |
10 namespace blink { | 13 namespace blink { |
11 | 14 |
12 // static | 15 // static |
13 SubresourceFilter* SubresourceFilter::create( | 16 SubresourceFilter* SubresourceFilter::create( |
14 DocumentLoader* loader, | 17 DocumentLoader* loader, |
15 std::unique_ptr<WebDocumentSubresourceFilter> filter) { | 18 std::unique_ptr<WebDocumentSubresourceFilter> filter) { |
16 return new SubresourceFilter(loader, std::move(filter)); | 19 return new SubresourceFilter(loader, std::move(filter)); |
17 } | 20 } |
18 | 21 |
19 SubresourceFilter::SubresourceFilter( | 22 SubresourceFilter::SubresourceFilter( |
20 DocumentLoader* documentLoader, | 23 DocumentLoader* documentLoader, |
21 std::unique_ptr<WebDocumentSubresourceFilter> subresourceFilter) | 24 std::unique_ptr<WebDocumentSubresourceFilter> subresourceFilter) |
22 : m_documentLoader(documentLoader), | 25 : m_documentLoader(documentLoader), |
23 m_subresourceFilter(std::move(subresourceFilter)) {} | 26 m_subresourceFilter(std::move(subresourceFilter)) {} |
24 | 27 |
25 SubresourceFilter::~SubresourceFilter() {} | 28 SubresourceFilter::~SubresourceFilter() {} |
26 | 29 |
27 bool SubresourceFilter::allowLoad( | 30 bool SubresourceFilter::allowLoad( |
28 const KURL& resourceUrl, | 31 const KURL& resourceUrl, |
29 WebURLRequest::RequestContext requestContext, | 32 WebURLRequest::RequestContext requestContext, |
30 SecurityViolationReportingPolicy reportingPolicy) { | 33 SecurityViolationReportingPolicy reportingPolicy) { |
31 // TODO(csharrison): Implement a caching layer here which is a HashMap of | 34 // TODO(csharrison): Implement a caching layer here which is a HashMap of |
32 // Pair<url string, context> -> LoadPolicy. | 35 // Pair<url string, context> -> LoadPolicy. |
33 WebDocumentSubresourceFilter::LoadPolicy loadPolicy = | 36 WebDocumentSubresourceFilter::LoadPolicy loadPolicy = |
34 m_subresourceFilter->getLoadPolicy(resourceUrl, requestContext); | 37 m_subresourceFilter->getLoadPolicy(resourceUrl, requestContext); |
35 if (reportingPolicy == SecurityViolationReportingPolicy::Report) { | 38 if (reportingPolicy == SecurityViolationReportingPolicy::Report) |
36 switch (loadPolicy) { | 39 notifyLoad(resourceUrl, loadPolicy); |
37 case WebDocumentSubresourceFilter::Allow: | |
38 break; | |
39 case WebDocumentSubresourceFilter::Disallow: | |
40 m_subresourceFilter->reportDisallowedLoad(); | |
41 // fall through | |
42 case WebDocumentSubresourceFilter::WouldDisallow: | |
43 m_documentLoader->didObserveLoadingBehavior( | |
44 WebLoadingBehaviorSubresourceFilterMatch); | |
45 break; | |
46 } | |
47 } | |
48 return loadPolicy != WebDocumentSubresourceFilter::Disallow; | 40 return loadPolicy != WebDocumentSubresourceFilter::Disallow; |
49 } | 41 } |
50 | 42 |
43 bool SubresourceFilter::allowWebSocketConnection(const KURL& resourceUrl) { | |
44 // TODO(csharrison): Should probably have a new API for this in | |
45 // WebDocumentSubresourceFilter rather than sending subresource context. | |
pkalinnikov
2017/03/02 12:33:53
Right, there is no RequestContext for WebSocket. W
Charlie Harrison
2017/03/02 14:48:01
I slightly prefer (1), but (2) is also ok to me, t
| |
46 WebDocumentSubresourceFilter::LoadPolicy loadPolicy = | |
47 m_subresourceFilter->getLoadPolicy( | |
48 resourceUrl, WebURLRequest::RequestContextSubresource); | |
pkalinnikov
2017/03/02 12:33:53
Using this type temporarily looks good. Note that
Charlie Harrison
2017/03/02 14:48:00
Acknowledged.
| |
49 | |
50 // Post a task to notify this load to avoid unduly blocking the worker | |
51 // thread. | |
52 TaskRunnerHelper::get(TaskType::Networking, m_documentLoader->frame()) | |
pkalinnikov
2017/03/02 12:33:53
Is this intended that allowWebSocketConnection rep
Charlie Harrison
2017/03/02 14:48:01
This was intentional. The reason is that Reporting
| |
53 ->postTask(BLINK_FROM_HERE, | |
54 WTF::bind(&SubresourceFilter::notifyLoad, wrapPersistent(this), | |
55 resourceUrl, loadPolicy)); | |
56 return loadPolicy != WebDocumentSubresourceFilter::Disallow; | |
57 } | |
58 | |
59 void SubresourceFilter::notifyLoad( | |
60 const KURL& resourceUrl, | |
61 WebDocumentSubresourceFilter::LoadPolicy loadPolicy) { | |
62 switch (loadPolicy) { | |
63 case WebDocumentSubresourceFilter::Allow: | |
64 break; | |
65 case WebDocumentSubresourceFilter::Disallow: | |
66 m_subresourceFilter->reportDisallowedLoad(); | |
67 // fall through | |
68 case WebDocumentSubresourceFilter::WouldDisallow: | |
69 m_documentLoader->didObserveLoadingBehavior( | |
70 WebLoadingBehaviorSubresourceFilterMatch); | |
71 break; | |
72 } | |
73 } | |
74 | |
51 } // namespace blink | 75 } // namespace blink |
OLD | NEW |