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 29 matching lines...) Expand all Loading... |
40 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; | 40 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; |
41 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; | 41 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; |
42 NSString* const kEntriesKey = @"entries"; | 42 NSString* const kEntriesKey = @"entries"; |
43 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; | 43 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; |
44 NSString* const kOpenerIdKey = @"openerId"; | 44 NSString* const kOpenerIdKey = @"openerId"; |
45 NSString* const kOpenedByDOMKey = @"openedByDOM"; | 45 NSString* const kOpenedByDOMKey = @"openedByDOM"; |
46 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; | 46 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; |
47 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | 47 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
48 NSString* const kTabIdKey = @"tabId"; | 48 NSString* const kTabIdKey = @"tabId"; |
49 NSString* const kWindowNameKey = @"windowName"; | 49 NSString* const kWindowNameKey = @"windowName"; |
50 NSString* const kXCallbackParametersKey = @"xCallbackParameters"; | 50 } // namespace |
51 } // anonymous namespace | |
52 | 51 |
53 @interface CRWSessionController () { | 52 @interface CRWSessionController () { |
54 // Weak pointer back to the owning NavigationManager. This is to facilitate | 53 // Weak pointer back to the owning NavigationManager. This is to facilitate |
55 // the incremental merging of the two classes. | 54 // the incremental merging of the two classes. |
56 web::NavigationManagerImpl* _navigationManager; | 55 web::NavigationManagerImpl* _navigationManager; |
57 | 56 |
58 NSString* _tabId; // Unique id of the tab. | 57 NSString* _tabId; // Unique id of the tab. |
59 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. | 58 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. |
60 // Navigation index of the tab which opened this tab. Do not rely on the | 59 // Navigation index of the tab which opened this tab. Do not rely on the |
61 // value of this member variable to indicate whether or not this tab has | 60 // value of this member variable to indicate whether or not this tab has |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // If |YES|, override |currentEntry.useDesktopUserAgent| and create the | 95 // If |YES|, override |currentEntry.useDesktopUserAgent| and create the |
97 // pending entry using the desktop user agent. | 96 // pending entry using the desktop user agent. |
98 BOOL _useDesktopUserAgentForNextPendingEntry; | 97 BOOL _useDesktopUserAgentForNextPendingEntry; |
99 | 98 |
100 // The browser state associated with this CRWSessionController; | 99 // The browser state associated with this CRWSessionController; |
101 web::BrowserState* _browserState; // weak | 100 web::BrowserState* _browserState; // weak |
102 | 101 |
103 // Time smoother for navigation entry timestamps; see comment in | 102 // Time smoother for navigation entry timestamps; see comment in |
104 // navigation_controller_impl.h | 103 // navigation_controller_impl.h |
105 web::TimeSmoother _timeSmoother; | 104 web::TimeSmoother _timeSmoother; |
106 | |
107 // XCallback parameters used to create (or clobber) the tab. Can be nil. | |
108 XCallbackParameters* _xCallbackParameters; | |
109 } | 105 } |
110 | 106 |
111 // Redefine as readwrite. | 107 // Redefine as readwrite. |
112 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 108 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
113 | 109 |
114 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 110 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
115 // clang bug. crbug.com/228650 | 111 // clang bug. crbug.com/228650 |
116 @property(nonatomic, readwrite, copy) NSString* tabId; | 112 @property(nonatomic, readwrite, copy) NSString* tabId; |
117 @property(nonatomic, readwrite, strong) NSArray* entries; | 113 @property(nonatomic, readwrite, strong) NSArray* entries; |
118 @property(nonatomic, readwrite, strong) | 114 @property(nonatomic, readwrite, strong) |
(...skipping 20 matching lines...) Expand all Loading... |
139 @synthesize tabId = _tabId; | 135 @synthesize tabId = _tabId; |
140 @synthesize currentNavigationIndex = _currentNavigationIndex; | 136 @synthesize currentNavigationIndex = _currentNavigationIndex; |
141 @synthesize previousNavigationIndex = _previousNavigationIndex; | 137 @synthesize previousNavigationIndex = _previousNavigationIndex; |
142 @synthesize entries = _entries; | 138 @synthesize entries = _entries; |
143 @synthesize windowName = _windowName; | 139 @synthesize windowName = _windowName; |
144 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | 140 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
145 @synthesize openerId = _openerId; | 141 @synthesize openerId = _openerId; |
146 @synthesize openedByDOM = _openedByDOM; | 142 @synthesize openedByDOM = _openedByDOM; |
147 @synthesize openerNavigationIndex = _openerNavigationIndex; | 143 @synthesize openerNavigationIndex = _openerNavigationIndex; |
148 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 144 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
149 @synthesize xCallbackParameters = _xCallbackParameters; | |
150 | 145 |
151 - (id)initWithWindowName:(NSString*)windowName | 146 - (id)initWithWindowName:(NSString*)windowName |
152 openerId:(NSString*)openerId | 147 openerId:(NSString*)openerId |
153 openedByDOM:(BOOL)openedByDOM | 148 openedByDOM:(BOOL)openedByDOM |
154 openerNavigationIndex:(NSInteger)openerIndex | 149 openerNavigationIndex:(NSInteger)openerIndex |
155 browserState:(web::BrowserState*)browserState { | 150 browserState:(web::BrowserState*)browserState { |
156 self = [super init]; | 151 self = [super init]; |
157 if (self) { | 152 if (self) { |
158 self.windowName = windowName; | 153 self.windowName = windowName; |
159 _tabId = [[self uniqueID] copy]; | 154 _tabId = [[self uniqueID] copy]; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 _entries = temp; | 226 _entries = temp; |
232 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 227 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
233 if (![_entries count]) | 228 if (![_entries count]) |
234 _currentNavigationIndex = -1; | 229 _currentNavigationIndex = -1; |
235 _sessionCertificatePolicyManager = | 230 _sessionCertificatePolicyManager = |
236 [aDecoder decodeObjectForKey:kCertificatePolicyManagerKey]; | 231 [aDecoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
237 if (!_sessionCertificatePolicyManager) { | 232 if (!_sessionCertificatePolicyManager) { |
238 _sessionCertificatePolicyManager = | 233 _sessionCertificatePolicyManager = |
239 [[CRWSessionCertificatePolicyManager alloc] init]; | 234 [[CRWSessionCertificatePolicyManager alloc] init]; |
240 } | 235 } |
241 | |
242 _xCallbackParameters = | |
243 [aDecoder decodeObjectForKey:kXCallbackParametersKey]; | |
244 } | 236 } |
245 return self; | 237 return self; |
246 } | 238 } |
247 | 239 |
248 - (void)encodeWithCoder:(NSCoder*)aCoder { | 240 - (void)encodeWithCoder:(NSCoder*)aCoder { |
249 [aCoder encodeObject:_tabId forKey:kTabIdKey]; | 241 [aCoder encodeObject:_tabId forKey:kTabIdKey]; |
250 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; | 242 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; |
251 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; | 243 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; |
252 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; | 244 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; |
253 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; | 245 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; |
254 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; | 246 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; |
255 [aCoder encodeInt:_previousNavigationIndex | 247 [aCoder encodeInt:_previousNavigationIndex |
256 forKey:kPreviousNavigationIndexKey]; | 248 forKey:kPreviousNavigationIndexKey]; |
257 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; | 249 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; |
258 [aCoder encodeObject:_entries forKey:kEntriesKey]; | 250 [aCoder encodeObject:_entries forKey:kEntriesKey]; |
259 [aCoder encodeObject:_sessionCertificatePolicyManager | 251 [aCoder encodeObject:_sessionCertificatePolicyManager |
260 forKey:kCertificatePolicyManagerKey]; | 252 forKey:kCertificatePolicyManagerKey]; |
261 [aCoder encodeObject:_xCallbackParameters forKey:kXCallbackParametersKey]; | |
262 // rendererInitiated is deliberately not preserved, as upstream. | 253 // rendererInitiated is deliberately not preserved, as upstream. |
263 } | 254 } |
264 | 255 |
265 - (id)copyWithZone:(NSZone*)zone { | 256 - (id)copyWithZone:(NSZone*)zone { |
266 CRWSessionController* copy = [[[self class] alloc] init]; | 257 CRWSessionController* copy = [[[self class] alloc] init]; |
267 copy->_tabId = [_tabId copy]; | 258 copy->_tabId = [_tabId copy]; |
268 copy->_openerId = [_openerId copy]; | 259 copy->_openerId = [_openerId copy]; |
269 copy->_openedByDOM = _openedByDOM; | 260 copy->_openedByDOM = _openedByDOM; |
270 copy->_openerNavigationIndex = _openerNavigationIndex; | 261 copy->_openerNavigationIndex = _openerNavigationIndex; |
271 copy.windowName = self.windowName; | 262 copy.windowName = self.windowName; |
272 copy->_currentNavigationIndex = _currentNavigationIndex; | 263 copy->_currentNavigationIndex = _currentNavigationIndex; |
273 copy->_previousNavigationIndex = _previousNavigationIndex; | 264 copy->_previousNavigationIndex = _previousNavigationIndex; |
274 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | 265 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
275 copy->_entries = | 266 copy->_entries = |
276 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; | 267 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
277 copy->_sessionCertificatePolicyManager = | 268 copy->_sessionCertificatePolicyManager = |
278 [_sessionCertificatePolicyManager copy]; | 269 [_sessionCertificatePolicyManager copy]; |
279 copy->_xCallbackParameters = [base::mac::ObjCCastStrict<NSObject<NSCopying>>( | |
280 _xCallbackParameters) copy]; | |
281 return copy; | 270 return copy; |
282 } | 271 } |
283 | 272 |
284 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { | 273 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { |
285 if (_currentNavigationIndex != currentNavigationIndex) { | 274 if (_currentNavigationIndex != currentNavigationIndex) { |
286 _currentNavigationIndex = currentNavigationIndex; | 275 _currentNavigationIndex = currentNavigationIndex; |
287 if (_navigationManager) | 276 if (_navigationManager) |
288 _navigationManager->RemoveTransientURLRewriters(); | 277 _navigationManager->RemoveTransientURLRewriters(); |
289 } | 278 } |
290 } | 279 } |
291 | 280 |
292 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { | 281 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { |
293 _navigationManager = navigationManager; | 282 _navigationManager = navigationManager; |
294 if (_navigationManager) { | 283 if (_navigationManager) { |
295 // _browserState will be nullptr if CRWSessionController has been | 284 // _browserState will be nullptr if CRWSessionController has been |
296 // initialized with -initWithCoder: method. Take _browserState from | 285 // initialized with -initWithCoder: method. Take _browserState from |
297 // NavigationManagerImpl if that's the case. | 286 // NavigationManagerImpl if that's the case. |
298 if (!_browserState) { | 287 if (!_browserState) { |
299 _browserState = _navigationManager->GetBrowserState(); | 288 _browserState = _navigationManager->GetBrowserState(); |
300 } | 289 } |
301 DCHECK_EQ(_browserState, _navigationManager->GetBrowserState()); | 290 DCHECK_EQ(_browserState, _navigationManager->GetBrowserState()); |
302 } | 291 } |
303 } | 292 } |
304 | 293 |
305 - (NSString*)description { | 294 - (NSString*)description { |
306 return [NSString | 295 return [NSString |
307 stringWithFormat: | 296 stringWithFormat: |
308 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS | 297 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS |
309 @"\nprevious index: %" PRIdNS "\n%@\npending: %@\ntransient: %@\n" | 298 @"\nprevious index: %" PRIdNS "\n%@\npending: %@\ntransient: %@\n", |
310 @"xCallback:\n%@\n", | |
311 _tabId, self.windowName, _lastVisitedTimestamp, | 299 _tabId, self.windowName, _lastVisitedTimestamp, |
312 _currentNavigationIndex, _previousNavigationIndex, _entries, | 300 _currentNavigationIndex, _previousNavigationIndex, _entries, |
313 _pendingEntry.get(), _transientEntry.get(), _xCallbackParameters]; | 301 _pendingEntry.get(), _transientEntry.get()]; |
314 } | 302 } |
315 | 303 |
316 // Returns the current entry in the session list, or the pending entry if there | 304 // Returns the current entry in the session list, or the pending entry if there |
317 // is a navigation in progress. | 305 // is a navigation in progress. |
318 - (CRWSessionEntry*)currentEntry { | 306 - (CRWSessionEntry*)currentEntry { |
319 if (_transientEntry) | 307 if (_transientEntry) |
320 return _transientEntry.get(); | 308 return _transientEntry.get(); |
321 if (_pendingEntry) | 309 if (_pendingEntry) |
322 return _pendingEntry.get(); | 310 return _pendingEntry.get(); |
323 return [self lastCommittedEntry]; | 311 return [self lastCommittedEntry]; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 548 } |
561 | 549 |
562 - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession | 550 - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession |
563 replaceState:(BOOL)replaceState { | 551 replaceState:(BOOL)replaceState { |
564 DCHECK(otherSession); | 552 DCHECK(otherSession); |
565 if (replaceState) { | 553 if (replaceState) { |
566 [_entries removeAllObjects]; | 554 [_entries removeAllObjects]; |
567 self.currentNavigationIndex = -1; | 555 self.currentNavigationIndex = -1; |
568 _previousNavigationIndex = -1; | 556 _previousNavigationIndex = -1; |
569 } | 557 } |
570 self.xCallbackParameters = [base::mac::ObjCCastStrict<NSObject<NSCopying>>( | |
571 otherSession.xCallbackParameters) copy]; | |
572 self.windowName = otherSession.windowName; | 558 self.windowName = otherSession.windowName; |
573 NSInteger numInitialEntries = [_entries count]; | 559 NSInteger numInitialEntries = [_entries count]; |
574 | 560 |
575 // Cycle through the entries from the other session and insert them before any | 561 // Cycle through the entries from the other session and insert them before any |
576 // entries from this session. Do not copy anything that comes after the other | 562 // entries from this session. Do not copy anything that comes after the other |
577 // session's current entry unless replaceState is true. | 563 // session's current entry unless replaceState is true. |
578 NSArray* otherEntries = [otherSession entries]; | 564 NSArray* otherEntries = [otherSession entries]; |
579 | 565 |
580 // The other session may not have any entries, in which case there is nothing | 566 // The other session may not have any entries, in which case there is nothing |
581 // to copy or prune. The other session's currentNavigationEntry will be bogus | 567 // to copy or prune. The other session's currentNavigationEntry will be bogus |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); | 861 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); |
876 item->SetURL(loaded_url); | 862 item->SetURL(loaded_url); |
877 item->SetReferrer(referrer); | 863 item->SetReferrer(referrer); |
878 item->SetTransitionType(transition); | 864 item->SetTransitionType(transition); |
879 item->SetIsOverridingUserAgent(useDesktopUserAgent); | 865 item->SetIsOverridingUserAgent(useDesktopUserAgent); |
880 item->set_is_renderer_initiated(rendererInitiated); | 866 item->set_is_renderer_initiated(rendererInitiated); |
881 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 867 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
882 } | 868 } |
883 | 869 |
884 @end | 870 @end |
OLD | NEW |