Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/devtools/global_confirm_info_bar.h" | 5 #include "chrome/browser/devtools/global_confirm_info_bar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { | 153 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { |
| 154 while (!proxies_.empty()) { | 154 while (!proxies_.empty()) { |
| 155 auto it = proxies_.begin(); | 155 auto it = proxies_.begin(); |
| 156 it->second->Detach(); | 156 it->second->Detach(); |
| 157 it->first->RemoveObserver(this); | 157 it->first->RemoveObserver(this); |
| 158 it->first->RemoveInfoBar(it->second->info_bar_); | 158 it->first->RemoveInfoBar(it->second->info_bar_); |
| 159 proxies_.erase(it); | 159 proxies_.erase(it); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 void GlobalConfirmInfoBar::TabInsertedAt(content::WebContents* web_contents, | 163 // Do not use |tab_strip_model| as it may be null from the call in |
| 164 // TabChangedAt(). If it is ever needed later, the solution is to add a pointer | |
| 165 // to the TabStripModel as a parameter of TabStripModelObserver::TabChangedAt(). | |
| 166 void GlobalConfirmInfoBar::TabInsertedAt(TabStripModel* tab_strip_model, | |
|
sky
2016/09/19 22:52:58
Good comment, but this is still rather rather erro
Patrick Monette
2016/09/20 17:46:54
Done. Can you double check that the code in TabCha
| |
| 167 content::WebContents* web_contents, | |
| 164 int index, | 168 int index, |
| 165 bool foreground) { | 169 bool foreground) { |
| 166 InfoBarService* infobar_service = | 170 InfoBarService* infobar_service = |
| 167 InfoBarService::FromWebContents(web_contents); | 171 InfoBarService::FromWebContents(web_contents); |
| 168 // WebContents from the tab strip must have the infobar service. | 172 // WebContents from the tab strip must have the infobar service. |
| 169 DCHECK(infobar_service); | 173 DCHECK(infobar_service); |
| 170 if (proxies_.find(infobar_service) != proxies_.end()) | 174 if (proxies_.find(infobar_service) != proxies_.end()) |
| 171 return; | 175 return; |
| 172 | 176 |
| 173 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( | 177 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( |
| 174 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); | 178 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); |
| 175 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); | 179 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); |
| 176 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( | 180 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( |
| 177 infobar_service->CreateConfirmInfoBar(std::move(proxy))); | 181 infobar_service->CreateConfirmInfoBar(std::move(proxy))); |
| 178 | 182 |
| 179 proxy_ptr->info_bar_ = added_bar; | 183 proxy_ptr->info_bar_ = added_bar; |
| 180 DCHECK(added_bar); | 184 DCHECK(added_bar); |
| 181 proxies_[infobar_service] = proxy_ptr; | 185 proxies_[infobar_service] = proxy_ptr; |
| 182 infobar_service->AddObserver(this); | 186 infobar_service->AddObserver(this); |
| 183 } | 187 } |
| 184 | 188 |
| 185 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, | 189 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, |
| 186 int index, | 190 int index, |
| 187 TabChangeType change_type) { | 191 TabChangeType change_type) { |
| 188 InfoBarService* infobar_service = | 192 InfoBarService* infobar_service = |
| 189 InfoBarService::FromWebContents(web_contents); | 193 InfoBarService::FromWebContents(web_contents); |
| 190 auto it = proxies_.find(infobar_service); | 194 auto it = proxies_.find(infobar_service); |
| 191 if (it == proxies_.end()) | 195 if (it == proxies_.end()) |
| 192 TabInsertedAt(web_contents, index, false); | 196 TabInsertedAt(nullptr, web_contents, index, false); |
| 193 } | 197 } |
| 194 | 198 |
| 195 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar, | 199 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar, |
| 196 bool animate) { | 200 bool animate) { |
| 197 // Do not process alien infobars. | 201 // Do not process alien infobars. |
| 198 for (auto it : proxies_) { | 202 for (auto it : proxies_) { |
| 199 if (it.second->info_bar_ == info_bar) { | 203 if (it.second->info_bar_ == info_bar) { |
| 200 OnManagerShuttingDown(info_bar->owner()); | 204 OnManagerShuttingDown(info_bar->owner()); |
| 201 break; | 205 break; |
| 202 } | 206 } |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 void GlobalConfirmInfoBar::OnManagerShuttingDown( | 210 void GlobalConfirmInfoBar::OnManagerShuttingDown( |
| 207 infobars::InfoBarManager* manager) { | 211 infobars::InfoBarManager* manager) { |
| 208 manager->RemoveObserver(this); | 212 manager->RemoveObserver(this); |
| 209 proxies_.erase(manager); | 213 proxies_.erase(manager); |
| 210 } | 214 } |
| OLD | NEW |