OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/public/browser/navigation_handle.h" |
| 10 |
| 11 namespace subresource_filter { |
| 12 |
| 13 SubframeNavigationFilteringThrottle::SubframeNavigationFilteringThrottle( |
| 14 content::NavigationHandle* handle, |
| 15 AsyncDocumentSubresourceFilter* parent_frame_filter) |
| 16 : content::NavigationThrottle(handle), |
| 17 parent_frame_filter_(parent_frame_filter), |
| 18 weak_ptr_factory_(this) { |
| 19 DCHECK(!handle->IsInMainFrame()); |
| 20 DCHECK(parent_frame_filter_); |
| 21 } |
| 22 |
| 23 SubframeNavigationFilteringThrottle::~SubframeNavigationFilteringThrottle() {} |
| 24 |
| 25 content::NavigationThrottle::ThrottleCheckResult |
| 26 SubframeNavigationFilteringThrottle::WillStartRequest() { |
| 27 return DeferToCalculateLoadPolicy(); |
| 28 } |
| 29 |
| 30 content::NavigationThrottle::ThrottleCheckResult |
| 31 SubframeNavigationFilteringThrottle::WillRedirectRequest() { |
| 32 return DeferToCalculateLoadPolicy(); |
| 33 } |
| 34 |
| 35 content::NavigationThrottle::ThrottleCheckResult |
| 36 SubframeNavigationFilteringThrottle::DeferToCalculateLoadPolicy() { |
| 37 parent_frame_filter_->GetLoadPolicyForSubdocument( |
| 38 navigation_handle()->GetURL(), |
| 39 base::Bind(&SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy, |
| 40 weak_ptr_factory_.GetWeakPtr())); |
| 41 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
| 42 } |
| 43 |
| 44 void SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy( |
| 45 LoadPolicy policy) { |
| 46 // TODO(csharrison): Support WouldDisallow pattern and expose the policy for |
| 47 // metrics. Also, cancel with BLOCK_AND_COLLAPSE when it is implemented. |
| 48 if (policy == LoadPolicy::DISALLOW) { |
| 49 parent_frame_filter_->ReportDisallowedLoad(); |
| 50 navigation_handle()->CancelDeferredNavigation( |
| 51 content::NavigationThrottle::CANCEL); |
| 52 } else { |
| 53 navigation_handle()->Resume(); |
| 54 } |
| 55 } |
| 56 |
| 57 } // namespace subresource_filter |
OLD | NEW |