| 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/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/ios/block_types.h" | 10 #include "base/ios/block_types.h" |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 | 1259 |
| 1260 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)url | 1260 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)url |
| 1261 stateObjectJSON:(NSString*)stateObject { | 1261 stateObjectJSON:(NSString*)stateObject { |
| 1262 std::string outURL; | 1262 std::string outURL; |
| 1263 base::EscapeJSONString(url.spec(), true, &outURL); | 1263 base::EscapeJSONString(url.spec(), true, &outURL); |
| 1264 return | 1264 return |
| 1265 [NSString stringWithFormat:@"__gCrWeb.replaceWebViewURL(%@, %@);", | 1265 [NSString stringWithFormat:@"__gCrWeb.replaceWebViewURL(%@, %@);", |
| 1266 base::SysUTF8ToNSString(outURL), stateObject]; | 1266 base::SysUTF8ToNSString(outURL), stateObject]; |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 - (void)finishPushStateNavigationToURL:(const GURL&)url | 1269 - (void)setPushedOrReplacedURL:(const GURL&)url |
| 1270 withStateObject:(NSString*)stateObject { | 1270 stateObject:(NSString*)stateObject { |
| 1271 // TODO(stuartmorgan): Make CRWSessionController manage this internally (or | 1271 // TODO(stuartmorgan): Make CRWSessionController manage this internally (or |
| 1272 // remove it; it's not clear this matches other platforms' behavior). | 1272 // remove it; it's not clear this matches other platforms' behavior). |
| 1273 _webStateImpl->GetNavigationManagerImpl().OnNavigationItemCommitted(); | 1273 _webStateImpl->GetNavigationManagerImpl().OnNavigationItemCommitted(); |
| 1274 | 1274 |
| 1275 NSString* replaceWebViewUrlJS = | 1275 NSString* replaceWebViewUrlJS = |
| 1276 [self javascriptToReplaceWebViewURL:url stateObjectJSON:stateObject]; | 1276 [self javascriptToReplaceWebViewURL:url stateObjectJSON:stateObject]; |
| 1277 std::string outState; | 1277 std::string outState; |
| 1278 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); | 1278 base::EscapeJSONString(base::SysNSStringToUTF8(stateObject), true, &outState); |
| 1279 NSString* popstateJS = | 1279 NSString* popstateJS = |
| 1280 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", | 1280 [NSString stringWithFormat:@"__gCrWeb.dispatchPopstateEvent(%@);", |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 [self restoreStateFromHistory]; | 1756 [self restoreStateFromHistory]; |
| 1757 _webStateImpl->OnPageLoaded(currentURL, loadSuccess); | 1757 _webStateImpl->OnPageLoaded(currentURL, loadSuccess); |
| 1758 _webStateImpl->SetIsLoading(false); | 1758 _webStateImpl->SetIsLoading(false); |
| 1759 // Inform the embedder the load completed. | 1759 // Inform the embedder the load completed. |
| 1760 [_delegate webDidFinishWithURL:currentURL loadSuccess:loadSuccess]; | 1760 [_delegate webDidFinishWithURL:currentURL loadSuccess:loadSuccess]; |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { | 1763 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| 1764 [_delegate webWillFinishHistoryNavigationFromEntry:fromEntry]; | 1764 [_delegate webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| 1765 | 1765 |
| 1766 // Check if toEntry was created by a JavaScript window.history.pushState() | 1766 // If the current entry has a serialized state object, inject its state into |
| 1767 // call from fromEntry. If it was, don't load the URL. Instead update | 1767 // the web view. |
| 1768 // UIWebView's URL and dispatch a popstate event. | 1768 web::NavigationItemImpl* currentItem = |
| 1769 if ([_webStateImpl->GetNavigationManagerImpl().GetSessionController() | 1769 self.currentSessionEntry.navigationItemImpl; |
| 1770 NSString* state = currentItem->GetSerializedStateObject(); |
| 1771 if (state.length) |
| 1772 [self setPushedOrReplacedURL:currentItem->GetURL() stateObject:state]; |
| 1773 // Only load the new URL if the current entry was not created by a JavaScript |
| 1774 // window.history.pushState() call from |fromEntry|. |
| 1775 if (![_webStateImpl->GetNavigationManagerImpl().GetSessionController() |
| 1770 isPushStateNavigationBetweenEntry:fromEntry | 1776 isPushStateNavigationBetweenEntry:fromEntry |
| 1771 andEntry:self.currentSessionEntry]) { | 1777 andEntry:self.currentSessionEntry]) { |
| 1772 NSString* state = [self currentSessionEntry] | |
| 1773 .navigationItemImpl->GetSerializedStateObject(); | |
| 1774 [self finishPushStateNavigationToURL:[self currentNavigationURL] | |
| 1775 withStateObject:state]; | |
| 1776 } else { | |
| 1777 web::NavigationItem* currentItem = | 1778 web::NavigationItem* currentItem = |
| 1778 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); | 1779 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); |
| 1779 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem | 1780 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem |
| 1780 toItem:currentItem]; | 1781 toItem:currentItem]; |
| 1781 ui::PageTransition transition = ui::PageTransitionFromInt( | 1782 ui::PageTransition transition = ui::PageTransitionFromInt( |
| 1782 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); | 1783 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); |
| 1783 | 1784 |
| 1784 web::WebLoadParams params(endURL); | 1785 web::WebLoadParams params(endURL); |
| 1785 if (currentItem) { | 1786 if (currentItem) { |
| 1786 params.referrer = currentItem->GetReferrer(); | 1787 params.referrer = currentItem->GetReferrer(); |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3800 if (!_externalRequest || !_externalRequest->window_name) | 3801 if (!_externalRequest || !_externalRequest->window_name) |
| 3801 return @""; | 3802 return @""; |
| 3802 return _externalRequest->window_name; | 3803 return _externalRequest->window_name; |
| 3803 } | 3804 } |
| 3804 | 3805 |
| 3805 - (void)resetExternalRequest { | 3806 - (void)resetExternalRequest { |
| 3806 _externalRequest.reset(); | 3807 _externalRequest.reset(); |
| 3807 } | 3808 } |
| 3808 | 3809 |
| 3809 @end | 3810 @end |
| OLD | NEW |