Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: ios/web/navigation/crw_session_controller.mm

Issue 2915303002: Added NavigationManager::GetIndexOfItem(). (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 _previousItemIndex--; 592 _previousItemIndex--;
593 593
594 if (_navigationManager) 594 if (_navigationManager)
595 _navigationManager->OnNavigationItemsPruned(1U); 595 _navigationManager->OnNavigationItemsPruned(1U);
596 } 596 }
597 597
598 - (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem 598 - (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem
599 andItem:(web::NavigationItem*)secondItem { 599 andItem:(web::NavigationItem*)secondItem {
600 if (!firstItem || !secondItem || firstItem == secondItem) 600 if (!firstItem || !secondItem || firstItem == secondItem)
601 return NO; 601 return NO;
602 NSUInteger firstIndex = [self indexOfItem:firstItem]; 602 int firstIndex = [self indexOfItem:firstItem];
603 NSUInteger secondIndex = [self indexOfItem:secondItem]; 603 int secondIndex = [self indexOfItem:secondItem];
604 if (firstIndex == NSNotFound || secondIndex == NSNotFound) 604 if (firstIndex == -1 || secondIndex == -1)
605 return NO; 605 return NO;
606 NSUInteger startIndex = firstIndex < secondIndex ? firstIndex : secondIndex; 606 int startIndex = firstIndex < secondIndex ? firstIndex : secondIndex;
607 NSUInteger endIndex = firstIndex < secondIndex ? secondIndex : firstIndex; 607 int endIndex = firstIndex < secondIndex ? secondIndex : firstIndex;
608 608
609 for (NSUInteger i = startIndex + 1; i <= endIndex; i++) { 609 for (int i = startIndex + 1; i <= endIndex; i++) {
610 web::NavigationItemImpl* item = self.items[i].get(); 610 web::NavigationItemImpl* item = self.items[i].get();
611 // Every item in the sequence has to be created from a hash change or 611 // Every item in the sequence has to be created from a hash change or
612 // pushState() call. 612 // pushState() call.
613 if (!item->IsCreatedFromPushState() && !item->IsCreatedFromHashChange()) 613 if (!item->IsCreatedFromPushState() && !item->IsCreatedFromHashChange())
614 return NO; 614 return NO;
615 // Every item in the sequence has to have a URL that could have been 615 // Every item in the sequence has to have a URL that could have been
616 // created from a pushState() call. 616 // created from a pushState() call.
617 if (!web::history_state_util::IsHistoryStateChangeValid(firstItem->GetURL(), 617 if (!web::history_state_util::IsHistoryStateChangeValid(firstItem->GetURL(),
618 item->GetURL())) 618 item->GetURL()))
619 return NO; 619 return NO;
620 } 620 }
621 return YES; 621 return YES;
622 } 622 }
623 623
624 - (NSInteger)indexOfItem:(const web::NavigationItem*)item { 624 - (int)indexOfItem:(const web::NavigationItem*)item {
625 DCHECK(item); 625 DCHECK(item);
626 for (size_t index = 0; index < self.items.size(); ++index) { 626 for (size_t index = 0; index < self.items.size(); ++index) {
627 if (self.items[index].get() == item) 627 if (self.items[index].get() == item)
628 return index; 628 return index;
629 } 629 }
630 return NSNotFound; 630 return -1;
631 } 631 }
632 632
633 - (web::NavigationItemImpl*)itemAtIndex:(NSInteger)index { 633 - (web::NavigationItemImpl*)itemAtIndex:(NSInteger)index {
634 if (index < 0 || self.items.size() <= static_cast<NSUInteger>(index)) 634 if (index < 0 || self.items.size() <= static_cast<NSUInteger>(index))
635 return nullptr; 635 return nullptr;
636 return self.items[index].get(); 636 return self.items[index].get();
637 } 637 }
638 638
639 #pragma mark - 639 #pragma mark -
640 #pragma mark Private methods 640 #pragma mark Private methods
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 return item; 684 return item;
685 } 685 }
686 686
687 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { 687 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index {
688 DCHECK_LT(index, self.items.size()); 688 DCHECK_LT(index, self.items.size());
689 ui::PageTransition transition = self.items[index]->GetTransitionType(); 689 ui::PageTransition transition = self.items[index]->GetTransitionType();
690 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; 690 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO;
691 } 691 }
692 692
693 @end 693 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/crw_session_controller.h ('k') | ios/web/navigation/navigation_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698