Bug 251548

Summary: [iOS] Crashes when WebValidationBubbleViewController is presented twice
Product: WebKit Reporter: Ali Juma <ajuma>
Component: WebKit2Assignee: Ali Juma <ajuma>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, gambard, kkinnunen, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Sample project none

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.