| 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 #include "ios/web/navigation/navigation_manager_impl.h" | 5 #include "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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 ? GetCurrentItemIndex() | 343 ? GetCurrentItemIndex() |
| 344 : static_cast<int>([session_controller_ pendingEntryIndex]); | 344 : static_cast<int>([session_controller_ pendingEntryIndex]); |
| 345 | 345 |
| 346 if (offset < 0) { | 346 if (offset < 0) { |
| 347 if (GetTransientItem()) { | 347 if (GetTransientItem()) { |
| 348 // Going back from transient entry is a matter of discarding it and there | 348 // Going back from transient entry is a matter of discarding it and there |
| 349 // is no need to move navigation index back. | 349 // is no need to move navigation index back. |
| 350 offset++; | 350 offset++; |
| 351 } | 351 } |
| 352 | 352 |
| 353 while (offset < 0) { | 353 while (offset < 0 && result > 0) { |
| 354 // To stop the user getting 'stuck' on redirecting pages they weren't | 354 // To stop the user getting 'stuck' on redirecting pages they weren't |
| 355 // even aware existed, it is necessary to pass over pages that would | 355 // even aware existed, it is necessary to pass over pages that would |
| 356 // immediately result in a redirect (the entry *before* the redirected | 356 // immediately result in a redirect (the entry *before* the redirected |
| 357 // page). | 357 // page). |
| 358 while (result > 0 && IsRedirectItemAtIndex(result)) { | 358 while (result > 0 && IsRedirectItemAtIndex(result)) { |
| 359 --result; | 359 --result; |
| 360 } | 360 } |
| 361 --result; | 361 --result; |
| 362 ++offset; | 362 ++offset; |
| 363 } | 363 } |
| 364 // Result may be out of bounds, so stop trying to skip redirect items and |
| 365 // simply add the remainder. |
| 366 result += offset; |
| 367 if (result > GetItemCount() /* overflow */) |
| 368 result = INT_MIN; |
| 364 } else if (offset > 0) { | 369 } else if (offset > 0) { |
| 365 if (GetPendingItem() && [session_controller_ pendingEntryIndex] == -1) { | 370 if (GetPendingItem() && [session_controller_ pendingEntryIndex] == -1) { |
| 366 // Chrome for iOS does not allow forward navigation if there is another | 371 // Chrome for iOS does not allow forward navigation if there is another |
| 367 // pending navigation in progress. Returning invalid index indicates that | 372 // pending navigation in progress. Returning invalid index indicates that |
| 368 // forward navigation will not be allowed (and |INT_MAX| works for that). | 373 // forward navigation will not be allowed (and |INT_MAX| works for that). |
| 369 // This is different from other platforms which allow forward navigation | 374 // This is different from other platforms which allow forward navigation |
| 370 // if pending entry exist. | 375 // if pending entry exist. |
| 371 // TODO(crbug.com/661858): Remove this once back-forward navigation uses | 376 // TODO(crbug.com/661858): Remove this once back-forward navigation uses |
| 372 // pending index. | 377 // pending index. |
| 373 return INT_MAX; | 378 return INT_MAX; |
| 374 } | 379 } |
| 375 | 380 while (offset > 0 && result < GetItemCount()) { |
| 376 while (offset > 0) { | |
| 377 ++result; | 381 ++result; |
| 378 --offset; | 382 --offset; |
| 379 // As with going back, skip over redirects. | 383 // As with going back, skip over redirects. |
| 380 while (result + 1 < GetItemCount() && IsRedirectItemAtIndex(result + 1)) { | 384 while (result + 1 < GetItemCount() && IsRedirectItemAtIndex(result + 1)) { |
| 381 ++result; | 385 ++result; |
| 382 } | 386 } |
| 383 } | 387 } |
| 388 // Result may be out of bounds, so stop trying to skip redirect items and |
| 389 // simply add the remainder. |
| 390 result += offset; |
| 391 if (result < 0 /* overflow */) |
| 392 result = INT_MAX; |
| 384 } | 393 } |
| 385 | 394 |
| 386 return result; | 395 return result; |
| 387 } | 396 } |
| 388 | 397 |
| 389 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 398 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 390 DCHECK_GT(index, 0); | 399 DCHECK_GT(index, 0); |
| 391 DCHECK_LT(index, GetItemCount()); | 400 DCHECK_LT(index, GetItemCount()); |
| 392 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 401 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 393 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 402 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 394 } | 403 } |
| 395 | 404 |
| 396 } // namespace web | 405 } // namespace web |
| OLD | NEW |