Index: ios/web/web_state/ui/crw_web_controller.mm |
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm |
index 2bdc779a02dbebffe5213ae641014c96133b87ea..620d34c013fbcb81ebd526b843ed1cf361387b8c 100644 |
--- a/ios/web/web_state/ui/crw_web_controller.mm |
+++ b/ios/web/web_state/ui/crw_web_controller.mm |
@@ -1266,8 +1266,8 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
base::SysUTF8ToNSString(outURL), stateObject]; |
} |
-- (void)finishPushStateNavigationToURL:(const GURL&)url |
- withStateObject:(NSString*)stateObject { |
+- (void)setPushedOrReplacedURL:(const GURL&)url |
+ stateObject:(NSString*)stateObject { |
// TODO(stuartmorgan): Make CRWSessionController manage this internally (or |
// remove it; it's not clear this matches other platforms' behavior). |
_webStateImpl->GetNavigationManagerImpl().OnNavigationItemCommitted(); |
@@ -1763,17 +1763,18 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
- (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
[_delegate webWillFinishHistoryNavigationFromEntry:fromEntry]; |
- // Check if toEntry was created by a JavaScript window.history.pushState() |
- // call from fromEntry. If it was, don't load the URL. Instead update |
- // UIWebView's URL and dispatch a popstate event. |
- if ([_webStateImpl->GetNavigationManagerImpl().GetSessionController() |
+ // If the current entry has a serialized state object, inject its state into |
+ // the web view. |
+ web::NavigationItemImpl* currentItem = |
+ self.currentSessionEntry.navigationItemImpl; |
+ NSString* state = currentItem->GetSerializedStateObject(); |
+ if (state.length) |
+ [self setPushedOrReplacedURL:currentItem->GetURL() stateObject:state]; |
+ // Only load the new URL if the current entry was not created by a JavaScript |
+ // window.history.pushState() call from |fromEntry|. |
+ if (![_webStateImpl->GetNavigationManagerImpl().GetSessionController() |
isPushStateNavigationBetweenEntry:fromEntry |
andEntry:self.currentSessionEntry]) { |
- NSString* state = [self currentSessionEntry] |
- .navigationItemImpl->GetSerializedStateObject(); |
- [self finishPushStateNavigationToURL:[self currentNavigationURL] |
- withStateObject:state]; |
- } else { |
web::NavigationItem* currentItem = |
_webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); |
GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem |