| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 // The transient entry, if any. A transient entry is discarded on any | 56 // The transient entry, if any. A transient entry is discarded on any |
| 57 // navigation, and is used for representing interstitials that need to be | 57 // navigation, and is used for representing interstitials that need to be |
| 58 // represented in the session. It backs the property of the same name and | 58 // represented in the session. It backs the property of the same name and |
| 59 // should only be set through its setter. | 59 // should only be set through its setter. |
| 60 base::scoped_nsobject<CRWSessionEntry> _transientEntry; | 60 base::scoped_nsobject<CRWSessionEntry> _transientEntry; |
| 61 | 61 |
| 62 // Stores the certificate policies decided by the user. | 62 // Stores the certificate policies decided by the user. |
| 63 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; | 63 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; |
| 64 | 64 |
| 65 // The timestamp of the last time this tab is visited, represented in time | |
| 66 // interval since 1970. | |
| 67 NSTimeInterval _lastVisitedTimestamp; | |
| 68 | |
| 69 // The browser state associated with this CRWSessionController; | 65 // The browser state associated with this CRWSessionController; |
| 70 web::BrowserState* _browserState; // weak | 66 web::BrowserState* _browserState; // weak |
| 71 | 67 |
| 72 // Time smoother for navigation entry timestamps; see comment in | 68 // Time smoother for navigation entry timestamps; see comment in |
| 73 // navigation_controller_impl.h | 69 // navigation_controller_impl.h |
| 74 web::TimeSmoother _timeSmoother; | 70 web::TimeSmoother _timeSmoother; |
| 75 } | 71 } |
| 76 | 72 |
| 77 // Redefine as readwrite. | 73 // Redefine as readwrite. |
| 78 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 74 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 // Returns a NavigationItemList containing the NavigationItems from |entries|. | 101 // Returns a NavigationItemList containing the NavigationItems from |entries|. |
| 106 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; | 102 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; |
| 107 @end | 103 @end |
| 108 | 104 |
| 109 @implementation CRWSessionController | 105 @implementation CRWSessionController |
| 110 | 106 |
| 111 @synthesize currentNavigationIndex = _currentNavigationIndex; | 107 @synthesize currentNavigationIndex = _currentNavigationIndex; |
| 112 @synthesize previousNavigationIndex = _previousNavigationIndex; | 108 @synthesize previousNavigationIndex = _previousNavigationIndex; |
| 113 @synthesize pendingItemIndex = _pendingItemIndex; | 109 @synthesize pendingItemIndex = _pendingItemIndex; |
| 114 @synthesize entries = _entries; | 110 @synthesize entries = _entries; |
| 115 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | |
| 116 @synthesize openedByDOM = _openedByDOM; | 111 @synthesize openedByDOM = _openedByDOM; |
| 117 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 112 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 118 | 113 |
| 119 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState | 114 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState |
| 120 openedByDOM:(BOOL)openedByDOM { | 115 openedByDOM:(BOOL)openedByDOM { |
| 121 self = [super init]; | 116 self = [super init]; |
| 122 if (self) { | 117 if (self) { |
| 123 _openedByDOM = openedByDOM; | 118 _openedByDOM = openedByDOM; |
| 124 _browserState = browserState; | 119 _browserState = browserState; |
| 125 _entries = [NSMutableArray array]; | 120 _entries = [NSMutableArray array]; |
| 126 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | |
| 127 _currentNavigationIndex = -1; | 121 _currentNavigationIndex = -1; |
| 128 _previousNavigationIndex = -1; | 122 _previousNavigationIndex = -1; |
| 129 _pendingItemIndex = -1; | 123 _pendingItemIndex = -1; |
| 130 _sessionCertificatePolicyManager = | 124 _sessionCertificatePolicyManager = |
| 131 [[CRWSessionCertificatePolicyManager alloc] init]; | 125 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 132 } | 126 } |
| 133 return self; | 127 return self; |
| 134 } | 128 } |
| 135 | 129 |
| 136 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState | 130 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 } | 143 } |
| 150 self.currentNavigationIndex = currentIndex; | 144 self.currentNavigationIndex = currentIndex; |
| 151 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 145 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
| 152 if (![_entries count]) | 146 if (![_entries count]) |
| 153 self.currentNavigationIndex = -1; | 147 self.currentNavigationIndex = -1; |
| 154 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { | 148 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { |
| 155 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; | 149 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; |
| 156 } | 150 } |
| 157 _previousNavigationIndex = -1; | 151 _previousNavigationIndex = -1; |
| 158 _pendingItemIndex = -1; | 152 _pendingItemIndex = -1; |
| 159 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | |
| 160 _sessionCertificatePolicyManager = | 153 _sessionCertificatePolicyManager = |
| 161 [[CRWSessionCertificatePolicyManager alloc] init]; | 154 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 162 } | 155 } |
| 163 return self; | 156 return self; |
| 164 } | 157 } |
| 165 | 158 |
| 166 - (id)copyWithZone:(NSZone*)zone { | 159 - (id)copyWithZone:(NSZone*)zone { |
| 167 CRWSessionController* copy = [[[self class] alloc] init]; | 160 CRWSessionController* copy = [[[self class] alloc] init]; |
| 168 copy->_openedByDOM = _openedByDOM; | 161 copy->_openedByDOM = _openedByDOM; |
| 169 copy->_currentNavigationIndex = _currentNavigationIndex; | 162 copy->_currentNavigationIndex = _currentNavigationIndex; |
| 170 copy->_previousNavigationIndex = _previousNavigationIndex; | 163 copy->_previousNavigationIndex = _previousNavigationIndex; |
| 171 copy->_pendingItemIndex = _pendingItemIndex; | 164 copy->_pendingItemIndex = _pendingItemIndex; |
| 172 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | |
| 173 copy->_entries = | 165 copy->_entries = |
| 174 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; | 166 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
| 175 copy->_sessionCertificatePolicyManager = | 167 copy->_sessionCertificatePolicyManager = |
| 176 [_sessionCertificatePolicyManager copy]; | 168 [_sessionCertificatePolicyManager copy]; |
| 177 return copy; | 169 return copy; |
| 178 } | 170 } |
| 179 | 171 |
| 180 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { | 172 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { |
| 181 if (_currentNavigationIndex != currentNavigationIndex) { | 173 if (_currentNavigationIndex != currentNavigationIndex) { |
| 182 _currentNavigationIndex = currentNavigationIndex; | 174 _currentNavigationIndex = currentNavigationIndex; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 207 } | 199 } |
| 208 } | 200 } |
| 209 | 201 |
| 210 - (void)setBrowserState:(web::BrowserState*)browserState { | 202 - (void)setBrowserState:(web::BrowserState*)browserState { |
| 211 _browserState = browserState; | 203 _browserState = browserState; |
| 212 DCHECK(!_navigationManager || | 204 DCHECK(!_navigationManager || |
| 213 _navigationManager->GetBrowserState() == _browserState); | 205 _navigationManager->GetBrowserState() == _browserState); |
| 214 } | 206 } |
| 215 | 207 |
| 216 - (NSString*)description { | 208 - (NSString*)description { |
| 217 return [NSString | 209 return [NSString stringWithFormat:@"current index: %" PRIdNS |
| 218 stringWithFormat:@"last visit: %f\ncurrent index: %" PRIdNS | 210 @"\nprevious index: %" PRIdNS |
| 219 @"\nprevious index: %" PRIdNS | 211 @"\npending index: %" PRIdNS |
| 220 @"\npending index: %" PRIdNS | 212 @"\n%@\npending: %@\ntransient: %@\n", |
| 221 @"\n%@\npending: %@\ntransient: %@\n", | 213 _currentNavigationIndex, |
| 222 _lastVisitedTimestamp, _currentNavigationIndex, | 214 _previousNavigationIndex, _pendingItemIndex, |
| 223 _previousNavigationIndex, _pendingItemIndex, _entries, | 215 _entries, _pendingEntry.get(), |
| 224 _pendingEntry.get(), _transientEntry.get()]; | 216 _transientEntry.get()]; |
| 225 } | 217 } |
| 226 | 218 |
| 227 - (web::NavigationItemList)items { | 219 - (web::NavigationItemList)items { |
| 228 return [self itemListForEntryList:self.entries]; | 220 return [self itemListForEntryList:self.entries]; |
| 229 } | 221 } |
| 230 | 222 |
| 231 - (web::NavigationItemImpl*)currentItem { | 223 - (web::NavigationItemImpl*)currentItem { |
| 232 return self.currentEntry.navigationItemImpl; | 224 return self.currentEntry.navigationItemImpl; |
| 233 } | 225 } |
| 234 | 226 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 } | 688 } |
| 697 | 689 |
| 698 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { | 690 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { |
| 699 web::NavigationItemList list(entries.count); | 691 web::NavigationItemList list(entries.count); |
| 700 for (size_t index = 0; index < entries.count; ++index) | 692 for (size_t index = 0; index < entries.count; ++index) |
| 701 list[index] = [entries[index] navigationItem]; | 693 list[index] = [entries[index] navigationItem]; |
| 702 return list; | 694 return list; |
| 703 } | 695 } |
| 704 | 696 |
| 705 @end | 697 @end |
| OLD | NEW |