| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ | |
| 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/string16.h" | |
| 10 #include "webkit/glue/window_open_disposition.h" | |
| 11 | |
| 12 class AutoLoginInfoBarDelegate; | |
| 13 class ConfirmInfoBarDelegate; | |
| 14 class ExtensionInfoBarDelegate; | |
| 15 class InfoBar; | |
| 16 class InfoBarTabHelper; | |
| 17 class InsecureContentInfoBarDelegate; | |
| 18 class LinkInfoBarDelegate; | |
| 19 class MediaStreamInfoBarDelegate; | |
| 20 class PluginInstallerInfoBarDelegate; | |
| 21 class RegisterProtocolHandlerInfoBarDelegate; | |
| 22 class SavePasswordInfoBarDelegate; | |
| 23 class ThemeInstalledInfoBarDelegate; | |
| 24 class TranslateInfoBarDelegate; | |
| 25 | |
| 26 namespace gfx { | |
| 27 class Image; | |
| 28 } | |
| 29 namespace content { | |
| 30 struct LoadCommittedDetails; | |
| 31 } | |
| 32 | |
| 33 // An interface implemented by objects wishing to control an InfoBar. | |
| 34 // Implementing this interface is not sufficient to use an InfoBar, since it | |
| 35 // does not map to a specific InfoBar type. Instead, you must implement either | |
| 36 // LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own | |
| 37 // delegate for your own InfoBar variety. | |
| 38 class InfoBarDelegate { | |
| 39 public: | |
| 40 // The type of the infobar. It controls its appearance, such as its background | |
| 41 // color. | |
| 42 enum Type { | |
| 43 WARNING_TYPE, | |
| 44 PAGE_ACTION_TYPE, | |
| 45 }; | |
| 46 | |
| 47 enum InfoBarAutomationType { | |
| 48 CONFIRM_INFOBAR, | |
| 49 ONE_CLICK_LOGIN_INFOBAR, | |
| 50 PASSWORD_INFOBAR, | |
| 51 RPH_INFOBAR, | |
| 52 UNKNOWN_INFOBAR, | |
| 53 }; | |
| 54 | |
| 55 virtual ~InfoBarDelegate(); | |
| 56 | |
| 57 virtual InfoBarAutomationType GetInfoBarAutomationType() const; | |
| 58 | |
| 59 // Called to create the InfoBar. Implementation of this method is | |
| 60 // platform-specific. | |
| 61 virtual InfoBar* CreateInfoBar(InfoBarTabHelper* owner) = 0; | |
| 62 | |
| 63 // Called by the InfoBarTabHelper when it removes us. | |
| 64 void clear_owner() { owner_ = NULL; } | |
| 65 | |
| 66 // TODO(pkasting): Move to InfoBar once InfoBars own their delegates. | |
| 67 InfoBarTabHelper* owner() { return owner_; } | |
| 68 | |
| 69 // Returns true if the supplied |delegate| is equal to this one. Equality is | |
| 70 // left to the implementation to define. This function is called by the | |
| 71 // InfoBarTabHelper when determining whether or not a delegate should be | |
| 72 // added because a matching one already exists. If this function returns true, | |
| 73 // the InfoBarTabHelper will not add the new delegate because it considers | |
| 74 // one to already be present. | |
| 75 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; | |
| 76 | |
| 77 // Returns true if the InfoBar should be closed automatically after the page | |
| 78 // is navigated. By default this returns true if the navigation is to a new | |
| 79 // page (not including reloads). Subclasses wishing to change this behavior | |
| 80 // can override either this function or ShouldExpireInternal(), depending on | |
| 81 // what level of control they need. | |
| 82 virtual bool ShouldExpire(const content::LoadCommittedDetails& details) const; | |
| 83 | |
| 84 // Called when the user clicks on the close button to dismiss the infobar. | |
| 85 virtual void InfoBarDismissed(); | |
| 86 | |
| 87 // Called after the InfoBar is closed. Deletes |this|. | |
| 88 // TODO(pkasting): Get rid of this and delete delegates directly. | |
| 89 void InfoBarClosed(); | |
| 90 | |
| 91 // Return the icon to be shown for this InfoBar. If the returned Image is | |
| 92 // NULL, no icon is shown. | |
| 93 virtual gfx::Image* GetIcon() const; | |
| 94 | |
| 95 // Returns the type of the infobar. The type determines the appearance (such | |
| 96 // as background color) of the infobar. | |
| 97 virtual Type GetInfoBarType() const; | |
| 98 | |
| 99 // Type-checking downcast routines: | |
| 100 virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate(); | |
| 101 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); | |
| 102 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); | |
| 103 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate(); | |
| 104 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); | |
| 105 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate(); | |
| 106 virtual RegisterProtocolHandlerInfoBarDelegate* | |
| 107 AsRegisterProtocolHandlerInfoBarDelegate(); | |
| 108 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); | |
| 109 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); | |
| 110 | |
| 111 protected: | |
| 112 // If |contents| is non-NULL, its active entry's unique ID will be stored | |
| 113 // using StoreActiveEntryUniqueID automatically. | |
| 114 explicit InfoBarDelegate(InfoBarTabHelper* infobar_helper); | |
| 115 | |
| 116 // Store the unique id for the active entry in the specified WebContents, to | |
| 117 // be used later upon navigation to determine if this InfoBarDelegate should | |
| 118 // be expired from |contents_|. | |
| 119 void StoreActiveEntryUniqueID(InfoBarTabHelper* infobar_helper); | |
| 120 | |
| 121 // Direct accessors for subclasses that need to do something special. | |
| 122 int contents_unique_id() const { return contents_unique_id_; } | |
| 123 void set_contents_unique_id(int contents_unique_id) { | |
| 124 contents_unique_id_ = contents_unique_id; | |
| 125 } | |
| 126 | |
| 127 // Returns true if the navigation is to a new URL or a reload occured. | |
| 128 virtual bool ShouldExpireInternal( | |
| 129 const content::LoadCommittedDetails& details) const; | |
| 130 | |
| 131 // Removes ourself from |owner_| if we haven't already been removed. | |
| 132 // TODO(pkasting): Move to InfoBar. | |
| 133 void RemoveSelf(); | |
| 134 | |
| 135 private: | |
| 136 // The unique id of the active NavigationEntry of the WebContents that we were | |
| 137 // opened for. Used to help expire on navigations. | |
| 138 int contents_unique_id_; | |
| 139 | |
| 140 // TODO(pkasting): Remove. | |
| 141 InfoBarTabHelper* owner_; | |
| 142 | |
| 143 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); | |
| 144 }; | |
| 145 | |
| 146 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ | |
| OLD | NEW |