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

Unified Diff: components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.cc

Issue 2696493003: Introduce SubframeNavigationFilteringThrottle (Closed)
Patch Set: remove tests 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
« no previous file with comments | « components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.cc
diff --git a/components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.cc b/components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fa61169d4b655f2ac8757f476fde8aa5ed55df2
--- /dev/null
+++ b/components/subresource_filter/content/browser/subframe_navigation_filtering_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_navigation_filtering_throttle.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "content/public/browser/navigation_handle.h"
+
+namespace subresource_filter {
+
+SubframeNavigationFilteringThrottle::SubframeNavigationFilteringThrottle(
+ content::NavigationHandle* handle,
+ AsyncDocumentSubresourceFilter* parent_frame_filter)
+ : content::NavigationThrottle(handle),
+ parent_frame_filter_(parent_frame_filter),
+ weak_ptr_factory_(this) {
+ DCHECK(!handle->IsInMainFrame());
+ DCHECK(parent_frame_filter_);
+}
+
+SubframeNavigationFilteringThrottle::~SubframeNavigationFilteringThrottle() {}
+
+content::NavigationThrottle::ThrottleCheckResult
+SubframeNavigationFilteringThrottle::WillStartRequest() {
+ return DeferToCalculateLoadPolicy();
+}
+
+content::NavigationThrottle::ThrottleCheckResult
+SubframeNavigationFilteringThrottle::WillRedirectRequest() {
+ return DeferToCalculateLoadPolicy();
+}
+
+content::NavigationThrottle::ThrottleCheckResult
+SubframeNavigationFilteringThrottle::DeferToCalculateLoadPolicy() {
+ parent_frame_filter_->GetLoadPolicyForSubdocument(
+ navigation_handle()->GetURL(),
+ base::Bind(&SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy,
+ weak_ptr_factory_.GetWeakPtr()));
+ return content::NavigationThrottle::ThrottleCheckResult::DEFER;
+}
+
+void SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy(
+ 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 == LoadPolicy::DISALLOW) {
+ parent_frame_filter_->ReportDisallowedLoad();
+ navigation_handle()->CancelDeferredNavigation(
+ content::NavigationThrottle::CANCEL);
+ } else {
+ navigation_handle()->Resume();
+ }
+}
+
+} // namespace subresource_filter
« no previous file with comments | « components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698