infobar_delegate.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // Copyright 2014 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_INFOBARS_CORE_INFOBAR_DELEGATE_H_
  5. #define COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
  6. #include <string>
  7. #include "base/memory/raw_ptr.h"
  8. #include "build/build_config.h"
  9. #include "ui/base/models/image_model.h"
  10. #include "ui/base/window_open_disposition.h"
  11. #include "url/gurl.h"
  12. class ConfirmInfoBarDelegate;
  13. class HungRendererInfoBarDelegate;
  14. class ThemeInstalledInfoBarDelegate;
  15. namespace blocked_content {
  16. class PopupBlockedInfoBarDelegate;
  17. }
  18. #if BUILDFLAG(IS_ANDROID)
  19. namespace offline_pages {
  20. class OfflinePageInfoBarDelegate;
  21. }
  22. #endif
  23. namespace translate {
  24. class TranslateInfoBarDelegate;
  25. }
  26. namespace gfx {
  27. class Image;
  28. struct VectorIcon;
  29. }
  30. namespace infobars {
  31. class InfoBar;
  32. // An interface implemented by objects wishing to control an InfoBar.
  33. // Implementing this interface is not sufficient to use an InfoBar, since it
  34. // does not map to a specific InfoBar type. Instead, you must implement
  35. // ConfirmInfoBarDelegate, or override with your own delegate for your own
  36. // InfoBar variety.
  37. class InfoBarDelegate {
  38. public:
  39. // The type of the infobar. It controls its appearance, such as its background
  40. // color.
  41. enum Type {
  42. WARNING_TYPE,
  43. PAGE_ACTION_TYPE,
  44. };
  45. enum InfoBarAutomationType {
  46. CONFIRM_INFOBAR,
  47. PASSWORD_INFOBAR,
  48. RPH_INFOBAR,
  49. UNKNOWN_INFOBAR,
  50. };
  51. // Unique identifier for every InfoBarDelegate subclass. Use suffixes to mark
  52. // infobars specific to particular OSes/platforms.
  53. // KEEP IN SYNC WITH THE InfoBarIdentifier ENUM IN enums.xml.
  54. // NEW VALUES MUST BE APPENDED AND AVOID CHANGING ANY PRE-EXISTING VALUES.
  55. // A Java counterpart will be generated for this enum.
  56. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.infobar
  57. enum InfoBarIdentifier {
  58. INVALID = -1,
  59. TEST_INFOBAR = 0,
  60. // Removed: APP_BANNER_INFOBAR_DELEGATE = 1,
  61. // Removed: APP_BANNER_INFOBAR_DELEGATE_DESKTOP = 2,
  62. // Removed: ANDROID_DOWNLOAD_MANAGER_DUPLICATE_INFOBAR_DELEGATE = 3,
  63. DUPLICATE_DOWNLOAD_INFOBAR_DELEGATE_ANDROID = 4,
  64. // Removed: DOWNLOAD_REQUEST_INFOBAR_DELEGATE_ANDROID = 5,
  65. // Removed: FULLSCREEN_INFOBAR_DELEGATE = 6,
  66. HUNG_PLUGIN_INFOBAR_DELEGATE = 7,
  67. HUNG_RENDERER_INFOBAR_DELEGATE_ANDROID = 8,
  68. // Removed: MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID = 9,
  69. // Removed: MEDIA_THROTTLE_INFOBAR_DELEGATE = 10,
  70. // Removed: REQUEST_QUOTA_INFOBAR_DELEGATE = 11,
  71. DEV_TOOLS_INFOBAR_DELEGATE = 12,
  72. EXTENSION_DEV_TOOLS_INFOBAR_DELEGATE = 13,
  73. INCOGNITO_CONNECTABILITY_INFOBAR_DELEGATE = 14,
  74. THEME_INSTALLED_INFOBAR_DELEGATE = 15,
  75. // Removed: GEOLOCATION_INFOBAR_DELEGATE_ANDROID = 16,
  76. THREE_D_API_INFOBAR_DELEGATE = 17,
  77. // Removed: INSECURE_CONTENT_INFOBAR_DELEGATE = 18,
  78. // Removed: MIDI_PERMISSION_INFOBAR_DELEGATE_ANDROID = 19,
  79. // Removed: PROTECTED_MEDIA_IDENTIFIER_INFOBAR_DELEGATE_ANDROID = 20,
  80. NACL_INFOBAR_DELEGATE = 21,
  81. // Removed: DATA_REDUCTION_PROXY_INFOBAR_DELEGATE_ANDROID = 22,
  82. // Removed: NOTIFICATION_PERMISSION_INFOBAR_DELEGATE = 23,
  83. // Removed: AUTO_SIGNIN_FIRST_RUN_INFOBAR_DELEGATE = 24,
  84. GENERATED_PASSWORD_SAVED_INFOBAR_DELEGATE_ANDROID = 25,
  85. SAVE_PASSWORD_INFOBAR_DELEGATE_MOBILE = 26,
  86. // Removed: PEPPER_BROKER_INFOBAR_DELEGATE = 27,
  87. PERMISSION_UPDATE_INFOBAR_DELEGATE_ANDROID = 28,
  88. // Removed: DURABLE_STORAGE_PERMISSION_INFOBAR_DELEGATE_ANDROID = 29,
  89. // Removed: NPAPI_REMOVAL_INFOBAR_DELEGATE = 30,
  90. OUTDATED_PLUGIN_INFOBAR_DELEGATE = 31,
  91. // Removed: PLUGIN_METRO_MODE_INFOBAR_DELEGATE = 32,
  92. RELOAD_PLUGIN_INFOBAR_DELEGATE = 33,
  93. PLUGIN_OBSERVER_INFOBAR_DELEGATE = 34,
  94. // Removed: SSL_ADD_CERTIFICATE = 35,
  95. // Removed: SSL_ADD_CERTIFICATE_INFOBAR_DELEGATE = 36,
  96. POPUP_BLOCKED_INFOBAR_DELEGATE_MOBILE = 37,
  97. FILE_ACCESS_DISABLED_INFOBAR_DELEGATE = 38,
  98. KEYSTONE_PROMOTION_INFOBAR_DELEGATE_MAC = 39,
  99. COLLECTED_COOKIES_INFOBAR_DELEGATE = 40,
  100. INSTALLATION_ERROR_INFOBAR_DELEGATE = 41,
  101. ALTERNATE_NAV_INFOBAR_DELEGATE = 42,
  102. BAD_FLAGS_INFOBAR_DELEGATE = 43,
  103. DEFAULT_BROWSER_INFOBAR_DELEGATE = 44,
  104. GOOGLE_API_KEYS_INFOBAR_DELEGATE = 45,
  105. OBSOLETE_SYSTEM_INFOBAR_DELEGATE = 46,
  106. SESSION_CRASHED_INFOBAR_DELEGATE_IOS = 47,
  107. PAGE_INFO_INFOBAR_DELEGATE = 48,
  108. AUTOFILL_CC_INFOBAR_DELEGATE_MOBILE = 49,
  109. TRANSLATE_INFOBAR_DELEGATE_NON_AURA = 50,
  110. // Removed: IOS_CHROME_SAVE_PASSWORD_INFOBAR_DELEGATE = 51,
  111. // Removed: NATIVE_APP_INSTALLER_INFOBAR_DELEGATE = 52,
  112. // Removed: NATIVE_APP_LAUNCHER_INFOBAR_DELEGATE = 53,
  113. // Removed: NATIVE_APP_OPEN_POLICY_INFOBAR_DELEGATE = 54,
  114. RE_SIGN_IN_INFOBAR_DELEGATE_IOS = 55,
  115. SHOW_PASSKIT_ERROR_INFOBAR_DELEGATE_IOS = 56,
  116. // Removed: READER_MODE_INFOBAR_DELEGATE_IOS = 57,
  117. SYNC_ERROR_INFOBAR_DELEGATE_IOS = 58,
  118. UPGRADE_INFOBAR_DELEGATE_IOS = 59,
  119. // Removed: WINDOW_ERROR_INFOBAR_DELEGATE_ANDROID = 60,
  120. DANGEROUS_DOWNLOAD_INFOBAR_DELEGATE_ANDROID = 61,
  121. // Removed: DESKTOP_SEARCH_REDIRECTION_INFOBAR_DELEGATE = 62,
  122. UPDATE_PASSWORD_INFOBAR_DELEGATE_MOBILE = 63,
  123. // Removed: DATA_REDUCTION_PROMO_INFOBAR_DELEGATE_ANDROID = 64,
  124. AUTOFILL_CREDIT_CARD_FILLING_INFOBAR_DELEGATE_ANDROID = 65,
  125. ADS_BLOCKED_INFOBAR_DELEGATE_ANDROID = 66,
  126. INSTANT_APPS_INFOBAR_DELEGATE_ANDROID = 67,
  127. // Removed: DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE = 68,
  128. // Removed: SCREEN_CAPTURE_INFOBAR_DELEGATE_ANDROID = 69,
  129. GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID = 70,
  130. OFFLINE_PAGE_INFOBAR_DELEGATE_ANDROID = 71,
  131. SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE_ANDROID = 72,
  132. AUTOMATION_INFOBAR_DELEGATE = 73,
  133. // Removed: VR_SERVICES_UPGRADE_ANDROID = 74,
  134. READER_MODE_INFOBAR_ANDROID = 75,
  135. VR_FEEDBACK_INFOBAR_ANDROID = 76,
  136. // Removed: FRAMEBUST_BLOCK_INFOBAR_ANDROID = 77,
  137. SURVEY_INFOBAR_ANDROID = 78,
  138. NEAR_OOM_INFOBAR_ANDROID = 79,
  139. INSTALLABLE_AMBIENT_BADGE_INFOBAR_DELEGATE = 80,
  140. // Removed: PAGE_LOAD_CAPPING_INFOBAR_DELEGATE = 81,
  141. DOWNLOAD_PROGRESS_INFOBAR_ANDROID = 82,
  142. // Removed: AR_CORE_UPGRADE_ANDROID = 83,
  143. BLOATED_RENDERER_INFOBAR_DELEGATE = 84,
  144. // Removed: SUPERVISED_USERS_DEPRECATED_INFOBAR_DELEGATE = 85,
  145. NEAR_OOM_REDUCTION_INFOBAR_ANDROID = 86,
  146. // Removed: LITE_PAGE_PREVIEWS_INFOBAR = 87,
  147. // Removed: MODULE_INSTALL_FAILURE_INFOBAR_ANDROID = 88,
  148. // Removed: INLINE_UPDATE_READY_INFOBAR_ANDROID = 89,
  149. // Removed: INLINE_UPDATE_FAILED_INFOBAR_ANDROID = 90,
  150. // Removed: FLASH_DEPRECATION_INFOBAR_DELEGATE = 91,
  151. SEND_TAB_TO_SELF_INFOBAR_DELEGATE = 92,
  152. TAB_SHARING_INFOBAR_DELEGATE = 93,
  153. SAFETY_TIP_INFOBAR_DELEGATE = 94,
  154. WEBOTP_SERVICE_INFOBAR_DELEGATE = 95,
  155. KNOWN_INTERCEPTION_DISCLOSURE_INFOBAR_DELEGATE = 96,
  156. SYNC_ERROR_INFOBAR_DELEGATE_ANDROID = 97,
  157. MIXED_CONTENT_DOWNLOAD_INFOBAR_DELEGATE_ANDROID = 98,
  158. // Removed: CONDITIONAL_TAB_STRIP_INFOBAR_ANDROID = 99,
  159. // Removed: LITE_MODE_HTTPS_IMAGE_COMPRESSION_INFOBAR_ANDROID = 100,
  160. // Removed: SYSTEM_INFOBAR_DELEGATE_MAC = 101,
  161. EXPERIMENTAL_INFOBAR_DELEGATE_LACROS = 102,
  162. // Removed: ROSETTA_REQUIRED_INFOBAR_DELEGATE = 103,
  163. // Removed: WEBID_PERMISSION_INFOBAR_DELEGATE = 104,
  164. AUTOFILL_OFFER_NOTIFICATION_INFOBAR_DELEGATE = 105,
  165. AUTOFILL_ADDRESS_PROFILE_INFOBAR_DELEGATE_IOS = 106,
  166. ADD_TO_READING_LIST_IOS = 107,
  167. IOS_PERMISSIONS_INFOBAR_DELEGATE = 108,
  168. SUPPORTED_LINKS_INFOBAR_DELEGATE_CHROMEOS = 109,
  169. AUTOFILL_VIRTUAL_CARD_ENROLLMENT_INFOBAR_DELEGATE_MOBILE = 110,
  170. };
  171. // Describes navigation events, used to decide whether infobars should be
  172. // dismissed.
  173. struct NavigationDetails {
  174. // Unique identifier for the entry.
  175. int entry_id;
  176. // True if it is a navigation to a different page (as opposed to in-page).
  177. bool is_navigation_to_different_page;
  178. // True if the entry replaced the existing one.
  179. bool did_replace_entry;
  180. bool is_reload;
  181. bool is_redirect;
  182. // True if the navigation was caused by a form submission.
  183. bool is_form_submission = false;
  184. };
  185. // Value to use when the InfoBar has no icon to show.
  186. static const int kNoIconID;
  187. InfoBarDelegate(const InfoBarDelegate&) = delete;
  188. InfoBarDelegate& operator=(const InfoBarDelegate&) = delete;
  189. // Called when the InfoBar that owns this delegate is being destroyed. At
  190. // this point nothing is visible onscreen.
  191. virtual ~InfoBarDelegate();
  192. // Returns a unique value identifying the infobar.
  193. // New implementers must append a new value to the InfoBarIdentifier enum here
  194. // and in histograms/enums.xml.
  195. virtual InfoBarIdentifier GetIdentifier() const = 0;
  196. virtual InfoBarAutomationType GetInfoBarAutomationType() const;
  197. // Returns the resource ID of the icon to be shown for this InfoBar. If the
  198. // value is equal to |kNoIconID|, GetIcon() will not show an icon by default.
  199. virtual int GetIconId() const;
  200. // Returns the vector icon identifier to be shown for this InfoBar. This will
  201. // take precedence over GetIconId() (although typically only one of the two
  202. // should be defined for any given infobar).
  203. virtual const gfx::VectorIcon& GetVectorIcon() const;
  204. // Returns the icon to be shown for this InfoBar. If the returned Image is
  205. // empty, no icon is shown.
  206. //
  207. // Most subclasses should not override this; override GetIconId() instead
  208. // unless the infobar needs to show an image from somewhere other than the
  209. // resource bundle as its icon.
  210. virtual ui::ImageModel GetIcon() const;
  211. // Returns the text of the link to be displayed, if any. Otherwise returns
  212. // an empty string.
  213. virtual std::u16string GetLinkText() const;
  214. // Returns the URL the link should navigate to.
  215. virtual GURL GetLinkURL() const;
  216. // Returns true if the supplied |delegate| is equal to this one. Equality is
  217. // left to the implementation to define. This function is called by the
  218. // InfoBarManager when determining whether or not a delegate should be
  219. // added because a matching one already exists. If this function returns true,
  220. // the InfoBarManager will not add the new delegate because it considers
  221. // one to already be present.
  222. virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
  223. // Returns true if the InfoBar should be closed automatically after the page
  224. // is navigated. By default this returns true if the navigation is to a new
  225. // page (not including reloads). Subclasses wishing to change this behavior
  226. // can override this function.
  227. virtual bool ShouldExpire(const NavigationDetails& details) const;
  228. // Called when the link (if any) is clicked; if this function returns true,
  229. // the infobar is then immediately closed. The default implementation opens
  230. // the URL returned by GetLinkURL(), above, and returns false. Subclasses MUST
  231. // NOT return true if in handling this call something triggers the infobar to
  232. // begin closing.
  233. //
  234. // The |disposition| specifies how the resulting document should be loaded
  235. // (based on the event flags present when the link was clicked).
  236. virtual bool LinkClicked(WindowOpenDisposition disposition);
  237. // Called when the user clicks on the close button to dismiss the infobar.
  238. virtual void InfoBarDismissed();
  239. // Returns true if the InfoBar has a close button; true by default.
  240. virtual bool IsCloseable() const;
  241. // Returns true if the InfoBar should animate when showing or hiding; true by
  242. // default.
  243. virtual bool ShouldAnimate() const;
  244. // Type-checking downcast routines:
  245. virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
  246. virtual HungRendererInfoBarDelegate* AsHungRendererInfoBarDelegate();
  247. virtual blocked_content::PopupBlockedInfoBarDelegate*
  248. AsPopupBlockedInfoBarDelegate();
  249. virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
  250. virtual translate::TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
  251. #if BUILDFLAG(IS_ANDROID)
  252. virtual offline_pages::OfflinePageInfoBarDelegate*
  253. AsOfflinePageInfoBarDelegate();
  254. #endif
  255. void set_infobar(InfoBar* infobar) { infobar_ = infobar; }
  256. void set_nav_entry_id(int nav_entry_id) { nav_entry_id_ = nav_entry_id; }
  257. protected:
  258. InfoBarDelegate();
  259. InfoBar* infobar() { return infobar_; }
  260. private:
  261. // The InfoBar associated with us.
  262. raw_ptr<InfoBar> infobar_ = nullptr;
  263. // The ID of the active navigation entry at the time we became owned.
  264. int nav_entry_id_ = 0;
  265. };
  266. } // namespace infobars
  267. #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_