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

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

Issue 2645283007: Add the client for accessing Subresource Filter only list. (Closed)
Patch Set: adressed comments from jwd Created 3 years, 9 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/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "components/subresource_filter/content/browser/subresource_filter_clien t.h" 10 #include "components/subresource_filter/content/browser/subresource_filter_clien t.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 url == referrer.url; 72 url == referrer.url;
73 } 73 }
74 74
75 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( 75 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory(
76 content::WebContents* web_contents, 76 content::WebContents* web_contents,
77 std::unique_ptr<SubresourceFilterClient> client) 77 std::unique_ptr<SubresourceFilterClient> client)
78 : content::WebContentsObserver(web_contents), 78 : content::WebContentsObserver(web_contents),
79 client_(std::move(client)), 79 client_(std::move(client)),
80 activation_level_(ActivationLevel::DISABLED), 80 activation_level_(ActivationLevel::DISABLED),
81 activation_decision_(ActivationDecision::UNKNOWN), 81 activation_decision_(ActivationDecision::UNKNOWN),
82 measure_performance_(false) {} 82 measure_performance_(false),
83 subresource_filter_only_hit_(false) {}
83 84
84 ContentSubresourceFilterDriverFactory:: 85 ContentSubresourceFilterDriverFactory::
85 ~ContentSubresourceFilterDriverFactory() {} 86 ~ContentSubresourceFilterDriverFactory() {}
86 87
87 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { 88 void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
88 if (ShouldSuppressNotifications()) 89 if (ShouldSuppressNotifications())
89 return; 90 return;
90 91
91 client_->ToggleNotificationVisibility(activation_level_ == 92 client_->ToggleNotificationVisibility(activation_level_ ==
92 ActivationLevel::ENABLED); 93 ActivationLevel::ENABLED);
(...skipping 25 matching lines...) Expand all
118 OnMainResourceMatchedSafeBrowsingBlacklist( 119 OnMainResourceMatchedSafeBrowsingBlacklist(
119 const GURL& url, 120 const GURL& url,
120 const std::vector<GURL>& redirect_urls, 121 const std::vector<GURL>& redirect_urls,
121 safe_browsing::SBThreatType threat_type, 122 safe_browsing::SBThreatType threat_type,
122 safe_browsing::ThreatPatternType threat_type_metadata) { 123 safe_browsing::ThreatPatternType threat_type_metadata) {
123 bool is_phishing_interstitial = 124 bool is_phishing_interstitial =
124 (threat_type == safe_browsing::SB_THREAT_TYPE_URL_PHISHING); 125 (threat_type == safe_browsing::SB_THREAT_TYPE_URL_PHISHING);
125 bool is_soc_engineering_ads_interstitial = 126 bool is_soc_engineering_ads_interstitial =
126 threat_type_metadata == 127 threat_type_metadata ==
127 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS; 128 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS;
128 129 subresource_filter_only_hit_ =
130 threat_type == safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER;
129 if (is_phishing_interstitial) { 131 if (is_phishing_interstitial) {
130 if (is_soc_engineering_ads_interstitial) { 132 if (is_soc_engineering_ads_interstitial) {
131 AddActivationListMatch(url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); 133 AddActivationListMatch(url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL);
132 } 134 }
133 AddActivationListMatch(url, ActivationList::PHISHING_INTERSTITIAL); 135 AddActivationListMatch(url, ActivationList::PHISHING_INTERSTITIAL);
136 } else if (subresource_filter_only_hit_) {
137 AddActivationListMatch(url, ActivationList::SUBRESOURCE_FILTER);
134 } 138 }
135 } 139 }
136 140
137 void ContentSubresourceFilterDriverFactory::AddHostOfURLToWhitelistSet( 141 void ContentSubresourceFilterDriverFactory::AddHostOfURLToWhitelistSet(
138 const GURL& url) { 142 const GURL& url) {
139 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) 143 if (url.has_host() && url.SchemeIsHTTPOrHTTPS())
140 whitelisted_hosts_.insert(url.host()); 144 whitelisted_hosts_.insert(url.host());
141 } 145 }
142 146
143 ContentSubresourceFilterDriverFactory::ActivationDecision 147 ContentSubresourceFilterDriverFactory::ActivationDecision
(...skipping 12 matching lines...) Expand all
156 return ActivationDecision::URL_WHITELISTED; 160 return ActivationDecision::URL_WHITELISTED;
157 161
158 switch (scope) { 162 switch (scope) {
159 case ActivationScope::ALL_SITES: 163 case ActivationScope::ALL_SITES:
160 return ActivationDecision::ACTIVATED; 164 return ActivationDecision::ACTIVATED;
161 case ActivationScope::ACTIVATION_LIST: 165 case ActivationScope::ACTIVATION_LIST:
162 // The logic to ensure only http/https URLs are activated lives in 166 // The logic to ensure only http/https URLs are activated lives in
163 // AddActivationListMatch to ensure the activation list only has relevant 167 // AddActivationListMatch to ensure the activation list only has relevant
164 // entries. 168 // entries.
165 DCHECK(url.SchemeIsHTTPOrHTTPS() || 169 DCHECK(url.SchemeIsHTTPOrHTTPS() ||
166 !DidURLMatchCurrentActivationList(url)); 170 !DidURLMatchActivationList(url, GetCurrentActivationList()));
167 return DidURLMatchCurrentActivationList(url) 171 return DidURLMatchActivationList(url, GetCurrentActivationList())
168 ? ActivationDecision::ACTIVATED 172 ? ActivationDecision::ACTIVATED
169 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED; 173 : ActivationDecision::ACTIVATION_LIST_NOT_MATCHED;
170 default: 174 default:
171 return ActivationDecision::ACTIVATION_DISABLED; 175 return ActivationDecision::ACTIVATION_DISABLED;
172 } 176 }
173 } 177 }
174 178
175 void ContentSubresourceFilterDriverFactory::ActivateForFrameHostIfNeeded( 179 void ContentSubresourceFilterDriverFactory::ActivateForFrameHostIfNeeded(
176 content::RenderFrameHost* render_frame_host, 180 content::RenderFrameHost* render_frame_host,
177 const GURL& url) { 181 const GURL& url) {
(...skipping 21 matching lines...) Expand all
199 } 203 }
200 204
201 void ContentSubresourceFilterDriverFactory::DidStartNavigation( 205 void ContentSubresourceFilterDriverFactory::DidStartNavigation(
202 content::NavigationHandle* navigation_handle) { 206 content::NavigationHandle* navigation_handle) {
203 if (navigation_handle->IsInMainFrame() && 207 if (navigation_handle->IsInMainFrame() &&
204 !navigation_handle->IsSameDocument()) { 208 !navigation_handle->IsSameDocument()) {
205 activation_decision_ = ActivationDecision::UNKNOWN; 209 activation_decision_ = ActivationDecision::UNKNOWN;
206 ResetActivationState(); 210 ResetActivationState();
207 navigation_chain_.push_back(navigation_handle->GetURL()); 211 navigation_chain_.push_back(navigation_handle->GetURL());
208 client_->ToggleNotificationVisibility(false); 212 client_->ToggleNotificationVisibility(false);
213 subresource_filter_only_hit_ = false;
209 } 214 }
210 } 215 }
211 216
212 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation( 217 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation(
213 content::NavigationHandle* navigation_handle) { 218 content::NavigationHandle* navigation_handle) {
214 DCHECK(!navigation_handle->IsSameDocument()); 219 DCHECK(!navigation_handle->IsSameDocument());
215 if (navigation_handle->IsInMainFrame()) 220 if (navigation_handle->IsInMainFrame())
216 navigation_chain_.push_back(navigation_handle->GetURL()); 221 navigation_chain_.push_back(navigation_handle->GetURL());
217 } 222 }
218 223
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ResetActivationState(); 319 ResetActivationState();
315 return; 320 return;
316 } 321 }
317 322
318 activation_level_ = GetMaximumActivationLevel(); 323 activation_level_ = GetMaximumActivationLevel();
319 measure_performance_ = activation_level_ != ActivationLevel::DISABLED && 324 measure_performance_ = activation_level_ != ActivationLevel::DISABLED &&
320 ShouldMeasurePerformanceForPageLoad(); 325 ShouldMeasurePerformanceForPageLoad();
321 ActivateForFrameHostIfNeeded(render_frame_host, url); 326 ActivateForFrameHostIfNeeded(render_frame_host, url);
322 } 327 }
323 328
324 bool ContentSubresourceFilterDriverFactory::DidURLMatchCurrentActivationList( 329 bool ContentSubresourceFilterDriverFactory::DidURLMatchActivationList(
325 const GURL& url) const { 330 const GURL& url,
331 ActivationList acttivation_list) const {
326 auto match_types = 332 auto match_types =
327 activation_list_matches_.find(DistillURLToHostAndPath(url)); 333 activation_list_matches_.find(DistillURLToHostAndPath(url));
328 return match_types != activation_list_matches_.end() && 334 return match_types != activation_list_matches_.end() &&
329 match_types->second.find(GetCurrentActivationList()) != 335 match_types->second.find(acttivation_list) !=
330 match_types->second.end(); 336 match_types->second.end();
331 } 337 }
332 338
333 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( 339 void ContentSubresourceFilterDriverFactory::AddActivationListMatch(
334 const GURL& url, 340 const GURL& url,
335 ActivationList match_type) { 341 ActivationList match_type) {
336 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) 342 if (url.has_host() && url.SchemeIsHTTPOrHTTPS())
337 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); 343 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type);
338 } 344 }
339 345
340 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() 346 int ContentSubresourceFilterDriverFactory::CalculateHitPatternForActivationList(
341 const { 347 ActivationList activation_list) const {
342 int hits_pattern = 0; 348 int hits_pattern = 0;
343 const int kInitialURLHitMask = 0x4; 349 const int kInitialURLHitMask = 0x4;
344 const int kRedirectURLHitMask = 0x2; 350 const int kRedirectURLHitMask = 0x2;
345 const int kFinalURLHitMask = 0x1; 351 const int kFinalURLHitMask = 0x1;
352
346 if (navigation_chain_.size() > 1) { 353 if (navigation_chain_.size() > 1) {
347 if (DidURLMatchCurrentActivationList(navigation_chain_.back())) 354 if (DidURLMatchActivationList(navigation_chain_.back(), activation_list))
348 hits_pattern |= kFinalURLHitMask; 355 hits_pattern |= kFinalURLHitMask;
349 if (DidURLMatchCurrentActivationList(navigation_chain_.front())) 356 if (DidURLMatchActivationList(navigation_chain_.front(), activation_list))
350 hits_pattern |= kInitialURLHitMask; 357 hits_pattern |= kInitialURLHitMask;
351 358
352 // Examine redirects. 359 // Examine redirects.
353 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) { 360 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) {
354 if (DidURLMatchCurrentActivationList(navigation_chain_[i])) { 361 if (DidURLMatchActivationList(navigation_chain_[i], activation_list)) {
355 hits_pattern |= kRedirectURLHitMask; 362 hits_pattern |= kRedirectURLHitMask;
356 break; 363 break;
357 } 364 }
358 } 365 }
359 } else { 366 } else {
360 if (navigation_chain_.size() && 367 if (navigation_chain_.size() &&
361 DidURLMatchCurrentActivationList(navigation_chain_.front())) { 368 DidURLMatchActivationList(navigation_chain_.front(), activation_list)) {
362 hits_pattern = 0x8; // One url hit. 369 hits_pattern = 0x8; // One url hit.
363 } 370 }
364 } 371 }
372 return hits_pattern;
373 }
374
375 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern()
376 const {
377 int hits_pattern = CalculateHitPatternForActivationList(
378 !subresource_filter_only_hit_ ? GetCurrentActivationList()
379 : ActivationList::SUBRESOURCE_FILTER);
365 if (!hits_pattern) 380 if (!hits_pattern)
366 return; 381 return;
367 UMA_HISTOGRAM_ENUMERATION( 382 if (subresource_filter_only_hit_) {
368 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern, 383 UMA_HISTOGRAM_ENUMERATION(
369 0x10 /* max value */); 384 "SubresourceFilter.PageLoad.RedirectChainMatchPattern."
370 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength", 385 "SubresourceFilterOnly",
371 navigation_chain_.size()); 386 hits_pattern, 0x10 /* max value */);
387 UMA_HISTOGRAM_COUNTS(
388 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly",
389 navigation_chain_.size());
390
391 } else {
392 UMA_HISTOGRAM_ENUMERATION(
393 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern,
394 0x10 /* max value */);
395 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength",
396 navigation_chain_.size());
397 };
372 } 398 }
373 399
374 } // namespace subresource_filter 400 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698