| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/web/navigation/navigation_manager_impl.h" | 5 #import "ios/web/navigation/navigation_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (facade_delegate_) | 133 if (facade_delegate_) |
| 134 facade_delegate_->OnNavigationItemChanged(); | 134 facade_delegate_->OnNavigationItemChanged(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void NavigationManagerImpl::OnNavigationItemCommitted() { | 137 void NavigationManagerImpl::OnNavigationItemCommitted() { |
| 138 LoadCommittedDetails details; | 138 LoadCommittedDetails details; |
| 139 details.item = GetLastCommittedItem(); | 139 details.item = GetLastCommittedItem(); |
| 140 DCHECK(details.item); | 140 DCHECK(details.item); |
| 141 details.previous_item_index = [session_controller_ previousNavigationIndex]; | 141 details.previous_item_index = [session_controller_ previousNavigationIndex]; |
| 142 if (details.previous_item_index >= 0) { | 142 if (details.previous_item_index >= 0) { |
| 143 DCHECK(GetPreviousItem()); | 143 DCHECK([session_controller_ previousItem]); |
| 144 details.previous_url = GetPreviousItem()->GetURL(); | 144 details.previous_url = [session_controller_ previousItem]->GetURL(); |
| 145 details.is_in_page = | 145 details.is_in_page = |
| 146 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); | 146 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); |
| 147 } else { | 147 } else { |
| 148 details.previous_url = GURL(); | 148 details.previous_url = GURL(); |
| 149 details.is_in_page = NO; | 149 details.is_in_page = NO; |
| 150 } | 150 } |
| 151 | 151 |
| 152 delegate_->OnNavigationItemCommitted(details); | 152 delegate_->OnNavigationItemCommitted(details); |
| 153 | 153 |
| 154 if (facade_delegate_) { | 154 if (facade_delegate_) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (use_desktop_user_agent) | 212 if (use_desktop_user_agent) |
| 213 pending_item->SetUserAgentType(UserAgentType::DESKTOP); | 213 pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
| 214 } | 214 } |
| 215 override_desktop_user_agent_for_next_pending_item_ = false; | 215 override_desktop_user_agent_for_next_pending_item_ = false; |
| 216 } | 216 } |
| 217 | 217 |
| 218 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 218 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
| 219 return [session_controller_ lastUserItem]; | 219 return [session_controller_ lastUserItem]; |
| 220 } | 220 } |
| 221 | 221 |
| 222 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | |
| 223 return [session_controller_ previousItem]; | |
| 224 } | |
| 225 | |
| 226 NavigationItemList NavigationManagerImpl::GetItems() const { | 222 NavigationItemList NavigationManagerImpl::GetItems() const { |
| 227 return [session_controller_ items]; | 223 return [session_controller_ items]; |
| 228 } | 224 } |
| 229 | 225 |
| 230 BrowserState* NavigationManagerImpl::GetBrowserState() const { | 226 BrowserState* NavigationManagerImpl::GetBrowserState() const { |
| 231 return browser_state_; | 227 return browser_state_; |
| 232 } | 228 } |
| 233 | 229 |
| 234 WebState* NavigationManagerImpl::GetWebState() const { | 230 WebState* NavigationManagerImpl::GetWebState() const { |
| 235 return delegate_->GetWebState(); | 231 return delegate_->GetWebState(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 BrowserURLRewriter::URLRewriter rewriter) { | 264 BrowserURLRewriter::URLRewriter rewriter) { |
| 269 DCHECK(rewriter); | 265 DCHECK(rewriter); |
| 270 if (!transient_url_rewriters_) { | 266 if (!transient_url_rewriters_) { |
| 271 transient_url_rewriters_.reset( | 267 transient_url_rewriters_.reset( |
| 272 new std::vector<BrowserURLRewriter::URLRewriter>()); | 268 new std::vector<BrowserURLRewriter::URLRewriter>()); |
| 273 } | 269 } |
| 274 transient_url_rewriters_->push_back(rewriter); | 270 transient_url_rewriters_->push_back(rewriter); |
| 275 } | 271 } |
| 276 | 272 |
| 277 int NavigationManagerImpl::GetItemCount() const { | 273 int NavigationManagerImpl::GetItemCount() const { |
| 278 return GetItems().size(); | 274 return [session_controller_ itemCount]; |
| 279 } | 275 } |
| 280 | 276 |
| 281 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { | 277 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { |
| 282 NavigationItemList items = GetItems(); | 278 return [session_controller_ itemAtIndex:index]; |
| 283 return index < items.size() ? items[index] : nullptr; | |
| 284 } | 279 } |
| 285 | 280 |
| 286 int NavigationManagerImpl::GetCurrentItemIndex() const { | 281 int NavigationManagerImpl::GetCurrentItemIndex() const { |
| 287 return [session_controller_ currentNavigationIndex]; | 282 return [session_controller_ currentNavigationIndex]; |
| 288 } | 283 } |
| 289 | 284 |
| 290 int NavigationManagerImpl::GetPendingItemIndex() const { | 285 int NavigationManagerImpl::GetPendingItemIndex() const { |
| 291 if (GetPendingItem()) { | 286 if (GetPendingItem()) { |
| 292 if ([session_controller_ pendingItemIndex] != -1) { | 287 if ([session_controller_ pendingItemIndex] != -1) { |
| 293 return [session_controller_ pendingItemIndex]; | 288 return [session_controller_ pendingItemIndex]; |
| 294 } | 289 } |
| 295 // TODO(crbug.com/665189): understand why current item index is | 290 // TODO(crbug.com/665189): understand why current item index is |
| 296 // returned here. | 291 // returned here. |
| 297 return GetCurrentItemIndex(); | 292 return GetCurrentItemIndex(); |
| 298 } | 293 } |
| 299 return -1; | 294 return -1; |
| 300 } | 295 } |
| 301 | 296 |
| 302 int NavigationManagerImpl::GetLastCommittedItemIndex() const { | 297 int NavigationManagerImpl::GetLastCommittedItemIndex() const { |
| 303 if (GetItems().empty()) | 298 if (GetItemCount() == 0) |
| 304 return -1; | 299 return -1; |
| 305 return [session_controller_ currentNavigationIndex]; | 300 return [session_controller_ currentNavigationIndex]; |
| 306 } | 301 } |
| 307 | 302 |
| 308 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { | 303 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { |
| 309 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) | 304 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) |
| 310 return false; | 305 return false; |
| 311 | 306 |
| 312 size_t idx = static_cast<size_t>(index); | 307 if (index < 0 || index >= GetItemCount()) |
| 313 if (idx >= GetItems().size()) | |
| 314 return false; | 308 return false; |
| 315 | 309 |
| 316 [session_controller_ removeItemAtIndex:index]; | 310 [session_controller_ removeItemAtIndex:index]; |
| 317 return true; | 311 return true; |
| 318 } | 312 } |
| 319 | 313 |
| 320 bool NavigationManagerImpl::CanGoBack() const { | 314 bool NavigationManagerImpl::CanGoBack() const { |
| 321 return CanGoToOffset(-1); | 315 return CanGoToOffset(-1); |
| 322 } | 316 } |
| 323 | 317 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 NavigationItemList items = [session_controller_ items]; | 449 NavigationItemList items = [session_controller_ items]; |
| 456 while (index >= 0) { | 450 while (index >= 0) { |
| 457 NavigationItem* item = items[index--]; | 451 NavigationItem* item = items[index--]; |
| 458 if (!client->IsAppSpecificURL(item->GetVirtualURL())) | 452 if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
| 459 return item; | 453 return item; |
| 460 } | 454 } |
| 461 return nullptr; | 455 return nullptr; |
| 462 } | 456 } |
| 463 | 457 |
| 464 } // namespace web | 458 } // namespace web |
| OLD | NEW |