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

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

Issue 2895643002: [subresource_filter] Display dev tools console message for subresource blocking (Closed)
Patch Set: Created 3 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/subresource_filter/resource-disallowed-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bdfbdf10756a94ec33a0dce2aeb67cb83cc3a41a..98d99e24607e4ce785be0116ee2b92998c5cdcc8 100644
--- a/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp
+++ b/third_party/WebKit/Source/core/loader/SubresourceFilter.cpp
@@ -6,13 +6,27 @@
#include <utility>
+#include "core/dom/Document.h"
#include "core/dom/TaskRunnerHelper.h"
+#include "core/frame/LocalFrame.h"
+#include "core/inspector/ConsoleMessage.h"
#include "platform/WebTaskRunner.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/WebTraceLocation.h"
namespace blink {
+namespace {
+
+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
+ 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
+ "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
+ document.AddConsoleMessage(
+ ConsoleMessage::Create(kJSMessageSource, kErrorMessageLevel, message));
+}
+
+} // namespace
+
// static
SubresourceFilter* SubresourceFilter::Create(
DocumentLoader* loader,
@@ -36,6 +50,15 @@ bool SubresourceFilter::AllowLoad(
// Pair<url string, context> -> LoadPolicy.
WebDocumentSubresourceFilter::LoadPolicy load_policy =
subresource_filter_->GetLoadPolicy(resource_url, request_context);
+
+ Document* document = document_loader_->GetFrame()
+ ? document_loader_->GetFrame()->GetDocument()
+ : nullptr;
+ 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.
+ load_policy == WebDocumentSubresourceFilter::kDisallow && document) {
+ emitErrorForDisallowedLoads(resource_url.GetString(), *document);
+ }
+
if (reporting_policy == SecurityViolationReportingPolicy::kReport)
ReportLoad(load_policy);
return load_policy != WebDocumentSubresourceFilter::kDisallow;
@@ -67,8 +90,6 @@ void SubresourceFilter::ReportLoad(
subresource_filter_->ReportDisallowedLoad();
// fall through
case WebDocumentSubresourceFilter::kWouldDisallow:
- // TODO(csharrison): log console errors here based on
- // subresource_filter_->ShouldLogToConsole().
document_loader_->DidObserveLoadingBehavior(
kWebLoadingBehaviorSubresourceFilterMatch);
break;
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/subresource_filter/resource-disallowed-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698