Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / components / page_info / page_info_ui.h
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_
6 #define COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "build/build_config.h"
13 #include "components/content_settings/core/common/content_settings.h"
14 #include "components/content_settings/core/common/content_settings_types.h"
15 #include "components/page_info/page_info.h"
16 #include "components/permissions/object_permission_context_base.h"
17 #include "components/privacy_sandbox/canonical_topic.h"
18 #include "components/safe_browsing/buildflags.h"
19 #include "ui/base/models/image_model.h"
20 #include "ui/gfx/native_widget_types.h"
21
22 #if !BUILDFLAG(IS_ANDROID)
23 #include "ui/gfx/image/image_skia.h"
24 #endif
25
26 class PageInfo;
27 class PageInfoUiDelegate;
28
29 namespace net {
30 class X509Certificate;
31 }
32
33 // The class |PageInfoUI| specifies the platform independent
34 // interface of the page info UI. The page info UI displays
35 // information and controls for site specific data (local stored objects like
36 // cookies), site specific permissions (location, popup, plugin, etc.
37 // permissions) and site specific information (identity, connection status,
38 // etc.).
39 class PageInfoUI {
40  public:
41   enum class SecuritySummaryColor {
42     RED,
43     GREEN,
44   };
45
46   enum class SecurityDescriptionType {
47     // The UI describes whether the connection is secure, e.g. secure
48     // HTTPS, non-secure HTTP.
49     CONNECTION,
50     // The UI describes e.g. an internal (chrome://) page or extension page.
51     INTERNAL,
52     // The UI describes a Safe Browsing warning, e.g. site deceptive or contains
53     // malware.
54     SAFE_BROWSING,
55     // The UI shows a Safety Tip.
56     SAFETY_TIP,
57   };
58
59   struct SecurityDescription {
60     // The text style for |summary| used to color it. This provides an
61     // opinionated guide to the user on the overall security state of the site.
62     SecuritySummaryColor summary_style;
63     // A one-line summary of the security state.
64     std::u16string summary;
65     // A short paragraph with more details about the state, and how
66     // the user should treat it.
67     std::u16string details;
68     // The category of the security description, used to determine which help
69     // center article to link to.
70     SecurityDescriptionType type;
71   };
72
73   // |CookieInfo| contains information about the cookies from a specific source.
74   // A source can for example be a specific origin or an entire wildcard domain.
75   // TODO(crbug.com/1346305): Remove after finishing cookies subpage
76   // implementation.
77   struct CookieInfo {
78     CookieInfo();
79
80     // The number of allowed cookies.
81     int allowed;
82     // The number of blocked cookies.
83     int blocked;
84
85     // Whether these cookies are from the current top-level origin as seen by
86     // the user, or from third-party origins.
87     bool is_first_party;
88   };
89
90   // |CookiesFpsInfo| contains information about a specific First-Party Set.
91   struct CookiesFpsInfo {
92     explicit CookiesFpsInfo(const std::u16string& owner_name);
93     ~CookiesFpsInfo();
94
95     // The name of the owner of the FPS.
96     std::u16string owner_name;
97
98     // Whether the Fps are managed by the company.
99     bool is_managed = false;
100   };
101
102   // |CookiesNewInfo| contains information about the sites that are allowed
103   // to access cookies and fps cookies info for new UI.
104   // TODO(crbug.com/1346305):  Change the name to "CookieInfo" after finishing
105   // cookies subpage implementation
106   struct CookiesNewInfo {
107     CookiesNewInfo();
108     ~CookiesNewInfo();
109
110     // The number of third-party sites blocked.
111     int blocked_sites_count = -1;
112
113     // The number of sites allowed to access cookies.
114     int allowed_sites_count = -1;
115
116     // The status of blocking third-party cookies.
117     CookieControlsStatus status;
118
119     // The status of enforcement of blocking third-party cookies.
120     CookieControlsEnforcement enforcement;
121
122     absl::optional<CookiesFpsInfo> fps_info;
123   };
124
125   // |ChosenObjectInfo| contains information about a single |chooser_object| of
126   // a chooser |type| that the current website has been granted access to.
127   struct ChosenObjectInfo {
128     ChosenObjectInfo(
129         const PageInfo::ChooserUIInfo& ui_info,
130         std::unique_ptr<permissions::ObjectPermissionContextBase::Object>
131             chooser_object);
132     ~ChosenObjectInfo();
133     // |ui_info| for this chosen object type.
134     const PageInfo::ChooserUIInfo& ui_info;
135     // The opaque |chooser_object| representing the thing the user selected.
136     std::unique_ptr<permissions::ObjectPermissionContextBase::Object>
137         chooser_object;
138   };
139
140   // |IdentityInfo| contains information about the site's identity and
141   // connection.
142   struct IdentityInfo {
143     IdentityInfo();
144     ~IdentityInfo();
145
146     // The site's identity: the certificate's Organization Name for sites with
147     // Extended Validation certificates, or the URL's hostname for all other
148     // sites.
149     std::string site_identity;
150     // Status of the site's identity.
151     PageInfo::SiteIdentityStatus identity_status;
152     // Site's Safe Browsing status.
153     PageInfo::SafeBrowsingStatus safe_browsing_status;
154     // Site's safety tip info. Only set if the feature is enabled to show the
155     // Safety Tip UI.
156     security_state::SafetyTipInfo safety_tip_info;
157     // Textual description of the Safe Browsing status.
158     std::u16string safe_browsing_details;
159
160 #if BUILDFLAG(IS_ANDROID)
161     // Textual description of the site's identity status that is displayed to
162     // the user.
163     std::string identity_status_description_android;
164 #endif
165
166     // The server certificate if a secure connection.
167     scoped_refptr<net::X509Certificate> certificate;
168     // Status of the site's connection.
169     PageInfo::SiteConnectionStatus connection_status;
170     // Textual description of the site's connection status that is displayed to
171     // the user.
172     std::string connection_status_description;
173     // Set when the user has explicitly bypassed an SSL error for this host
174     // and/or the user has explicitly bypassed an HTTP warning (from HTTPS-First
175     // Mode) for this host. When `show_ssl_decision_revoke_button` is true, the
176     // connection area of the page info UI will include an option for the user
177     // to revoke their decision to bypass warnings for this host.
178     bool show_ssl_decision_revoke_button;
179     // Set when the user ignored the password reuse modal warning dialog. When
180     // |show_change_password_buttons| is true, the page identity area of the
181     // page info will include buttons to change corresponding password, and
182     // to whitelist current site.
183     bool show_change_password_buttons;
184   };
185
186   struct PageFeatureInfo {
187     PageFeatureInfo();
188
189     // True if VR content is being presented in a headset.
190     bool is_vr_presentation_in_headset;
191   };
192
193   struct PermissionUIInfo {
194     ContentSettingsType type;
195     int string_id;
196     int string_id_mid_sentence;
197   };
198
199   struct AdPersonalizationInfo {
200     AdPersonalizationInfo();
201     ~AdPersonalizationInfo();
202     bool is_empty() const;
203
204     bool has_joined_user_to_interest_group;
205     std::vector<privacy_sandbox::CanonicalTopic> accessed_topics;
206   };
207
208   using CookieInfoList = std::vector<CookieInfo>;
209   using PermissionInfoList = std::vector<PageInfo::PermissionInfo>;
210   using ChosenObjectInfoList = std::vector<std::unique_ptr<ChosenObjectInfo>>;
211
212   virtual ~PageInfoUI();
213
214   // Returns the UI string for the given permission |type|.
215   static std::u16string PermissionTypeToUIString(ContentSettingsType type);
216   // Returns the UI string for the given permission |type| when used
217   // mid-sentence.
218   static std::u16string PermissionTypeToUIStringMidSentence(
219       ContentSettingsType type);
220   static base::span<const PermissionUIInfo>
221   GetContentSettingsUIInfoForTesting();
222
223   // Returns the UI string describing the action taken for a permission,
224   // including why that action was taken. E.g. "Allowed by you",
225   // "Blocked by default". If |setting| is default, specify the actual default
226   // setting using |default_setting|.
227   static std::u16string PermissionActionToUIString(
228       PageInfoUiDelegate* delegate,
229       ContentSettingsType type,
230       ContentSetting setting,
231       ContentSetting default_setting,
232       content_settings::SettingSource source,
233       bool is_one_time);
234
235   static std::u16string PermissionStateToUIString(
236       PageInfoUiDelegate* delegate,
237       const PageInfo::PermissionInfo& permission);
238
239   static std::u16string PermissionMainPageStateToUIString(
240       PageInfoUiDelegate* delegate,
241       const PageInfo::PermissionInfo& permission);
242
243   static std::u16string PermissionManagedTooltipToUIString(
244       PageInfoUiDelegate* delegate,
245       const PageInfo::PermissionInfo& permission);
246
247   static std::u16string PermissionAutoBlockedToUIString(
248       PageInfoUiDelegate* delegate,
249       const PageInfo::PermissionInfo& permission);
250
251   static void ToggleBetweenAllowAndBlock(PageInfo::PermissionInfo& permission);
252
253   static void ToggleBetweenRememberAndForget(
254       PageInfo::PermissionInfo& permission);
255
256   static bool IsToggleOn(const PageInfo::PermissionInfo& permission);
257
258   // Returns the color to use for the permission decision reason strings.
259   static SkColor GetSecondaryTextColor();
260
261 #if BUILDFLAG(IS_ANDROID)
262   // Returns the identity icon ID for the given identity |status|.
263   static int GetIdentityIconID(PageInfo::SiteIdentityStatus status);
264
265   // Returns the connection icon ID for the given connection |status|.
266   static int GetConnectionIconID(PageInfo::SiteConnectionStatus status);
267
268   // Returns the identity icon color ID for the given identity |status|.
269   static int GetIdentityIconColorID(PageInfo::SiteIdentityStatus status);
270
271   // Returns the connection icon color ID for the given connection |status|.
272   static int GetConnectionIconColorID(PageInfo::SiteConnectionStatus status);
273 #endif  // BUILDFLAG(IS_ANDROID)
274
275   // Return true if the given ContentSettingsType is in PageInfoUI.
276   static bool ContentSettingsTypeInPageInfo(ContentSettingsType type);
277
278   static std::unique_ptr<SecurityDescription>
279   CreateSafetyTipSecurityDescription(const security_state::SafetyTipInfo& info);
280
281   // Sets cookie information.
282   // TODO(crbug.com/1346305) remove unused function overload after finished
283   // project. Sets cookie information.
284   virtual void SetCookieInfo(const CookieInfoList& cookie_info_list) {}
285   virtual void SetCookieInfo(const CookiesNewInfo& cookie_info) {}
286
287   // Sets permission information.
288   virtual void SetPermissionInfo(const PermissionInfoList& permission_info_list,
289                                  ChosenObjectInfoList chosen_object_info_list) {
290   }
291
292   // Sets site identity information.
293   virtual void SetIdentityInfo(const IdentityInfo& identity_info) {}
294
295   // Sets feature related information; for now only if VR content is being
296   // presented in a headset.
297   virtual void SetPageFeatureInfo(const PageFeatureInfo& page_feature_info) {}
298
299   // Sets ad personalization information.
300   virtual void SetAdPersonalizationInfo(
301       const AdPersonalizationInfo& ad_personalization_info) {}
302
303   // Helper to get security description info to display to the user.
304   std::unique_ptr<SecurityDescription> GetSecurityDescription(
305       const IdentityInfo& identity_info) const;
306 };
307
308 typedef PageInfoUI::CookieInfoList CookieInfoList;
309 typedef PageInfoUI::PermissionInfoList PermissionInfoList;
310 typedef PageInfoUI::ChosenObjectInfoList ChosenObjectInfoList;
311
312 #endif  // COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_