| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/lazy_instance.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/non_thread_safe.h" |
| 15 #include "base/time/clock.h" | 17 #include "base/time/clock.h" |
| 16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 17 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ssl/bad_clock_blocking_page.h" | 21 #include "chrome/browser/ssl/bad_clock_blocking_page.h" |
| 20 #include "chrome/browser/ssl/ssl_blocking_page.h" | 22 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 21 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 23 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 22 #include "chrome/common/features.h" | 24 #include "chrome/common/features.h" |
| 23 #include "components/network_time/network_time_tracker.h" | 25 #include "components/network_time/network_time_tracker.h" |
| 24 #include "components/ssl_errors/error_classification.h" | 26 #include "components/ssl_errors/error_classification.h" |
| 25 #include "components/ssl_errors/error_info.h" | 27 #include "components/ssl_errors/error_info.h" |
| 26 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 28 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
| 29 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 30 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 31 | 33 |
| 32 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 34 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 33 #include "chrome/browser/captive_portal/captive_portal_service.h" | 35 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 34 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 36 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| 35 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 37 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 36 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 38 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 37 #endif | 39 #endif |
| 38 | 40 |
| 39 namespace network_time { | |
| 40 class NetworkTimeTracker; | |
| 41 } | |
| 42 | |
| 43 namespace { | 41 namespace { |
| 44 | 42 |
| 45 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 43 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 46 const base::Feature kCaptivePortalInterstitial{ | 44 const base::Feature kCaptivePortalInterstitial{ |
| 47 "CaptivePortalInterstitial", base::FEATURE_ENABLED_BY_DEFAULT}; | 45 "CaptivePortalInterstitial", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 48 #endif | 46 #endif |
| 49 | 47 |
| 50 const base::Feature kSSLCommonNameMismatchHandling{ | 48 const base::Feature kSSLCommonNameMismatchHandling{ |
| 51 "SSLCommonNameMismatchHandling", base::FEATURE_ENABLED_BY_DEFAULT}; | 49 "SSLCommonNameMismatchHandling", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 52 | 50 |
| 53 // The delay in milliseconds before displaying the SSL interstitial. | 51 // Default delay in milliseconds before displaying the SSL interstitial. |
| 54 // This can be changed in tests. | 52 // This can be changed in tests. |
| 55 // - If there is a name mismatch and a suggested URL available result arrives | 53 // - If there is a name mismatch and a suggested URL available result arrives |
| 56 // during this time, the user is redirected to the suggester URL. | 54 // during this time, the user is redirected to the suggester URL. |
| 57 // - If a "captive portal detected" result arrives during this time, | 55 // - If a "captive portal detected" result arrives during this time, |
| 58 // a captive portal interstitial is displayed. | 56 // a captive portal interstitial is displayed. |
| 59 // - Otherwise, an SSL interstitial is displayed. | 57 // - Otherwise, an SSL interstitial is displayed. |
| 60 int64_t g_interstitial_delay_in_milliseconds = 3000; | 58 const int64_t kInterstitialDelayInMilliseconds = 3000; |
| 61 | |
| 62 // Callback to call when the interstitial timer is started. Used for testing. | |
| 63 SSLErrorHandler::TimerStartedCallback* g_timer_started_callback = nullptr; | |
| 64 | |
| 65 // The clock to use when deciding which error type to display. Used for testing. | |
| 66 base::Clock* g_testing_clock = nullptr; | |
| 67 | |
| 68 network_time::NetworkTimeTracker* g_network_time_tracker = nullptr; | |
| 69 | 59 |
| 70 // Events for UMA. | 60 // Events for UMA. |
| 71 enum SSLErrorHandlerEvent { | 61 enum SSLErrorHandlerEvent { |
| 72 HANDLE_ALL, | 62 HANDLE_ALL, |
| 73 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE, | 63 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_NONOVERRIDABLE, |
| 74 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, | 64 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, |
| 75 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE, | 65 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE, |
| 76 SHOW_SSL_INTERSTITIAL_OVERRIDABLE, | 66 SHOW_SSL_INTERSTITIAL_OVERRIDABLE, |
| 77 WWW_MISMATCH_FOUND, | 67 WWW_MISMATCH_FOUND, |
| 78 WWW_MISMATCH_URL_AVAILABLE, | 68 WWW_MISMATCH_URL_AVAILABLE, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 136 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 147 bool IsCaptivePortalInterstitialEnabled() { | 137 bool IsCaptivePortalInterstitialEnabled() { |
| 148 return base::FeatureList::IsEnabled(kCaptivePortalInterstitial); | 138 return base::FeatureList::IsEnabled(kCaptivePortalInterstitial); |
| 149 } | 139 } |
| 150 #endif | 140 #endif |
| 151 | 141 |
| 152 bool IsSSLCommonNameMismatchHandlingEnabled() { | 142 bool IsSSLCommonNameMismatchHandlingEnabled() { |
| 153 return base::FeatureList::IsEnabled(kSSLCommonNameMismatchHandling); | 143 return base::FeatureList::IsEnabled(kSSLCommonNameMismatchHandling); |
| 154 } | 144 } |
| 155 | 145 |
| 146 // Configuration for SSLErrorHandler. |
| 147 class ConfigSingleton : public base::NonThreadSafe { |
| 148 public: |
| 149 ConfigSingleton(); |
| 150 |
| 151 base::TimeDelta interstitial_delay() const; |
| 152 SSLErrorHandler::TimerStartedCallback* timer_started_callback() const; |
| 153 base::Clock* clock() const; |
| 154 network_time::NetworkTimeTracker* network_time_tracker() const; |
| 155 |
| 156 void SetInterstitialDelayForTesting(const base::TimeDelta& delay); |
| 157 void SetTimerStartedCallbackForTesting( |
| 158 SSLErrorHandler::TimerStartedCallback* callback); |
| 159 void SetClockForTesting(base::Clock* clock); |
| 160 void SetNetworkTimeTrackerForTesting( |
| 161 network_time::NetworkTimeTracker* tracker); |
| 162 |
| 163 private: |
| 164 base::TimeDelta interstitial_delay_; |
| 165 |
| 166 // Callback to call when the interstitial timer is started. Used for |
| 167 // testing. |
| 168 SSLErrorHandler::TimerStartedCallback* timer_started_callback_ = nullptr; |
| 169 |
| 170 // The clock to use when deciding which error type to display. Used for |
| 171 // testing. |
| 172 base::Clock* testing_clock_ = nullptr; |
| 173 |
| 174 network_time::NetworkTimeTracker* network_time_tracker_ = nullptr; |
| 175 }; |
| 176 |
| 177 ConfigSingleton::ConfigSingleton() |
| 178 : interstitial_delay_( |
| 179 base::TimeDelta::FromMilliseconds(kInterstitialDelayInMilliseconds)) { |
| 180 } |
| 181 |
| 182 base::TimeDelta ConfigSingleton::interstitial_delay() const { |
| 183 return interstitial_delay_; |
| 184 } |
| 185 |
| 186 SSLErrorHandler::TimerStartedCallback* ConfigSingleton::timer_started_callback() |
| 187 const { |
| 188 return timer_started_callback_; |
| 189 } |
| 190 |
| 191 network_time::NetworkTimeTracker* ConfigSingleton::network_time_tracker() |
| 192 const { |
| 193 return network_time_tracker_ ? network_time_tracker_ |
| 194 : g_browser_process->network_time_tracker(); |
| 195 } |
| 196 |
| 197 base::Clock* ConfigSingleton::clock() const { |
| 198 return testing_clock_; |
| 199 } |
| 200 |
| 201 void ConfigSingleton::SetInterstitialDelayForTesting( |
| 202 const base::TimeDelta& delay) { |
| 203 interstitial_delay_ = delay; |
| 204 } |
| 205 |
| 206 void ConfigSingleton::SetTimerStartedCallbackForTesting( |
| 207 SSLErrorHandler::TimerStartedCallback* callback) { |
| 208 DCHECK(!callback || !callback->is_null()); |
| 209 timer_started_callback_ = callback; |
| 210 } |
| 211 |
| 212 void ConfigSingleton::SetClockForTesting(base::Clock* clock) { |
| 213 testing_clock_ = clock; |
| 214 } |
| 215 |
| 216 void ConfigSingleton::SetNetworkTimeTrackerForTesting( |
| 217 network_time::NetworkTimeTracker* tracker) { |
| 218 network_time_tracker_ = tracker; |
| 219 } |
| 220 |
| 221 static base::LazyInstance<ConfigSingleton>::Leaky g_config = |
| 222 LAZY_INSTANCE_INITIALIZER; |
| 223 |
| 156 } // namespace | 224 } // namespace |
| 157 | 225 |
| 158 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); | 226 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); |
| 159 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CommonNameMismatchRedirectObserver); | 227 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CommonNameMismatchRedirectObserver); |
| 160 | 228 |
| 161 void SSLErrorHandler::HandleSSLError( | 229 void SSLErrorHandler::HandleSSLError( |
| 162 content::WebContents* web_contents, | 230 content::WebContents* web_contents, |
| 163 int cert_error, | 231 int cert_error, |
| 164 const net::SSLInfo& ssl_info, | 232 const net::SSLInfo& ssl_info, |
| 165 const GURL& request_url, | 233 const GURL& request_url, |
| 166 int options_mask, | 234 int options_mask, |
| 167 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 235 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 168 const base::Callback<void(content::CertificateRequestResultType)>& | 236 const base::Callback<void(content::CertificateRequestResultType)>& |
| 169 callback) { | 237 callback) { |
| 170 DCHECK(!FromWebContents(web_contents)); | 238 DCHECK(!FromWebContents(web_contents)); |
| 171 SSLErrorHandler* error_handler = | 239 SSLErrorHandler* error_handler = |
| 172 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, | 240 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, |
| 173 options_mask, std::move(ssl_cert_reporter), callback); | 241 options_mask, std::move(ssl_cert_reporter), callback); |
| 174 web_contents->SetUserData(UserDataKey(), error_handler); | 242 web_contents->SetUserData(UserDataKey(), error_handler); |
| 175 error_handler->StartHandlingError(); | 243 error_handler->StartHandlingError(); |
| 176 } | 244 } |
| 177 | 245 |
| 178 // static | 246 // static |
| 179 void SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta delay) { | 247 void SSLErrorHandler::SetInterstitialDelayForTesting( |
| 180 g_interstitial_delay_in_milliseconds = delay.InMilliseconds(); | 248 const base::TimeDelta& delay) { |
| 249 g_config.Pointer()->SetInterstitialDelayForTesting(delay); |
| 181 } | 250 } |
| 182 | 251 |
| 183 // static | 252 // static |
| 184 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( | 253 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTesting( |
| 185 TimerStartedCallback* callback) { | 254 TimerStartedCallback* callback) { |
| 186 DCHECK(!callback || !callback->is_null()); | 255 g_config.Pointer()->SetTimerStartedCallbackForTesting(callback); |
| 187 g_timer_started_callback = callback; | |
| 188 } | 256 } |
| 189 | 257 |
| 190 // static | 258 // static |
| 191 void SSLErrorHandler::SetClockForTest(base::Clock* testing_clock) { | 259 void SSLErrorHandler::SetClockForTesting(base::Clock* testing_clock) { |
| 192 g_testing_clock = testing_clock; | 260 g_config.Pointer()->SetClockForTesting(testing_clock); |
| 193 } | 261 } |
| 194 | 262 |
| 195 // static | 263 // static |
| 196 void SSLErrorHandler::SetNetworkTimeTrackerForTest( | 264 void SSLErrorHandler::SetNetworkTimeTrackerForTesting( |
| 197 network_time::NetworkTimeTracker* tracker) { | 265 network_time::NetworkTimeTracker* tracker) { |
| 198 g_network_time_tracker = tracker; | 266 g_config.Pointer()->SetNetworkTimeTrackerForTesting(tracker); |
| 199 } | 267 } |
| 200 | 268 |
| 201 SSLErrorHandler::SSLErrorHandler( | 269 SSLErrorHandler::SSLErrorHandler( |
| 202 content::WebContents* web_contents, | 270 content::WebContents* web_contents, |
| 203 int cert_error, | 271 int cert_error, |
| 204 const net::SSLInfo& ssl_info, | 272 const net::SSLInfo& ssl_info, |
| 205 const GURL& request_url, | 273 const GURL& request_url, |
| 206 int options_mask, | 274 int options_mask, |
| 207 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 275 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 208 const base::Callback<void(content::CertificateRequestResultType)>& callback) | 276 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 310 |
| 243 // Show the SSL intersitial if |CERT_STATUS_COMMON_NAME_INVALID| is not | 311 // Show the SSL intersitial if |CERT_STATUS_COMMON_NAME_INVALID| is not |
| 244 // the only error. Need not check for captive portal in this case. | 312 // the only error. Need not check for captive portal in this case. |
| 245 // (See the comment below). | 313 // (See the comment below). |
| 246 if (net::IsCertStatusError(extra_cert_errors) && | 314 if (net::IsCertStatusError(extra_cert_errors) && |
| 247 !net::IsCertStatusMinorError(ssl_info_.cert_status)) { | 315 !net::IsCertStatusMinorError(ssl_info_.cert_status)) { |
| 248 ShowSSLInterstitial(); | 316 ShowSSLInterstitial(); |
| 249 return; | 317 return; |
| 250 } | 318 } |
| 251 CheckSuggestedUrl(suggested_url); | 319 CheckSuggestedUrl(suggested_url); |
| 252 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( | 320 timer_.Start(FROM_HERE, g_config.Pointer()->interstitial_delay(), this, |
| 253 g_interstitial_delay_in_milliseconds), | 321 &SSLErrorHandler::ShowSSLInterstitial); |
| 254 this, &SSLErrorHandler::ShowSSLInterstitial); | 322 |
| 255 if (g_timer_started_callback) | 323 if (g_config.Pointer()->timer_started_callback()) |
| 256 g_timer_started_callback->Run(web_contents_); | 324 g_config.Pointer()->timer_started_callback()->Run(web_contents_); |
| 257 | 325 |
| 258 // Do not check for a captive portal in this case, because a captive | 326 // Do not check for a captive portal in this case, because a captive |
| 259 // portal most likely cannot serve a valid certificate which passes the | 327 // portal most likely cannot serve a valid certificate which passes the |
| 260 // similarity check. | 328 // similarity check. |
| 261 return; | 329 return; |
| 262 } | 330 } |
| 263 | 331 |
| 264 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 332 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 265 CaptivePortalTabHelper* captive_portal_tab_helper = | 333 CaptivePortalTabHelper* captive_portal_tab_helper = |
| 266 CaptivePortalTabHelper::FromWebContents(web_contents_); | 334 CaptivePortalTabHelper::FromWebContents(web_contents_); |
| 267 if (captive_portal_tab_helper) { | 335 if (captive_portal_tab_helper) { |
| 268 captive_portal_tab_helper->OnSSLCertError(ssl_info_); | 336 captive_portal_tab_helper->OnSSLCertError(ssl_info_); |
| 269 } | 337 } |
| 270 | 338 |
| 271 registrar_.Add(this, chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 339 registrar_.Add(this, chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 272 content::Source<Profile>(profile_)); | 340 content::Source<Profile>(profile_)); |
| 273 | 341 |
| 274 if (IsCaptivePortalInterstitialEnabled()) { | 342 if (IsCaptivePortalInterstitialEnabled()) { |
| 275 CheckForCaptivePortal(); | 343 CheckForCaptivePortal(); |
| 276 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( | 344 timer_.Start(FROM_HERE, g_config.Pointer()->interstitial_delay(), this, |
| 277 g_interstitial_delay_in_milliseconds), | 345 &SSLErrorHandler::ShowSSLInterstitial); |
| 278 this, &SSLErrorHandler::ShowSSLInterstitial); | 346 if (g_config.Pointer()->timer_started_callback()) |
| 279 if (g_timer_started_callback) | 347 g_config.Pointer()->timer_started_callback()->Run(web_contents_); |
| 280 g_timer_started_callback->Run(web_contents_); | |
| 281 return; | 348 return; |
| 282 } | 349 } |
| 283 #endif | 350 #endif |
| 284 // Display an SSL interstitial. | 351 // Display an SSL interstitial. |
| 285 ShowSSLInterstitial(); | 352 ShowSSLInterstitial(); |
| 286 } | 353 } |
| 287 | 354 |
| 288 void SSLErrorHandler::CheckForCaptivePortal() { | 355 void SSLErrorHandler::CheckForCaptivePortal() { |
| 289 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 356 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 290 CaptivePortalService* captive_portal_service = | 357 CaptivePortalService* captive_portal_service = |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 if (common_name_mismatch_handler_) { | 492 if (common_name_mismatch_handler_) { |
| 426 common_name_mismatch_handler_->Cancel(); | 493 common_name_mismatch_handler_->Cancel(); |
| 427 common_name_mismatch_handler_.reset(); | 494 common_name_mismatch_handler_.reset(); |
| 428 } | 495 } |
| 429 // Deletes |this| and also destroys the timer. | 496 // Deletes |this| and also destroys the timer. |
| 430 web_contents_->RemoveUserData(UserDataKey()); | 497 web_contents_->RemoveUserData(UserDataKey()); |
| 431 } | 498 } |
| 432 | 499 |
| 433 void SSLErrorHandler::HandleCertDateInvalidError() { | 500 void SSLErrorHandler::HandleCertDateInvalidError() { |
| 434 const base::TimeTicks now = base::TimeTicks::Now(); | 501 const base::TimeTicks now = base::TimeTicks::Now(); |
| 435 network_time::NetworkTimeTracker* tracker = | 502 timer_.Start(FROM_HERE, g_config.Pointer()->interstitial_delay(), |
| 436 g_network_time_tracker ? g_network_time_tracker | |
| 437 : g_browser_process->network_time_tracker(); | |
| 438 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( | |
| 439 g_interstitial_delay_in_milliseconds), | |
| 440 base::Bind(&SSLErrorHandler::HandleCertDateInvalidErrorImpl, | 503 base::Bind(&SSLErrorHandler::HandleCertDateInvalidErrorImpl, |
| 441 base::Unretained(this), now)); | 504 base::Unretained(this), now)); |
| 442 // Try kicking off a time fetch to get an up-to-date estimate of the | 505 // Try kicking off a time fetch to get an up-to-date estimate of the |
| 443 // true time. This will only have an effect if network time is | 506 // true time. This will only have an effect if network time is |
| 444 // unavailable or if there is not already a query in progress. | 507 // unavailable or if there is not already a query in progress. |
| 445 // | 508 // |
| 446 // Pass a weak pointer as the callback; if the timer fires before the | 509 // Pass a weak pointer as the callback; if the timer fires before the |
| 447 // fetch completes and shows an interstitial, this SSLErrorHandler | 510 // fetch completes and shows an interstitial, this SSLErrorHandler |
| 448 // will be deleted. | 511 // will be deleted. |
| 512 network_time::NetworkTimeTracker* tracker = |
| 513 g_config.Pointer()->network_time_tracker(); |
| 449 if (!tracker->StartTimeFetch( | 514 if (!tracker->StartTimeFetch( |
| 450 base::Bind(&SSLErrorHandler::HandleCertDateInvalidErrorImpl, | 515 base::Bind(&SSLErrorHandler::HandleCertDateInvalidErrorImpl, |
| 451 weak_ptr_factory_.GetWeakPtr(), now))) { | 516 weak_ptr_factory_.GetWeakPtr(), now))) { |
| 452 HandleCertDateInvalidErrorImpl(now); | 517 HandleCertDateInvalidErrorImpl(now); |
| 453 return; | 518 return; |
| 454 } | 519 } |
| 455 | 520 |
| 456 if (g_timer_started_callback) | 521 if (g_config.Pointer()->timer_started_callback()) |
| 457 g_timer_started_callback->Run(web_contents_); | 522 g_config.Pointer()->timer_started_callback()->Run(web_contents_); |
| 458 } | 523 } |
| 459 | 524 |
| 460 void SSLErrorHandler::HandleCertDateInvalidErrorImpl( | 525 void SSLErrorHandler::HandleCertDateInvalidErrorImpl( |
| 461 base::TimeTicks started_handling_error) { | 526 base::TimeTicks started_handling_error) { |
| 462 UMA_HISTOGRAM_CUSTOM_TIMES( | 527 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 463 "interstitial.ssl_error_handler.cert_date_error_delay", | 528 "interstitial.ssl_error_handler.cert_date_error_delay", |
| 464 base::TimeTicks::Now() - started_handling_error, | 529 base::TimeTicks::Now() - started_handling_error, |
| 465 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(4), | 530 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(4), |
| 466 50); | 531 50); |
| 467 | 532 |
| 533 timer_.Stop(); |
| 534 base::Clock* testing_clock = g_config.Pointer()->clock(); |
| 535 const base::Time now = |
| 536 testing_clock ? testing_clock->Now() : base::Time::NowFromSystemTime(); |
| 537 |
| 468 network_time::NetworkTimeTracker* tracker = | 538 network_time::NetworkTimeTracker* tracker = |
| 469 g_network_time_tracker ? g_network_time_tracker | 539 g_config.Pointer()->network_time_tracker(); |
| 470 : g_browser_process->network_time_tracker(); | |
| 471 timer_.Stop(); | |
| 472 const base::Time now = g_testing_clock == nullptr | |
| 473 ? base::Time::NowFromSystemTime() | |
| 474 : g_testing_clock->Now(); | |
| 475 ssl_errors::ClockState clock_state = ssl_errors::GetClockState(now, tracker); | 540 ssl_errors::ClockState clock_state = ssl_errors::GetClockState(now, tracker); |
| 476 if (clock_state == ssl_errors::CLOCK_STATE_FUTURE || | 541 if (clock_state == ssl_errors::CLOCK_STATE_FUTURE || |
| 477 clock_state == ssl_errors::CLOCK_STATE_PAST) { | 542 clock_state == ssl_errors::CLOCK_STATE_PAST) { |
| 478 ShowBadClockInterstitial(now, clock_state); | 543 ShowBadClockInterstitial(now, clock_state); |
| 479 return; // |this| is deleted after showing the interstitial. | 544 return; // |this| is deleted after showing the interstitial. |
| 480 } | 545 } |
| 481 ShowSSLInterstitial(); | 546 ShowSSLInterstitial(); |
| 482 } | 547 } |
| OLD | NEW |