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 #include "chrome/browser/infobars/infobar_tab_helper.h" | 5 #include "chrome/browser/infobars/infobar_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/infobars/infobar.h" | 7 #include "chrome/browser/infobars/infobar.h" |
8 #include "chrome/browser/infobars/infobar_delegate.h" | 8 #include "chrome/browser/infobars/infobar_delegate.h" |
9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" | 9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { | 130 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { |
131 return infobars_[index]; | 131 return infobars_[index]; |
132 } | 132 } |
133 | 133 |
134 content::WebContents* InfoBarTabHelper::GetWebContents() { | 134 content::WebContents* InfoBarTabHelper::GetWebContents() { |
135 return content::WebContentsObserver::web_contents(); | 135 return content::WebContentsObserver::web_contents(); |
136 } | 136 } |
137 | 137 |
138 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, | |
139 bool animate) { | |
140 if (!infobars_enabled_) { | |
141 DCHECK(infobars_.empty()); | |
142 return; | |
143 } | |
144 | |
145 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), delegate)); | |
146 DCHECK(i != infobars_.end()); | |
147 | |
148 delegate->clear_owner(); | |
149 // Remove the delegate before notifying, so that if any observers call back to | |
150 // AddInfoBar() or similar, we don't dupe-check against this delegate. | |
151 infobars_.erase(i); | |
152 // Remove ourselves as an observer if we are tracking no more InfoBars. | |
153 if (infobars_.empty()) { | |
154 registrar_.Remove( | |
155 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
156 content::Source<NavigationController>( | |
157 &web_contents()->GetController())); | |
158 } | |
159 | |
160 InfoBarRemovedDetails removed_details(delegate, animate); | |
161 content::NotificationService::current()->Notify( | |
162 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
163 content::Source<InfoBarService>(this), | |
164 content::Details<InfoBarRemovedDetails>(&removed_details)); | |
165 } | |
166 | |
167 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { | |
168 while (!infobars_.empty()) | |
169 RemoveInfoBarInternal(GetInfoBarDelegateAt(GetInfoBarCount() - 1), animate); | |
170 } | |
171 | |
172 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { | |
173 InsecureContentInfoBarDelegate::Create( | |
174 this, InsecureContentInfoBarDelegate::DISPLAY); | |
175 } | |
176 | |
177 void InfoBarTabHelper::OnDidBlockRunningInsecureContent() { | |
178 InsecureContentInfoBarDelegate::Create(this, | |
179 InsecureContentInfoBarDelegate::RUN); | |
180 } | |
181 | |
182 void InfoBarTabHelper::RenderViewGone(base::TerminationStatus status) { | 138 void InfoBarTabHelper::RenderViewGone(base::TerminationStatus status) { |
183 RemoveAllInfoBars(true); | 139 RemoveAllInfoBars(true); |
184 } | 140 } |
185 | 141 |
186 bool InfoBarTabHelper::OnMessageReceived(const IPC::Message& message) { | 142 bool InfoBarTabHelper::OnMessageReceived(const IPC::Message& message) { |
187 bool handled = true; | 143 bool handled = true; |
188 IPC_BEGIN_MESSAGE_MAP(InfoBarTabHelper, message) | 144 IPC_BEGIN_MESSAGE_MAP(InfoBarTabHelper, message) |
189 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, | 145 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, |
190 OnDidBlockDisplayingInsecureContent) | 146 OnDidBlockDisplayingInsecureContent) |
191 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, | 147 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, |
(...skipping 28 matching lines...) Expand all Loading... |
220 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_DESTROYED); | 176 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_DESTROYED); |
221 // The WebContents is going away; be aggressively paranoid and delete | 177 // The WebContents is going away; be aggressively paranoid and delete |
222 // ourselves lest other parts of the system attempt to add infobars or use | 178 // ourselves lest other parts of the system attempt to add infobars or use |
223 // us otherwise during the destruction. | 179 // us otherwise during the destruction. |
224 DCHECK_EQ(web_contents(), content::Source<WebContents>(source).ptr()); | 180 DCHECK_EQ(web_contents(), content::Source<WebContents>(source).ptr()); |
225 web_contents()->RemoveUserData(UserDataKey()); | 181 web_contents()->RemoveUserData(UserDataKey()); |
226 // That was the equivalent of "delete this". This object is now destroyed; | 182 // That was the equivalent of "delete this". This object is now destroyed; |
227 // returning from this function is the only safe thing to do. | 183 // returning from this function is the only safe thing to do. |
228 return; | 184 return; |
229 } | 185 } |
| 186 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, |
| 187 bool animate) { |
| 188 if (!infobars_enabled_) { |
| 189 DCHECK(infobars_.empty()); |
| 190 return; |
| 191 } |
| 192 |
| 193 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), delegate)); |
| 194 DCHECK(i != infobars_.end()); |
| 195 |
| 196 delegate->clear_owner(); |
| 197 // Remove the delegate before notifying, so that if any observers call back to |
| 198 // AddInfoBar() or similar, we don't dupe-check against this delegate. |
| 199 infobars_.erase(i); |
| 200 // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 201 if (infobars_.empty()) { |
| 202 registrar_.Remove( |
| 203 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 204 content::Source<NavigationController>( |
| 205 &web_contents()->GetController())); |
| 206 } |
| 207 |
| 208 InfoBarRemovedDetails removed_details(delegate, animate); |
| 209 content::NotificationService::current()->Notify( |
| 210 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 211 content::Source<InfoBarService>(this), |
| 212 content::Details<InfoBarRemovedDetails>(&removed_details)); |
| 213 } |
| 214 |
| 215 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { |
| 216 while (!infobars_.empty()) |
| 217 RemoveInfoBarInternal(GetInfoBarDelegateAt(GetInfoBarCount() - 1), animate); |
| 218 } |
| 219 |
| 220 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { |
| 221 InsecureContentInfoBarDelegate::Create( |
| 222 this, InsecureContentInfoBarDelegate::DISPLAY); |
| 223 } |
| 224 |
| 225 void InfoBarTabHelper::OnDidBlockRunningInsecureContent() { |
| 226 InsecureContentInfoBarDelegate::Create(this, |
| 227 InsecureContentInfoBarDelegate::RUN); |
| 228 } |
OLD | NEW |