Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2842443002: Create NavigationContext right after the navigation was started. (Closed)
Patch Set: Fixed tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #import <objc/runtime.h> 9 #import <objc/runtime.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // navigation is committed. 592 // navigation is committed.
593 - (void)commitPendingNavigationInfo; 593 - (void)commitPendingNavigationInfo;
594 // Returns a NSMutableURLRequest that represents the current NavigationItem. 594 // Returns a NSMutableURLRequest that represents the current NavigationItem.
595 - (NSMutableURLRequest*)requestForCurrentNavigationItem; 595 - (NSMutableURLRequest*)requestForCurrentNavigationItem;
596 // Returns the WKBackForwardListItemHolder for the current navigation item. 596 // Returns the WKBackForwardListItemHolder for the current navigation item.
597 - (web::WKBackForwardListItemHolder*)currentBackForwardListItemHolder; 597 - (web::WKBackForwardListItemHolder*)currentBackForwardListItemHolder;
598 // Updates the WKBackForwardListItemHolder navigation item. 598 // Updates the WKBackForwardListItemHolder navigation item.
599 - (void)updateCurrentBackForwardListItemHolder; 599 - (void)updateCurrentBackForwardListItemHolder;
600 600
601 // Loads the current nativeController in a native view. If a web view is 601 // Loads the current nativeController in a native view. If a web view is
602 // present, removes it and swaps in the native view in its place. 602 // present, removes it and swaps in the native view in its place. |context| can
603 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess; 603 // not be null.
604 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess
605 navigationContext:(web::NavigationContextImpl*)context;
606 // Loads the correct HTML page for |error| in a native controller, retrieved
607 // from the native provider.
608 - (void)loadErrorInNativeView:(NSError*)error
609 navigationContext:(web::NavigationContextImpl*)context;
604 // YES if the navigation to |url| should be treated as a reload. 610 // YES if the navigation to |url| should be treated as a reload.
605 - (BOOL)shouldReload:(const GURL&)destinationURL 611 - (BOOL)shouldReload:(const GURL&)destinationURL
606 transition:(ui::PageTransition)transition; 612 transition:(ui::PageTransition)transition;
607 // Internal implementation of reload. Reloads without notifying the delegate. 613 // Internal implementation of reload. Reloads without notifying the delegate.
608 // Most callers should use -reload instead. 614 // Most callers should use -reload instead.
609 - (void)reloadInternal; 615 - (void)reloadInternal;
610 // Aborts any load for both the web view and web controller. 616 // Aborts any load for both the web view and web controller.
611 - (void)abortLoad; 617 - (void)abortLoad;
612 // Updates the internal state and informs the delegate that any outstanding load 618 // Updates the internal state and informs the delegate that any outstanding load
613 // operations are cancelled. 619 // operations are cancelled.
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)), 1335 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)),
1330 web::ReferrerPolicyAlways); 1336 web::ReferrerPolicyAlways);
1331 } 1337 }
1332 1338
1333 - (void)pushStateWithPageURL:(const GURL&)pageURL 1339 - (void)pushStateWithPageURL:(const GURL&)pageURL
1334 stateObject:(NSString*)stateObject 1340 stateObject:(NSString*)stateObject
1335 transition:(ui::PageTransition)transition { 1341 transition:(ui::PageTransition)transition {
1336 [[self sessionController] pushNewItemWithURL:pageURL 1342 [[self sessionController] pushNewItemWithURL:pageURL
1337 stateObject:stateObject 1343 stateObject:stateObject
1338 transition:transition]; 1344 transition:transition];
1339 _webStateImpl->OnSameDocumentNavigation(pageURL); 1345 std::unique_ptr<web::NavigationContext> context =
1346 web::NavigationContextImpl::CreateSameDocumentNavigationContext(
1347 _webStateImpl, pageURL);
1348 _webStateImpl->OnNavigationFinished(context.get());
1340 self.userInteractionRegistered = NO; 1349 self.userInteractionRegistered = NO;
1341 } 1350 }
1342 1351
1343 - (void)replaceStateWithPageURL:(const GURL&)pageURL 1352 - (void)replaceStateWithPageURL:(const GURL&)pageURL
1344 stateObject:(NSString*)stateObject { 1353 stateObject:(NSString*)stateObject {
1345 [[self sessionController] updateCurrentItemWithURL:pageURL 1354 [[self sessionController] updateCurrentItemWithURL:pageURL
1346 stateObject:stateObject]; 1355 stateObject:stateObject];
1347 _webStateImpl->OnSameDocumentNavigation(pageURL); 1356 std::unique_ptr<web::NavigationContext> context =
1357 web::NavigationContextImpl::CreateSameDocumentNavigationContext(
1358 _webStateImpl, pageURL);
1359 _webStateImpl->OnNavigationFinished(context.get());
1348 } 1360 }
1349 1361
1350 - (void)setDocumentURL:(const GURL&)newURL { 1362 - (void)setDocumentURL:(const GURL&)newURL {
1351 if (newURL != _documentURL && newURL.is_valid()) { 1363 if (newURL != _documentURL && newURL.is_valid()) {
1352 _documentURL = newURL; 1364 _documentURL = newURL;
1353 _interactionRegisteredSinceLastURLChange = NO; 1365 _interactionRegisteredSinceLastURLChange = NO;
1354 } 1366 }
1355 } 1367 }
1356 1368
1357 - (void)setNavigationItemTitle:(NSString*)title { 1369 - (void)setNavigationItemTitle:(NSString*)title {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1519 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1508 [[self sessionController] updatePendingItem:requestURL]; 1520 [[self sessionController] updatePendingItem:requestURL];
1509 } else { 1521 } else {
1510 // A new session history entry needs to be created. 1522 // A new session history entry needs to be created.
1511 self.navigationManagerImpl->AddPendingItem( 1523 self.navigationManagerImpl->AddPendingItem(
1512 requestURL, referrer, transition, 1524 requestURL, referrer, transition,
1513 web::NavigationInitiationType::RENDERER_INITIATED, 1525 web::NavigationInitiationType::RENDERER_INITIATED,
1514 web::NavigationManager::UserAgentOverrideOption::INHERIT); 1526 web::NavigationManager::UserAgentOverrideOption::INHERIT);
1515 } 1527 }
1516 std::unique_ptr<web::NavigationContextImpl> context = 1528 std::unique_ptr<web::NavigationContextImpl> context =
1517 web::NavigationContextImpl::CreateNavigationContext( 1529 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl,
1518 _webStateImpl, requestURL, nullptr /* response_headers */); 1530 requestURL);
1519 _webStateImpl->SetIsLoading(true); 1531 _webStateImpl->SetIsLoading(true);
1520 // TODO(crbug.com/713836): pass context to |OnProvisionalNavigationStarted|. 1532 // TODO(crbug.com/713836): pass context to |OnProvisionalNavigationStarted|.
1521 _webStateImpl->OnProvisionalNavigationStarted(requestURL); 1533 _webStateImpl->OnProvisionalNavigationStarted(requestURL);
1522 return context; 1534 return context;
1523 } 1535 }
1524 1536
1525 - (void)updateHTML5HistoryState { 1537 - (void)updateHTML5HistoryState {
1526 web::NavigationItemImpl* currentItem = self.currentNavItem; 1538 web::NavigationItemImpl* currentItem = self.currentNavItem;
1527 if (!currentItem) 1539 if (!currentItem)
1528 return; 1540 return;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 holder->set_http_method([_pendingNavigationInfo HTTPMethod]); 1754 holder->set_http_method([_pendingNavigationInfo HTTPMethod]);
1743 1755
1744 // Only update the MIME type in the holder if there was MIME type information 1756 // Only update the MIME type in the holder if there was MIME type information
1745 // as part of this pending load. It will be nil when doing a fast 1757 // as part of this pending load. It will be nil when doing a fast
1746 // back/forward navigation, for instance, because the callback that would 1758 // back/forward navigation, for instance, because the callback that would
1747 // populate it is not called in that flow. 1759 // populate it is not called in that flow.
1748 if ([_pendingNavigationInfo MIMEType]) 1760 if ([_pendingNavigationInfo MIMEType])
1749 holder->set_mime_type([_pendingNavigationInfo MIMEType]); 1761 holder->set_mime_type([_pendingNavigationInfo MIMEType]);
1750 } 1762 }
1751 1763
1752 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { 1764 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess
1765 navigationContext:(web::NavigationContextImpl*)context {
1753 const GURL currentURL([self currentURL]); 1766 const GURL currentURL([self currentURL]);
1754 [self didStartLoadingURL:currentURL]; 1767 [self didStartLoadingURL:currentURL];
1755 _loadPhase = web::PAGE_LOADED; 1768 _loadPhase = web::PAGE_LOADED;
1756 if (loadSuccess) { 1769 _webStateImpl->OnNavigationFinished(context);
1757 _webStateImpl->OnNavigationCommitted(currentURL);
1758 } else {
1759 _webStateImpl->OnErrorPageNavigation(currentURL);
1760 }
1761 1770
1762 // Perform post-load-finished updates. 1771 // Perform post-load-finished updates.
1763 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; 1772 [self didFinishWithURL:currentURL loadSuccess:loadSuccess];
1764 1773
1765 NSString* title = [self.nativeController title]; 1774 NSString* title = [self.nativeController title];
1766 if (title) { 1775 if (title) {
1767 [self setNavigationItemTitle:title]; 1776 [self setNavigationItemTitle:title];
1768 } 1777 }
1769 1778
1770 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { 1779 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) {
1771 [self.nativeController setDelegate:self]; 1780 [self.nativeController setDelegate:self];
1772 } 1781 }
1773 } 1782 }
1774 1783
1775 - (void)loadErrorInNativeView:(NSError*)error { 1784 - (void)loadErrorInNativeView:(NSError*)error
1785 navigationContext:(web::NavigationContextImpl*)context {
1776 [self removeWebViewAllowingCachedReconstruction:NO]; 1786 [self removeWebViewAllowingCachedReconstruction:NO];
1777 web::NavigationItem* item = self.currentNavItem; 1787 web::NavigationItem* item = self.currentNavItem;
1778 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); 1788 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
1779 1789
1780 if (web::IsWKWebViewSSLCertError(error)) { 1790 if (web::IsWKWebViewSSLCertError(error)) {
1781 // This could happen only if certificate is absent or could not be parsed. 1791 // This could happen only if certificate is absent or could not be parsed.
1782 error = web::NetErrorFromError(error, net::ERR_SSL_SERVER_CERT_BAD_FORMAT); 1792 error = web::NetErrorFromError(error, net::ERR_SSL_SERVER_CERT_BAD_FORMAT);
1783 #if defined(DEBUG) 1793 #if defined(DEBUG)
1784 net::SSLInfo info; 1794 net::SSLInfo info;
1785 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); 1795 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info);
1786 CHECK(!error.cert); 1796 CHECK(!error.cert);
1787 #endif 1797 #endif
1788 } else { 1798 } else {
1789 error = web::NetErrorFromError(error); 1799 error = web::NetErrorFromError(error);
1790 } 1800 }
1791 1801
1792 BOOL isPost = [self isCurrentNavigationItemPOST]; 1802 BOOL isPost = [self isCurrentNavigationItemPOST];
1793 [self setNativeController:[_nativeProvider controllerForURL:currentURL 1803 [self setNativeController:[_nativeProvider controllerForURL:currentURL
1794 withError:error 1804 withError:error
1795 isPost:isPost]]; 1805 isPost:isPost]];
1796 [self loadNativeViewWithSuccess:NO]; 1806 [self loadNativeViewWithSuccess:NO navigationContext:context];
1797 } 1807 }
1798 1808
1799 // Load the current URL in a native controller, retrieved from the native 1809 // Loads the current URL in a native controller, retrieved from the native
1800 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. 1810 // provider.
1801 - (void)loadCurrentURLInNativeView { 1811 - (void)loadCurrentURLInNativeView {
1802 // Free the web view. 1812 // Free the web view.
1803 [self removeWebViewAllowingCachedReconstruction:NO]; 1813 [self removeWebViewAllowingCachedReconstruction:NO];
1804 1814
1805 web::NavigationItem* item = self.currentNavItem; 1815 web::NavigationItem* item = self.currentNavItem;
1806 const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL(); 1816 const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL();
1807 const web::Referrer referrer; 1817 const web::Referrer referrer;
1808 id<CRWNativeContent> nativeContent = 1818 id<CRWNativeContent> nativeContent =
1809 [_nativeProvider controllerForURL:targetURL webState:self.webState]; 1819 [_nativeProvider controllerForURL:targetURL webState:self.webState];
1810 // Unlike the WebView case, always create a new controller and view. 1820 // Unlike the WebView case, always create a new controller and view.
1811 // TODO(pinkerton): What to do if this does return nil? 1821 // TODO(pinkerton): What to do if this does return nil?
1812 [self setNativeController:nativeContent]; 1822 [self setNativeController:nativeContent];
1813 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { 1823 if ([nativeContent respondsToSelector:@selector(virtualURL)]) {
1814 item->SetVirtualURL([nativeContent virtualURL]); 1824 item->SetVirtualURL([nativeContent virtualURL]);
1815 } 1825 }
1816 1826
1817 std::unique_ptr<web::NavigationContextImpl> navigationContext = 1827 std::unique_ptr<web::NavigationContextImpl> navigationContext =
1818 [self registerLoadRequestForURL:targetURL 1828 [self registerLoadRequestForURL:targetURL
1819 referrer:referrer 1829 referrer:referrer
1820 transition:self.currentTransition]; 1830 transition:self.currentTransition];
1821 [self loadNativeViewWithSuccess:YES]; 1831 [self loadNativeViewWithSuccess:YES
1832 navigationContext:navigationContext.get()];
1822 } 1833 }
1823 1834
1824 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params { 1835 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params {
1825 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK)); 1836 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK));
1826 1837
1827 // Clear transient view before making any changes to history and navigation 1838 // Clear transient view before making any changes to history and navigation
1828 // manager. TODO(stuartmorgan): Drive Transient Item clearing from 1839 // manager. TODO(stuartmorgan): Drive Transient Item clearing from
1829 // navigation system, rather than from WebController. 1840 // navigation system, rather than from WebController.
1830 [self clearTransientContentView]; 1841 [self clearTransientContentView];
1831 1842
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3055 // Reset SSL status to default, unless the load was cancelled (manually or by 3066 // Reset SSL status to default, unless the load was cancelled (manually or by
3056 // back-forward navigation). 3067 // back-forward navigation).
3057 web::NavigationManager* navManager = self.webState->GetNavigationManager(); 3068 web::NavigationManager* navManager = self.webState->GetNavigationManager();
3058 if (navManager->GetLastCommittedItem() && [error code] != NSURLErrorCancelled) 3069 if (navManager->GetLastCommittedItem() && [error code] != NSURLErrorCancelled)
3059 navManager->GetLastCommittedItem()->GetSSL() = web::SSLStatus(); 3070 navManager->GetLastCommittedItem()->GetSSL() = web::SSLStatus();
3060 3071
3061 NSURL* errorURL = [NSURL 3072 NSURL* errorURL = [NSURL
3062 URLWithString:[userInfo objectForKey:NSURLErrorFailingURLStringErrorKey]]; 3073 URLWithString:[userInfo objectForKey:NSURLErrorFailingURLStringErrorKey]];
3063 const GURL errorGURL = net::GURLWithNSURL(errorURL); 3074 const GURL errorGURL = net::GURLWithNSURL(errorURL);
3064 3075
3076 web::NavigationContextImpl* navigationContext =
3077 [_navigationStates contextForNavigation:navigation];
3078 navigationContext->SetIsErrorPage(true);
3079
3065 // Handles Frame Load Interrupted errors from WebView. 3080 // Handles Frame Load Interrupted errors from WebView.
3066 if ([error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] && 3081 if ([error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] &&
3067 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) { 3082 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) {
3068 // See if the delegate wants to handle this case. 3083 // See if the delegate wants to handle this case.
3069 if (errorGURL.is_valid() && 3084 if (errorGURL.is_valid() &&
3070 [_delegate 3085 [_delegate
3071 respondsToSelector:@selector( 3086 respondsToSelector:@selector(
3072 controllerForUnhandledContentAtURL:)]) { 3087 controllerForUnhandledContentAtURL:)]) {
3073 id<CRWNativeContent> controller = 3088 id<CRWNativeContent> controller =
3074 [_delegate controllerForUnhandledContentAtURL:errorGURL]; 3089 [_delegate controllerForUnhandledContentAtURL:errorGURL];
3075 if (controller) { 3090 if (controller) {
3076 [self loadCompleteWithSuccess:NO forNavigation:navigation]; 3091 [self loadCompleteWithSuccess:NO forNavigation:navigation];
3077 [self removeWebViewAllowingCachedReconstruction:NO]; 3092 [self removeWebViewAllowingCachedReconstruction:NO];
3078 [self setNativeController:controller]; 3093 [self setNativeController:controller];
3079 [self loadNativeViewWithSuccess:YES]; 3094 [self loadNativeViewWithSuccess:YES
3095 navigationContext:navigationContext];
3080 return; 3096 return;
3081 } 3097 }
3082 } 3098 }
3083 3099
3084 // Ignore errors that originate from URLs that are opened in external apps. 3100 // Ignore errors that originate from URLs that are opened in external apps.
3085 if ([_openedApplicationURL containsObject:errorURL]) 3101 if ([_openedApplicationURL containsObject:errorURL])
3086 return; 3102 return;
3087 // Certain frame errors don't have URL information for some reason; for 3103 // Certain frame errors don't have URL information for some reason; for
3088 // those cases (so far the only known case is plugin content loaded directly 3104 // those cases (so far the only known case is plugin content loaded directly
3089 // in a frame) just ignore the error. See crbug.com/414295 3105 // in a frame) just ignore the error. See crbug.com/414295
3090 if (!errorURL) { 3106 if (!errorURL) {
3091 DCHECK(!inMainFrame); 3107 DCHECK(!inMainFrame);
3092 return; 3108 return;
3093 } 3109 }
3094 // The wrapper error uses the URL of the error and not the requested URL 3110 // The wrapper error uses the URL of the error and not the requested URL
3095 // (which can be different in case of a redirect) to match desktop Chrome 3111 // (which can be different in case of a redirect) to match desktop Chrome
3096 // behavior. 3112 // behavior.
3097 NSError* wrapperError = [NSError 3113 NSError* wrapperError = [NSError
3098 errorWithDomain:[error domain] 3114 errorWithDomain:[error domain]
3099 code:[error code] 3115 code:[error code]
3100 userInfo:@{ 3116 userInfo:@{
3101 NSURLErrorFailingURLStringErrorKey : [errorURL absoluteString], 3117 NSURLErrorFailingURLStringErrorKey : [errorURL absoluteString],
3102 NSUnderlyingErrorKey : error 3118 NSUnderlyingErrorKey : error
3103 }]; 3119 }];
3104 [self loadCompleteWithSuccess:NO forNavigation:navigation]; 3120 [self loadCompleteWithSuccess:NO forNavigation:navigation];
3105 [self loadErrorInNativeView:wrapperError]; 3121 [self loadErrorInNativeView:wrapperError
3122 navigationContext:navigationContext];
3106 return; 3123 return;
3107 } 3124 }
3108 3125
3109 if ([error code] == NSURLErrorCancelled) { 3126 if ([error code] == NSURLErrorCancelled) {
3110 [self handleCancelledError:error]; 3127 [self handleCancelledError:error];
3111 // NSURLErrorCancelled errors that aren't handled by aborting the load will 3128 // NSURLErrorCancelled errors that aren't handled by aborting the load will
3112 // automatically be retried by the web view, so early return in this case. 3129 // automatically be retried by the web view, so early return in this case.
3113 return; 3130 return;
3114 } 3131 }
3115 3132
3116 [self loadCompleteWithSuccess:NO forNavigation:navigation]; 3133 [self loadCompleteWithSuccess:NO forNavigation:navigation];
3117 [self loadErrorInNativeView:error]; 3134 [self loadErrorInNativeView:error navigationContext:navigationContext];
3118 } 3135 }
3119 3136
3120 - (void)handleCancelledError:(NSError*)error { 3137 - (void)handleCancelledError:(NSError*)error {
3121 if ([self shouldCancelLoadForCancelledError:error]) { 3138 if ([self shouldCancelLoadForCancelledError:error]) {
3122 [self loadCancelled]; 3139 [self loadCancelled];
3123 [[self sessionController] discardNonCommittedItems]; 3140 [[self sessionController] discardNonCommittedItems];
3124 } 3141 }
3125 } 3142 }
3126 3143
3127 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error { 3144 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error {
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
4093 4110
4094 // Web View should not be created for App Specific URLs. 4111 // Web View should not be created for App Specific URLs.
4095 if (!web::GetWebClient()->IsAppSpecificURL(URL)) { 4112 if (!web::GetWebClient()->IsAppSpecificURL(URL)) {
4096 [self ensureWebViewCreated]; 4113 [self ensureWebViewCreated];
4097 DCHECK(_webView) << "_webView null while trying to load HTML"; 4114 DCHECK(_webView) << "_webView null while trying to load HTML";
4098 } 4115 }
4099 WKNavigation* navigation = 4116 WKNavigation* navigation =
4100 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)]; 4117 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)];
4101 [_navigationStates setState:web::WKNavigationState::REQUESTED 4118 [_navigationStates setState:web::WKNavigationState::REQUESTED
4102 forNavigation:navigation]; 4119 forNavigation:navigation];
4120 std::unique_ptr<web::NavigationContextImpl> context =
4121 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl, URL);
4122 [_navigationStates setContext:std::move(context) forNavigation:navigation];
4103 } 4123 }
4104 4124
4105 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { 4125 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL {
4106 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); 4126 CHECK(web::GetWebClient()->IsAppSpecificURL(URL));
4107 [self loadHTML:HTML forURL:URL]; 4127 [self loadHTML:HTML forURL:URL];
4108 } 4128 }
4109 4129
4110 - (void)loadHTMLForCurrentURL:(NSString*)HTML { 4130 - (void)loadHTMLForCurrentURL:(NSString*)HTML {
4111 [self loadHTML:HTML forURL:self.currentURL]; 4131 [self loadHTML:HTML forURL:self.currentURL];
4112 } 4132 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
4375 // dangerous. 4395 // dangerous.
4376 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) { 4396 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) {
4377 [self abortLoad]; 4397 [self abortLoad];
4378 NavigationManager::WebLoadParams params(webViewURL); 4398 NavigationManager::WebLoadParams params(webViewURL);
4379 [self loadWithParams:params]; 4399 [self loadWithParams:params];
4380 } 4400 }
4381 return; 4401 return;
4382 } else { 4402 } else {
4383 std::unique_ptr<web::NavigationContextImpl> navigationContext = 4403 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4384 [self registerLoadRequestForURL:webViewURL]; 4404 [self registerLoadRequestForURL:webViewURL];
4405 [_navigationStates setContext:std::move(navigationContext)
4406 forNavigation:navigation];
4385 } 4407 }
4386 } 4408 }
4387 4409
4388 // Ensure the URL is registered and loadPhase is as expected. 4410 // Ensure the URL is registered and loadPhase is as expected.
4389 DCHECK(_lastRegisteredRequestURL == webViewURL); 4411 DCHECK(_lastRegisteredRequestURL == webViewURL);
4390 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 4412 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
4391 } 4413 }
4392 4414
4393 - (void)webView:(WKWebView*)webView 4415 - (void)webView:(WKWebView*)webView
4394 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 4416 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 // TODO(crbug.com/712269): 4541 // TODO(crbug.com/712269):
4520 for (int i = 0; i < self.navigationManagerImpl->GetItemCount(); i++) { 4542 for (int i = 0; i < self.navigationManagerImpl->GetItemCount(); i++) {
4521 web::NavigationItem* item = self.navigationManagerImpl->GetItemAtIndex(i); 4543 web::NavigationItem* item = self.navigationManagerImpl->GetItemAtIndex(i);
4522 if (item->GetURL() == _documentURL) { 4544 if (item->GetURL() == _documentURL) {
4523 // Do not discard pending entry, because another pending navigation is 4545 // Do not discard pending entry, because another pending navigation is
4524 // still in progress and will commit or fail soon. 4546 // still in progress and will commit or fail soon.
4525 [self.sessionController goToItemAtIndex:i discardNonCommittedItems:NO]; 4547 [self.sessionController goToItemAtIndex:i discardNonCommittedItems:NO];
4526 } 4548 }
4527 } 4549 }
4528 } 4550 }
4529 self.webStateImpl->OnNavigationCommitted(_documentURL); 4551
4552 web::NavigationContextImpl* context =
4553 [_navigationStates contextForNavigation:navigation];
4554 context->SetResponseHeaders(_webStateImpl->GetHttpResponseHeaders());
4555 self.webStateImpl->OnNavigationFinished(context);
4530 4556
4531 [self updateSSLStatusForCurrentNavigationItem]; 4557 [self updateSSLStatusForCurrentNavigationItem];
4532 4558
4533 // Attempt to update the HTML5 history state. 4559 // Attempt to update the HTML5 history state.
4534 [self updateHTML5HistoryState]; 4560 [self updateHTML5HistoryState];
4535 4561
4536 // This is the point where pending entry has been committed, and navigation 4562 // This is the point where pending entry has been committed, and navigation
4537 // item title should be updated. 4563 // item title should be updated.
4538 [self setNavigationItemTitle:[_webView title]]; 4564 [self setNavigationItemTitle:[_webView title]];
4539 4565
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
4711 } 4737 }
4712 4738
4713 if (!navigationWasCommitted && ![_pendingNavigationInfo cancelled]) { 4739 if (!navigationWasCommitted && ![_pendingNavigationInfo cancelled]) {
4714 // A fast back/forward within the same origin does not call 4740 // A fast back/forward within the same origin does not call
4715 // |didCommitNavigation:|, so signal page change explicitly. 4741 // |didCommitNavigation:|, so signal page change explicitly.
4716 DCHECK_EQ(_documentURL.GetOrigin(), webViewURL.GetOrigin()); 4742 DCHECK_EQ(_documentURL.GetOrigin(), webViewURL.GetOrigin());
4717 BOOL isSameDocumentNavigation = 4743 BOOL isSameDocumentNavigation =
4718 [self isKVOChangePotentialSameDocumentNavigationToURL:webViewURL]; 4744 [self isKVOChangePotentialSameDocumentNavigationToURL:webViewURL];
4719 [self setDocumentURL:webViewURL]; 4745 [self setDocumentURL:webViewURL];
4720 [self webPageChanged]; 4746 [self webPageChanged];
4721 if (isSameDocumentNavigation) { 4747
4722 _webStateImpl->OnSameDocumentNavigation(webViewURL); 4748 // Same document navigation does not contain response headers.
4723 } else { 4749 std::unique_ptr<web::NavigationContextImpl> context =
4724 _webStateImpl->OnNavigationCommitted(webViewURL); 4750 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl,
4725 } 4751 webViewURL);
4752 net::HttpResponseHeaders* headers =
4753 isSameDocumentNavigation ? nullptr
4754 : _webStateImpl->GetHttpResponseHeaders();
4755 context->SetResponseHeaders(headers);
4756 context->SetIsSameDocument(isSameDocumentNavigation);
4757 _webStateImpl->OnNavigationFinished(context.get());
4726 } 4758 }
4727 4759
4728 [self updateSSLStatusForCurrentNavigationItem]; 4760 [self updateSSLStatusForCurrentNavigationItem];
4729 4761
4730 // Fast back forward navigation may not call |didFinishNavigation:|, so 4762 // Fast back forward navigation may not call |didFinishNavigation:|, so
4731 // signal did finish navigation explicitly. 4763 // signal did finish navigation explicitly.
4732 if (_lastRegisteredRequestURL == _documentURL) { 4764 if (_lastRegisteredRequestURL == _documentURL) {
4733 [self didFinishNavigation:nil]; 4765 [self didFinishNavigation:nil];
4734 } 4766 }
4735 } 4767 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 // the next runloop. 4896 // the next runloop.
4865 // 4897 //
4866 // Otherwise, simulate the whole delegate flow for a load (since the 4898 // Otherwise, simulate the whole delegate flow for a load (since the
4867 // superclass currently doesn't have a clean separation between URL changes 4899 // superclass currently doesn't have a clean separation between URL changes
4868 // and document changes). Note that the order of these calls is important: 4900 // and document changes). Note that the order of these calls is important:
4869 // registering a load request logically comes before updating the document 4901 // registering a load request logically comes before updating the document
4870 // URL, but also must come first since it uses state that is reset on URL 4902 // URL, but also must come first since it uses state that is reset on URL
4871 // changes. 4903 // changes.
4872 std::unique_ptr<web::NavigationContextImpl> navigationContext; 4904 std::unique_ptr<web::NavigationContextImpl> navigationContext;
4873 if (!_changingHistoryState) { 4905 if (!_changingHistoryState) {
4874 // If this wasn't a previously-expected load (e.g., certain back/forward 4906 if ([self isLoadRequestPendingForURL:newURL]) {
4875 // navigations), register the load request. 4907 // |loadWithParams:| was called with URL that has different fragment
4876 if (![self isLoadRequestPendingForURL:newURL]) { 4908 // comparing to the orevious URL.
4909 // TODO(crbug.com/713836): Instead of creating a new context, find
4910 // existing navigation context stored in |_navigationStates| and use it.
4911 navigationContext = web::NavigationContextImpl::CreateNavigationContext(
4912 _webStateImpl, newURL);
4913 } else {
4914 // This could be:
4915 // 1.) Renderer-initiated fragment change
4916 // 2.) Assigning same-origin URL to window.location
4917 // 3.) Incorrectly handled window.location.replace (crbug.com/307072)
4918 // 4.) Back-forward same document navigation
4877 navigationContext = [self registerLoadRequestForURL:newURL]; 4919 navigationContext = [self registerLoadRequestForURL:newURL];
4878 4920
4879 // Use the current title for items created by same document navigations. 4921 // Use the current title for items created by same document navigations.
4880 auto* pendingItem = self.navigationManagerImpl->GetPendingItem(); 4922 auto* pendingItem = self.navigationManagerImpl->GetPendingItem();
4881 if (pendingItem) 4923 if (pendingItem)
4882 pendingItem->SetTitle(_webStateImpl->GetTitle()); 4924 pendingItem->SetTitle(_webStateImpl->GetTitle());
4883 } 4925 }
4926 navigationContext->SetIsSameDocument(true);
4884 } 4927 }
4885 4928
4886 [self setDocumentURL:newURL]; 4929 [self setDocumentURL:newURL];
4887 4930
4888 if (!_changingHistoryState) { 4931 if (!_changingHistoryState) {
4889 [self didStartLoadingURL:_documentURL]; 4932 [self didStartLoadingURL:_documentURL];
4890 _webStateImpl->OnSameDocumentNavigation(newURL); 4933 _webStateImpl->OnNavigationFinished(navigationContext.get());
4891 [self updateSSLStatusForCurrentNavigationItem]; 4934 [self updateSSLStatusForCurrentNavigationItem];
4892 [self didFinishNavigation:nil]; 4935 [self didFinishNavigation:nil];
4893 } 4936 }
4894 } 4937 }
4895 4938
4896 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { 4939 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL {
4897 if (self.loadPhase != web::LOAD_REQUESTED) 4940 if (self.loadPhase != web::LOAD_REQUESTED)
4898 return NO; 4941 return NO;
4899 4942
4900 web::NavigationItem* pendingItem = 4943 web::NavigationItem* pendingItem =
(...skipping 26 matching lines...) Expand all
4927 if (POSTData.length && !repostedForm) { 4970 if (POSTData.length && !repostedForm) {
4928 [request setHTTPMethod:@"POST"]; 4971 [request setHTTPMethod:@"POST"];
4929 [request setHTTPBody:POSTData]; 4972 [request setHTTPBody:POSTData];
4930 [request setAllHTTPHeaderFields:self.currentHTTPHeaders]; 4973 [request setAllHTTPHeaderFields:self.currentHTTPHeaders];
4931 GURL navigationURL = 4974 GURL navigationURL =
4932 currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); 4975 currentItem ? currentItem->GetURL() : GURL::EmptyGURL();
4933 std::unique_ptr<web::NavigationContextImpl> navigationContext = 4976 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4934 [self registerLoadRequestForURL:navigationURL 4977 [self registerLoadRequestForURL:navigationURL
4935 referrer:self.currentNavItemReferrer 4978 referrer:self.currentNavItemReferrer
4936 transition:self.currentTransition]; 4979 transition:self.currentTransition];
4937 [self loadPOSTRequest:request]; 4980 WKNavigation* navigation = [self loadPOSTRequest:request];
4981 [_navigationStates setContext:std::move(navigationContext)
4982 forNavigation:navigation];
4938 return; 4983 return;
4939 } 4984 }
4940 4985
4941 ProceduralBlock defaultNavigationBlock = ^{ 4986 ProceduralBlock defaultNavigationBlock = ^{
4942 web::NavigationItem* item = self.currentNavItem; 4987 web::NavigationItem* item = self.currentNavItem;
4943 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 4988 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
4944 std::unique_ptr<web::NavigationContextImpl> navigationContext = 4989 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4945 [self registerLoadRequestForURL:navigationURL 4990 [self registerLoadRequestForURL:navigationURL
4946 referrer:self.currentNavItemReferrer 4991 referrer:self.currentNavItemReferrer
4947 transition:self.currentTransition]; 4992 transition:self.currentTransition];
4948 [self loadRequest:request]; 4993 WKNavigation* navigation = [self loadRequest:request];
4994 [_navigationStates setContext:std::move(navigationContext)
4995 forNavigation:navigation];
4949 [self reportBackForwardNavigationTypeForFastNavigation:NO]; 4996 [self reportBackForwardNavigationTypeForFastNavigation:NO];
4950 }; 4997 };
4951 4998
4952 // When navigating via WKBackForwardListItem to pages created or updated by 4999 // When navigating via WKBackForwardListItem to pages created or updated by
4953 // calls to pushState() and replaceState(), sometimes web_bundle.js is not 5000 // calls to pushState() and replaceState(), sometimes web_bundle.js is not
4954 // injected correctly. This means that calling window.history navigation 5001 // injected correctly. This means that calling window.history navigation
4955 // functions will invoke WKWebView's non-overridden implementations, causing a 5002 // functions will invoke WKWebView's non-overridden implementations, causing a
4956 // mismatch between the WKBackForwardList and NavigationManager. 5003 // mismatch between the WKBackForwardList and NavigationManager.
4957 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection 5004 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection
4958 // flake. 5005 // flake.
(...skipping 30 matching lines...) Expand all
4989 } else { 5036 } else {
4990 // |didCommitNavigation:| may not be called for fast navigation, so update 5037 // |didCommitNavigation:| may not be called for fast navigation, so update
4991 // the navigation type now as it is already known. 5038 // the navigation type now as it is already known.
4992 holder->set_navigation_type(WKNavigationTypeBackForward); 5039 holder->set_navigation_type(WKNavigationTypeBackForward);
4993 navigation = 5040 navigation =
4994 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 5041 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
4995 [self reportBackForwardNavigationTypeForFastNavigation:YES]; 5042 [self reportBackForwardNavigationTypeForFastNavigation:YES];
4996 } 5043 }
4997 [_navigationStates setState:web::WKNavigationState::REQUESTED 5044 [_navigationStates setState:web::WKNavigationState::REQUESTED
4998 forNavigation:navigation]; 5045 forNavigation:navigation];
5046 [_navigationStates setContext:std::move(navigationContext)
5047 forNavigation:navigation];
4999 }; 5048 };
5000 5049
5001 // If the request is not a form submission or resubmission, or the user 5050 // If the request is not a form submission or resubmission, or the user
5002 // doesn't need to confirm the load, then continue right away. 5051 // doesn't need to confirm the load, then continue right away.
5003 5052
5004 if (!repostedForm || currentItem->ShouldSkipRepostFormConfirmation()) { 5053 if (!repostedForm || currentItem->ShouldSkipRepostFormConfirmation()) {
5005 webViewNavigationBlock(); 5054 webViewNavigationBlock();
5006 return; 5055 return;
5007 } 5056 }
5008 5057
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
5095 - (NSUInteger)observerCount { 5144 - (NSUInteger)observerCount {
5096 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5145 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5097 return [_observers count]; 5146 return [_observers count];
5098 } 5147 }
5099 5148
5100 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5149 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5101 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5150 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5102 } 5151 }
5103 5152
5104 @end 5153 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | ios/web/web_state/ui/crw_wk_navigation_states_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698