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/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/content_subresource_filt
er_driver.h" | 10 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return static_cast<ContentSubresourceFilterDriverFactory*>( | 61 return static_cast<ContentSubresourceFilterDriverFactory*>( |
62 web_contents->GetUserData(kWebContentsUserDataKey)); | 62 web_contents->GetUserData(kWebContentsUserDataKey)); |
63 } | 63 } |
64 | 64 |
65 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( | 65 ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( |
66 content::WebContents* web_contents, | 66 content::WebContents* web_contents, |
67 std::unique_ptr<SubresourceFilterClient> client) | 67 std::unique_ptr<SubresourceFilterClient> client) |
68 : content::WebContentsObserver(web_contents), | 68 : content::WebContentsObserver(web_contents), |
69 client_(std::move(client)), | 69 client_(std::move(client)), |
70 activation_level_(ActivationLevel::DISABLED), | 70 activation_level_(ActivationLevel::DISABLED), |
71 measure_performance_(false) { | 71 measure_performance_(false), |
| 72 subresource_filter_only_hit_(false) { |
72 content::RenderFrameHost* main_frame_host = web_contents->GetMainFrame(); | 73 content::RenderFrameHost* main_frame_host = web_contents->GetMainFrame(); |
73 if (main_frame_host && main_frame_host->IsRenderFrameLive()) | 74 if (main_frame_host && main_frame_host->IsRenderFrameLive()) |
74 CreateDriverForFrameHostIfNeeded(main_frame_host); | 75 CreateDriverForFrameHostIfNeeded(main_frame_host); |
75 } | 76 } |
76 | 77 |
77 ContentSubresourceFilterDriverFactory:: | 78 ContentSubresourceFilterDriverFactory:: |
78 ~ContentSubresourceFilterDriverFactory() {} | 79 ~ContentSubresourceFilterDriverFactory() {} |
79 | 80 |
80 void ContentSubresourceFilterDriverFactory::CreateDriverForFrameHostIfNeeded( | 81 void ContentSubresourceFilterDriverFactory::CreateDriverForFrameHostIfNeeded( |
81 content::RenderFrameHost* render_frame_host) { | 82 content::RenderFrameHost* render_frame_host) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 OnMainResourceMatchedSafeBrowsingBlacklist( | 122 OnMainResourceMatchedSafeBrowsingBlacklist( |
122 const GURL& url, | 123 const GURL& url, |
123 const std::vector<GURL>& redirect_urls, | 124 const std::vector<GURL>& redirect_urls, |
124 safe_browsing::SBThreatType threat_type, | 125 safe_browsing::SBThreatType threat_type, |
125 safe_browsing::ThreatPatternType threat_type_metadata) { | 126 safe_browsing::ThreatPatternType threat_type_metadata) { |
126 bool is_phishing_interstitial = | 127 bool is_phishing_interstitial = |
127 (threat_type == safe_browsing::SB_THREAT_TYPE_URL_PHISHING); | 128 (threat_type == safe_browsing::SB_THREAT_TYPE_URL_PHISHING); |
128 bool is_soc_engineering_ads_interstitial = | 129 bool is_soc_engineering_ads_interstitial = |
129 threat_type_metadata == | 130 threat_type_metadata == |
130 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS; | 131 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS; |
131 | 132 subresource_filter_only_hit_ = |
| 133 threat_type == safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER; |
132 if (is_phishing_interstitial) { | 134 if (is_phishing_interstitial) { |
133 if (is_soc_engineering_ads_interstitial) { | 135 if (is_soc_engineering_ads_interstitial) { |
134 AddActivationListMatch(url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 136 AddActivationListMatch(url, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
135 } | 137 } |
136 AddActivationListMatch(url, ActivationList::PHISHING_INTERSTITIAL); | 138 AddActivationListMatch(url, ActivationList::PHISHING_INTERSTITIAL); |
| 139 } else if (subresource_filter_only_hit_) { |
| 140 AddActivationListMatch(url, ActivationList::SUBRESOURCE_FILTER_ONLY); |
137 } | 141 } |
138 } | 142 } |
139 | 143 |
140 void ContentSubresourceFilterDriverFactory::AddHostOfURLToWhitelistSet( | 144 void ContentSubresourceFilterDriverFactory::AddHostOfURLToWhitelistSet( |
141 const GURL& url) { | 145 const GURL& url) { |
142 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) | 146 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) |
143 whitelisted_hosts_.insert(url.host()); | 147 whitelisted_hosts_.insert(url.host()); |
144 } | 148 } |
145 | 149 |
146 bool ContentSubresourceFilterDriverFactory::ShouldActivateForMainFrameURL( | 150 bool ContentSubresourceFilterDriverFactory::ShouldActivateForMainFrameURL( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 content::NavigationHandle* navigation_handle) { | 201 content::NavigationHandle* navigation_handle) { |
198 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) { | 202 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsSamePage()) { |
199 navigation_chain_.clear(); | 203 navigation_chain_.clear(); |
200 activation_list_matches_.clear(); | 204 activation_list_matches_.clear(); |
201 navigation_chain_.push_back(navigation_handle->GetURL()); | 205 navigation_chain_.push_back(navigation_handle->GetURL()); |
202 | 206 |
203 client_->ToggleNotificationVisibility(false); | 207 client_->ToggleNotificationVisibility(false); |
204 activation_level_ = ActivationLevel::DISABLED; | 208 activation_level_ = ActivationLevel::DISABLED; |
205 measure_performance_ = false; | 209 measure_performance_ = false; |
206 aggregated_document_statistics_ = DocumentLoadStatistics(); | 210 aggregated_document_statistics_ = DocumentLoadStatistics(); |
| 211 subresource_filter_only_hit_ = false; |
207 } | 212 } |
208 } | 213 } |
209 | 214 |
210 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation( | 215 void ContentSubresourceFilterDriverFactory::DidRedirectNavigation( |
211 content::NavigationHandle* navigation_handle) { | 216 content::NavigationHandle* navigation_handle) { |
212 DCHECK(!navigation_handle->IsSamePage()); | 217 DCHECK(!navigation_handle->IsSamePage()); |
213 if (navigation_handle->IsInMainFrame()) | 218 if (navigation_handle->IsInMainFrame()) |
214 navigation_chain_.push_back(navigation_handle->GetURL()); | 219 navigation_chain_.push_back(navigation_handle->GetURL()); |
215 } | 220 } |
216 | 221 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 315 |
311 bool ContentSubresourceFilterDriverFactory::DidURLMatchCurrentActivationList( | 316 bool ContentSubresourceFilterDriverFactory::DidURLMatchCurrentActivationList( |
312 const GURL& url) const { | 317 const GURL& url) const { |
313 auto match_types = | 318 auto match_types = |
314 activation_list_matches_.find(DistillURLToHostAndPath(url)); | 319 activation_list_matches_.find(DistillURLToHostAndPath(url)); |
315 return match_types != activation_list_matches_.end() && | 320 return match_types != activation_list_matches_.end() && |
316 match_types->second.find(GetCurrentActivationList()) != | 321 match_types->second.find(GetCurrentActivationList()) != |
317 match_types->second.end(); | 322 match_types->second.end(); |
318 } | 323 } |
319 | 324 |
| 325 bool ContentSubresourceFilterDriverFactory:: |
| 326 DidURLMatchSubresourceFilterOnlyList(const GURL& url) const { |
| 327 auto match_types = |
| 328 activation_list_matches_.find(DistillURLToHostAndPath(url)); |
| 329 return match_types != activation_list_matches_.end() && |
| 330 match_types->second.find(ActivationList::SUBRESOURCE_FILTER_ONLY) != |
| 331 match_types->second.end(); |
| 332 } |
| 333 |
320 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( | 334 void ContentSubresourceFilterDriverFactory::AddActivationListMatch( |
321 const GURL& url, | 335 const GURL& url, |
322 ActivationList match_type) { | 336 ActivationList match_type) { |
323 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) | 337 if (url.has_host() && url.SchemeIsHTTPOrHTTPS()) |
324 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); | 338 activation_list_matches_[DistillURLToHostAndPath(url)].insert(match_type); |
325 } | 339 } |
326 | 340 |
327 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() | 341 void ContentSubresourceFilterDriverFactory::RecordRedirectChainMatchPattern() |
328 const { | 342 const { |
329 int hits_pattern = 0; | 343 int hits_pattern = 0; |
330 const int kInitialURLHitMask = 0x4; | 344 const int kInitialURLHitMask = 0x4; |
331 const int kRedirectURLHitMask = 0x2; | 345 const int kRedirectURLHitMask = 0x2; |
332 const int kFinalURLHitMask = 0x1; | 346 const int kFinalURLHitMask = 0x1; |
| 347 auto in_list = [this](const GURL& url) { |
| 348 return subresource_filter_only_hit_ |
| 349 ? DidURLMatchSubresourceFilterOnlyList(url) |
| 350 : DidURLMatchCurrentActivationList(url); |
| 351 }; |
333 if (navigation_chain_.size() > 1) { | 352 if (navigation_chain_.size() > 1) { |
334 if (DidURLMatchCurrentActivationList(navigation_chain_.back())) | 353 if (in_list(navigation_chain_.back())) |
335 hits_pattern |= kFinalURLHitMask; | 354 hits_pattern |= kFinalURLHitMask; |
336 if (DidURLMatchCurrentActivationList(navigation_chain_.front())) | 355 if (in_list(navigation_chain_.front())) |
337 hits_pattern |= kInitialURLHitMask; | 356 hits_pattern |= kInitialURLHitMask; |
338 | 357 |
339 // Examine redirects. | 358 // Examine redirects. |
340 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) { | 359 for (size_t i = 1; i < navigation_chain_.size() - 1; ++i) { |
341 if (DidURLMatchCurrentActivationList(navigation_chain_[i])) { | 360 if (in_list(navigation_chain_[i])) { |
342 hits_pattern |= kRedirectURLHitMask; | 361 hits_pattern |= kRedirectURLHitMask; |
343 break; | 362 break; |
344 } | 363 } |
345 } | 364 } |
346 } else { | 365 } else { |
347 if (navigation_chain_.size() && | 366 if (navigation_chain_.size() && in_list(navigation_chain_.front())) { |
348 DidURLMatchCurrentActivationList(navigation_chain_.front())) { | |
349 hits_pattern = 0x8; // One url hit. | 367 hits_pattern = 0x8; // One url hit. |
350 } | 368 } |
351 } | 369 } |
352 if (!hits_pattern) | 370 if (!hits_pattern) |
353 return; | 371 return; |
354 UMA_HISTOGRAM_ENUMERATION( | 372 if (subresource_filter_only_hit_) { |
355 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern, | 373 UMA_HISTOGRAM_ENUMERATION( |
356 0x10 /* max value */); | 374 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." |
357 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength", | 375 "SubresourceFilterOnly", |
358 navigation_chain_.size()); | 376 hits_pattern, 0x10 /* max value */); |
| 377 UMA_HISTOGRAM_COUNTS( |
| 378 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly", |
| 379 navigation_chain_.size()); |
| 380 |
| 381 } else { |
| 382 UMA_HISTOGRAM_ENUMERATION( |
| 383 "SubresourceFilter.PageLoad.RedirectChainMatchPattern", hits_pattern, |
| 384 0x10 /* max value */); |
| 385 UMA_HISTOGRAM_COUNTS("SubresourceFilter.PageLoad.RedirectChainLength", |
| 386 navigation_chain_.size()); |
| 387 } |
359 } | 388 } |
360 | 389 |
361 } // namespace subresource_filter | 390 } // namespace subresource_filter |
OLD | NEW |