Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / infobars / core / infobar_delegate.h
blobbd7455f02198511f521ebff61d928b1ad4a6a0f7
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 AutoLoginInfoBarDelegate;
13 class ConfirmInfoBarDelegate;
14 class InsecureContentInfoBarDelegate;
15 class MediaStreamInfoBarDelegate;
16 class NativeAppInfoBarDelegate;
17 class PopupBlockedInfoBarDelegate;
18 class RegisterProtocolHandlerInfoBarDelegate;
19 class ScreenCaptureInfoBarDelegate;
20 class ThemeInstalledInfoBarDelegate;
21 class ThreeDAPIInfoBarDelegate;
23 namespace translate {
24 class TranslateInfoBarDelegate;
27 namespace gfx {
28 class Image;
31 namespace infobars {
33 class InfoBar;
35 // An interface implemented by objects wishing to control an InfoBar.
36 // Implementing this interface is not sufficient to use an InfoBar, since it
37 // does not map to a specific InfoBar type. Instead, you must implement
38 // ConfirmInfoBarDelegate, or override with your own delegate for your own
39 // InfoBar variety.
40 class InfoBarDelegate {
41 public:
42 // The type of the infobar. It controls its appearance, such as its background
43 // color.
44 enum Type {
45 WARNING_TYPE,
46 PAGE_ACTION_TYPE,
49 enum InfoBarAutomationType {
50 CONFIRM_INFOBAR,
51 PASSWORD_INFOBAR,
52 RPH_INFOBAR,
53 UNKNOWN_INFOBAR,
56 // Describes navigation events, used to decide whether infobars should be
57 // dismissed.
58 struct NavigationDetails {
59 // Unique identifier for the entry.
60 int entry_id;
61 // True if it is a navigation to a different page (as opposed to in-page).
62 bool is_navigation_to_different_page;
63 // True if the entry replaced the existing one.
64 bool did_replace_entry;
65 // True for the main frame, false for a sub-frame.
66 bool is_main_frame;
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 icon to be shown for this InfoBar. If the returned Image is
89 // empty, no icon is shown.
91 // Most subclasses should not override this; override GetIconID() instead
92 // unless the infobar needs to show an image from somewhere other than the
93 // resource bundle as its icon.
94 virtual gfx::Image GetIcon() const;
96 // Returns true if the supplied |delegate| is equal to this one. Equality is
97 // left to the implementation to define. This function is called by the
98 // InfoBarManager when determining whether or not a delegate should be
99 // added because a matching one already exists. If this function returns true,
100 // the InfoBarManager will not add the new delegate because it considers
101 // one to already be present.
102 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
104 // Returns true if the InfoBar should be closed automatically after the page
105 // is navigated. By default this returns true if the navigation is to a new
106 // page (not including reloads). Subclasses wishing to change this behavior
107 // can override either this function or ShouldExpireInternal(), depending on
108 // what level of control they need.
109 virtual bool ShouldExpire(const NavigationDetails& details) const;
111 // Called when the user clicks on the close button to dismiss the infobar.
112 virtual void InfoBarDismissed();
114 // Type-checking downcast routines:
115 virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate();
116 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
117 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
118 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
119 virtual NativeAppInfoBarDelegate* AsNativeAppInfoBarDelegate();
120 virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate();
121 virtual RegisterProtocolHandlerInfoBarDelegate*
122 AsRegisterProtocolHandlerInfoBarDelegate();
123 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate();
124 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
125 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate();
126 virtual translate::TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
128 void set_infobar(InfoBar* infobar) { infobar_ = infobar; }
130 // Store the unique id for the active entry, to be used later upon navigation
131 // to determine if this InfoBarDelegate should be expired.
132 void StoreActiveEntryUniqueID();
134 protected:
135 InfoBarDelegate();
137 // Returns true if the navigation is to a new URL or a reload occured.
138 virtual bool ShouldExpireInternal(const NavigationDetails& details) const;
140 int contents_unique_id() const { return contents_unique_id_; }
141 InfoBar* infobar() { return infobar_; }
143 private:
144 // The unique id of the active NavigationEntry of the WebContents that we were
145 // opened for. Used to help expire on navigations.
146 int contents_unique_id_;
148 // The InfoBar associated with us.
149 InfoBar* infobar_;
151 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
154 } // namespace infobars
156 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_