Changeset 269983 in webkit
- Timestamp:
- Nov 18, 2020 1:57:01 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r269977 r269983 1 2020-11-18 Chris Dumez <cdumez@apple.com> 2 3 [iOS] beforeunload event does not fire in MobileSafari 4 https://bugs.webkit.org/show_bug.cgi?id=219102 5 <rdar://problem/70550655> 6 7 Reviewed by Geoff Garen. 8 9 MobileSafari on iOS does not implement WKUIDelegate's runJavaScriptAlertPanelWithMessage because 10 it never shows any before unload prompt. When the client does not implement this delegate, 11 Chrome::canRunBeforeUnloadConfirmPanel() returns false and this was causing 12 FrameLoader::shouldClose() to return early, before even firing the beforeunload event in each 13 frame. I updated our logic so that we now fire the beforeunload events no matter what and we 14 merely do not attempt to show the beforeunload prompt when Chrome::canRunBeforeUnloadConfirmPanel() 15 return false, similarly to what we do when the document does not have a user gesture. 16 17 Note that we already fire the pagehide and unload events on iOS so this is not a significant 18 change in policy. 19 20 * loader/FrameLoader.cpp: 21 (WebCore::FrameLoader::shouldClose): 22 (WebCore::FrameLoader::dispatchBeforeUnloadEvent): 23 1 24 2020-11-18 Aditya Keerthi <akeerthi@apple.com> 2 25 -
trunk/Source/WebCore/loader/FrameLoader.cpp
r269953 r269983 3235 3235 if (!page) 3236 3236 return true; 3237 if (!page->chrome().canRunBeforeUnloadConfirmPanel())3238 return true;3239 3237 3240 3238 // Store all references to each subframe in advance since beforeunload's event handler may modify frame … … 3366 3364 document->defaultEventHandler(beforeUnloadEvent.get()); 3367 3365 3368 if (! shouldAskForNavigationConfirmation(*document, beforeUnloadEvent))3366 if (!chrome.canRunBeforeUnloadConfirmPanel() || !shouldAskForNavigationConfirmation(*document, beforeUnloadEvent)) 3369 3367 return true; 3370 3368 -
trunk/Tools/ChangeLog
r269960 r269983 1 2020-11-18 Chris Dumez <cdumez@apple.com> 2 3 [iOS] beforeunload event does not fire in MobileSafari 4 https://bugs.webkit.org/show_bug.cgi?id=219102 5 <rdar://problem/70550655> 6 7 Reviewed by Geoff Garen. 8 9 Add API test coverage. 10 11 * TestWebKitAPI/Tests/WebKit/beforeunload.html: 12 * TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm: 13 (-[UIDelegateWithoutRunBeforeUnload webViewDidClose:]): 14 (-[BeforeUnloadMessageHandler userContentController:didReceiveScriptMessage:]): 15 (TEST): 16 1 17 2020-11-18 Chris Dumez <cdumez@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKit/beforeunload.html
r254711 r269983 4 4 <script> 5 5 onbeforeunload = (ev) => { 6 if (window.webkit && webkit.messageHandlers.testHandler) 7 webkit.messageHandlers.testHandler.postMessage("beforeunload called"); 6 8 ev.preventDefault(); 7 9 return "foo"; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ModalAlerts.mm
r260366 r269983 314 314 315 315 #endif 316 317 static bool wasBeforeUnloadEventHandlerCalled = false; 318 319 @interface UIDelegateWithoutRunBeforeUnload : NSObject <WKUIDelegate> 320 @end 321 322 @implementation UIDelegateWithoutRunBeforeUnload 323 324 - (void)webViewDidClose:(WKWebView *)webView 325 { 326 [webView _close]; 327 } 328 329 @end 330 331 @interface BeforeUnloadMessageHandler : NSObject <WKScriptMessageHandler> 332 @end 333 334 @implementation BeforeUnloadMessageHandler 335 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message 336 { 337 NSString *scriptMessage = [message body]; 338 EXPECT_WK_STREQ(@"beforeunload called", scriptMessage); 339 wasBeforeUnloadEventHandlerCalled = true; 340 } 341 @end 342 343 TEST(WebKit, BeforeUnloadEventWithoutRunBeforeUnloadConfirmPanelUIDelegate) 344 { 345 auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]); 346 auto messageHandler = adoptNS([[BeforeUnloadMessageHandler alloc] init]); 347 [[webViewConfiguration userContentController] addScriptMessageHandler:messageHandler.get() name:@"testHandler"]; 348 349 auto uiDelegate = adoptNS([[UIDelegateWithoutRunBeforeUnload alloc] init]); 350 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]); 351 [webView setUIDelegate:uiDelegate.get()]; 352 353 [webView synchronouslyLoadTestPageNamed:@"beforeunload"]; 354 355 TestWebKitAPI::Util::spinRunLoop(10); 356 357 [webView _tryClose]; 358 359 // The beforeunload event handler should get called even if the client application does not 360 // have a UIDelegate that can show the before unload prompt. 361 TestWebKitAPI::Util::run(&wasBeforeUnloadEventHandlerCalled); 362 363 // The view should get closed. 364 while (![webView _isClosed]) 365 TestWebKitAPI::Util::sleep(0.1); 366 }
Note: See TracChangeset
for help on using the changeset viewer.