| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 629 |
| 630 - (void)goBack { | 630 - (void)goBack { |
| 631 [self goDelta:-1]; | 631 [self goDelta:-1]; |
| 632 } | 632 } |
| 633 | 633 |
| 634 - (void)goForward { | 634 - (void)goForward { |
| 635 [self goDelta:1]; | 635 [self goDelta:1]; |
| 636 } | 636 } |
| 637 | 637 |
| 638 - (void)goDelta:(int)delta { | 638 - (void)goDelta:(int)delta { |
| 639 if (delta == 0 || ![self canGoDelta:delta]) | 639 if (delta != 0 && [self canGoDelta:delta]) { |
| 640 return; | 640 NSInteger newNavigationIndex = [self indexOfEntryForDelta:delta]; |
| 641 | 641 [self goToEntry:_entries[newNavigationIndex]]; |
| 642 NSInteger oldNavigationIndex = self.currentNavigationIndex; | |
| 643 NSInteger newNavigationIndex = [self indexOfEntryForDelta:delta]; | |
| 644 | |
| 645 if (delta < 0) { | |
| 646 [self discardNonCommittedEntries]; | |
| 647 for (int i = delta; i < 0; i++) { | |
| 648 base::RecordAction(UserMetricsAction("Back")); | |
| 649 } | |
| 650 } else if (delta > 0) { | |
| 651 [self discardTransientEntry]; | |
| 652 for (int i = 0; i < delta; i++) { | |
| 653 base::RecordAction(UserMetricsAction("Forward")); | |
| 654 } | |
| 655 } | 642 } |
| 656 | |
| 657 _currentNavigationIndex = newNavigationIndex; | |
| 658 _previousNavigationIndex = oldNavigationIndex; | |
| 659 } | 643 } |
| 660 | 644 |
| 661 - (void)goToEntry:(CRWSessionEntry*)entry { | 645 - (void)goToEntry:(CRWSessionEntry*)entry { |
| 662 DCHECK(entry); | 646 DCHECK(entry); |
| 647 if (![_entries containsObject:entry]) |
| 648 return; |
| 663 | 649 |
| 664 [self discardTransientEntry]; | 650 NSInteger newNavigationIndex = [_entries indexOfObject:entry]; |
| 651 NSInteger delta = newNavigationIndex - _currentNavigationIndex; |
| 652 if (delta < 0) { |
| 653 for (int i = delta; i < 0; i++) { |
| 654 base::RecordAction(UserMetricsAction("Back")); |
| 655 } |
| 656 [self discardNonCommittedEntries]; |
| 657 } else if (0 < delta) { |
| 658 for (int i = 0; i < delta; i++) { |
| 659 base::RecordAction(UserMetricsAction("Forward")); |
| 660 } |
| 661 [self discardTransientEntry]; |
| 662 } else { |
| 663 // delta is 0, no need to change current navigation index. |
| 664 return; |
| 665 } |
| 665 | 666 |
| 666 // Check that |entries_| still contains |entry|. |entry| could have been | 667 _previousNavigationIndex = _currentNavigationIndex; |
| 667 // removed by -clearForwardEntries. | 668 _currentNavigationIndex = newNavigationIndex; |
| 668 if ([_entries containsObject:entry]) { | |
| 669 _previousNavigationIndex = self.currentNavigationIndex; | |
| 670 self.currentNavigationIndex = [_entries indexOfObject:entry]; | |
| 671 } | |
| 672 } | 669 } |
| 673 | 670 |
| 674 - (void)removeEntryAtIndex:(NSInteger)index { | 671 - (void)removeEntryAtIndex:(NSInteger)index { |
| 675 DCHECK(index < static_cast<NSInteger>([_entries count])); | 672 DCHECK(index < static_cast<NSInteger>([_entries count])); |
| 676 DCHECK(index != _currentNavigationIndex); | 673 DCHECK(index != _currentNavigationIndex); |
| 677 DCHECK(index >= 0); | 674 DCHECK(index >= 0); |
| 678 | 675 |
| 679 [self discardNonCommittedEntries]; | 676 [self discardNonCommittedEntries]; |
| 680 | 677 |
| 681 [_entries removeObjectAtIndex:index]; | 678 [_entries removeObjectAtIndex:index]; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 item->set_is_renderer_initiated(rendererInitiated); | 878 item->set_is_renderer_initiated(rendererInitiated); |
| 882 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 879 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
| 883 } | 880 } |
| 884 | 881 |
| 885 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { | 882 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { |
| 886 ui::PageTransition transition = [self transitionForIndex:index]; | 883 ui::PageTransition transition = [self transitionForIndex:index]; |
| 887 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 884 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 888 } | 885 } |
| 889 | 886 |
| 890 @end | 887 @end |
| OLD | NEW |