Bug 251548 - [iOS] Crashes when WebValidationBubbleViewController is presented twice
Summary: [iOS] Crashes when WebValidationBubbleViewController is presented twice
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ali Juma
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-02-01 13:54 PST by Ali Juma
Modified: 2023-02-09 14:28 PST (History)
5 users (show)

See Also:


Attachments
Sample project (52.80 KB, application/zip)
2023-02-01 13:54 PST, Ali Juma
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Juma 2023-02-01 13:54:50 PST
Created attachment 464804 [details]
Sample project

Chrome for iOS is getting a significant number of crash reports from an exception that is triggered when WebValidationBubbleViewController is presented while already being presented ("[Exception] Application tried to present modally a view controller <WebValidationBubbleViewController: 0x#> that is already being presented by <TabGridViewController: 0x#>").

Debugging, it turns out that the logic in ValidationBubble::show to guard against presenting the view controller when it's already presented has a race condition. After the call to  [m_presentingViewController presentViewController:animated:completion:], m_popoverController doesn't immediately have a parentViewController or a presentingViewController, so there's a short period of time where a second call ValidationBubble::show won't early-out, but will instead try to present m_popoverController again, leading to the exception.

See https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/ios/ValidationBubbleIOS.mm#L190

In practice ValidationBubble::show can get called multiple times since WebPageProxy::setIsScrollingOrZooming will call m_validationBubble->show() when scrolling/zooming stops, so if this happens multiple times over the lifetime of the same m_validationBubble, we're in trouble. 

I've attached a sample project that reproduces this crash. Steps to reproduce:
1) After the page loads, tap once anywhere. This will cause a green box to slide down.
2) Tap again quickly (before the green box slides away) on the "Se connecter" button to trigger the WebValidationBubble.

A couple potential fixes:
1) In ValidationBubble, add an m_isPresentingBubble bool that is set to true when ValidationBubble::show calls presentViewController and cleared in the completion handler, and early-out in ValidationBubble::show when m_isPresentingBubble is true

2) In WebPageProxy, add an m_waitingToShowValidationBubble bool that is set to true when m_validationBubble, and cleared after calling m_validationBubble->show().
Comment 1 Radar WebKit Bug Importer 2023-02-08 13:55:20 PST
<rdar://problem/105191060>
Comment 2 Ali Juma 2023-02-09 11:48:26 PST
Pull request: https://github.com/WebKit/WebKit/pull/9880
Comment 3 EWS 2023-02-09 14:28:20 PST
Committed 260085@main (01bfc814e829): <https://commits.webkit.org/260085@main>

Reviewed commits have been landed. Closing PR #9880 and removing active labels.