OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | 5 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 delegate_->WillAddWebState(web_state); | 207 delegate_->WillAddWebState(web_state); |
208 | 208 |
209 ClearOpenersReferencing(index); | 209 ClearOpenersReferencing(index); |
210 | 210 |
211 auto& web_state_wrapper = web_state_wrappers_[index]; | 211 auto& web_state_wrapper = web_state_wrappers_[index]; |
212 web::WebState* old_web_state = web_state_wrapper->ReplaceWebState(web_state); | 212 web::WebState* old_web_state = web_state_wrapper->ReplaceWebState(web_state); |
213 | 213 |
214 for (auto& observer : observers_) | 214 for (auto& observer : observers_) |
215 observer.WebStateReplacedAt(this, old_web_state, web_state, index); | 215 observer.WebStateReplacedAt(this, old_web_state, web_state, index); |
216 | 216 |
| 217 delegate_->WebStateDetached(old_web_state); |
217 return old_web_state; | 218 return old_web_state; |
218 } | 219 } |
219 | 220 |
220 web::WebState* WebStateList::DetachWebStateAt(int index) { | 221 web::WebState* WebStateList::DetachWebStateAt(int index) { |
221 DCHECK(ContainsIndex(index)); | 222 DCHECK(ContainsIndex(index)); |
222 int new_active_index = order_controller_->DetermineNewActiveIndex(index); | 223 int new_active_index = order_controller_->DetermineNewActiveIndex(index); |
223 | 224 |
224 web::WebState* old_web_state = web_state_wrappers_[index]->web_state(); | 225 web::WebState* old_web_state = web_state_wrappers_[index]->web_state(); |
| 226 for (auto& observer : observers_) |
| 227 observer.WillDetachWebStateAt(this, old_web_state, index); |
225 | 228 |
226 ClearOpenersReferencing(index); | 229 ClearOpenersReferencing(index); |
227 web_state_wrappers_.erase(web_state_wrappers_.begin() + index); | 230 web_state_wrappers_.erase(web_state_wrappers_.begin() + index); |
228 | 231 |
229 // Update the active index to prevent observer from seeing an invalid WebState | 232 // Update the active index to prevent observer from seeing an invalid WebState |
230 // as the active one but only send the WebStateActivatedAt notification after | 233 // as the active one but only send the WebStateActivatedAt notification after |
231 // the WebStateDetachedAt one. | 234 // the WebStateDetachedAt one. |
232 bool active_web_state_was_closed = (index == active_index_); | 235 bool active_web_state_was_closed = (index == active_index_); |
233 if (active_index_ > index) | 236 if (active_index_ > index) |
234 --active_index_; | 237 --active_index_; |
235 else if (active_index_ == index) | 238 else if (active_index_ == index) |
236 active_index_ = new_active_index; | 239 active_index_ = new_active_index; |
237 | 240 |
238 for (auto& observer : observers_) | 241 for (auto& observer : observers_) |
239 observer.WebStateDetachedAt(this, old_web_state, index); | 242 observer.WebStateDetachedAt(this, old_web_state, index); |
240 | 243 |
241 if (active_web_state_was_closed) | 244 if (active_web_state_was_closed) |
242 NotifyIfActiveWebStateChanged(old_web_state, false); | 245 NotifyIfActiveWebStateChanged(old_web_state, false); |
243 | 246 |
| 247 delegate_->WebStateDetached(old_web_state); |
244 return old_web_state; | 248 return old_web_state; |
245 } | 249 } |
246 | 250 |
247 void WebStateList::ActivateWebStateAt(int index) { | 251 void WebStateList::ActivateWebStateAt(int index) { |
248 DCHECK(ContainsIndex(index)); | 252 DCHECK(ContainsIndex(index)); |
249 web::WebState* old_web_state = GetActiveWebState(); | 253 web::WebState* old_web_state = GetActiveWebState(); |
250 active_index_ = index; | 254 active_index_ = index; |
251 NotifyIfActiveWebStateChanged(old_web_state, true); | 255 NotifyIfActiveWebStateChanged(old_web_state, true); |
252 } | 256 } |
253 | 257 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } else if (found_index != kInvalidIndex) { | 304 } else if (found_index != kInvalidIndex) { |
301 return found_index; | 305 return found_index; |
302 } | 306 } |
303 } | 307 } |
304 | 308 |
305 return found_index; | 309 return found_index; |
306 } | 310 } |
307 | 311 |
308 // static | 312 // static |
309 const int WebStateList::kInvalidIndex; | 313 const int WebStateList::kInvalidIndex; |
OLD | NEW |