OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content_subresource_filt
er_driver_factory.h" | 5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK_NE(activation_options_.activation_level, ActivationLevel::DISABLED); | 121 DCHECK_NE(activation_options_.activation_level, ActivationLevel::DISABLED); |
122 ActivationState state = ActivationState(activation_options_.activation_level); | 122 ActivationState state = ActivationState(activation_options_.activation_level); |
123 state.measure_performance = ShouldMeasurePerformanceForPageLoad( | 123 state.measure_performance = ShouldMeasurePerformanceForPageLoad( |
124 activation_options_.performance_measurement_rate); | 124 activation_options_.performance_measurement_rate); |
125 // TODO(csharrison): Set state.enable_logging based on metadata returns from | 125 // TODO(csharrison): Set state.enable_logging based on metadata returns from |
126 // the safe browsing filter, when it is available. Add tests for this | 126 // the safe browsing filter, when it is available. Add tests for this |
127 // behavior. | 127 // behavior. |
128 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); | 128 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); |
129 } | 129 } |
130 | 130 |
| 131 // Be careful when modifying this method, as the order in which the |
| 132 // activation_decision_ is decided is very important and corresponds to UMA |
| 133 // metrics. In general we want to follow the pattern that |
| 134 // ACTIVATION_CONDITIONS_NOT_MET will always be logged if no configuration |
| 135 // matches this navigation. We log other decisions only if a configuration |
| 136 // matches and also would have activated. |
131 void ContentSubresourceFilterDriverFactory:: | 137 void ContentSubresourceFilterDriverFactory:: |
132 ComputeActivationForMainFrameNavigation( | 138 ComputeActivationForMainFrameNavigation( |
133 content::NavigationHandle* navigation_handle, | 139 content::NavigationHandle* navigation_handle, |
134 ActivationList matched_list) { | 140 ActivationList matched_list) { |
135 const GURL& url(navigation_handle->GetURL()); | 141 const GURL& url(navigation_handle->GetURL()); |
136 | 142 |
137 if (!url.SchemeIsHTTPOrHTTPS()) { | 143 bool scheme_is_http_or_https = url.SchemeIsHTTPOrHTTPS(); |
138 activation_decision_ = ActivationDecision::UNSUPPORTED_SCHEME; | |
139 activation_options_ = Configuration::ActivationOptions(); | |
140 return; | |
141 } | |
142 | |
143 const auto config_list = GetEnabledConfigurations(); | 144 const auto config_list = GetEnabledConfigurations(); |
144 const auto highest_priority_activated_config = | 145 const auto highest_priority_activated_config = |
145 std::find_if(config_list->configs_by_decreasing_priority().begin(), | 146 std::find_if(config_list->configs_by_decreasing_priority().begin(), |
146 config_list->configs_by_decreasing_priority().end(), | 147 config_list->configs_by_decreasing_priority().end(), |
147 [&url, matched_list, this](const Configuration& config) { | 148 [&url, scheme_is_http_or_https, matched_list, |
| 149 this](const Configuration& config) { |
148 return DoesMainFrameURLSatisfyActivationConditions( | 150 return DoesMainFrameURLSatisfyActivationConditions( |
149 url, config.activation_conditions, matched_list); | 151 url, scheme_is_http_or_https, |
| 152 config.activation_conditions, matched_list); |
150 }); | 153 }); |
151 | 154 |
152 bool has_activated_config = | 155 bool has_activated_config = |
153 highest_priority_activated_config != | 156 highest_priority_activated_config != |
154 config_list->configs_by_decreasing_priority().end(); | 157 config_list->configs_by_decreasing_priority().end(); |
155 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("loading"), | 158 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("loading"), |
156 "ContentSubresourceFilterDriverFactory::" | 159 "ContentSubresourceFilterDriverFactory::" |
157 "ComputeActivationForMainFrameNavigation", | 160 "ComputeActivationForMainFrameNavigation", |
158 "highest_priority_activated_config", | 161 "highest_priority_activated_config", |
159 has_activated_config | 162 has_activated_config |
160 ? highest_priority_activated_config->ToTracedValue() | 163 ? highest_priority_activated_config->ToTracedValue() |
161 : base::MakeUnique<base::trace_event::TracedValue>()); | 164 : base::MakeUnique<base::trace_event::TracedValue>()); |
162 if (!has_activated_config) { | 165 if (!has_activated_config) { |
163 activation_decision_ = ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET; | 166 activation_decision_ = ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET; |
164 activation_options_ = Configuration::ActivationOptions(); | 167 activation_options_ = Configuration::ActivationOptions(); |
165 return; | 168 return; |
166 } | 169 } |
167 | 170 |
168 activation_options_ = highest_priority_activated_config->activation_options; | 171 const Configuration::ActivationOptions& activation_options = |
| 172 highest_priority_activated_config->activation_options; |
| 173 |
| 174 // Log UNSUPPORTED_SCHEME if we would have otherwise activated. |
| 175 if (!scheme_is_http_or_https && |
| 176 activation_options.activation_level != ActivationLevel::DISABLED) { |
| 177 activation_decision_ = ActivationDecision::UNSUPPORTED_SCHEME; |
| 178 activation_options_ = Configuration::ActivationOptions(); |
| 179 return; |
| 180 } |
| 181 |
| 182 activation_options_ = activation_options; |
169 activation_decision_ = | 183 activation_decision_ = |
170 activation_options_.activation_level == ActivationLevel::DISABLED | 184 activation_options_.activation_level == ActivationLevel::DISABLED |
171 ? ActivationDecision::ACTIVATION_DISABLED | 185 ? ActivationDecision::ACTIVATION_DISABLED |
172 : ActivationDecision::ACTIVATED; | 186 : ActivationDecision::ACTIVATED; |
173 } | 187 } |
174 | 188 |
175 bool ContentSubresourceFilterDriverFactory:: | 189 bool ContentSubresourceFilterDriverFactory:: |
176 DoesMainFrameURLSatisfyActivationConditions( | 190 DoesMainFrameURLSatisfyActivationConditions( |
177 const GURL& url, | 191 const GURL& url, |
| 192 bool scheme_is_http_or_https, |
178 const Configuration::ActivationConditions& conditions, | 193 const Configuration::ActivationConditions& conditions, |
179 ActivationList matched_list) const { | 194 ActivationList matched_list) const { |
| 195 // scheme_is_http_or_https implies url.SchemeIsHTTPOrHTTPS(). |
| 196 DCHECK(!scheme_is_http_or_https || url.SchemeIsHTTPOrHTTPS()); |
180 switch (conditions.activation_scope) { | 197 switch (conditions.activation_scope) { |
181 case ActivationScope::ALL_SITES: | 198 case ActivationScope::ALL_SITES: |
182 return true; | 199 return true; |
183 case ActivationScope::ACTIVATION_LIST: | 200 case ActivationScope::ACTIVATION_LIST: |
| 201 // ACTIVATION_LIST does not support non http/s URLs. |
| 202 if (!scheme_is_http_or_https) |
| 203 return false; |
184 if (conditions.activation_list == matched_list) | 204 if (conditions.activation_list == matched_list) |
185 return true; | 205 return true; |
186 if (conditions.activation_list == ActivationList::PHISHING_INTERSTITIAL && | 206 if (conditions.activation_list == ActivationList::PHISHING_INTERSTITIAL && |
187 matched_list == ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL) { | 207 matched_list == ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL) { |
188 // Handling special case, where activation on the phishing sites also | 208 // Handling special case, where activation on the phishing sites also |
189 // mean the activation on the sites with social engineering metadata. | 209 // mean the activation on the sites with social engineering metadata. |
190 return true; | 210 return true; |
191 } | 211 } |
192 return false; | 212 return false; |
193 case ActivationScope::NO_SITES: | 213 case ActivationScope::NO_SITES: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (navigation_handle->IsInMainFrame() && | 254 if (navigation_handle->IsInMainFrame() && |
235 !navigation_handle->IsSameDocument() && | 255 !navigation_handle->IsSameDocument() && |
236 activation_decision_ == ActivationDecision::UNKNOWN && | 256 activation_decision_ == ActivationDecision::UNKNOWN && |
237 navigation_handle->HasCommitted()) { | 257 navigation_handle->HasCommitted()) { |
238 activation_decision_ = ActivationDecision::ACTIVATION_DISABLED; | 258 activation_decision_ = ActivationDecision::ACTIVATION_DISABLED; |
239 activation_options_ = Configuration::ActivationOptions(); | 259 activation_options_ = Configuration::ActivationOptions(); |
240 } | 260 } |
241 } | 261 } |
242 | 262 |
243 } // namespace subresource_filter | 263 } // namespace subresource_filter |
OLD | NEW |