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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" | 11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
| 12 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h" |
12 #import "ios/web/public/navigation_manager.h" | 13 #import "ios/web/public/navigation_manager.h" |
13 #import "ios/web/public/web_state/web_state.h" | 14 #import "ios/web/public/web_state/web_state.h" |
14 | 15 |
15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
17 #endif | 18 #endif |
18 | 19 |
19 // Wrapper around a WebState stored in a WebStateList. May own the WebState | 20 // Wrapper around a WebState stored in a WebStateList. May own the WebState |
20 // dependending on the WebStateList ownership setting (should always be true | 21 // dependending on the WebStateList ownership setting (should always be true |
21 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). | 22 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 if (opener_ != opener) | 89 if (opener_ != opener) |
89 return false; | 90 return false; |
90 | 91 |
91 if (!use_group) | 92 if (!use_group) |
92 return true; | 93 return true; |
93 | 94 |
94 return opener_last_committed_index_ == opener_navigation_index; | 95 return opener_last_committed_index_ == opener_navigation_index; |
95 } | 96 } |
96 | 97 |
97 WebStateList::WebStateList(WebStateOwnership ownership) | 98 WebStateList::WebStateList(WebStateOwnership ownership) |
98 : web_state_ownership_(ownership) {} | 99 : web_state_ownership_(ownership), |
| 100 order_controller_(base::MakeUnique<WebStateListOrderController>(this)) {} |
99 | 101 |
100 WebStateList::~WebStateList() = default; | 102 WebStateList::~WebStateList() = default; |
101 | 103 |
102 bool WebStateList::ContainsIndex(int index) const { | 104 bool WebStateList::ContainsIndex(int index) const { |
103 return 0 <= index && index < count(); | 105 return 0 <= index && index < count(); |
104 } | 106 } |
105 | 107 |
106 web::WebState* WebStateList::GetWebStateAt(int index) const { | 108 web::WebState* WebStateList::GetWebStateAt(int index) const { |
107 DCHECK(ContainsIndex(index)); | 109 DCHECK(ContainsIndex(index)); |
108 return web_state_wrappers_[index]->web_state(); | 110 return web_state_wrappers_[index]->web_state(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 base::MakeUnique<WebStateWrapper>(web_state, | 150 base::MakeUnique<WebStateWrapper>(web_state, |
149 web_state_ownership_ == WebStateOwned)); | 151 web_state_ownership_ == WebStateOwned)); |
150 | 152 |
151 if (opener) | 153 if (opener) |
152 SetOpenerOfWebStateAt(index, opener); | 154 SetOpenerOfWebStateAt(index, opener); |
153 | 155 |
154 for (auto& observer : observers_) | 156 for (auto& observer : observers_) |
155 observer.WebStateInsertedAt(this, web_state, index); | 157 observer.WebStateInsertedAt(this, web_state, index); |
156 } | 158 } |
157 | 159 |
| 160 void WebStateList::AppendWebState(ui::PageTransition transition, |
| 161 web::WebState* web_state, |
| 162 web::WebState* opener) { |
| 163 int index = order_controller_->DetermineInsertionIndex(transition, opener); |
| 164 if (index < 0 || count() < index) |
| 165 index = count(); |
| 166 |
| 167 InsertWebState(index, web_state, opener); |
| 168 } |
| 169 |
158 void WebStateList::MoveWebStateAt(int from_index, int to_index) { | 170 void WebStateList::MoveWebStateAt(int from_index, int to_index) { |
159 DCHECK(ContainsIndex(from_index)); | 171 DCHECK(ContainsIndex(from_index)); |
160 DCHECK(ContainsIndex(to_index)); | 172 DCHECK(ContainsIndex(to_index)); |
161 if (from_index == to_index) | 173 if (from_index == to_index) |
162 return; | 174 return; |
163 | 175 |
164 std::unique_ptr<WebStateWrapper> web_state_wrapper = | 176 std::unique_ptr<WebStateWrapper> web_state_wrapper = |
165 std::move(web_state_wrappers_[from_index]); | 177 std::move(web_state_wrappers_[from_index]); |
166 web::WebState* web_state = web_state_wrapper->web_state(); | 178 web::WebState* web_state = web_state_wrapper->web_state(); |
167 web_state_wrappers_.erase(web_state_wrappers_.begin() + from_index); | 179 web_state_wrappers_.erase(web_state_wrappers_.begin() + from_index); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } else if (found_index != kInvalidIndex) { | 249 } else if (found_index != kInvalidIndex) { |
238 return found_index; | 250 return found_index; |
239 } | 251 } |
240 } | 252 } |
241 | 253 |
242 return found_index; | 254 return found_index; |
243 } | 255 } |
244 | 256 |
245 // static | 257 // static |
246 const int WebStateList::kInvalidIndex; | 258 const int WebStateList::kInvalidIndex; |
OLD | NEW |