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

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

Issue 2691423006: Introduce the ThrottleManager (Closed)
Patch Set: respond to more comments 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/subresource_filter/content/browser/activation_state_computi ng_navigation_throttle.h" 5 #include "components/subresource_filter/content/browser/activation_state_computi ng_navigation_throttle.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" 12 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h"
13 #include "content/public/browser/navigation_handle.h" 13 #include "content/public/browser/navigation_handle.h"
14 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
15 15
16 namespace subresource_filter { 16 namespace subresource_filter {
17 17
18 // static 18 // static
19 std::unique_ptr<ActivationStateComputingNavigationThrottle> 19 std::unique_ptr<ActivationStateComputingNavigationThrottle>
20 ActivationStateComputingNavigationThrottle::CreateForMainFrame( 20 ActivationStateComputingNavigationThrottle::CreateForMainFrame(
21 content::NavigationHandle* navigation_handle) { 21 content::NavigationHandle* navigation_handle) {
22 DCHECK(navigation_handle->IsInMainFrame()); 22 DCHECK(navigation_handle->IsInMainFrame());
23 return base::WrapUnique(new ActivationStateComputingNavigationThrottle( 23 return base::WrapUnique(new ActivationStateComputingNavigationThrottle(
24 navigation_handle, base::Optional<ActivationState>(), nullptr)); 24 navigation_handle, base::Optional<ActivationState>(), nullptr,
25 base::OnceClosure()));
25 } 26 }
26 27
27 // static 28 // static
28 std::unique_ptr<ActivationStateComputingNavigationThrottle> 29 std::unique_ptr<ActivationStateComputingNavigationThrottle>
29 ActivationStateComputingNavigationThrottle::CreateForSubframe( 30 ActivationStateComputingNavigationThrottle::CreateForSubframe(
30 content::NavigationHandle* navigation_handle, 31 content::NavigationHandle* navigation_handle,
31 VerifiedRuleset::Handle* ruleset_handle, 32 VerifiedRuleset::Handle* ruleset_handle,
32 const ActivationState& parent_activation_state) { 33 const ActivationState& parent_activation_state,
34 base::OnceClosure first_disallowed_load_callback) {
33 DCHECK(!navigation_handle->IsInMainFrame()); 35 DCHECK(!navigation_handle->IsInMainFrame());
34 DCHECK_NE(ActivationLevel::DISABLED, 36 DCHECK_NE(ActivationLevel::DISABLED,
35 parent_activation_state.activation_level); 37 parent_activation_state.activation_level);
36 DCHECK(ruleset_handle); 38 DCHECK(ruleset_handle);
37 return base::WrapUnique(new ActivationStateComputingNavigationThrottle( 39 return base::WrapUnique(new ActivationStateComputingNavigationThrottle(
38 navigation_handle, parent_activation_state, ruleset_handle)); 40 navigation_handle, parent_activation_state, ruleset_handle,
41 std::move(first_disallowed_load_callback)));
39 } 42 }
40 43
41 ActivationStateComputingNavigationThrottle:: 44 ActivationStateComputingNavigationThrottle::
42 ActivationStateComputingNavigationThrottle( 45 ActivationStateComputingNavigationThrottle(
43 content::NavigationHandle* navigation_handle, 46 content::NavigationHandle* navigation_handle,
44 const base::Optional<ActivationState> parent_activation_state, 47 const base::Optional<ActivationState> parent_activation_state,
45 VerifiedRuleset::Handle* ruleset_handle) 48 VerifiedRuleset::Handle* ruleset_handle,
49 base::OnceClosure first_disallowed_load_callback)
46 : content::NavigationThrottle(navigation_handle), 50 : content::NavigationThrottle(navigation_handle),
47 parent_activation_state_(parent_activation_state), 51 parent_activation_state_(parent_activation_state),
48 ruleset_handle_(ruleset_handle), 52 ruleset_handle_(ruleset_handle),
53 first_disallowed_load_callback_(
54 std::move(first_disallowed_load_callback)),
49 weak_ptr_factory_(this) {} 55 weak_ptr_factory_(this) {}
50 56
51 ActivationStateComputingNavigationThrottle:: 57 ActivationStateComputingNavigationThrottle::
52 ~ActivationStateComputingNavigationThrottle() {} 58 ~ActivationStateComputingNavigationThrottle() {}
53 59
54 void ActivationStateComputingNavigationThrottle:: 60 void ActivationStateComputingNavigationThrottle::
55 NotifyPageActivationWithRuleset( 61 NotifyPageActivationWithRuleset(
56 VerifiedRuleset::Handle* ruleset_handle, 62 VerifiedRuleset::Handle* ruleset_handle,
57 const ActivationState& page_activation_state) { 63 const ActivationState& page_activation_state,
64 base::OnceClosure first_disallowed_load_callback) {
58 DCHECK(navigation_handle()->IsInMainFrame()); 65 DCHECK(navigation_handle()->IsInMainFrame());
59 DCHECK(!parent_activation_state_); 66 DCHECK(!parent_activation_state_);
60 DCHECK(!activation_state_); 67 DCHECK(!activation_state_);
61 DCHECK(!ruleset_handle_); 68 DCHECK(!ruleset_handle_);
62 // DISABLED implies null ruleset. 69 // DISABLED implies null ruleset.
63 DCHECK(page_activation_state.activation_level != ActivationLevel::DISABLED || 70 DCHECK(page_activation_state.activation_level != ActivationLevel::DISABLED ||
64 !ruleset_handle); 71 !ruleset_handle);
65 parent_activation_state_.emplace(page_activation_state); 72 parent_activation_state_.emplace(page_activation_state);
66 ruleset_handle_ = ruleset_handle; 73 ruleset_handle_ = ruleset_handle;
74 first_disallowed_load_callback_ = std::move(first_disallowed_load_callback);
67 } 75 }
68 76
69 content::NavigationThrottle::ThrottleCheckResult 77 content::NavigationThrottle::ThrottleCheckResult
70 ActivationStateComputingNavigationThrottle::WillProcessResponse() { 78 ActivationStateComputingNavigationThrottle::WillProcessResponse() {
71 // Main frame navigations with disabled page-level activation become 79 // Main frame navigations with disabled page-level activation become
72 // pass-through throttles. 80 // pass-through throttles.
73 if (!parent_activation_state_ || 81 if (!parent_activation_state_ ||
74 parent_activation_state_->activation_level == ActivationLevel::DISABLED) { 82 parent_activation_state_->activation_level == ActivationLevel::DISABLED) {
75 DCHECK(navigation_handle()->IsInMainFrame()); 83 DCHECK(navigation_handle()->IsInMainFrame());
76 DCHECK(!ruleset_handle_); 84 DCHECK(!ruleset_handle_);
77 activation_state_.emplace(ActivationLevel::DISABLED); 85 activation_state_.emplace(ActivationLevel::DISABLED);
78 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; 86 return content::NavigationThrottle::ThrottleCheckResult::PROCEED;
79 } 87 }
80 88
81 DCHECK(ruleset_handle_); 89 DCHECK(ruleset_handle_);
82 AsyncDocumentSubresourceFilter::InitializationParams params; 90 AsyncDocumentSubresourceFilter::InitializationParams params;
83 params.document_url = navigation_handle()->GetURL(); 91 params.document_url = navigation_handle()->GetURL();
84 params.parent_activation_state = parent_activation_state_.value(); 92 params.parent_activation_state = parent_activation_state_.value();
85 if (!navigation_handle()->IsInMainFrame()) { 93 if (!navigation_handle()->IsInMainFrame()) {
86 params.parent_document_origin = navigation_handle() 94 params.parent_document_origin = navigation_handle()
87 ->GetRenderFrameHost() 95 ->GetRenderFrameHost()
88 ->GetParent() 96 ->GetParent()
89 ->GetLastCommittedOrigin(); 97 ->GetLastCommittedOrigin();
90 } 98 }
91 // TODO(csharrison): Replace the empty OnceClosure with a UI-triggering
92 // callback.
93 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( 99 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>(
94 ruleset_handle_, std::move(params), 100 ruleset_handle_, std::move(params),
95 base::Bind(&ActivationStateComputingNavigationThrottle:: 101 base::Bind(&ActivationStateComputingNavigationThrottle::
96 SetActivationStateAndResume, 102 SetActivationStateAndResume,
97 weak_ptr_factory_.GetWeakPtr()), 103 weak_ptr_factory_.GetWeakPtr()),
98 base::OnceClosure()); 104 std::move(first_disallowed_load_callback_));
99 return content::NavigationThrottle::ThrottleCheckResult::DEFER; 105 return content::NavigationThrottle::ThrottleCheckResult::DEFER;
100 } 106 }
101 107
102 void ActivationStateComputingNavigationThrottle::SetActivationStateAndResume( 108 void ActivationStateComputingNavigationThrottle::SetActivationStateAndResume(
103 ActivationState state) { 109 ActivationState state) {
104 // Cannot send activation level to the renderer until ReadyToCommitNavigation, 110 // Cannot send activation level to the renderer until ReadyToCommitNavigation,
105 // the driver will pull the state out of |this| when that callback occurs. 111 // the driver will pull the state out of |this| when that callback occurs.
106 DCHECK(!activation_state_); 112 DCHECK(!activation_state_);
107 activation_state_.emplace(state); 113 activation_state_.emplace(state);
108 navigation_handle()->Resume(); 114 navigation_handle()->Resume();
109 } 115 }
110 116
111 std::unique_ptr<AsyncDocumentSubresourceFilter> 117 std::unique_ptr<AsyncDocumentSubresourceFilter>
112 ActivationStateComputingNavigationThrottle::ReleaseFilter() { 118 ActivationStateComputingNavigationThrottle::ReleaseFilter() {
113 return std::move(async_filter_); 119 return std::move(async_filter_);
114 } 120 }
115 121
116 const ActivationState& 122 const ActivationState&
117 ActivationStateComputingNavigationThrottle::GetActivationState() const { 123 ActivationStateComputingNavigationThrottle::GetActivationState() const {
118 return activation_state_.value(); 124 return activation_state_.value();
119 } 125 }
120 126
121 } // namespace subresource_filter 127 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698