base_safe_browsing_error_ui.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_
  5. #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/time/time.h"
  8. #include "base/values.h"
  9. #include "components/security_interstitials/core/controller_client.h"
  10. #include "url/gurl.h"
  11. namespace security_interstitials {
  12. // A base class for quiet vs loud versions of the safe browsing interstitial.
  13. // This class displays UI for Safe Browsing errors that block page loads. This
  14. // class is purely about visual display; it does not do any error-handling logic
  15. // to determine what type of error should be displayed when.
  16. class BaseSafeBrowsingErrorUI {
  17. public:
  18. enum SBInterstitialReason {
  19. SB_REASON_MALWARE,
  20. SB_REASON_HARMFUL,
  21. SB_REASON_PHISHING,
  22. SB_REASON_BILLING,
  23. };
  24. struct SBErrorDisplayOptions {
  25. SBErrorDisplayOptions(bool is_main_frame_load_blocked,
  26. bool is_extended_reporting_opt_in_allowed,
  27. bool is_off_the_record,
  28. bool is_extended_reporting_enabled,
  29. bool is_extended_reporting_policy_managed,
  30. bool is_enhanced_protection_enabled,
  31. bool is_proceed_anyway_disabled,
  32. bool should_open_links_in_new_tab,
  33. bool always_show_back_to_safety,
  34. bool is_enhanced_protection_message_enabled,
  35. bool is_safe_browsing_managed,
  36. const std::string& help_center_article_link);
  37. SBErrorDisplayOptions(const SBErrorDisplayOptions& other);
  38. // Indicates if this SB interstitial is blocking main frame load.
  39. bool is_main_frame_load_blocked;
  40. // Indicates if user is allowed to opt-in extended reporting preference.
  41. bool is_extended_reporting_opt_in_allowed;
  42. // Indicates if user is in incognito mode.
  43. bool is_off_the_record;
  44. // Indicates if user opted in for SB extended reporting.
  45. bool is_extended_reporting_enabled;
  46. // Whether the SBER pref is being managed by enterprise policy, meaning the
  47. // user is unable to change the pref.
  48. bool is_extended_reporting_policy_managed;
  49. // Indicates if enhanced protection is on for the user.
  50. bool is_enhanced_protection_enabled;
  51. // Indicates if kSafeBrowsingProceedAnywayDisabled preference is set.
  52. bool is_proceed_anyway_disabled;
  53. // Indicates if links should use a new foreground tab or the current tab.
  54. bool should_open_links_in_new_tab;
  55. // Indicates if the 'Back to safety' primary action button should always be
  56. // shown. If the option is false, this button is shown only when there is
  57. // a proper page to navigate back to. Chrome and Chromium builds should
  58. // always set this option to true,
  59. bool always_show_back_to_safety;
  60. // Indicates if the feature to show enhanced protection message on the
  61. // interstitial is enabled.
  62. bool is_enhanced_protection_message_enabled;
  63. // Indicates if Safe Browsing is managed.
  64. bool is_safe_browsing_managed;
  65. // The p= query parameter used when visiting the Help Center. If this is
  66. // nullptr, then a default value will be used for the SafeBrowsing article.
  67. std::string help_center_article_link;
  68. };
  69. BaseSafeBrowsingErrorUI(
  70. const GURL& request_url,
  71. const GURL& main_frame_url,
  72. BaseSafeBrowsingErrorUI::SBInterstitialReason reason,
  73. const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options,
  74. const std::string& app_locale,
  75. const base::Time& time_triggered,
  76. ControllerClient* controller);
  77. BaseSafeBrowsingErrorUI(const BaseSafeBrowsingErrorUI&) = delete;
  78. BaseSafeBrowsingErrorUI& operator=(const BaseSafeBrowsingErrorUI&) = delete;
  79. virtual ~BaseSafeBrowsingErrorUI();
  80. bool is_main_frame_load_blocked() const {
  81. return display_options_.is_main_frame_load_blocked;
  82. }
  83. bool is_extended_reporting_opt_in_allowed() const {
  84. return display_options_.is_extended_reporting_opt_in_allowed;
  85. }
  86. bool is_off_the_record() const { return display_options_.is_off_the_record; }
  87. bool is_extended_reporting_enabled() const {
  88. return display_options_.is_extended_reporting_enabled;
  89. }
  90. void set_extended_reporting(bool pref) {
  91. display_options_.is_extended_reporting_enabled = pref;
  92. }
  93. bool is_extended_reporting_policy_managed() const {
  94. return display_options_.is_extended_reporting_policy_managed;
  95. }
  96. bool is_enhanced_protection_enabled() const {
  97. return display_options_.is_enhanced_protection_enabled;
  98. }
  99. bool is_proceed_anyway_disabled() const {
  100. return display_options_.is_proceed_anyway_disabled;
  101. }
  102. bool should_open_links_in_new_tab() const {
  103. return display_options_.should_open_links_in_new_tab;
  104. }
  105. bool always_show_back_to_safety() const {
  106. return display_options_.always_show_back_to_safety;
  107. }
  108. const std::string& get_help_center_article_link() const {
  109. return display_options_.help_center_article_link;
  110. }
  111. bool is_enhanced_protection_message_enabled() const {
  112. return display_options_.is_enhanced_protection_message_enabled;
  113. }
  114. bool is_safe_browsing_managed() const {
  115. return display_options_.is_safe_browsing_managed;
  116. }
  117. const SBErrorDisplayOptions& get_error_display_options() const {
  118. return display_options_;
  119. }
  120. // Checks if we should even show the extended reporting option.
  121. // We don't show it:
  122. // - in incognito mode
  123. // - if kSafeBrowsingExtendedReportingOptInAllowed preference is disabled.
  124. // - if kSafeBrowsingExtendedReporting is managed by enterprise policy.
  125. // - if enhanced protection is on
  126. bool CanShowExtendedReportingOption() {
  127. return !is_off_the_record() && is_extended_reporting_opt_in_allowed() &&
  128. !is_extended_reporting_policy_managed() &&
  129. !is_enhanced_protection_enabled();
  130. }
  131. // Checks if we should even show the enhanced protection message.
  132. // We don't show it:
  133. // - in incognito mode, OR
  134. // - if kEnhancedProtectionMessageInInterstitials flag is disabled, OR
  135. // - if kSafeBrowsingEnabled or kSafeBrowsingEnhanced is managed by enterprise
  136. // policy, OR
  137. // - if enhanced protection is on
  138. bool CanShowEnhancedProtectionMessage() {
  139. return !is_off_the_record() && is_enhanced_protection_message_enabled() &&
  140. !is_safe_browsing_managed() && !is_enhanced_protection_enabled();
  141. }
  142. SBInterstitialReason interstitial_reason() const {
  143. return interstitial_reason_;
  144. }
  145. const std::string app_locale() const { return app_locale_; }
  146. ControllerClient* controller() { return controller_; }
  147. GURL request_url() const { return request_url_; }
  148. GURL main_frame_url() const { return main_frame_url_; }
  149. virtual void PopulateStringsForHtml(base::Value::Dict& load_time_data) = 0;
  150. virtual void HandleCommand(SecurityInterstitialCommand command) = 0;
  151. virtual int GetHTMLTemplateId() const = 0;
  152. private:
  153. const GURL request_url_;
  154. const GURL main_frame_url_;
  155. const SBInterstitialReason interstitial_reason_;
  156. SBErrorDisplayOptions display_options_;
  157. const std::string app_locale_;
  158. const base::Time time_triggered_;
  159. raw_ptr<ControllerClient> controller_;
  160. };
  161. } // security_interstitials
  162. #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_