| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #import "ios/shared/chrome/browser/tabs/web_state_list_delegate.h" |
| 12 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" | 13 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
| 13 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h" | 14 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h" |
| 14 #import "ios/web/public/navigation_manager.h" | 15 #import "ios/web/public/navigation_manager.h" |
| 15 #import "ios/web/public/web_state/web_state.h" | 16 #import "ios/web/public/web_state/web_state.h" |
| 16 | 17 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 // Wrapper around a WebState stored in a WebStateList. | 22 // Wrapper around a WebState stored in a WebStateList. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 DCHECK(opener); | 81 DCHECK(opener); |
| 81 if (opener_ != opener) | 82 if (opener_ != opener) |
| 82 return false; | 83 return false; |
| 83 | 84 |
| 84 if (!use_group) | 85 if (!use_group) |
| 85 return true; | 86 return true; |
| 86 | 87 |
| 87 return opener_last_committed_index_ == opener_navigation_index; | 88 return opener_last_committed_index_ == opener_navigation_index; |
| 88 } | 89 } |
| 89 | 90 |
| 90 WebStateList::WebStateList(WebStateOwnership ownership) | 91 WebStateList::WebStateList(WebStateListDelegate* delegate, |
| 91 : web_state_ownership_(ownership), | 92 WebStateOwnership ownership) |
| 92 order_controller_(base::MakeUnique<WebStateListOrderController>(this)) {} | 93 : delegate_(delegate), |
| 94 web_state_ownership_(ownership), |
| 95 order_controller_(base::MakeUnique<WebStateListOrderController>(this)) { |
| 96 DCHECK(delegate_); |
| 97 } |
| 93 | 98 |
| 94 WebStateList::~WebStateList() { | 99 WebStateList::~WebStateList() { |
| 95 // Once WebStateList owns the WebState and has a CloseWebStateAt() method, | 100 // Once WebStateList owns the WebState and has a CloseWebStateAt() method, |
| 96 // then change this to close all the WebState. See http://crbug.com/546222 | 101 // then change this to close all the WebState. See http://crbug.com/546222 |
| 97 // for progress. | 102 // for progress. |
| 98 if (web_state_ownership_ == WebStateOwned) { | 103 if (web_state_ownership_ == WebStateOwned) { |
| 99 for (auto& web_state_wrapper : web_state_wrappers_) { | 104 for (auto& web_state_wrapper : web_state_wrappers_) { |
| 100 web::WebState* web_state = web_state_wrapper->web_state(); | 105 web::WebState* web_state = web_state_wrapper->web_state(); |
| 101 delete web_state; | 106 delete web_state; |
| 102 } | 107 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 int WebStateList::GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, | 151 int WebStateList::GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, |
| 147 int start_index, | 152 int start_index, |
| 148 bool use_group) const { | 153 bool use_group) const { |
| 149 return GetIndexOfNthWebStateOpenedBy(opener, start_index, use_group, INT_MAX); | 154 return GetIndexOfNthWebStateOpenedBy(opener, start_index, use_group, INT_MAX); |
| 150 } | 155 } |
| 151 | 156 |
| 152 void WebStateList::InsertWebState(int index, | 157 void WebStateList::InsertWebState(int index, |
| 153 web::WebState* web_state, | 158 web::WebState* web_state, |
| 154 web::WebState* opener) { | 159 web::WebState* opener) { |
| 155 DCHECK(ContainsIndex(index) || index == count()); | 160 DCHECK(ContainsIndex(index) || index == count()); |
| 161 delegate_->WillAddWebState(web_state); |
| 162 |
| 156 web_state_wrappers_.insert(web_state_wrappers_.begin() + index, | 163 web_state_wrappers_.insert(web_state_wrappers_.begin() + index, |
| 157 base::MakeUnique<WebStateWrapper>(web_state)); | 164 base::MakeUnique<WebStateWrapper>(web_state)); |
| 158 | 165 |
| 159 if (active_index_ >= index) | 166 if (active_index_ >= index) |
| 160 ++active_index_; | 167 ++active_index_; |
| 161 | 168 |
| 162 if (opener) | 169 if (opener) |
| 163 SetOpenerOfWebStateAt(index, opener); | 170 SetOpenerOfWebStateAt(index, opener); |
| 164 | 171 |
| 165 for (auto& observer : observers_) | 172 for (auto& observer : observers_) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 207 } |
| 201 | 208 |
| 202 for (auto& observer : observers_) | 209 for (auto& observer : observers_) |
| 203 observer.WebStateMoved(this, web_state, from_index, to_index); | 210 observer.WebStateMoved(this, web_state, from_index, to_index); |
| 204 } | 211 } |
| 205 | 212 |
| 206 web::WebState* WebStateList::ReplaceWebStateAt(int index, | 213 web::WebState* WebStateList::ReplaceWebStateAt(int index, |
| 207 web::WebState* web_state, | 214 web::WebState* web_state, |
| 208 web::WebState* opener) { | 215 web::WebState* opener) { |
| 209 DCHECK(ContainsIndex(index)); | 216 DCHECK(ContainsIndex(index)); |
| 217 delegate_->WillAddWebState(web_state); |
| 218 |
| 210 ClearOpenersReferencing(index); | 219 ClearOpenersReferencing(index); |
| 211 | 220 |
| 212 auto& web_state_wrapper = web_state_wrappers_[index]; | 221 auto& web_state_wrapper = web_state_wrappers_[index]; |
| 213 web::WebState* old_web_state = web_state_wrapper->ReplaceWebState(web_state); | 222 web::WebState* old_web_state = web_state_wrapper->ReplaceWebState(web_state); |
| 214 | 223 |
| 215 if (opener && opener != old_web_state) | 224 if (opener && opener != old_web_state) |
| 216 SetOpenerOfWebStateAt(index, opener); | 225 SetOpenerOfWebStateAt(index, opener); |
| 217 | 226 |
| 218 for (auto& observer : observers_) | 227 for (auto& observer : observers_) |
| 219 observer.WebStateReplacedAt(this, old_web_state, web_state, index); | 228 observer.WebStateReplacedAt(this, old_web_state, web_state, index); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } else if (found_index != kInvalidIndex) { | 312 } else if (found_index != kInvalidIndex) { |
| 304 return found_index; | 313 return found_index; |
| 305 } | 314 } |
| 306 } | 315 } |
| 307 | 316 |
| 308 return found_index; | 317 return found_index; |
| 309 } | 318 } |
| 310 | 319 |
| 311 // static | 320 // static |
| 312 const int WebStateList::kInvalidIndex; | 321 const int WebStateList::kInvalidIndex; |
| OLD | NEW |