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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 strict_enforcement_(strict_enforcement), | 286 strict_enforcement_(strict_enforcement), |
287 interstitial_page_(NULL), | 287 interstitial_page_(NULL), |
288 internal_(false), | 288 internal_(false), |
289 num_visits_(-1), | 289 num_visits_(-1), |
290 captive_portal_detection_enabled_(false), | 290 captive_portal_detection_enabled_(false), |
291 captive_portal_probe_completed_(false), | 291 captive_portal_probe_completed_(false), |
292 captive_portal_no_response_(false), | 292 captive_portal_no_response_(false), |
293 captive_portal_detected_(false) { | 293 captive_portal_detected_(false) { |
294 Profile* profile = Profile::FromBrowserContext( | 294 Profile* profile = Profile::FromBrowserContext( |
295 web_contents->GetBrowserContext()); | 295 web_contents->GetBrowserContext()); |
| 296 if (strict_enforcement_) overridable_ = false; |
296 // For UMA stats. | 297 // For UMA stats. |
297 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) | 298 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) |
298 internal_ = true; | 299 internal_ = true; |
299 RecordSSLBlockingPageEventStats(SHOW_ALL); | 300 RecordSSLBlockingPageEventStats(SHOW_ALL); |
300 if (overridable_ && !strict_enforcement_) { | 301 if (overridable_) { |
301 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 302 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
302 if (internal_) | 303 if (internal_) |
303 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); | 304 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); |
304 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 305 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
305 profile, Profile::EXPLICIT_ACCESS); | 306 profile, Profile::EXPLICIT_ACCESS); |
306 if (history_service) { | 307 if (history_service) { |
307 history_service->GetVisibleVisitCountToHost( | 308 history_service->GetVisibleVisitCountToHost( |
308 request_url_, | 309 request_url_, |
309 base::Bind(&SSLBlockingPage::OnGotHistoryCount, | 310 base::Bind(&SSLBlockingPage::OnGotHistoryCount, |
310 base::Unretained(this)), | 311 base::Unretained(this)), |
311 &request_tracker_); | 312 &request_tracker_); |
312 } | 313 } |
313 } | 314 } |
314 | 315 |
315 SSLErrorClassification ssl_error_classification( | 316 SSLErrorClassification ssl_error_classification( |
316 base::Time::NowFromSystemTime(), | 317 base::Time::NowFromSystemTime(), |
317 request_url_, | 318 request_url_, |
318 *ssl_info_.cert.get()); | 319 *ssl_info_.cert.get()); |
319 ssl_error_classification.RecordUMAStatistics( | 320 ssl_error_classification.RecordUMAStatistics(overridable_, cert_error_); |
320 overridable_ && !strict_enforcement_, cert_error_); | |
321 | 321 |
322 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 322 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
323 CaptivePortalService* captive_portal_service = | 323 CaptivePortalService* captive_portal_service = |
324 CaptivePortalServiceFactory::GetForProfile(profile); | 324 CaptivePortalServiceFactory::GetForProfile(profile); |
325 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); | 325 captive_portal_detection_enabled_ = captive_portal_service ->enabled(); |
326 captive_portal_service ->DetectCaptivePortal(); | 326 captive_portal_service ->DetectCaptivePortal(); |
327 registrar_.Add(this, | 327 registrar_.Add(this, |
328 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 328 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
329 content::Source<Profile>(profile)); | 329 content::Source<Profile>(profile)); |
330 #endif | 330 #endif |
331 | 331 |
332 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 332 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
333 // it leaks memory, so don't create it here. | 333 // it leaks memory, so don't create it here. |
334 } | 334 } |
335 | 335 |
336 SSLBlockingPage::~SSLBlockingPage() { | 336 SSLBlockingPage::~SSLBlockingPage() { |
337 if (!callback_.is_null()) { | 337 if (!callback_.is_null()) { |
338 RecordSSLBlockingPageDetailedStats(false, | 338 RecordSSLBlockingPageDetailedStats(false, |
339 cert_error_, | 339 cert_error_, |
340 overridable_ && !strict_enforcement_, | 340 overridable_, |
341 internal_, | 341 internal_, |
342 num_visits_, | 342 num_visits_, |
343 captive_portal_detection_enabled_, | 343 captive_portal_detection_enabled_, |
344 captive_portal_probe_completed_, | 344 captive_portal_probe_completed_, |
345 captive_portal_no_response_, | 345 captive_portal_no_response_, |
346 captive_portal_detected_); | 346 captive_portal_detected_); |
347 // The page is closed without the user having chosen what to do, default to | 347 // The page is closed without the user having chosen what to do, default to |
348 // deny. | 348 // deny. |
349 NotifyDenyCertificate(); | 349 NotifyDenyCertificate(); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 void SSLBlockingPage::Show() { | 353 void SSLBlockingPage::Show() { |
354 DCHECK(!interstitial_page_); | 354 DCHECK(!interstitial_page_); |
355 interstitial_page_ = InterstitialPage::Create( | 355 interstitial_page_ = InterstitialPage::Create( |
356 web_contents_, true, request_url_, this); | 356 web_contents_, true, request_url_, this); |
357 interstitial_page_->Show(); | 357 interstitial_page_->Show(); |
358 } | 358 } |
359 | 359 |
360 std::string SSLBlockingPage::GetHTMLContents() { | 360 std::string SSLBlockingPage::GetHTMLContents() { |
361 base::DictionaryValue load_time_data; | 361 base::DictionaryValue load_time_data; |
362 base::string16 url(ASCIIToUTF16(request_url_.host())); | 362 base::string16 url(ASCIIToUTF16(request_url_.host())); |
363 if (base::i18n::IsRTL()) | 363 if (base::i18n::IsRTL()) |
364 base::i18n::WrapStringWithLTRFormatting(&url); | 364 base::i18n::WrapStringWithLTRFormatting(&url); |
365 webui::SetFontAndTextDirection(&load_time_data); | 365 webui::SetFontAndTextDirection(&load_time_data); |
366 | 366 |
367 // Shared values for both the overridable and non-overridable versions. | 367 // Shared values for both the overridable and non-overridable versions. |
368 load_time_data.SetBoolean("ssl", true); | 368 load_time_data.SetBoolean("ssl", true); |
369 load_time_data.SetBoolean( | 369 load_time_data.SetBoolean("overridable", overridable_); |
370 "overridable", overridable_ && !strict_enforcement_); | |
371 load_time_data.SetString( | 370 load_time_data.SetString( |
372 "tabTitle", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE)); | 371 "tabTitle", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE)); |
373 load_time_data.SetString( | 372 load_time_data.SetString( |
374 "heading", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING)); | 373 "heading", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING)); |
375 if ((SSLErrorClassification::IsUserClockInThePast( | 374 if ((SSLErrorClassification::IsUserClockInThePast( |
376 base::Time::NowFromSystemTime())) | 375 base::Time::NowFromSystemTime())) |
377 && (SSLErrorInfo::NetErrorToErrorType(cert_error_) == | 376 && (SSLErrorInfo::NetErrorToErrorType(cert_error_) == |
378 SSLErrorInfo::CERT_DATE_INVALID)) { | 377 SSLErrorInfo::CERT_DATE_INVALID)) { |
379 load_time_data.SetString("primaryParagraph", | 378 load_time_data.SetString("primaryParagraph", |
380 l10n_util::GetStringFUTF16( | 379 l10n_util::GetStringFUTF16( |
381 IDS_SSL_CLOCK_ERROR, | 380 IDS_SSL_CLOCK_ERROR, |
382 url, | 381 url, |
383 base::TimeFormatShortDate(base::Time::Now()))); | 382 base::TimeFormatShortDate(base::Time::Now()))); |
384 } else { | 383 } else { |
385 load_time_data.SetString( | 384 load_time_data.SetString( |
386 "primaryParagraph", | 385 "primaryParagraph", |
387 l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url)); | 386 l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url)); |
388 } | 387 } |
389 load_time_data.SetString( | 388 load_time_data.SetString( |
390 "openDetails", | 389 "openDetails", |
391 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); | 390 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); |
392 load_time_data.SetString( | 391 load_time_data.SetString( |
393 "closeDetails", | 392 "closeDetails", |
394 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON)); | 393 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON)); |
395 load_time_data.SetString("errorCode", net::ErrorToString(cert_error_)); | 394 load_time_data.SetString("errorCode", net::ErrorToString(cert_error_)); |
396 | 395 |
397 if (overridable_ && !strict_enforcement_) { // Overridable. | 396 if (overridable_) { // Overridable. |
398 SSLErrorInfo error_info = | 397 SSLErrorInfo error_info = |
399 SSLErrorInfo::CreateError( | 398 SSLErrorInfo::CreateError( |
400 SSLErrorInfo::NetErrorToErrorType(cert_error_), | 399 SSLErrorInfo::NetErrorToErrorType(cert_error_), |
401 ssl_info_.cert.get(), | 400 ssl_info_.cert.get(), |
402 request_url_); | 401 request_url_); |
403 load_time_data.SetString( | 402 load_time_data.SetString( |
404 "explanationParagraph", error_info.details()); | 403 "explanationParagraph", error_info.details()); |
405 load_time_data.SetString( | 404 load_time_data.SetString( |
406 "primaryButtonText", | 405 "primaryButtonText", |
407 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); | 406 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 void SSLBlockingPage::OverrideRendererPrefs( | 511 void SSLBlockingPage::OverrideRendererPrefs( |
513 content::RendererPreferences* prefs) { | 512 content::RendererPreferences* prefs) { |
514 Profile* profile = Profile::FromBrowserContext( | 513 Profile* profile = Profile::FromBrowserContext( |
515 web_contents_->GetBrowserContext()); | 514 web_contents_->GetBrowserContext()); |
516 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 515 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
517 } | 516 } |
518 | 517 |
519 void SSLBlockingPage::OnProceed() { | 518 void SSLBlockingPage::OnProceed() { |
520 RecordSSLBlockingPageDetailedStats(true, | 519 RecordSSLBlockingPageDetailedStats(true, |
521 cert_error_, | 520 cert_error_, |
522 overridable_ && !strict_enforcement_, | 521 overridable_, |
523 internal_, | 522 internal_, |
524 num_visits_, | 523 num_visits_, |
525 captive_portal_detection_enabled_, | 524 captive_portal_detection_enabled_, |
526 captive_portal_probe_completed_, | 525 captive_portal_probe_completed_, |
527 captive_portal_no_response_, | 526 captive_portal_no_response_, |
528 captive_portal_detected_); | 527 captive_portal_detected_); |
529 // Accepting the certificate resumes the loading of the page. | 528 // Accepting the certificate resumes the loading of the page. |
530 NotifyAllowCertificate(); | 529 NotifyAllowCertificate(); |
531 } | 530 } |
532 | 531 |
533 void SSLBlockingPage::OnDontProceed() { | 532 void SSLBlockingPage::OnDontProceed() { |
534 RecordSSLBlockingPageDetailedStats(false, | 533 RecordSSLBlockingPageDetailedStats(false, |
535 cert_error_, | 534 cert_error_, |
536 overridable_ && !strict_enforcement_, | 535 overridable_, |
537 internal_, | 536 internal_, |
538 num_visits_, | 537 num_visits_, |
539 captive_portal_detection_enabled_, | 538 captive_portal_detection_enabled_, |
540 captive_portal_probe_completed_, | 539 captive_portal_probe_completed_, |
541 captive_portal_no_response_, | 540 captive_portal_no_response_, |
542 captive_portal_detected_); | 541 captive_portal_detected_); |
543 NotifyDenyCertificate(); | 542 NotifyDenyCertificate(); |
544 } | 543 } |
545 | 544 |
546 void SSLBlockingPage::NotifyDenyCertificate() { | 545 void SSLBlockingPage::NotifyDenyCertificate() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 // sure we don't clear the captive portal flag, since the interstitial was | 607 // sure we don't clear the captive portal flag, since the interstitial was |
609 // potentially caused by the captive portal. | 608 // potentially caused by the captive portal. |
610 captive_portal_detected_ = captive_portal_detected_ || | 609 captive_portal_detected_ = captive_portal_detected_ || |
611 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | 610 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
612 // Also keep track of non-HTTP portals and error cases. | 611 // Also keep track of non-HTTP portals and error cases. |
613 captive_portal_no_response_ = captive_portal_no_response_ || | 612 captive_portal_no_response_ = captive_portal_no_response_ || |
614 (results->result == captive_portal::RESULT_NO_RESPONSE); | 613 (results->result == captive_portal::RESULT_NO_RESPONSE); |
615 } | 614 } |
616 #endif | 615 #endif |
617 } | 616 } |
OLD | NEW |