Fix build break
[chromium-blink-merge.git] / chrome / browser / infobars / infobar_delegate.h
blobabe03a746668a859cddae180bcd5d8f64a1cb038
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.
5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
8 #include "base/basictypes.h"
9 #include "base/string16.h"
10 #include "ui/base/window_open_disposition.h"
12 class AlternateNavInfoBarDelegate;
13 class AutoLoginInfoBarDelegate;
14 class ConfirmInfoBarDelegate;
15 class ExtensionInfoBarDelegate;
16 class InfoBar;
17 class InfoBarService;
18 class InsecureContentInfoBarDelegate;
19 class MediaStreamInfoBarDelegate;
20 class PluginInstallerInfoBarDelegate;
21 class RegisterProtocolHandlerInfoBarDelegate;
22 class SavePasswordInfoBarDelegate;
23 class ScreenCaptureInfoBarDelegate;
24 class ThemeInstalledInfoBarDelegate;
25 class ThreeDAPIInfoBarDelegate;
26 class TranslateInfoBarDelegate;
28 namespace gfx {
29 class Image;
31 namespace content {
32 struct LoadCommittedDetails;
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 ONE_CLICK_LOGIN_INFOBAR,
52 PASSWORD_INFOBAR,
53 RPH_INFOBAR,
54 UNKNOWN_INFOBAR,
57 virtual ~InfoBarDelegate();
59 virtual InfoBarAutomationType GetInfoBarAutomationType() const;
61 // Called to create the InfoBar. Implementation of this method is
62 // platform-specific.
63 virtual InfoBar* CreateInfoBar(InfoBarService* owner) = 0;
65 // TODO(pkasting): Move to InfoBar once InfoBars own their delegates.
66 InfoBarService* owner() { return owner_; }
68 void clear_owner() { owner_ = NULL; }
70 // Returns true if the supplied |delegate| is equal to this one. Equality is
71 // left to the implementation to define. This function is called by the
72 // InfoBarService when determining whether or not a delegate should be
73 // added because a matching one already exists. If this function returns true,
74 // the InfoBarService will not add the new delegate because it considers
75 // one to already be present.
76 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
78 // Returns true if the InfoBar should be closed automatically after the page
79 // is navigated. By default this returns true if the navigation is to a new
80 // page (not including reloads). Subclasses wishing to change this behavior
81 // can override either this function or ShouldExpireInternal(), depending on
82 // what level of control they need.
83 virtual bool ShouldExpire(const content::LoadCommittedDetails& details) const;
85 // Called when the user clicks on the close button to dismiss the infobar.
86 virtual void InfoBarDismissed();
88 // Return the icon to be shown for this InfoBar. If the returned Image is
89 // NULL, no icon is shown.
90 virtual gfx::Image* GetIcon() const;
92 // Returns the type of the infobar. The type determines the appearance (such
93 // as background color) of the infobar.
94 virtual Type GetInfoBarType() const;
96 // Type-checking downcast routines:
97 virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate();
98 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
99 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
100 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
101 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
102 virtual RegisterProtocolHandlerInfoBarDelegate*
103 AsRegisterProtocolHandlerInfoBarDelegate();
104 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate();
105 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
106 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate();
107 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
109 protected:
110 // If |contents| is non-NULL, its active entry's unique ID will be stored
111 // using StoreActiveEntryUniqueID automatically.
112 explicit InfoBarDelegate(InfoBarService* infobar_service);
114 // Store the unique id for the active entry in our WebContents, to be used
115 // later upon navigation to determine if this InfoBarDelegate should be
116 // expired.
117 void StoreActiveEntryUniqueID();
119 int contents_unique_id() const { return contents_unique_id_; }
121 // Returns true if the navigation is to a new URL or a reload occured.
122 virtual bool ShouldExpireInternal(
123 const content::LoadCommittedDetails& details) const;
125 // Removes ourself from |owner_| if we haven't already been removed.
126 // TODO(pkasting): Move to InfoBar.
127 void RemoveSelf();
129 private:
130 // The unique id of the active NavigationEntry of the WebContents that we were
131 // opened for. Used to help expire on navigations.
132 int contents_unique_id_;
134 // TODO(pkasting): Remove.
135 InfoBarService* owner_;
137 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
140 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_