Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / infobars / core / infobar_delegate.h
blob9d6ba770d2a7fddc1d22cc68b39d3e8a03602830
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.
5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
8 #include "base/basictypes.h"
9 #include "base/strings/string16.h"
10 #include "ui/base/window_open_disposition.h"
12 class ConfirmInfoBarDelegate;
13 class HungRendererInfoBarDelegate;
14 class InsecureContentInfoBarDelegate;
15 class MediaStreamInfoBarDelegate;
16 class NativeAppInfoBarDelegate;
17 class PermissionInfobarDelegate;
18 class PopupBlockedInfoBarDelegate;
19 class RegisterProtocolHandlerInfoBarDelegate;
20 class ScreenCaptureInfoBarDelegate;
21 class ThemeInstalledInfoBarDelegate;
22 class ThreeDAPIInfoBarDelegate;
24 namespace translate {
25 class TranslateInfoBarDelegate;
28 namespace gfx {
29 class Image;
30 enum class VectorIconId;
33 namespace infobars {
35 class InfoBar;
37 // An interface implemented by objects wishing to control an InfoBar.
38 // Implementing this interface is not sufficient to use an InfoBar, since it
39 // does not map to a specific InfoBar type. Instead, you must implement
40 // ConfirmInfoBarDelegate, or override with your own delegate for your own
41 // InfoBar variety.
42 class InfoBarDelegate {
43 public:
44 // The type of the infobar. It controls its appearance, such as its background
45 // color.
46 enum Type {
47 WARNING_TYPE,
48 PAGE_ACTION_TYPE,
51 enum InfoBarAutomationType {
52 CONFIRM_INFOBAR,
53 PASSWORD_INFOBAR,
54 RPH_INFOBAR,
55 UNKNOWN_INFOBAR,
58 // Describes navigation events, used to decide whether infobars should be
59 // dismissed.
60 struct NavigationDetails {
61 // Unique identifier for the entry.
62 int entry_id;
63 // True if it is a navigation to a different page (as opposed to in-page).
64 bool is_navigation_to_different_page;
65 // True if the entry replaced the existing one.
66 bool did_replace_entry;
67 bool is_reload;
68 bool is_redirect;
71 // Value to use when the InfoBar has no icon to show.
72 static const int kNoIconID;
74 // Called when the InfoBar that owns this delegate is being destroyed. At
75 // this point nothing is visible onscreen.
76 virtual ~InfoBarDelegate();
78 // Returns the type of the infobar. The type determines the appearance (such
79 // as background color) of the infobar.
80 virtual Type GetInfoBarType() const;
82 virtual InfoBarAutomationType GetInfoBarAutomationType() const;
84 // Returns the resource ID of the icon to be shown for this InfoBar. If the
85 // value is equal to |kNoIconID|, GetIcon() will not show an icon by default.
86 virtual int GetIconId() const;
88 // Returns the vector icon identifier to be shown for this InfoBar. This will
89 // take precedent over GetIconId() (although typically only one of the two
90 // should be defined for any given infobar).
91 virtual gfx::VectorIconId GetVectorIconId() const;
93 // Returns the icon to be shown for this InfoBar. If the returned Image is
94 // empty, no icon is shown.
96 // Most subclasses should not override this; override GetIconId() instead
97 // unless the infobar needs to show an image from somewhere other than the
98 // resource bundle as its icon.
99 virtual gfx::Image GetIcon() const;
101 // Returns true if the supplied |delegate| is equal to this one. Equality is
102 // left to the implementation to define. This function is called by the
103 // InfoBarManager when determining whether or not a delegate should be
104 // added because a matching one already exists. If this function returns true,
105 // the InfoBarManager will not add the new delegate because it considers
106 // one to already be present.
107 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
109 // Returns true if the InfoBar should be closed automatically after the page
110 // is navigated. By default this returns true if the navigation is to a new
111 // page (not including reloads). Subclasses wishing to change this behavior
112 // can override either this function or ShouldExpireInternal(), depending on
113 // what level of control they need.
114 virtual bool ShouldExpire(const NavigationDetails& details) const;
116 // Called when the user clicks on the close button to dismiss the infobar.
117 virtual void InfoBarDismissed();
119 // Type-checking downcast routines:
120 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
121 virtual HungRendererInfoBarDelegate* AsHungRendererInfoBarDelegate();
122 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
123 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
124 virtual NativeAppInfoBarDelegate* AsNativeAppInfoBarDelegate();
125 virtual PermissionInfobarDelegate* AsPermissionInfobarDelegate();
126 virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate();
127 virtual RegisterProtocolHandlerInfoBarDelegate*
128 AsRegisterProtocolHandlerInfoBarDelegate();
129 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate();
130 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
131 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate();
132 virtual translate::TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
134 void set_infobar(InfoBar* infobar) { infobar_ = infobar; }
135 void set_nav_entry_id(int nav_entry_id) { nav_entry_id_ = nav_entry_id; }
137 protected:
138 InfoBarDelegate();
140 InfoBar* infobar() { return infobar_; }
142 private:
143 // The InfoBar associated with us.
144 InfoBar* infobar_;
146 // The ID of the active navigation entry at the time we became owned.
147 int nav_entry_id_;
149 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
152 } // namespace infobars
154 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_