Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "core/dom/Document.h" | |
| 9 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
| 11 #include "core/frame/LocalFrame.h" | |
| 12 #include "core/inspector/ConsoleMessage.h" | |
| 10 #include "platform/WebTaskRunner.h" | 13 #include "platform/WebTaskRunner.h" |
| 11 #include "platform/weborigin/KURL.h" | 14 #include "platform/weborigin/KURL.h" |
| 12 #include "public/platform/WebTraceLocation.h" | 15 #include "public/platform/WebTraceLocation.h" |
| 13 | 16 |
| 14 namespace blink { | 17 namespace blink { |
| 15 | 18 |
| 19 namespace { | |
| 20 | |
| 21 void emitErrorForDisallowedLoads(const String& url, Document& document) { | |
|
Charlie Harrison
2017/05/19 17:56:44
Just inlining this in AllowLoad is better imo.
shivanisha
2017/05/22 14:26:27
Compiler complains about declaring variables insid
Charlie Harrison
2017/05/22 14:35:03
How about renaming this method "GetErrorStringForD
shivanisha
2017/05/23 18:54:00
done
| |
| 22 String message = | |
|
Charlie Harrison
2017/05/19 17:56:44
Use StringBuilder for more efficient string append
shivanisha
2017/05/22 14:26:27
done
| |
| 23 "Subresource filtering disallowed loading this resource, " + url + "."; | |
|
Charlie Harrison
2017/05/19 17:56:44
Needs a TODO to update the string when we've decid
shivanisha
2017/05/22 14:26:27
done
| |
| 24 document.AddConsoleMessage( | |
| 25 ConsoleMessage::Create(kJSMessageSource, kErrorMessageLevel, message)); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 16 // static | 30 // static |
| 17 SubresourceFilter* SubresourceFilter::Create( | 31 SubresourceFilter* SubresourceFilter::Create( |
| 18 DocumentLoader* loader, | 32 DocumentLoader* loader, |
| 19 std::unique_ptr<WebDocumentSubresourceFilter> filter) { | 33 std::unique_ptr<WebDocumentSubresourceFilter> filter) { |
| 20 return new SubresourceFilter(loader, std::move(filter)); | 34 return new SubresourceFilter(loader, std::move(filter)); |
| 21 } | 35 } |
| 22 | 36 |
| 23 SubresourceFilter::SubresourceFilter( | 37 SubresourceFilter::SubresourceFilter( |
| 24 DocumentLoader* document_loader, | 38 DocumentLoader* document_loader, |
| 25 std::unique_ptr<WebDocumentSubresourceFilter> subresource_filter) | 39 std::unique_ptr<WebDocumentSubresourceFilter> subresource_filter) |
| 26 : document_loader_(document_loader), | 40 : document_loader_(document_loader), |
| 27 subresource_filter_(std::move(subresource_filter)) {} | 41 subresource_filter_(std::move(subresource_filter)) {} |
| 28 | 42 |
| 29 SubresourceFilter::~SubresourceFilter() {} | 43 SubresourceFilter::~SubresourceFilter() {} |
| 30 | 44 |
| 31 bool SubresourceFilter::AllowLoad( | 45 bool SubresourceFilter::AllowLoad( |
| 32 const KURL& resource_url, | 46 const KURL& resource_url, |
| 33 WebURLRequest::RequestContext request_context, | 47 WebURLRequest::RequestContext request_context, |
| 34 SecurityViolationReportingPolicy reporting_policy) { | 48 SecurityViolationReportingPolicy reporting_policy) { |
| 35 // TODO(csharrison): Implement a caching layer here which is a HashMap of | 49 // TODO(csharrison): Implement a caching layer here which is a HashMap of |
| 36 // Pair<url string, context> -> LoadPolicy. | 50 // Pair<url string, context> -> LoadPolicy. |
| 37 WebDocumentSubresourceFilter::LoadPolicy load_policy = | 51 WebDocumentSubresourceFilter::LoadPolicy load_policy = |
| 38 subresource_filter_->GetLoadPolicy(resource_url, request_context); | 52 subresource_filter_->GetLoadPolicy(resource_url, request_context); |
| 53 | |
| 54 Document* document = document_loader_->GetFrame() | |
| 55 ? document_loader_->GetFrame()->GetDocument() | |
| 56 : nullptr; | |
| 57 if (subresource_filter_->ShouldLogToConsole() && | |
|
Charlie Harrison
2017/05/19 17:56:44
This logic needs to be in ReportLoad, because its
shivanisha
2017/05/22 14:26:27
Done. Thanks.
| |
| 58 load_policy == WebDocumentSubresourceFilter::kDisallow && document) { | |
| 59 emitErrorForDisallowedLoads(resource_url.GetString(), *document); | |
| 60 } | |
| 61 | |
| 39 if (reporting_policy == SecurityViolationReportingPolicy::kReport) | 62 if (reporting_policy == SecurityViolationReportingPolicy::kReport) |
| 40 ReportLoad(load_policy); | 63 ReportLoad(load_policy); |
| 41 return load_policy != WebDocumentSubresourceFilter::kDisallow; | 64 return load_policy != WebDocumentSubresourceFilter::kDisallow; |
| 42 } | 65 } |
| 43 | 66 |
| 44 bool SubresourceFilter::AllowWebSocketConnection(const KURL& url) { | 67 bool SubresourceFilter::AllowWebSocketConnection(const KURL& url) { |
| 45 WebDocumentSubresourceFilter::LoadPolicy load_policy = | 68 WebDocumentSubresourceFilter::LoadPolicy load_policy = |
| 46 subresource_filter_->GetLoadPolicyForWebSocketConnect(url); | 69 subresource_filter_->GetLoadPolicyForWebSocketConnect(url); |
| 47 | 70 |
| 48 // Post a task to notify this load to avoid unduly blocking the worker | 71 // Post a task to notify this load to avoid unduly blocking the worker |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 60 | 83 |
| 61 void SubresourceFilter::ReportLoad( | 84 void SubresourceFilter::ReportLoad( |
| 62 WebDocumentSubresourceFilter::LoadPolicy load_policy) { | 85 WebDocumentSubresourceFilter::LoadPolicy load_policy) { |
| 63 switch (load_policy) { | 86 switch (load_policy) { |
| 64 case WebDocumentSubresourceFilter::kAllow: | 87 case WebDocumentSubresourceFilter::kAllow: |
| 65 break; | 88 break; |
| 66 case WebDocumentSubresourceFilter::kDisallow: | 89 case WebDocumentSubresourceFilter::kDisallow: |
| 67 subresource_filter_->ReportDisallowedLoad(); | 90 subresource_filter_->ReportDisallowedLoad(); |
| 68 // fall through | 91 // fall through |
| 69 case WebDocumentSubresourceFilter::kWouldDisallow: | 92 case WebDocumentSubresourceFilter::kWouldDisallow: |
| 70 // TODO(csharrison): log console errors here based on | |
| 71 // subresource_filter_->ShouldLogToConsole(). | |
| 72 document_loader_->DidObserveLoadingBehavior( | 93 document_loader_->DidObserveLoadingBehavior( |
| 73 kWebLoadingBehaviorSubresourceFilterMatch); | 94 kWebLoadingBehaviorSubresourceFilterMatch); |
| 74 break; | 95 break; |
| 75 } | 96 } |
| 76 } | 97 } |
| 77 | 98 |
| 78 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |