OLD | NEW |
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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 ActivationStateComputingNavigationThrottle:: | 52 ActivationStateComputingNavigationThrottle:: |
53 ~ActivationStateComputingNavigationThrottle() {} | 53 ~ActivationStateComputingNavigationThrottle() {} |
54 | 54 |
55 void ActivationStateComputingNavigationThrottle:: | 55 void ActivationStateComputingNavigationThrottle:: |
56 NotifyPageActivationWithRuleset( | 56 NotifyPageActivationWithRuleset( |
57 VerifiedRuleset::Handle* ruleset_handle, | 57 VerifiedRuleset::Handle* ruleset_handle, |
58 const ActivationState& page_activation_state) { | 58 const ActivationState& page_activation_state) { |
59 DCHECK(navigation_handle()->IsInMainFrame()); | 59 DCHECK(navigation_handle()->IsInMainFrame()); |
60 DCHECK(!parent_activation_state_); | 60 DCHECK(!parent_activation_state_); |
61 DCHECK(!activation_state_); | |
62 DCHECK(!ruleset_handle_); | 61 DCHECK(!ruleset_handle_); |
63 // DISABLED implies null ruleset. | 62 // DISABLED implies null ruleset. |
64 DCHECK(page_activation_state.activation_level != ActivationLevel::DISABLED || | 63 DCHECK(page_activation_state.activation_level != ActivationLevel::DISABLED || |
65 !ruleset_handle); | 64 !ruleset_handle); |
66 parent_activation_state_.emplace(page_activation_state); | 65 parent_activation_state_ = page_activation_state; |
67 ruleset_handle_ = ruleset_handle; | 66 ruleset_handle_ = ruleset_handle; |
68 } | 67 } |
69 | 68 |
70 content::NavigationThrottle::ThrottleCheckResult | 69 content::NavigationThrottle::ThrottleCheckResult |
71 ActivationStateComputingNavigationThrottle::WillProcessResponse() { | 70 ActivationStateComputingNavigationThrottle::WillProcessResponse() { |
72 // Main frame navigations with disabled page-level activation become | 71 // Main frame navigations with disabled page-level activation become |
73 // pass-through throttles. | 72 // pass-through throttles. |
74 if (!parent_activation_state_ || | 73 if (!parent_activation_state_ || |
75 parent_activation_state_->activation_level == ActivationLevel::DISABLED) { | 74 parent_activation_state_->activation_level == ActivationLevel::DISABLED) { |
76 DCHECK(navigation_handle()->IsInMainFrame()); | 75 DCHECK(navigation_handle()->IsInMainFrame()); |
77 DCHECK(!ruleset_handle_); | 76 DCHECK(!ruleset_handle_); |
78 activation_state_.emplace(ActivationLevel::DISABLED); | |
79 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; | 77 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; |
80 } | 78 } |
81 | 79 |
82 DCHECK(ruleset_handle_); | 80 DCHECK(ruleset_handle_); |
83 AsyncDocumentSubresourceFilter::InitializationParams params; | 81 AsyncDocumentSubresourceFilter::InitializationParams params; |
84 params.document_url = navigation_handle()->GetURL(); | 82 params.document_url = navigation_handle()->GetURL(); |
85 params.parent_activation_state = parent_activation_state_.value(); | 83 params.parent_activation_state = parent_activation_state_.value(); |
86 if (!navigation_handle()->IsInMainFrame()) { | 84 if (!navigation_handle()->IsInMainFrame()) { |
87 content::RenderFrameHost* parent = | 85 content::RenderFrameHost* parent = |
88 navigation_handle()->GetWebContents()->FindFrameByFrameTreeNodeId( | 86 navigation_handle()->GetWebContents()->FindFrameByFrameTreeNodeId( |
89 navigation_handle()->GetParentFrameTreeNodeId()); | 87 navigation_handle()->GetParentFrameTreeNodeId()); |
90 DCHECK(parent); | 88 DCHECK(parent); |
91 params.parent_document_origin = parent->GetLastCommittedOrigin(); | 89 params.parent_document_origin = parent->GetLastCommittedOrigin(); |
92 } | 90 } |
93 // TODO(csharrison): Replace the empty OnceClosure with a UI-triggering | 91 |
94 // callback. | |
95 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( | 92 async_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( |
96 ruleset_handle_, std::move(params), | 93 ruleset_handle_, std::move(params), |
97 base::Bind(&ActivationStateComputingNavigationThrottle:: | 94 base::Bind(&ActivationStateComputingNavigationThrottle:: |
98 SetActivationStateAndResume, | 95 OnActivationStateComputed, |
99 weak_ptr_factory_.GetWeakPtr()), | 96 weak_ptr_factory_.GetWeakPtr())); |
100 base::OnceClosure()); | |
101 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | 97 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
102 } | 98 } |
103 | 99 |
104 void ActivationStateComputingNavigationThrottle::SetActivationStateAndResume( | 100 void ActivationStateComputingNavigationThrottle::OnActivationStateComputed( |
105 ActivationState state) { | 101 ActivationState state) { |
106 // Cannot send activation level to the renderer until ReadyToCommitNavigation, | |
107 // the driver will pull the state out of |this| when that callback occurs. | |
108 DCHECK(!activation_state_); | |
109 activation_state_.emplace(state); | |
110 navigation_handle()->Resume(); | 102 navigation_handle()->Resume(); |
111 } | 103 } |
112 | 104 |
| 105 // Ensure the caller cannot take ownership of a subresource filter for cases |
| 106 // when activation IPCs are not sent to the render process. |
113 std::unique_ptr<AsyncDocumentSubresourceFilter> | 107 std::unique_ptr<AsyncDocumentSubresourceFilter> |
114 ActivationStateComputingNavigationThrottle::ReleaseFilter() { | 108 ActivationStateComputingNavigationThrottle::ReleaseFilter() { |
115 return std::move(async_filter_); | 109 return will_send_activation_to_renderer_ ? std::move(async_filter_) : nullptr; |
116 } | 110 } |
117 | 111 |
118 const ActivationState& | 112 void ActivationStateComputingNavigationThrottle:: |
119 ActivationStateComputingNavigationThrottle::GetActivationState() const { | 113 WillSendActivationToRenderer() { |
120 return activation_state_.value(); | 114 DCHECK(async_filter_); |
| 115 will_send_activation_to_renderer_ = true; |
121 } | 116 } |
122 | 117 |
123 } // namespace subresource_filter | 118 } // namespace subresource_filter |
OLD | NEW |