Changeset 271493 in webkit
- Timestamp:
- Jan 14, 2021, 10:44:13 AM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 53 edited
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/cocoa/MainThreadCocoa.mm (modified) (4 diffs)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (modified) (3 diffs)
-
WebCore/platform/audio/cocoa/AudioSampleDataSource.mm (modified) (6 diffs)
-
WebCore/platform/audio/ios/MediaSessionHelperIOS.mm (modified) (3 diffs)
-
WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm (modified) (3 diffs)
-
WebCore/platform/cocoa/PowerSourceNotifier.mm (modified) (2 diffs)
-
WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (modified) (1 diff)
-
WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm (modified) (4 diffs)
-
WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm (modified) (4 diffs)
-
WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm (modified) (3 diffs)
-
WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm (modified) (2 diffs)
-
WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm (modified) (23 diffs)
-
WebCore/platform/ios/wak/WebCoreThread.mm (modified) (2 diffs)
-
WebCore/platform/mac/VideoFullscreenInterfaceMac.mm (modified) (1 diff)
-
WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm (modified) (2 diffs)
-
WebKit/Shared/Cocoa/DefaultWebBrowserChecks.mm (modified) (1 diff)
-
WebKit/UIProcess/API/C/mac/WKContextPrivateMac.mm (modified) (2 diffs)
-
WebKit/UIProcess/API/Cocoa/NSAttributedString.mm (modified) (1 diff)
-
WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm (modified) (2 diffs)
-
WebKit/UIProcess/API/Cocoa/WKWebView.mm (modified) (2 diffs)
-
WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (modified) (1 diff)
-
WebKit/UIProcess/API/ios/WKWebViewIOS.mm (modified) (4 diffs)
-
WebKit/UIProcess/Cocoa/AutomationClient.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/NavigationState.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/PreferenceObserver.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/WebInspectorPreferenceObserver.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (modified) (1 diff)
-
WebKit/UIProcess/Cocoa/WebViewImpl.mm (modified) (6 diffs)
-
WebKit/UIProcess/EndowmentStateTracker.mm (modified) (2 diffs)
-
WebKit/UIProcess/_WKTouchEventGenerator.mm (modified) (3 diffs)
-
WebKit/UIProcess/ios/ProcessAssertionIOS.mm (modified) (5 diffs)
-
WebKit/UIProcess/ios/WKContentViewInteraction.mm (modified) (1 diff)
-
WebKit/UIProcess/ios/WKPDFView.mm (modified) (1 diff)
-
WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm (modified) (2 diffs)
-
WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm (modified) (1 diff)
-
WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (modified) (8 diffs)
-
WebKitLegacy/ios/ChangeLog (modified) (1 diff)
-
WebKitLegacy/ios/Misc/WebGeolocationProviderIOS.mm (modified) (5 diffs)
-
WebKitLegacy/ios/WebCoreSupport/WebChromeClientIOS.mm (modified) (1 diff)
-
WebKitLegacy/ios/WebCoreSupport/WebInspectorClientIOS.mm (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/Plugins/npapi.mm (modified) (2 diffs)
-
WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebImmediateActionController.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebView.mm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r271482 r271493 1 2021-01-14 Geoffrey Garen <ggaren@apple.com> 2 3 Removed most uses of dispatch_async(dispatch_get_main_queue(), ...) 4 https://bugs.webkit.org/show_bug.cgi?id=220066 5 6 Reviewed by Antti Koivisto. 7 8 dispatch_async has two downsides: 9 10 (1) Its order is undefined (and in practice highly variable) relative to 11 other WebKit operations. This sometimes causes flakiness. 12 13 (2) It doesn't honor the RunLoop first paint optimization. 14 15 We can use RunLoop::dispatch() instead. 16 17 * wtf/cocoa/MainThreadCocoa.mm: 18 (WTF::dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded): 19 (WTF::callOnWebThreadOrDispatchAsyncOnMainThread): 20 1 21 2021-01-14 Per Arne Vollan <pvollan@apple.com> 2 22 -
trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm
r263981 r271493 35 35 #import <stdio.h> 36 36 #import <wtf/Assertions.h> 37 #import <wtf/BlockPtr.h> 37 38 #import <wtf/HashSet.h> 38 39 #import <wtf/RetainPtr.h> … … 74 75 #if USE(WEB_THREAD) 75 76 if (WebCoreWebThreadIsEnabled && WebCoreWebThreadIsEnabled()) { 76 dispatch_async(dispatch_get_main_queue(), ^{77 RunLoop::main().dispatch([block = makeBlockPtr(block)] { 77 78 WebCoreWebThreadLock(); 78 79 block(); … … 81 82 } 82 83 #endif 83 dispatch_async(dispatch_get_main_queue(), block); 84 RunLoop::main().dispatch([block = makeBlockPtr(block)] { 85 block(); 86 }); 84 87 } 85 88 … … 92 95 } 93 96 #endif 94 dispatch_async(dispatch_get_main_queue(), block); 97 RunLoop::main().dispatch([block = makeBlockPtr(block)] { 98 block(); 99 }); 95 100 } 96 101 -
trunk/Source/WebCore/ChangeLog
r271488 r271493 1 2021-01-14 Geoffrey Garen <ggaren@apple.com> 2 3 Removed most uses of dispatch_async(dispatch_get_main_queue(), ...) 4 https://bugs.webkit.org/show_bug.cgi?id=220066 5 6 Reviewed by Antti Koivisto. 7 8 dispatch_async has two downsides: 9 10 (1) Its order is undefined (and in practice highly variable) relative to 11 other WebKit operations. This sometimes causes flakiness. 12 13 (2) It doesn't honor the RunLoop first paint optimization. 14 15 We can use RunLoop::dispatch() instead. 16 17 * accessibility/mac/WebAccessibilityObjectWrapperMac.mm: 18 (-[WebAccessibilityObjectWrapper accessibilityPerformPressAction]): 19 (-[WebAccessibilityObjectWrapper accessibilityPerformIncrementAction]): 20 (-[WebAccessibilityObjectWrapper accessibilityPerformDecrementAction]): 21 * platform/audio/cocoa/AudioSampleDataSource.mm: 22 (WebCore::AudioSampleDataSource::setupConverter): 23 (WebCore::AudioSampleDataSource::pushSamplesInternal): 24 (WebCore::AudioSampleDataSource::pullSamplesInternal): 25 * platform/audio/ios/MediaSessionHelperIOS.mm: 26 (-[WebMediaSessionHelper initWithCallback:]): 27 (-[WebMediaSessionHelper dealloc]): 28 * platform/cocoa/ContentFilterUnblockHandlerCocoa.mm: 29 (WebCore::ContentFilterUnblockHandler::requestUnblockAsync const): 30 (WebCore::dispatchToMainThread): Deleted. 31 * platform/cocoa/PowerSourceNotifier.mm: 32 (WebCore::PowerSourceNotifier::PowerSourceNotifier): 33 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: 34 (WebCore::MediaPlayerPrivateAVFoundationObjC::setAVPlayerItem): 35 * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm: 36 (WebCore::PlatformCALayerCocoa::clone const): 37 (WebCore::PlatformCALayer::setBoundsOnMainThread): 38 (WebCore::PlatformCALayer::setPositionOnMainThread): 39 (WebCore::PlatformCALayer::setAnchorPointOnMainThread): 40 * platform/graphics/cocoa/WebCoreDecompressionSession.mm: 41 (WebCore::WebCoreDecompressionSession::maybeBecomeReadyForMoreMediaData): 42 (WebCore::WebCoreDecompressionSession::enqueueDecodedSample): 43 (WebCore::WebCoreDecompressionSession::requestMediaDataWhenReady): 44 (WebCore::WebCoreDecompressionSession::notifyWhenHasAvailableVideoFrame): 45 * platform/ios/VideoFullscreenInterfaceAVKit.mm: 46 (-[WebAVPlayerLayer layoutSublayers]): 47 (VideoFullscreenInterfaceAVKit::finalizeSetup): 48 (VideoFullscreenInterfaceAVKit::doExitFullscreen): 49 * platform/ios/WebSQLiteDatabaseTrackerClient.mm: 50 (WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction): 51 (WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction): 52 * platform/ios/WebVideoFullscreenControllerAVKit.mm: 53 (VideoFullscreenControllerContext::requestUpdateInlineRect): 54 (VideoFullscreenControllerContext::requestVideoContentLayer): 55 (VideoFullscreenControllerContext::returnVideoContentLayer): 56 (VideoFullscreenControllerContext::didSetupFullscreen): 57 (VideoFullscreenControllerContext::didExitFullscreen): 58 (VideoFullscreenControllerContext::fullscreenMayReturnToInline): 59 (VideoFullscreenControllerContext::durationChanged): 60 (VideoFullscreenControllerContext::currentTimeChanged): 61 (VideoFullscreenControllerContext::bufferedTimeChanged): 62 (VideoFullscreenControllerContext::rateChanged): 63 (VideoFullscreenControllerContext::hasVideoChanged): 64 (VideoFullscreenControllerContext::videoDimensionsChanged): 65 (VideoFullscreenControllerContext::seekableRangesChanged): 66 (VideoFullscreenControllerContext::canPlayFastReverseChanged): 67 (VideoFullscreenControllerContext::audioMediaSelectionOptionsChanged): 68 (VideoFullscreenControllerContext::legibleMediaSelectionOptionsChanged): 69 (VideoFullscreenControllerContext::wirelessVideoPlaybackDisabledChanged): 70 (VideoFullscreenControllerContext::mutedChanged): 71 (VideoFullscreenControllerContext::volumeChanged): 72 (VideoFullscreenControllerContext::setUpFullscreen): 73 (VideoFullscreenControllerContext::exitFullscreen): 74 * platform/ios/wak/WebCoreThread.mm: 75 (MainThreadAdoptAndRelease): 76 (WebThreadPostNotification): 77 * platform/mac/VideoFullscreenInterfaceMac.mm: 78 (WebCore::VideoFullscreenInterfaceMac::setupFullscreen): 79 * platform/mediastream/mac/AVCaptureDeviceManager.mm: 80 (-[WebCoreAVCaptureDeviceManagerObserver deviceConnectedDidChange:]): 81 1 82 2021-01-14 Youenn Fablet <youenn@apple.com> 2 83 -
trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
r271416 r271493 3181 3181 // In case anything we do by performing the press action causes an alert or other modal 3182 3182 // behaviors, we need to return now, so that VoiceOver doesn't hang indefinitely. 3183 dispatch_async(dispatch_get_main_queue(), ^{3183 RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] { 3184 3184 [self _accessibilityPerformPressAction]; 3185 3185 }); … … 3200 3200 - (void)accessibilityPerformIncrementAction 3201 3201 { 3202 dispatch_async(dispatch_get_main_queue(), ^{3202 RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] { 3203 3203 [self _accessibilityPerformIncrementAction]; 3204 3204 }); … … 3219 3219 - (void)accessibilityPerformDecrementAction 3220 3220 { 3221 dispatch_async(dispatch_get_main_queue(), ^{3221 RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] { 3222 3222 [self _accessibilityPerformDecrementAction]; 3223 3223 }); -
trunk/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm
r270663 r271493 37 37 #import <pal/avfoundation/MediaTimeAVFoundation.h> 38 38 #import <syslog.h> 39 #import <wtf/RunLoop.h> 39 40 #import <wtf/StringPrintStream.h> 40 41 … … 88 89 OSStatus err = AudioConverterNew(&m_inputDescription->streamDescription(), &m_outputDescription->streamDescription(), &m_converter); 89 90 if (err) { 90 dispatch_async(dispatch_get_main_queue(),[this, protectedThis = makeRefPtr(*this), err] {91 RunLoop::main().dispatch([this, protectedThis = makeRefPtr(*this), err] { 91 92 ERROR_LOG("AudioConverterNew returned error ", err); 92 93 }); … … 162 163 if (m_inputSampleOffset == MediaTime::invalidTime()) { 163 164 m_inputSampleOffset = MediaTime(1 - sampleTime.timeValue(), sampleTime.timeScale()); 164 dispatch_async(dispatch_get_main_queue(),[logIdentifier = LOGIDENTIFIER, inputSampleOffset = m_inputSampleOffset.timeValue(), maximumSampleCount = m_maximumSampleCount, this, protectedThis = makeRefPtr(*this)] {165 RunLoop::main().dispatch([logIdentifier = LOGIDENTIFIER, inputSampleOffset = m_inputSampleOffset.timeValue(), maximumSampleCount = m_maximumSampleCount, this, protectedThis = makeRefPtr(*this)] { 165 166 ALWAYS_LOG(logIdentifier, "input sample offset is ", inputSampleOffset, ", maximumSampleCount is ", maximumSampleCount); 166 167 }); … … 239 240 m_outputSampleOffset = (endFrame - sampleCount) - timeStamp; 240 241 m_outputSampleOffset -= computeOffsetDelay(m_outputDescription->sampleRate(), m_lastPushedSampleCount); 241 dispatch_async(dispatch_get_main_queue(),[logIdentifier = LOGIDENTIFIER, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] {242 RunLoop::main().dispatch([logIdentifier = LOGIDENTIFIER, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] { 242 243 ALWAYS_LOG(logIdentifier, "setting new offset to ", outputSampleOffset); 243 244 }); … … 247 248 248 249 if (timeStamp < startFrame || timeStamp + sampleCount > endFrame) { 249 dispatch_async(dispatch_get_main_queue(),[logIdentifier = LOGIDENTIFIER, timeStamp, startFrame, endFrame, sampleCount, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] {250 RunLoop::main().dispatch([logIdentifier = LOGIDENTIFIER, timeStamp, startFrame, endFrame, sampleCount, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] { 250 251 ERROR_LOG(logIdentifier, "not enough data, sample ", timeStamp, " with offset ", outputSampleOffset, ", trying to get ", sampleCount, " samples, but not completely in range [", startFrame, " .. ", endFrame, "]"); 251 252 }); … … 260 261 // We are too close from endFrame, let's wait for more data to be pushed. 261 262 m_outputSampleOffset -= sampleCount; 262 dispatch_async(dispatch_get_main_queue(),[logIdentifier = LOGIDENTIFIER, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] {263 RunLoop::main().dispatch([logIdentifier = LOGIDENTIFIER, outputSampleOffset = m_outputSampleOffset, this, protectedThis = makeRefPtr(*this)] { 263 264 ALWAYS_LOG(logIdentifier, "updating offset to ", outputSampleOffset); 264 265 }); -
trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm
r270681 r271493 40 40 #import <wtf/MainThread.h> 41 41 #import <wtf/RetainPtr.h> 42 #import <wtf/RunLoop.h> 42 43 #import <wtf/UniqueRef.h> 43 44 … … 363 364 364 365 // Now playing won't work unless we turn on the delivery of remote control events. 365 dispatch_async(dispatch_get_main_queue(), ^{366 RunLoop::main().dispatch([] { 366 367 BEGIN_BLOCK_OBJC_EXCEPTIONS 367 368 [[PAL::getUIApplicationClass() sharedApplication] beginReceivingRemoteControlEvents]; … … 378 379 #if !PLATFORM(WATCHOS) 379 380 if (!pthread_main_np()) { 380 dispatch_async(dispatch_get_main_queue(),[routeDetector = WTFMove(_routeDetector)] () mutable {381 RunLoop::main().dispatch([routeDetector = WTFMove(_routeDetector)] () mutable { 381 382 LOG(Media, "safelyTearDown - dipatched to UI thread."); 382 383 BEGIN_BLOCK_OBJC_EXCEPTIONS -
trunk/Source/WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm
r264006 r271493 138 138 } 139 139 140 static inline void dispatchToMainThread(void (^block)())141 {142 dispatch_async(dispatch_get_main_queue(), ^{143 #if PLATFORM(IOS_FAMILY)144 WebThreadRun(block);145 #else146 block();147 #endif148 });149 }150 151 140 void ContentFilterUnblockHandler::requestUnblockAsync(DecisionHandlerFunction decisionHandler) const 152 141 { … … 154 143 if (m_webFilterEvaluator) { 155 144 [m_webFilterEvaluator unblockWithCompletion:[decisionHandler](BOOL unblocked, NSError *) { 156 dispatchToMainThread([decisionHandler, unblocked] {145 callOnMainThread([decisionHandler, unblocked] { 157 146 LOG(ContentFiltering, "WebFilterEvaluator %s the unblock request.\n", unblocked ? "allowed" : "did not allow"); 158 147 decisionHandler(unblocked); … … 165 154 if (m_unblockRequester) { 166 155 m_unblockRequester([decisionHandler](bool unblocked) { 167 dispatchToMainThread([decisionHandler, unblocked] {156 callOnMainThread([decisionHandler, unblocked] { 168 157 decisionHandler(unblocked); 169 158 }); -
trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm
r265056 r271493 30 30 #import <notify.h> 31 31 #import <pal/spi/cocoa/IOPSLibSPI.h> 32 #import <wtf/RunLoop.h> 32 33 33 34 namespace WebCore { … … 46 47 // If the current value of systemHasAC() is uncached, force a notification. 47 48 if (!cachedSystemHasAC()) { 48 dispatch_async(dispatch_get_main_queue(),[weakThis = makeWeakPtr(*this)] {49 RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { 49 50 if (weakThis) 50 51 weakThis->notifyPowerSourceChanged(); -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
r271219 r271493 943 943 RetainPtr<AVPlayer> strongPlayer = m_avPlayer.get(); 944 944 RetainPtr<AVPlayerItem> strongItem = item; 945 dispatch_async(dispatch_get_main_queue(),[strongPlayer, strongItem] {945 RunLoop::main().dispatch([strongPlayer, strongItem] { 946 946 [strongPlayer replaceCurrentItemWithPlayerItem:strongItem.get()]; 947 947 }); -
trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm
r271388 r271493 373 373 ASSERT(sourcePlayerLayer); 374 374 375 dispatch_async(dispatch_get_main_queue(), ^{375 RunLoop::main().dispatch([destinationPlayerLayer = retainPtr(destinationPlayerLayer), sourcePlayerLayer = retainPtr(sourcePlayerLayer)] { 376 376 [destinationPlayerLayer setPlayer:[sourcePlayerLayer player]]; 377 377 }); … … 1091 1091 void PlatformCALayer::setBoundsOnMainThread(CGRect bounds) 1092 1092 { 1093 CALayer *layer = m_layer.get(); 1094 dispatch_async(dispatch_get_main_queue(), ^{ 1093 RunLoop::main().dispatch([layer = m_layer, bounds] { 1095 1094 BEGIN_BLOCK_OBJC_EXCEPTIONS 1096 1095 [layer setBounds:bounds]; … … 1101 1100 void PlatformCALayer::setPositionOnMainThread(CGPoint position) 1102 1101 { 1103 CALayer *layer = m_layer.get(); 1104 dispatch_async(dispatch_get_main_queue(), ^{ 1102 RunLoop::main().dispatch([layer = m_layer, position] { 1105 1103 BEGIN_BLOCK_OBJC_EXCEPTIONS 1106 1104 [layer setPosition:position]; … … 1111 1109 void PlatformCALayer::setAnchorPointOnMainThread(FloatPoint3D value) 1112 1110 { 1113 CALayer *layer = m_layer.get(); 1114 dispatch_async(dispatch_get_main_queue(), ^{ 1111 RunLoop::main().dispatch([layer = m_layer, value] { 1115 1112 BEGIN_BLOCK_OBJC_EXCEPTIONS 1116 1113 [layer setAnchorPoint:CGPointMake(value.x(), value.y())]; -
trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm
r264839 r271493 102 102 103 103 RefPtr<WebCoreDecompressionSession> protectedThis { this }; 104 dispatch_async(dispatch_get_main_queue(),[protectedThis] {104 RunLoop::main().dispatch([protectedThis] { 105 105 if (protectedThis->m_notificationCallback) 106 106 protectedThis->m_notificationCallback(); … … 420 420 return; 421 421 422 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), callback = WTFMove(m_hasAvailableFrameCallback)] {422 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), callback = WTFMove(m_hasAvailableFrameCallback)] { 423 423 callback(); 424 424 }); … … 438 438 if (notificationCallback && isReadyForMoreMediaData()) { 439 439 RefPtr<WebCoreDecompressionSession> protectedThis { this }; 440 dispatch_async(dispatch_get_main_queue(),[protectedThis] {440 RunLoop::main().dispatch([protectedThis] { 441 441 if (protectedThis->m_notificationCallback) 442 442 protectedThis->m_notificationCallback(); … … 454 454 { 455 455 if (callback && m_producerQueue && !CMBufferQueueIsEmpty(m_producerQueue.get())) { 456 dispatch_async(dispatch_get_main_queue(),[callback] {456 RunLoop::main().dispatch([callback] { 457 457 callback(); 458 458 }); -
trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm
r271387 r271493 318 318 319 319 NSTimeInterval animationDuration = [CATransaction animationDuration]; 320 dispatch_async(dispatch_get_main_queue(), ^{320 RunLoop::main().dispatch([self, strongSelf = retainPtr(self), targetVideoFrame, animationDuration] { 321 321 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil]; 322 322 … … 1420 1420 void VideoFullscreenInterfaceAVKit::finalizeSetup() 1421 1421 { 1422 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this] {1422 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] { 1423 1423 if (m_fullscreenChangeObserver) { 1424 1424 if (!m_hasVideoContentLayer && m_targetMode.hasVideo()) { … … 1540 1540 m_standby = false; 1541 1541 1542 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this] {1542 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] { 1543 1543 if (m_fullscreenChangeObserver) 1544 1544 m_fullscreenChangeObserver->didExitFullscreen(); -
trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm
r237266 r271493 62 62 void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction() 63 63 { 64 dispatch_async(dispatch_get_main_queue(),[this] {64 RunLoop::main().dispatch([this] { 65 65 m_hysteresis.start(); 66 66 }); … … 69 69 void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction() 70 70 { 71 dispatch_async(dispatch_get_main_queue(),[this] {71 RunLoop::main().dispatch([this] { 72 72 m_hysteresis.stop(); 73 73 }); -
trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm
r269557 r271493 243 243 WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable { 244 244 IntRect clientRect = elementRectInWindow(m_videoElement.get()); 245 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, clientRect] {245 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, clientRect] { 246 246 m_interface->setInlineRect(clientRect, clientRect != IntRect(0, 0, 0, 0)); 247 247 }); … … 259 259 [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)]; 260 260 m_fullscreenModel->setVideoFullscreenLayer(videoFullscreenLayer.get(), [protectedThis = WTFMove(protectedThis), this] () mutable { 261 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this] {261 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this] { 262 262 if (!m_interface) 263 263 return; … … 279 279 [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)]; 280 280 m_fullscreenModel->setVideoFullscreenLayer(nil, [protectedThis = WTFMove(protectedThis), this] () mutable { 281 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this] {281 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this] { 282 282 if (!m_interface) 283 283 return; … … 296 296 ASSERT(isUIThread()); 297 297 #if PLATFORM(IOS_FAMILY) 298 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this] {298 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] { 299 299 m_interface->enterFullscreen(); 300 300 }); … … 303 303 [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)]; 304 304 m_fullscreenModel->setVideoFullscreenLayer(videoFullscreenLayer.get(), [protectedThis = WTFMove(protectedThis), this] () mutable { 305 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this] {305 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this] { 306 306 m_interface->enterFullscreen(); 307 307 }); … … 325 325 ASSERT(isUIThread()); 326 326 #if PLATFORM(IOS_FAMILY) 327 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this] {327 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] { 328 328 m_interface->cleanupFullscreen(); 329 329 }); … … 331 331 WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable { 332 332 m_fullscreenModel->setVideoFullscreenLayer(nil, [protectedThis = WTFMove(protectedThis), this] () mutable { 333 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this] {333 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this] { 334 334 m_interface->cleanupFullscreen(); 335 335 }); … … 365 365 WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable { 366 366 IntRect clientRect = elementRectInWindow(m_videoElement.get()); 367 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, clientRect] {367 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, clientRect] { 368 368 m_interface->preparedToReturnToInline(true, clientRect); 369 369 }); … … 376 376 { 377 377 if (WebThreadIsCurrent()) { 378 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), duration] {378 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), duration] { 379 379 protectedThis->durationChanged(duration); 380 380 }); … … 389 389 { 390 390 if (WebThreadIsCurrent()) { 391 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), currentTime, anchorTime] {391 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), currentTime, anchorTime] { 392 392 protectedThis->currentTimeChanged(currentTime, anchorTime); 393 393 }); … … 402 402 { 403 403 if (WebThreadIsCurrent()) { 404 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), bufferedTime] {404 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), bufferedTime] { 405 405 protectedThis->bufferedTimeChanged(bufferedTime); 406 406 }); … … 415 415 { 416 416 if (WebThreadIsCurrent()) { 417 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), isPlaying, playbackRate] {417 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), isPlaying, playbackRate] { 418 418 protectedThis->rateChanged(isPlaying, playbackRate); 419 419 }); … … 428 428 { 429 429 if (WebThreadIsCurrent()) { 430 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), hasVideo] {430 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), hasVideo] { 431 431 protectedThis->hasVideoChanged(hasVideo); 432 432 }); … … 441 441 { 442 442 if (WebThreadIsCurrent()) { 443 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), videoDimensions = videoDimensions] {443 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoDimensions = videoDimensions] { 444 444 protectedThis->videoDimensionsChanged(videoDimensions); 445 445 }); … … 454 454 { 455 455 if (WebThreadIsCurrent()) { 456 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), platformTimeRanges = timeRanges.ranges(), lastModifiedTime, liveUpdateInterval] {456 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), platformTimeRanges = timeRanges.ranges(), lastModifiedTime, liveUpdateInterval] { 457 457 protectedThis->seekableRangesChanged(TimeRanges::create(platformTimeRanges), lastModifiedTime, liveUpdateInterval); 458 458 }); … … 467 467 { 468 468 if (WebThreadIsCurrent()) { 469 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), canPlayFastReverse] {469 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), canPlayFastReverse] { 470 470 protectedThis->canPlayFastReverseChanged(canPlayFastReverse); 471 471 }); … … 489 489 { 490 490 if (WebThreadIsCurrent()) { 491 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), options = isolatedCopy(options), selectedIndex] {491 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), options = isolatedCopy(options), selectedIndex] { 492 492 protectedThis->audioMediaSelectionOptionsChanged(options, selectedIndex); 493 493 }); … … 502 502 { 503 503 if (WebThreadIsCurrent()) { 504 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), options = isolatedCopy(options), selectedIndex] {504 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), options = isolatedCopy(options), selectedIndex] { 505 505 protectedThis->legibleMediaSelectionOptionsChanged(options, selectedIndex); 506 506 }); … … 529 529 { 530 530 if (WebThreadIsCurrent()) { 531 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), disabled] {531 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), disabled] { 532 532 protectedThis->wirelessVideoPlaybackDisabledChanged(disabled); 533 533 }); … … 542 542 { 543 543 if (WebThreadIsCurrent()) { 544 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), muted] {544 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), muted] { 545 545 protectedThis->mutedChanged(muted); 546 546 }); … … 555 555 { 556 556 if (WebThreadIsCurrent()) { 557 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), volume] {557 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), volume] { 558 558 protectedThis->volumeChanged(volume); 559 559 }); … … 984 984 FloatSize videoDimensions = { (float)videoElement.videoWidth(), (float)videoElement.videoHeight() }; 985 985 986 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this, videoElementClientRect, videoDimensions, viewRef, mode, allowsPictureInPicture] {986 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this, videoElementClientRect, videoDimensions, viewRef, mode, allowsPictureInPicture] { 987 987 ASSERT(isUIThread()); 988 988 WebThreadLock(); … … 1003 1003 ASSERT(WebThreadIsCurrent() || isMainThread()); 1004 1004 IntRect clientRect = elementRectInWindow(m_videoElement.get()); 1005 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this, clientRect] {1005 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this, clientRect] { 1006 1006 ASSERT(isUIThread()); 1007 1007 m_interface->exitFullscreen(clientRect); -
trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm
r269658 r271493 290 290 // We own obj at this point, so we don't need the block to implicitly 291 291 // retain it. 292 __block id objNotRetained = obj; 293 dispatch_async(dispatch_get_main_queue(), ^{ 294 [objNotRetained release]; 292 RunLoop::main().dispatch([obj] { 293 [obj release]; 295 294 }); 296 295 } … … 438 437 [[NSNotificationCenter defaultCenter] postNotificationName:name object:object userInfo:userInfo]; 439 438 else { 440 dispatch_async(dispatch_get_main_queue(), ^{441 [[NSNotificationCenter defaultCenter] postNotificationName:name object:object userInfo:userInfo];439 RunLoop::main().dispatch([name = retainPtr(name), object = retainPtr(object), userInfo = retainPtr(userInfo)] { 440 [[NSNotificationCenter defaultCenter] postNotificationName:name.get() object:object.get() userInfo:userInfo.get()]; 442 441 }); 443 442 } -
trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm
r270069 r271493 457 457 [videoFullscreenInterfaceObjC() setUpPIPForVideoView:&layerHostedView withFrame:(NSRect)initialRect inWindow:parentWindow]; 458 458 459 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), this] {459 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] { 460 460 if (m_fullscreenChangeObserver) 461 461 m_fullscreenChangeObserver->didSetupFullscreen(); -
trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm
r247489 r271493 261 261 return; 262 262 263 dispatch_async(dispatch_get_main_queue(), ^{263 RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] { 264 264 if (m_callback) 265 265 m_callback->refreshCaptureDevices(); -
trunk/Source/WebKit/ChangeLog
r271486 r271493 1 2021-01-14 Geoffrey Garen <ggaren@apple.com> 2 3 Removed most uses of dispatch_async(dispatch_get_main_queue(), ...) 4 https://bugs.webkit.org/show_bug.cgi?id=220066 5 6 Reviewed by Antti Koivisto. 7 8 dispatch_async has two downsides: 9 10 (1) Its order is undefined (and in practice highly variable) relative to 11 other WebKit operations. This sometimes causes flakiness. 12 13 (2) It doesn't honor the RunLoop first paint optimization. 14 15 We can use RunLoop::dispatch() instead. 16 17 * Platform/cocoa/WKPaymentAuthorizationDelegate.mm: 18 (-[WKPaymentAuthorizationDelegate _didRequestMerchantSession:]): 19 * Shared/Cocoa/DefaultWebBrowserChecks.mm: 20 (WebKit::determineITPState): 21 * UIProcess/API/C/mac/WKContextPrivateMac.mm: 22 (WKContextGetInfoForInstalledPlugIns): 23 * UIProcess/API/Cocoa/NSAttributedString.mm: 24 (+[NSAttributedString _loadFromHTMLWithOptions:contentLoader:completionHandler:]): 25 * UIProcess/API/Cocoa/WKBrowsingContextController.mm: 26 (+[WKBrowsingContextController registerSchemeForCustomProtocol:]): 27 (+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]): 28 * UIProcess/API/Cocoa/WKWebView.mm: 29 (-[WKWebView _evaluateJavaScript:asAsyncFunction:withSourceURL:withArguments:forceUserGesture:inFrame:inWorld:completionHandler:]): 30 (-[WKWebView _internalDoAfterNextPresentationUpdate:withoutWaitingForPainting:withoutWaitingForAnimatedResize:]): 31 * UIProcess/API/Cocoa/WKWebViewTesting.mm: 32 (-[WKWebView _doAfterNextVisibleContentRectUpdate:]): 33 * UIProcess/API/ios/WKWebViewIOS.mm: 34 (-[WKWebView _scheduleVisibleContentRectUpdateAfterScrollInView:]): 35 (-[WKWebView _updateVisibleContentRects]): 36 (-[WKWebView _firePresentationUpdateForPendingStableStatePresentationCallbacks]): 37 (-[WKWebView _doAfterNextStablePresentationUpdate:]): 38 * UIProcess/Cocoa/AutomationClient.mm: 39 (WebKit::AutomationClient::requestAutomationSession): 40 * UIProcess/Cocoa/NavigationState.mm: 41 (WebKit::tryInterceptNavigation): 42 * UIProcess/Cocoa/PreferenceObserver.mm: 43 (-[WKPreferenceObserver preferenceDidChange:key:encodedValue:]): 44 * UIProcess/Cocoa/WebInspectorPreferenceObserver.mm: 45 (-[WKWebInspectorPreferenceObserver observeValueForKeyPath:ofObject:change:context:]): 46 * UIProcess/Cocoa/WebPageProxyCocoa.mm: 47 (WebKit::WebPageProxy::requestThumbnailWithOperation): 48 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 49 (WebKit::webProcessPoolHighDynamicRangeDidChangeCallback): 50 * UIProcess/Cocoa/WebViewImpl.mm: 51 (-[WKDOMPasteMenuDelegate menuDidClose:]): 52 (WebKit::WebViewImpl::updateWindowAndViewFrames): 53 (WebKit::WebViewImpl::setTopContentInset): 54 (WebKit::WebViewImpl::didBecomeEditable): 55 (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): 56 (WebKit::WebViewImpl::performDragOperation): 57 * UIProcess/EndowmentStateTracker.mm: 58 (WebKit::EndowmentStateTracker::registerMonitorIfNecessary): 59 * UIProcess/_WKTouchEventGenerator.mm: 60 (-[_WKTouchEventGenerator _sendHIDEvent:]): 61 (-[_WKTouchEventGenerator _sendMarkerHIDEventWithCompletionBlock:]): 62 * UIProcess/ios/ProcessAssertionIOS.mm: 63 (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]): 64 (-[WKProcessAssertionBackgroundTaskManager _handleBackgroundTaskExpirationOnMainThread]): 65 (-[WKRBSAssertionDelegate assertion:didInvalidateWithError:]): 66 (WebKit::ProcessAssertion::ProcessAssertion): 67 * UIProcess/ios/WKContentViewInteraction.mm: 68 (-[WKContentView resignFirstResponderForWebView]): 69 * UIProcess/ios/WKPDFView.mm: 70 (-[WKPDFView pdfHostViewControllerExtensionProcessDidCrash:]): 71 * UIProcess/ios/forms/WKFileUploadPanel.mm: 72 (-[WKFileUploadPanel imagePickerController:didFinishPickingMediaWithInfo:]): 73 (-[WKFileUploadPanel imagePickerController:didFinishPickingMultipleMediaWithInfo:]): 74 * UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm: 75 (-[WKFullScreenWindowController placeholderWillMoveToSuperview:]): 76 * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm: 77 (WebKit::PlatformCALayerRemoteCustom::clone const): 78 * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: 79 (WebKit::RemoteLayerTreeDrawingArea::updateRendering): 80 * WebProcess/cocoa/VideoFullscreenManager.mm: 81 (WebKit::VideoFullscreenManager::requestVideoContentLayer): 82 (WebKit::VideoFullscreenManager::returnVideoContentLayer): 83 (WebKit::VideoFullscreenManager::didSetupFullscreen): 84 (WebKit::VideoFullscreenManager::willExitFullscreen): 85 (WebKit::VideoFullscreenManager::didEnterFullscreen): 86 (WebKit::VideoFullscreenManager::didExitFullscreen): 87 (WebKit::VideoFullscreenManager::didCleanupFullscreen): 88 1 89 2021-01-14 Youenn Fablet <youenn@apple.com> 2 90 -
trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm
r263426 r271493 136 136 LOG_ERROR("PKCanMakePaymentsWithMerchantIdentifierAndDomain error %@", error); 137 137 138 dispatch_async(dispatch_get_main_queue(), ^{138 RunLoop::main().dispatch([self, protectedSelf = retainPtr(self), merchantURL = retainPtr(merchantURL)] { 139 139 ASSERT(_didRequestMerchantSessionCompletion); 140 140 … … 145 145 } 146 146 147 presenter->client().presenterWillValidateMerchant(*presenter, merchantURL );147 presenter->client().presenterWillValidateMerchant(*presenter, merchantURL.get()); 148 148 }); 149 149 }]; -
trunk/Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.mm
r271283 r271493 136 136 g_currentITPState = determineITPStateInternal(appWasLinkedOnOrAfter, bundleIdentifier) ? ITPState::Enabled : ITPState::Disabled; 137 137 138 dispatch_async(dispatch_get_main_queue(), ^{138 RunLoop::main().dispatch([] { 139 139 dispatch_release(g_itpQueue); 140 140 g_itpQueue = nullptr; -
trunk/Source/WebKit/UIProcess/API/C/mac/WKContextPrivateMac.mm
r269785 r271493 41 41 #import <WebCore/PluginBlocklist.h> 42 42 #import <WebCore/WebGLBlocklist.h> 43 #import <wtf/BlockPtr.h> 43 44 #import <wtf/RetainPtr.h> 44 45 … … 84 85 85 86 WebKit::toImpl(contextRef)->ref(); 86 dispatch_async(dispatch_get_main_queue(), ^(){87 RunLoop::main().dispatch([block = makeBlockPtr(block), array = WTFMove(array), contextRef] { 87 88 block(WebKit::toAPI(array.get()), 0); 88 89 -
trunk/Source/WebKit/UIProcess/API/Cocoa/NSAttributedString.mm
r261407 r271493 336 336 runConversion(); 337 337 else 338 dispatch_async(dispatch_get_main_queue(), runConversion); 338 RunLoop::main().dispatch([runConversion = makeBlockPtr(runConversion)] { 339 runConversion(); 340 }); 339 341 } 340 342 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm
r268401 r271493 106 106 WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme); 107 107 else { 108 dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {108 RunLoop::main().dispatch([scheme = retainPtr(scheme)] { 109 109 WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get()); 110 }) .get());110 }); 111 111 } 112 112 } … … 117 117 WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme); 118 118 else { 119 dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {119 RunLoop::main().dispatch([scheme = retainPtr(scheme)] { 120 120 WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get()); 121 }) .get());121 }); 122 122 } 123 123 } -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r271424 r271493 1031 1031 1032 1032 auto error = adoptNS([[NSError alloc] initWithDomain:WKErrorDomain code:WKErrorJavaScriptExceptionOccurred userInfo:userInfo.get()]); 1033 dispatch_async(dispatch_get_main_queue(),[handler, error] {1033 RunLoop::main().dispatch([handler, error] { 1034 1034 auto rawHandler = (void (^)(id, NSError *))handler.get(); 1035 1035 rawHandler(nil, error.get()); … … 1346 1346 #if PLATFORM(IOS_FAMILY) 1347 1347 if (![self usesStandardContentView]) { 1348 dispatch_async(dispatch_get_main_queue(), updateBlock); 1348 RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] { 1349 updateBlock(); 1350 }); 1349 1351 return; 1350 1352 } -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
r270669 r271493 115 115 [self _scheduleVisibleContentRectUpdate]; 116 116 #else 117 dispatch_async(dispatch_get_main_queue(), updateBlock); 117 RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] { 118 updateBlock(); 119 }); 118 120 #endif 119 121 } -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
r271000 r271493 1942 1942 } 1943 1943 1944 dispatch_async(dispatch_get_main_queue(),[retainedSelf = retainPtr(self)] {1944 RunLoop::main().dispatch([retainedSelf = retainPtr(self)] { 1945 1945 WKWebView *webView = retainedSelf.get(); 1946 1946 if (![webView _isValid]) … … 2080 2080 if (!CGPointEqualToPoint(activePoint, currentPoint)) { 2081 2081 RetainPtr<WKScrollView> strongScrollView = _scrollView; 2082 dispatch_async(dispatch_get_main_queue(),[strongScrollView, activePoint] {2082 RunLoop::main().dispatch([strongScrollView, activePoint] { 2083 2083 [strongScrollView setContentOffset:activePoint animated:NO]; 2084 2084 }); … … 2439 2439 RetainPtr<WKWebView> strongSelf = self; 2440 2440 [self _doAfterNextPresentationUpdate:[strongSelf] { 2441 dispatch_async(dispatch_get_main_queue(),[strongSelf] {2441 RunLoop::main().dispatch([strongSelf] { 2442 2442 if ([strongSelf->_stableStatePresentationUpdateCallbacks count]) 2443 2443 [strongSelf _firePresentationUpdateForPendingStableStatePresentationCallbacks]; … … 2720 2720 { 2721 2721 if (![self usesStandardContentView]) { 2722 dispatch_async(dispatch_get_main_queue(), updateBlock); 2722 RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] { 2723 updateBlock(); 2724 }); 2723 2725 return; 2724 2726 } -
trunk/Source/WebKit/UIProcess/Cocoa/AutomationClient.mm
r242339 r271493 86 86 // deadlock because it's already taken while handling XPC messages. 87 87 NSString *requestedSessionIdentifier = sessionIdentifier; 88 dispatch_async(dispatch_get_main_queue(), ^{88 RunLoop::main().dispatch([this, requestedSessionIdentifier = retainPtr(requestedSessionIdentifier), configuration = retainPtr(configuration)] { 89 89 if (m_delegateMethods.requestAutomationSession) 90 [m_delegate.get() _processPool:m_processPool didRequestAutomationSessionWithIdentifier:requestedSessionIdentifier configuration:configuration];90 [m_delegate.get() _processPool:m_processPool didRequestAutomationSessionWithIdentifier:requestedSessionIdentifier.get() configuration:configuration.get()]; 91 91 }); 92 92 } -
trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm
r271264 r271493 452 452 }); 453 453 [LSAppLink openWithURL:url completionHandler:[localCompletionHandler](BOOL success, NSError *) { 454 dispatch_async(dispatch_get_main_queue(),[localCompletionHandler, success] {454 RunLoop::main().dispatch([localCompletionHandler, success] { 455 455 (*localCompletionHandler)(success); 456 456 delete localCompletionHandler; -
trunk/Source/WebKit/UIProcess/Cocoa/PreferenceObserver.mm
r268421 r271493 180 180 { 181 181 #if ENABLE(CFPREFS_DIRECT_MODE) 182 dispatch_async(dispatch_get_main_queue(), ^{182 RunLoop::main().dispatch([domain = retainPtr(domain), key = retainPtr(key), encodedValue = retainPtr(encodedValue)] { 183 183 Optional<String> encodedString; 184 184 if (encodedValue) 185 encodedString = String(encodedValue );185 encodedString = String(encodedValue.get()); 186 186 187 187 for (auto* processPool : WebKit::WebProcessPool::allProcessPools()) 188 processPool->notifyPreferencesChanged(domain , key, encodedString);188 processPool->notifyPreferencesChanged(domain.get(), key.get(), encodedString); 189 189 }); 190 190 #endif -
trunk/Source/WebKit/UIProcess/Cocoa/WebInspectorPreferenceObserver.mm
r270035 r271493 68 68 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context 69 69 { 70 dispatch_async(dispatch_get_main_queue(), ^{70 RunLoop::main().dispatch([] { 71 71 for (auto* pool : WebKit::WebProcessPool::allProcessPools()) { 72 72 for (size_t i = 0; i < pool->processes().size(); ++i) { -
trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
r271479 r271493 457 457 { 458 458 [operation setCompletionBlock:^{ 459 dispatch_async(dispatch_get_main_queue(), ^{459 RunLoop::main().dispatch([this, operation = retainPtr(operation)] { 460 460 auto identifier = [operation identifier]; 461 461 auto convertedImage = convertPlatformImageToBitmap([operation thumbnail], WebCore::IntSize(400, 400)); -
trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r271448 r271493 890 890 static void webProcessPoolHighDynamicRangeDidChangeCallback(CMNotificationCenterRef, const void*, CFStringRef notificationName, const void*, CFTypeRef) 891 891 { 892 dispatch_async(dispatch_get_main_queue(), ^{892 RunLoop::main().dispatch([] { 893 893 auto properties = WebCore::collectScreenProperties(); 894 894 for (auto& pool : WebProcessPool::allProcessPools()) -
trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
r271459 r271493 930 930 - (void)menuDidClose:(NSMenu *)menu 931 931 { 932 dispatch_async(dispatch_get_main_queue(),[impl = _impl] {932 RunLoop::main().dispatch([impl = _impl] { 933 933 if (impl) 934 934 impl->handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture); … … 1810 1810 m_didScheduleWindowAndViewFrameUpdate = true; 1811 1811 1812 auto weakThis = makeWeakPtr(*this); 1813 dispatch_async(dispatch_get_main_queue(), [weakThis] { 1812 RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { 1814 1813 if (!weakThis) 1815 1814 return; … … 1937 1936 m_didScheduleSetTopContentInset = true; 1938 1937 1939 auto weakThis = makeWeakPtr(*this); 1940 dispatch_async(dispatch_get_main_queue(), [weakThis] { 1938 RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { 1941 1939 if (!weakThis) 1942 1940 return; … … 2941 2939 [m_windowVisibilityObserver startObservingFontPanel]; 2942 2940 2943 dispatch_async(dispatch_get_main_queue(),[] {2941 RunLoop::main().dispatch([] { 2944 2942 [[NSSpellChecker sharedSpellChecker] _preflightChosenSpellServer]; 2945 2943 }); … … 3384 3382 auto weakThis = makeWeakPtr(*this); 3385 3383 m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:selectedRange inString:postLayoutData.paragraphContextForCandidateRequest types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakThis](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) { 3386 dispatch_async(dispatch_get_main_queue(), ^{3384 RunLoop::main().dispatch([weakThis, sequenceNumber, candidates = retainPtr(candidates)] { 3387 3385 if (!weakThis) 3388 3386 return; 3389 weakThis->handleRequestedCandidates(sequenceNumber, candidates );3387 weakThis->handleRequestedCandidates(sequenceNumber, candidates.get()); 3390 3388 }); 3391 3389 }]; … … 4130 4128 return; 4131 4129 4132 dispatch_async(dispatch_get_main_queue(),[this, path = RetainPtr<NSString>(fileURL.path), fileNames, fileCount, dragData, pasteboardName] {4130 RunLoop::main().dispatch([this, path = RetainPtr<NSString>(fileURL.path), fileNames, fileCount, dragData, pasteboardName] { 4133 4131 fileNames->append(path.get()); 4134 4132 if (fileNames->size() == fileCount) { -
trunk/Source/WebKit/UIProcess/EndowmentStateTracker.mm
r265222 r271493 32 32 #import "RunningBoardServicesSPI.h" 33 33 #include <wtf/NeverDestroyed.h> 34 #include <wtf/RunLoop.h> 34 35 35 36 namespace WebKit { … … 105 106 106 107 [config setUpdateHandler:[this] (RBSProcessMonitor * _Nonnull monitor, RBSProcessHandle * _Nonnull process, RBSProcessStateUpdate * _Nonnull update) mutable { 107 dispatch_async(dispatch_get_main_queue(),[this, state = stateFromEndowments(update.state.endowmentNamespaces)]() mutable {108 RunLoop::main().dispatch([this, state = stateFromEndowments(update.state.endowmentNamespaces)]() mutable { 108 109 setState(WTFMove(state)); 109 110 }); -
trunk/Source/WebKit/UIProcess/_WKTouchEventGenerator.mm
r258478 r271493 34 34 #import <wtf/Assertions.h> 35 35 #import <wtf/RetainPtr.h> 36 #import <wtf/RunLoop.h> 36 37 #import <wtf/SoftLinking.h> 37 38 … … 213 214 214 215 if (eventRef) { 215 RetainPtr<IOHIDEventRef> strongEvent = eventRef; 216 dispatch_async(dispatch_get_main_queue(), ^{ 216 RunLoop::main().dispatch([strongEvent = retainPtr(eventRef)] { 217 217 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 218 218 uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId; … … 241 241 242 242 if (markerEvent) { 243 dispatch_async(dispatch_get_main_queue(),[markerEvent = WTFMove(markerEvent)] {243 RunLoop::main().dispatch([markerEvent = WTFMove(markerEvent)] { 244 244 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 245 245 auto contextID = [UIApplication sharedApplication].keyWindow._contextId; -
trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm
r269256 r271493 183 183 // Release the background task asynchronously because releasing the background task may destroy the ProcessThrottler and we don't 184 184 // want it to get destroyed while in the middle of updating its assertion. 185 dispatch_async(dispatch_get_main_queue(), ^{185 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 186 186 if (_assertionsNeedingBackgroundTask.computesEmpty()) 187 187 [self _releaseBackgroundTask]; … … 224 224 if (remainingTime == RBSProcessTimeLimitationNone) { 225 225 [self _releaseBackgroundTask]; 226 dispatch_async(dispatch_get_main_queue(), ^{226 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 227 227 [self _updateBackgroundTask]; 228 228 }); … … 272 272 RELEASE_LOG(ProcessSuspension, "%p - WKRBSAssertionDelegate: assertion was invalidated, error: %{public}@", error, self); 273 273 274 __weak WKRBSAssertionDelegate *weakSelf = self; 275 dispatch_async(dispatch_get_main_queue(), ^{ 276 WKRBSAssertionDelegate *strongSelf = weakSelf; 277 if (strongSelf && strongSelf.invalidationCallback) 278 strongSelf.invalidationCallback(); 274 RunLoop::main().dispatch([weakSelf = WeakObjCPtr<WKRBSAssertionDelegate>(self)] { 275 auto strongSelf = weakSelf.get(); 276 if (strongSelf && strongSelf.get().invalidationCallback) 277 strongSelf.get().invalidationCallback(); 279 278 }); 280 279 } … … 303 302 , m_pid(pid) 304 303 { 305 auto weakThis = makeWeakPtr(*this);306 304 NSString *runningBoardAssertionName = runningBoardNameForAssertionType(assertionType); 307 305 ASSERT(runningBoardAssertionName); … … 325 323 if (![m_rbsAssertion acquireWithError:&acquisitionError]) { 326 324 RELEASE_LOG_ERROR(ProcessSuspension, "%p - ProcessAssertion: Failed to acquire RBS %{public}@ assertion '%{public}s' for process with PID %d, error: %{public}@", this, runningBoardAssertionName, reason.utf8().data(), pid, acquisitionError); 327 dispatch_async(dispatch_get_main_queue(), ^{325 RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] { 328 326 if (weakThis) 329 processAssertionWasInvalidated();327 weakThis->processAssertionWasInvalidated(); 330 328 }); 331 329 } else -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r271445 r271493 1451 1451 1452 1452 if (_keyWebEventHandler) { 1453 dispatch_async(dispatch_get_main_queue(),[weakHandler = WeakObjCPtr<id>(_keyWebEventHandler.get()), weakSelf = WeakObjCPtr<WKContentView>(self)] {1453 RunLoop::main().dispatch([weakHandler = WeakObjCPtr<id>(_keyWebEventHandler.get()), weakSelf = WeakObjCPtr<WKContentView>(self)] { 1454 1454 auto strongSelf = weakSelf.get(); 1455 1455 if (!strongSelf || [strongSelf isFirstResponder]) -
trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm
r269869 r271493 510 510 { 511 511 // FIXME 40916725: PDFKit should dispatch this message to the main thread like it does for other delegate messages. 512 dispatch_async(dispatch_get_main_queue(),[webView = _webView] {512 RunLoop::main().dispatch([webView = _webView] { 513 513 if (auto page = [webView _page]) 514 514 page->dispatchProcessDidTerminate(WebKit::ProcessTerminationReason::Crash); -
trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm
r269869 r271493 684 684 ASSERT([processedResults count] == 1); 685 685 _WKFileUploadItem *result = [processedResults objectAtIndex:0]; 686 dispatch_async(dispatch_get_main_queue(), ^{687 [self _chooseFiles:@[result. fileURL] displayString:displayString iconImage:result.displayImage.get()];686 RunLoop::main().dispatch([self, strongSelf = retainPtr(self), result = retainPtr(result), displayString = retainPtr(displayString)] { 687 [self _chooseFiles:@[result.get().fileURL] displayString:displayString.get() iconImage:result.get().displayImage.get()]; 688 688 }); 689 689 } 690 690 failureBlock:^{ 691 dispatch_async(dispatch_get_main_queue(), ^{691 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 692 692 [self _cancel]; 693 693 }); … … 713 713 } 714 714 715 dispatch_async(dispatch_get_main_queue(), ^{716 [self _chooseFiles:fileURLs displayString:displayStringiconImage:iconImage.get()];715 RunLoop::main().dispatch([self, strongSelf = retainPtr(self), fileURLs = retainPtr(fileURLs), displayString = retainPtr(displayString), iconImage] { 716 [self _chooseFiles:fileURLs.get() displayString:displayString.get() iconImage:iconImage.get()]; 717 717 }); 718 718 } 719 719 failureBlock:^{ 720 dispatch_async(dispatch_get_main_queue(), ^{720 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 721 721 [self _cancel]; 722 722 }); -
trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm
r271171 r271493 880 880 return; 881 881 882 dispatch_async(dispatch_get_main_queue(), ^{882 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 883 883 if ([_webViewPlaceholder superview] == nil && [_webViewPlaceholder parent] == self) 884 884 [self close]; -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm
r263323 r271493 113 113 AVPlayerLayer *destinationPlayerLayer = static_cast<AVPlayerLayer *>(clonedLayer.get()); 114 114 AVPlayerLayer *sourcePlayerLayer = static_cast<AVPlayerLayer *>(platformLayer()); 115 dispatch_async(dispatch_get_main_queue(),[destinationPlayerLayer, sourcePlayerLayer] {115 RunLoop::main().dispatch([destinationPlayerLayer, sourcePlayerLayer] { 116 116 [destinationPlayerLayer setPlayer:[sourcePlayerLayer player]]; 117 117 }); -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm
r271171 r271493 417 417 418 418 MonotonicTime timestamp = MonotonicTime::now(); 419 dispatch_async(dispatch_get_main_queue(),[pageID, timestamp] {419 RunLoop::main().dispatch([pageID, timestamp] { 420 420 if (WebPage* webPage = WebProcess::singleton().webPage(pageID)) 421 421 webPage->didFlushLayerTreeAtTime(timestamp); -
trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm
r271325 r271493 386 386 387 387 model->setVideoFullscreenLayer(videoLayer, [protectedThis = makeRefPtr(this), this, contextId] () mutable { 388 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, contextId] {388 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, contextId] { 389 389 if (protectedThis->m_page) 390 390 m_page->send(Messages::VideoFullscreenManagerProxy::SetHasVideoContentLayer(contextId, true)); … … 400 400 401 401 model->waitForPreparedForInlineThen([protectedThis = makeRefPtr(this), this, contextId, model] () mutable { // need this for return video layer 402 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, contextId, model] () mutable {402 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, contextId, model] () mutable { 403 403 model->setVideoFullscreenLayer(nil, [protectedThis = WTFMove(protectedThis), this, contextId] () mutable { 404 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, contextId] {404 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, contextId] { 405 405 if (protectedThis->m_page) 406 406 m_page->send(Messages::VideoFullscreenManagerProxy::SetHasVideoContentLayer(contextId, false)); … … 421 421 422 422 model->setVideoFullscreenLayer(videoLayer, [protectedThis = makeRefPtr(this), this, contextId] () mutable { 423 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), this, contextId] {423 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), this, contextId] { 424 424 if (protectedThis->m_page) 425 425 m_page->send(Messages::VideoFullscreenManagerProxy::EnterFullscreen(contextId)); … … 439 439 return; 440 440 441 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), videoElement = WTFMove(videoElement), contextId] {441 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoElement = WTFMove(videoElement), contextId] { 442 442 videoElement->willExitFullscreen(); 443 443 if (protectedThis->m_page) … … 465 465 466 466 // exit fullscreen now if it was previously requested during an animation. 467 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), videoElement] {467 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoElement] { 468 468 if (protectedThis->m_page) 469 469 protectedThis->exitVideoFullscreenForVideoElement(*videoElement, [](bool) { }); … … 480 480 481 481 #if PLATFORM(IOS_FAMILY) 482 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), contextId, interface] {482 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), contextId, interface] { 483 483 if (protectedThis->m_page) 484 484 protectedThis->m_page->send(Messages::VideoFullscreenManagerProxy::CleanupFullscreen(contextId)); … … 486 486 #else 487 487 model->waitForPreparedForInlineThen([protectedThis = makeRefPtr(this), contextId, interface, model]() mutable { 488 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), contextId, interface, model] () mutable {488 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), contextId, interface, model] () mutable { 489 489 model->setVideoFullscreenLayer(nil, [protectedThis = WTFMove(protectedThis), contextId, interface] () mutable { 490 dispatch_async(dispatch_get_main_queue(),[protectedThis = WTFMove(protectedThis), contextId, interface] {490 RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), contextId, interface] { 491 491 if (interface->layerHostingContext()) { 492 492 interface->layerHostingContext()->setRootLayer(nullptr); … … 531 531 return; 532 532 533 dispatch_async(dispatch_get_main_queue(),[protectedThis = makeRefPtr(this), videoElement, mode, standby] {533 RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoElement, mode, standby] { 534 534 if (protectedThis->m_page) 535 535 protectedThis->enterVideoFullscreenForVideoElement(*videoElement, mode, standby); -
trunk/Source/WebKitLegacy/ios/ChangeLog
r269545 r271493 1 2021-01-14 Geoffrey Garen <ggaren@apple.com> 2 3 Removed most uses of dispatch_async(dispatch_get_main_queue(), ...) 4 https://bugs.webkit.org/show_bug.cgi?id=220066 5 6 Reviewed by Antti Koivisto. 7 8 dispatch_async has two downsides: 9 10 (1) Its order is undefined (and in practice highly variable) relative to 11 other WebKit operations. This sometimes causes flakiness. 12 13 (2) It doesn't honor the RunLoop first paint optimization. 14 15 We can use RunLoop::dispatch() instead. 16 17 * Misc/WebGeolocationProviderIOS.mm: 18 (-[WebGeolocationProviderIOS registerWebView:]): 19 (-[WebGeolocationProviderIOS unregisterWebView:]): 20 (-[WebGeolocationProviderIOS setEnableHighAccuracy:]): 21 (-[WebGeolocationProviderIOS initializeGeolocationForWebView:listener:]): 22 * WebCoreSupport/WebChromeClientIOS.mm: 23 (WebChromeClientIOS::runOpenPanel): 24 * WebCoreSupport/WebInspectorClientIOS.mm: 25 (WebInspectorClient::didSetSearchingForNode): 26 1 27 2020-11-06 Sam Weinig <weinig@apple.com> 2 28 -
trunk/Source/WebKitLegacy/ios/Misc/WebGeolocationProviderIOS.mm
r249066 r271493 38 38 #import <wtf/HashMap.h> 39 39 #import <wtf/RetainPtr.h> 40 #import <wtf/RunLoop.h> 40 41 #import <wtf/Vector.h> 41 42 … … 179 180 180 181 if (!_isSuspended) { 181 dispatch_async(dispatch_get_main_queue(), ^{182 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 182 183 if (!_coreLocationProvider) { 183 184 ASSERT(!_coreLocationUpdateListenerProxy); … … 209 210 210 211 if (_registeredWebViews.isEmpty()) { 211 dispatch_async(dispatch_get_main_queue(), ^{212 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 212 213 [_coreLocationProvider stop]; 213 214 }); … … 227 228 ASSERT(WebThreadIsLockedOrDisabled()); 228 229 _enableHighAccuracy = _enableHighAccuracy || enableHighAccuracy; 229 dispatch_async(dispatch_get_main_queue(), ^{230 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 230 231 [_coreLocationProvider setEnableHighAccuracy:_enableHighAccuracy]; 231 232 }); … … 242 243 _trackedWebViews.add(webView); 243 244 244 dispatch_async(dispatch_get_main_queue(), ^{245 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 245 246 if (!_coreLocationProvider) { 246 247 ASSERT(!_coreLocationUpdateListenerProxy); -
trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebChromeClientIOS.mm
r259843 r271493 147 147 148 148 if (WebThreadIsCurrent()) { 149 dispatch_async(dispatch_get_main_queue(), ^{150 [[webView() _UIKitDelegateForwarder] webView:webView() runOpenPanelForFileButtonWithResultListener:listener configuration:configuration];149 RunLoop::main().dispatch([this, listener = retainPtr(listener), configuration = retainPtr(configuration)] { 150 [[webView() _UIKitDelegateForwarder] webView:webView() runOpenPanelForFileButtonWithResultListener:listener.get() configuration:configuration.get()]; 151 151 }); 152 152 } else -
trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebInspectorClientIOS.mm
r257835 r271493 105 105 void WebInspectorClient::didSetSearchingForNode(bool enabled) 106 106 { 107 WebInspector *inspector = [m_inspectedWebView inspector];108 107 NSString *notificationName = enabled ? WebInspectorDidStartSearchingForNode : WebInspectorDidStopSearchingForNode; 109 dispatch_async(dispatch_get_main_queue(), ^{110 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:inspector];108 RunLoop::main().dispatch([notificationName = retainPtr(notificationName), inspector = retainPtr([m_inspectedWebView inspector])] { 109 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName.get() object:inspector.get()]; 111 110 }); 112 111 } -
trunk/Source/WebKitLegacy/mac/ChangeLog
r271456 r271493 1 2021-01-14 Geoffrey Garen <ggaren@apple.com> 2 3 Removed most uses of dispatch_async(dispatch_get_main_queue(), ...) 4 https://bugs.webkit.org/show_bug.cgi?id=220066 5 6 Reviewed by Antti Koivisto. 7 8 dispatch_async has two downsides: 9 10 (1) Its order is undefined (and in practice highly variable) relative to 11 other WebKit operations. This sometimes causes flakiness. 12 13 (2) It doesn't honor the RunLoop first paint optimization. 14 15 We can use RunLoop::dispatch() instead. 16 17 * Plugins/npapi.mm: 18 (NPN_PluginThreadAsyncCall): 19 * WebCoreSupport/WebEditorClient.mm: 20 (WebEditorClient::requestCandidatesForSelection): 21 * WebCoreSupport/WebFrameLoaderClient.mm: 22 * WebView/WebImmediateActionController.mm: 23 (-[WebImmediateActionController immediateActionRecognizerWillPrepare:]): 24 * WebView/WebView.mm: 25 (+[WebView willEnterBackgroundWithCompletionHandler:]): 26 (-[_WebSafeAsyncForwarder forwardInvocation:]): 27 (-[WebView performDragOperation:]): 28 (-[WebView setEditable:]): 29 1 30 2021-01-13 Alex Christensen <achristensen@webkit.org> 2 31 -
trunk/Source/WebKitLegacy/mac/Plugins/npapi.mm
r234685 r271493 32 32 #import "WebNetscapePluginView.h" 33 33 #import "WebKitLogging.h" 34 #import <wtf/RunLoop.h> 34 35 35 36 using namespace WebCore; … … 175 176 WebNetscapePluginView *pluginView = pluginViewForInstance(instance); 176 177 177 dispatch_async(dispatch_get_main_queue(), ^{178 RunLoop::main().dispatch([pluginView = retainPtr(pluginView), userData, func] { 178 179 if (!pluginView || !pluginView->plugin) { 179 180 // The plug-in has already been destroyed. -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
r267938 r271493 1123 1123 auto weakEditor = makeWeakPtr(*this); 1124 1124 m_lastCandidateRequestSequenceNumber = [[NSSpellChecker sharedSpellChecker] requestCandidatesForSelectedRange:m_rangeForCandidates inString:m_paragraphContextForCandidateRequest.get() types:checkingTypes options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() completionHandler:[weakEditor](NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates) { 1125 dispatch_async(dispatch_get_main_queue(), ^{1125 RunLoop::main().dispatch([weakEditor, sequenceNumber, candidates = retainPtr(candidates)] { 1126 1126 if (!weakEditor) 1127 1127 return; 1128 weakEditor->handleRequestedCandidates(sequenceNumber, candidates );1128 weakEditor->handleRequestedCandidates(sequenceNumber, candidates.get()); 1129 1129 }); 1130 1130 }]; -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm
r271378 r271493 2373 2373 WebThreadRun(^{ 2374 2374 #else 2375 dispatch_async(dispatch_get_main_queue(), ^{2375 RunLoop::main().dispatch([self, strongSelf = retainPtr(self), success] { 2376 2376 #endif 2377 2377 if (success) -
trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm
r268813 r271493 200 200 if (![_immediateActionRecognizer animationController]) { 201 201 // FIXME: We should be able to remove the dispatch_async when rdar://problem/19502927 is resolved. 202 dispatch_async(dispatch_get_main_queue(), ^{202 RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] { 203 203 [self _cancelImmediateAction]; 204 204 }); -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r271456 r271493 245 245 #import <pal/spi/mac/NSWindowSPI.h> 246 246 #import <wtf/Assertions.h> 247 #import <wtf/BlockPtr.h> 247 248 #import <wtf/FileSystem.h> 248 249 #import <wtf/HashTraits.h> … … 1892 1893 WebThreadRun(^{ 1893 1894 [WebView _releaseMemoryNow]; 1894 dispatch_async(dispatch_get_main_queue(), handler); 1895 RunLoop::main().dispatch([handler = makeBlockPtr(handler)] { 1896 handler(); 1897 }); 1895 1898 }); 1896 1899 } … … 5025 5028 - (void)forwardInvocation:(NSInvocation *)invocation 5026 5029 { 5027 // Store _forwarder in an ivar so it is retained by the block.5028 _WebSafeForwarder *forwarder = _forwarder;5029 5030 if (WebThreadIsCurrent()) { 5030 5031 [invocation retainArguments]; 5031 dispatch_async(dispatch_get_main_queue(), ^{5032 [forwarder forwardInvocation:invocation ];5032 RunLoop::main().dispatch([forwarder = retainPtr(_forwarder), invocation = retainPtr(invocation)] { 5033 [forwarder forwardInvocation:invocation.get()]; 5033 5034 }); 5034 5035 } else 5035 [ forwarder forwardInvocation:invocation];5036 [_forwarder forwardInvocation:invocation]; 5036 5037 } 5037 5038 … … 6450 6451 return; 6451 6452 6452 dispatch_async(dispatch_get_main_queue(),[self, path = RetainPtr<NSString>(fileURL.path), fileNames, fileCount, dragData] {6453 RunLoop::main().dispatch([self, path = RetainPtr<NSString>(fileURL.path), fileNames, fileCount, dragData] { 6453 6454 fileNames->append(path.get()); 6454 6455 if (fileNames->size() == fileCount) { … … 7978 7979 #if PLATFORM(MAC) 7979 7980 if (flag) { 7980 dispatch_async(dispatch_get_main_queue(),[] {7981 RunLoop::main().dispatch([] { 7981 7982 [[NSSpellChecker sharedSpellChecker] _preflightChosenSpellServer]; 7982 7983 });
Note:
See TracChangeset
for help on using the changeset viewer.