Chromium Code Reviews| Index: ios/web/navigation/crw_session_controller.mm |
| diff --git a/ios/web/navigation/crw_session_controller.mm b/ios/web/navigation/crw_session_controller.mm |
| index bc03108a4936197276c2be68fbb8f7273fa23784..a373120d0d30786cd9cf5ff86bb96f2fb17017e9 100644 |
| --- a/ios/web/navigation/crw_session_controller.mm |
| +++ b/ios/web/navigation/crw_session_controller.mm |
| @@ -77,7 +77,7 @@ @interface CRWSessionController () { |
| // If |YES|, override |currentEntry.useDesktopUserAgent| and create the |
| // pending entry using the desktop user agent. |
| - BOOL _useDesktopUserAgentForNextPendingEntry; |
| + BOOL _useDesktopUserAgentForNextPendingItem; |
| // The browser state associated with this CRWSessionController; |
| web::BrowserState* _browserState; // weak |
| @@ -107,9 +107,9 @@ @interface CRWSessionController () { |
| - (NSString*)uniqueID; |
| // Removes all entries after currentNavigationIndex_. |
| -- (void)clearForwardEntries; |
| +- (void)clearForwardItems; |
| // Discards the transient entry, if any. |
| -- (void)discardTransientEntry; |
| +- (void)discardTransientItem; |
| // Create a new autoreleased session entry. |
| - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| referrer:(const web::Referrer&)referrer |
| @@ -118,7 +118,9 @@ - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| rendererInitiated:(BOOL)rendererInitiated; |
| // Returns YES if the PageTransition for the underlying navigationItem at |
| // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
| -- (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index; |
| +- (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; |
| +// Returns a NavigationItemList containing the NavigationItems from |entries|. |
| +- (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; |
| @end |
| @implementation CRWSessionController |
| @@ -126,7 +128,7 @@ @implementation CRWSessionController |
| @synthesize tabId = _tabId; |
| @synthesize currentNavigationIndex = _currentNavigationIndex; |
| @synthesize previousNavigationIndex = _previousNavigationIndex; |
| -@synthesize pendingEntryIndex = _pendingEntryIndex; |
| +@synthesize pendingItemIndex = _pendingItemIndex; |
| @synthesize entries = _entries; |
| @synthesize windowName = _windowName; |
| @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
| @@ -152,7 +154,7 @@ - (id)initWithWindowName:(NSString*)windowName |
| _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
| _currentNavigationIndex = -1; |
| _previousNavigationIndex = -1; |
| - _pendingEntryIndex = -1; |
| + _pendingItemIndex = -1; |
| _sessionCertificatePolicyManager = |
| [[CRWSessionCertificatePolicyManager alloc] init]; |
| } |
| @@ -185,7 +187,7 @@ - (id)initWithNavigationItems: |
| self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; |
| } |
| _previousNavigationIndex = -1; |
| - _pendingEntryIndex = -1; |
| + _pendingItemIndex = -1; |
| _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
| _sessionCertificatePolicyManager = |
| [[CRWSessionCertificatePolicyManager alloc] init]; |
| @@ -202,7 +204,7 @@ - (id)copyWithZone:(NSZone*)zone { |
| copy.windowName = self.windowName; |
| copy->_currentNavigationIndex = _currentNavigationIndex; |
| copy->_previousNavigationIndex = _previousNavigationIndex; |
| - copy->_pendingEntryIndex = _pendingEntryIndex; |
| + copy->_pendingItemIndex = _pendingItemIndex; |
| copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
| copy->_entries = |
| [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
| @@ -219,13 +221,13 @@ - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { |
| } |
| } |
| -- (void)setPendingEntryIndex:(NSInteger)index { |
| +- (void)setPendingItemIndex:(NSInteger)index { |
| DCHECK_GE(index, -1); |
| DCHECK_LT(index, static_cast<NSInteger>(_entries.count)); |
| - _pendingEntryIndex = index; |
| + _pendingItemIndex = index; |
| CRWSessionEntry* entry = index != -1 ? _entries[index] : nil; |
| _pendingEntry.reset(entry); |
| - DCHECK(_pendingEntryIndex == -1 || _pendingEntry); |
| + DCHECK(_pendingItemIndex == -1 || _pendingEntry); |
| } |
| - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { |
| @@ -241,6 +243,12 @@ - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { |
| } |
| } |
| +- (void)setBrowserState:(web::BrowserState*)browserState { |
| + _browserState = browserState; |
| + DCHECK(!_navigationManager || |
| + _navigationManager->GetBrowserState() == _browserState); |
| +} |
| + |
| - (NSString*)description { |
| return [NSString |
| stringWithFormat: |
| @@ -248,10 +256,50 @@ - (NSString*)description { |
| @"\nprevious index: %" PRIdNS @"\npending index: %" PRIdNS |
| @"\n%@\npending: %@\ntransient: %@\n", |
| _tabId, self.windowName, _lastVisitedTimestamp, |
| - _currentNavigationIndex, _previousNavigationIndex, _pendingEntryIndex, |
| + _currentNavigationIndex, _previousNavigationIndex, _pendingItemIndex, |
| _entries, _pendingEntry.get(), _transientEntry.get()]; |
| } |
| +- (web::NavigationItemList)items { |
| + return [self itemListForEntryList:self.entries]; |
| +} |
| + |
| +- (web::NavigationItemImpl*)currentItem { |
| + return self.currentEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)visibleItem { |
| + return self.visibleEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)pendingItem { |
| + return self.pendingEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)transientItem { |
| + return self.transientEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)lastCommittedItem { |
| + return self.lastCommittedEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)previousItem { |
| + return self.previousEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemImpl*)lastUserItem { |
| + return self.lastUserEntry.navigationItemImpl; |
| +} |
| + |
| +- (web::NavigationItemList)backwardItems { |
| + return [self itemListForEntryList:self.backwardEntries]; |
| +} |
| + |
| +- (web::NavigationItemList)forwardItems { |
| + return [self itemListForEntryList:self.forwardEntries]; |
| +} |
| + |
| // Returns the current entry in the session list, or the pending entry if there |
| // is a navigation in progress. |
| - (CRWSessionEntry*)currentEntry { |
| @@ -272,7 +320,7 @@ - (CRWSessionEntry*)visibleEntry { |
| web::NavigationItemImpl* pendingItem = [_pendingEntry navigationItemImpl]; |
| bool safeToShowPending = pendingItem && |
| !pendingItem->is_renderer_initiated() && |
| - _pendingEntryIndex == -1; |
| + _pendingItemIndex == -1; |
| if (safeToShowPending) { |
| return _pendingEntry.get(); |
| } |
| @@ -300,12 +348,12 @@ - (CRWSessionEntry*)previousEntry { |
| return [_entries objectAtIndex:_previousNavigationIndex]; |
| } |
| -- (void)addPendingEntry:(const GURL&)url |
| - referrer:(const web::Referrer&)ref |
| - transition:(ui::PageTransition)trans |
| - rendererInitiated:(BOOL)rendererInitiated { |
| - [self discardTransientEntry]; |
| - _pendingEntryIndex = -1; |
| +- (void)addPendingItem:(const GURL&)url |
| + referrer:(const web::Referrer&)ref |
| + transition:(ui::PageTransition)trans |
| + rendererInitiated:(BOOL)rendererInitiated { |
| + [self discardTransientItem]; |
| + _pendingItemIndex = -1; |
| // Don't create a new entry if it's already the same as the current entry, |
| // allowing this routine to be called multiple times in a row without issue. |
| @@ -335,10 +383,10 @@ - (void)addPendingEntry:(const GURL&)url |
| } |
| BOOL useDesktopUserAgent = |
| - _useDesktopUserAgentForNextPendingEntry || |
| + _useDesktopUserAgentForNextPendingItem || |
| (self.currentEntry.navigationItem && |
| self.currentEntry.navigationItem->IsOverridingUserAgent()); |
| - _useDesktopUserAgentForNextPendingEntry = NO; |
| + _useDesktopUserAgentForNextPendingItem = NO; |
| _pendingEntry.reset([self sessionEntryWithURL:url |
| referrer:ref |
| transition:trans |
| @@ -350,7 +398,7 @@ - (void)addPendingEntry:(const GURL&)url |
| } |
| } |
| -- (void)updatePendingEntry:(const GURL&)url { |
| +- (void)updatePendingItem:(const GURL&)url { |
| // If there is no pending entry, navigation is probably happening within the |
| // session history. Don't modify the entry list. |
| if (!_pendingEntry) |
| @@ -361,7 +409,7 @@ - (void)updatePendingEntry:(const GURL&)url { |
| // Assume a redirection, and discard any transient entry. |
| // TODO(stuartmorgan): Once the current safe browsing code is gone, |
| // consider making this a DCHECK that there's no transient entry. |
| - [self discardTransientEntry]; |
| + [self discardTransientItem]; |
| item->SetURL(url); |
| item->SetVirtualURL(url); |
| @@ -378,35 +426,35 @@ - (void)updatePendingEntry:(const GURL&)url { |
| } |
| } |
| -- (void)clearForwardEntries { |
| - DCHECK_EQ(_pendingEntryIndex, -1); |
| - [self discardTransientEntry]; |
| +- (void)clearForwardItems { |
| + DCHECK_EQ(_pendingItemIndex, -1); |
| + [self discardTransientItem]; |
| - NSInteger forwardEntryStartIndex = _currentNavigationIndex + 1; |
| - DCHECK(forwardEntryStartIndex >= 0); |
| + NSInteger forwardItemStartIndex = _currentNavigationIndex + 1; |
| + DCHECK(forwardItemStartIndex >= 0); |
| - if (forwardEntryStartIndex >= static_cast<NSInteger>([_entries count])) |
| + if (forwardItemStartIndex >= static_cast<NSInteger>([_entries count])) |
| return; |
| - NSRange remove = NSMakeRange(forwardEntryStartIndex, |
| - [_entries count] - forwardEntryStartIndex); |
| + NSRange remove = NSMakeRange(forwardItemStartIndex, |
| + [_entries count] - forwardItemStartIndex); |
| // Store removed items in temporary NSArray so they can be deallocated after |
| // their facades. |
| base::scoped_nsobject<NSArray> removedItems( |
| [_entries subarrayWithRange:remove]); |
| [_entries removeObjectsInRange:remove]; |
| - if (_previousNavigationIndex >= forwardEntryStartIndex) |
| + if (_previousNavigationIndex >= forwardItemStartIndex) |
| _previousNavigationIndex = -1; |
| if (_navigationManager) { |
| _navigationManager->OnNavigationItemsPruned(remove.length); |
| } |
| } |
| -- (void)commitPendingEntry { |
| +- (void)commitPendingItem { |
| if (_pendingEntry) { |
| - NSInteger newNavigationIndex = _pendingEntryIndex; |
| - if (_pendingEntryIndex == -1) { |
| - [self clearForwardEntries]; |
| + NSInteger newNavigationIndex = _pendingItemIndex; |
| + if (_pendingItemIndex == -1) { |
| + [self clearForwardItems]; |
| // Add the new entry at the end. |
| [_entries addObject:_pendingEntry]; |
| newNavigationIndex = [_entries count] - 1; |
| @@ -417,7 +465,7 @@ - (void)commitPendingEntry { |
| // the implementation in NavigationController.) |
| [_pendingEntry navigationItemImpl]->ResetForCommit(); |
| _pendingEntry.reset(); |
| - _pendingEntryIndex = -1; |
| + _pendingItemIndex = -1; |
| } |
| CRWSessionEntry* currentEntry = self.currentEntry; |
| @@ -428,10 +476,10 @@ - (void)commitPendingEntry { |
| if (_navigationManager && item) |
| _navigationManager->OnNavigationItemCommitted(); |
| - DCHECK_EQ(_pendingEntryIndex, -1); |
| + DCHECK_EQ(_pendingItemIndex, -1); |
| } |
| -- (void)addTransientEntryWithURL:(const GURL&)URL { |
| +- (void)addTransientItemWithURL:(const GURL&)URL { |
| _transientEntry.reset([self |
| sessionEntryWithURL:URL |
| referrer:web::Referrer() |
| @@ -445,9 +493,9 @@ - (void)addTransientEntryWithURL:(const GURL&)URL { |
| _timeSmoother.GetSmoothedTime(base::Time::Now())); |
| } |
| -- (void)pushNewEntryWithURL:(const GURL&)URL |
| - stateObject:(NSString*)stateObject |
| - transition:(ui::PageTransition)transition { |
| +- (void)pushNewItemWithURL:(const GURL&)URL |
| + stateObject:(NSString*)stateObject |
| + transition:(ui::PageTransition)transition { |
| DCHECK(![self pendingEntry]); |
| DCHECK([self currentEntry]); |
| web::NavigationItem* item = [self currentEntry].navigationItem; |
| @@ -468,7 +516,7 @@ - (void)pushNewEntryWithURL:(const GURL&)URL |
| web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); |
| pushedEntry.get().navigationItem->GetSSL() = sslStatus; |
| - [self clearForwardEntries]; |
| + [self clearForwardItems]; |
| // Add the new entry at the end. |
| [_entries addObject:pushedEntry]; |
| _previousNavigationIndex = _currentNavigationIndex; |
| @@ -478,8 +526,8 @@ - (void)pushNewEntryWithURL:(const GURL&)URL |
| _navigationManager->OnNavigationItemCommitted(); |
| } |
| -- (void)updateCurrentEntryWithURL:(const GURL&)url |
| - stateObject:(NSString*)stateObject { |
| +- (void)updateCurrentItemWithURL:(const GURL&)url |
| + stateObject:(NSString*)stateObject { |
| DCHECK(!_transientEntry); |
| CRWSessionEntry* currentEntry = self.currentEntry; |
| web::NavigationItemImpl* currentItem = self.currentEntry.navigationItemImpl; |
| @@ -493,13 +541,13 @@ - (void)updateCurrentEntryWithURL:(const GURL&)url |
| _navigationManager->OnNavigationItemChanged(); |
| } |
| -- (void)discardNonCommittedEntries { |
| - [self discardTransientEntry]; |
| +- (void)discardNonCommittedItems { |
| + [self discardTransientItem]; |
| _pendingEntry.reset(); |
| - _pendingEntryIndex = -1; |
| + _pendingItemIndex = -1; |
| } |
| -- (void)discardTransientEntry { |
| +- (void)discardTransientItem { |
| // Keep the entry alive temporarily. There are flows that get the current |
| // entry, do some navigation operation, and then try to use that old current |
| // entry; since navigations clear the transient entry, these flows might |
| @@ -508,10 +556,6 @@ - (void)discardTransientEntry { |
| _transientEntry.reset(); |
| } |
| -- (BOOL)hasPendingEntry { |
| - return _pendingEntry != nil; |
| -} |
| - |
| - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession { |
| DCHECK(sourceSession); |
| self.windowName = sourceSession.windowName; |
| @@ -533,23 +577,23 @@ - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession { |
| _previousNavigationIndex = -1; |
| _currentNavigationIndex += lastIndexToCopy + 1; |
| - if (_pendingEntryIndex != -1) |
| - _pendingEntryIndex += lastIndexToCopy + 1; |
| + if (_pendingItemIndex != -1) |
| + _pendingItemIndex += lastIndexToCopy + 1; |
| DCHECK_LT(static_cast<NSUInteger>(_currentNavigationIndex), _entries.count); |
| - DCHECK(_pendingEntryIndex == -1 || _pendingEntry); |
| + DCHECK(_pendingItemIndex == -1 || _pendingEntry); |
| } |
| -- (void)goToEntryAtIndex:(NSInteger)index { |
| +- (void)goToItemAtIndex:(NSInteger)index { |
| if (index < 0 || static_cast<NSUInteger>(index) >= _entries.count) |
| return; |
| if (index < _currentNavigationIndex) { |
| // Going back. |
| - [self discardNonCommittedEntries]; |
| + [self discardNonCommittedItems]; |
| } else if (_currentNavigationIndex < index) { |
| // Going forward. |
| - [self discardTransientEntry]; |
| + [self discardTransientItem]; |
| } else { |
| // |delta| is 0, no need to change current navigation index. |
| return; |
| @@ -559,12 +603,12 @@ - (void)goToEntryAtIndex:(NSInteger)index { |
| _currentNavigationIndex = index; |
| } |
| -- (void)removeEntryAtIndex:(NSInteger)index { |
| +- (void)removeItemAtIndex:(NSInteger)index { |
| DCHECK(index < static_cast<NSInteger>([_entries count])); |
| DCHECK(index != _currentNavigationIndex); |
| DCHECK(index >= 0); |
| - [self discardNonCommittedEntries]; |
| + [self discardNonCommittedItems]; |
| [_entries removeObjectAtIndex:index]; |
| if (_currentNavigationIndex > index) |
| @@ -576,7 +620,7 @@ - (void)removeEntryAtIndex:(NSInteger)index { |
| - (NSArray*)backwardEntries { |
| NSMutableArray* entries = [NSMutableArray array]; |
| for (NSInteger index = _currentNavigationIndex; index > 0; --index) { |
| - if (![self isRedirectTransitionForEntryAtIndex:index]) |
| + if (![self isRedirectTransitionForItemAtIndex:index]) |
| [entries addObject:_entries[index - 1]]; |
| } |
| return entries; |
| @@ -596,12 +640,12 @@ - (NSArray*)forwardEntries { |
| return entries; |
| } |
| -- (BOOL)isSameDocumentNavigationBetweenEntry:(CRWSessionEntry*)firstEntry |
| - andEntry:(CRWSessionEntry*)secondEntry { |
| - if (!firstEntry || !secondEntry || firstEntry == secondEntry) |
| +- (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem |
| + andItem:(web::NavigationItem*)secondItem { |
| + if (!firstItem || !secondItem || firstItem == secondItem) |
| return NO; |
| - NSUInteger firstIndex = [_entries indexOfObject:firstEntry]; |
| - NSUInteger secondIndex = [_entries indexOfObject:secondEntry]; |
| + NSUInteger firstIndex = [self indexOfItem:firstItem]; |
| + NSUInteger secondIndex = [self indexOfItem:secondItem]; |
| if (firstIndex == NSNotFound || secondIndex == NSNotFound) |
| return NO; |
| NSUInteger startIndex = firstIndex < secondIndex ? firstIndex : secondIndex; |
| @@ -615,8 +659,8 @@ - (BOOL)isSameDocumentNavigationBetweenEntry:(CRWSessionEntry*)firstEntry |
| return NO; |
| // Every entry in the sequence has to have a URL that could have been |
| // created from a pushState() call. |
| - if (!web::history_state_util::IsHistoryStateChangeValid( |
| - firstEntry.navigationItem->GetURL(), item->GetURL())) |
| + if (!web::history_state_util::IsHistoryStateChangeValid(firstItem->GetURL(), |
| + item->GetURL())) |
| return NO; |
| } |
| return YES; |
| @@ -629,17 +673,26 @@ - (CRWSessionEntry*)lastUserEntry { |
| NSInteger index = _currentNavigationIndex; |
| // This will return the first session entry if all other entries are |
| // redirects, regardless of the transition state of the first entry. |
| - while (index > 0 && [self isRedirectTransitionForEntryAtIndex:index]) { |
| + while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) { |
| --index; |
| } |
| return [_entries objectAtIndex:index]; |
| } |
| -- (void)useDesktopUserAgentForNextPendingEntry { |
| +- (void)useDesktopUserAgentForNextPendingItem { |
| if (_pendingEntry) |
| [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true); |
| else |
| - _useDesktopUserAgentForNextPendingEntry = YES; |
| + _useDesktopUserAgentForNextPendingItem = YES; |
| +} |
| + |
| +- (NSInteger)indexOfItem:(web::NavigationItem*)item { |
| + web::NavigationItemList items = self.items; |
| + for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { |
| + if (items[i] == item) |
| + return i; |
| + } |
| + return NSNotFound; |
| } |
| #pragma mark - |
| @@ -685,10 +738,17 @@ - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
| } |
| -- (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { |
| +- (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index { |
| ui::PageTransition transition = |
| [_entries[index] navigationItem]->GetTransitionType(); |
| return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| } |
| +- (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { |
| + web::NavigationItemList list; |
|
Eugene But (OOO till 7-30)
2017/02/03 23:33:33
nit: pass entries.count into constructor?
kkhorimoto
2017/02/04 02:45:30
Done.
|
| + for (CRWSessionEntry* entry in entries) |
| + list.push_back(entry.navigationItem); |
|
Eugene But (OOO till 7-30)
2017/02/03 23:33:33
emplace_back ?
kkhorimoto
2017/02/04 02:45:30
|emplace_back| passes its input parameters to the
|
| + return list; |
| +} |
| + |
| @end |