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

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

Issue 2844063002: Add support for multiple simultaneous subresource_filter::Configurations. (Closed)
Patch Set: Fix compile error. Created 3 years, 7 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 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( 78 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory(
79 content::WebContents* web_contents, 79 content::WebContents* web_contents,
80 SubresourceFilterClient* client) 80 SubresourceFilterClient* client)
81 : content::WebContentsObserver(web_contents), 81 : content::WebContentsObserver(web_contents),
82 client_(client), 82 client_(client),
83 throttle_manager_( 83 throttle_manager_(
84 base::MakeUnique<ContentSubresourceFilterThrottleManager>( 84 base::MakeUnique<ContentSubresourceFilterThrottleManager>(
85 this, 85 this,
86 client_->GetRulesetDealer(), 86 client_->GetRulesetDealer(),
87 web_contents)), 87 web_contents)) {}
88 activation_level_(ActivationLevel::DISABLED),
89 activation_decision_(ActivationDecision::UNKNOWN),
90 measure_performance_(false) {}
91 88
92 ContentSubresourceFilterDriverFactory:: 89 ContentSubresourceFilterDriverFactory::
93 ~ContentSubresourceFilterDriverFactory() {} 90 ~ContentSubresourceFilterDriverFactory() {}
94 91
95 void ContentSubresourceFilterDriverFactory:: 92 void ContentSubresourceFilterDriverFactory::
96 OnMainResourceMatchedSafeBrowsingBlacklist( 93 OnMainResourceMatchedSafeBrowsingBlacklist(
97 const GURL& url, 94 const GURL& url,
98 const std::vector<GURL>& redirect_urls, 95 const std::vector<GURL>& redirect_urls,
99 safe_browsing::SBThreatType threat_type, 96 safe_browsing::SBThreatType threat_type,
100 safe_browsing::ThreatPatternType threat_type_metadata) { 97 safe_browsing::ThreatPatternType threat_type_metadata) {
101 AddActivationListMatch( 98 AddActivationListMatch(
102 url, GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata)); 99 url, GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata));
103 } 100 }
104 101
102 void ContentSubresourceFilterDriverFactory::
103 ComputeActivationForMainFrameNavigation(
104 content::NavigationHandle* navigation_handle) {
105 activation_decision_ = ActivationDecision::ACTIVATION_DISABLED;
106 activation_options_ = Configuration::ActivationOptions();
107 const auto config_list = GetEnabledConfigurations();
108 for (const auto& config : config_list->configs_by_decreasing_priority()) {
109 ActivationDecision decision =
110 ComputePerConfigActivationDecisionForMainFrameNavigation(
111 navigation_handle, config);
112 if (decision == ActivationDecision::ACTIVATED) {
Charlie Harrison 2017/05/05 13:12:52 As Pavel pointed out I think the main problem here
engedy 2017/05/05 13:21:23 Ah, I slightly misunderstood the concern previousl
113 activation_decision_ = ActivationDecision::ACTIVATED;
114 activation_options_ = config.activation_options;
115 return;
116 }
117
118 // Remember a |decision| more specific than `ACTIVATION_DISABLED`, if any.
119 if (decision != ActivationDecision::ACTIVATION_DISABLED)
120 activation_decision_ = decision;
121 }
122 }
123
105 ContentSubresourceFilterDriverFactory::ActivationDecision 124 ContentSubresourceFilterDriverFactory::ActivationDecision
106 ContentSubresourceFilterDriverFactory:: 125 ContentSubresourceFilterDriverFactory::
107 ComputeActivationDecisionForMainFrameNavigation( 126 ComputePerConfigActivationDecisionForMainFrameNavigation(
108 content::NavigationHandle* navigation_handle) const { 127 content::NavigationHandle* navigation_handle,
128 const Configuration& configuration) const {
109 const GURL& url(navigation_handle->GetURL()); 129 const GURL& url(navigation_handle->GetURL());
110 130 if (configuration.activation_options.activation_level ==
111 const auto configurations = GetActiveConfigurations();
112 if (configurations->the_one_and_only().activation_level ==
113 ActivationLevel::DISABLED) 131 ActivationLevel::DISABLED)
114 return ActivationDecision::ACTIVATION_DISABLED; 132 return ActivationDecision::ACTIVATION_DISABLED;
115 133
116 if (configurations->the_one_and_only().activation_scope == 134 if (configuration.activation_conditions.activation_scope ==
117 ActivationScope::NO_SITES) 135 ActivationScope::NO_SITES)
118 return ActivationDecision::ACTIVATION_DISABLED; 136 return ActivationDecision::ACTIVATION_DISABLED;
119 137
120 if (!url.SchemeIsHTTPOrHTTPS()) 138 if (!url.SchemeIsHTTPOrHTTPS())
121 return ActivationDecision::UNSUPPORTED_SCHEME; 139 return ActivationDecision::UNSUPPORTED_SCHEME;
140
122 // TODO(csharrison): The throttle manager also performs this check. Remove 141 // TODO(csharrison): The throttle manager also performs this check. Remove
123 // this one when the activation decision is sent directly to the throttle 142 // this one when the activation decision is sent directly to the throttle
124 // manager. 143 // manager.
125 if (client_->ShouldSuppressActivation(navigation_handle)) 144 if (client_->ShouldSuppressActivation(navigation_handle))
126 return ActivationDecision::URL_WHITELISTED; 145 return ActivationDecision::URL_WHITELISTED;
127 146
128 switch (configurations->the_one_and_only().activation_scope) { 147 switch (configuration.activation_conditions.activation_scope) {
129 case ActivationScope::ALL_SITES: 148 case ActivationScope::ALL_SITES:
130 return ActivationDecision::ACTIVATED; 149 return ActivationDecision::ACTIVATED;
131 case ActivationScope::ACTIVATION_LIST: { 150 case ActivationScope::ACTIVATION_LIST: {
132 // The logic to ensure only http/https URLs are activated lives in 151 // The logic to ensure only http/https URLs are activated lives in
133 // AddActivationListMatch to ensure the activation list only has relevant 152 // AddActivationListMatch to ensure the activation list only has relevant
134 // entries. 153 // entries.
135 DCHECK(url.SchemeIsHTTPOrHTTPS() || 154 DCHECK(url.SchemeIsHTTPOrHTTPS() ||
136 !DidURLMatchActivationList( 155 !DidURLMatchActivationList(
137 url, configurations->the_one_and_only().activation_list)); 156 url, configuration.activation_conditions.activation_list));
138 bool should_activate = DidURLMatchActivationList( 157 bool should_activate = DidURLMatchActivationList(
139 url, configurations->the_one_and_only().activation_list); 158 url, configuration.activation_conditions.activation_list);
140 if (configurations->the_one_and_only().activation_list == 159 if (configuration.activation_conditions.activation_list ==
141 ActivationList::PHISHING_INTERSTITIAL) { 160 ActivationList::PHISHING_INTERSTITIAL) {
142 // Handling special case, where activation on the phishing sites also 161 // Handling special case, where activation on the phishing sites also
143 // mean the activation on the sites with social engineering metadata. 162 // mean the activation on the sites with social engineering metadata.
144 should_activate |= DidURLMatchActivationList( 163 should_activate |= DidURLMatchActivationList(
145 url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); 164 url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL);
146 } 165 }
147 return should_activate ? ActivationDecision::ACTIVATED 166 return should_activate ? ActivationDecision::ACTIVATED
148 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED; 167 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED;
149 } 168 }
150 default: 169 default:
(...skipping 24 matching lines...) Expand all
175 navigation_handle->GetNetErrorCode() != net::OK) { 194 navigation_handle->GetNetErrorCode() != net::OK) {
176 return; 195 return;
177 } 196 }
178 197
179 const GURL& url = navigation_handle->GetURL(); 198 const GURL& url = navigation_handle->GetURL();
180 const content::Referrer& referrer = navigation_handle->GetReferrer(); 199 const content::Referrer& referrer = navigation_handle->GetReferrer();
181 ui::PageTransition transition = navigation_handle->GetPageTransition(); 200 ui::PageTransition transition = navigation_handle->GetPageTransition();
182 201
183 RecordRedirectChainMatchPattern(); 202 RecordRedirectChainMatchPattern();
184 203
185 const auto configurations = GetActiveConfigurations(); 204 if (activation_options_.should_whitelist_site_on_reload &&
186 if (configurations->the_one_and_only().should_whitelist_site_on_reload &&
187 NavigationIsPageReload(url, referrer, transition)) { 205 NavigationIsPageReload(url, referrer, transition)) {
188 // Whitelist this host for the current as well as subsequent navigations. 206 // Whitelist this host for the current as well as subsequent navigations.
189 client_->WhitelistInCurrentWebContents(url); 207 client_->WhitelistInCurrentWebContents(url);
190 } 208 }
191 209
192 activation_decision_ = 210 ComputeActivationForMainFrameNavigation(navigation_handle);
193 ComputeActivationDecisionForMainFrameNavigation(navigation_handle); 211 DCHECK_NE(activation_decision_, ActivationDecision::UNKNOWN);
194 DCHECK(activation_decision_ != ActivationDecision::UNKNOWN);
195 if (activation_decision_ != ActivationDecision::ACTIVATED) { 212 if (activation_decision_ != ActivationDecision::ACTIVATED) {
196 ResetActivationState(); 213 DCHECK_EQ(activation_options_.activation_level, ActivationLevel::DISABLED);
197 return; 214 return;
198 } 215 }
199 216
200 activation_level_ = configurations->the_one_and_only().activation_level; 217 DCHECK_NE(activation_options_.activation_level, ActivationLevel::DISABLED);
201 measure_performance_ = 218 ActivationState state = ActivationState(activation_options_.activation_level);
202 activation_level_ != ActivationLevel::DISABLED && 219 state.measure_performance = ShouldMeasurePerformanceForPageLoad(
203 ShouldMeasurePerformanceForPageLoad( 220 activation_options_.performance_measurement_rate);
204 configurations->the_one_and_only().performance_measurement_rate);
205 ActivationState state = ActivationState(activation_level_);
206 state.measure_performance = measure_performance_;
207 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); 221 throttle_manager_->NotifyPageActivationComputed(navigation_handle, state);
208 } 222 }
209 223
210 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { 224 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
211 const auto configurations = GetActiveConfigurations(); 225 if (activation_options_.should_suppress_notifications)
212 if (configurations->the_one_and_only().should_suppress_notifications)
213 return; 226 return;
214 227 client_->ToggleNotificationVisibility(activation_options_.activation_level ==
215 client_->ToggleNotificationVisibility(activation_level_ ==
216 ActivationLevel::ENABLED); 228 ActivationLevel::ENABLED);
217 } 229 }
218 230
219 bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation( 231 bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation(
220 content::NavigationHandle* navigation_handle) { 232 content::NavigationHandle* navigation_handle) {
221 return client_->ShouldSuppressActivation(navigation_handle); 233 return client_->ShouldSuppressActivation(navigation_handle);
222 } 234 }
223 235
224 void ContentSubresourceFilterDriverFactory::ResetActivationState() {
225 navigation_chain_.clear();
226 activation_list_matches_.clear();
227 activation_level_ = ActivationLevel::DISABLED;
228 measure_performance_ = false;
229 }
230
231 void ContentSubresourceFilterDriverFactory::DidStartNavigation( 236 void ContentSubresourceFilterDriverFactory::DidStartNavigation(
232 content::NavigationHandle* navigation_handle) { 237 content::NavigationHandle* navigation_handle) {
233 if (navigation_handle->IsInMainFrame() && 238 if (navigation_handle->IsInMainFrame() &&
234 !navigation_handle->IsSameDocument()) { 239 !navigation_handle->IsSameDocument()) {
235 activation_decision_ = ActivationDecision::UNKNOWN; 240 activation_decision_ = ActivationDecision::UNKNOWN;
236 ResetActivationState(); 241 activation_list_matches_.clear();
237 navigation_chain_.push_back(navigation_handle->GetURL()); 242 navigation_chain_ = {navigation_handle->GetURL()};
238 client_->ToggleNotificationVisibility(false); 243 client_->ToggleNotificationVisibility(false);
239 } 244 }
240 } 245 }
241 246
242 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation( 247 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation(
243 content::NavigationHandle* navigation_handle) { 248 content::NavigationHandle* navigation_handle) {
244 DCHECK(!navigation_handle->IsSameDocument()); 249 DCHECK(!navigation_handle->IsSameDocument());
245 if (navigation_handle->IsInMainFrame()) 250 if (navigation_handle->IsInMainFrame())
246 navigation_chain_.push_back(navigation_handle->GetURL()); 251 navigation_chain_.push_back(navigation_handle->GetURL());
247 } 252 }
248 253
254 void ContentSubresourceFilterDriverFactory::DidFinishNavigation(
255 content::NavigationHandle* navigation_handle) {
256 if (navigation_handle->IsInMainFrame() &&
257 !navigation_handle->IsSameDocument() &&
258 activation_decision_ == ActivationDecision::UNKNOWN &&
259 navigation_handle->HasCommitted()) {
260 activation_decision_ = ActivationDecision::ACTIVATION_DISABLED;
261 activation_options_ = Configuration::ActivationOptions();
262 }
263 }
264
249 bool ContentSubresourceFilterDriverFactory::DidURLMatchActivationList( 265 bool ContentSubresourceFilterDriverFactory::DidURLMatchActivationList(
250 const GURL& url, 266 const GURL& url,
251 ActivationList activation_list) const { 267 ActivationList activation_list) const {
252 auto match_types = 268 auto match_types =
253 activation_list_matches_.find(DistillURLToHostAndPath(url)); 269 activation_list_matches_.find(DistillURLToHostAndPath(url));
254 return match_types != activation_list_matches_.end() && 270 return match_types != activation_list_matches_.end() &&
255 match_types->second.find(activation_list) != match_types->second.end(); 271 match_types->second.find(activation_list) != match_types->second.end();
256 } 272 }
257 273
258 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( 274 void ContentSubresourceFilterDriverFactory::AddActivationListMatch(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern, 337 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", hits_pattern,
322 chain_size); 338 chain_size);
323 break; 339 break;
324 default: 340 default:
325 NOTREACHED(); 341 NOTREACHED();
326 break; 342 break;
327 } 343 }
328 } 344 }
329 345
330 } // namespace subresource_filter 346 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698