Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: ios/web/navigation/crw_session_controller.mm

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

Powered by Google App Engine
This is Rietveld 408576698