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.
5 #ifndef COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_
6 #define COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_
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"
22 #if !BUILDFLAG(IS_ANDROID)
23 #include "ui/gfx/image/image_skia.h"
27 class PageInfoUiDelegate;
30 class X509Certificate;
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,
41 enum class SecuritySummaryColor {
46 enum class SecurityDescriptionType {
47 // The UI describes whether the connection is secure, e.g. secure
48 // HTTPS, non-secure HTTP.
50 // The UI describes e.g. an internal (chrome://) page or extension page.
52 // The UI describes a Safe Browsing warning, e.g. site deceptive or contains
55 // The UI shows a Safety Tip.
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;
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
80 // The number of allowed cookies.
82 // The number of blocked cookies.
85 // Whether these cookies are from the current top-level origin as seen by
86 // the user, or from third-party origins.
90 // |CookiesFpsInfo| contains information about a specific First-Party Set.
91 struct CookiesFpsInfo {
92 explicit CookiesFpsInfo(const std::u16string& owner_name);
95 // The name of the owner of the FPS.
96 std::u16string owner_name;
98 // Whether the Fps are managed by the company.
99 bool is_managed = false;
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 {
110 // The number of third-party sites blocked.
111 int blocked_sites_count = -1;
113 // The number of sites allowed to access cookies.
114 int allowed_sites_count = -1;
116 // The status of blocking third-party cookies.
117 CookieControlsStatus status;
119 // The status of enforcement of blocking third-party cookies.
120 CookieControlsEnforcement enforcement;
122 absl::optional<CookiesFpsInfo> fps_info;
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 {
129 const PageInfo::ChooserUIInfo& ui_info,
130 std::unique_ptr<permissions::ObjectPermissionContextBase::Object>
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>
140 // |IdentityInfo| contains information about the site's identity and
142 struct IdentityInfo {
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
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
156 security_state::SafetyTipInfo safety_tip_info;
157 // Textual description of the Safe Browsing status.
158 std::u16string safe_browsing_details;
160 #if BUILDFLAG(IS_ANDROID)
161 // Textual description of the site's identity status that is displayed to
163 std::string identity_status_description_android;
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
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;
186 struct PageFeatureInfo {
189 // True if VR content is being presented in a headset.
190 bool is_vr_presentation_in_headset;
193 struct PermissionUIInfo {
194 ContentSettingsType type;
196 int string_id_mid_sentence;
199 struct AdPersonalizationInfo {
200 AdPersonalizationInfo();
201 ~AdPersonalizationInfo();
202 bool is_empty() const;
204 bool has_joined_user_to_interest_group;
205 std::vector<privacy_sandbox::CanonicalTopic> accessed_topics;
208 using CookieInfoList = std::vector<CookieInfo>;
209 using PermissionInfoList = std::vector<PageInfo::PermissionInfo>;
210 using ChosenObjectInfoList = std::vector<std::unique_ptr<ChosenObjectInfo>>;
212 virtual ~PageInfoUI();
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
218 static std::u16string PermissionTypeToUIStringMidSentence(
219 ContentSettingsType type);
220 static base::span<const PermissionUIInfo>
221 GetContentSettingsUIInfoForTesting();
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,
235 static std::u16string PermissionStateToUIString(
236 PageInfoUiDelegate* delegate,
237 const PageInfo::PermissionInfo& permission);
239 static std::u16string PermissionMainPageStateToUIString(
240 PageInfoUiDelegate* delegate,
241 const PageInfo::PermissionInfo& permission);
243 static std::u16string PermissionManagedTooltipToUIString(
244 PageInfoUiDelegate* delegate,
245 const PageInfo::PermissionInfo& permission);
247 static std::u16string PermissionAutoBlockedToUIString(
248 PageInfoUiDelegate* delegate,
249 const PageInfo::PermissionInfo& permission);
251 static void ToggleBetweenAllowAndBlock(PageInfo::PermissionInfo& permission);
253 static void ToggleBetweenRememberAndForget(
254 PageInfo::PermissionInfo& permission);
256 static bool IsToggleOn(const PageInfo::PermissionInfo& permission);
258 // Returns the color to use for the permission decision reason strings.
259 static SkColor GetSecondaryTextColor();
261 #if BUILDFLAG(IS_ANDROID)
262 // Returns the identity icon ID for the given identity |status|.
263 static int GetIdentityIconID(PageInfo::SiteIdentityStatus status);
265 // Returns the connection icon ID for the given connection |status|.
266 static int GetConnectionIconID(PageInfo::SiteConnectionStatus status);
268 // Returns the identity icon color ID for the given identity |status|.
269 static int GetIdentityIconColorID(PageInfo::SiteIdentityStatus status);
271 // Returns the connection icon color ID for the given connection |status|.
272 static int GetConnectionIconColorID(PageInfo::SiteConnectionStatus status);
273 #endif // BUILDFLAG(IS_ANDROID)
275 // Return true if the given ContentSettingsType is in PageInfoUI.
276 static bool ContentSettingsTypeInPageInfo(ContentSettingsType type);
278 static std::unique_ptr<SecurityDescription>
279 CreateSafetyTipSecurityDescription(const security_state::SafetyTipInfo& info);
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) {}
287 // Sets permission information.
288 virtual void SetPermissionInfo(const PermissionInfoList& permission_info_list,
289 ChosenObjectInfoList chosen_object_info_list) {
292 // Sets site identity information.
293 virtual void SetIdentityInfo(const IdentityInfo& identity_info) {}
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) {}
299 // Sets ad personalization information.
300 virtual void SetAdPersonalizationInfo(
301 const AdPersonalizationInfo& ad_personalization_info) {}
303 // Helper to get security description info to display to the user.
304 std::unique_ptr<SecurityDescription> GetSecurityDescription(
305 const IdentityInfo& identity_info) const;
308 typedef PageInfoUI::CookieInfoList CookieInfoList;
309 typedef PageInfoUI::PermissionInfoList PermissionInfoList;
310 typedef PageInfoUI::ChosenObjectInfoList ChosenObjectInfoList;
312 #endif // COMPONENTS_PAGE_INFO_PAGE_INFO_UI_H_