Commit fec2080c authored by Yi Su's avatar Yi Su Committed by Commit Bot

Move webView:didReceiveServerRedirectForProvisionalNavigation into CRWWKNavigationHandler.

This CL moves
WKNavigationDelegate.didReceiveServerRedirectForProvisionalNavigation
from CRWWebController into CRWWKNavigationHandler.
CRWWebController.didReceiveRedirectForNavigation:context is also moved
into CRWWKNavigationHandler and temporarily exposed as a public method.
It will be removed when WKNavigationDelegate.didCommitNavigation is
moved into CRWWKNavigationHandler.

Bug: 956511
Change-Id: I27e8d994544a1e54bdf46a39e3114b1195064296
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617827Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661346}
parent 0463c2b1
......@@ -133,6 +133,12 @@ class UserInteractionState;
- (web::NavigationContextImpl*)contextForPendingMainFrameNavigationWithURL:
(const GURL&)URL;
// Notifies that server redirect has been received.
// TODO(crbug.com/956511): Remove this once "webView:didCommitNavigation" is
// moved into CRWWKNavigationHandler.
- (void)didReceiveRedirectForNavigation:(web::NavigationContextImpl*)context
withURL:(const GURL&)URL;
@end
#endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_
......@@ -577,6 +577,19 @@ using web::wk_navigation_util::IsWKInternalUrl;
- (void)webView:(WKWebView*)webView
didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
[self didReceiveWKNavigationDelegateCallback];
GURL webViewURL = net::GURLWithNSURL(webView.URL);
// This callback should never be triggered for placeholder navigations.
DCHECK(!(web::GetWebClient()->IsSlimNavigationManagerEnabled() &&
IsPlaceholderUrl(webViewURL)));
[self.navigationStates setState:web::WKNavigationState::REDIRECTED
forNavigation:navigation];
web::NavigationContextImpl* context =
[self.navigationStates contextForNavigation:navigation];
[self didReceiveRedirectForNavigation:context withURL:webViewURL];
}
- (void)webView:(WKWebView*)webView
......@@ -871,6 +884,29 @@ using web::wk_navigation_util::IsWKInternalUrl;
MIMEType, transition);
}
// Updates URL for navigation context and navigation item.
- (void)didReceiveRedirectForNavigation:(web::NavigationContextImpl*)context
withURL:(const GURL&)URL {
context->SetUrl(URL);
web::NavigationItemImpl* item =
web::GetItemWithUniqueID(self.navigationManagerImpl, context);
// Associated item can be a pending item, previously discarded by another
// navigation. WKWebView allows multiple provisional navigations, while
// Navigation Manager has only one pending navigation.
if (item) {
if (!IsWKInternalUrl(URL)) {
item->SetVirtualURL(URL);
item->SetURL(URL);
}
// Redirects (3xx response code), must change POST requests to GETs.
item->SetPostData(nil);
item->ResetHttpRequestHeaders();
}
self.userInteractionState->ResetLastTransferTime();
}
#pragma mark - Public methods
- (void)stopLoading {
......
......@@ -3888,20 +3888,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
[self.navigationHandler webView:webView
didReceiveServerRedirectForProvisionalNavigation:navigation];
GURL webViewURL = net::GURLWithNSURL(webView.URL);
// This callback should never be triggered for placeholder navigations.
DCHECK(!(web::GetWebClient()->IsSlimNavigationManagerEnabled() &&
IsPlaceholderUrl(webViewURL)));
[self.navigationHandler.navigationStates
setState:web::WKNavigationState::REDIRECTED
forNavigation:navigation];
web::NavigationContextImpl* context =
[self.navigationHandler.navigationStates contextForNavigation:navigation];
[self didReceiveRedirectForNavigation:context withURL:webViewURL];
}
- (void)webView:(WKWebView*)webView
......@@ -4051,7 +4037,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
// rdar://37547029 was fixed on iOS 12.
} else if (context && !context->IsPlaceholderNavigation() &&
context->GetUrl() != webViewURL) {
[self didReceiveRedirectForNavigation:context withURL:webViewURL];
[self.navigationHandler didReceiveRedirectForNavigation:context
withURL:webViewURL];
}
}
......@@ -4705,29 +4692,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
self.navigationHandler.pendingNavigationInfo.MIMEType);
}
// Updates URL for navigation context and navigation item.
- (void)didReceiveRedirectForNavigation:(web::NavigationContextImpl*)context
withURL:(const GURL&)URL {
context->SetUrl(URL);
web::NavigationItemImpl* item =
web::GetItemWithUniqueID(self.navigationManagerImpl, context);
// Associated item can be a pending item, previously discarded by another
// navigation. WKWebView allows multiple provisional navigations, while
// Navigation Manager has only one pending navigation.
if (item) {
if (!IsWKInternalUrl(URL)) {
item->SetVirtualURL(URL);
item->SetURL(URL);
}
// Redirects (3xx response code), must change POST requests to GETs.
item->SetPostData(nil);
item->ResetHttpRequestHeaders();
}
_userInteractionState.ResetLastTransferTime();
}
// Returns YES if the current live view is a web view with an image MIME type.
- (BOOL)contentIsImage {
if (!self.webView)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment