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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/mac/objc_property_releaser.h" | 15 #import "base/mac/foundation_util.h" |
16 #import "base/mac/scoped_nsobject.h" | 16 #import "base/mac/scoped_nsobject.h" |
17 #include "base/metrics/user_metrics.h" | 17 #include "base/metrics/user_metrics.h" |
18 #include "base/metrics/user_metrics_action.h" | 18 #include "base/metrics/user_metrics_action.h" |
19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
20 #import "ios/web/history_state_util.h" | 20 #import "ios/web/history_state_util.h" |
21 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 21 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
22 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 22 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
23 #import "ios/web/navigation/crw_session_entry.h" | 23 #import "ios/web/navigation/crw_session_entry.h" |
24 #include "ios/web/navigation/navigation_item_impl.h" | 24 #include "ios/web/navigation/navigation_item_impl.h" |
25 #import "ios/web/navigation/navigation_manager_facade_delegate.h" | 25 #import "ios/web/navigation/navigation_manager_facade_delegate.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 95 |
96 // The browser state associated with this CRWSessionController; | 96 // The browser state associated with this CRWSessionController; |
97 web::BrowserState* _browserState; // weak | 97 web::BrowserState* _browserState; // weak |
98 | 98 |
99 // Time smoother for navigation entry timestamps; see comment in | 99 // Time smoother for navigation entry timestamps; see comment in |
100 // navigation_controller_impl.h | 100 // navigation_controller_impl.h |
101 web::TimeSmoother _timeSmoother; | 101 web::TimeSmoother _timeSmoother; |
102 | 102 |
103 // XCallback parameters used to create (or clobber) the tab. Can be nil. | 103 // XCallback parameters used to create (or clobber) the tab. Can be nil. |
104 XCallbackParameters* _xCallbackParameters; | 104 XCallbackParameters* _xCallbackParameters; |
105 | |
106 base::mac::ObjCPropertyReleaser _propertyReleaser_CRWSessionController; | |
107 } | 105 } |
108 | 106 |
109 // Redefine as readwrite. | 107 // Redefine as readwrite. |
110 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 108 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
111 | 109 |
112 // 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 |
113 // clang bug. crbug.com/228650 | 111 // clang bug. crbug.com/228650 |
114 @property(nonatomic, readwrite, retain) NSString* tabId; | 112 @property(nonatomic, readwrite, copy) NSString* tabId; |
115 @property(nonatomic, readwrite, retain) NSArray* entries; | 113 @property(nonatomic, readwrite, strong) NSArray* entries; |
116 @property(nonatomic, readwrite, retain) | 114 @property(nonatomic, readwrite, strong) |
117 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 115 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
118 | 116 |
119 - (NSString*)uniqueID; | 117 - (NSString*)uniqueID; |
120 // Removes all entries after currentNavigationIndex_. | 118 // Removes all entries after currentNavigationIndex_. |
121 - (void)clearForwardEntries; | 119 - (void)clearForwardEntries; |
122 // Discards the transient entry, if any. | 120 // Discards the transient entry, if any. |
123 - (void)discardTransientEntry; | 121 - (void)discardTransientEntry; |
124 // Create a new autoreleased session entry. | 122 // Create a new autoreleased session entry. |
125 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 123 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
126 referrer:(const web::Referrer&)referrer | 124 referrer:(const web::Referrer&)referrer |
(...skipping 19 matching lines...) Expand all Loading... | |
146 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 144 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
147 @synthesize xCallbackParameters = _xCallbackParameters; | 145 @synthesize xCallbackParameters = _xCallbackParameters; |
148 | 146 |
149 - (id)initWithWindowName:(NSString*)windowName | 147 - (id)initWithWindowName:(NSString*)windowName |
150 openerId:(NSString*)openerId | 148 openerId:(NSString*)openerId |
151 openedByDOM:(BOOL)openedByDOM | 149 openedByDOM:(BOOL)openedByDOM |
152 openerNavigationIndex:(NSInteger)openerIndex | 150 openerNavigationIndex:(NSInteger)openerIndex |
153 browserState:(web::BrowserState*)browserState { | 151 browserState:(web::BrowserState*)browserState { |
154 self = [super init]; | 152 self = [super init]; |
155 if (self) { | 153 if (self) { |
156 _propertyReleaser_CRWSessionController.Init(self, | |
157 [CRWSessionController class]); | |
158 self.windowName = windowName; | 154 self.windowName = windowName; |
159 _tabId = [[self uniqueID] retain]; | 155 _tabId = [[self uniqueID] copy]; |
160 _openerId = [openerId copy]; | 156 _openerId = [openerId copy]; |
161 _openedByDOM = openedByDOM; | 157 _openedByDOM = openedByDOM; |
162 _openerNavigationIndex = openerIndex; | 158 _openerNavigationIndex = openerIndex; |
163 _browserState = browserState; | 159 _browserState = browserState; |
164 _entries = [[NSMutableArray array] retain]; | 160 _entries = [NSMutableArray array]; |
165 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 161 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
166 _currentNavigationIndex = -1; | 162 _currentNavigationIndex = -1; |
167 _previousNavigationIndex = -1; | 163 _previousNavigationIndex = -1; |
168 _sessionCertificatePolicyManager = | 164 _sessionCertificatePolicyManager = |
169 [[CRWSessionCertificatePolicyManager alloc] init]; | 165 [[CRWSessionCertificatePolicyManager alloc] init]; |
170 } | 166 } |
171 return self; | 167 return self; |
172 } | 168 } |
173 | 169 |
174 - (id)initWithNavigationItems:(ScopedVector<web::NavigationItem>)scoped_items | 170 - (id)initWithNavigationItems:(ScopedVector<web::NavigationItem>)scoped_items |
175 currentIndex:(NSUInteger)currentIndex | 171 currentIndex:(NSUInteger)currentIndex |
176 browserState:(web::BrowserState*)browserState { | 172 browserState:(web::BrowserState*)browserState { |
177 self = [super init]; | 173 self = [super init]; |
178 if (self) { | 174 if (self) { |
179 _propertyReleaser_CRWSessionController.Init(self, | 175 _tabId = [[self uniqueID] copy]; |
180 [CRWSessionController class]); | |
181 _tabId = [[self uniqueID] retain]; | |
182 _openerId = nil; | 176 _openerId = nil; |
183 _browserState = browserState; | 177 _browserState = browserState; |
184 | 178 |
185 // Create entries array from list of navigations. | 179 // Create entries array from list of navigations. |
186 _entries = [[NSMutableArray alloc] initWithCapacity:scoped_items.size()]; | 180 _entries = [[NSMutableArray alloc] initWithCapacity:scoped_items.size()]; |
187 std::vector<web::NavigationItem*> items; | 181 std::vector<web::NavigationItem*> items; |
188 scoped_items.release(&items); | 182 scoped_items.release(&items); |
189 | 183 |
190 for (size_t i = 0; i < items.size(); ++i) { | 184 for (size_t i = 0; i < items.size(); ++i) { |
191 std::unique_ptr<web::NavigationItem> item(items[i]); | 185 std::unique_ptr<web::NavigationItem> item(items[i]); |
(...skipping 12 matching lines...) Expand all Loading... | |
204 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 198 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
205 _sessionCertificatePolicyManager = | 199 _sessionCertificatePolicyManager = |
206 [[CRWSessionCertificatePolicyManager alloc] init]; | 200 [[CRWSessionCertificatePolicyManager alloc] init]; |
207 } | 201 } |
208 return self; | 202 return self; |
209 } | 203 } |
210 | 204 |
211 - (id)initWithCoder:(NSCoder*)aDecoder { | 205 - (id)initWithCoder:(NSCoder*)aDecoder { |
212 self = [super init]; | 206 self = [super init]; |
213 if (self) { | 207 if (self) { |
214 _propertyReleaser_CRWSessionController.Init(self, | |
215 [CRWSessionController class]); | |
216 NSString* uuid = [aDecoder decodeObjectForKey:kTabIdKey]; | 208 NSString* uuid = [aDecoder decodeObjectForKey:kTabIdKey]; |
217 if (!uuid) | 209 if (!uuid) |
218 uuid = [self uniqueID]; | 210 uuid = [self uniqueID]; |
219 | 211 |
220 self.windowName = [aDecoder decodeObjectForKey:kWindowNameKey]; | 212 self.windowName = [aDecoder decodeObjectForKey:kWindowNameKey]; |
221 _tabId = [uuid retain]; | 213 _tabId = [uuid copy]; |
222 _openerId = [[aDecoder decodeObjectForKey:kOpenerIdKey] copy]; | 214 _openerId = [[aDecoder decodeObjectForKey:kOpenerIdKey] copy]; |
223 _openedByDOM = [aDecoder decodeBoolForKey:kOpenedByDOMKey]; | 215 _openedByDOM = [aDecoder decodeBoolForKey:kOpenedByDOMKey]; |
224 _openerNavigationIndex = | 216 _openerNavigationIndex = |
225 [aDecoder decodeIntForKey:kOpenerNavigationIndexKey]; | 217 [aDecoder decodeIntForKey:kOpenerNavigationIndexKey]; |
226 _currentNavigationIndex = | 218 _currentNavigationIndex = |
227 [aDecoder decodeIntForKey:kCurrentNavigationIndexKey]; | 219 [aDecoder decodeIntForKey:kCurrentNavigationIndexKey]; |
228 _previousNavigationIndex = | 220 _previousNavigationIndex = |
229 [aDecoder decodeIntForKey:kPreviousNavigationIndexKey]; | 221 [aDecoder decodeIntForKey:kPreviousNavigationIndexKey]; |
230 _lastVisitedTimestamp = | 222 _lastVisitedTimestamp = |
231 [aDecoder decodeDoubleForKey:kLastVisitedTimestampKey]; | 223 [aDecoder decodeDoubleForKey:kLastVisitedTimestampKey]; |
232 NSMutableArray* temp = | 224 NSMutableArray* temp = |
233 [NSMutableArray arrayWithArray: | 225 [NSMutableArray arrayWithArray: |
234 [aDecoder decodeObjectForKey:kEntriesKey]]; | 226 [aDecoder decodeObjectForKey:kEntriesKey]]; |
235 _entries = [temp retain]; | 227 _entries = temp; |
236 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 228 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
237 if (![_entries count]) | 229 if (![_entries count]) |
238 _currentNavigationIndex = -1; | 230 _currentNavigationIndex = -1; |
239 _sessionCertificatePolicyManager = | 231 _sessionCertificatePolicyManager = |
240 [[aDecoder decodeObjectForKey:kCertificatePolicyManagerKey] retain]; | 232 [aDecoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
241 if (!_sessionCertificatePolicyManager) { | 233 if (!_sessionCertificatePolicyManager) { |
242 _sessionCertificatePolicyManager = | 234 _sessionCertificatePolicyManager = |
243 [[CRWSessionCertificatePolicyManager alloc] init]; | 235 [[CRWSessionCertificatePolicyManager alloc] init]; |
244 } | 236 } |
245 | 237 |
246 _xCallbackParameters = | 238 _xCallbackParameters = |
247 [[aDecoder decodeObjectForKey:kXCallbackParametersKey] retain]; | 239 [aDecoder decodeObjectForKey:kXCallbackParametersKey]; |
248 } | 240 } |
249 return self; | 241 return self; |
250 } | 242 } |
251 | 243 |
252 - (void)encodeWithCoder:(NSCoder*)aCoder { | 244 - (void)encodeWithCoder:(NSCoder*)aCoder { |
253 [aCoder encodeObject:_tabId forKey:kTabIdKey]; | 245 [aCoder encodeObject:_tabId forKey:kTabIdKey]; |
254 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; | 246 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; |
255 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; | 247 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; |
256 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; | 248 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; |
257 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; | 249 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; |
258 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; | 250 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; |
259 [aCoder encodeInt:_previousNavigationIndex | 251 [aCoder encodeInt:_previousNavigationIndex |
260 forKey:kPreviousNavigationIndexKey]; | 252 forKey:kPreviousNavigationIndexKey]; |
261 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; | 253 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; |
262 [aCoder encodeObject:_entries forKey:kEntriesKey]; | 254 [aCoder encodeObject:_entries forKey:kEntriesKey]; |
263 [aCoder encodeObject:_sessionCertificatePolicyManager | 255 [aCoder encodeObject:_sessionCertificatePolicyManager |
264 forKey:kCertificatePolicyManagerKey]; | 256 forKey:kCertificatePolicyManagerKey]; |
265 [aCoder encodeObject:_xCallbackParameters forKey:kXCallbackParametersKey]; | 257 [aCoder encodeObject:_xCallbackParameters forKey:kXCallbackParametersKey]; |
266 // rendererInitiated is deliberately not preserved, as upstream. | 258 // rendererInitiated is deliberately not preserved, as upstream. |
267 } | 259 } |
268 | 260 |
269 - (id)copyWithZone:(NSZone*)zone { | 261 - (id)copyWithZone:(NSZone*)zone { |
270 CRWSessionController* copy = [[[self class] alloc] init]; | 262 CRWSessionController* copy = [[[self class] alloc] init]; |
271 copy->_propertyReleaser_CRWSessionController.Init( | |
272 copy, [CRWSessionController class]); | |
273 copy->_tabId = [_tabId copy]; | 263 copy->_tabId = [_tabId copy]; |
274 copy->_openerId = [_openerId copy]; | 264 copy->_openerId = [_openerId copy]; |
275 copy->_openedByDOM = _openedByDOM; | 265 copy->_openedByDOM = _openedByDOM; |
276 copy->_openerNavigationIndex = _openerNavigationIndex; | 266 copy->_openerNavigationIndex = _openerNavigationIndex; |
277 copy.windowName = self.windowName; | 267 copy.windowName = self.windowName; |
278 copy->_currentNavigationIndex = _currentNavigationIndex; | 268 copy->_currentNavigationIndex = _currentNavigationIndex; |
279 copy->_previousNavigationIndex = _previousNavigationIndex; | 269 copy->_previousNavigationIndex = _previousNavigationIndex; |
280 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | 270 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
281 copy->_entries = | 271 copy->_entries = |
282 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; | 272 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
283 copy->_sessionCertificatePolicyManager = | 273 copy->_sessionCertificatePolicyManager = |
284 [_sessionCertificatePolicyManager copy]; | 274 [_sessionCertificatePolicyManager copy]; |
285 copy->_xCallbackParameters = [_xCallbackParameters copy]; | 275 copy->_xCallbackParameters = [base::mac::ObjCCastStrict<NSObject<NSCopying>>( |
276 _xCallbackParameters) copy]; | |
286 return copy; | 277 return copy; |
287 } | 278 } |
288 | 279 |
289 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { | 280 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { |
290 if (_currentNavigationIndex != currentNavigationIndex) { | 281 if (_currentNavigationIndex != currentNavigationIndex) { |
291 _currentNavigationIndex = currentNavigationIndex; | 282 _currentNavigationIndex = currentNavigationIndex; |
292 if (_navigationManager) | 283 if (_navigationManager) |
293 _navigationManager->RemoveTransientURLRewriters(); | 284 _navigationManager->RemoveTransientURLRewriters(); |
294 } | 285 } |
295 } | 286 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 } | 385 } |
395 return; | 386 return; |
396 } | 387 } |
397 } | 388 } |
398 | 389 |
399 BOOL useDesktopUserAgent = | 390 BOOL useDesktopUserAgent = |
400 _useDesktopUserAgentForNextPendingEntry || | 391 _useDesktopUserAgentForNextPendingEntry || |
401 (self.currentEntry.navigationItem && | 392 (self.currentEntry.navigationItem && |
402 self.currentEntry.navigationItem->IsOverridingUserAgent()); | 393 self.currentEntry.navigationItem->IsOverridingUserAgent()); |
403 _useDesktopUserAgentForNextPendingEntry = NO; | 394 _useDesktopUserAgentForNextPendingEntry = NO; |
404 _pendingEntry.reset([[self sessionEntryWithURL:url | 395 _pendingEntry.reset([self sessionEntryWithURL:url |
405 referrer:ref | 396 referrer:ref |
406 transition:trans | 397 transition:trans |
407 useDesktopUserAgent:useDesktopUserAgent | 398 useDesktopUserAgent:useDesktopUserAgent |
408 rendererInitiated:rendererInitiated] retain]); | 399 rendererInitiated:rendererInitiated]); |
409 | 400 |
410 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 401 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
411 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 402 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
412 } | 403 } |
413 } | 404 } |
414 | 405 |
415 - (void)updatePendingEntry:(const GURL&)url { | 406 - (void)updatePendingEntry:(const GURL&)url { |
416 // If there is no pending entry, navigation is probably happening within the | 407 // If there is no pending entry, navigation is probably happening within the |
417 // session history. Don't modify the entry list. | 408 // session history. Don't modify the entry list. |
418 if (!_pendingEntry) | 409 if (!_pendingEntry) |
(...skipping 28 matching lines...) Expand all Loading... | |
447 DCHECK(forwardEntryStartIndex >= 0); | 438 DCHECK(forwardEntryStartIndex >= 0); |
448 | 439 |
449 if (forwardEntryStartIndex >= static_cast<NSInteger>([_entries count])) | 440 if (forwardEntryStartIndex >= static_cast<NSInteger>([_entries count])) |
450 return; | 441 return; |
451 | 442 |
452 NSRange remove = NSMakeRange(forwardEntryStartIndex, | 443 NSRange remove = NSMakeRange(forwardEntryStartIndex, |
453 [_entries count] - forwardEntryStartIndex); | 444 [_entries count] - forwardEntryStartIndex); |
454 // Store removed items in temporary NSArray so they can be deallocated after | 445 // Store removed items in temporary NSArray so they can be deallocated after |
455 // their facades. | 446 // their facades. |
456 base::scoped_nsobject<NSArray> removedItems( | 447 base::scoped_nsobject<NSArray> removedItems( |
457 [[_entries subarrayWithRange:remove] retain]); | 448 [_entries subarrayWithRange:remove]); |
458 [_entries removeObjectsInRange:remove]; | 449 [_entries removeObjectsInRange:remove]; |
459 if (_previousNavigationIndex >= forwardEntryStartIndex) | 450 if (_previousNavigationIndex >= forwardEntryStartIndex) |
460 _previousNavigationIndex = -1; | 451 _previousNavigationIndex = -1; |
461 if (_navigationManager) { | 452 if (_navigationManager) { |
462 _navigationManager->OnNavigationItemsPruned(remove.length); | 453 _navigationManager->OnNavigationItemsPruned(remove.length); |
463 } | 454 } |
464 } | 455 } |
465 | 456 |
466 - (void)commitPendingEntry { | 457 - (void)commitPendingEntry { |
467 if (_pendingEntry) { | 458 if (_pendingEntry) { |
(...skipping 12 matching lines...) Expand all Loading... | |
480 web::NavigationItem* item = currentEntry.navigationItem; | 471 web::NavigationItem* item = currentEntry.navigationItem; |
481 // Update the navigation timestamp now that it's actually happened. | 472 // Update the navigation timestamp now that it's actually happened. |
482 if (item) | 473 if (item) |
483 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); | 474 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); |
484 | 475 |
485 if (_navigationManager && item) | 476 if (_navigationManager && item) |
486 _navigationManager->OnNavigationItemCommitted(); | 477 _navigationManager->OnNavigationItemCommitted(); |
487 } | 478 } |
488 | 479 |
489 - (void)addTransientEntryWithURL:(const GURL&)URL { | 480 - (void)addTransientEntryWithURL:(const GURL&)URL { |
490 _transientEntry.reset( | 481 _transientEntry.reset([self |
491 [[self sessionEntryWithURL:URL | 482 sessionEntryWithURL:URL |
492 referrer:web::Referrer() | 483 referrer:web::Referrer() |
493 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 484 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
494 useDesktopUserAgent:NO | 485 useDesktopUserAgent:NO |
495 rendererInitiated:NO] retain]); | 486 rendererInitiated:NO]); |
496 | 487 |
497 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; | 488 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; |
498 DCHECK(navigationItem); | 489 DCHECK(navigationItem); |
499 navigationItem->SetTimestamp( | 490 navigationItem->SetTimestamp( |
500 _timeSmoother.GetSmoothedTime(base::Time::Now())); | 491 _timeSmoother.GetSmoothedTime(base::Time::Now())); |
501 } | 492 } |
502 | 493 |
503 - (void)pushNewEntryWithURL:(const GURL&)URL | 494 - (void)pushNewEntryWithURL:(const GURL&)URL |
504 stateObject:(NSString*)stateObject | 495 stateObject:(NSString*)stateObject |
505 transition:(ui::PageTransition)transition { | 496 transition:(ui::PageTransition)transition { |
506 DCHECK([self currentEntry]); | 497 DCHECK([self currentEntry]); |
507 web::NavigationItem* item = [self currentEntry].navigationItem; | 498 web::NavigationItem* item = [self currentEntry].navigationItem; |
508 CHECK( | 499 CHECK( |
509 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); | 500 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); |
510 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); | 501 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); |
511 bool overrideUserAgent = | 502 bool overrideUserAgent = |
512 self.currentEntry.navigationItem->IsOverridingUserAgent(); | 503 self.currentEntry.navigationItem->IsOverridingUserAgent(); |
513 base::scoped_nsobject<CRWSessionEntry> pushedEntry( | 504 base::scoped_nsobject<CRWSessionEntry> pushedEntry([self |
514 [[self sessionEntryWithURL:URL | 505 sessionEntryWithURL:URL |
515 referrer:referrer | 506 referrer:referrer |
516 transition:transition | 507 transition:transition |
517 useDesktopUserAgent:overrideUserAgent | 508 useDesktopUserAgent:overrideUserAgent |
518 rendererInitiated:NO] retain]); | 509 rendererInitiated:NO]); |
519 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; | 510 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; |
520 pushedItem->SetSerializedStateObject(stateObject); | 511 pushedItem->SetSerializedStateObject(stateObject); |
521 pushedItem->SetIsCreatedFromPushState(true); | 512 pushedItem->SetIsCreatedFromPushState(true); |
522 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); | 513 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); |
523 pushedEntry.get().navigationItem->GetSSL() = sslStatus; | 514 pushedEntry.get().navigationItem->GetSSL() = sslStatus; |
524 | 515 |
525 [self clearForwardEntries]; | 516 [self clearForwardEntries]; |
526 // Add the new entry at the end. | 517 // Add the new entry at the end. |
527 [_entries addObject:pushedEntry]; | 518 [_entries addObject:pushedEntry]; |
528 _previousNavigationIndex = _currentNavigationIndex; | 519 _previousNavigationIndex = _currentNavigationIndex; |
(...skipping 20 matching lines...) Expand all Loading... | |
549 [self discardTransientEntry]; | 540 [self discardTransientEntry]; |
550 _pendingEntry.reset(); | 541 _pendingEntry.reset(); |
551 } | 542 } |
552 | 543 |
553 - (void)discardTransientEntry { | 544 - (void)discardTransientEntry { |
554 // Keep the entry alive temporarily. There are flows that get the current | 545 // Keep the entry alive temporarily. There are flows that get the current |
555 // entry, do some navigation operation, and then try to use that old current | 546 // entry, do some navigation operation, and then try to use that old current |
556 // entry; since navigations clear the transient entry, these flows might | 547 // entry; since navigations clear the transient entry, these flows might |
557 // crash. (This should be removable once more session management is handled | 548 // crash. (This should be removable once more session management is handled |
558 // within this class and/or NavigationManager). | 549 // within this class and/or NavigationManager). |
559 [[_transientEntry retain] autorelease]; | |
560 _transientEntry.reset(); | 550 _transientEntry.reset(); |
561 } | 551 } |
562 | 552 |
563 - (BOOL)hasPendingEntry { | 553 - (BOOL)hasPendingEntry { |
564 return _pendingEntry != nil; | 554 return _pendingEntry != nil; |
565 } | 555 } |
566 | 556 |
567 - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession | 557 - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession |
568 replaceState:(BOOL)replaceState { | 558 replaceState:(BOOL)replaceState { |
569 DCHECK(otherSession); | 559 DCHECK(otherSession); |
570 if (replaceState) { | 560 if (replaceState) { |
571 [_entries removeAllObjects]; | 561 [_entries removeAllObjects]; |
572 self.currentNavigationIndex = -1; | 562 self.currentNavigationIndex = -1; |
573 _previousNavigationIndex = -1; | 563 _previousNavigationIndex = -1; |
574 } | 564 } |
575 self.xCallbackParameters = | 565 self.xCallbackParameters = [base::mac::ObjCCastStrict<NSObject<NSCopying>>( |
576 [[otherSession.xCallbackParameters copy] autorelease]; | 566 otherSession.xCallbackParameters) copy]; |
577 self.windowName = otherSession.windowName; | 567 self.windowName = otherSession.windowName; |
578 NSInteger numInitialEntries = [_entries count]; | 568 NSInteger numInitialEntries = [_entries count]; |
579 | 569 |
580 // Cycle through the entries from the other session and insert them before any | 570 // Cycle through the entries from the other session and insert them before any |
581 // entries from this session. Do not copy anything that comes after the other | 571 // entries from this session. Do not copy anything that comes after the other |
582 // session's current entry unless replaceState is true. | 572 // session's current entry unless replaceState is true. |
583 NSArray* otherEntries = [otherSession entries]; | 573 NSArray* otherEntries = [otherSession entries]; |
584 | 574 |
585 // The other session may not have any entries, in which case there is nothing | 575 // The other session may not have any entries, in which case there is nothing |
586 // to copy or prune. The other session's currentNavigationEntry will be bogus | 576 // to copy or prune. The other session's currentNavigationEntry will be bogus |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 _useDesktopUserAgentForNextPendingEntry = YES; | 833 _useDesktopUserAgentForNextPendingEntry = YES; |
844 } | 834 } |
845 | 835 |
846 #pragma mark - | 836 #pragma mark - |
847 #pragma mark Private methods | 837 #pragma mark Private methods |
848 | 838 |
849 - (NSString*)uniqueID { | 839 - (NSString*)uniqueID { |
850 CFUUIDRef uuidRef = CFUUIDCreate(NULL); | 840 CFUUIDRef uuidRef = CFUUIDCreate(NULL); |
851 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); | 841 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); |
852 CFRelease(uuidRef); | 842 CFRelease(uuidRef); |
853 NSString* uuid = [NSString stringWithString:(NSString*)uuidStringRef]; | 843 NSString* uuid = |
844 [NSString stringWithString:(__bridge NSString*)uuidStringRef]; | |
Eugene But (OOO till 7-30)
2016/08/01 21:13:48
Optional NIT: since you touching this could you pl
stkhapugin
2016/08/18 17:09:36
Done.
| |
854 CFRelease(uuidStringRef); | 845 CFRelease(uuidStringRef); |
855 return uuid; | 846 return uuid; |
856 } | 847 } |
857 | 848 |
858 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 849 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
859 referrer:(const web::Referrer&)referrer | 850 referrer:(const web::Referrer&)referrer |
860 transition:(ui::PageTransition)transition | 851 transition:(ui::PageTransition)transition |
861 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 852 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
862 rendererInitiated:(BOOL)rendererInitiated { | 853 rendererInitiated:(BOOL)rendererInitiated { |
863 GURL loaded_url(url); | 854 GURL loaded_url(url); |
864 BOOL urlWasRewritten = NO; | 855 BOOL urlWasRewritten = NO; |
865 if (_navigationManager) { | 856 if (_navigationManager) { |
866 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> | 857 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> |
867 transientRewriters = _navigationManager->GetTransientURLRewriters(); | 858 transientRewriters = _navigationManager->GetTransientURLRewriters(); |
868 if (transientRewriters) { | 859 if (transientRewriters) { |
869 urlWasRewritten = web::BrowserURLRewriter::RewriteURLWithWriters( | 860 urlWasRewritten = web::BrowserURLRewriter::RewriteURLWithWriters( |
870 &loaded_url, _browserState, *transientRewriters.get()); | 861 &loaded_url, _browserState, *transientRewriters.get()); |
871 } | 862 } |
872 } | 863 } |
873 if (!urlWasRewritten) { | 864 if (!urlWasRewritten) { |
874 web::BrowserURLRewriter::GetInstance()->RewriteURLIfNecessary( | 865 web::BrowserURLRewriter::GetInstance()->RewriteURLIfNecessary( |
875 &loaded_url, _browserState); | 866 &loaded_url, _browserState); |
876 } | 867 } |
877 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); | 868 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); |
878 item->SetURL(loaded_url); | 869 item->SetURL(loaded_url); |
879 item->SetReferrer(referrer); | 870 item->SetReferrer(referrer); |
880 item->SetTransitionType(transition); | 871 item->SetTransitionType(transition); |
881 item->SetIsOverridingUserAgent(useDesktopUserAgent); | 872 item->SetIsOverridingUserAgent(useDesktopUserAgent); |
882 item->set_is_renderer_initiated(rendererInitiated); | 873 item->set_is_renderer_initiated(rendererInitiated); |
883 return [[[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)] | 874 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
884 autorelease]; | |
885 } | 875 } |
886 | 876 |
887 @end | 877 @end |
OLD | NEW |