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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 - (void)setBrowserState:(web::BrowserState*)browserState { | 278 - (void)setBrowserState:(web::BrowserState*)browserState { |
279 _browserState = browserState; | 279 _browserState = browserState; |
280 DCHECK(!_navigationManager || | 280 DCHECK(!_navigationManager || |
281 _navigationManager->GetBrowserState() == _browserState); | 281 _navigationManager->GetBrowserState() == _browserState); |
282 } | 282 } |
283 | 283 |
284 - (void)addPendingItem:(const GURL&)url | 284 - (void)addPendingItem:(const GURL&)url |
285 referrer:(const web::Referrer&)ref | 285 referrer:(const web::Referrer&)ref |
286 transition:(ui::PageTransition)trans | 286 transition:(ui::PageTransition)trans |
287 initiationType:(web::NavigationInitiationType)initiationType { | 287 initiationType:(web::NavigationInitiationType)initiationType |
288 userAgentOverrideOption:(web::NavigationManager::UserAgentOverrideOption) | |
289 userAgentOverrideOption { | |
288 // Server side redirects are handled by updating existing pending item instead | 290 // Server side redirects are handled by updating existing pending item instead |
289 // of adding a new item. | 291 // of adding a new item. |
290 DCHECK((trans & ui::PAGE_TRANSITION_SERVER_REDIRECT) == 0); | 292 DCHECK((trans & ui::PAGE_TRANSITION_SERVER_REDIRECT) == 0); |
291 | 293 |
292 [self discardTransientItem]; | 294 [self discardTransientItem]; |
293 self.pendingItemIndex = -1; | 295 self.pendingItemIndex = -1; |
294 | 296 |
295 // Don't create a new item if it's already the same as the current item, | 297 // Don't create a new item if it's already the same as the current item, |
296 // allowing this routine to be called multiple times in a row without issue. | 298 // allowing this routine to be called multiple times in a row without issue. |
297 // Note: CRWSessionController currently has the responsibility to distinguish | 299 // Note: CRWSessionController currently has the responsibility to distinguish |
298 // between new navigations and history stack navigation, hence the inclusion | 300 // between new navigations and history stack navigation, hence the inclusion |
299 // of specific transiton type logic here, in order to make it reliable with | 301 // of specific transiton type logic here, in order to make it reliable with |
300 // real-world observed behavior. | 302 // real-world observed behavior. |
301 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere | 303 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere |
302 // in the web layer so that this hack can be removed. | 304 // in the web layer so that this hack can be removed. |
303 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. | 305 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. |
304 web::NavigationItemImpl* currentItem = self.currentItem; | 306 web::NavigationItemImpl* currentItem = self.currentItem; |
305 if (currentItem) { | 307 if (currentItem) { |
306 BOOL hasSameURL = currentItem->GetURL() == url; | 308 BOOL hasSameURL = currentItem->GetURL() == url; |
307 BOOL isPendingTransitionFormSubmit = | 309 BOOL isPendingTransitionFormSubmit = |
308 PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT); | 310 PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT); |
309 BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs( | 311 BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs( |
310 currentItem->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT); | 312 currentItem->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT); |
313 | |
kkhorimoto
2017/04/06 22:36:19
Remove this newline.
liaoyuke
2017/04/07 15:49:08
Done.
| |
314 DCHECK(userAgentOverrideOption != | |
Eugene But (OOO till 7-30)
2017/04/06 22:53:17
Please explain in the comments the purpose of thes
liaoyuke
2017/04/07 15:49:08
Done.
| |
315 web::NavigationManager::UserAgentOverrideOption::DESKTOP || | |
316 currentItem->GetUserAgentType() != web::UserAgentType::DESKTOP); | |
317 DCHECK(userAgentOverrideOption != | |
318 web::NavigationManager::UserAgentOverrideOption::MOBILE || | |
319 currentItem->GetUserAgentType() != web::UserAgentType::MOBILE); | |
kkhorimoto
2017/04/06 22:36:19
Let's move these DCHECKs to the top of this functi
liaoyuke
2017/04/07 15:49:08
Acknowledged.
| |
320 BOOL hasDifferentUserAgentType = | |
kkhorimoto
2017/04/06 22:36:19
Can we instead have a BOOL |isInheritingUserAgentT
liaoyuke
2017/04/07 15:49:08
Done.
| |
321 userAgentOverrideOption != | |
322 web::NavigationManager::UserAgentOverrideOption::INHERIT; | |
323 | |
311 BOOL shouldCreatePendingItem = | 324 BOOL shouldCreatePendingItem = |
Eugene But (OOO till 7-30)
2017/04/06 22:53:17
This logic was already complex and got even more c
liaoyuke
2017/04/07 15:49:08
yes, that's better.
| |
312 !hasSameURL || | 325 !hasSameURL || |
313 (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit); | 326 (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit) || |
327 hasDifferentUserAgentType; | |
314 | 328 |
315 if (!shouldCreatePendingItem) { | 329 if (!shouldCreatePendingItem) { |
316 // Send the notification anyway, to preserve old behavior. It's unknown | 330 // Send the notification anyway, to preserve old behavior. It's unknown |
317 // whether anything currently relies on this, but since both this whole | 331 // whether anything currently relies on this, but since both this whole |
318 // hack and the content facade will both be going away, it's not worth | 332 // hack and the content facade will both be going away, it's not worth |
319 // trying to unwind. | 333 // trying to unwind. |
320 if (_navigationManager && _navigationManager->GetFacadeDelegate()) | 334 if (_navigationManager && _navigationManager->GetFacadeDelegate()) |
321 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 335 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
322 return; | 336 return; |
323 } | 337 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 return item; | 643 return item; |
630 } | 644 } |
631 | 645 |
632 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { | 646 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { |
633 DCHECK_LT(index, self.items.size()); | 647 DCHECK_LT(index, self.items.size()); |
634 ui::PageTransition transition = self.items[index]->GetTransitionType(); | 648 ui::PageTransition transition = self.items[index]->GetTransitionType(); |
635 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 649 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
636 } | 650 } |
637 | 651 |
638 @end | 652 @end |
OLD | NEW |