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

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

Issue 2714573002: Enable websocket filtering via SubresourceFilter (Closed)
Patch Set: Enable websocket filtering via WebDocumentSubresourceFilter Created 3 years, 10 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
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..b9aadfc839bef83d916818b5855708ff6c6dc7cd 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,41 @@ 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.
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
+ WebDocumentSubresourceFilter::LoadPolicy loadPolicy =
+ m_subresourceFilter->getLoadPolicy(
+ 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.
+
+ // Post a task to notify this load to avoid unduly blocking the worker
+ // thread.
+ 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
+ ->postTask(BLINK_FROM_HERE,
+ WTF::bind(&SubresourceFilter::notifyLoad, wrapPersistent(this),
+ resourceUrl, loadPolicy));
return loadPolicy != WebDocumentSubresourceFilter::Disallow;
}
+void SubresourceFilter::notifyLoad(
+ const KURL& resourceUrl,
+ 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

Powered by Google App Engine
This is Rietveld 408576698