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 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 "content/browser/tab_contents/infobar_delegate.h" |
10 #include "base/string16.h" | |
11 #include "chrome/browser/tab_contents/navigation_controller.h" | |
12 #include "webkit/glue/window_open_disposition.h" | |
13 | |
14 class ConfirmInfoBarDelegate; | |
15 class CrashedExtensionInfoBarDelegate; | |
16 class ExtensionInfoBarDelegate; | |
17 class InfoBar; | |
18 class LinkInfoBarDelegate; | |
19 class PluginInstallerInfoBarDelegate; | |
20 class SkBitmap; | |
21 class ThemeInstalledInfoBarDelegate; | |
22 class TranslateInfoBarDelegate; | |
23 | |
24 // An interface implemented by objects wishing to control an InfoBar. | |
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 | |
27 // LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own | |
28 // delegate for your own InfoBar variety. | |
29 // | |
30 // --- WARNING --- | |
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 | |
33 // 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 | |
35 // 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 | |
37 // because a second InfoBar can be added while the first one is in the process | |
38 // of closing (the animations). This can cause problems because when the first | |
39 // one does finally fully close InfoBarDelegate::InfoBarClosed() is called, | |
40 // and the delegate is free to clean itself up or reset state, which may have | |
41 // fatal consequences for the InfoBar that was in the process of opening (or is | |
42 // now fully opened) -- it is referencing a delegate that may not even exist | |
43 // anymore. | |
44 // As such, it is generally much safer to dedicate a delegate instance to | |
45 // AddInfoBar! | |
46 class InfoBarDelegate { | |
47 public: | |
48 // The type of the infobar. It controls its appearance, such as its background | |
49 // color. | |
50 enum Type { | |
51 WARNING_TYPE, | |
52 PAGE_ACTION_TYPE, | |
53 }; | |
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 | |
61 // Returns true if the supplied |delegate| is equal to this one. Equality is | |
62 // left to the implementation to define. This function is called by the | |
63 // TabContents when determining whether or not a delegate should be added | |
64 // because a matching one already exists. If this function returns true, the | |
65 // TabContents will not add the new delegate because it considers one to | |
66 // already be present. | |
67 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; | |
68 | |
69 // Returns true if the InfoBar should be closed automatically after the page | |
70 // is navigated. The default behavior is to return true if the page is | |
71 // navigated somewhere else or reloaded. | |
72 virtual bool ShouldExpire( | |
73 const NavigationController::LoadCommittedDetails& details) const; | |
74 | |
75 // Called when the user clicks on the close button to dismiss the infobar. | |
76 virtual void InfoBarDismissed(); | |
77 | |
78 // Called after the InfoBar is closed. The delegate is free to delete itself | |
79 // at this point. | |
80 virtual void InfoBarClosed(); | |
81 | |
82 // Return the icon to be shown for this InfoBar. If the returned bitmap is | |
83 // NULL, no icon is shown. | |
84 virtual SkBitmap* GetIcon() const; | |
85 | |
86 // Returns the type of the infobar. The type determines the appearance (such | |
87 // as background color) of the infobar. | |
88 virtual Type GetInfoBarType() const; | |
89 | |
90 // Type-checking downcast routines: | |
91 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); | |
92 virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate(); | |
93 virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); | |
94 virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); | |
95 virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate(); | |
96 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); | |
97 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); | |
98 | |
99 protected: | |
100 // 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 | |
102 // stored using StoreActiveEntryUniqueID automatically. | |
103 explicit InfoBarDelegate(TabContents* contents); | |
104 | |
105 // 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 | |
107 // be expired from |contents_|. | |
108 void StoreActiveEntryUniqueID(TabContents* contents); | |
109 | |
110 private: | |
111 // The unique id of the active NavigationEntry of the TabContents that we were | |
112 // opened for. Used to help expire on navigations. | |
113 int contents_unique_id_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); | |
116 }; | |
117 | 10 |
118 // An interface derived from InfoBarDelegate implemented by objects wishing to | 11 // An interface derived from InfoBarDelegate implemented by objects wishing to |
119 // control a LinkInfoBar. | 12 // control a LinkInfoBar. |
120 class LinkInfoBarDelegate : public InfoBarDelegate { | 13 class LinkInfoBarDelegate : public InfoBarDelegate { |
121 public: | 14 public: |
122 // Returns the message string to be displayed in the InfoBar. |link_offset| | 15 // 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 | 16 // 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 | 17 // to string16::npos (it is by default), the link is right aligned within |
125 // the InfoBar rather than being embedded in the message text. | 18 // the InfoBar rather than being embedded in the message text. |
126 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; | 19 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 virtual int GetButtons() const; | 117 virtual int GetButtons() const; |
225 | 118 |
226 SkBitmap* icon_; | 119 SkBitmap* icon_; |
227 string16 message_; | 120 string16 message_; |
228 bool auto_expire_; // Should it expire automatically on navigation? | 121 bool auto_expire_; // Should it expire automatically on navigation? |
229 | 122 |
230 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); | 123 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); |
231 }; | 124 }; |
232 | 125 |
233 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ | 126 #endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ |
OLD | NEW |