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 // This class displays UI for Safe Browsing errors that block page loads. This | 16 // 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 | 17 // 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. | 18 // to determine what type of error should be displayed when. |
Nathan Parker
2017/05/12 17:02:47
Maybe add a comment describing the intention for t
edwardjung
2017/05/12 17:45:53
Done.
| |
19 class SafeBrowsingErrorUI { | 19 class BaseSafeBrowsingErrorUI { |
20 public: | 20 public: |
21 enum SBInterstitialReason { | 21 enum SBInterstitialReason { |
22 SB_REASON_MALWARE, | 22 SB_REASON_MALWARE, |
23 SB_REASON_HARMFUL, | 23 SB_REASON_HARMFUL, |
24 SB_REASON_PHISHING, | 24 SB_REASON_PHISHING, |
25 }; | 25 }; |
26 | 26 |
27 struct SBErrorDisplayOptions { | 27 struct SBErrorDisplayOptions { |
28 SBErrorDisplayOptions(bool is_main_frame_load_blocked, | 28 SBErrorDisplayOptions(bool is_main_frame_load_blocked, |
29 bool is_extended_reporting_opt_in_allowed, | 29 bool is_extended_reporting_opt_in_allowed, |
(...skipping 27 matching lines...) Expand all Loading... | |
57 bool is_scout_reporting_enabled; | 57 bool is_scout_reporting_enabled; |
58 | 58 |
59 // Indicates if kSafeBrowsingProceedAnywayDisabled preference is set. | 59 // Indicates if kSafeBrowsingProceedAnywayDisabled preference is set. |
60 bool is_proceed_anyway_disabled; | 60 bool is_proceed_anyway_disabled; |
61 | 61 |
62 // Indicates if "back to safety" should cancel the pending navigation or | 62 // Indicates if "back to safety" should cancel the pending navigation or |
63 // navigate back after it's committed. | 63 // navigate back after it's committed. |
64 bool is_resource_cancellable; | 64 bool is_resource_cancellable; |
65 }; | 65 }; |
66 | 66 |
67 SafeBrowsingErrorUI(const GURL& request_url, | 67 BaseSafeBrowsingErrorUI( |
68 const GURL& main_frame_url, | 68 const GURL& request_url, |
69 SBInterstitialReason reason, | 69 const GURL& main_frame_url, |
70 const SBErrorDisplayOptions& display_options, | 70 BaseSafeBrowsingErrorUI::SBInterstitialReason reason, |
71 const std::string& app_locale, | 71 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options, |
72 const base::Time& time_triggered, | 72 const std::string& app_locale, |
73 ControllerClient* controller); | 73 const base::Time& time_triggered, |
74 ~SafeBrowsingErrorUI(); | 74 ControllerClient* controller); |
75 | 75 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 | 76 |
84 bool is_main_frame_load_blocked() const { | 77 bool is_main_frame_load_blocked() const { |
85 return display_options_.is_main_frame_load_blocked; | 78 return display_options_.is_main_frame_load_blocked; |
86 } | 79 } |
87 | 80 |
88 bool is_extended_reporting_opt_in_allowed() const { | 81 bool is_extended_reporting_opt_in_allowed() const { |
89 return display_options_.is_extended_reporting_opt_in_allowed; | 82 return display_options_.is_extended_reporting_opt_in_allowed; |
90 } | 83 } |
91 | 84 |
92 bool is_off_the_record() const { | 85 bool is_off_the_record() const { return display_options_.is_off_the_record; } |
93 return display_options_.is_off_the_record; | |
94 } | |
95 | 86 |
96 bool is_extended_reporting_enabled() const { | 87 bool is_extended_reporting_enabled() const { |
97 return display_options_.is_extended_reporting_enabled; | 88 return display_options_.is_extended_reporting_enabled; |
98 } | 89 } |
99 | 90 |
91 void set_extended_reporting(bool pref) { | |
92 display_options_.is_extended_reporting_enabled = pref; | |
93 } | |
94 | |
95 bool is_scout_reporting_enabled() const { | |
96 return display_options_.is_scout_reporting_enabled; | |
97 } | |
98 | |
100 bool is_proceed_anyway_disabled() const { | 99 bool is_proceed_anyway_disabled() const { |
101 return display_options_.is_proceed_anyway_disabled; | 100 return display_options_.is_proceed_anyway_disabled; |
102 } | 101 } |
103 | 102 |
104 const std::string app_locale() const { | 103 bool is_resource_cancellable() const { |
105 return app_locale_; | 104 return display_options_.is_resource_cancellable; |
106 } | 105 } |
107 | 106 |
107 // Checks if we should even show the extended reporting option. We don't show | |
108 // it in incognito mode or if kSafeBrowsingExtendedReportingOptInAllowed | |
109 // preference is disabled. | |
110 bool CanShowExtendedReportingOption() { | |
111 return !is_off_the_record() && is_extended_reporting_opt_in_allowed(); | |
112 } | |
113 | |
114 SBInterstitialReason interstitial_reason() const { | |
115 return interstitial_reason_; | |
116 } | |
117 | |
118 const std::string app_locale() const { return app_locale_; } | |
119 | |
120 ControllerClient* controller() { return controller_; }; | |
121 | |
122 GURL request_url() const { return request_url_; } | |
123 GURL main_frame_url() const { return main_frame_url_; } | |
124 | |
125 virtual void PopulateStringsForHTML( | |
126 base::DictionaryValue* load_time_data) = 0; | |
127 virtual void HandleCommand(SecurityInterstitialCommands command) = 0; | |
128 | |
108 private: | 129 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_; | 130 const GURL request_url_; |
117 const GURL main_frame_url_; | 131 const GURL main_frame_url_; |
118 const SBInterstitialReason interstitial_reason_; | 132 const SBInterstitialReason interstitial_reason_; |
119 SBErrorDisplayOptions display_options_; | 133 SBErrorDisplayOptions display_options_; |
120 const std::string app_locale_; | 134 const std::string app_locale_; |
121 const base::Time time_triggered_; | 135 const base::Time time_triggered_; |
122 | 136 |
123 ControllerClient* controller_; | 137 ControllerClient* controller_; |
124 | 138 |
125 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingErrorUI); | 139 DISALLOW_COPY_AND_ASSIGN(BaseSafeBrowsingErrorUI); |
126 }; | 140 }; |
127 | 141 |
128 } // security_interstitials | 142 } // security_interstitials |
129 | 143 |
130 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_SAFE_BROWSING_ERROR_UI_H_ | 144 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_BASE_SAFE_BROWSING_ERROR_UI_H_ |
OLD | NEW |