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 #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/tab_contents/insecure_content_infobar_delegate.h" | 9 #include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
12 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 | 15 |
| 16 using content::NavigationController; |
16 using content::WebContents; | 17 using content::WebContents; |
17 | 18 |
18 InfoBarTabHelper::InfoBarTabHelper(WebContents* web_contents) | 19 InfoBarTabHelper::InfoBarTabHelper(WebContents* web_contents) |
19 : content::WebContentsObserver(web_contents), | 20 : content::WebContentsObserver(web_contents), |
20 infobars_enabled_(true) { | 21 infobars_enabled_(true) { |
21 DCHECK(web_contents); | 22 DCHECK(web_contents); |
22 } | 23 } |
23 | 24 |
24 InfoBarTabHelper::~InfoBarTabHelper() { | 25 InfoBarTabHelper::~InfoBarTabHelper() { |
25 // Destroy all remaining InfoBars. It's important to not animate here so that | 26 // Destroy all remaining InfoBars. It's important to not animate here so that |
(...skipping 25 matching lines...) Expand all Loading... |
51 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 52 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
52 content::Source<InfoBarTabHelper>(this), | 53 content::Source<InfoBarTabHelper>(this), |
53 content::Details<InfoBarAddedDetails>(delegate)); | 54 content::Details<InfoBarAddedDetails>(delegate)); |
54 | 55 |
55 // Add ourselves as an observer for navigations the first time a delegate is | 56 // Add ourselves as an observer for navigations the first time a delegate is |
56 // added. We use this notification to expire InfoBars that need to expire on | 57 // added. We use this notification to expire InfoBars that need to expire on |
57 // page transitions. | 58 // page transitions. |
58 if (infobars_.size() == 1) { | 59 if (infobars_.size() == 1) { |
59 registrar_.Add( | 60 registrar_.Add( |
60 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 61 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
61 content::Source<content::NavigationController>( | 62 content::Source<NavigationController>( |
62 &web_contents()->GetController())); | 63 &web_contents()->GetController())); |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 void InfoBarTabHelper::RemoveInfoBar(InfoBarDelegate* delegate) { | 67 void InfoBarTabHelper::RemoveInfoBar(InfoBarDelegate* delegate) { |
67 RemoveInfoBarInternal(delegate, true); | 68 RemoveInfoBarInternal(delegate, true); |
68 } | 69 } |
69 | 70 |
70 void InfoBarTabHelper::ReplaceInfoBar(InfoBarDelegate* old_delegate, | 71 void InfoBarTabHelper::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
71 InfoBarDelegate* new_delegate) { | 72 InfoBarDelegate* new_delegate) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 content::NotificationService::current()->Notify( | 118 content::NotificationService::current()->Notify( |
118 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 119 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
119 content::Source<InfoBarTabHelper>(this), | 120 content::Source<InfoBarTabHelper>(this), |
120 content::Details<InfoBarRemovedDetails>(&removed_details)); | 121 content::Details<InfoBarRemovedDetails>(&removed_details)); |
121 | 122 |
122 infobars_.erase(infobars_.begin() + i); | 123 infobars_.erase(infobars_.begin() + i); |
123 // Remove ourselves as an observer if we are tracking no more InfoBars. | 124 // Remove ourselves as an observer if we are tracking no more InfoBars. |
124 if (infobars_.empty()) { | 125 if (infobars_.empty()) { |
125 registrar_.Remove( | 126 registrar_.Remove( |
126 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 127 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
127 content::Source<content::NavigationController>( | 128 content::Source<NavigationController>( |
128 &web_contents()->GetController())); | 129 &web_contents()->GetController())); |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { | 133 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { |
133 while (!infobars_.empty()) | 134 while (!infobars_.empty()) |
134 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | 135 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); |
135 } | 136 } |
136 | 137 |
137 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { | 138 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 IPC_END_MESSAGE_MAP() | 177 IPC_END_MESSAGE_MAP() |
177 return handled; | 178 return handled; |
178 } | 179 } |
179 | 180 |
180 void InfoBarTabHelper::Observe(int type, | 181 void InfoBarTabHelper::Observe(int type, |
181 const content::NotificationSource& source, | 182 const content::NotificationSource& source, |
182 const content::NotificationDetails& details) { | 183 const content::NotificationDetails& details) { |
183 switch (type) { | 184 switch (type) { |
184 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 185 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
185 DCHECK(&web_contents()->GetController() == | 186 DCHECK(&web_contents()->GetController() == |
186 content::Source<content::NavigationController>(source).ptr()); | 187 content::Source<NavigationController>(source).ptr()); |
187 | 188 |
188 content::LoadCommittedDetails& committed_details = | 189 content::LoadCommittedDetails& committed_details = |
189 *(content::Details<content::LoadCommittedDetails>(details).ptr()); | 190 *(content::Details<content::LoadCommittedDetails>(details).ptr()); |
190 | 191 |
191 // NOTE: It is not safe to change the following code to count upwards or | 192 // NOTE: It is not safe to change the following code to count upwards or |
192 // use iterators, as the RemoveInfoBar() call synchronously modifies our | 193 // use iterators, as the RemoveInfoBar() call synchronously modifies our |
193 // delegate list. | 194 // delegate list. |
194 for (size_t i = infobars_.size(); i > 0; --i) { | 195 for (size_t i = infobars_.size(); i > 0; --i) { |
195 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); | 196 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); |
196 if (delegate->ShouldExpire(committed_details)) | 197 if (delegate->ShouldExpire(committed_details)) |
197 RemoveInfoBar(delegate); | 198 RemoveInfoBar(delegate); |
198 } | 199 } |
199 | 200 |
200 break; | 201 break; |
201 } | 202 } |
202 default: | 203 default: |
203 NOTREACHED(); | 204 NOTREACHED(); |
204 } | 205 } |
205 } | 206 } |
OLD | NEW |