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. 4 5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_ 6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/strings/string16.h" 10 #include "ui/base/window_open_disposition.h" 11 12 class AutoLoginInfoBarDelegate; 13 class ConfirmInfoBarDelegate; 14 class ExtensionInfoBarDelegate; 15 class InsecureContentInfoBarDelegate; 16 class MediaStreamInfoBarDelegate; 17 class PopupBlockedInfoBarDelegate; 18 class RegisterProtocolHandlerInfoBarDelegate; 19 class ScreenCaptureInfoBarDelegate; 20 class ThemeInstalledInfoBarDelegate; 21 class ThreeDAPIInfoBarDelegate; 22 23 namespace translate { 24 class TranslateInfoBarDelegate; 25 } 26 27 namespace gfx { 28 class Image; 29 } 30 31 namespace infobars { 32 33 class InfoBar; 34 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, 47 }; 48 49 enum InfoBarAutomationType { 50 CONFIRM_INFOBAR, 51 PASSWORD_INFOBAR, 52 RPH_INFOBAR, 53 UNKNOWN_INFOBAR, 54 }; 55 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; 69 }; 70 71 // Value to use when the InfoBar has no icon to show. 72 static const int kNoIconID; 73 74 // Called when the InfoBar that owns this delegate is being destroyed. At 75 // this point nothing is visible onscreen. 76 virtual ~InfoBarDelegate(); 77 78 virtual InfoBarAutomationType GetInfoBarAutomationType() const; 79 80 // Returns true if the supplied |delegate| is equal to this one. Equality is 81 // left to the implementation to define. This function is called by the 82 // InfoBarManager when determining whether or not a delegate should be 83 // added because a matching one already exists. If this function returns true, 84 // the InfoBarManager will not add the new delegate because it considers 85 // one to already be present. 86 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; 87 88 // Returns true if the InfoBar should be closed automatically after the page 89 // is navigated. By default this returns true if the navigation is to a new 90 // page (not including reloads). Subclasses wishing to change this behavior 91 // can override either this function or ShouldExpireInternal(), depending on 92 // what level of control they need. 93 virtual bool ShouldExpire(const NavigationDetails& details) const; 94 95 // Called when the user clicks on the close button to dismiss the infobar. 96 virtual void InfoBarDismissed(); 97 98 // Return the resource ID of the icon to be shown for this InfoBar. If the 99 // value is equal to |kNoIconID|, no icon is shown. 100 virtual int GetIconID() const; 101 102 // Returns the type of the infobar. The type determines the appearance (such 103 // as background color) of the infobar. 104 virtual Type GetInfoBarType() const; 105 106 // Type-checking downcast routines: 107 virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate(); 108 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); 109 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); 110 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate(); 111 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate(); 112 virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate(); 113 virtual RegisterProtocolHandlerInfoBarDelegate* 114 AsRegisterProtocolHandlerInfoBarDelegate(); 115 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate(); 116 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); 117 virtual translate::TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); 118 set_infobar(InfoBar * infobar)119 void set_infobar(InfoBar* infobar) { infobar_ = infobar; } 120 121 // Store the unique id for the active entry, to be used later upon navigation 122 // to determine if this InfoBarDelegate should be expired. 123 void StoreActiveEntryUniqueID(); 124 125 // Return the icon to be shown for this InfoBar. If the returned Image is 126 // empty, no icon is shown. 127 virtual gfx::Image GetIcon() const; 128 129 protected: 130 InfoBarDelegate(); 131 132 // Returns true if the navigation is to a new URL or a reload occured. 133 virtual bool ShouldExpireInternal(const NavigationDetails& details) const; 134 contents_unique_id()135 int contents_unique_id() const { return contents_unique_id_; } infobar()136 InfoBar* infobar() { return infobar_; } 137 138 private: 139 // The unique id of the active NavigationEntry of the WebContents that we were 140 // opened for. Used to help expire on navigations. 141 int contents_unique_id_; 142 143 // The InfoBar associated with us. 144 InfoBar* infobar_; 145 146 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); 147 }; 148 149 } // namespace infobars 150 151 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_ 152