Chromium Code Reviews| 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/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 ui::PageTransition transition) { | 79 ui::PageTransition transition) { |
| 80 return ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) || | 80 return ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) || |
| 81 // Some pages 'reload' from JavaScript by navigating to themselves. | 81 // Some pages 'reload' from JavaScript by navigating to themselves. |
| 82 url == referrer.url; | 82 url == referrer.url; |
| 83 } | 83 } |
| 84 | 84 |
| 85 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( | 85 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( |
| 86 content::WebContents* web_contents, | 86 content::WebContents* web_contents, |
| 87 std::unique_ptr<SubresourceFilterClient> client) | 87 std::unique_ptr<SubresourceFilterClient> client) |
| 88 : content::WebContentsObserver(web_contents), | 88 : content::WebContentsObserver(web_contents), |
| 89 configuration_(GetActiveConfiguration()), | |
| 90 client_(std::move(client)), | 89 client_(std::move(client)), |
| 91 throttle_manager_( | 90 throttle_manager_( |
| 92 base::MakeUnique<ContentSubresourceFilterThrottleManager>( | 91 base::MakeUnique<ContentSubresourceFilterThrottleManager>( |
| 93 this, | 92 this, |
| 94 client_->GetRulesetDealer(), | 93 client_->GetRulesetDealer(), |
| 95 web_contents)), | 94 web_contents)), |
| 96 activation_level_(ActivationLevel::DISABLED), | 95 activation_level_(ActivationLevel::DISABLED), |
| 97 activation_decision_(ActivationDecision::UNKNOWN), | 96 activation_decision_(ActivationDecision::UNKNOWN), |
| 98 measure_performance_(false) {} | 97 measure_performance_(false) {} |
| 99 | 98 |
| 100 ContentSubresourceFilterDriverFactory:: | 99 ContentSubresourceFilterDriverFactory:: |
| 101 ~ContentSubresourceFilterDriverFactory() {} | 100 ~ContentSubresourceFilterDriverFactory() {} |
| 102 | 101 |
| 103 void ContentSubresourceFilterDriverFactory:: | 102 void ContentSubresourceFilterDriverFactory:: |
| 104 OnMainResourceMatchedSafeBrowsingBlacklist( | 103 OnMainResourceMatchedSafeBrowsingBlacklist( |
| 105 const GURL& url, | 104 const GURL& url, |
| 106 const std::vector<GURL>& redirect_urls, | 105 const std::vector<GURL>& redirect_urls, |
| 107 safe_browsing::SBThreatType threat_type, | 106 safe_browsing::SBThreatType threat_type, |
| 108 safe_browsing::ThreatPatternType threat_type_metadata) { | 107 safe_browsing::ThreatPatternType threat_type_metadata) { |
| 109 AddActivationListMatch( | 108 AddActivationListMatch( |
| 110 url, GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata)); | 109 url, GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata)); |
| 111 } | 110 } |
| 112 | 111 |
| 113 ContentSubresourceFilterDriverFactory::ActivationDecision | 112 ContentSubresourceFilterDriverFactory::ActivationDecision |
| 114 ContentSubresourceFilterDriverFactory:: | 113 ContentSubresourceFilterDriverFactory:: |
| 115 ComputeActivationDecisionForMainFrameNavigation( | 114 ComputeActivationDecisionForMainFrameNavigation( |
| 116 content::NavigationHandle* navigation_handle) const { | 115 content::NavigationHandle* navigation_handle) const { |
| 117 const GURL& url(navigation_handle->GetURL()); | 116 const GURL& url(navigation_handle->GetURL()); |
| 118 if (configuration_.activation_level == ActivationLevel::DISABLED) | 117 |
| 118 auto configurations = GetActiveConfigurations(); | |
|
Sorin Jianu
2017/04/24 21:58:59
const?
Also, please review the similar call sites
engedy
2017/04/25 08:34:24
Done.
| |
| 119 if (configurations->the_one_and_only().activation_level == | |
| 120 ActivationLevel::DISABLED) | |
| 119 return ActivationDecision::ACTIVATION_DISABLED; | 121 return ActivationDecision::ACTIVATION_DISABLED; |
| 120 | 122 |
| 121 if (configuration_.activation_scope == ActivationScope::NO_SITES) | 123 if (configurations->the_one_and_only().activation_scope == |
| 124 ActivationScope::NO_SITES) | |
| 122 return ActivationDecision::ACTIVATION_DISABLED; | 125 return ActivationDecision::ACTIVATION_DISABLED; |
| 123 | 126 |
| 124 if (!url.SchemeIsHTTPOrHTTPS()) | 127 if (!url.SchemeIsHTTPOrHTTPS()) |
| 125 return ActivationDecision::UNSUPPORTED_SCHEME; | 128 return ActivationDecision::UNSUPPORTED_SCHEME; |
| 126 // TODO(csharrison): The throttle manager also performs this check. Remove | 129 // TODO(csharrison): The throttle manager also performs this check. Remove |
| 127 // this one when the activation decision is sent directly to the throttle | 130 // this one when the activation decision is sent directly to the throttle |
| 128 // manager. | 131 // manager. |
| 129 if (client_->ShouldSuppressActivation(navigation_handle)) | 132 if (client_->ShouldSuppressActivation(navigation_handle)) |
| 130 return ActivationDecision::URL_WHITELISTED; | 133 return ActivationDecision::URL_WHITELISTED; |
| 131 | 134 |
| 132 switch (configuration_.activation_scope) { | 135 switch (configurations->the_one_and_only().activation_scope) { |
| 133 case ActivationScope::ALL_SITES: | 136 case ActivationScope::ALL_SITES: |
| 134 return ActivationDecision::ACTIVATED; | 137 return ActivationDecision::ACTIVATED; |
| 135 case ActivationScope::ACTIVATION_LIST: { | 138 case ActivationScope::ACTIVATION_LIST: { |
| 136 // The logic to ensure only http/https URLs are activated lives in | 139 // The logic to ensure only http/https URLs are activated lives in |
| 137 // AddActivationListMatch to ensure the activation list only has relevant | 140 // AddActivationListMatch to ensure the activation list only has relevant |
| 138 // entries. | 141 // entries. |
| 139 DCHECK(url.SchemeIsHTTPOrHTTPS() || | 142 DCHECK(url.SchemeIsHTTPOrHTTPS() || |
| 140 !DidURLMatchActivationList(url, configuration_.activation_list)); | 143 !DidURLMatchActivationList( |
| 141 bool should_activate = | 144 url, configurations->the_one_and_only().activation_list)); |
| 142 DidURLMatchActivationList(url, configuration_.activation_list); | 145 bool should_activate = DidURLMatchActivationList( |
| 143 if (configuration_.activation_list == | 146 url, configurations->the_one_and_only().activation_list); |
| 147 if (configurations->the_one_and_only().activation_list == | |
| 144 ActivationList::PHISHING_INTERSTITIAL) { | 148 ActivationList::PHISHING_INTERSTITIAL) { |
| 145 // Handling special case, where activation on the phishing sites also | 149 // Handling special case, where activation on the phishing sites also |
| 146 // mean the activation on the sites with social engineering metadata. | 150 // mean the activation on the sites with social engineering metadata. |
| 147 should_activate |= DidURLMatchActivationList( | 151 should_activate |= DidURLMatchActivationList( |
| 148 url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 152 url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 149 } | 153 } |
| 150 return should_activate ? ActivationDecision::ACTIVATED | 154 return should_activate ? ActivationDecision::ACTIVATED |
| 151 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED; | 155 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED; |
| 152 } | 156 } |
| 153 default: | 157 default: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 178 navigation_handle->GetNetErrorCode() != net::OK) { | 182 navigation_handle->GetNetErrorCode() != net::OK) { |
| 179 return; | 183 return; |
| 180 } | 184 } |
| 181 | 185 |
| 182 const GURL& url = navigation_handle->GetURL(); | 186 const GURL& url = navigation_handle->GetURL(); |
| 183 const content::Referrer& referrer = navigation_handle->GetReferrer(); | 187 const content::Referrer& referrer = navigation_handle->GetReferrer(); |
| 184 ui::PageTransition transition = navigation_handle->GetPageTransition(); | 188 ui::PageTransition transition = navigation_handle->GetPageTransition(); |
| 185 | 189 |
| 186 RecordRedirectChainMatchPattern(); | 190 RecordRedirectChainMatchPattern(); |
| 187 | 191 |
| 188 if (configuration_.should_whitelist_site_on_reload && | 192 auto configurations = GetActiveConfigurations(); |
| 193 if (configurations->the_one_and_only().should_whitelist_site_on_reload && | |
| 189 NavigationIsPageReload(url, referrer, transition)) { | 194 NavigationIsPageReload(url, referrer, transition)) { |
| 190 // Whitelist this host for the current as well as subsequent navigations. | 195 // Whitelist this host for the current as well as subsequent navigations. |
| 191 client_->WhitelistInCurrentWebContents(url); | 196 client_->WhitelistInCurrentWebContents(url); |
| 192 } | 197 } |
| 193 | 198 |
| 194 activation_decision_ = | 199 activation_decision_ = |
| 195 ComputeActivationDecisionForMainFrameNavigation(navigation_handle); | 200 ComputeActivationDecisionForMainFrameNavigation(navigation_handle); |
| 196 DCHECK(activation_decision_ != ActivationDecision::UNKNOWN); | 201 DCHECK(activation_decision_ != ActivationDecision::UNKNOWN); |
| 197 if (activation_decision_ != ActivationDecision::ACTIVATED) { | 202 if (activation_decision_ != ActivationDecision::ACTIVATED) { |
| 198 ResetActivationState(); | 203 ResetActivationState(); |
| 199 return; | 204 return; |
| 200 } | 205 } |
| 201 | 206 |
| 202 activation_level_ = configuration_.activation_level; | 207 activation_level_ = configurations->the_one_and_only().activation_level; |
| 203 measure_performance_ = activation_level_ != ActivationLevel::DISABLED && | 208 measure_performance_ = |
| 204 ShouldMeasurePerformanceForPageLoad( | 209 activation_level_ != ActivationLevel::DISABLED && |
| 205 configuration_.performance_measurement_rate); | 210 ShouldMeasurePerformanceForPageLoad( |
| 211 configurations->the_one_and_only().performance_measurement_rate); | |
| 206 ActivationState state = ActivationState(activation_level_); | 212 ActivationState state = ActivationState(activation_level_); |
| 207 state.measure_performance = measure_performance_; | 213 state.measure_performance = measure_performance_; |
| 208 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); | 214 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); |
| 209 } | 215 } |
| 210 | 216 |
| 211 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { | 217 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { |
| 212 if (configuration_.should_suppress_notifications) | 218 auto configurations = GetActiveConfigurations(); |
| 219 if (configurations->the_one_and_only().should_suppress_notifications) | |
| 213 return; | 220 return; |
| 214 | 221 |
| 215 client_->ToggleNotificationVisibility(activation_level_ == | 222 client_->ToggleNotificationVisibility(activation_level_ == |
| 216 ActivationLevel::ENABLED); | 223 ActivationLevel::ENABLED); |
| 217 } | 224 } |
| 218 | 225 |
| 219 bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation( | 226 bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation( |
| 220 content::NavigationHandle* navigation_handle) { | 227 content::NavigationHandle* navigation_handle) { |
| 221 return client_->ShouldSuppressActivation(navigation_handle); | 228 return client_->ShouldSuppressActivation(navigation_handle); |
| 222 } | 229 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, | 328 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, |
| 322 chain_size); | 329 chain_size); |
| 323 break; | 330 break; |
| 324 default: | 331 default: |
| 325 NOTREACHED(); | 332 NOTREACHED(); |
| 326 break; | 333 break; |
| 327 } | 334 } |
| 328 } | 335 } |
| 329 | 336 |
| 330 } // namespace subresource_filter | 337 } // namespace subresource_filter |
| OLD | NEW |