Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: chrome/browser/tab_contents/infobar_delegate.h

Issue 6249010: Cleanup: de-inline a bunch of classes, rename and move "PluginInstaller" to "... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ 6 #define CHROME_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 "chrome/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 AlertInfoBarDelegate; 14 class AlertInfoBarDelegate;
15 class ConfirmInfoBarDelegate; 15 class ConfirmInfoBarDelegate;
16 class CrashedExtensionInfoBarDelegate; 16 class CrashedExtensionInfoBarDelegate;
17 class ExtensionInfoBarDelegate; 17 class ExtensionInfoBarDelegate;
18 class TranslateInfoBarDelegate;
19 class InfoBar; 18 class InfoBar;
20 class LinkInfoBarDelegate; 19 class LinkInfoBarDelegate;
21 class SkBitmap; 20 class SkBitmap;
22 class ThemeInstalledInfoBarDelegate; 21 class ThemeInstalledInfoBarDelegate;
22 class TranslateInfoBarDelegate;
23 23
24 // An interface implemented by objects wishing to control an InfoBar. 24 // An interface implemented by objects wishing to control an InfoBar.
25 // Implementing this interface is not sufficient to use an InfoBar, since it 25 // Implementing this interface is not sufficient to use an InfoBar, since it
26 // does not map to a specific InfoBar type. Instead, you must implement either 26 // does not map to a specific InfoBar type. Instead, you must implement either
27 // AlertInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own 27 // AlertInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own
28 // delegate for your own InfoBar variety. 28 // delegate for your own InfoBar variety.
29 // 29 //
30 // --- WARNING --- 30 // --- WARNING ---
31 // When creating your InfoBarDelegate subclass, it is recommended that you 31 // When creating your InfoBarDelegate subclass, it is recommended that you
32 // design it such that you instantiate a brand new delegate for every call to 32 // design it such that you instantiate a brand new delegate for every call to
(...skipping 12 matching lines...) Expand all
45 // AddInfoBar! 45 // AddInfoBar!
46 class InfoBarDelegate { 46 class InfoBarDelegate {
47 public: 47 public:
48 // The type of the infobar. It controls its appearance, such as its background 48 // The type of the infobar. It controls its appearance, such as its background
49 // color. 49 // color.
50 enum Type { 50 enum Type {
51 WARNING_TYPE, 51 WARNING_TYPE,
52 PAGE_ACTION_TYPE, 52 PAGE_ACTION_TYPE,
53 }; 53 };
54 54
55 virtual ~InfoBarDelegate();
56
57 // Called to create the InfoBar. Implementation of this method is
58 // platform-specific.
59 virtual InfoBar* CreateInfoBar() = 0;
60
55 // Returns true if the supplied |delegate| is equal to this one. Equality is 61 // Returns true if the supplied |delegate| is equal to this one. Equality is
56 // left to the implementation to define. This function is called by the 62 // left to the implementation to define. This function is called by the
57 // TabContents when determining whether or not a delegate should be added 63 // TabContents when determining whether or not a delegate should be added
58 // because a matching one already exists. If this function returns true, the 64 // because a matching one already exists. If this function returns true, the
59 // TabContents will not add the new delegate because it considers one to 65 // TabContents will not add the new delegate because it considers one to
60 // already be present. 66 // already be present.
61 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; 67 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
62 68
63 // Returns true if the InfoBar should be closed automatically after the page 69 // Returns true if the InfoBar should be closed automatically after the page
64 // is navigated. The default behavior is to return true if the page is 70 // is navigated. The default behavior is to return true if the page is
65 // navigated somewhere else or reloaded. 71 // navigated somewhere else or reloaded.
66 virtual bool ShouldExpire( 72 virtual bool ShouldExpire(
67 const NavigationController::LoadCommittedDetails& details) const; 73 const NavigationController::LoadCommittedDetails& details) const;
68 74
69 // Called when the user clicks on the close button to dismiss the infobar. 75 // Called when the user clicks on the close button to dismiss the infobar.
70 virtual void InfoBarDismissed() {} 76 virtual void InfoBarDismissed();
71 77
72 // Called after the InfoBar is closed. The delegate is free to delete itself 78 // Called after the InfoBar is closed. The delegate is free to delete itself
73 // at this point. 79 // at this point.
74 virtual void InfoBarClosed() {} 80 virtual void InfoBarClosed();
75
76 // Called to create the InfoBar. Implementation of this method is
77 // platform-specific.
78 virtual InfoBar* CreateInfoBar() = 0;
79 81
80 // Return the icon to be shown for this InfoBar. If the returned bitmap is 82 // Return the icon to be shown for this InfoBar. If the returned bitmap is
81 // NULL, no icon is shown. 83 // NULL, no icon is shown.
82 virtual SkBitmap* GetIcon() const; 84 virtual SkBitmap* GetIcon() const;
83 85
84 // Returns a pointer to the AlertInfoBarDelegate interface, if implemented.
85 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
86
87 // Returns a pointer to the LinkInfoBarDelegate interface, if implemented.
88 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
89
90 // Returns a pointer to the ConfirmInfoBarDelegate interface, if implemented.
91 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
92
93 // Returns a pointer to the ThemeInstalledInfoBarDelegate interface, if
94 // implemented.
95 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
96
97 // Returns a pointer to the TranslateInfoBarDelegate interface, if
98 // implemented.
99 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
100
101 // Returns a pointer to the ExtensionInfoBarDelegate interface, if
102 // implemented.
103 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
104
105 // Returns a pointer to the CrashedExtensionInfoBarDelegate interface, if
106 // implemented.
107 virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate();
108
109 // Returns the type of the infobar. The type determines the appearance (such 86 // Returns the type of the infobar. The type determines the appearance (such
110 // as background color) of the infobar. 87 // as background color) of the infobar.
111 virtual Type GetInfoBarType(); 88 virtual Type GetInfoBarType() const;
89
90 // Type-checking downcast routines:
91 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
92 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
93 virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate();
94 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
95 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
96 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
97 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
112 98
113 protected: 99 protected:
114 // Provided to subclasses as a convenience to initialize the state of this 100 // Provided to subclasses as a convenience to initialize the state of this
115 // object. If |contents| is non-NULL, its active entry's unique ID will be 101 // object. If |contents| is non-NULL, its active entry's unique ID will be
116 // stored using StoreActiveEntryUniqueID automatically. 102 // stored using StoreActiveEntryUniqueID automatically.
117 explicit InfoBarDelegate(TabContents* contents); 103 explicit InfoBarDelegate(TabContents* contents);
118 104
119 virtual ~InfoBarDelegate() { }
120
121 // Store the unique id for the active entry in the specified TabContents, to 105 // Store the unique id for the active entry in the specified TabContents, to
122 // be used later upon navigation to determine if this InfoBarDelegate should 106 // be used later upon navigation to determine if this InfoBarDelegate should
123 // be expired from |contents_|. 107 // be expired from |contents_|.
124 void StoreActiveEntryUniqueID(TabContents* contents); 108 void StoreActiveEntryUniqueID(TabContents* contents);
125 109
126 private: 110 private:
127 // The unique id of the active NavigationEntry of the TabContents taht we were 111 // The unique id of the active NavigationEntry of the TabContents that we were
128 // opened for. Used to help expire on navigations. 112 // opened for. Used to help expire on navigations.
129 int contents_unique_id_; 113 int contents_unique_id_;
130 114
131 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); 115 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
132 }; 116 };
133 117
134 // An interface derived from InfoBarDelegate implemented by objects wishing to 118 // An interface derived from InfoBarDelegate implemented by objects wishing to
135 // control an AlertInfoBar. 119 // control an AlertInfoBar.
136 class AlertInfoBarDelegate : public InfoBarDelegate { 120 class AlertInfoBarDelegate : public InfoBarDelegate {
137 public: 121 public:
138 // Returns the message string to be displayed for the InfoBar. 122 // Returns the message string to be displayed for the InfoBar.
139 virtual string16 GetMessageText() const = 0; 123 virtual string16 GetMessageText() const = 0;
140 124
141 // Overridden from InfoBarDelegate. 125 // InfoBarDelegate:
142 virtual SkBitmap* GetIcon() const; 126 virtual InfoBar* CreateInfoBar();
143
144 // Overridden from InfoBarDelegate:
145 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; 127 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
146 virtual InfoBar* CreateInfoBar();
147 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
148 128
149 protected: 129 protected:
150 explicit AlertInfoBarDelegate(TabContents* contents); 130 explicit AlertInfoBarDelegate(TabContents* contents);
131 virtual ~AlertInfoBarDelegate();
132
133 private:
134 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
151 135
152 DISALLOW_COPY_AND_ASSIGN(AlertInfoBarDelegate); 136 DISALLOW_COPY_AND_ASSIGN(AlertInfoBarDelegate);
153 }; 137 };
154 138
155 // An interface derived from InfoBarDelegate implemented by objects wishing to 139 // An interface derived from InfoBarDelegate implemented by objects wishing to
156 // control a LinkInfoBar. 140 // control a LinkInfoBar.
157 class LinkInfoBarDelegate : public InfoBarDelegate { 141 class LinkInfoBarDelegate : public InfoBarDelegate {
158 public: 142 public:
159 // Returns the message string to be displayed in the InfoBar. |link_offset| 143 // Returns the message string to be displayed in the InfoBar. |link_offset|
160 // is the position where the link should be inserted. If |link_offset| is set 144 // is the position where the link should be inserted. If |link_offset| is set
161 // to string16::npos (it is by default), the link is right aligned within 145 // to string16::npos (it is by default), the link is right aligned within
162 // the InfoBar rather than being embedded in the message text. 146 // the InfoBar rather than being embedded in the message text.
163 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; 147 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const;
164 148
165 // Returns the text of the link to be displayed. 149 // Returns the text of the link to be displayed.
166 virtual string16 GetLinkText() const = 0; 150 virtual string16 GetLinkText() const = 0;
167 151
168 // Overridden from InfoBarDelegate.
169 virtual SkBitmap* GetIcon() const;
170
171 // Called when the Link is clicked. The |disposition| specifies how the 152 // Called when the Link is clicked. The |disposition| specifies how the
172 // resulting document should be loaded (based on the event flags present when 153 // resulting document should be loaded (based on the event flags present when
173 // the link was clicked). This function returns true if the InfoBar should be 154 // the link was clicked). This function returns true if the InfoBar should be
174 // closed now or false if it should remain until the user explicitly closes 155 // closed now or false if it should remain until the user explicitly closes
175 // it. 156 // it.
176 virtual bool LinkClicked(WindowOpenDisposition disposition); 157 virtual bool LinkClicked(WindowOpenDisposition disposition);
177 158
178 // Overridden from InfoBarDelegate: 159 protected:
160 explicit LinkInfoBarDelegate(TabContents* contents);
161 virtual ~LinkInfoBarDelegate();
162
163 private:
164 // InfoBarDelegate:
179 virtual InfoBar* CreateInfoBar(); 165 virtual InfoBar* CreateInfoBar();
180 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); 166 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
181 167
182 protected:
183 explicit LinkInfoBarDelegate(TabContents* contents);
184
185 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate); 168 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate);
186 }; 169 };
187 170
188 // An interface derived from InfoBarDelegate implemented by objects wishing to 171 // An interface derived from InfoBarDelegate implemented by objects wishing to
189 // control a ConfirmInfoBar. 172 // control a ConfirmInfoBar.
190 class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { 173 class ConfirmInfoBarDelegate : public AlertInfoBarDelegate {
191 public: 174 public:
192 enum InfoBarButton { 175 enum InfoBarButton {
193 BUTTON_NONE = 0, 176 BUTTON_NONE = 0,
194 BUTTON_OK = 1 << 0, 177 BUTTON_OK = 1 << 0,
195 BUTTON_CANCEL = 1 << 1, 178 BUTTON_CANCEL = 1 << 1,
196 // Specifies that the OK button should be rendered like a default button.
197 BUTTON_OK_DEFAULT = 1 << 2
198 }; 179 };
199 180
200 // Return the buttons to be shown for this InfoBar. 181 // Return the buttons to be shown for this InfoBar.
201 virtual int GetButtons() const; 182 virtual int GetButtons() const;
202 183
203 // Return the label for the specified button. The default implementation 184 // Return the label for the specified button. The default implementation
204 // returns "OK" for the OK button and "Cancel" for the Cancel button. 185 // returns "OK" for the OK button and "Cancel" for the Cancel button.
205 virtual string16 GetButtonLabel(InfoBarButton button) const; 186 virtual string16 GetButtonLabel(InfoBarButton button) const;
206 187
207 // Return whether or not the specified button needs elevation. 188 // Return whether or not the specified button needs elevation.
(...skipping 12 matching lines...) Expand all
220 virtual string16 GetLinkText(); 201 virtual string16 GetLinkText();
221 202
222 // Called when the Link is clicked. The |disposition| specifies how the 203 // Called when the Link is clicked. The |disposition| specifies how the
223 // resulting document should be loaded (based on the event flags present when 204 // resulting document should be loaded (based on the event flags present when
224 // the link was clicked). This function returns true if the InfoBar should be 205 // the link was clicked). This function returns true if the InfoBar should be
225 // closed now or false if it should remain until the user explicitly closes 206 // closed now or false if it should remain until the user explicitly closes
226 // it. 207 // it.
227 // Will only be called if GetLinkText() returns non-empty string. 208 // Will only be called if GetLinkText() returns non-empty string.
228 virtual bool LinkClicked(WindowOpenDisposition disposition); 209 virtual bool LinkClicked(WindowOpenDisposition disposition);
229 210
230 // Overridden from InfoBarDelegate: 211 protected:
212 explicit ConfirmInfoBarDelegate(TabContents* contents);
213 virtual ~ConfirmInfoBarDelegate();
214
215 private:
216 // InfoBarDelegate:
231 virtual InfoBar* CreateInfoBar(); 217 virtual InfoBar* CreateInfoBar();
232 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); 218 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
233 219
234 protected:
235 explicit ConfirmInfoBarDelegate(TabContents* contents);
236
237 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate); 220 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate);
238 }; 221 };
239 222
240 // Simple implementations for common use cases --------------------------------- 223 // Simple implementations for common use cases ---------------------------------
241 224
242 class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate { 225 class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate {
243 public: 226 public:
244 // |icon| may be |NULL|.
245 SimpleAlertInfoBarDelegate(TabContents* contents, 227 SimpleAlertInfoBarDelegate(TabContents* contents,
228 SkBitmap* icon, // May be NULL.
246 const string16& message, 229 const string16& message,
247 SkBitmap* icon,
248 bool auto_expire); 230 bool auto_expire);
249 231
250 // Overridden from AlertInfoBarDelegate: 232 private:
233 virtual ~SimpleAlertInfoBarDelegate();
234
235 // AlertInfoBarDelegate:
251 virtual bool ShouldExpire( 236 virtual bool ShouldExpire(
252 const NavigationController::LoadCommittedDetails& details) const; 237 const NavigationController::LoadCommittedDetails& details) const;
238 virtual void InfoBarClosed();
239 virtual SkBitmap* GetIcon() const;
253 virtual string16 GetMessageText() const; 240 virtual string16 GetMessageText() const;
254 virtual SkBitmap* GetIcon() const;
255 virtual void InfoBarClosed();
256 241
257 private: 242 SkBitmap* icon_;
258 string16 message_; 243 string16 message_;
259 SkBitmap* icon_;
260 bool auto_expire_; // Should it expire automatically on navigation? 244 bool auto_expire_; // Should it expire automatically on navigation?
261 245
262 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); 246 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate);
263 }; 247 };
264 248
265 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ 249 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_input_manager.cc ('k') | chrome/browser/tab_contents/infobar_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698