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

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

Issue 6262018: Cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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;
15 class ConfirmInfoBarDelegate; 14 class ConfirmInfoBarDelegate;
16 class CrashedExtensionInfoBarDelegate; 15 class CrashedExtensionInfoBarDelegate;
17 class ExtensionInfoBarDelegate; 16 class ExtensionInfoBarDelegate;
18 class InfoBar; 17 class InfoBar;
19 class LinkInfoBarDelegate; 18 class LinkInfoBarDelegate;
20 class SkBitmap; 19 class SkBitmap;
21 class ThemeInstalledInfoBarDelegate; 20 class ThemeInstalledInfoBarDelegate;
22 class TranslateInfoBarDelegate; 21 class TranslateInfoBarDelegate;
23 22
24 // An interface implemented by objects wishing to control an InfoBar. 23 // An interface implemented by objects wishing to control an InfoBar.
25 // Implementing this interface is not sufficient to use an InfoBar, since it 24 // 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 25 // does not map to a specific InfoBar type. Instead, you must implement either
27 // AlertInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own 26 // LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own
28 // delegate for your own InfoBar variety. 27 // delegate for your own InfoBar variety.
29 // 28 //
30 // --- WARNING --- 29 // --- WARNING ---
31 // When creating your InfoBarDelegate subclass, it is recommended that you 30 // 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 31 // design it such that you instantiate a brand new delegate for every call to
33 // AddInfoBar, rather than re-using/sharing a delegate object. Otherwise, 32 // AddInfoBar, rather than re-using/sharing a delegate object. Otherwise,
34 // you need to consider the fact that more than one InfoBar instance can exist 33 // you need to consider the fact that more than one InfoBar instance can exist
35 // and reference the same delegate -- even though it is also true that we only 34 // and reference the same delegate -- even though it is also true that we only
36 // ever fully show one infobar (they don't stack). The dual-references occur 35 // ever fully show one infobar (they don't stack). The dual-references occur
37 // because a second InfoBar can be added while the first one is in the process 36 // because a second InfoBar can be added while the first one is in the process
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 80
82 // Return the icon to be shown for this InfoBar. If the returned bitmap is 81 // Return the icon to be shown for this InfoBar. If the returned bitmap is
83 // NULL, no icon is shown. 82 // NULL, no icon is shown.
84 virtual SkBitmap* GetIcon() const; 83 virtual SkBitmap* GetIcon() const;
85 84
86 // Returns the type of the infobar. The type determines the appearance (such 85 // Returns the type of the infobar. The type determines the appearance (such
87 // as background color) of the infobar. 86 // as background color) of the infobar.
88 virtual Type GetInfoBarType() const; 87 virtual Type GetInfoBarType() const;
89 88
90 // Type-checking downcast routines: 89 // Type-checking downcast routines:
91 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
92 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); 90 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
93 virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate(); 91 virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate();
94 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); 92 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
95 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); 93 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
96 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); 94 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
97 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); 95 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
98 96
99 protected: 97 protected:
100 // Provided to subclasses as a convenience to initialize the state of this 98 // Provided to subclasses as a convenience to initialize the state of this
101 // object. If |contents| is non-NULL, its active entry's unique ID will be 99 // object. If |contents| is non-NULL, its active entry's unique ID will be
102 // stored using StoreActiveEntryUniqueID automatically. 100 // stored using StoreActiveEntryUniqueID automatically.
103 explicit InfoBarDelegate(TabContents* contents); 101 explicit InfoBarDelegate(TabContents* contents);
104 102
105 // Store the unique id for the active entry in the specified TabContents, to 103 // Store the unique id for the active entry in the specified TabContents, to
106 // be used later upon navigation to determine if this InfoBarDelegate should 104 // be used later upon navigation to determine if this InfoBarDelegate should
107 // be expired from |contents_|. 105 // be expired from |contents_|.
108 void StoreActiveEntryUniqueID(TabContents* contents); 106 void StoreActiveEntryUniqueID(TabContents* contents);
109 107
110 private: 108 private:
111 // The unique id of the active NavigationEntry of the TabContents that we were 109 // The unique id of the active NavigationEntry of the TabContents that we were
112 // opened for. Used to help expire on navigations. 110 // opened for. Used to help expire on navigations.
113 int contents_unique_id_; 111 int contents_unique_id_;
114 112
115 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); 113 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
116 }; 114 };
117 115
118 // An interface derived from InfoBarDelegate implemented by objects wishing to 116 // An interface derived from InfoBarDelegate implemented by objects wishing to
119 // control an AlertInfoBar.
120 class AlertInfoBarDelegate : public InfoBarDelegate {
121 public:
122 // Returns the message string to be displayed for the InfoBar.
123 virtual string16 GetMessageText() const = 0;
124
125 // InfoBarDelegate:
126 virtual InfoBar* CreateInfoBar();
127 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
128
129 protected:
130 explicit AlertInfoBarDelegate(TabContents* contents);
131 virtual ~AlertInfoBarDelegate();
132
133 private:
134 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate();
135
136 DISALLOW_COPY_AND_ASSIGN(AlertInfoBarDelegate);
137 };
138
139 // An interface derived from InfoBarDelegate implemented by objects wishing to
140 // control a LinkInfoBar. 117 // control a LinkInfoBar.
141 class LinkInfoBarDelegate : public InfoBarDelegate { 118 class LinkInfoBarDelegate : public InfoBarDelegate {
142 public: 119 public:
143 // Returns the message string to be displayed in the InfoBar. |link_offset| 120 // Returns the message string to be displayed in the InfoBar. |link_offset|
144 // is the position where the link should be inserted. If |link_offset| is set 121 // is the position where the link should be inserted. If |link_offset| is set
145 // to string16::npos (it is by default), the link is right aligned within 122 // to string16::npos (it is by default), the link is right aligned within
146 // the InfoBar rather than being embedded in the message text. 123 // the InfoBar rather than being embedded in the message text.
147 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; 124 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const;
148 125
149 // Returns the text of the link to be displayed. 126 // Returns the text of the link to be displayed.
(...skipping 13 matching lines...) Expand all
163 private: 140 private:
164 // InfoBarDelegate: 141 // InfoBarDelegate:
165 virtual InfoBar* CreateInfoBar(); 142 virtual InfoBar* CreateInfoBar();
166 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); 143 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate();
167 144
168 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate); 145 DISALLOW_COPY_AND_ASSIGN(LinkInfoBarDelegate);
169 }; 146 };
170 147
171 // An interface derived from InfoBarDelegate implemented by objects wishing to 148 // An interface derived from InfoBarDelegate implemented by objects wishing to
172 // control a ConfirmInfoBar. 149 // control a ConfirmInfoBar.
173 class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { 150 class ConfirmInfoBarDelegate : public InfoBarDelegate {
174 public: 151 public:
175 enum InfoBarButton { 152 enum InfoBarButton {
176 BUTTON_NONE = 0, 153 BUTTON_NONE = 0,
177 BUTTON_OK = 1 << 0, 154 BUTTON_OK = 1 << 0,
178 BUTTON_CANCEL = 1 << 1, 155 BUTTON_CANCEL = 1 << 1,
179 }; 156 };
180 157
158 // Returns the message string to be displayed for the InfoBar.
159 virtual string16 GetMessageText() const = 0;
160
181 // Return the buttons to be shown for this InfoBar. 161 // Return the buttons to be shown for this InfoBar.
182 virtual int GetButtons() const; 162 virtual int GetButtons() const;
183 163
184 // Return the label for the specified button. The default implementation 164 // Return the label for the specified button. The default implementation
185 // returns "OK" for the OK button and "Cancel" for the Cancel button. 165 // returns "OK" for the OK button and "Cancel" for the Cancel button.
186 virtual string16 GetButtonLabel(InfoBarButton button) const; 166 virtual string16 GetButtonLabel(InfoBarButton button) const;
187 167
188 // Return whether or not the specified button needs elevation. 168 // Return whether or not the specified button needs elevation.
189 virtual bool NeedElevation(InfoBarButton button) const; 169 virtual bool NeedElevation(InfoBarButton button) const;
190 170
(...skipping 17 matching lines...) Expand all
208 // Will only be called if GetLinkText() returns non-empty string. 188 // Will only be called if GetLinkText() returns non-empty string.
209 virtual bool LinkClicked(WindowOpenDisposition disposition); 189 virtual bool LinkClicked(WindowOpenDisposition disposition);
210 190
211 protected: 191 protected:
212 explicit ConfirmInfoBarDelegate(TabContents* contents); 192 explicit ConfirmInfoBarDelegate(TabContents* contents);
213 virtual ~ConfirmInfoBarDelegate(); 193 virtual ~ConfirmInfoBarDelegate();
214 194
215 private: 195 private:
216 // InfoBarDelegate: 196 // InfoBarDelegate:
217 virtual InfoBar* CreateInfoBar(); 197 virtual InfoBar* CreateInfoBar();
198 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
218 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); 199 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
219 200
220 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate); 201 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate);
221 }; 202 };
222 203
223 // Simple implementations for common use cases --------------------------------- 204 // Simple implementations for common use cases ---------------------------------
224 205
225 class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate { 206 class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate {
226 public: 207 public:
227 SimpleAlertInfoBarDelegate(TabContents* contents, 208 SimpleAlertInfoBarDelegate(TabContents* contents,
228 SkBitmap* icon, // May be NULL. 209 SkBitmap* icon, // May be NULL.
229 const string16& message, 210 const string16& message,
230 bool auto_expire); 211 bool auto_expire);
231 212
232 private: 213 private:
233 virtual ~SimpleAlertInfoBarDelegate(); 214 virtual ~SimpleAlertInfoBarDelegate();
234 215
235 // AlertInfoBarDelegate: 216 // ConfirmInfoBarDelegate:
236 virtual bool ShouldExpire( 217 virtual bool ShouldExpire(
237 const NavigationController::LoadCommittedDetails& details) const; 218 const NavigationController::LoadCommittedDetails& details) const;
238 virtual void InfoBarClosed(); 219 virtual void InfoBarClosed();
239 virtual SkBitmap* GetIcon() const; 220 virtual SkBitmap* GetIcon() const;
240 virtual string16 GetMessageText() const; 221 virtual string16 GetMessageText() const;
222 virtual int GetButtons() const;
241 223
242 SkBitmap* icon_; 224 SkBitmap* icon_;
243 string16 message_; 225 string16 message_;
244 bool auto_expire_; // Should it expire automatically on navigation? 226 bool auto_expire_; // Should it expire automatically on navigation?
245 227
246 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); 228 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate);
247 }; 229 };
248 230
249 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ 231 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager_delegate_impl.cc ('k') | chrome/browser/tab_contents/infobar_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698