OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 6 #define CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "chrome/browser/tab_contents/navigation_controller.h" | 11 #include "content/browser/tab_contents/navigation_controller.h" |
12 #include "webkit/glue/window_open_disposition.h" | 12 #include "webkit/glue/window_open_disposition.h" |
13 | 13 |
14 class ConfirmInfoBarDelegate; | 14 class ConfirmInfoBarDelegate; |
15 class CrashedExtensionInfoBarDelegate; | 15 class CrashedExtensionInfoBarDelegate; |
16 class ExtensionInfoBarDelegate; | 16 class ExtensionInfoBarDelegate; |
17 class InfoBar; | 17 class InfoBar; |
18 class LinkInfoBarDelegate; | 18 class LinkInfoBarDelegate; |
19 class PluginInstallerInfoBarDelegate; | 19 class PluginInstallerInfoBarDelegate; |
20 class SkBitmap; | 20 class SkBitmap; |
21 class ThemeInstalledInfoBarDelegate; | 21 class ThemeInstalledInfoBarDelegate; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void StoreActiveEntryUniqueID(TabContents* contents); | 108 void StoreActiveEntryUniqueID(TabContents* contents); |
109 | 109 |
110 private: | 110 private: |
111 // The unique id of the active NavigationEntry of the TabContents that we were | 111 // The unique id of the active NavigationEntry of the TabContents that we were |
112 // opened for. Used to help expire on navigations. | 112 // opened for. Used to help expire on navigations. |
113 int contents_unique_id_; | 113 int contents_unique_id_; |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); | 115 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); |
116 }; | 116 }; |
117 | 117 |
118 // An interface derived from InfoBarDelegate implemented by objects wishing to | 118 #endif // CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
119 // control a LinkInfoBar. | |
120 class LinkInfoBarDelegate : public InfoBarDelegate { | |
121 public: | |
122 // Returns the message string to be displayed in the InfoBar. |link_offset| | |
123 // is the position where the link should be inserted. If |link_offset| is set | |
124 // to string16::npos (it is by default), the link is right aligned within | |
125 // the InfoBar rather than being embedded in the message text. | |
126 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; | |
127 | |
128 // Returns the text of the link to be displayed. | |
129 virtual string16 GetLinkText() const = 0; | |
130 | |
131 // Called when the Link is clicked. The |disposition| specifies how the | |
132 // resulting document should be loaded (based on the event flags present when | |
133 // the link was clicked). This function returns true if the InfoBar should be | |
134 // closed now or false if it should remain until the user explicitly closes | |
135 // it. | |
136 virtual bool LinkClicked(WindowOpenDisposition disposition); | |
137 | |
138 protected: | |
139 explicit LinkInfoBarDelegate(TabContents* contents); | |
140 virtual ~LinkInfoBarDelegate(); | |
141 | |
142 private: | |
143 // InfoBarDelegate: | |
144 virtual InfoBar* CreateInfoBar(); | |
145 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); | |
146 | |
147 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate); | |
148 }; | |
149 | |
150 // An interface derived from InfoBarDelegate implemented by objects wishing to | |
151 // control a ConfirmInfoBar. | |
152 class ConfirmInfoBarDelegate : public InfoBarDelegate { | |
153 public: | |
154 enum InfoBarButton { | |
155 BUTTON_NONE = 0, | |
156 BUTTON_OK = 1 << 0, | |
157 BUTTON_CANCEL = 1 << 1, | |
158 }; | |
159 | |
160 // Returns the message string to be displayed for the InfoBar. | |
161 virtual string16 GetMessageText() const = 0; | |
162 | |
163 // Return the buttons to be shown for this InfoBar. | |
164 virtual int GetButtons() const; | |
165 | |
166 // Return the label for the specified button. The default implementation | |
167 // returns "OK" for the OK button and "Cancel" for the Cancel button. | |
168 virtual string16 GetButtonLabel(InfoBarButton button) const; | |
169 | |
170 // Return whether or not the specified button needs elevation. | |
171 virtual bool NeedElevation(InfoBarButton button) const; | |
172 | |
173 // Called when the OK button is pressed. If the function returns true, the | |
174 // InfoBarDelegate should be removed from the associated TabContents. | |
175 virtual bool Accept(); | |
176 | |
177 // Called when the Cancel button is pressed. If the function returns true, | |
178 // the InfoBarDelegate should be removed from the associated TabContents. | |
179 virtual bool Cancel(); | |
180 | |
181 // Returns the text of the link to be displayed, if any. Otherwise returns | |
182 // and empty string. | |
183 virtual string16 GetLinkText(); | |
184 | |
185 // Called when the Link is clicked. The |disposition| specifies how the | |
186 // resulting document should be loaded (based on the event flags present when | |
187 // the link was clicked). This function returns true if the InfoBar should be | |
188 // closed now or false if it should remain until the user explicitly closes | |
189 // it. | |
190 // Will only be called if GetLinkText() returns non-empty string. | |
191 virtual bool LinkClicked(WindowOpenDisposition disposition); | |
192 | |
193 protected: | |
194 explicit ConfirmInfoBarDelegate(TabContents* contents); | |
195 virtual ~ConfirmInfoBarDelegate(); | |
196 | |
197 private: | |
198 // InfoBarDelegate: | |
199 virtual InfoBar* CreateInfoBar(); | |
200 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; | |
201 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); | |
202 | |
203 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate); | |
204 }; | |
205 | |
206 // Simple implementations for common use cases --------------------------------- | |
207 | |
208 class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate { | |
209 public: | |
210 SimpleAlertInfoBarDelegate(TabContents* contents, | |
211 SkBitmap* icon, // May be NULL. | |
212 const string16& message, | |
213 bool auto_expire); | |
214 | |
215 private: | |
216 virtual ~SimpleAlertInfoBarDelegate(); | |
217 | |
218 // ConfirmInfoBarDelegate: | |
219 virtual bool ShouldExpire( | |
220 const NavigationController::LoadCommittedDetails& details) const; | |
221 virtual void InfoBarClosed(); | |
222 virtual SkBitmap* GetIcon() const; | |
223 virtual string16 GetMessageText() const; | |
224 virtual int GetButtons() const; | |
225 | |
226 SkBitmap* icon_; | |
227 string16 message_; | |
228 bool auto_expire_; // Should it expire automatically on navigation? | |
229 | |
230 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); | |
231 }; | |
232 | |
233 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | |
OLD | NEW |