page_info_ui.h 11 KB

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