| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/subresource_filter_safe_
browsing_activation_throttle.h" | 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_activation_throttle.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 content::NavigationThrottle::ThrottleCheckResult | 77 content::NavigationThrottle::ThrottleCheckResult |
| 78 SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() { | 78 SubresourceFilterSafeBrowsingActivationThrottle::WillRedirectRequest() { |
| 79 CheckCurrentUrl(); | 79 CheckCurrentUrl(); |
| 80 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; | 80 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; |
| 81 } | 81 } |
| 82 | 82 |
| 83 content::NavigationThrottle::ThrottleCheckResult | 83 content::NavigationThrottle::ThrottleCheckResult |
| 84 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() { | 84 SubresourceFilterSafeBrowsingActivationThrottle::WillProcessResponse() { |
| 85 if (!database_client_) | |
| 86 return content::NavigationThrottle::PROCEED; | |
| 87 | |
| 88 // No need to defer the navigation if the check already happened. | 85 // No need to defer the navigation if the check already happened. |
| 89 if (check_results_.back().finished) { | 86 if (!database_client_ || check_results_.back().finished) { |
| 90 NotifyResult(); | 87 NotifyResult(); |
| 91 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; | 88 return content::NavigationThrottle::ThrottleCheckResult::PROCEED; |
| 92 } | 89 } |
| 93 defer_time_ = base::TimeTicks::Now(); | 90 defer_time_ = base::TimeTicks::Now(); |
| 94 return content::NavigationThrottle::ThrottleCheckResult::DEFER; | 91 return content::NavigationThrottle::ThrottleCheckResult::DEFER; |
| 95 } | 92 } |
| 96 | 93 |
| 97 const char* | 94 const char* |
| 98 SubresourceFilterSafeBrowsingActivationThrottle::GetNameForLogging() { | 95 SubresourceFilterSafeBrowsingActivationThrottle::GetNameForLogging() { |
| 99 return "SubresourceFilterSafeBrowsingActivationThrottle"; | 96 return "SubresourceFilterSafeBrowsingActivationThrottle"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 125 navigation_handle()->GetURL(), id)); | 122 navigation_handle()->GetURL(), id)); |
| 126 } | 123 } |
| 127 | 124 |
| 128 void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() { | 125 void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() { |
| 129 content::WebContents* web_contents = navigation_handle()->GetWebContents(); | 126 content::WebContents* web_contents = navigation_handle()->GetWebContents(); |
| 130 if (!web_contents) | 127 if (!web_contents) |
| 131 return; | 128 return; |
| 132 | 129 |
| 133 using subresource_filter::ContentSubresourceFilterDriverFactory; | 130 using subresource_filter::ContentSubresourceFilterDriverFactory; |
| 134 | 131 |
| 135 const SubresourceFilterSafeBrowsingClient::CheckResult& result = | |
| 136 check_results_.back(); | |
| 137 ContentSubresourceFilterDriverFactory* driver_factory = | 132 ContentSubresourceFilterDriverFactory* driver_factory = |
| 138 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); | 133 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); |
| 139 DCHECK(driver_factory); | 134 DCHECK(driver_factory); |
| 140 | 135 |
| 141 driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist( | 136 auto threat_type = safe_browsing::SBThreatType::SB_THREAT_TYPE_SAFE; |
| 142 navigation_handle()->GetURL(), result.threat_type, result.pattern_type); | 137 auto pattern_type = safe_browsing::ThreatPatternType::NONE; |
| 138 if (database_client_) { |
| 139 DCHECK(!check_results_.empty()); |
| 140 DCHECK(check_results_.back().finished); |
| 141 threat_type = check_results_.back().threat_type; |
| 142 pattern_type = check_results_.back().pattern_type; |
| 143 } |
| 144 driver_factory->OnSafeBrowsingMatchComputed(navigation_handle(), threat_type, |
| 145 pattern_type); |
| 143 | 146 |
| 144 base::TimeDelta delay = defer_time_.is_null() | 147 base::TimeDelta delay = defer_time_.is_null() |
| 145 ? base::TimeDelta::FromMilliseconds(0) | 148 ? base::TimeDelta::FromMilliseconds(0) |
| 146 : base::TimeTicks::Now() - defer_time_; | 149 : base::TimeTicks::Now() - defer_time_; |
| 147 UMA_HISTOGRAM_TIMES("SubresourceFilter.PageLoad.SafeBrowsingDelay", delay); | 150 UMA_HISTOGRAM_TIMES("SubresourceFilter.PageLoad.SafeBrowsingDelay", delay); |
| 148 | 151 |
| 149 // Log a histogram for the delay we would have introduced if the throttle only | 152 // Log a histogram for the delay we would have introduced if the throttle only |
| 150 // speculatively checks URLs on WillStartRequest. This is only different from | 153 // speculatively checks URLs on WillStartRequest. This is only different from |
| 151 // the actual delay if there was at least one redirect. | 154 // the actual delay if there was at least one redirect. |
| 152 base::TimeDelta no_redirect_speculation_delay = | 155 base::TimeDelta no_redirect_speculation_delay = |
| 153 check_results_.size() > 1 ? result.check_time : delay; | 156 check_results_.size() > 1 ? check_results_.back().check_time : delay; |
| 154 UMA_HISTOGRAM_TIMES( | 157 UMA_HISTOGRAM_TIMES( |
| 155 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation", | 158 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation", |
| 156 no_redirect_speculation_delay); | 159 no_redirect_speculation_delay); |
| 157 } | 160 } |
| 158 | 161 |
| 159 void SubresourceFilterSafeBrowsingActivationThrottle:: | 162 void SubresourceFilterSafeBrowsingActivationThrottle:: |
| 160 RecordRedirectChainMatchPatternForList(ActivationList activation_list) { | 163 RecordRedirectChainMatchPatternForList(ActivationList activation_list) { |
| 161 DCHECK(check_results_.back().finished); | 164 DCHECK(check_results_.back().finished); |
| 162 ActivationList matched_list = GetListForThreatTypeAndMetadata( | 165 ActivationList matched_list = GetListForThreatTypeAndMetadata( |
| 163 check_results_.back().threat_type, check_results_.back().pattern_type); | 166 check_results_.back().threat_type, check_results_.back().pattern_type); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 176 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", is_matched, | 179 REPORT_REDIRECT_PATTERN_FOR_SUFFIX("SubresourceFilterOnly", is_matched, |
| 177 chain_size); | 180 chain_size); |
| 178 break; | 181 break; |
| 179 default: | 182 default: |
| 180 NOTREACHED(); | 183 NOTREACHED(); |
| 181 break; | 184 break; |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 | 187 |
| 185 } // namespace subresource_filter | 188 } // namespace subresource_filter |
| OLD | NEW |