Chromium Code Reviews| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 107 |
| 108 - (NSString*)uniqueID; | 108 - (NSString*)uniqueID; |
| 109 // Removes all entries after currentNavigationIndex_. | 109 // Removes all entries after currentNavigationIndex_. |
| 110 - (void)clearForwardItems; | 110 - (void)clearForwardItems; |
| 111 // Discards the transient entry, if any. | 111 // Discards the transient entry, if any. |
| 112 - (void)discardTransientItem; | 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 | |
| 118 rendererInitiated:(BOOL)rendererInitiated; | 117 rendererInitiated:(BOOL)rendererInitiated; |
| 119 // Returns YES if the PageTransition for the underlying navigationItem at | 118 // Returns YES if the PageTransition for the underlying navigationItem at |
| 120 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. | 119 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
| 121 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; | 120 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; |
| 122 // Returns a NavigationItemList containing the NavigationItems from |entries|. | 121 // Returns a NavigationItemList containing the NavigationItems from |entries|. |
| 123 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; | 122 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; |
| 124 @end | 123 @end |
| 125 | 124 |
| 126 @implementation CRWSessionController | 125 @implementation CRWSessionController |
| 127 | 126 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 // Note: CRWSessionController currently has the responsibility to distinguish | 359 // Note: CRWSessionController currently has the responsibility to distinguish |
| 361 // between new navigations and history stack navigation, hence the inclusion | 360 // between new navigations and history stack navigation, hence the inclusion |
| 362 // of specific transiton type logic here, in order to make it reliable with | 361 // of specific transiton type logic here, in order to make it reliable with |
| 363 // real-world observed behavior. | 362 // real-world observed behavior. |
| 364 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere | 363 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere |
| 365 // in the web layer so that this hack can be removed. | 364 // in the web layer so that this hack can be removed. |
| 366 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. | 365 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. |
| 367 CRWSessionEntry* currentEntry = self.currentEntry; | 366 CRWSessionEntry* currentEntry = self.currentEntry; |
| 368 if (currentEntry) { | 367 if (currentEntry) { |
| 369 web::NavigationItem* item = [currentEntry navigationItem]; | 368 web::NavigationItem* item = [currentEntry navigationItem]; |
| 370 if (item->GetURL() == url && | 369 |
| 371 (!PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT) || | 370 BOOL hasSameURL = item->GetURL() == url; |
| 372 PageTransitionCoreTypeIs(item->GetTransitionType(), | 371 BOOL isPendingTransitionFormSubmit = |
| 373 ui::PAGE_TRANSITION_FORM_SUBMIT))) { | 372 PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT); |
| 373 BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs( | |
| 374 item->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT); | |
| 375 BOOL shouldCreatePendingItem = | |
| 376 !hasSameURL || | |
| 377 (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit); | |
| 378 | |
| 379 if (!shouldCreatePendingItem) { | |
| 374 // Send the notification anyway, to preserve old behavior. It's unknown | 380 // Send the notification anyway, to preserve old behavior. It's unknown |
| 375 // whether anything currently relies on this, but since both this whole | 381 // whether anything currently relies on this, but since both this whole |
| 376 // hack and the content facade will both be going away, it's not worth | 382 // hack and the content facade will both be going away, it's not worth |
| 377 // trying to unwind. | 383 // trying to unwind. |
| 378 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 384 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
| 379 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 385 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
| 380 } | 386 } |
| 381 return; | 387 return; |
| 382 } | 388 } |
| 383 } | 389 } |
| 384 | 390 |
| 385 BOOL useDesktopUserAgent = | |
| 386 _useDesktopUserAgentForNextPendingItem || | |
| 387 (self.currentEntry.navigationItem && | |
| 388 self.currentEntry.navigationItem->IsOverridingUserAgent()); | |
| 389 _useDesktopUserAgentForNextPendingItem = NO; | |
| 390 _pendingEntry.reset([self sessionEntryWithURL:url | 391 _pendingEntry.reset([self sessionEntryWithURL:url |
| 391 referrer:ref | 392 referrer:ref |
| 392 transition:trans | 393 transition:trans |
| 393 useDesktopUserAgent:useDesktopUserAgent | |
| 394 rendererInitiated:rendererInitiated]); | 394 rendererInitiated:rendererInitiated]); |
| 395 | 395 |
| 396 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { | 396 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { |
| 397 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); | 397 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 - (void)updatePendingItem:(const GURL&)url { | 401 - (void)updatePendingItem:(const GURL&)url { |
| 402 // 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 |
| 403 // session history. Don't modify the entry list. | 403 // session history. Don't modify the entry list. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 if (_navigationManager && item) | 477 if (_navigationManager && item) |
| 478 _navigationManager->OnNavigationItemCommitted(); | 478 _navigationManager->OnNavigationItemCommitted(); |
| 479 DCHECK_EQ(_pendingItemIndex, -1); | 479 DCHECK_EQ(_pendingItemIndex, -1); |
| 480 } | 480 } |
| 481 | 481 |
| 482 - (void)addTransientItemWithURL:(const GURL&)URL { | 482 - (void)addTransientItemWithURL:(const GURL&)URL { |
| 483 _transientEntry.reset([self | 483 _transientEntry.reset([self |
| 484 sessionEntryWithURL:URL | 484 sessionEntryWithURL:URL |
| 485 referrer:web::Referrer() | 485 referrer:web::Referrer() |
| 486 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 486 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
| 487 useDesktopUserAgent:NO | |
| 488 rendererInitiated:NO]); | 487 rendererInitiated:NO]); |
| 489 | 488 |
| 490 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; | 489 web::NavigationItem* navigationItem = [_transientEntry navigationItem]; |
| 491 DCHECK(navigationItem); | 490 DCHECK(navigationItem); |
| 492 navigationItem->SetTimestamp( | 491 navigationItem->SetTimestamp( |
| 493 _timeSmoother.GetSmoothedTime(base::Time::Now())); | 492 _timeSmoother.GetSmoothedTime(base::Time::Now())); |
| 494 } | 493 } |
| 495 | 494 |
| 496 - (void)pushNewItemWithURL:(const GURL&)URL | 495 - (void)pushNewItemWithURL:(const GURL&)URL |
| 497 stateObject:(NSString*)stateObject | 496 stateObject:(NSString*)stateObject |
| 498 transition:(ui::PageTransition)transition { | 497 transition:(ui::PageTransition)transition { |
| 499 DCHECK(![self pendingEntry]); | 498 DCHECK(![self pendingEntry]); |
| 500 DCHECK([self currentEntry]); | 499 DCHECK([self currentEntry]); |
| 501 web::NavigationItem* item = [self currentEntry].navigationItem; | 500 web::NavigationItem* item = [self currentEntry].navigationItem; |
| 502 CHECK( | 501 CHECK( |
| 503 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); | 502 web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL)); |
| 504 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); | 503 web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault); |
| 505 bool overrideUserAgent = | 504 |
| 506 self.currentEntry.navigationItem->IsOverridingUserAgent(); | |
| 507 base::scoped_nsobject<CRWSessionEntry> pushedEntry([self | 505 base::scoped_nsobject<CRWSessionEntry> pushedEntry([self |
| 508 sessionEntryWithURL:URL | 506 sessionEntryWithURL:URL |
| 509 referrer:referrer | 507 referrer:referrer |
| 510 transition:transition | 508 transition:transition |
| 511 useDesktopUserAgent:overrideUserAgent | |
| 512 rendererInitiated:NO]); | 509 rendererInitiated:NO]); |
| 510 | |
| 513 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; | 511 web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl]; |
| 512 bool overrideUserAgent = | |
| 513 self.currentEntry.navigationItem->IsOverridingUserAgent(); | |
|
Eugene But (OOO till 7-30)
2017/02/16 02:20:48
nit: How about this?:
pushedItem->SetIsOverridingU
liaoyuke
2017/02/16 22:04:29
Done.
| |
| 514 pushedItem->SetIsOverridingUserAgent(overrideUserAgent); | |
| 514 pushedItem->SetSerializedStateObject(stateObject); | 515 pushedItem->SetSerializedStateObject(stateObject); |
| 515 pushedItem->SetIsCreatedFromPushState(true); | 516 pushedItem->SetIsCreatedFromPushState(true); |
| 516 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); | 517 web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL(); |
| 517 pushedEntry.get().navigationItem->GetSSL() = sslStatus; | 518 pushedEntry.get().navigationItem->GetSSL() = sslStatus; |
| 518 | 519 |
| 519 [self clearForwardItems]; | 520 [self clearForwardItems]; |
| 520 // Add the new entry at the end. | 521 // Add the new entry at the end. |
| 521 [_entries addObject:pushedEntry]; | 522 [_entries addObject:pushedEntry]; |
| 522 _previousNavigationIndex = _currentNavigationIndex; | 523 _previousNavigationIndex = _currentNavigationIndex; |
| 523 self.currentNavigationIndex = [_entries count] - 1; | 524 self.currentNavigationIndex = [_entries count] - 1; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 | 673 |
| 673 NSInteger index = _currentNavigationIndex; | 674 NSInteger index = _currentNavigationIndex; |
| 674 // This will return the first session entry if all other entries are | 675 // This will return the first session entry if all other entries are |
| 675 // redirects, regardless of the transition state of the first entry. | 676 // redirects, regardless of the transition state of the first entry. |
| 676 while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) { | 677 while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) { |
| 677 --index; | 678 --index; |
| 678 } | 679 } |
| 679 return [_entries objectAtIndex:index]; | 680 return [_entries objectAtIndex:index]; |
| 680 } | 681 } |
| 681 | 682 |
| 682 - (void)useDesktopUserAgentForNextPendingItem { | |
| 683 if (_pendingEntry) | |
| 684 [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true); | |
| 685 else | |
| 686 _useDesktopUserAgentForNextPendingItem = YES; | |
| 687 } | |
| 688 | |
| 689 - (NSInteger)indexOfItem:(const web::NavigationItem*)item { | 683 - (NSInteger)indexOfItem:(const web::NavigationItem*)item { |
| 690 web::NavigationItemList items = self.items; | 684 web::NavigationItemList items = self.items; |
| 691 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { | 685 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { |
| 692 if (items[i] == item) | 686 if (items[i] == item) |
| 693 return i; | 687 return i; |
| 694 } | 688 } |
| 695 return NSNotFound; | 689 return NSNotFound; |
| 696 } | 690 } |
| 697 | 691 |
| 698 #pragma mark - | 692 #pragma mark - |
| 699 #pragma mark Private methods | 693 #pragma mark Private methods |
| 700 | 694 |
| 701 - (NSString*)uniqueID { | 695 - (NSString*)uniqueID { |
| 702 CFUUIDRef uuidRef = CFUUIDCreate(NULL); | 696 CFUUIDRef uuidRef = CFUUIDCreate(NULL); |
| 703 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); | 697 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); |
| 704 CFRelease(uuidRef); | 698 CFRelease(uuidRef); |
| 705 | 699 |
| 706 NSString* uuid = | 700 NSString* uuid = |
| 707 [NSString stringWithString:base::mac::ObjCCastStrict<NSString>( | 701 [NSString stringWithString:base::mac::ObjCCastStrict<NSString>( |
| 708 CFBridgingRelease(uuidStringRef))]; | 702 CFBridgingRelease(uuidStringRef))]; |
| 709 return uuid; | 703 return uuid; |
| 710 } | 704 } |
| 711 | 705 |
| 712 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 706 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| 713 referrer:(const web::Referrer&)referrer | 707 referrer:(const web::Referrer&)referrer |
| 714 transition:(ui::PageTransition)transition | 708 transition:(ui::PageTransition)transition |
| 715 useDesktopUserAgent:(BOOL)useDesktopUserAgent | |
| 716 rendererInitiated:(BOOL)rendererInitiated { | 709 rendererInitiated:(BOOL)rendererInitiated { |
| 717 GURL loaded_url(url); | 710 GURL loaded_url(url); |
| 718 BOOL urlWasRewritten = NO; | 711 BOOL urlWasRewritten = NO; |
| 719 if (_navigationManager) { | 712 if (_navigationManager) { |
| 720 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> | 713 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> |
| 721 transientRewriters = _navigationManager->GetTransientURLRewriters(); | 714 transientRewriters = _navigationManager->GetTransientURLRewriters(); |
| 722 if (transientRewriters) { | 715 if (transientRewriters) { |
| 723 urlWasRewritten = web::BrowserURLRewriter::RewriteURLWithWriters( | 716 urlWasRewritten = web::BrowserURLRewriter::RewriteURLWithWriters( |
| 724 &loaded_url, _browserState, *transientRewriters.get()); | 717 &loaded_url, _browserState, *transientRewriters.get()); |
| 725 } | 718 } |
| 726 } | 719 } |
| 727 if (!urlWasRewritten) { | 720 if (!urlWasRewritten) { |
| 728 web::BrowserURLRewriter::GetInstance()->RewriteURLIfNecessary( | 721 web::BrowserURLRewriter::GetInstance()->RewriteURLIfNecessary( |
| 729 &loaded_url, _browserState); | 722 &loaded_url, _browserState); |
| 730 } | 723 } |
| 731 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); | 724 std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl()); |
| 732 item->SetOriginalRequestURL(loaded_url); | 725 item->SetOriginalRequestURL(loaded_url); |
| 733 item->SetURL(loaded_url); | 726 item->SetURL(loaded_url); |
| 734 item->SetReferrer(referrer); | 727 item->SetReferrer(referrer); |
| 735 item->SetTransitionType(transition); | 728 item->SetTransitionType(transition); |
| 736 item->SetIsOverridingUserAgent(useDesktopUserAgent); | |
| 737 item->set_is_renderer_initiated(rendererInitiated); | 729 item->set_is_renderer_initiated(rendererInitiated); |
| 738 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 730 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
| 739 } | 731 } |
| 740 | 732 |
| 741 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index { | 733 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index { |
| 742 ui::PageTransition transition = | 734 ui::PageTransition transition = |
| 743 [_entries[index] navigationItem]->GetTransitionType(); | 735 [_entries[index] navigationItem]->GetTransitionType(); |
| 744 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 736 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 745 } | 737 } |
| 746 | 738 |
| 747 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { | 739 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { |
| 748 web::NavigationItemList list(entries.count); | 740 web::NavigationItemList list(entries.count); |
| 749 for (size_t index = 0; index < entries.count; ++index) | 741 for (size_t index = 0; index < entries.count; ++index) |
| 750 list[index] = [entries[index] navigationItem]; | 742 list[index] = [entries[index] navigationItem]; |
| 751 return list; | 743 return list; |
| 752 } | 744 } |
| 753 | 745 |
| 754 @end | 746 @end |
| OLD | NEW |