blocked_interception_ui.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/security_interstitials/core/blocked_interception_ui.h"
  5. #include "base/i18n/number_formatting.h"
  6. #include "base/strings/escape.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "build/build_config.h"
  9. #include "components/security_interstitials/core/common_string_util.h"
  10. #include "components/security_interstitials/core/metrics_helper.h"
  11. #include "components/ssl_errors/error_info.h"
  12. #include "components/strings/grit/components_strings.h"
  13. #include "ui/base/l10n/l10n_util.h"
  14. namespace security_interstitials {
  15. BlockedInterceptionUI::BlockedInterceptionUI(const GURL& request_url,
  16. int cert_error,
  17. const net::SSLInfo& ssl_info,
  18. ControllerClient* controller)
  19. : request_url_(request_url),
  20. cert_error_(cert_error),
  21. ssl_info_(ssl_info),
  22. controller_(controller),
  23. user_made_decision_(false) {
  24. controller_->metrics_helper()->RecordUserInteraction(
  25. security_interstitials::MetricsHelper::TOTAL_VISITS);
  26. }
  27. BlockedInterceptionUI::~BlockedInterceptionUI() {
  28. // If the page is closing without an explicit decision, record it as not
  29. // proceeding.
  30. if (!user_made_decision_) {
  31. controller_->metrics_helper()->RecordUserDecision(
  32. MetricsHelper::DONT_PROCEED);
  33. }
  34. controller_->metrics_helper()->RecordShutdownMetrics();
  35. }
  36. void BlockedInterceptionUI::PopulateStringsForHTML(
  37. base::Value::Dict& load_time_data) {
  38. // Shared with other SSL errors.
  39. common_string_util::PopulateSSLLayoutStrings(cert_error_, load_time_data);
  40. common_string_util::PopulateSSLDebuggingStrings(
  41. ssl_info_, base::Time::NowFromSystemTime(), load_time_data);
  42. load_time_data.Set("overridable", true);
  43. load_time_data.Set("hide_primary_button", false);
  44. load_time_data.Set("bad_clock", false);
  45. load_time_data.Set("type", "BLOCKED_INTERCEPTION");
  46. const std::u16string hostname(
  47. common_string_util::GetFormattedHostName(request_url_));
  48. // Set strings that are shared between enterprise and non-enterprise
  49. // interstitials.
  50. load_time_data.Set(
  51. "tabTitle",
  52. l10n_util::GetStringFUTF16(IDS_BLOCKED_INTERCEPTION_HEADING, hostname));
  53. load_time_data.Set(
  54. "heading",
  55. l10n_util::GetStringFUTF16(IDS_BLOCKED_INTERCEPTION_HEADING, hostname));
  56. load_time_data.Set(
  57. "primaryButtonText",
  58. l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON));
  59. load_time_data.Set("finalParagraph", "");
  60. // Reuse the strings from the WebUI page.
  61. load_time_data.Set("primaryParagraph",
  62. l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_BODY1));
  63. load_time_data.Set("explanationParagraph",
  64. l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_BODY2));
  65. load_time_data.Set("finalParagraph",
  66. l10n_util::GetStringFUTF16(
  67. IDS_SSL_OVERRIDABLE_PROCEED_PARAGRAPH, hostname));
  68. }
  69. void BlockedInterceptionUI::HandleCommand(SecurityInterstitialCommand command) {
  70. switch (command) {
  71. case CMD_PROCEED: {
  72. controller_->metrics_helper()->RecordUserDecision(MetricsHelper::PROCEED);
  73. controller_->Proceed();
  74. user_made_decision_ = true;
  75. break;
  76. }
  77. case CMD_DO_REPORT:
  78. controller_->SetReportingPreference(true);
  79. break;
  80. case CMD_DONT_REPORT:
  81. controller_->SetReportingPreference(false);
  82. break;
  83. case CMD_SHOW_MORE_SECTION:
  84. controller_->metrics_helper()->RecordUserInteraction(
  85. security_interstitials::MetricsHelper::SHOW_ADVANCED);
  86. break;
  87. case CMD_OPEN_REPORTING_PRIVACY:
  88. controller_->OpenExtendedReportingPrivacyPolicy(true);
  89. break;
  90. case CMD_OPEN_WHITEPAPER:
  91. controller_->OpenExtendedReportingWhitepaper(true);
  92. break;
  93. case CMD_OPEN_ENHANCED_PROTECTION_SETTINGS:
  94. controller_->metrics_helper()->RecordUserInteraction(
  95. security_interstitials::MetricsHelper::OPEN_ENHANCED_PROTECTION);
  96. controller_->OpenEnhancedProtectionSettings();
  97. break;
  98. case CMD_OPEN_HELP_CENTER:
  99. case CMD_DONT_PROCEED:
  100. case CMD_RELOAD:
  101. case CMD_OPEN_DATE_SETTINGS:
  102. case CMD_OPEN_DIAGNOSTIC:
  103. case CMD_OPEN_LOGIN:
  104. case CMD_REPORT_PHISHING_ERROR:
  105. // Not supported by the SSL error page.
  106. NOTREACHED() << "Unsupported command: " << command;
  107. break;
  108. case CMD_ERROR:
  109. case CMD_TEXT_FOUND:
  110. case CMD_TEXT_NOT_FOUND:
  111. // Commands are for testing.
  112. break;
  113. }
  114. }
  115. } // namespace security_interstitials