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/api/infobars/infobar_delegate.h" | 7 #include "chrome/browser/api/infobars/infobar_delegate.h" |
8 #include "chrome/browser/infobars/infobar.h" | 8 #include "chrome/browser/infobars/infobar.h" |
9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" | 9 #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
10 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 | 16 |
16 using content::NavigationController; | 17 using content::NavigationController; |
17 using content::WebContents; | 18 using content::WebContents; |
18 | 19 |
| 20 InfoBarTabService* InfoBarTabService::ForTab(TabContents* tab) { |
| 21 return tab->infobar_tab_helper(); |
| 22 } |
| 23 |
19 InfoBarTabHelper::InfoBarTabHelper(WebContents* web_contents) | 24 InfoBarTabHelper::InfoBarTabHelper(WebContents* web_contents) |
20 : content::WebContentsObserver(web_contents), | 25 : content::WebContentsObserver(web_contents), |
21 infobars_enabled_(true) { | 26 infobars_enabled_(true) { |
22 DCHECK(web_contents); | 27 DCHECK(web_contents); |
23 } | 28 } |
24 | 29 |
25 InfoBarTabHelper::~InfoBarTabHelper() { | 30 InfoBarTabHelper::~InfoBarTabHelper() { |
26 // Destroy all remaining InfoBars. It's important to not animate here so that | 31 // Destroy all remaining InfoBars. It's important to not animate here so that |
27 // we guarantee that we'll delete all delegates before we do anything else. | 32 // we guarantee that we'll delete all delegates before we do anything else. |
28 // | 33 // |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 92 |
88 old_delegate->clear_owner(); | 93 old_delegate->clear_owner(); |
89 InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); | 94 InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); |
90 content::NotificationService::current()->Notify( | 95 content::NotificationService::current()->Notify( |
91 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, | 96 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
92 content::Source<InfoBarTabHelper>(this), | 97 content::Source<InfoBarTabHelper>(this), |
93 content::Details<InfoBarReplacedDetails>(&replaced_details)); | 98 content::Details<InfoBarReplacedDetails>(&replaced_details)); |
94 return true; | 99 return true; |
95 } | 100 } |
96 | 101 |
| 102 size_t InfoBarTabHelper::GetInfoBarCount() const { |
| 103 return infobars_.size(); |
| 104 } |
| 105 |
97 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { | 106 InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { |
98 return infobars_[index]; | 107 return infobars_[index]; |
99 } | 108 } |
100 | 109 |
| 110 content::WebContents* InfoBarTabHelper::GetWebContents() { |
| 111 return content::WebContentsObserver::web_contents(); |
| 112 } |
| 113 |
101 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, | 114 void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, |
102 bool animate) { | 115 bool animate) { |
103 if (!infobars_enabled_) { | 116 if (!infobars_enabled_) { |
104 DCHECK(infobars_.empty()); | 117 DCHECK(infobars_.empty()); |
105 return; | 118 return; |
106 } | 119 } |
107 | 120 |
108 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), delegate)); | 121 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), delegate)); |
109 DCHECK(i != infobars_.end()); | 122 DCHECK(i != infobars_.end()); |
110 | 123 |
(...skipping 11 matching lines...) Expand all Loading... |
122 | 135 |
123 InfoBarRemovedDetails removed_details(delegate, animate); | 136 InfoBarRemovedDetails removed_details(delegate, animate); |
124 content::NotificationService::current()->Notify( | 137 content::NotificationService::current()->Notify( |
125 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 138 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
126 content::Source<InfoBarTabHelper>(this), | 139 content::Source<InfoBarTabHelper>(this), |
127 content::Details<InfoBarRemovedDetails>(&removed_details)); | 140 content::Details<InfoBarRemovedDetails>(&removed_details)); |
128 } | 141 } |
129 | 142 |
130 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { | 143 void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { |
131 while (!infobars_.empty()) | 144 while (!infobars_.empty()) |
132 RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); | 145 RemoveInfoBarInternal(GetInfoBarDelegateAt(GetInfoBarCount() - 1), animate); |
133 } | 146 } |
134 | 147 |
135 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { | 148 void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { |
136 // At most one infobar and do not supersede the stronger running content bar. | 149 // At most one infobar and do not supersede the stronger running content bar. |
137 for (size_t i = 0; i < infobars_.size(); ++i) { | 150 for (size_t i = 0; i < infobars_.size(); ++i) { |
138 if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate()) | 151 if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate()) |
139 return; | 152 return; |
140 } | 153 } |
141 AddInfoBar(new InsecureContentInfoBarDelegate(this, | 154 AddInfoBar(new InsecureContentInfoBarDelegate(this, |
142 InsecureContentInfoBarDelegate::DISPLAY)); | 155 InsecureContentInfoBarDelegate::DISPLAY)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (delegate->ShouldExpire(committed_details)) | 207 if (delegate->ShouldExpire(committed_details)) |
195 RemoveInfoBar(delegate); | 208 RemoveInfoBar(delegate); |
196 } | 209 } |
197 | 210 |
198 break; | 211 break; |
199 } | 212 } |
200 default: | 213 default: |
201 NOTREACHED(); | 214 NOTREACHED(); |
202 } | 215 } |
203 } | 216 } |
OLD | NEW |