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

Side by Side Diff: third_party/WebKit/Source/core/loader/SubresourceFilter.cpp

Issue 2714573002: Enable websocket filtering via SubresourceFilter (Closed)
Patch Set: sync to #455176 Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 reportLoad(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& url) {
44 // TODO(csharrison): Should probably have a new API for this in
45 // WebDocumentSubresourceFilter rather than sending subresource context.
46 // Alternatively, could augment the filter API so that we send a
47 // WebDocumentSubresourceFilterResourceType that matches
48 // subresource_filter::proto::ElementType.
49 WebDocumentSubresourceFilter::LoadPolicy loadPolicy =
50 m_subresourceFilter->getLoadPolicy(
51 url, WebURLRequest::RequestContextSubresource);
52
53 // Post a task to notify this load to avoid unduly blocking the worker
54 // thread. Note that this unconditionally calls reportLoad unlike allowLoad,
55 // because there aren't developer-invisible connections (like speculative
56 // preloads) happening here.
57 RefPtr<WebTaskRunner> taskRunner =
58 TaskRunnerHelper::get(TaskType::Networking, m_documentLoader->frame());
59 DCHECK(taskRunner->runsTasksOnCurrentThread());
60 taskRunner->postTask(BLINK_FROM_HERE,
61 WTF::bind(&SubresourceFilter::reportLoad,
62 wrapPersistent(this), loadPolicy));
63 return loadPolicy != WebDocumentSubresourceFilter::Disallow;
64 }
65
66 void SubresourceFilter::reportLoad(
67 WebDocumentSubresourceFilter::LoadPolicy loadPolicy) {
68 // TODO(csharrison): log console errors here.
69 switch (loadPolicy) {
70 case WebDocumentSubresourceFilter::Allow:
71 break;
72 case WebDocumentSubresourceFilter::Disallow:
73 m_subresourceFilter->reportDisallowedLoad();
74 // fall through
75 case WebDocumentSubresourceFilter::WouldDisallow:
76 m_documentLoader->didObserveLoadingBehavior(
77 WebLoadingBehaviorSubresourceFilterMatch);
78 break;
79 }
80 }
81
51 } // namespace blink 82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698