From 2d0d1fc8884e34c58f00739e52340e6e4c985b15 Mon Sep 17 00:00:00 2001 From: Ali Juma Date: Mon, 17 Oct 2022 14:45:16 +0000 Subject: [PATCH] [iOS] Close JS dialogs when a new navigation starts This CL closes any JS dialogs left behind by the previous page when a new navigation starts, since these are no longer relevant to the user. Bug: 1373025 Change-Id: I8bec157bf2cd83a9a15f9b83ecad2e89820e7b6a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3954143 Commit-Queue: Ali Juma Reviewed-by: Gauthier Ambard Cr-Commit-Position: refs/heads/main@{#1059942} --- ios/web/web_state/web_state_impl_realized_web_state.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ios/web/web_state/web_state_impl_realized_web_state.mm b/ios/web/web_state/web_state_impl_realized_web_state.mm index c36294acc9c8be..f61afec66a03ad 100644 --- a/ios/web/web_state/web_state_impl_realized_web_state.mm +++ b/ios/web/web_state/web_state_impl_realized_web_state.mm @@ -191,6 +191,10 @@ void WebStateImpl::RealizedWebState::OnNavigationStarted( NavigationContextImpl* context) { + // When a navigation starts, immediately close any visible dialogs to avoid + // confusion about the origin of a dialog. + ClearDialogs(); + // Navigation manager loads internal URLs to restore session history and // create back-forward entries for WebUI. Do not trigger external callbacks. if ([CRWErrorPageHelper isErrorPageFileURL:context->GetUrl()] ||