Index: components/subresource_filter/content/browser/subframe_filtering_navigation_throttle.cc |
diff --git a/components/subresource_filter/content/browser/subframe_filtering_navigation_throttle.cc b/components/subresource_filter/content/browser/subframe_filtering_navigation_throttle.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4527556cc76d6cc01c1a4e353ecc6adb84ef9bb1 |
--- /dev/null |
+++ b/components/subresource_filter/content/browser/subframe_filtering_navigation_throttle.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/subresource_filter/content/browser/subframe_filtering_navigation_throttle.h" |
+ |
+#include "base/bind.h" |
+#include "components/subresource_filter/content/browser/async_document_subresource_filter.h" |
+#include "content/public/browser/navigation_handle.h" |
+ |
+namespace subresource_filter { |
+ |
+SubframeFilteringNavigationThrottle::SubframeFilteringNavigationThrottle( |
+ content::NavigationHandle* handle, |
+ AsyncDocumentSubresourceFilter* parent_filter) |
+ : content::NavigationThrottle(handle), |
+ parent_filter_(parent_filter), |
+ weak_ptr_factory_(this) { |
+ DCHECK(!handle->IsInMainFrame()); |
engedy
2017/02/14 22:04:33
nit: #include "base/logging.h"
Charlie Harrison
2017/02/14 23:06:55
Done.
|
+ DCHECK(parent_filter_); |
+} |
+ |
+SubframeFilteringNavigationThrottle::~SubframeFilteringNavigationThrottle() {} |
+ |
+content::NavigationThrottle::ThrottleCheckResult |
+SubframeFilteringNavigationThrottle::WillStartRequest() { |
+ return DeferToCalculateLoadPolicy(); |
+} |
+ |
+content::NavigationThrottle::ThrottleCheckResult |
+SubframeFilteringNavigationThrottle::WillRedirectRequest() { |
+ return DeferToCalculateLoadPolicy(); |
+} |
+ |
+content::NavigationThrottle::ThrottleCheckResult |
+SubframeFilteringNavigationThrottle::DeferToCalculateLoadPolicy() { |
+ parent_filter_->GetLoadPolicyForSubdocument( |
+ navigation_handle()->GetURL(), |
+ base::Bind(&SubframeFilteringNavigationThrottle::OnCalculatedLoadPolicy, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
+} |
+ |
+void SubframeFilteringNavigationThrottle::OnCalculatedLoadPolicy( |
+ blink::WebDocumentSubresourceFilter::LoadPolicy policy) { |
+ // TODO(csharrison): Support WouldDisallow pattern and expose the policy for |
+ // metrics. Also, cancel with BLOCK_AND_COLLAPSE when it is implemented. |
+ if (policy == blink::WebDocumentSubresourceFilter::Disallow) { |
+ navigation_handle()->CancelDeferredNavigation( |
engedy
2017/02/14 22:04:32
Should we swap this with the next line? A comment
Charlie Harrison
2017/02/14 23:06:55
Good catch. This would get caught in a browser tes
|
+ content::NavigationThrottle::CANCEL); |
+ parent_filter_->ReportDisallowedLoad(); |
+ } else { |
+ navigation_handle()->Resume(); |
+ } |
+} |
+ |
+} // namespace subresource_filter |