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 ExtensionInfoBarDelegate
;
15 class InsecureContentInfoBarDelegate
;
16 class MediaStreamInfoBarDelegate
;
17 class NativeAppInfoBarDelegate
;
18 class PopupBlockedInfoBarDelegate
;
19 class RegisterProtocolHandlerInfoBarDelegate
;
20 class ScreenCaptureInfoBarDelegate
;
21 class ThemeInstalledInfoBarDelegate
;
22 class ThreeDAPIInfoBarDelegate
;
25 class TranslateInfoBarDelegate
;
36 // An interface implemented by objects wishing to control an InfoBar.
37 // Implementing this interface is not sufficient to use an InfoBar, since it
38 // does not map to a specific InfoBar type. Instead, you must implement
39 // ConfirmInfoBarDelegate, or override with your own delegate for your own
41 class InfoBarDelegate
{
43 // The type of the infobar. It controls its appearance, such as its background
50 enum InfoBarAutomationType
{
57 // Describes navigation events, used to decide whether infobars should be
59 struct NavigationDetails
{
60 // Unique identifier for the entry.
62 // True if it is a navigation to a different page (as opposed to in-page).
63 bool is_navigation_to_different_page
;
64 // True if the entry replaced the existing one.
65 bool did_replace_entry
;
66 // True for the main frame, false for a sub-frame.
72 // Value to use when the InfoBar has no icon to show.
73 static const int kNoIconID
;
75 // Called when the InfoBar that owns this delegate is being destroyed. At
76 // this point nothing is visible onscreen.
77 virtual ~InfoBarDelegate();
79 virtual InfoBarAutomationType
GetInfoBarAutomationType() const;
81 // Returns true if the supplied |delegate| is equal to this one. Equality is
82 // left to the implementation to define. This function is called by the
83 // InfoBarManager when determining whether or not a delegate should be
84 // added because a matching one already exists. If this function returns true,
85 // the InfoBarManager will not add the new delegate because it considers
86 // one to already be present.
87 virtual bool EqualsDelegate(InfoBarDelegate
* delegate
) const;
89 // Returns true if the InfoBar should be closed automatically after the page
90 // is navigated. By default this returns true if the navigation is to a new
91 // page (not including reloads). Subclasses wishing to change this behavior
92 // can override either this function or ShouldExpireInternal(), depending on
93 // what level of control they need.
94 virtual bool ShouldExpire(const NavigationDetails
& details
) const;
96 // Called when the user clicks on the close button to dismiss the infobar.
97 virtual void InfoBarDismissed();
99 // Return the resource ID of the icon to be shown for this InfoBar. If the
100 // value is equal to |kNoIconID|, no icon is shown.
101 virtual int GetIconID() const;
103 // Returns the type of the infobar. The type determines the appearance (such
104 // as background color) of the infobar.
105 virtual Type
GetInfoBarType() const;
107 // Type-checking downcast routines:
108 virtual AutoLoginInfoBarDelegate
* AsAutoLoginInfoBarDelegate();
109 virtual ConfirmInfoBarDelegate
* AsConfirmInfoBarDelegate();
110 virtual ExtensionInfoBarDelegate
* AsExtensionInfoBarDelegate();
111 virtual InsecureContentInfoBarDelegate
* AsInsecureContentInfoBarDelegate();
112 virtual MediaStreamInfoBarDelegate
* AsMediaStreamInfoBarDelegate();
113 virtual NativeAppInfoBarDelegate
* AsNativeAppInfoBarDelegate();
114 virtual PopupBlockedInfoBarDelegate
* AsPopupBlockedInfoBarDelegate();
115 virtual RegisterProtocolHandlerInfoBarDelegate
*
116 AsRegisterProtocolHandlerInfoBarDelegate();
117 virtual ScreenCaptureInfoBarDelegate
* AsScreenCaptureInfoBarDelegate();
118 virtual ThemeInstalledInfoBarDelegate
* AsThemePreviewInfobarDelegate();
119 virtual translate::TranslateInfoBarDelegate
* AsTranslateInfoBarDelegate();
121 void set_infobar(InfoBar
* infobar
) { infobar_
= infobar
; }
123 // Store the unique id for the active entry, to be used later upon navigation
124 // to determine if this InfoBarDelegate should be expired.
125 void StoreActiveEntryUniqueID();
127 // Return the icon to be shown for this InfoBar. If the returned Image is
128 // empty, no icon is shown.
129 virtual gfx::Image
GetIcon() const;
134 // Returns true if the navigation is to a new URL or a reload occured.
135 virtual bool ShouldExpireInternal(const NavigationDetails
& details
) const;
137 int contents_unique_id() const { return contents_unique_id_
; }
138 InfoBar
* infobar() { return infobar_
; }
141 // The unique id of the active NavigationEntry of the WebContents that we were
142 // opened for. Used to help expire on navigations.
143 int contents_unique_id_
;
145 // The InfoBar associated with us.
148 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate
);
151 } // namespace infobars
153 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_