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