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

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: fix HistoryNavTest 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/common/subresource_filter_messag es.h" 10 #include "components/subresource_filter/content/common/subresource_filter_messag es.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 aggregated_document_statistics_ = DocumentLoadStatistics(); 202 aggregated_document_statistics_ = DocumentLoadStatistics();
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() && !navigation_handle->IsSamePage()) { 207 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) {
204 activation_decision_ = ActivationDecision::UNKNOWN; 208 activation_decision_ = ActivationDecision::UNKNOWN;
205 ResetActivationState(); 209 ResetActivationState();
206 navigation_chain_.push_back(navigation_handle->GetURL()); 210 navigation_chain_.push_back(navigation_handle->GetURL());
207 client_->ToggleNotificationVisibility(false); 211 client_->ToggleNotificationVisibility(false);
212 subresource_filter_only_hit_ = false;
208 } 213 }
209 } 214 }
210 215
211 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation( 216 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation(
212 content::NavigationHandle* navigation_handle) { 217 content::NavigationHandle* navigation_handle) {
213 DCHECK(!navigation_handle->IsSamePage()); 218 DCHECK(!navigation_handle->IsSamePage());
214 if (navigation_handle->IsInMainFrame()) 219 if (navigation_handle->IsInMainFrame())
215 navigation_chain_.push_back(navigation_handle->GetURL()); 220 navigation_chain_.push_back(navigation_handle->GetURL());
216 } 221 }
217 222
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 327
323 bool ContentSubresourceFilterDriverFactory::DidURLMatchCurrentActivationList( 328 bool ContentSubresourceFilterDriverFactory::DidURLMatchCurrentActivationList(
324 const GURL& url) const { 329 const GURL& url) const {
325 auto match_types = 330 auto match_types =
326 activation_list_matches_.find(DistillURLToHostAndPath(url)); 331 activation_list_matches_.find(DistillURLToHostAndPath(url));
327 return match_types != activation_list_matches_.end() && 332 return match_types != activation_list_matches_.end() &&
328 match_types->second.find(GetCurrentActivationList()) != 333 match_types->second.find(GetCurrentActivationList()) !=
329 match_types->second.end(); 334 match_types->second.end();
330 } 335 }
331 336
337 bool ContentSubresourceFilterDriverFactory::
338 DidURLMatchSubresourceFilterOnlyList(const GURL& url) const {
engedy 2017/03/02 12:00:42 Let's try to avoid duplicating the code above, and
melandory 2017/03/06 15:00:00 Done.
339 auto match_types =
340 activation_list_matches_.find(DistillURLToHostAndPath(url));
341 return match_types != activation_list_matches_.end() &&
342 match_types->second.find(ActivationList::SUBRESOURCE_FILTER) !=
343 match_types->second.end();
344 }
345
332 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( 346 void ContentSubresourceFilterDriverFactory::AddActivationListMatch(
333 const GURL& url, 347 const GURL& url,
334 ActivationList match_type) { 348 ActivationList match_type) {
335 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) 349 if (url.has_host() && url.SchemeIsHTTPOrHTTPS())
336 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); 350 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type);
337 } 351 }
338 352
339 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() 353 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern()
engedy 2017/03/02 12:00:43 What do you think of recording two histograms here
melandory 2017/03/06 15:00:00 I like the idea. A bit of refactoring will be invo
340 const { 354 const {
341 int hits_pattern = 0; 355 int hits_pattern = 0;
342 const int kInitialURLHitMask = 0x4; 356 const int kInitialURLHitMask = 0x4;
343 const int kRedirectURLHitMask = 0x2; 357 const int kRedirectURLHitMask = 0x2;
344 const int kFinalURLHitMask = 0x1; 358 const int kFinalURLHitMask = 0x1;
359 auto in_list = [this](const GURL& url) {
360 return subresource_filter_only_hit_
361 ? DidURLMatchSubresourceFilterOnlyList(url)
362 : DidURLMatchCurrentActivationList(url);
363 };
345 if (navigation_chain_.size() > 1) { 364 if (navigation_chain_.size() > 1) {
346 if (DidURLMatchCurrentActivationList(navigation_chain_.back())) 365 if (in_list(navigation_chain_.back()))
347 hits_pattern |= kFinalURLHitMask; 366 hits_pattern |= kFinalURLHitMask;
348 if (DidURLMatchCurrentActivationList(navigation_chain_.front())) 367 if (in_list(navigation_chain_.front()))
349 hits_pattern |= kInitialURLHitMask; 368 hits_pattern |= kInitialURLHitMask;
350 369
351 // Examine redirects. 370 // Examine redirects.
352 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) { 371 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) {
353 if (DidURLMatchCurrentActivationList(navigation_chain_[i])) { 372 if (in_list(navigation_chain_[i])) {
354 hits_pattern |= kRedirectURLHitMask; 373 hits_pattern |= kRedirectURLHitMask;
355 break; 374 break;
356 } 375 }
357 } 376 }
358 } else { 377 } else {
359 if (navigation_chain_.size() && 378 if (navigation_chain_.size() && in_list(navigation_chain_.front())) {
360 DidURLMatchCurrentActivationList(navigation_chain_.front())) {
361 hits_pattern = 0x8; // One url hit. 379 hits_pattern = 0x8; // One url hit.
362 } 380 }
363 } 381 }
364 if (!hits_pattern) 382 if (!hits_pattern)
365 return; 383 return;
366 UMA_HISTOGRAM_ENUMERATION( 384 if (subresource_filter_only_hit_) {
367 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern, 385 UMA_HISTOGRAM_ENUMERATION(
368 0x10 /* max value */); 386 "SubresourceFilter.PageLoad.RedirectChainMatchPattern."
369 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength", 387 "SubresourceFilterOnly",
370 navigation_chain_.size()); 388 hits_pattern, 0x10 /* max value */);
389 UMA_HISTOGRAM_COUNTS(
390 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly",
391 navigation_chain_.size());
392
393 } else {
394 UMA_HISTOGRAM_ENUMERATION(
395 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern,
396 0x10 /* max value */);
397 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength",
398 navigation_chain_.size());
399 }
371 } 400 }
372 401
373 } // namespace subresource_filter 402 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698