Commit c1fa0052 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

Reland "[Nav Experiment] Fix form repost detection in WKBasedNavigationManager."

This is a reland of 091e44cb.

It fixes the regression in
WebUITestCase/testChromeURLBackAndForwardAndReloadNavigation. WebUI
needs special handling in reload because calling [WKWebView -reload]
simply reloads WKWebView.URL (which is an app-specific URL in this case)
and results in a provisional load failure.

The other suspected test failure
(ContextMenuJsTest.LinkOfTextWithCalloutNone) is not caused by the
original CL. It seems to be flaky. It failed again after the revert:
https://luci-milo.appspot.com/buildbot/internal.bling.main/iphone11-device-x64/2532
and it failed before the original CL was checked in:
https://luci-milo.appspot.com/buildbot/internal.bling.main/iphone11-device-x64/2504

Original change's description:
> [Nav Experiment] Fix form repost detection in WKBasedNavigationManager.
>
> This CL moves form repost detection for WKBasedNavigationManager to
> in |webView:decidePolicyForNavigationAction|, where WKWebView gives a
> clear signal about form reposting (WKNavigationTypeFormResubmitted).
> This allows simplifying reload for WKBasedNavigationManager to directly
> delegating to [WKWebView reload].
>
> FormsTestCase now pass with WKBasedNavigationManager.
>
> Bug: 807428,705020
> Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
> Change-Id: Ia35978c42b21405a3749d1764a0485cde9c805d2
> Reviewed-on: https://chromium-review.googlesource.com/894892
> Commit-Queue: Danyao Wang <danyao@chromium.org>
> Reviewed-by: Eugene But <eugenebut@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#533692}t

Bug: 807428
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If0bb1c907472ec402931c69f347c9259907c4f28
Reviewed-on: https://chromium-review.googlesource.com/899916Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Danyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534163}
parent edabf451
...@@ -1943,7 +1943,16 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -1943,7 +1943,16 @@ registerLoadRequestForURL:(const GURL&)requestURL
} else { } else {
self.currentNavItem->SetTransitionType( self.currentNavItem->SetTransitionType(
ui::PageTransition::PAGE_TRANSITION_RELOAD); ui::PageTransition::PAGE_TRANSITION_RELOAD);
[self loadCurrentURL]; if (web::GetWebClient()->IsSlimNavigationManagerEnabled() &&
!web::GetWebClient()->IsAppSpecificURL(
net::GURLWithNSURL(_webView.URL))) {
// New navigation manager can delegate directly to WKWebView to reload
// for non-app-specific URLs. The necessary navigation states will be
// updated in WKNavigationDelegate callbacks.
[_webView reload];
} else {
[self loadCurrentURL];
}
} }
} }
} }
...@@ -4191,11 +4200,32 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4191,11 +4200,32 @@ registerLoadRequestForURL:(const GURL&)requestURL
// retrieved state will be pending until |didCommitNavigation| callback. // retrieved state will be pending until |didCommitNavigation| callback.
[self updatePendingNavigationInfoFromNavigationAction:action]; [self updatePendingNavigationInfoFromNavigationAction:action];
// If this is a placeholder navigation, pass through. if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
if (web::GetWebClient()->IsSlimNavigationManagerEnabled() && // If this is a placeholder navigation, pass through.
IsPlaceholderUrl(requestURL)) { if (IsPlaceholderUrl(requestURL)) {
decisionHandler(WKNavigationActionPolicyAllow); decisionHandler(WKNavigationActionPolicyAllow);
return; return;
}
// WKBasedNavigationManager doesn't use |loadCurrentURL| for reload or back/
// forward navigation. So this is the first point where a form repost would
// be detected. Display the confirmation dialog.
if ([action.request.HTTPMethod isEqual:@"POST"] &&
(action.navigationType == WKNavigationTypeFormResubmitted ||
action.navigationType == WKNavigationTypeBackForward)) {
_webStateImpl->ShowRepostFormWarningDialog(
base::BindBlockArc(^(bool shouldContinue) {
if (shouldContinue) {
decisionHandler(WKNavigationActionPolicyAllow);
} else {
decisionHandler(WKNavigationActionPolicyCancel);
if (action.targetFrame.mainFrame) {
[_pendingNavigationInfo setCancelled:YES];
}
}
}));
return;
}
} }
// Invalid URLs should not be loaded. // Invalid URLs should not be loaded.
...@@ -5303,6 +5333,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5303,6 +5333,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
// If the request is form submission or resubmission, then prompt the // If the request is form submission or resubmission, then prompt the
// user before proceeding. // user before proceeding.
DCHECK(repostedForm); DCHECK(repostedForm);
DCHECK(!web::GetWebClient()->IsSlimNavigationManagerEnabled());
_webStateImpl->ShowRepostFormWarningDialog( _webStateImpl->ShowRepostFormWarningDialog(
base::BindBlockArc(^(bool shouldContinue) { base::BindBlockArc(^(bool shouldContinue) {
if (shouldContinue) if (shouldContinue)
......
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