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

Side by Side Diff: components/subresource_filter/content/browser/subframe_navigation_filtering_throttle.cc

Issue 2696493003: Introduce SubframeNavigationFilteringThrottle (Closed)
Patch Set: s/proceed2/allowed2/ (trybots prev) 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 unified diff | Download patch
OLDNEW
(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 "components/subresource_filter/content/browser/async_document_subresour ce_filter.h"
10 #include "content/public/browser/navigation_handle.h"
11
12 namespace subresource_filter {
13
14 SubframeNavigationFilteringThrottle::SubframeNavigationFilteringThrottle(
15 content::NavigationHandle* handle,
16 AsyncDocumentSubresourceFilter* parent_frame_filter)
17 : content::NavigationThrottle(handle),
18 parent_frame_filter_(parent_frame_filter),
19 weak_ptr_factory_(this) {
20 DCHECK(!handle->IsInMainFrame());
21 DCHECK(parent_frame_filter_);
22 }
23
24 SubframeNavigationFilteringThrottle::~SubframeNavigationFilteringThrottle() {}
25
26 content::NavigationThrottle::ThrottleCheckResult
27 SubframeNavigationFilteringThrottle::WillStartRequest() {
28 return DeferToCalculateLoadPolicy();
29 }
30
31 content::NavigationThrottle::ThrottleCheckResult
32 SubframeNavigationFilteringThrottle::WillRedirectRequest() {
33 return DeferToCalculateLoadPolicy();
34 }
35
36 content::NavigationThrottle::ThrottleCheckResult
37 SubframeNavigationFilteringThrottle::DeferToCalculateLoadPolicy() {
38 parent_frame_filter_->GetLoadPolicyForSubdocument(
39 navigation_handle()->GetURL(),
40 base::Bind(&SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy,
41 weak_ptr_factory_.GetWeakPtr()));
42 return content::NavigationThrottle::ThrottleCheckResult::DEFER;
43 }
44
45 void SubframeNavigationFilteringThrottle::OnCalculatedLoadPolicy(
46 blink::WebDocumentSubresourceFilter::LoadPolicy policy) {
47 // TODO(csharrison): Support WouldDisallow pattern and expose the policy for
48 // metrics. Also, cancel with BLOCK_AND_COLLAPSE when it is implemented.
49 if (policy == blink::WebDocumentSubresourceFilter::Disallow) {
50 parent_frame_filter_->ReportDisallowedLoad();
51 navigation_handle()->CancelDeferredNavigation(
52 content::NavigationThrottle::CANCEL);
53 } else {
54 navigation_handle()->Resume();
55 }
56 }
57
58 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698