| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 [session_controller_ setNavigationManager:this]; | 97 [session_controller_ setNavigationManager:this]; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void NavigationManagerImpl::InitializeSession() { | 100 void NavigationManagerImpl::InitializeSession() { |
| 101 SetSessionController( | 101 SetSessionController( |
| 102 [[CRWSessionController alloc] initWithBrowserState:browser_state_]); | 102 [[CRWSessionController alloc] initWithBrowserState:browser_state_]); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void NavigationManagerImpl::ReplaceSessionHistory( | 105 void NavigationManagerImpl::ReplaceSessionHistory( |
| 106 std::vector<std::unique_ptr<web::NavigationItem>> items, | 106 std::vector<std::unique_ptr<web::NavigationItem>> items, |
| 107 int current_index) { | 107 int lastCommittedItemIndex) { |
| 108 SetSessionController([[CRWSessionController alloc] | 108 SetSessionController([[CRWSessionController alloc] |
| 109 initWithBrowserState:browser_state_ | 109 initWithBrowserState:browser_state_ |
| 110 navigationItems:std::move(items) | 110 navigationItems:std::move(items) |
| 111 currentIndex:current_index]); | 111 lastCommittedItemIndex:lastCommittedItemIndex]); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void NavigationManagerImpl::SetFacadeDelegate( | 114 void NavigationManagerImpl::SetFacadeDelegate( |
| 115 NavigationManagerFacadeDelegate* facade_delegate) { | 115 NavigationManagerFacadeDelegate* facade_delegate) { |
| 116 facade_delegate_ = facade_delegate; | 116 facade_delegate_ = facade_delegate; |
| 117 } | 117 } |
| 118 | 118 |
| 119 NavigationManagerFacadeDelegate* NavigationManagerImpl::GetFacadeDelegate() | 119 NavigationManagerFacadeDelegate* NavigationManagerImpl::GetFacadeDelegate() |
| 120 const { | 120 const { |
| 121 return facade_delegate_; | 121 return facade_delegate_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 132 delegate_->OnNavigationItemChanged(); | 132 delegate_->OnNavigationItemChanged(); |
| 133 | 133 |
| 134 if (facade_delegate_) | 134 if (facade_delegate_) |
| 135 facade_delegate_->OnNavigationItemChanged(); | 135 facade_delegate_->OnNavigationItemChanged(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void NavigationManagerImpl::OnNavigationItemCommitted() { | 138 void NavigationManagerImpl::OnNavigationItemCommitted() { |
| 139 LoadCommittedDetails details; | 139 LoadCommittedDetails details; |
| 140 details.item = GetLastCommittedItem(); | 140 details.item = GetLastCommittedItem(); |
| 141 DCHECK(details.item); | 141 DCHECK(details.item); |
| 142 details.previous_item_index = [session_controller_ previousNavigationIndex]; | 142 details.previous_item_index = [session_controller_ previousItemIndex]; |
| 143 if (details.previous_item_index >= 0) { | 143 if (details.previous_item_index >= 0) { |
| 144 DCHECK([session_controller_ previousItem]); | 144 DCHECK([session_controller_ previousItem]); |
| 145 details.previous_url = [session_controller_ previousItem]->GetURL(); | 145 details.previous_url = [session_controller_ previousItem]->GetURL(); |
| 146 details.is_in_page = | 146 details.is_in_page = |
| 147 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); | 147 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); |
| 148 } else { | 148 } else { |
| 149 details.previous_url = GURL(); | 149 details.previous_url = GURL(); |
| 150 details.is_in_page = NO; | 150 details.is_in_page = NO; |
| 151 } | 151 } |
| 152 | 152 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 | 269 |
| 270 int NavigationManagerImpl::GetItemCount() const { | 270 int NavigationManagerImpl::GetItemCount() const { |
| 271 return [session_controller_ items].size(); | 271 return [session_controller_ items].size(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { | 274 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { |
| 275 return [session_controller_ itemAtIndex:index]; | 275 return [session_controller_ itemAtIndex:index]; |
| 276 } | 276 } |
| 277 | 277 |
| 278 int NavigationManagerImpl::GetCurrentItemIndex() const { | |
| 279 return [session_controller_ currentNavigationIndex]; | |
| 280 } | |
| 281 | |
| 282 int NavigationManagerImpl::GetPendingItemIndex() const { | 278 int NavigationManagerImpl::GetPendingItemIndex() const { |
| 283 if (GetPendingItem()) { | 279 if (GetPendingItem()) { |
| 284 if ([session_controller_ pendingItemIndex] != -1) { | 280 if ([session_controller_ pendingItemIndex] != -1) { |
| 285 return [session_controller_ pendingItemIndex]; | 281 return [session_controller_ pendingItemIndex]; |
| 286 } | 282 } |
| 287 // TODO(crbug.com/665189): understand why current item index is | 283 // TODO(crbug.com/665189): understand why last committed item index is |
| 288 // returned here. | 284 // returned here. |
| 289 return GetCurrentItemIndex(); | 285 return GetLastCommittedItemIndex(); |
| 290 } | 286 } |
| 291 return -1; | 287 return -1; |
| 292 } | 288 } |
| 293 | 289 |
| 294 int NavigationManagerImpl::GetLastCommittedItemIndex() const { | 290 int NavigationManagerImpl::GetLastCommittedItemIndex() const { |
| 295 if (GetItemCount() == 0) | 291 if (GetItemCount() == 0) |
| 296 return -1; | 292 return -1; |
| 297 return [session_controller_ currentNavigationIndex]; | 293 return [session_controller_ lastCommittedItemIndex]; |
| 298 } | 294 } |
| 299 | 295 |
| 300 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { | 296 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { |
| 301 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) | 297 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) |
| 302 return false; | 298 return false; |
| 303 | 299 |
| 304 if (index < 0 || index >= GetItemCount()) | 300 if (index < 0 || index >= GetItemCount()) |
| 305 return false; | 301 return false; |
| 306 | 302 |
| 307 [session_controller_ removeItemAtIndex:index]; | 303 [session_controller_ removeItemAtIndex:index]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 NavigationManagerImpl::GetTransientURLRewriters() { | 358 NavigationManagerImpl::GetTransientURLRewriters() { |
| 363 return std::move(transient_url_rewriters_); | 359 return std::move(transient_url_rewriters_); |
| 364 } | 360 } |
| 365 | 361 |
| 366 void NavigationManagerImpl::RemoveTransientURLRewriters() { | 362 void NavigationManagerImpl::RemoveTransientURLRewriters() { |
| 367 transient_url_rewriters_.reset(); | 363 transient_url_rewriters_.reset(); |
| 368 } | 364 } |
| 369 | 365 |
| 370 int NavigationManagerImpl::GetIndexForOffset(int offset) const { | 366 int NavigationManagerImpl::GetIndexForOffset(int offset) const { |
| 371 int result = [session_controller_ pendingItemIndex] == -1 | 367 int result = [session_controller_ pendingItemIndex] == -1 |
| 372 ? GetCurrentItemIndex() | 368 ? GetLastCommittedItemIndex() |
| 373 : static_cast<int>([session_controller_ pendingItemIndex]); | 369 : static_cast<int>([session_controller_ pendingItemIndex]); |
| 374 | 370 |
| 375 if (offset < 0) { | 371 if (offset < 0) { |
| 376 if (GetTransientItem() && [session_controller_ pendingItemIndex] == -1) { | 372 if (GetTransientItem() && [session_controller_ pendingItemIndex] == -1) { |
| 377 // Going back from transient item that added to the end navigation stack | 373 // Going back from transient item that added to the end navigation stack |
| 378 // is a matter of discarding it as there is no need to move navigation | 374 // is a matter of discarding it as there is no need to move navigation |
| 379 // index back. | 375 // index back. |
| 380 offset++; | 376 offset++; |
| 381 } | 377 } |
| 382 | 378 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 435 |
| 440 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 436 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 441 DCHECK_GT(index, 0); | 437 DCHECK_GT(index, 0); |
| 442 DCHECK_LT(index, GetItemCount()); | 438 DCHECK_LT(index, GetItemCount()); |
| 443 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 439 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 444 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 440 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 445 } | 441 } |
| 446 | 442 |
| 447 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() | 443 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() |
| 448 const { | 444 const { |
| 449 int index = GetCurrentItemIndex(); | 445 int index = GetLastCommittedItemIndex(); |
| 450 if (index == -1) | 446 if (index == -1) |
| 451 return nullptr; | 447 return nullptr; |
| 452 WebClient* client = GetWebClient(); | 448 WebClient* client = GetWebClient(); |
| 453 const ScopedNavigationItemImplList& items = [session_controller_ items]; | 449 const ScopedNavigationItemImplList& items = [session_controller_ items]; |
| 454 while (index >= 0) { | 450 while (index >= 0) { |
| 455 NavigationItem* item = items[index--].get(); | 451 NavigationItem* item = items[index--].get(); |
| 456 if (!client->IsAppSpecificURL(item->GetVirtualURL())) | 452 if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
| 457 return item; | 453 return item; |
| 458 } | 454 } |
| 459 return nullptr; | 455 return nullptr; |
| 460 } | 456 } |
| 461 | 457 |
| 462 } // namespace web | 458 } // namespace web |
| OLD | NEW |