OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_SAFE_BROWSING_ERROR_UI_H_ | 5 #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_ |
6 #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_SAFE_BROWSING_ERROR_UI_H_ | 6 #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "components/security_interstitials/core/controller_client.h" | 11 #include "components/security_interstitials/core/controller_client.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 namespace security_interstitials { | 14 namespace security_interstitials { |
15 | 15 |
| 16 // A base class for quiet vs loud versions of the safe browsing interstitial. |
16 // This class displays UI for Safe Browsing errors that block page loads. This | 17 // This class displays UI for Safe Browsing errors that block page loads. This |
17 // class is purely about visual display; it does not do any error-handling logic | 18 // class is purely about visual display; it does not do any error-handling logic |
18 // to determine what type of error should be displayed when. | 19 // to determine what type of error should be displayed when. |
19 class SafeBrowsingErrorUI { | 20 class BaseSafeBrowsingErrorUI { |
20 public: | 21 public: |
21 enum SBInterstitialReason { | 22 enum SBInterstitialReason { |
22 SB_REASON_MALWARE, | 23 SB_REASON_MALWARE, |
23 SB_REASON_HARMFUL, | 24 SB_REASON_HARMFUL, |
24 SB_REASON_PHISHING, | 25 SB_REASON_PHISHING, |
25 }; | 26 }; |
26 | 27 |
27 struct SBErrorDisplayOptions { | 28 struct SBErrorDisplayOptions { |
28 SBErrorDisplayOptions(bool is_main_frame_load_blocked, | 29 SBErrorDisplayOptions(bool is_main_frame_load_blocked, |
29 bool is_extended_reporting_opt_in_allowed, | 30 bool is_extended_reporting_opt_in_allowed, |
(...skipping 27 matching lines...) Expand all Loading... |
57 bool is_scout_reporting_enabled; | 58 bool is_scout_reporting_enabled; |
58 | 59 |
59 // Indicates if kSafeBrowsingProceedAnywayDisabled preference is set. | 60 // Indicates if kSafeBrowsingProceedAnywayDisabled preference is set. |
60 bool is_proceed_anyway_disabled; | 61 bool is_proceed_anyway_disabled; |
61 | 62 |
62 // Indicates if "back to safety" should cancel the pending navigation or | 63 // Indicates if "back to safety" should cancel the pending navigation or |
63 // navigate back after it's committed. | 64 // navigate back after it's committed. |
64 bool is_resource_cancellable; | 65 bool is_resource_cancellable; |
65 }; | 66 }; |
66 | 67 |
67 SafeBrowsingErrorUI(const GURL& request_url, | 68 BaseSafeBrowsingErrorUI( |
68 const GURL& main_frame_url, | 69 const GURL& request_url, |
69 SBInterstitialReason reason, | 70 const GURL& main_frame_url, |
70 const SBErrorDisplayOptions& display_options, | 71 BaseSafeBrowsingErrorUI::SBInterstitialReason reason, |
71 const std::string& app_locale, | 72 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options, |
72 const base::Time& time_triggered, | 73 const std::string& app_locale, |
73 ControllerClient* controller); | 74 const base::Time& time_triggered, |
74 ~SafeBrowsingErrorUI(); | 75 ControllerClient* controller); |
75 | 76 virtual ~BaseSafeBrowsingErrorUI(); |
76 void PopulateStringsForHTML(base::DictionaryValue* load_time_data); | |
77 void HandleCommand(SecurityInterstitialCommands command); | |
78 | |
79 // Checks if we should even show the extended reporting option. We don't show | |
80 // it in incognito mode or if kSafeBrowsingExtendedReportingOptInAllowed | |
81 // preference is disabled. | |
82 bool CanShowExtendedReportingOption(); | |
83 | 77 |
84 bool is_main_frame_load_blocked() const { | 78 bool is_main_frame_load_blocked() const { |
85 return display_options_.is_main_frame_load_blocked; | 79 return display_options_.is_main_frame_load_blocked; |
86 } | 80 } |
87 | 81 |
88 bool is_extended_reporting_opt_in_allowed() const { | 82 bool is_extended_reporting_opt_in_allowed() const { |
89 return display_options_.is_extended_reporting_opt_in_allowed; | 83 return display_options_.is_extended_reporting_opt_in_allowed; |
90 } | 84 } |
91 | 85 |
92 bool is_off_the_record() const { | 86 bool is_off_the_record() const { return display_options_.is_off_the_record; } |
93 return display_options_.is_off_the_record; | |
94 } | |
95 | 87 |
96 bool is_extended_reporting_enabled() const { | 88 bool is_extended_reporting_enabled() const { |
97 return display_options_.is_extended_reporting_enabled; | 89 return display_options_.is_extended_reporting_enabled; |
98 } | 90 } |
99 | 91 |
| 92 void set_extended_reporting(bool pref) { |
| 93 display_options_.is_extended_reporting_enabled = pref; |
| 94 } |
| 95 |
| 96 bool is_scout_reporting_enabled() const { |
| 97 return display_options_.is_scout_reporting_enabled; |
| 98 } |
| 99 |
100 bool is_proceed_anyway_disabled() const { | 100 bool is_proceed_anyway_disabled() const { |
101 return display_options_.is_proceed_anyway_disabled; | 101 return display_options_.is_proceed_anyway_disabled; |
102 } | 102 } |
103 | 103 |
104 const std::string app_locale() const { | 104 bool is_resource_cancellable() const { |
105 return app_locale_; | 105 return display_options_.is_resource_cancellable; |
106 } | 106 } |
107 | 107 |
| 108 // Checks if we should even show the extended reporting option. We don't show |
| 109 // it in incognito mode or if kSafeBrowsingExtendedReportingOptInAllowed |
| 110 // preference is disabled. |
| 111 bool CanShowExtendedReportingOption() { |
| 112 return !is_off_the_record() && is_extended_reporting_opt_in_allowed(); |
| 113 } |
| 114 |
| 115 SBInterstitialReason interstitial_reason() const { |
| 116 return interstitial_reason_; |
| 117 } |
| 118 |
| 119 const std::string app_locale() const { return app_locale_; } |
| 120 |
| 121 ControllerClient* controller() { return controller_; }; |
| 122 |
| 123 GURL request_url() const { return request_url_; } |
| 124 GURL main_frame_url() const { return main_frame_url_; } |
| 125 |
| 126 virtual void PopulateStringsForHTML( |
| 127 base::DictionaryValue* load_time_data) = 0; |
| 128 virtual void HandleCommand(SecurityInterstitialCommands command) = 0; |
| 129 |
108 private: | 130 private: |
109 // Fills the passed dictionary with the values to be passed to the template | |
110 // when creating the HTML. | |
111 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data); | |
112 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); | |
113 void PopulateHarmfulLoadTimeData(base::DictionaryValue* load_time_data); | |
114 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); | |
115 | |
116 const GURL request_url_; | 131 const GURL request_url_; |
117 const GURL main_frame_url_; | 132 const GURL main_frame_url_; |
118 const SBInterstitialReason interstitial_reason_; | 133 const SBInterstitialReason interstitial_reason_; |
119 SBErrorDisplayOptions display_options_; | 134 SBErrorDisplayOptions display_options_; |
120 const std::string app_locale_; | 135 const std::string app_locale_; |
121 const base::Time time_triggered_; | 136 const base::Time time_triggered_; |
122 | 137 |
123 ControllerClient* controller_; | 138 ControllerClient* controller_; |
124 | 139 |
125 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingErrorUI); | 140 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingErrorUI); |
126 }; | 141 }; |
127 | 142 |
128 } // security_interstitials | 143 } // security_interstitials |
129 | 144 |
130 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_SAFE_BROWSING_ERROR_UI_H_ | 145 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_ |
OLD | NEW |