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_filtering_navig ation_throttle.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" | |
9 #include "content/public/browser/navigation_handle.h" | |
10 | |
11 namespace subresource_filter { | |
12 | |
13 SubframeFilteringNavigationThrottle::SubframeFilteringNavigationThrottle( | |
14 content::NavigationHandle* handle, | |
15 AsyncDocumentSubresourceFilter* parent_filter) | |
16 : content::NavigationThrottle(handle), | |
17 parent_filter_(parent_filter), | |
18 weak_ptr_factory_(this) { | |
19 DCHECK(!handle->IsInMainFrame()); | |
engedy
2017/02/14 22:04:33
nit: #include "base/logging.h"
Charlie Harrison
2017/02/14 23:06:55
Done.
| |
20 DCHECK(parent_filter_); | |
21 } | |
22 | |
23 SubframeFilteringNavigationThrottle::~SubframeFilteringNavigationThrottle() {} | |
24 | |
25 content::NavigationThrottle::ThrottleCheckResult | |
26 SubframeFilteringNavigationThrottle::WillStartRequest() { | |
27 return DeferToCalculateLoadPolicy(); | |
28 } | |
29 | |
30 content::NavigationThrottle::ThrottleCheckResult | |
31 SubframeFilteringNavigationThrottle::WillRedirectRequest() { | |
32 return DeferToCalculateLoadPolicy(); | |
33 } | |
34 | |
35 content::NavigationThrottle::ThrottleCheckResult | |
36 SubframeFilteringNavigationThrottle::DeferToCalculateLoadPolicy() { | |
37 parent_filter_->GetLoadPolicyForSubdocument( | |
38 navigation_handle()->GetURL(), | |
39 base::Bind(&SubframeFilteringNavigationThrottle::OnCalculatedLoadPolicy, | |
40 weak_ptr_factory_.GetWeakPtr())); | |
41 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | |
42 } | |
43 | |
44 void SubframeFilteringNavigationThrottle::OnCalculatedLoadPolicy( | |
45 blink::WebDocumentSubresourceFilter::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 == blink::WebDocumentSubresourceFilter::Disallow) { | |
49 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
| |
50 content::NavigationThrottle::CANCEL); | |
51 parent_filter_->ReportDisallowedLoad(); | |
52 } else { | |
53 navigation_handle()->Resume(); | |
54 } | |
55 } | |
56 | |
57 } // namespace subresource_filter | |
OLD | NEW |