Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_blocking_page.h" | 5 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 6 | 6 |
| 7 #include "base/build_time.h" | 7 #include "base/build_time.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
| 40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 41 #include "net/base/hash_value.h" | 41 #include "net/base/hash_value.h" |
| 42 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
| 43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
| 44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "ui/base/webui/jstemplate_builder.h" | 46 #include "ui/base/webui/jstemplate_builder.h" |
| 47 #include "ui/base/webui/web_ui_util.h" | 47 #include "ui/base/webui/web_ui_util.h" |
| 48 | 48 |
| 49 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 50 #include "chrome/browser/captive_portal/captive_portal_service.h" | |
| 51 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | |
| 52 #endif | |
| 53 | |
| 54 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 55 #include "base/base_paths_win.h" | 50 #include "base/base_paths_win.h" |
| 56 #include "base/path_service.h" | 51 #include "base/path_service.h" |
| 57 #include "base/strings/string16.h" | 52 #include "base/strings/string16.h" |
| 58 #include "base/win/windows_version.h" | 53 #include "base/win/windows_version.h" |
| 59 #endif | 54 #endif |
| 60 | 55 |
| 61 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 62 #include "chrome/browser/profiles/profile_manager.h" | 57 #include "chrome/browser/profiles/profile_manager.h" |
| 63 #include "chrome/browser/ui/chrome_pages.h" | 58 #include "chrome/browser/ui/chrome_pages.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 84 DONT_PROCEED_NAME, | 79 DONT_PROCEED_NAME, |
| 85 DONT_PROCEED_DATE, | 80 DONT_PROCEED_DATE, |
| 86 DONT_PROCEED_AUTHORITY, | 81 DONT_PROCEED_AUTHORITY, |
| 87 MORE, | 82 MORE, |
| 88 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. | 83 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. |
| 89 SHOW_INTERNAL_HOSTNAME, | 84 SHOW_INTERNAL_HOSTNAME, |
| 90 PROCEED_INTERNAL_HOSTNAME, | 85 PROCEED_INTERNAL_HOSTNAME, |
| 91 SHOW_NEW_SITE, | 86 SHOW_NEW_SITE, |
| 92 PROCEED_NEW_SITE, | 87 PROCEED_NEW_SITE, |
| 93 PROCEED_MANUAL_NONOVERRIDABLE, | 88 PROCEED_MANUAL_NONOVERRIDABLE, |
| 94 CAPTIVE_PORTAL_DETECTION_ENABLED, | 89 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED, // Captive Portal errors moved |
| 95 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, | 90 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, // to |
| 96 CAPTIVE_PORTAL_PROBE_COMPLETED, | 91 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED, // ssl_error_classification. |
| 97 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, | 92 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, |
| 98 CAPTIVE_PORTAL_NO_RESPONSE, | 93 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE, |
| 99 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, | 94 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, |
| 100 CAPTIVE_PORTAL_DETECTED, | 95 DEPRECATED_CAPTIVE_PORTAL_DETECTED, |
| 101 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, | 96 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, |
| 102 UNUSED_BLOCKING_PAGE_EVENT, | 97 UNUSED_BLOCKING_PAGE_EVENT, |
| 103 }; | 98 }; |
| 104 | 99 |
| 105 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { | 100 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { |
| 106 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", | 101 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", |
| 107 event, | 102 event, |
| 108 UNUSED_BLOCKING_PAGE_EVENT); | 103 UNUSED_BLOCKING_PAGE_EVENT); |
| 109 } | 104 } |
| 110 | 105 |
| 111 void RecordSSLBlockingPageDetailedStats( | 106 void RecordSSLBlockingPageDetailedStats( |
| 112 bool proceed, | 107 bool proceed, |
| 113 int cert_error, | 108 int cert_error, |
| 114 bool overridable, | 109 bool overridable, |
| 115 bool internal, | 110 bool internal, |
| 116 int num_visits, | 111 int num_visits) { |
| 117 bool captive_portal_detection_enabled, | |
| 118 bool captive_portal_probe_completed, | |
| 119 bool captive_portal_no_response, | |
| 120 bool captive_portal_detected) { | |
| 121 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", | 112 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", |
| 122 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); | 113 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); |
| 123 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 124 if (captive_portal_detection_enabled) | |
| 125 RecordSSLBlockingPageEventStats( | |
| 126 overridable ? | |
| 127 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE : | |
| 128 CAPTIVE_PORTAL_DETECTION_ENABLED); | |
| 129 if (captive_portal_probe_completed) | |
| 130 RecordSSLBlockingPageEventStats( | |
| 131 overridable ? | |
| 132 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE : | |
| 133 CAPTIVE_PORTAL_PROBE_COMPLETED); | |
| 134 // Log only one of portal detected and no response results. | |
| 135 if (captive_portal_detected) | |
| 136 RecordSSLBlockingPageEventStats( | |
| 137 overridable ? | |
| 138 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE : | |
| 139 CAPTIVE_PORTAL_DETECTED); | |
| 140 else if (captive_portal_no_response) | |
| 141 RecordSSLBlockingPageEventStats( | |
| 142 overridable ? | |
| 143 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE : | |
| 144 CAPTIVE_PORTAL_NO_RESPONSE); | |
| 145 #endif | |
| 146 if (!overridable) { | 114 if (!overridable) { |
| 147 if (proceed) { | 115 if (proceed) { |
| 148 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); | 116 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); |
| 149 } | 117 } |
| 150 // Overridable is false if the user didn't have any option except to turn | 118 // Overridable is false if the user didn't have any option except to turn |
| 151 // back. If that's the case, don't record some of the metrics. | 119 // back. If that's the case, don't record some of the metrics. |
| 152 return; | 120 return; |
| 153 } | 121 } |
| 154 if (num_visits == 0) | 122 if (num_visits == 0) |
| 155 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); | 123 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 const base::Callback<void(bool)>& callback) | 247 const base::Callback<void(bool)>& callback) |
| 280 : callback_(callback), | 248 : callback_(callback), |
| 281 web_contents_(web_contents), | 249 web_contents_(web_contents), |
| 282 cert_error_(cert_error), | 250 cert_error_(cert_error), |
| 283 ssl_info_(ssl_info), | 251 ssl_info_(ssl_info), |
| 284 request_url_(request_url), | 252 request_url_(request_url), |
| 285 overridable_(overridable), | 253 overridable_(overridable), |
| 286 strict_enforcement_(strict_enforcement), | 254 strict_enforcement_(strict_enforcement), |
| 287 interstitial_page_(NULL), | 255 interstitial_page_(NULL), |
| 288 internal_(false), | 256 internal_(false), |
| 289 num_visits_(-1), | 257 num_visits_(-1) { |
| 290 captive_portal_detection_enabled_(false), | |
| 291 captive_portal_probe_completed_(false), | |
| 292 captive_portal_no_response_(false), | |
| 293 captive_portal_detected_(false) { | |
| 294 Profile* profile = Profile::FromBrowserContext( | 258 Profile* profile = Profile::FromBrowserContext( |
| 295 web_contents->GetBrowserContext()); | 259 web_contents->GetBrowserContext()); |
| 296 // For UMA stats. | 260 // For UMA stats. |
| 297 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) | 261 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) |
| 298 internal_ = true; | 262 internal_ = true; |
| 299 RecordSSLBlockingPageEventStats(SHOW_ALL); | 263 RecordSSLBlockingPageEventStats(SHOW_ALL); |
| 300 if (overridable_ && !strict_enforcement_) { | 264 if (overridable_ && !strict_enforcement_) { |
| 301 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 265 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
| 302 if (internal_) | 266 if (internal_) |
| 303 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); | 267 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); |
| 304 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 268 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 305 profile, Profile::EXPLICIT_ACCESS); | 269 profile, Profile::EXPLICIT_ACCESS); |
| 306 if (history_service) { | 270 if (history_service) { |
| 307 history_service->GetVisibleVisitCountToHost( | 271 history_service->GetVisibleVisitCountToHost( |
| 308 request_url_, | 272 request_url_, |
| 309 base::Bind(&SSLBlockingPage::OnGotHistoryCount, | 273 base::Bind(&SSLBlockingPage::OnGotHistoryCount, |
| 310 base::Unretained(this)), | 274 base::Unretained(this)), |
| 311 &request_tracker_); | 275 &request_tracker_); |
| 312 } | 276 } |
| 313 } | 277 } |
| 314 | 278 |
| 315 SSLErrorClassification ssl_error_classification( | 279 SSLErrorClassification ssl_error_classification( |
| 280 web_contents_, | |
| 316 base::Time::NowFromSystemTime(), | 281 base::Time::NowFromSystemTime(), |
| 317 request_url_, | 282 request_url_, |
| 283 cert_error_, | |
| 318 *ssl_info_.cert.get()); | 284 *ssl_info_.cert.get()); |
| 319 ssl_error_classification.RecordUMAStatistics( | 285 ssl_error_classification.RecordUMAStatistics( |
| 320 overridable_ && !strict_enforcement_, cert_error_); | 286 overridable_ && !strict_enforcement_); |
| 321 | 287 |
| 322 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 288 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 323 CaptivePortalService* captive_portal_service = | 289 ssl_error_classification.RecordCaptivePortalUMAStatistics( |
| 324 CaptivePortalServiceFactory::GetForProfile(profile); | 290 overridable_ && !strict_enforcement_); |
| 325 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); | |
| 326 captive_portal_service ->DetectCaptivePortal(); | |
| 327 registrar_.Add(this, | |
| 328 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | |
| 329 content::Source<Profile>(profile)); | |
| 330 #endif | 291 #endif |
| 331 | 292 |
| 332 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 293 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
| 333 // it leaks memory, so don't create it here. | 294 // it leaks memory, so don't create it here. |
| 334 } | 295 } |
| 335 | 296 |
| 336 SSLBlockingPage::~SSLBlockingPage() { | 297 SSLBlockingPage::~SSLBlockingPage() { |
| 298 // InvalidCommonNameSeverityScore() and InvalidDateSeverityScore() are in the | |
| 299 // destrcutor because they depend on knowing whether captive portal detection | |
|
felt
2014/08/07 23:31:42
destructor, not destrcutor
| |
| 300 // happened before the user made a decision. | |
| 301 SSLErrorClassification ssl_error_classification( | |
| 302 web_contents_, | |
| 303 base::Time::NowFromSystemTime(), | |
| 304 request_url_, | |
| 305 cert_error_, | |
| 306 *ssl_info_.cert.get()); | |
| 307 SSLErrorInfo::ErrorType type = | |
| 308 SSLErrorInfo::NetErrorToErrorType(cert_error_); | |
| 309 switch (type) { | |
| 310 case SSLErrorInfo::CERT_DATE_INVALID: { | |
| 311 ssl_error_classification.InvalidDateSeverityScore(); | |
| 312 break; | |
| 313 } | |
| 314 case SSLErrorInfo::CERT_AUTHORITY_INVALID: { | |
| 315 ssl_error_classification.InvalidCommonNameSeverityScore(); | |
| 316 break; | |
| 317 } | |
| 318 default: | |
| 319 break; | |
| 320 } | |
| 321 | |
| 337 if (!callback_.is_null()) { | 322 if (!callback_.is_null()) { |
| 338 RecordSSLBlockingPageDetailedStats(false, | 323 RecordSSLBlockingPageDetailedStats(false, |
| 339 cert_error_, | 324 cert_error_, |
| 340 overridable_ && !strict_enforcement_, | 325 overridable_ && !strict_enforcement_, |
| 341 internal_, | 326 internal_, |
| 342 num_visits_, | 327 num_visits_); |
| 343 captive_portal_detection_enabled_, | |
| 344 captive_portal_probe_completed_, | |
| 345 captive_portal_no_response_, | |
| 346 captive_portal_detected_); | |
| 347 // The page is closed without the user having chosen what to do, default to | 328 // The page is closed without the user having chosen what to do, default to |
| 348 // deny. | 329 // deny. |
| 349 NotifyDenyCertificate(); | 330 NotifyDenyCertificate(); |
| 350 } | 331 } |
| 351 } | 332 } |
| 352 | 333 |
| 353 void SSLBlockingPage::Show() { | 334 void SSLBlockingPage::Show() { |
| 354 DCHECK(!interstitial_page_); | 335 DCHECK(!interstitial_page_); |
| 355 interstitial_page_ = InterstitialPage::Create( | 336 interstitial_page_ = InterstitialPage::Create( |
| 356 web_contents_, true, request_url_, this); | 337 web_contents_, true, request_url_, this); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 Profile* profile = Profile::FromBrowserContext( | 495 Profile* profile = Profile::FromBrowserContext( |
| 515 web_contents_->GetBrowserContext()); | 496 web_contents_->GetBrowserContext()); |
| 516 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 497 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
| 517 } | 498 } |
| 518 | 499 |
| 519 void SSLBlockingPage::OnProceed() { | 500 void SSLBlockingPage::OnProceed() { |
| 520 RecordSSLBlockingPageDetailedStats(true, | 501 RecordSSLBlockingPageDetailedStats(true, |
| 521 cert_error_, | 502 cert_error_, |
| 522 overridable_ && !strict_enforcement_, | 503 overridable_ && !strict_enforcement_, |
| 523 internal_, | 504 internal_, |
| 524 num_visits_, | 505 num_visits_); |
| 525 captive_portal_detection_enabled_, | |
| 526 captive_portal_probe_completed_, | |
| 527 captive_portal_no_response_, | |
| 528 captive_portal_detected_); | |
| 529 // Accepting the certificate resumes the loading of the page. | 506 // Accepting the certificate resumes the loading of the page. |
| 530 NotifyAllowCertificate(); | 507 NotifyAllowCertificate(); |
| 531 } | 508 } |
| 532 | 509 |
| 533 void SSLBlockingPage::OnDontProceed() { | 510 void SSLBlockingPage::OnDontProceed() { |
| 534 RecordSSLBlockingPageDetailedStats(false, | 511 RecordSSLBlockingPageDetailedStats(false, |
| 535 cert_error_, | 512 cert_error_, |
| 536 overridable_ && !strict_enforcement_, | 513 overridable_ && !strict_enforcement_, |
| 537 internal_, | 514 internal_, |
| 538 num_visits_, | 515 num_visits_); |
| 539 captive_portal_detection_enabled_, | |
| 540 captive_portal_probe_completed_, | |
| 541 captive_portal_no_response_, | |
| 542 captive_portal_detected_); | |
| 543 NotifyDenyCertificate(); | 516 NotifyDenyCertificate(); |
| 544 } | 517 } |
| 545 | 518 |
| 546 void SSLBlockingPage::NotifyDenyCertificate() { | 519 void SSLBlockingPage::NotifyDenyCertificate() { |
| 547 // It's possible that callback_ may not exist if the user clicks "Proceed" | 520 // It's possible that callback_ may not exist if the user clicks "Proceed" |
| 548 // followed by pressing the back button before the interstitial is hidden. | 521 // followed by pressing the back button before the interstitial is hidden. |
| 549 // In that case the certificate will still be treated as allowed. | 522 // In that case the certificate will still be treated as allowed. |
| 550 if (callback_.is_null()) | 523 if (callback_.is_null()) |
| 551 return; | 524 return; |
| 552 | 525 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 576 for (; i < 5; i++) { | 549 for (; i < 5; i++) { |
| 577 strings->SetString(keys[i], std::string()); | 550 strings->SetString(keys[i], std::string()); |
| 578 } | 551 } |
| 579 } | 552 } |
| 580 | 553 |
| 581 void SSLBlockingPage::OnGotHistoryCount(bool success, | 554 void SSLBlockingPage::OnGotHistoryCount(bool success, |
| 582 int num_visits, | 555 int num_visits, |
| 583 base::Time first_visit) { | 556 base::Time first_visit) { |
| 584 num_visits_ = num_visits; | 557 num_visits_ = num_visits; |
| 585 } | 558 } |
| 586 | |
| 587 void SSLBlockingPage::Observe( | |
| 588 int type, | |
| 589 const content::NotificationSource& source, | |
| 590 const content::NotificationDetails& details) { | |
| 591 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 592 // When detection is disabled, captive portal service always sends | |
| 593 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. | |
| 594 if (!captive_portal_detection_enabled_) | |
| 595 return; | |
| 596 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { | |
| 597 captive_portal_probe_completed_ = true; | |
| 598 CaptivePortalService::Results* results = | |
| 599 content::Details<CaptivePortalService::Results>( | |
| 600 details).ptr(); | |
| 601 // If a captive portal was detected at any point when the interstitial was | |
| 602 // displayed, assume that the interstitial was caused by a captive portal. | |
| 603 // Example scenario: | |
| 604 // 1- Interstitial displayed and captive portal detected, setting the flag. | |
| 605 // 2- Captive portal detection automatically opens portal login page. | |
| 606 // 3- User logs in on the portal login page. | |
| 607 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make | |
| 608 // sure we don't clear the captive portal flag, since the interstitial was | |
| 609 // potentially caused by the captive portal. | |
| 610 captive_portal_detected_ = captive_portal_detected_ || | |
| 611 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | |
| 612 // Also keep track of non-HTTP portals and error cases. | |
| 613 captive_portal_no_response_ = captive_portal_no_response_ || | |
| 614 (results->result == captive_portal::RESULT_NO_RESPONSE); | |
| 615 } | |
| 616 #endif | |
| 617 } | |
| OLD | NEW |