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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 | 70 |
71 // Stores the certificate policies decided by the user. | 71 // Stores the certificate policies decided by the user. |
72 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; | 72 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; |
73 | 73 |
74 // The timestamp of the last time this tab is visited, represented in time | 74 // The timestamp of the last time this tab is visited, represented in time |
75 // interval since 1970. | 75 // interval since 1970. |
76 NSTimeInterval _lastVisitedTimestamp; | 76 NSTimeInterval _lastVisitedTimestamp; |
77 | 77 |
78 // If |YES|, override |currentEntry.useDesktopUserAgent| and create the | 78 // If |YES|, override |currentEntry.useDesktopUserAgent| and create the |
79 // pending entry using the desktop user agent. | 79 // pending entry using the desktop user agent. |
80 BOOL _useDesktopUserAgentForNextPendingEntry; | 80 BOOL _useDesktopUserAgentForNextPendingItem; |
81 | 81 |
82 // The browser state associated with this CRWSessionController; | 82 // The browser state associated with this CRWSessionController; |
83 web::BrowserState* _browserState; // weak | 83 web::BrowserState* _browserState; // weak |
84 | 84 |
85 // Time smoother for navigation entry timestamps; see comment in | 85 // Time smoother for navigation entry timestamps; see comment in |
86 // navigation_controller_impl.h | 86 // navigation_controller_impl.h |
87 web::TimeSmoother _timeSmoother; | 87 web::TimeSmoother _timeSmoother; |
88 } | 88 } |
89 | 89 |
90 // Redefine as readwrite. | 90 // Redefine as readwrite. |
91 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 91 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
92 | 92 |
93 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 93 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
94 // clang bug. crbug.com/228650 | 94 // clang bug. crbug.com/228650 |
95 @property(nonatomic, readwrite, copy) NSString* tabId; | 95 @property(nonatomic, readwrite, copy) NSString* tabId; |
96 @property(nonatomic, readwrite, strong) NSArray* entries; | 96 @property(nonatomic, readwrite, strong) NSArray* entries; |
97 @property(nonatomic, readwrite, strong) | 97 @property(nonatomic, readwrite, strong) |
98 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 98 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
99 | 99 |
100 // Expose setters for serialization properties. These are exposed in a category | 100 // Expose setters for serialization properties. These are exposed in a category |
101 // in NavigationManagerStorageBuilder, and will be removed as ownership of | 101 // in NavigationManagerStorageBuilder, and will be removed as ownership of |
102 // their backing ivars moves to NavigationManagerImpl. | 102 // their backing ivars moves to NavigationManagerImpl. |
103 @property(nonatomic, readwrite, copy) NSString* openerId; | 103 @property(nonatomic, readwrite, copy) NSString* openerId; |
104 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; | 104 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; |
105 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; | 105 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; |
106 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; | 106 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; |
107 | 107 |
108 - (NSString*)uniqueID; | 108 - (NSString*)uniqueID; |
109 // Removes all entries after currentNavigationIndex_. | 109 // Removes all entries after currentNavigationIndex_. |
110 - (void)clearForwardEntries; | 110 - (void)clearForwardItems; |
111 // Discards the transient entry, if any. | 111 // Discards the transient entry, if any. |
112 - (void)discardTransientEntry; | 112 - (void)discardTransientItem; |
113 // Create a new autoreleased session entry. | 113 // Create a new autoreleased session entry. |
114 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 114 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
115 referrer:(const web::Referrer&)referrer | 115 referrer:(const web::Referrer&)referrer |
116 transition:(ui::PageTransition)transition | 116 transition:(ui::PageTransition)transition |
117 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 117 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
118 rendererInitiated:(BOOL)rendererInitiated; | 118 rendererInitiated:(BOOL)rendererInitiated; |
119 // Returns YES if the PageTransition for the underlying navigationItem at | 119 // Returns YES if the PageTransition for the underlying navigationItem at |
120 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. | 120 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
121 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index; | 121 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; |
122 // Returns a NavigationItemList containing the NavigationItems from |entries|. | |
123 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; | |
122 @end | 124 @end |
123 | 125 |
124 @implementation CRWSessionController | 126 @implementation CRWSessionController |
125 | 127 |
126 @synthesize tabId = _tabId; | 128 @synthesize tabId = _tabId; |
127 @synthesize currentNavigationIndex = _currentNavigationIndex; | 129 @synthesize currentNavigationIndex = _currentNavigationIndex; |
128 @synthesize previousNavigationIndex = _previousNavigationIndex; | 130 @synthesize previousNavigationIndex = _previousNavigationIndex; |
129 @synthesize pendingEntryIndex = _pendingEntryIndex; | 131 @synthesize pendingItemIndex = _pendingItemIndex; |
130 @synthesize entries = _entries; | 132 @synthesize entries = _entries; |
131 @synthesize windowName = _windowName; | 133 @synthesize windowName = _windowName; |
132 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | 134 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
133 @synthesize openerId = _openerId; | 135 @synthesize openerId = _openerId; |
134 @synthesize openedByDOM = _openedByDOM; | 136 @synthesize openedByDOM = _openedByDOM; |
135 @synthesize openerNavigationIndex = _openerNavigationIndex; | 137 @synthesize openerNavigationIndex = _openerNavigationIndex; |
136 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 138 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
137 | 139 |
138 - (id)initWithWindowName:(NSString*)windowName | 140 - (id)initWithWindowName:(NSString*)windowName |
139 openerId:(NSString*)openerId | 141 openerId:(NSString*)openerId |
140 openedByDOM:(BOOL)openedByDOM | 142 openedByDOM:(BOOL)openedByDOM |
141 openerNavigationIndex:(NSInteger)openerIndex | 143 openerNavigationIndex:(NSInteger)openerIndex |
142 browserState:(web::BrowserState*)browserState { | 144 browserState:(web::BrowserState*)browserState { |
143 self = [super init]; | 145 self = [super init]; |
144 if (self) { | 146 if (self) { |
145 self.windowName = windowName; | 147 self.windowName = windowName; |
146 _tabId = [[self uniqueID] copy]; | 148 _tabId = [[self uniqueID] copy]; |
147 _openerId = [openerId copy]; | 149 _openerId = [openerId copy]; |
148 _openedByDOM = openedByDOM; | 150 _openedByDOM = openedByDOM; |
149 _openerNavigationIndex = openerIndex; | 151 _openerNavigationIndex = openerIndex; |
150 _browserState = browserState; | 152 _browserState = browserState; |
151 _entries = [NSMutableArray array]; | 153 _entries = [NSMutableArray array]; |
152 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 154 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
153 _currentNavigationIndex = -1; | 155 _currentNavigationIndex = -1; |
154 _previousNavigationIndex = -1; | 156 _previousNavigationIndex = -1; |
155 _pendingEntryIndex = -1; | 157 _pendingItemIndex = -1; |
156 _sessionCertificatePolicyManager = | 158 _sessionCertificatePolicyManager = |
157 [[CRWSessionCertificatePolicyManager alloc] init]; | 159 [[CRWSessionCertificatePolicyManager alloc] init]; |
158 } | 160 } |
159 return self; | 161 return self; |
160 } | 162 } |
161 | 163 |
162 - (id)initWithNavigationItems: | 164 - (id)initWithNavigationItems: |
163 (std::vector<std::unique_ptr<web::NavigationItem>>)items | 165 (std::vector<std::unique_ptr<web::NavigationItem>>)items |
164 currentIndex:(NSUInteger)currentIndex | 166 currentIndex:(NSUInteger)currentIndex |
165 browserState:(web::BrowserState*)browserState { | 167 browserState:(web::BrowserState*)browserState { |
(...skipping 12 matching lines...) Expand all Loading... | |
178 [_entries addObject:entry]; | 180 [_entries addObject:entry]; |
179 } | 181 } |
180 self.currentNavigationIndex = currentIndex; | 182 self.currentNavigationIndex = currentIndex; |
181 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 183 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
182 if (![_entries count]) | 184 if (![_entries count]) |
183 self.currentNavigationIndex = -1; | 185 self.currentNavigationIndex = -1; |
184 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { | 186 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { |
185 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; | 187 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; |
186 } | 188 } |
187 _previousNavigationIndex = -1; | 189 _previousNavigationIndex = -1; |
188 _pendingEntryIndex = -1; | 190 _pendingItemIndex = -1; |
189 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 191 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
190 _sessionCertificatePolicyManager = | 192 _sessionCertificatePolicyManager = |
191 [[CRWSessionCertificatePolicyManager alloc] init]; | 193 [[CRWSessionCertificatePolicyManager alloc] init]; |
192 } | 194 } |
193 return self; | 195 return self; |
194 } | 196 } |
195 | 197 |
196 - (id)copyWithZone:(NSZone*)zone { | 198 - (id)copyWithZone:(NSZone*)zone { |
197 CRWSessionController* copy = [[[self class] alloc] init]; | 199 CRWSessionController* copy = [[[self class] alloc] init]; |
198 copy->_tabId = [_tabId copy]; | 200 copy->_tabId = [_tabId copy]; |
199 copy->_openerId = [_openerId copy]; | 201 copy->_openerId = [_openerId copy]; |
200 copy->_openedByDOM = _openedByDOM; | 202 copy->_openedByDOM = _openedByDOM; |
201 copy->_openerNavigationIndex = _openerNavigationIndex; | 203 copy->_openerNavigationIndex = _openerNavigationIndex; |
202 copy.windowName = self.windowName; | 204 copy.windowName = self.windowName; |
203 copy->_currentNavigationIndex = _currentNavigationIndex; | 205 copy->_currentNavigationIndex = _currentNavigationIndex; |
204 copy->_previousNavigationIndex = _previousNavigationIndex; | 206 copy->_previousNavigationIndex = _previousNavigationIndex; |
205 copy->_pendingEntryIndex = _pendingEntryIndex; | 207 copy->_pendingItemIndex = _pendingItemIndex; |
206 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | 208 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
207 copy->_entries = | 209 copy->_entries = |
208 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; | 210 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
209 copy->_sessionCertificatePolicyManager = | 211 copy->_sessionCertificatePolicyManager = |
210 [_sessionCertificatePolicyManager copy]; | 212 [_sessionCertificatePolicyManager copy]; |
211 return copy; | 213 return copy; |
212 } | 214 } |
213 | 215 |
214 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { | 216 - (void)setCurrentNavigationIndex:(NSInteger)currentNavigationIndex { |
215 if (_currentNavigationIndex != currentNavigationIndex) { | 217 if (_currentNavigationIndex != currentNavigationIndex) { |
216 _currentNavigationIndex = currentNavigationIndex; | 218 _currentNavigationIndex = currentNavigationIndex; |
217 if (_navigationManager) | 219 if (_navigationManager) |
218 _navigationManager->RemoveTransientURLRewriters(); | 220 _navigationManager->RemoveTransientURLRewriters(); |
219 } | 221 } |
220 } | 222 } |
221 | 223 |
222 - (void)setPendingEntryIndex:(NSInteger)index { | 224 - (void)setPendingItemIndex:(NSInteger)index { |
223 DCHECK_GE(index, -1); | 225 DCHECK_GE(index, -1); |
224 DCHECK_LT(index, static_cast<NSInteger>(_entries.count)); | 226 DCHECK_LT(index, static_cast<NSInteger>(_entries.count)); |
225 _pendingEntryIndex = index; | 227 _pendingItemIndex = index; |
226 CRWSessionEntry* entry = index != -1 ? _entries[index] : nil; | 228 CRWSessionEntry* entry = index != -1 ? _entries[index] : nil; |
227 _pendingEntry.reset(entry); | 229 _pendingEntry.reset(entry); |
228 DCHECK(_pendingEntryIndex == -1 || _pendingEntry); | 230 DCHECK(_pendingItemIndex == -1 || _pendingEntry); |
229 } | 231 } |
230 | 232 |
231 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { | 233 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager { |
232 _navigationManager = navigationManager; | 234 _navigationManager = navigationManager; |
233 if (_navigationManager) { | 235 if (_navigationManager) { |
234 // _browserState will be nullptr if CRWSessionController has been | 236 // _browserState will be nullptr if CRWSessionController has been |
235 // initialized with -initWithCoder: method. Take _browserState from | 237 // initialized with -initWithCoder: method. Take _browserState from |
236 // NavigationManagerImpl if that's the case. | 238 // NavigationManagerImpl if that's the case. |
237 if (!_browserState) { | 239 if (!_browserState) { |
238 _browserState = _navigationManager->GetBrowserState(); | 240 _browserState = _navigationManager->GetBrowserState(); |
239 } | 241 } |
240 DCHECK_EQ(_browserState, _navigationManager->GetBrowserState()); | 242 DCHECK_EQ(_browserState, _navigationManager->GetBrowserState()); |
241 } | 243 } |
242 } | 244 } |
243 | 245 |
246 - (void)setBrowserState:(web::BrowserState*)browserState { | |
247 _browserState = browserState; | |
248 DCHECK(!_navigationManager || | |
249 _navigationManager->GetBrowserState() == _browserState); | |
250 } | |
251 | |
244 - (NSString*)description { | 252 - (NSString*)description { |
245 return [NSString | 253 return [NSString |
246 stringWithFormat: | 254 stringWithFormat: |
247 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS | 255 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS |
248 @"\nprevious index: %" PRIdNS @"\npending index: %" PRIdNS | 256 @"\nprevious index: %" PRIdNS @"\npending index: %" PRIdNS |
249 @"\n%@\npending: %@\ntransient: %@\n", | 257 @"\n%@\npending: %@\ntransient: %@\n", |
250 _tabId, self.windowName, _lastVisitedTimestamp, | 258 _tabId, self.windowName, _lastVisitedTimestamp, |
251 _currentNavigationIndex, _previousNavigationIndex, _pendingEntryIndex, | 259 _currentNavigationIndex, _previousNavigationIndex, _pendingItemIndex, |
252 _entries, _pendingEntry.get(), _transientEntry.get()]; | 260 _entries, _pendingEntry.get(), _transientEntry.get()]; |
253 } | 261 } |
254 | 262 |
263 - (web::NavigationItemList)items { | |
264 return [self itemListForEntryList:self.entries]; | |
265 } | |
266 | |
267 - (web::NavigationItemImpl*)currentItem { | |
268 return self.currentEntry.navigationItemImpl; | |
269 } | |
270 | |
271 - (web::NavigationItemImpl*)visibleItem { | |
272 return self.visibleEntry.navigationItemImpl; | |
273 } | |
274 | |
275 - (web::NavigationItemImpl*)pendingItem { | |
276 return self.pendingEntry.navigationItemImpl; | |
277 } | |
278 | |
279 - (web::NavigationItemImpl*)transientItem { | |
280 return self.transientEntry.navigationItemImpl; | |
281 } | |
282 | |
283 - (web::NavigationItemImpl*)lastCommittedItem { | |
284 return self.lastCommittedEntry.navigationItemImpl; | |
285 } | |
286 | |
287 - (web::NavigationItemImpl*)previousItem { | |
288 return self.previousEntry.navigationItemImpl; | |
289 } | |
290 | |
291 - (web::NavigationItemImpl*)lastUserItem { | |
292 return self.lastUserEntry.navigationItemImpl; | |
293 } | |
294 | |
295 - (web::NavigationItemList)backwardItems { | |
296 return [self itemListForEntryList:self.backwardEntries]; | |
297 } | |
298 | |
299 - (web::NavigationItemList)forwardItems { | |
300 return [self itemListForEntryList:self.forwardEntries]; | |
301 } | |
302 | |
255 // Returns the current entry in the session list, or the pending entry if there | 303 // Returns the current entry in the session list, or the pending entry if there |
256 // is a navigation in progress. | 304 // is a navigation in progress. |
257 - (CRWSessionEntry*)currentEntry { | 305 - (CRWSessionEntry*)currentEntry { |
258 if (_transientEntry) | 306 if (_transientEntry) |
259 return _transientEntry.get(); | 307 return _transientEntry.get(); |
260 if (_pendingEntry) | 308 if (_pendingEntry) |
261 return _pendingEntry.get(); | 309 return _pendingEntry.get(); |
262 return [self lastCommittedEntry]; | 310 return [self lastCommittedEntry]; |
263 } | 311 } |
264 | 312 |
265 // See NavigationController::GetVisibleEntry for the motivation for this | 313 // See NavigationController::GetVisibleEntry for the motivation for this |
266 // distinction. | 314 // distinction. |
267 - (CRWSessionEntry*)visibleEntry { | 315 - (CRWSessionEntry*)visibleEntry { |
268 if (_transientEntry) | 316 if (_transientEntry) |
269 return _transientEntry.get(); | 317 return _transientEntry.get(); |
270 // Only return the pending_entry for new (non-history), browser-initiated | 318 // Only return the pending_entry for new (non-history), browser-initiated |
271 // navigations in order to prevent URL spoof attacks. | 319 // navigations in order to prevent URL spoof attacks. |
272 web::NavigationItemImpl* pendingItem = [_pendingEntry navigationItemImpl]; | 320 web::NavigationItemImpl* pendingItem = [_pendingEntry navigationItemImpl]; |
273 bool safeToShowPending = pendingItem && | 321 bool safeToShowPending = pendingItem && |
274 !pendingItem->is_renderer_initiated() && | 322 !pendingItem->is_renderer_initiated() && |
275 _pendingEntryIndex == -1; | 323 _pendingItemIndex == -1; |
276 if (safeToShowPending) { | 324 if (safeToShowPending) { |
277 return _pendingEntry.get(); | 325 return _pendingEntry.get(); |
278 } | 326 } |
279 return [self lastCommittedEntry]; | 327 return [self lastCommittedEntry]; |
280 } | 328 } |
281 | 329 |
282 - (CRWSessionEntry*)pendingEntry { | 330 - (CRWSessionEntry*)pendingEntry { |
283 return _pendingEntry.get(); | 331 return _pendingEntry.get(); |
284 } | 332 } |
285 | 333 |
286 - (CRWSessionEntry*)transientEntry { | 334 - (CRWSessionEntry*)transientEntry { |
287 return _transientEntry.get(); | 335 return _transientEntry.get(); |
288 } | 336 } |
289 | 337 |
290 - (CRWSessionEntry*)lastCommittedEntry { | 338 - (CRWSessionEntry*)lastCommittedEntry { |
291 if (_currentNavigationIndex == -1) | 339 if (_currentNavigationIndex == -1) |
292 return nil; | 340 return nil; |
293 return [_entries objectAtIndex:_currentNavigationIndex]; | 341 return [_entries objectAtIndex:_currentNavigationIndex]; |
294 } | 342 } |
295 | 343 |
296 // Returns the previous entry in the session list, or nil if there isn't any. | 344 // Returns the previous entry in the session list, or nil if there isn't any. |
297 - (CRWSessionEntry*)previousEntry { | 345 - (CRWSessionEntry*)previousEntry { |
298 if ((_previousNavigationIndex < 0) || (![_entries count])) | 346 if ((_previousNavigationIndex < 0) || (![_entries count])) |
299 return nil; | 347 return nil; |
300 return [_entries objectAtIndex:_previousNavigationIndex]; | 348 return [_entries objectAtIndex:_previousNavigationIndex]; |
301 } | 349 } |
302 | 350 |
303 - (void)addPendingEntry:(const GURL&)url | 351 - (void)addPendingItem:(const GURL&)url |
304 referrer:(const web::Referrer&)ref | 352 referrer:(const web::Referrer&)ref |
305 transition:(ui::PageTransition)trans | 353 transition:(ui::PageTransition)trans |
306 rendererInitiated:(BOOL)rendererInitiated { | 354 rendererInitiated:(BOOL)rendererInitiated { |
307 [self discardTransientEntry]; | 355 [self discardTransientItem]; |
308 _pendingEntryIndex = -1; | 356 _pendingItemIndex = -1; |
309 | 357 |
310 // Don't create a new entry if it's already the same as the current entry, | 358 // Don't create a new entry if it's already the same as the current entry, |
311 // allowing this routine to be called multiple times in a row without issue. | 359 // allowing this routine to be called multiple times in a row without issue. |
312 // Note: CRWSessionController currently has the responsibility to distinguish | 360 // Note: CRWSessionController currently has the responsibility to distinguish |
313 // between new navigations and history stack navigation, hence the inclusion | 361 // between new navigations and history stack navigation, hence the inclusion |
314 // of specific transiton type logic here, in order to make it reliable with | 362 // of specific transiton type logic here, in order to make it reliable with |
315 // real-world observed behavior. | 363 // real-world observed behavior. |
316 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere | 364 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere |
317 // in the web layer so that this hack can be removed. | 365 // in the web layer so that this hack can be removed. |
318 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. | 366 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. |
319 CRWSessionEntry* currentEntry = self.currentEntry; | 367 CRWSessionEntry* currentEntry = self.currentEntry; |
320 if (currentEntry) { | 368 if (currentEntry) { |
321 web::NavigationItem* item = [currentEntry navigationItem]; | 369 web::NavigationItem* item = [currentEntry navigationItem]; |
322 if (item->GetURL() == url && | 370 if (item->GetURL() == url && |
323 (!PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT) || | 371 (!PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT) || |
324 PageTransitionCoreTypeIs(item->GetTransitionType(), | 372 PageTransitionCoreTypeIs(item->GetTransitionType(), |
325 ui::PAGE_TRANSITION_FORM_SUBMIT))) { | 373 ui::PAGE_TRANSITION_FORM_SUBMIT))) { |
326 // Send the notification anyway, to preserve old behavior. It's unknown | 374 // Send the notification anyway, to preserve old behavior. It's unknown |
327 // whether anything currently relies on this, but since both this whole | 375 // whether anything currently relies on this, but since both this whole |
328 // hack and the content facade will both be going away, it's not worth | 376 // hack and the content facade will both be going away, it's not worth |
329 // trying to unwind. | 377 // trying to unwind. |
330 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 378 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
331 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 379 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
332 } | 380 } |
333 return; | 381 return; |
334 } | 382 } |
335 } | 383 } |
336 | 384 |
337 BOOL useDesktopUserAgent = | 385 BOOL useDesktopUserAgent = |
338 _useDesktopUserAgentForNextPendingEntry || | 386 _useDesktopUserAgentForNextPendingItem || |
339 (self.currentEntry.navigationItem && | 387 (self.currentEntry.navigationItem && |
340 self.currentEntry.navigationItem->IsOverridingUserAgent()); | 388 self.currentEntry.navigationItem->IsOverridingUserAgent()); |
341 _useDesktopUserAgentForNextPendingEntry = NO; | 389 _useDesktopUserAgentForNextPendingItem = NO; |
342 _pendingEntry.reset([self sessionEntryWithURL:url | 390 _pendingEntry.reset([self sessionEntryWithURL:url |
343 referrer:ref | 391 referrer:ref |
344 transition:trans | 392 transition:trans |
345 useDesktopUserAgent:useDesktopUserAgent | 393 useDesktopUserAgent:useDesktopUserAgent |
346 rendererInitiated:rendererInitiated]); | 394 rendererInitiated:rendererInitiated]); |
347 | 395 |
348 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 396 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
349 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 397 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
350 } | 398 } |
351 } | 399 } |
352 | 400 |
353 - (void)updatePendingEntry:(const GURL&)url { | 401 - (void)updatePendingItem:(const GURL&)url { |
354 // If there is no pending entry, navigation is probably happening within the | 402 // If there is no pending entry, navigation is probably happening within the |
355 // session history. Don't modify the entry list. | 403 // session history. Don't modify the entry list. |
356 if (!_pendingEntry) | 404 if (!_pendingEntry) |
357 return; | 405 return; |
358 | 406 |
359 web::NavigationItemImpl* item = [_pendingEntry navigationItemImpl]; | 407 web::NavigationItemImpl* item = [_pendingEntry navigationItemImpl]; |
360 if (url != item->GetURL()) { | 408 if (url != item->GetURL()) { |
361 // Assume a redirection, and discard any transient entry. | 409 // Assume a redirection, and discard any transient entry. |
362 // TODO(stuartmorgan): Once the current safe browsing code is gone, | 410 // TODO(stuartmorgan): Once the current safe browsing code is gone, |
363 // consider making this a DCHECK that there's no transient entry. | 411 // consider making this a DCHECK that there's no transient entry. |
364 [self discardTransientEntry]; | 412 [self discardTransientItem]; |
365 | 413 |
366 item->SetURL(url); | 414 item->SetURL(url); |
367 item->SetVirtualURL(url); | 415 item->SetVirtualURL(url); |
368 // Redirects (3xx response code), or client side navigation must change | 416 // Redirects (3xx response code), or client side navigation must change |
369 // POST requests to GETs. | 417 // POST requests to GETs. |
370 item->SetPostData(nil); | 418 item->SetPostData(nil); |
371 item->ResetHttpRequestHeaders(); | 419 item->ResetHttpRequestHeaders(); |
372 } | 420 } |
373 | 421 |
374 // This should probably not be sent if the URLs matched, but that's what was | 422 // This should probably not be sent if the URLs matched, but that's what was |
375 // done before, so preserve behavior in case something relies on it. | 423 // done before, so preserve behavior in case something relies on it. |
376 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 424 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
377 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 425 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
378 } | 426 } |
379 } | 427 } |
380 | 428 |
381 - (void)clearForwardEntries { | 429 - (void)clearForwardItems { |
382 DCHECK_EQ(_pendingEntryIndex, -1); | 430 DCHECK_EQ(_pendingItemIndex, -1); |
383 [self discardTransientEntry]; | 431 [self discardTransientItem]; |
384 | 432 |
385 NSInteger forwardEntryStartIndex = _currentNavigationIndex + 1; | 433 NSInteger forwardItemStartIndex = _currentNavigationIndex + 1; |
386 DCHECK(forwardEntryStartIndex >= 0); | 434 DCHECK(forwardItemStartIndex >= 0); |
387 | 435 |
388 if (forwardEntryStartIndex >= static_cast<NSInteger>([_entries count])) | 436 if (forwardItemStartIndex >= static_cast<NSInteger>([_entries count])) |
389 return; | 437 return; |
390 | 438 |
391 NSRange remove = NSMakeRange(forwardEntryStartIndex, | 439 NSRange remove = NSMakeRange(forwardItemStartIndex, |
392 [_entries count] - forwardEntryStartIndex); | 440 [_entries count] - forwardItemStartIndex); |
393 // Store removed items in temporary NSArray so they can be deallocated after | 441 // Store removed items in temporary NSArray so they can be deallocated after |
394 // their facades. | 442 // their facades. |
395 base::scoped_nsobject<NSArray> removedItems( | 443 base::scoped_nsobject<NSArray> removedItems( |
396 [_entries subarrayWithRange:remove]); | 444 [_entries subarrayWithRange:remove]); |
397 [_entries removeObjectsInRange:remove]; | 445 [_entries removeObjectsInRange:remove]; |
398 if (_previousNavigationIndex >= forwardEntryStartIndex) | 446 if (_previousNavigationIndex >= forwardItemStartIndex) |
399 _previousNavigationIndex = -1; | 447 _previousNavigationIndex = -1; |
400 if (_navigationManager) { | 448 if (_navigationManager) { |
401 _navigationManager->OnNavigationItemsPruned(remove.length); | 449 _navigationManager->OnNavigationItemsPruned(remove.length); |
402 } | 450 } |
403 } | 451 } |
404 | 452 |
405 - (void)commitPendingEntry { | 453 - (void)commitPendingItem { |
406 if (_pendingEntry) { | 454 if (_pendingEntry) { |
407 NSInteger newNavigationIndex = _pendingEntryIndex; | 455 NSInteger newNavigationIndex = _pendingItemIndex; |
408 if (_pendingEntryIndex == -1) { | 456 if (_pendingItemIndex == -1) { |
409 [self clearForwardEntries]; | 457 [self clearForwardItems]; |
410 // Add the new entry at the end. | 458 // Add the new entry at the end. |
411 [_entries addObject:_pendingEntry]; | 459 [_entries addObject:_pendingEntry]; |
412 newNavigationIndex = [_entries count] - 1; | 460 newNavigationIndex = [_entries count] - 1; |
413 } | 461 } |
414 _previousNavigationIndex = _currentNavigationIndex; | 462 _previousNavigationIndex = _currentNavigationIndex; |
415 self.currentNavigationIndex = newNavigationIndex; | 463 self.currentNavigationIndex = newNavigationIndex; |
416 // Once an entry is committed it's not renderer-initiated any more. (Matches | 464 // Once an entry is committed it's not renderer-initiated any more. (Matches |
417 // the implementation in NavigationController.) | 465 // the implementation in NavigationController.) |
418 [_pendingEntry navigationItemImpl]->ResetForCommit(); | 466 [_pendingEntry navigationItemImpl]->ResetForCommit(); |
419 _pendingEntry.reset(); | 467 _pendingEntry.reset(); |
420 _pendingEntryIndex = -1; | 468 _pendingItemIndex = -1; |
421 } | 469 } |
422 | 470 |
423 CRWSessionEntry* currentEntry = self.currentEntry; | 471 CRWSessionEntry* currentEntry = self.currentEntry; |
424 web::NavigationItem* item = currentEntry.navigationItem; | 472 web::NavigationItem* item = currentEntry.navigationItem; |
425 // Update the navigation timestamp now that it's actually happened. | 473 // Update the navigation timestamp now that it's actually happened. |
426 if (item) | 474 if (item) |
427 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); | 475 item->SetTimestamp(_timeSmoother.GetSmoothedTime(base::Time::Now())); |
428 | 476 |
429 if (_navigationManager && item) | 477 if (_navigationManager && item) |
430 _navigationManager->OnNavigationItemCommitted(); | 478 _navigationManager->OnNavigationItemCommitted(); |
431 DCHECK_EQ(_pendingEntryIndex, -1); | 479 DCHECK_EQ(_pendingItemIndex, -1); |
432 } | 480 } |
433 | 481 |
434 - (void)addTransientEntryWithURL:(const GURL&)URL { | 482 - (void)addTransientItemWithURL:(const GURL&)URL { |
435 _transientEntry.reset([self | 483 _transientEntry.reset([self |
436 sessionEntryWithURL:URL | 484 sessionEntryWithURL:URL |
437 referrer:web::Referrer() | 485 referrer:web::Referrer() |
438 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 486 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
439 useDesktopUserAgent:NO | 487 useDesktopUserAgent:NO |
440 rendererInitiated:NO]); | 488 rendererInitiated:NO]); |
441 | 489 |
442 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; | 490 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; |
443 DCHECK(navigationItem); | 491 DCHECK(navigationItem); |
444 navigationItem->SetTimestamp( | 492 navigationItem->SetTimestamp( |
445 _timeSmoother.GetSmoothedTime(base::Time::Now())); | 493 _timeSmoother.GetSmoothedTime(base::Time::Now())); |
446 } | 494 } |
447 | 495 |
448 - (void)pushNewEntryWithURL:(const GURL&)URL | 496 - (void)pushNewItemWithURL:(const GURL&)URL |
449 stateObject:(NSString*)stateObject | 497 stateObject:(NSString*)stateObject |
450 transition:(ui::PageTransition)transition { | 498 transition:(ui::PageTransition)transition { |
451 DCHECK(![self pendingEntry]); | 499 DCHECK(![self pendingEntry]); |
452 DCHECK([self currentEntry]); | 500 DCHECK([self currentEntry]); |
453 web::NavigationItem* item = [self currentEntry].navigationItem; | 501 web::NavigationItem* item = [self currentEntry].navigationItem; |
454 CHECK( | 502 CHECK( |
455 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); | 503 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); |
456 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); | 504 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); |
457 bool overrideUserAgent = | 505 bool overrideUserAgent = |
458 self.currentEntry.navigationItem->IsOverridingUserAgent(); | 506 self.currentEntry.navigationItem->IsOverridingUserAgent(); |
459 base::scoped_nsobject<CRWSessionEntry> pushedEntry([self | 507 base::scoped_nsobject<CRWSessionEntry> pushedEntry([self |
460 sessionEntryWithURL:URL | 508 sessionEntryWithURL:URL |
461 referrer:referrer | 509 referrer:referrer |
462 transition:transition | 510 transition:transition |
463 useDesktopUserAgent:overrideUserAgent | 511 useDesktopUserAgent:overrideUserAgent |
464 rendererInitiated:NO]); | 512 rendererInitiated:NO]); |
465 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; | 513 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; |
466 pushedItem->SetSerializedStateObject(stateObject); | 514 pushedItem->SetSerializedStateObject(stateObject); |
467 pushedItem->SetIsCreatedFromPushState(true); | 515 pushedItem->SetIsCreatedFromPushState(true); |
468 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); | 516 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); |
469 pushedEntry.get().navigationItem->GetSSL() = sslStatus; | 517 pushedEntry.get().navigationItem->GetSSL() = sslStatus; |
470 | 518 |
471 [self clearForwardEntries]; | 519 [self clearForwardItems]; |
472 // Add the new entry at the end. | 520 // Add the new entry at the end. |
473 [_entries addObject:pushedEntry]; | 521 [_entries addObject:pushedEntry]; |
474 _previousNavigationIndex = _currentNavigationIndex; | 522 _previousNavigationIndex = _currentNavigationIndex; |
475 self.currentNavigationIndex = [_entries count] - 1; | 523 self.currentNavigationIndex = [_entries count] - 1; |
476 | 524 |
477 if (_navigationManager) | 525 if (_navigationManager) |
478 _navigationManager->OnNavigationItemCommitted(); | 526 _navigationManager->OnNavigationItemCommitted(); |
479 } | 527 } |
480 | 528 |
481 - (void)updateCurrentEntryWithURL:(const GURL&)url | 529 - (void)updateCurrentItemWithURL:(const GURL&)url |
482 stateObject:(NSString*)stateObject { | 530 stateObject:(NSString*)stateObject { |
483 DCHECK(!_transientEntry); | 531 DCHECK(!_transientEntry); |
484 CRWSessionEntry* currentEntry = self.currentEntry; | 532 CRWSessionEntry* currentEntry = self.currentEntry; |
485 web::NavigationItemImpl* currentItem = self.currentEntry.navigationItemImpl; | 533 web::NavigationItemImpl* currentItem = self.currentEntry.navigationItemImpl; |
486 currentItem->SetURL(url); | 534 currentItem->SetURL(url); |
487 currentItem->SetSerializedStateObject(stateObject); | 535 currentItem->SetSerializedStateObject(stateObject); |
488 currentItem->SetHasStateBeenReplaced(true); | 536 currentItem->SetHasStateBeenReplaced(true); |
489 currentItem->SetPostData(nil); | 537 currentItem->SetPostData(nil); |
490 currentEntry.navigationItem->SetURL(url); | 538 currentEntry.navigationItem->SetURL(url); |
491 // If the change is to a committed entry, notify interested parties. | 539 // If the change is to a committed entry, notify interested parties. |
492 if (currentEntry != self.pendingEntry && _navigationManager) | 540 if (currentEntry != self.pendingEntry && _navigationManager) |
493 _navigationManager->OnNavigationItemChanged(); | 541 _navigationManager->OnNavigationItemChanged(); |
494 } | 542 } |
495 | 543 |
496 - (void)discardNonCommittedEntries { | 544 - (void)discardNonCommittedItems { |
497 [self discardTransientEntry]; | 545 [self discardTransientItem]; |
498 _pendingEntry.reset(); | 546 _pendingEntry.reset(); |
499 _pendingEntryIndex = -1; | 547 _pendingItemIndex = -1; |
500 } | 548 } |
501 | 549 |
502 - (void)discardTransientEntry { | 550 - (void)discardTransientItem { |
503 // Keep the entry alive temporarily. There are flows that get the current | 551 // Keep the entry alive temporarily. There are flows that get the current |
504 // entry, do some navigation operation, and then try to use that old current | 552 // entry, do some navigation operation, and then try to use that old current |
505 // entry; since navigations clear the transient entry, these flows might | 553 // entry; since navigations clear the transient entry, these flows might |
506 // crash. (This should be removable once more session management is handled | 554 // crash. (This should be removable once more session management is handled |
507 // within this class and/or NavigationManager). | 555 // within this class and/or NavigationManager). |
508 _transientEntry.reset(); | 556 _transientEntry.reset(); |
509 } | 557 } |
510 | 558 |
511 - (BOOL)hasPendingEntry { | |
512 return _pendingEntry != nil; | |
513 } | |
514 | |
515 - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession { | 559 - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession { |
516 DCHECK(sourceSession); | 560 DCHECK(sourceSession); |
517 self.windowName = sourceSession.windowName; | 561 self.windowName = sourceSession.windowName; |
518 | 562 |
519 // The other session may not have any entries, in which case there is nothing | 563 // The other session may not have any entries, in which case there is nothing |
520 // to insert. The other session's currentNavigationEntry will be bogus | 564 // to insert. The other session's currentNavigationEntry will be bogus |
521 // in such cases, so ignore it and return early. | 565 // in such cases, so ignore it and return early. |
522 NSArray* sourceEntries = sourceSession.entries; | 566 NSArray* sourceEntries = sourceSession.entries; |
523 if (!sourceEntries.count) | 567 if (!sourceEntries.count) |
524 return; | 568 return; |
525 | 569 |
526 // 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 |
527 // 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 |
528 // session's current entry. | 572 // session's current entry. |
529 NSInteger lastIndexToCopy = sourceSession.currentNavigationIndex; | 573 NSInteger lastIndexToCopy = sourceSession.currentNavigationIndex; |
530 for (NSInteger i = 0; i <= lastIndexToCopy; ++i) { | 574 for (NSInteger i = 0; i <= lastIndexToCopy; ++i) { |
531 [_entries insertObject:sourceEntries[i] atIndex:i]; | 575 [_entries insertObject:sourceEntries[i] atIndex:i]; |
532 } | 576 } |
533 | 577 |
534 _previousNavigationIndex = -1; | 578 _previousNavigationIndex = -1; |
535 _currentNavigationIndex += lastIndexToCopy + 1; | 579 _currentNavigationIndex += lastIndexToCopy + 1; |
536 if (_pendingEntryIndex != -1) | 580 if (_pendingItemIndex != -1) |
537 _pendingEntryIndex += lastIndexToCopy + 1; | 581 _pendingItemIndex += lastIndexToCopy + 1; |
538 | 582 |
539 DCHECK_LT(static_cast<NSUInteger>(_currentNavigationIndex), _entries.count); | 583 DCHECK_LT(static_cast<NSUInteger>(_currentNavigationIndex), _entries.count); |
540 DCHECK(_pendingEntryIndex == -1 || _pendingEntry); | 584 DCHECK(_pendingItemIndex == -1 || _pendingEntry); |
541 } | 585 } |
542 | 586 |
543 - (void)goToEntryAtIndex:(NSInteger)index { | 587 - (void)goToItemAtIndex:(NSInteger)index { |
544 if (index < 0 || static_cast<NSUInteger>(index) >= _entries.count) | 588 if (index < 0 || static_cast<NSUInteger>(index) >= _entries.count) |
545 return; | 589 return; |
546 | 590 |
547 if (index < _currentNavigationIndex) { | 591 if (index < _currentNavigationIndex) { |
548 // Going back. | 592 // Going back. |
549 [self discardNonCommittedEntries]; | 593 [self discardNonCommittedItems]; |
550 } else if (_currentNavigationIndex < index) { | 594 } else if (_currentNavigationIndex < index) { |
551 // Going forward. | 595 // Going forward. |
552 [self discardTransientEntry]; | 596 [self discardTransientItem]; |
553 } else { | 597 } else { |
554 // |delta| is 0, no need to change current navigation index. | 598 // |delta| is 0, no need to change current navigation index. |
555 return; | 599 return; |
556 } | 600 } |
557 | 601 |
558 _previousNavigationIndex = _currentNavigationIndex; | 602 _previousNavigationIndex = _currentNavigationIndex; |
559 _currentNavigationIndex = index; | 603 _currentNavigationIndex = index; |
560 } | 604 } |
561 | 605 |
562 - (void)removeEntryAtIndex:(NSInteger)index { | 606 - (void)removeItemAtIndex:(NSInteger)index { |
563 DCHECK(index < static_cast<NSInteger>([_entries count])); | 607 DCHECK(index < static_cast<NSInteger>([_entries count])); |
564 DCHECK(index != _currentNavigationIndex); | 608 DCHECK(index != _currentNavigationIndex); |
565 DCHECK(index >= 0); | 609 DCHECK(index >= 0); |
566 | 610 |
567 [self discardNonCommittedEntries]; | 611 [self discardNonCommittedItems]; |
568 | 612 |
569 [_entries removeObjectAtIndex:index]; | 613 [_entries removeObjectAtIndex:index]; |
570 if (_currentNavigationIndex > index) | 614 if (_currentNavigationIndex > index) |
571 _currentNavigationIndex--; | 615 _currentNavigationIndex--; |
572 if (_previousNavigationIndex >= index) | 616 if (_previousNavigationIndex >= index) |
573 _previousNavigationIndex--; | 617 _previousNavigationIndex--; |
574 } | 618 } |
575 | 619 |
576 - (NSArray*)backwardEntries { | 620 - (NSArray*)backwardEntries { |
577 NSMutableArray* entries = [NSMutableArray array]; | 621 NSMutableArray* entries = [NSMutableArray array]; |
578 for (NSInteger index = _currentNavigationIndex; index > 0; --index) { | 622 for (NSInteger index = _currentNavigationIndex; index > 0; --index) { |
579 if (![self isRedirectTransitionForEntryAtIndex:index]) | 623 if (![self isRedirectTransitionForItemAtIndex:index]) |
580 [entries addObject:_entries[index - 1]]; | 624 [entries addObject:_entries[index - 1]]; |
581 } | 625 } |
582 return entries; | 626 return entries; |
583 } | 627 } |
584 | 628 |
585 - (NSArray*)forwardEntries { | 629 - (NSArray*)forwardEntries { |
586 NSMutableArray* entries = [NSMutableArray array]; | 630 NSMutableArray* entries = [NSMutableArray array]; |
587 NSUInteger lastNonRedirectedIndex = _currentNavigationIndex + 1; | 631 NSUInteger lastNonRedirectedIndex = _currentNavigationIndex + 1; |
588 while (lastNonRedirectedIndex < [_entries count]) { | 632 while (lastNonRedirectedIndex < [_entries count]) { |
589 CRWSessionEntry* entry = [_entries objectAtIndex:lastNonRedirectedIndex]; | 633 CRWSessionEntry* entry = [_entries objectAtIndex:lastNonRedirectedIndex]; |
590 if (!ui::PageTransitionIsRedirect( | 634 if (!ui::PageTransitionIsRedirect( |
591 entry.navigationItem->GetTransitionType())) { | 635 entry.navigationItem->GetTransitionType())) { |
592 [entries addObject:entry]; | 636 [entries addObject:entry]; |
593 } | 637 } |
594 ++lastNonRedirectedIndex; | 638 ++lastNonRedirectedIndex; |
595 } | 639 } |
596 return entries; | 640 return entries; |
597 } | 641 } |
598 | 642 |
599 - (BOOL)isSameDocumentNavigationBetweenEntry:(CRWSessionEntry*)firstEntry | 643 - (BOOL)isSameDocumentNavigationBetweenItem:(web::NavigationItem*)firstItem |
600 andEntry:(CRWSessionEntry*)secondEntry { | 644 andItem:(web::NavigationItem*)secondItem { |
601 if (!firstEntry || !secondEntry || firstEntry == secondEntry) | 645 if (!firstItem || !secondItem || firstItem == secondItem) |
602 return NO; | 646 return NO; |
603 NSUInteger firstIndex = [_entries indexOfObject:firstEntry]; | 647 NSUInteger firstIndex = [self indexOfItem:firstItem]; |
604 NSUInteger secondIndex = [_entries indexOfObject:secondEntry]; | 648 NSUInteger secondIndex = [self indexOfItem:secondItem]; |
605 if (firstIndex == NSNotFound || secondIndex == NSNotFound) | 649 if (firstIndex == NSNotFound || secondIndex == NSNotFound) |
606 return NO; | 650 return NO; |
607 NSUInteger startIndex = firstIndex < secondIndex ? firstIndex : secondIndex; | 651 NSUInteger startIndex = firstIndex < secondIndex ? firstIndex : secondIndex; |
608 NSUInteger endIndex = firstIndex < secondIndex ? secondIndex : firstIndex; | 652 NSUInteger endIndex = firstIndex < secondIndex ? secondIndex : firstIndex; |
609 | 653 |
610 for (NSUInteger i = startIndex + 1; i <= endIndex; i++) { | 654 for (NSUInteger i = startIndex + 1; i <= endIndex; i++) { |
611 web::NavigationItemImpl* item = [_entries[i] navigationItemImpl]; | 655 web::NavigationItemImpl* item = [_entries[i] navigationItemImpl]; |
612 // Every entry in the sequence has to be created from a hash change or | 656 // Every entry in the sequence has to be created from a hash change or |
613 // pushState() call. | 657 // pushState() call. |
614 if (!item->IsCreatedFromPushState() && !item->IsCreatedFromHashChange()) | 658 if (!item->IsCreatedFromPushState() && !item->IsCreatedFromHashChange()) |
615 return NO; | 659 return NO; |
616 // Every entry in the sequence has to have a URL that could have been | 660 // Every entry in the sequence has to have a URL that could have been |
617 // created from a pushState() call. | 661 // created from a pushState() call. |
618 if (!web::history_state_util::IsHistoryStateChangeValid( | 662 if (!web::history_state_util::IsHistoryStateChangeValid(firstItem->GetURL(), |
619 firstEntry.navigationItem->GetURL(), item->GetURL())) | 663 item->GetURL())) |
620 return NO; | 664 return NO; |
621 } | 665 } |
622 return YES; | 666 return YES; |
623 } | 667 } |
624 | 668 |
625 - (CRWSessionEntry*)lastUserEntry { | 669 - (CRWSessionEntry*)lastUserEntry { |
626 if (![_entries count]) | 670 if (![_entries count]) |
627 return nil; | 671 return nil; |
628 | 672 |
629 NSInteger index = _currentNavigationIndex; | 673 NSInteger index = _currentNavigationIndex; |
630 // This will return the first session entry if all other entries are | 674 // This will return the first session entry if all other entries are |
631 // redirects, regardless of the transition state of the first entry. | 675 // redirects, regardless of the transition state of the first entry. |
632 while (index > 0 && [self isRedirectTransitionForEntryAtIndex:index]) { | 676 while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) { |
633 --index; | 677 --index; |
634 } | 678 } |
635 return [_entries objectAtIndex:index]; | 679 return [_entries objectAtIndex:index]; |
636 } | 680 } |
637 | 681 |
638 - (void)useDesktopUserAgentForNextPendingEntry { | 682 - (void)useDesktopUserAgentForNextPendingItem { |
639 if (_pendingEntry) | 683 if (_pendingEntry) |
640 [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true); | 684 [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true); |
641 else | 685 else |
642 _useDesktopUserAgentForNextPendingEntry = YES; | 686 _useDesktopUserAgentForNextPendingItem = YES; |
687 } | |
688 | |
689 - (NSInteger)indexOfItem:(web::NavigationItem*)item { | |
690 web::NavigationItemList items = self.items; | |
691 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { | |
692 if (items[i] == item) | |
693 return i; | |
694 } | |
695 return NSNotFound; | |
643 } | 696 } |
644 | 697 |
645 #pragma mark - | 698 #pragma mark - |
646 #pragma mark Private methods | 699 #pragma mark Private methods |
647 | 700 |
648 - (NSString*)uniqueID { | 701 - (NSString*)uniqueID { |
649 CFUUIDRef uuidRef = CFUUIDCreate(NULL); | 702 CFUUIDRef uuidRef = CFUUIDCreate(NULL); |
650 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); | 703 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); |
651 CFRelease(uuidRef); | 704 CFRelease(uuidRef); |
652 | 705 |
(...skipping 25 matching lines...) Expand all Loading... | |
678 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); | 731 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); |
679 item->SetOriginalRequestURL(loaded_url); | 732 item->SetOriginalRequestURL(loaded_url); |
680 item->SetURL(loaded_url); | 733 item->SetURL(loaded_url); |
681 item->SetReferrer(referrer); | 734 item->SetReferrer(referrer); |
682 item->SetTransitionType(transition); | 735 item->SetTransitionType(transition); |
683 item->SetIsOverridingUserAgent(useDesktopUserAgent); | 736 item->SetIsOverridingUserAgent(useDesktopUserAgent); |
684 item->set_is_renderer_initiated(rendererInitiated); | 737 item->set_is_renderer_initiated(rendererInitiated); |
685 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 738 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
686 } | 739 } |
687 | 740 |
688 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { | 741 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index { |
689 ui::PageTransition transition = | 742 ui::PageTransition transition = |
690 [_entries[index] navigationItem]->GetTransitionType(); | 743 [_entries[index] navigationItem]->GetTransitionType(); |
691 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 744 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
692 } | 745 } |
693 | 746 |
747 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { | |
748 web::NavigationItemList list; | |
Eugene But (OOO till 7-30)
2017/02/03 23:33:33
nit: pass entries.count into constructor?
kkhorimoto
2017/02/04 02:45:30
Done.
| |
749 for (CRWSessionEntry* entry in entries) | |
750 list.push_back(entry.navigationItem); | |
Eugene But (OOO till 7-30)
2017/02/03 23:33:33
emplace_back ?
kkhorimoto
2017/02/04 02:45:30
|emplace_back| passes its input parameters to the
| |
751 return list; | |
752 } | |
753 | |
694 @end | 754 @end |
OLD | NEW |