| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 765 |
| 766 - (NSInteger)indexOfEntryForDelta:(int)delta { | 766 - (NSInteger)indexOfEntryForDelta:(int)delta { |
| 767 NSInteger result = _currentNavigationIndex; | 767 NSInteger result = _currentNavigationIndex; |
| 768 if (delta < 0) { | 768 if (delta < 0) { |
| 769 if (_transientEntry) { | 769 if (_transientEntry) { |
| 770 // Going back from transient entry is a matter of discarding it and there | 770 // Going back from transient entry is a matter of discarding it and there |
| 771 // is no need to move navigation index back. | 771 // is no need to move navigation index back. |
| 772 delta++; | 772 delta++; |
| 773 } | 773 } |
| 774 | 774 |
| 775 while (delta < 0) { | 775 while (delta < 0 && result > 0) { |
| 776 // To stop the user getting 'stuck' on redirecting pages they weren't | 776 // To stop the user getting 'stuck' on redirecting pages they weren't |
| 777 // even aware existed, it is necessary to pass over pages that would | 777 // even aware existed, it is necessary to pass over pages that would |
| 778 // immediately result in a redirect (the entry *before* the redirected | 778 // immediately result in a redirect (the entry *before* the redirected |
| 779 // page). | 779 // page). |
| 780 while (result > 0 && [self isRedirectTransitionForEntryAtIndex:result]) { | 780 while (result > 0 && [self isRedirectTransitionForEntryAtIndex:result]) { |
| 781 --result; | 781 --result; |
| 782 } | 782 } |
| 783 --result; | 783 --result; |
| 784 ++delta; | 784 ++delta; |
| 785 } | 785 } |
| 786 // Result may be out of bounds, so stop trying to skip redirect items and |
| 787 // simply add the remainder. |
| 788 result += delta; |
| 786 } else if (delta > 0) { | 789 } else if (delta > 0) { |
| 787 NSInteger count = static_cast<NSInteger>([_entries count]); | 790 NSInteger count = static_cast<NSInteger>([_entries count]); |
| 788 if (_pendingEntry && _pendingEntryIndex == -1) { | 791 if (_pendingEntry && _pendingEntryIndex == -1) { |
| 789 // Chrome for iOS does not allow forward navigation if there is another | 792 // Chrome for iOS does not allow forward navigation if there is another |
| 790 // pending navigation in progress. Returning invalid index indicates that | 793 // pending navigation in progress. Returning invalid index indicates that |
| 791 // forward navigation will not be allowed (and |NSNotFound| works for | 794 // forward navigation will not be allowed (and |NSNotFound| works for |
| 792 // that). This is different from other platforms which allow forward | 795 // that). This is different from other platforms which allow forward |
| 793 // navigation if pending entry exist. | 796 // navigation if pending entry exist. |
| 794 // TODO(crbug.com/661858): Remove this once back-forward navigation uses | 797 // TODO(crbug.com/661858): Remove this once back-forward navigation uses |
| 795 // pending index. | 798 // pending index. |
| 796 return NSNotFound; | 799 return NSNotFound; |
| 797 } | 800 } |
| 798 | 801 |
| 799 while (delta > 0) { | 802 while (delta > 0 && result < count) { |
| 800 ++result; | 803 ++result; |
| 801 --delta; | 804 --delta; |
| 802 // As with going back, skip over redirects. | 805 // As with going back, skip over redirects. |
| 803 while (result + 1 < count && | 806 while (result + 1 < count && |
| 804 [self isRedirectTransitionForEntryAtIndex:result + 1]) { | 807 [self isRedirectTransitionForEntryAtIndex:result + 1]) { |
| 805 ++result; | 808 ++result; |
| 806 } | 809 } |
| 807 } | 810 } |
| 811 // Result may be out of bounds, so stop trying to skip redirect items and |
| 812 // simply add the remainder. |
| 813 result += delta; |
| 808 } | 814 } |
| 809 | 815 |
| 810 return result; | 816 return result; |
| 811 } | 817 } |
| 812 | 818 |
| 813 #pragma mark - | 819 #pragma mark - |
| 814 #pragma mark Private methods | 820 #pragma mark Private methods |
| 815 | 821 |
| 816 - (NSString*)uniqueID { | 822 - (NSString*)uniqueID { |
| 817 CFUUIDRef uuidRef = CFUUIDCreate(NULL); | 823 CFUUIDRef uuidRef = CFUUIDCreate(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 858 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
| 853 } | 859 } |
| 854 | 860 |
| 855 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { | 861 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { |
| 856 ui::PageTransition transition = | 862 ui::PageTransition transition = |
| 857 [_entries[index] navigationItem]->GetTransitionType(); | 863 [_entries[index] navigationItem]->GetTransitionType(); |
| 858 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 864 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 859 } | 865 } |
| 860 | 866 |
| 861 @end | 867 @end |
| OLD | NEW |