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

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

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

Powered by Google App Engine
This is Rietveld 408576698