| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (facade_delegate_) | 132 if (facade_delegate_) |
| 133 facade_delegate_->OnNavigationItemChanged(); | 133 facade_delegate_->OnNavigationItemChanged(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void NavigationManagerImpl::OnNavigationItemCommitted() { | 136 void NavigationManagerImpl::OnNavigationItemCommitted() { |
| 137 LoadCommittedDetails details; | 137 LoadCommittedDetails details; |
| 138 details.item = GetLastCommittedItem(); | 138 details.item = GetLastCommittedItem(); |
| 139 DCHECK(details.item); | 139 DCHECK(details.item); |
| 140 details.previous_item_index = [session_controller_ previousNavigationIndex]; | 140 details.previous_item_index = [session_controller_ previousNavigationIndex]; |
| 141 if (details.previous_item_index >= 0) { | 141 if (details.previous_item_index >= 0) { |
| 142 DCHECK(GetPreviousItem()); | 142 DCHECK([session_controller_ previousItem]); |
| 143 details.previous_url = GetPreviousItem()->GetURL(); | 143 details.previous_url = [session_controller_ previousItem]->GetURL(); |
| 144 details.is_in_page = | 144 details.is_in_page = |
| 145 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); | 145 AreURLsInPageNavigation(details.previous_url, details.item->GetURL()); |
| 146 } else { | 146 } else { |
| 147 details.previous_url = GURL(); | 147 details.previous_url = GURL(); |
| 148 details.is_in_page = NO; | 148 details.is_in_page = NO; |
| 149 } | 149 } |
| 150 | 150 |
| 151 delegate_->OnNavigationItemCommitted(details); | 151 delegate_->OnNavigationItemCommitted(details); |
| 152 | 152 |
| 153 if (facade_delegate_) { | 153 if (facade_delegate_) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 GetLastCommittedItem()->IsOverridingUserAgent()); | 186 GetLastCommittedItem()->IsOverridingUserAgent()); |
| 187 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); | 187 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); |
| 188 override_desktop_user_agent_for_next_pending_item_ = false; | 188 override_desktop_user_agent_for_next_pending_item_ = false; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 192 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
| 193 return [session_controller_ lastUserItem]; | 193 return [session_controller_ lastUserItem]; |
| 194 } | 194 } |
| 195 | 195 |
| 196 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | |
| 197 return [session_controller_ previousItem]; | |
| 198 } | |
| 199 | |
| 200 NavigationItemList NavigationManagerImpl::GetItems() const { | 196 NavigationItemList NavigationManagerImpl::GetItems() const { |
| 201 return [session_controller_ items]; | 197 return [session_controller_ items]; |
| 202 } | 198 } |
| 203 | 199 |
| 204 BrowserState* NavigationManagerImpl::GetBrowserState() const { | 200 BrowserState* NavigationManagerImpl::GetBrowserState() const { |
| 205 return browser_state_; | 201 return browser_state_; |
| 206 } | 202 } |
| 207 | 203 |
| 208 WebState* NavigationManagerImpl::GetWebState() const { | 204 WebState* NavigationManagerImpl::GetWebState() const { |
| 209 return delegate_->GetWebState(); | 205 return delegate_->GetWebState(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 BrowserURLRewriter::URLRewriter rewriter) { | 238 BrowserURLRewriter::URLRewriter rewriter) { |
| 243 DCHECK(rewriter); | 239 DCHECK(rewriter); |
| 244 if (!transient_url_rewriters_) { | 240 if (!transient_url_rewriters_) { |
| 245 transient_url_rewriters_.reset( | 241 transient_url_rewriters_.reset( |
| 246 new std::vector<BrowserURLRewriter::URLRewriter>()); | 242 new std::vector<BrowserURLRewriter::URLRewriter>()); |
| 247 } | 243 } |
| 248 transient_url_rewriters_->push_back(rewriter); | 244 transient_url_rewriters_->push_back(rewriter); |
| 249 } | 245 } |
| 250 | 246 |
| 251 int NavigationManagerImpl::GetItemCount() const { | 247 int NavigationManagerImpl::GetItemCount() const { |
| 252 return GetItems().size(); | 248 return [session_controller_ itemCount]; |
| 253 } | 249 } |
| 254 | 250 |
| 255 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { | 251 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { |
| 256 NavigationItemList items = GetItems(); | 252 return [session_controller_ itemAtIndex:index]; |
| 257 return index < items.size() ? items[index] : nullptr; | |
| 258 } | 253 } |
| 259 | 254 |
| 260 int NavigationManagerImpl::GetCurrentItemIndex() const { | 255 int NavigationManagerImpl::GetCurrentItemIndex() const { |
| 261 return [session_controller_ currentNavigationIndex]; | 256 return [session_controller_ currentNavigationIndex]; |
| 262 } | 257 } |
| 263 | 258 |
| 264 int NavigationManagerImpl::GetPendingItemIndex() const { | 259 int NavigationManagerImpl::GetPendingItemIndex() const { |
| 265 if (GetPendingItem()) { | 260 if (GetPendingItem()) { |
| 266 if ([session_controller_ pendingItemIndex] != -1) { | 261 if ([session_controller_ pendingItemIndex] != -1) { |
| 267 return [session_controller_ pendingItemIndex]; | 262 return [session_controller_ pendingItemIndex]; |
| 268 } | 263 } |
| 269 // TODO(crbug.com/665189): understand why current item index is | 264 // TODO(crbug.com/665189): understand why current item index is |
| 270 // returned here. | 265 // returned here. |
| 271 return GetCurrentItemIndex(); | 266 return GetCurrentItemIndex(); |
| 272 } | 267 } |
| 273 return -1; | 268 return -1; |
| 274 } | 269 } |
| 275 | 270 |
| 276 int NavigationManagerImpl::GetLastCommittedItemIndex() const { | 271 int NavigationManagerImpl::GetLastCommittedItemIndex() const { |
| 277 if (GetItems().empty()) | 272 if (GetItemCount() == 0) |
| 278 return -1; | 273 return -1; |
| 279 return [session_controller_ currentNavigationIndex]; | 274 return [session_controller_ currentNavigationIndex]; |
| 280 } | 275 } |
| 281 | 276 |
| 282 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { | 277 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { |
| 283 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) | 278 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) |
| 284 return false; | 279 return false; |
| 285 | 280 |
| 286 size_t idx = static_cast<size_t>(index); | 281 if (index < 0 || index >= GetItemCount()) |
| 287 if (idx >= GetItems().size()) | |
| 288 return false; | 282 return false; |
| 289 | 283 |
| 290 [session_controller_ removeItemAtIndex:index]; | 284 [session_controller_ removeItemAtIndex:index]; |
| 291 return true; | 285 return true; |
| 292 } | 286 } |
| 293 | 287 |
| 294 bool NavigationManagerImpl::CanGoBack() const { | 288 bool NavigationManagerImpl::CanGoBack() const { |
| 295 return CanGoToOffset(-1); | 289 return CanGoToOffset(-1); |
| 296 } | 290 } |
| 297 | 291 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 403 } |
| 410 | 404 |
| 411 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 405 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 412 DCHECK_GT(index, 0); | 406 DCHECK_GT(index, 0); |
| 413 DCHECK_LT(index, GetItemCount()); | 407 DCHECK_LT(index, GetItemCount()); |
| 414 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 408 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 415 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 409 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 416 } | 410 } |
| 417 | 411 |
| 418 } // namespace web | 412 } // namespace web |
| OLD | NEW |