OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_INFOBARS_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 enum InfoBarAutomationType { | 44 enum InfoBarAutomationType { |
45 CONFIRM_INFOBAR, | 45 CONFIRM_INFOBAR, |
46 PASSWORD_INFOBAR, | 46 PASSWORD_INFOBAR, |
47 RPH_INFOBAR, | 47 RPH_INFOBAR, |
48 UNKNOWN_INFOBAR, | 48 UNKNOWN_INFOBAR, |
49 }; | 49 }; |
50 | 50 |
51 // Value to use when the InfoBar has no icon to show. | 51 // Value to use when the InfoBar has no icon to show. |
52 static const int kNoIconID; | 52 static const int kNoIconID; |
53 | 53 |
54 // Called when the InfoBar that owns this delegate is being destroyed. At | |
55 // this point nothing is visible onscreen. | |
56 virtual ~InfoBarDelegate(); | 54 virtual ~InfoBarDelegate(); |
57 | 55 |
58 virtual InfoBarAutomationType GetInfoBarAutomationType() const; | 56 virtual InfoBarAutomationType GetInfoBarAutomationType() const; |
59 | 57 |
| 58 // Called to create the InfoBar. Implementation of this method is |
| 59 // platform-specific. |
| 60 virtual InfoBar* CreateInfoBar(InfoBarService* owner) = 0; |
| 61 |
| 62 // TODO(pkasting): Move to InfoBar once InfoBars own their delegates. |
| 63 InfoBarService* owner() { return owner_; } |
| 64 |
| 65 void clear_owner() { owner_ = NULL; } |
| 66 |
60 // Returns true if the supplied |delegate| is equal to this one. Equality is | 67 // Returns true if the supplied |delegate| is equal to this one. Equality is |
61 // left to the implementation to define. This function is called by the | 68 // left to the implementation to define. This function is called by the |
62 // InfoBarService when determining whether or not a delegate should be | 69 // InfoBarService when determining whether or not a delegate should be |
63 // added because a matching one already exists. If this function returns true, | 70 // added because a matching one already exists. If this function returns true, |
64 // the InfoBarService will not add the new delegate because it considers | 71 // the InfoBarService will not add the new delegate because it considers |
65 // one to already be present. | 72 // one to already be present. |
66 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; | 73 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; |
67 | 74 |
68 // Returns true if the InfoBar should be closed automatically after the page | 75 // Returns true if the InfoBar should be closed automatically after the page |
69 // is navigated. By default this returns true if the navigation is to a new | 76 // is navigated. By default this returns true if the navigation is to a new |
(...skipping 20 matching lines...) Expand all Loading... |
90 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate(); | 97 virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate(); |
91 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate(); | 98 virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate(); |
92 virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate(); | 99 virtual PopupBlockedInfoBarDelegate* AsPopupBlockedInfoBarDelegate(); |
93 virtual RegisterProtocolHandlerInfoBarDelegate* | 100 virtual RegisterProtocolHandlerInfoBarDelegate* |
94 AsRegisterProtocolHandlerInfoBarDelegate(); | 101 AsRegisterProtocolHandlerInfoBarDelegate(); |
95 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate(); | 102 virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate(); |
96 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); | 103 virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); |
97 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate(); | 104 virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate(); |
98 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); | 105 virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); |
99 | 106 |
100 void set_infobar(InfoBar* infobar) { infobar_ = infobar; } | 107 // Return the icon to be shown for this InfoBar. If the returned Image is |
| 108 // empty, no icon is shown. |
| 109 virtual gfx::Image GetIcon() const; |
| 110 |
| 111 content::WebContents* web_contents() { |
| 112 return owner_ ? owner_->web_contents() : NULL; |
| 113 } |
| 114 |
| 115 protected: |
| 116 // If |contents| is non-NULL, its active entry's unique ID will be stored |
| 117 // using StoreActiveEntryUniqueID automatically. |
| 118 explicit InfoBarDelegate(InfoBarService* owner); |
101 | 119 |
102 // Store the unique id for the active entry in our WebContents, to be used | 120 // Store the unique id for the active entry in our WebContents, to be used |
103 // later upon navigation to determine if this InfoBarDelegate should be | 121 // later upon navigation to determine if this InfoBarDelegate should be |
104 // expired. | 122 // expired. |
105 void StoreActiveEntryUniqueID(); | 123 void StoreActiveEntryUniqueID(); |
106 | 124 |
107 // Return the icon to be shown for this InfoBar. If the returned Image is | 125 int contents_unique_id() const { return contents_unique_id_; } |
108 // empty, no icon is shown. | |
109 virtual gfx::Image GetIcon() const; | |
110 | |
111 // This trivial getter is defined out-of-line in order to avoid needing to | |
112 // #include infobar.h, which would lead to circular #includes. | |
113 content::WebContents* web_contents(); | |
114 | |
115 protected: | |
116 InfoBarDelegate(); | |
117 | 126 |
118 // Returns true if the navigation is to a new URL or a reload occured. | 127 // Returns true if the navigation is to a new URL or a reload occured. |
119 virtual bool ShouldExpireInternal( | 128 virtual bool ShouldExpireInternal( |
120 const content::LoadCommittedDetails& details) const; | 129 const content::LoadCommittedDetails& details) const; |
121 | 130 |
122 int contents_unique_id() const { return contents_unique_id_; } | 131 // Removes ourself from |owner_| if we haven't already been removed. |
123 InfoBar* infobar() { return infobar_; } | 132 // TODO(pkasting): Move to InfoBar. |
| 133 void RemoveSelf(); |
124 | 134 |
125 private: | 135 private: |
126 // The unique id of the active NavigationEntry of the WebContents that we were | 136 // The unique id of the active NavigationEntry of the WebContents that we were |
127 // opened for. Used to help expire on navigations. | 137 // opened for. Used to help expire on navigations. |
128 int contents_unique_id_; | 138 int contents_unique_id_; |
129 | 139 |
130 // The InfoBar associated with us. | 140 // TODO(pkasting): Remove. |
131 InfoBar* infobar_; | 141 InfoBarService* owner_; |
132 | 142 |
133 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); | 143 DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); |
134 }; | 144 }; |
135 | 145 |
136 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ | 146 #endif // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_ |
OLD | NEW |