| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) | 31 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." | 32 #error "This file requires ARC support." |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 @interface CRWSessionController () { | 35 @interface CRWSessionController () { |
| 36 // Weak pointer back to the owning NavigationManager. This is to facilitate | 36 // Weak pointer back to the owning NavigationManager. This is to facilitate |
| 37 // the incremental merging of the two classes. | 37 // the incremental merging of the two classes. |
| 38 web::NavigationManagerImpl* _navigationManager; | 38 web::NavigationManagerImpl* _navigationManager; |
| 39 | 39 |
| 40 // Identifies the index of the current navigation in the NavigationItem | 40 // Identifies the index of the last committed item in the items array. |
| 41 // array. | 41 NSInteger _lastCommittedItemIndex; |
| 42 NSInteger _currentNavigationIndex; | 42 // Identifies the index of the previous item in the items array. |
| 43 // Identifies the index of the previous navigation in the NavigationItem | 43 NSInteger _previousItemIndex; |
| 44 // array. | |
| 45 NSInteger _previousNavigationIndex; | |
| 46 | 44 |
| 47 // Stores the certificate policies decided by the user. | 45 // Stores the certificate policies decided by the user. |
| 48 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; | 46 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; |
| 49 | 47 |
| 50 // The browser state associated with this CRWSessionController; | 48 // The browser state associated with this CRWSessionController; |
| 51 web::BrowserState* _browserState; // weak | 49 web::BrowserState* _browserState; // weak |
| 52 | 50 |
| 53 // Time smoother for navigation item timestamps; see comment in | 51 // Time smoother for navigation item timestamps; see comment in |
| 54 // navigation_controller_impl.h | 52 // navigation_controller_impl.h |
| 55 web::TimeSmoother _timeSmoother; | 53 web::TimeSmoother _timeSmoother; |
| 56 | 54 |
| 57 // Backing objects for properties of the same name. | 55 // Backing objects for properties of the same name. |
| 58 web::ScopedNavigationItemImplList _items; | 56 web::ScopedNavigationItemImplList _items; |
| 59 // |_pendingItem| only contains a NavigationItem for non-history navigations. | 57 // |_pendingItem| only contains a NavigationItem for non-history navigations. |
| 60 // For back/forward navigations within session history, _pendingItemIndex will | 58 // For back/forward navigations within session history, _pendingItemIndex will |
| 61 // be an index within |_items|, and self.pendingItem will return the item at | 59 // be an index within |_items|, and self.pendingItem will return the item at |
| 62 // that index. | 60 // that index. |
| 63 std::unique_ptr<web::NavigationItemImpl> _pendingItem; | 61 std::unique_ptr<web::NavigationItemImpl> _pendingItem; |
| 64 std::unique_ptr<web::NavigationItemImpl> _transientItem; | 62 std::unique_ptr<web::NavigationItemImpl> _transientItem; |
| 65 } | 63 } |
| 66 | 64 |
| 67 // Redefine as readwrite. | 65 // Redefine as readwrite. |
| 68 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 66 @property(nonatomic, readwrite, assign) NSInteger lastCommittedItemIndex; |
| 69 | 67 |
| 70 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 68 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
| 71 // clang bug. crbug.com/228650 | 69 // clang bug. crbug.com/228650 |
| 72 @property(nonatomic, readwrite, strong) | 70 @property(nonatomic, readwrite, strong) |
| 73 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 71 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
| 74 | 72 |
| 75 // Expose setters for serialization properties. These are exposed in a category | 73 // Expose setters for serialization properties. These are exposed in a category |
| 76 // in SessionStorageBuilder, and will be removed as ownership of | 74 // in SessionStorageBuilder, and will be removed as ownership of |
| 77 // their backing ivars moves to NavigationManagerImpl. | 75 // their backing ivars moves to NavigationManagerImpl. |
| 78 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; | 76 @property(nonatomic, readwrite, assign) NSInteger previousItemIndex; |
| 79 | 77 |
| 80 // Removes all items after currentNavigationIndex_. | 78 // Removes all items after lastCommittedItemIndex. |
| 81 - (void)clearForwardItems; | 79 - (void)clearForwardItems; |
| 82 // Discards the transient item, if any. | 80 // Discards the transient item, if any. |
| 83 - (void)discardTransientItem; | 81 - (void)discardTransientItem; |
| 84 // Creates a NavigationItemImpl with the specified properties. | 82 // Creates a NavigationItemImpl with the specified properties. |
| 85 - (std::unique_ptr<web::NavigationItemImpl>) | 83 - (std::unique_ptr<web::NavigationItemImpl>) |
| 86 itemWithURL:(const GURL&)url | 84 itemWithURL:(const GURL&)url |
| 87 referrer:(const web::Referrer&)referrer | 85 referrer:(const web::Referrer&)referrer |
| 88 transition:(ui::PageTransition)transition | 86 transition:(ui::PageTransition)transition |
| 89 initiationType:(web::NavigationInitiationType)initiationType; | 87 initiationType:(web::NavigationInitiationType)initiationType; |
| 90 // Returns YES if the PageTransition for the underlying navigationItem at | 88 // Returns YES if the PageTransition for the underlying navigationItem at |
| 91 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. | 89 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
| 92 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index; | 90 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index; |
| 93 | 91 |
| 94 @end | 92 @end |
| 95 | 93 |
| 96 @implementation CRWSessionController | 94 @implementation CRWSessionController |
| 97 | 95 |
| 98 @synthesize currentNavigationIndex = _currentNavigationIndex; | 96 @synthesize lastCommittedItemIndex = _lastCommittedItemIndex; |
| 99 @synthesize previousNavigationIndex = _previousNavigationIndex; | 97 @synthesize previousItemIndex = _previousItemIndex; |
| 100 @synthesize pendingItemIndex = _pendingItemIndex; | 98 @synthesize pendingItemIndex = _pendingItemIndex; |
| 101 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 99 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 102 | 100 |
| 103 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState { | 101 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState { |
| 104 self = [super init]; | 102 self = [super init]; |
| 105 if (self) { | 103 if (self) { |
| 106 _browserState = browserState; | 104 _browserState = browserState; |
| 107 _currentNavigationIndex = -1; | 105 _lastCommittedItemIndex = -1; |
| 108 _previousNavigationIndex = -1; | 106 _previousItemIndex = -1; |
| 109 _pendingItemIndex = -1; | 107 _pendingItemIndex = -1; |
| 110 _sessionCertificatePolicyManager = | 108 _sessionCertificatePolicyManager = |
| 111 [[CRWSessionCertificatePolicyManager alloc] init]; | 109 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 112 } | 110 } |
| 113 return self; | 111 return self; |
| 114 } | 112 } |
| 115 | 113 |
| 116 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState | 114 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState |
| 117 navigationItems:(web::ScopedNavigationItemList)items | 115 navigationItems:(web::ScopedNavigationItemList)items |
| 118 currentIndex:(NSUInteger)currentIndex { | 116 lastCommittedItemIndex:(NSUInteger)lastCommittedItemIndex { |
| 119 self = [super init]; | 117 self = [super init]; |
| 120 if (self) { | 118 if (self) { |
| 121 _browserState = browserState; | 119 _browserState = browserState; |
| 122 _items = web::CreateScopedNavigationItemImplList(std::move(items)); | 120 _items = web::CreateScopedNavigationItemImplList(std::move(items)); |
| 123 _currentNavigationIndex = | 121 _lastCommittedItemIndex = |
| 124 std::min(static_cast<NSInteger>(currentIndex), | 122 std::min(static_cast<NSInteger>(lastCommittedItemIndex), |
| 125 static_cast<NSInteger>(_items.size()) - 1); | 123 static_cast<NSInteger>(_items.size()) - 1); |
| 126 _previousNavigationIndex = -1; | 124 _previousItemIndex = -1; |
| 127 _pendingItemIndex = -1; | 125 _pendingItemIndex = -1; |
| 128 _sessionCertificatePolicyManager = | 126 _sessionCertificatePolicyManager = |
| 129 [[CRWSessionCertificatePolicyManager alloc] init]; | 127 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 130 } | 128 } |
| 131 return self; | 129 return self; |
| 132 } | 130 } |
| 133 | 131 |
| 134 #pragma mark - Accessors | 132 #pragma mark - Accessors |
| 135 | 133 |
| 136 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { | 134 - (void)setLastCommittedItemIndex:(NSInteger)lastCommittedItemIndex { |
| 137 if (_currentNavigationIndex != currentNavigationIndex) { | 135 if (_lastCommittedItemIndex != lastCommittedItemIndex) { |
| 138 _currentNavigationIndex = currentNavigationIndex; | 136 _lastCommittedItemIndex = lastCommittedItemIndex; |
| 139 if (_navigationManager) | 137 if (_navigationManager) |
| 140 _navigationManager->RemoveTransientURLRewriters(); | 138 _navigationManager->RemoveTransientURLRewriters(); |
| 141 } | 139 } |
| 142 } | 140 } |
| 143 | 141 |
| 144 - (void)setPendingItemIndex:(NSInteger)pendingItemIndex { | 142 - (void)setPendingItemIndex:(NSInteger)pendingItemIndex { |
| 145 DCHECK_GE(pendingItemIndex, -1); | 143 DCHECK_GE(pendingItemIndex, -1); |
| 146 DCHECK_LT(pendingItemIndex, static_cast<NSInteger>(self.items.size())); | 144 DCHECK_LT(pendingItemIndex, static_cast<NSInteger>(self.items.size())); |
| 147 _pendingItemIndex = pendingItemIndex; | 145 _pendingItemIndex = pendingItemIndex; |
| 148 DCHECK(_pendingItemIndex == -1 || self.pendingItem); | 146 DCHECK(_pendingItemIndex == -1 || self.pendingItem); |
| 149 } | 147 } |
| 150 | 148 |
| 151 - (BOOL)canPruneAllButLastCommittedItem { | 149 - (BOOL)canPruneAllButLastCommittedItem { |
| 152 return self.currentNavigationIndex != -1 && self.pendingItemIndex == -1 && | 150 return self.lastCommittedItemIndex != -1 && self.pendingItemIndex == -1 && |
| 153 !self.transientItem; | 151 !self.transientItem; |
| 154 } | 152 } |
| 155 | 153 |
| 156 - (const web::ScopedNavigationItemImplList&)items { | 154 - (const web::ScopedNavigationItemImplList&)items { |
| 157 return _items; | 155 return _items; |
| 158 } | 156 } |
| 159 | 157 |
| 160 - (web::NavigationItemImpl*)currentItem { | 158 - (web::NavigationItemImpl*)currentItem { |
| 161 if (self.transientItem) | 159 if (self.transientItem) |
| 162 return self.transientItem; | 160 return self.transientItem; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 186 if (self.pendingItemIndex == -1) | 184 if (self.pendingItemIndex == -1) |
| 187 return _pendingItem.get(); | 185 return _pendingItem.get(); |
| 188 return self.items[self.pendingItemIndex].get(); | 186 return self.items[self.pendingItemIndex].get(); |
| 189 } | 187 } |
| 190 | 188 |
| 191 - (web::NavigationItemImpl*)transientItem { | 189 - (web::NavigationItemImpl*)transientItem { |
| 192 return _transientItem.get(); | 190 return _transientItem.get(); |
| 193 } | 191 } |
| 194 | 192 |
| 195 - (web::NavigationItemImpl*)lastCommittedItem { | 193 - (web::NavigationItemImpl*)lastCommittedItem { |
| 196 NSInteger index = self.currentNavigationIndex; | 194 NSInteger index = self.lastCommittedItemIndex; |
| 197 return index == -1 ? nullptr : self.items[index].get(); | 195 return index == -1 ? nullptr : self.items[index].get(); |
| 198 } | 196 } |
| 199 | 197 |
| 200 - (web::NavigationItemImpl*)previousItem { | 198 - (web::NavigationItemImpl*)previousItem { |
| 201 NSInteger index = self.previousNavigationIndex; | 199 NSInteger index = self.previousItemIndex; |
| 202 return index == -1 || self.items.empty() ? nullptr : self.items[index].get(); | 200 return index == -1 || self.items.empty() ? nullptr : self.items[index].get(); |
| 203 } | 201 } |
| 204 | 202 |
| 205 - (web::NavigationItemList)backwardItems { | 203 - (web::NavigationItemList)backwardItems { |
| 206 web::NavigationItemList items; | 204 web::NavigationItemList items; |
| 207 for (size_t index = _currentNavigationIndex; index > 0; --index) { | 205 for (size_t index = _lastCommittedItemIndex; index > 0; --index) { |
| 208 if (![self isRedirectTransitionForItemAtIndex:index]) | 206 if (![self isRedirectTransitionForItemAtIndex:index]) |
| 209 items.push_back(self.items[index - 1].get()); | 207 items.push_back(self.items[index - 1].get()); |
| 210 } | 208 } |
| 211 return items; | 209 return items; |
| 212 } | 210 } |
| 213 | 211 |
| 214 - (web::NavigationItemList)forwardItems { | 212 - (web::NavigationItemList)forwardItems { |
| 215 web::NavigationItemList items; | 213 web::NavigationItemList items; |
| 216 NSUInteger lastNonRedirectedIndex = _currentNavigationIndex + 1; | 214 NSUInteger lastNonRedirectedIndex = _lastCommittedItemIndex + 1; |
| 217 while (lastNonRedirectedIndex < self.items.size()) { | 215 while (lastNonRedirectedIndex < self.items.size()) { |
| 218 web::NavigationItem* item = self.items[lastNonRedirectedIndex].get(); | 216 web::NavigationItem* item = self.items[lastNonRedirectedIndex].get(); |
| 219 if (!ui::PageTransitionIsRedirect(item->GetTransitionType())) | 217 if (!ui::PageTransitionIsRedirect(item->GetTransitionType())) |
| 220 items.push_back(item); | 218 items.push_back(item); |
| 221 ++lastNonRedirectedIndex; | 219 ++lastNonRedirectedIndex; |
| 222 } | 220 } |
| 223 return items; | 221 return items; |
| 224 } | 222 } |
| 225 | 223 |
| 226 #pragma mark - NSObject | 224 #pragma mark - NSObject |
| (...skipping 17 matching lines...) Expand all Loading... |
| 244 #else | 242 #else |
| 245 if (self.pendingItem) { | 243 if (self.pendingItem) { |
| 246 pendingItemDescription = | 244 pendingItemDescription = |
| 247 [NSString stringWithFormat:@"%p", self.pendingItem]; | 245 [NSString stringWithFormat:@"%p", self.pendingItem]; |
| 248 } | 246 } |
| 249 if (self.transientItem) { | 247 if (self.transientItem) { |
| 250 transientItemDescription = | 248 transientItemDescription = |
| 251 [NSString stringWithFormat:@"%p", self.transientItem]; | 249 [NSString stringWithFormat:@"%p", self.transientItem]; |
| 252 } | 250 } |
| 253 #endif | 251 #endif |
| 254 return [NSString stringWithFormat:@"current index: %" PRIdNS | 252 return [NSString stringWithFormat:@"last committed item index: %" PRIdNS |
| 255 @"\nprevious index: %" PRIdNS | 253 @"\nprevious item index: %" PRIdNS |
| 256 @"\npending" | 254 @"\npending item index: %" PRIdNS |
| 257 @" index: %" PRIdNS | 255 @"\nall items: %@ \npending item: %@" |
| 258 @"\n%@\npending: %@\ntransient: %@\n", | 256 @"\ntransient item: %@\n", |
| 259 _currentNavigationIndex, | 257 _lastCommittedItemIndex, _previousItemIndex, |
| 260 _previousNavigationIndex, _pendingItemIndex, | 258 _pendingItemIndex, itemsDescription, |
| 261 itemsDescription, pendingItemDescription, | 259 pendingItemDescription, |
| 262 transientItemDescription]; | 260 transientItemDescription]; |
| 263 } | 261 } |
| 264 | 262 |
| 265 #pragma mark - Public | 263 #pragma mark - Public |
| 266 | 264 |
| 267 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { | 265 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { |
| 268 _navigationManager = navigationManager; | 266 _navigationManager = navigationManager; |
| 269 if (_navigationManager) { | 267 if (_navigationManager) { |
| 270 // _browserState will be nullptr if CRWSessionController has been | 268 // _browserState will be nullptr if CRWSessionController has been |
| 271 // initialized with -initWithCoder: method. Take _browserState from | 269 // initialized with -initWithCoder: method. Take _browserState from |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // This should probably not be sent if the URLs matched, but that's what was | 352 // This should probably not be sent if the URLs matched, but that's what was |
| 355 // done before, so preserve behavior in case something relies on it. | 353 // done before, so preserve behavior in case something relies on it. |
| 356 if (_navigationManager && _navigationManager->GetFacadeDelegate()) | 354 if (_navigationManager && _navigationManager->GetFacadeDelegate()) |
| 357 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 355 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
| 358 } | 356 } |
| 359 | 357 |
| 360 - (void)clearForwardItems { | 358 - (void)clearForwardItems { |
| 361 DCHECK_EQ(self.pendingItemIndex, -1); | 359 DCHECK_EQ(self.pendingItemIndex, -1); |
| 362 [self discardTransientItem]; | 360 [self discardTransientItem]; |
| 363 | 361 |
| 364 NSInteger forwardItemStartIndex = _currentNavigationIndex + 1; | 362 NSInteger forwardItemStartIndex = _lastCommittedItemIndex + 1; |
| 365 DCHECK(forwardItemStartIndex >= 0); | 363 DCHECK(forwardItemStartIndex >= 0); |
| 366 | 364 |
| 367 size_t itemCount = self.items.size(); | 365 size_t itemCount = self.items.size(); |
| 368 if (forwardItemStartIndex >= static_cast<NSInteger>(itemCount)) | 366 if (forwardItemStartIndex >= static_cast<NSInteger>(itemCount)) |
| 369 return; | 367 return; |
| 370 | 368 |
| 371 if (_previousNavigationIndex >= forwardItemStartIndex) | 369 if (_previousItemIndex >= forwardItemStartIndex) |
| 372 _previousNavigationIndex = -1; | 370 _previousItemIndex = -1; |
| 373 | 371 |
| 374 // Remove the NavigationItems and notify the NavigationManater | 372 // Remove the NavigationItems and notify the NavigationManater |
| 375 _items.erase(_items.begin() + forwardItemStartIndex, _items.end()); | 373 _items.erase(_items.begin() + forwardItemStartIndex, _items.end()); |
| 376 if (_navigationManager) { | 374 if (_navigationManager) { |
| 377 _navigationManager->OnNavigationItemsPruned(itemCount - | 375 _navigationManager->OnNavigationItemsPruned(itemCount - |
| 378 forwardItemStartIndex); | 376 forwardItemStartIndex); |
| 379 } | 377 } |
| 380 } | 378 } |
| 381 | 379 |
| 382 - (void)commitPendingItem { | 380 - (void)commitPendingItem { |
| 383 if (self.pendingItem) { | 381 if (self.pendingItem) { |
| 384 // Once an item is committed it's not renderer-initiated any more. (Matches | 382 // Once an item is committed it's not renderer-initiated any more. (Matches |
| 385 // the implementation in NavigationController.) | 383 // the implementation in NavigationController.) |
| 386 self.pendingItem->ResetForCommit(); | 384 self.pendingItem->ResetForCommit(); |
| 387 | 385 |
| 388 NSInteger newNavigationIndex = self.pendingItemIndex; | 386 NSInteger newItemIndex = self.pendingItemIndex; |
| 389 if (newNavigationIndex == -1) { | 387 if (newItemIndex == -1) { |
| 390 [self clearForwardItems]; | 388 [self clearForwardItems]; |
| 391 // Add the new item at the end. | 389 // Add the new item at the end. |
| 392 _items.push_back(std::move(_pendingItem)); | 390 _items.push_back(std::move(_pendingItem)); |
| 393 newNavigationIndex = self.items.size() - 1; | 391 newItemIndex = self.items.size() - 1; |
| 394 } | 392 } |
| 395 _previousNavigationIndex = _currentNavigationIndex; | 393 _previousItemIndex = _lastCommittedItemIndex; |
| 396 self.currentNavigationIndex = newNavigationIndex; | 394 self.lastCommittedItemIndex = newItemIndex; |
| 397 self.pendingItemIndex = -1; | 395 self.pendingItemIndex = -1; |
| 398 DCHECK(!_pendingItem); | 396 DCHECK(!_pendingItem); |
| 399 } | 397 } |
| 400 | 398 |
| 401 web::NavigationItem* item = self.currentItem; | 399 web::NavigationItem* item = self.currentItem; |
| 402 // Update the navigation timestamp now that it's actually happened. | 400 // Update the navigation timestamp now that it's actually happened. |
| 403 if (item) | 401 if (item) |
| 404 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); | 402 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); |
| 405 | 403 |
| 406 if (_navigationManager && item) | 404 if (_navigationManager && item) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 437 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 435 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 438 pushedItem->SetUserAgentType(lastCommittedItem->GetUserAgentType()); | 436 pushedItem->SetUserAgentType(lastCommittedItem->GetUserAgentType()); |
| 439 pushedItem->SetSerializedStateObject(stateObject); | 437 pushedItem->SetSerializedStateObject(stateObject); |
| 440 pushedItem->SetIsCreatedFromPushState(true); | 438 pushedItem->SetIsCreatedFromPushState(true); |
| 441 pushedItem->GetSSL() = lastCommittedItem->GetSSL(); | 439 pushedItem->GetSSL() = lastCommittedItem->GetSSL(); |
| 442 pushedItem->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); | 440 pushedItem->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); |
| 443 | 441 |
| 444 [self clearForwardItems]; | 442 [self clearForwardItems]; |
| 445 // Add the new item at the end. | 443 // Add the new item at the end. |
| 446 _items.push_back(std::move(pushedItem)); | 444 _items.push_back(std::move(pushedItem)); |
| 447 _previousNavigationIndex = _currentNavigationIndex; | 445 _previousItemIndex = _lastCommittedItemIndex; |
| 448 self.currentNavigationIndex = self.items.size() - 1; | 446 self.lastCommittedItemIndex = self.items.size() - 1; |
| 449 | 447 |
| 450 if (_navigationManager) | 448 if (_navigationManager) |
| 451 _navigationManager->OnNavigationItemCommitted(); | 449 _navigationManager->OnNavigationItemCommitted(); |
| 452 } | 450 } |
| 453 | 451 |
| 454 - (void)updateCurrentItemWithURL:(const GURL&)url | 452 - (void)updateCurrentItemWithURL:(const GURL&)url |
| 455 stateObject:(NSString*)stateObject { | 453 stateObject:(NSString*)stateObject { |
| 456 DCHECK(!self.transientItem); | 454 DCHECK(!self.transientItem); |
| 457 web::NavigationItemImpl* currentItem = self.currentItem; | 455 web::NavigationItemImpl* currentItem = self.currentItem; |
| 458 currentItem->SetURL(url); | 456 currentItem->SetURL(url); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 482 // The other session may not have any items, in which case there is nothing | 480 // The other session may not have any items, in which case there is nothing |
| 483 // to insert. | 481 // to insert. |
| 484 const web::ScopedNavigationItemImplList& sourceItems = source->_items; | 482 const web::ScopedNavigationItemImplList& sourceItems = source->_items; |
| 485 if (sourceItems.empty()) | 483 if (sourceItems.empty()) |
| 486 return; | 484 return; |
| 487 | 485 |
| 488 // Early return if there's no committed source item. | 486 // Early return if there's no committed source item. |
| 489 if (!source.lastCommittedItem) | 487 if (!source.lastCommittedItem) |
| 490 return; | 488 return; |
| 491 | 489 |
| 492 // Copy |sourceItems| into a new NavigationItemList. |mergedItems| is needs | 490 // Copy |sourceItems| into a new NavigationItemList. |mergedItems| needs to |
| 493 // to be large enough for all items in |source| preceding | 491 // be large enough for all items in |source| preceding |
| 494 // |sourceCurrentIndex|, the |source|'s current item, and |self|'s current | 492 // |sourceLastCommittedItemIndex|, the |source|'s current item, and |self|'s |
| 495 // item, which comes out to |sourceCurrentIndex| + 2. | 493 // current item, which comes out to |sourceCurrentIndex| + 2. |
| 496 DCHECK_GT(source.currentNavigationIndex, -1); | 494 DCHECK_GT(source.lastCommittedItemIndex, -1); |
| 497 size_t sourceCurrentIndex = | 495 size_t sourceLastCommittedItemIndex = |
| 498 static_cast<size_t>(source.currentNavigationIndex); | 496 static_cast<size_t>(source.lastCommittedItemIndex); |
| 499 web::ScopedNavigationItemImplList mergedItems(sourceCurrentIndex + 2); | 497 web::ScopedNavigationItemImplList mergedItems(sourceLastCommittedItemIndex + |
| 500 for (size_t index = 0; index <= sourceCurrentIndex; ++index) { | 498 2); |
| 499 for (size_t index = 0; index <= sourceLastCommittedItemIndex; ++index) { |
| 501 mergedItems[index] = | 500 mergedItems[index] = |
| 502 base::MakeUnique<web::NavigationItemImpl>(*sourceItems[index]); | 501 base::MakeUnique<web::NavigationItemImpl>(*sourceItems[index]); |
| 503 } | 502 } |
| 504 mergedItems.back() = std::move(_items[self.currentNavigationIndex]); | 503 mergedItems.back() = std::move(_items[self.lastCommittedItemIndex]); |
| 505 | 504 |
| 506 // Use |mergedItems| as the session history. | 505 // Use |mergedItems| as the session history. |
| 507 std::swap(mergedItems, _items); | 506 std::swap(mergedItems, _items); |
| 508 | 507 |
| 509 // Update state to reflect inserted NavigationItems. | 508 // Update state to reflect inserted NavigationItems. |
| 510 _previousNavigationIndex = -1; | 509 _previousItemIndex = -1; |
| 511 _currentNavigationIndex = self.items.size() - 1; | 510 _lastCommittedItemIndex = self.items.size() - 1; |
| 512 | 511 |
| 513 DCHECK_LT(static_cast<NSUInteger>(_currentNavigationIndex), | 512 DCHECK_LT(static_cast<NSUInteger>(_lastCommittedItemIndex), |
| 514 self.items.size()); | 513 self.items.size()); |
| 515 } | 514 } |
| 516 | 515 |
| 517 - (void)goToItemAtIndex:(NSInteger)index { | 516 - (void)goToItemAtIndex:(NSInteger)index { |
| 518 if (index < 0 || static_cast<NSUInteger>(index) >= self.items.size()) | 517 if (index < 0 || static_cast<NSUInteger>(index) >= self.items.size()) |
| 519 return; | 518 return; |
| 520 | 519 |
| 521 if (index < _currentNavigationIndex) { | 520 if (index < _lastCommittedItemIndex) { |
| 522 // Going back. | 521 // Going back. |
| 523 [self discardNonCommittedItems]; | 522 [self discardNonCommittedItems]; |
| 524 } else if (_currentNavigationIndex < index) { | 523 } else if (_lastCommittedItemIndex < index) { |
| 525 // Going forward. | 524 // Going forward. |
| 526 [self discardTransientItem]; | 525 [self discardTransientItem]; |
| 527 } else { | 526 } else { |
| 528 // |delta| is 0, no need to change current navigation index. | 527 // |delta| is 0, no need to change the last committed item index. |
| 529 return; | 528 return; |
| 530 } | 529 } |
| 531 | 530 |
| 532 _previousNavigationIndex = _currentNavigationIndex; | 531 _previousItemIndex = _lastCommittedItemIndex; |
| 533 _currentNavigationIndex = index; | 532 _lastCommittedItemIndex = index; |
| 534 } | 533 } |
| 535 | 534 |
| 536 - (void)removeItemAtIndex:(NSInteger)index { | 535 - (void)removeItemAtIndex:(NSInteger)index { |
| 537 DCHECK(index < static_cast<NSInteger>(self.items.size())); | 536 DCHECK(index < static_cast<NSInteger>(self.items.size())); |
| 538 DCHECK(index != _currentNavigationIndex); | 537 DCHECK(index != _lastCommittedItemIndex); |
| 539 DCHECK(index >= 0); | 538 DCHECK(index >= 0); |
| 540 | 539 |
| 541 [self discardNonCommittedItems]; | 540 [self discardNonCommittedItems]; |
| 542 | 541 |
| 543 _items.erase(_items.begin() + index); | 542 _items.erase(_items.begin() + index); |
| 544 if (_currentNavigationIndex > index) | 543 if (_lastCommittedItemIndex > index) |
| 545 _currentNavigationIndex--; | 544 _lastCommittedItemIndex--; |
| 546 if (_previousNavigationIndex >= index) | 545 if (_previousItemIndex >= index) |
| 547 _previousNavigationIndex--; | 546 _previousItemIndex--; |
| 548 } | 547 } |
| 549 | 548 |
| 550 - (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem | 549 - (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem |
| 551 andItem:(web::NavigationItem*)secondItem { | 550 andItem:(web::NavigationItem*)secondItem { |
| 552 if (!firstItem || !secondItem || firstItem == secondItem) | 551 if (!firstItem || !secondItem || firstItem == secondItem) |
| 553 return NO; | 552 return NO; |
| 554 NSUInteger firstIndex = [self indexOfItem:firstItem]; | 553 NSUInteger firstIndex = [self indexOfItem:firstItem]; |
| 555 NSUInteger secondIndex = [self indexOfItem:secondItem]; | 554 NSUInteger secondIndex = [self indexOfItem:secondItem]; |
| 556 if (firstIndex == NSNotFound || secondIndex == NSNotFound) | 555 if (firstIndex == NSNotFound || secondIndex == NSNotFound) |
| 557 return NO; | 556 return NO; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 return item; | 621 return item; |
| 623 } | 622 } |
| 624 | 623 |
| 625 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { | 624 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { |
| 626 DCHECK_LT(index, self.items.size()); | 625 DCHECK_LT(index, self.items.size()); |
| 627 ui::PageTransition transition = self.items[index]->GetTransitionType(); | 626 ui::PageTransition transition = self.items[index]->GetTransitionType(); |
| 628 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 627 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 629 } | 628 } |
| 630 | 629 |
| 631 @end | 630 @end |
| OLD | NEW |