⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 271493 in webkit


Ignore:
Timestamp:
Jan 14, 2021, 10:44:13 AM (6 years ago)
Author:
ggaren@apple.com
Message:

Removed most uses of dispatch_async(dispatch_get_main_queue(), ...)
https://bugs.webkit.org/show_bug.cgi?id=220066

Reviewed by Antti Koivisto.

dispatch_async has two downsides:

(1) Its order is undefined (and in practice highly variable) relative to
other WebKit operations. This sometimes causes flakiness.

(2) It doesn't honor the RunLoop first paint optimization.

We can use RunLoop::dispatch() instead.

Source/WebCore:

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper accessibilityPerformPressAction]):
(-[WebAccessibilityObjectWrapper accessibilityPerformIncrementAction]):
(-[WebAccessibilityObjectWrapper accessibilityPerformDecrementAction]):

  • platform/audio/cocoa/AudioSampleDataSource.mm:

(WebCore::AudioSampleDataSource::setupConverter):
(WebCore::AudioSampleDataSource::pushSamplesInternal):
(WebCore::AudioSampleDataSource::pullSamplesInternal):

  • platform/audio/ios/MediaSessionHelperIOS.mm:

(-[WebMediaSessionHelper initWithCallback:]):
(-[WebMediaSessionHelper dealloc]):

  • platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:

(WebCore::ContentFilterUnblockHandler::requestUnblockAsync const):
(WebCore::dispatchToMainThread): Deleted.

  • platform/cocoa/PowerSourceNotifier.mm:

(WebCore::PowerSourceNotifier::PowerSourceNotifier):

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::MediaPlayerPrivateAVFoundationObjC::setAVPlayerItem):

  • platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:

(WebCore::PlatformCALayerCocoa::clone const):
(WebCore::PlatformCALayer::setBoundsOnMainThread):
(WebCore::PlatformCALayer::setPositionOnMainThread):
(WebCore::PlatformCALayer::setAnchorPointOnMainThread):

  • platform/graphics/cocoa/WebCoreDecompressionSession.mm:

(WebCore::WebCoreDecompressionSession::maybeBecomeReadyForMoreMediaData):
(WebCore::WebCoreDecompressionSession::enqueueDecodedSample):
(WebCore::WebCoreDecompressionSession::requestMediaDataWhenReady):
(WebCore::WebCoreDecompressionSession::notifyWhenHasAvailableVideoFrame):

  • platform/ios/VideoFullscreenInterfaceAVKit.mm:

(-[WebAVPlayerLayer layoutSublayers]):
(VideoFullscreenInterfaceAVKit::finalizeSetup):
(VideoFullscreenInterfaceAVKit::doExitFullscreen):

  • platform/ios/WebSQLiteDatabaseTrackerClient.mm:

(WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction):
(WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction):

  • platform/ios/WebVideoFullscreenControllerAVKit.mm:

(VideoFullscreenControllerContext::requestUpdateInlineRect):
(VideoFullscreenControllerContext::requestVideoContentLayer):
(VideoFullscreenControllerContext::returnVideoContentLayer):
(VideoFullscreenControllerContext::didSetupFullscreen):
(VideoFullscreenControllerContext::didExitFullscreen):
(VideoFullscreenControllerContext::fullscreenMayReturnToInline):
(VideoFullscreenControllerContext::durationChanged):
(VideoFullscreenControllerContext::currentTimeChanged):
(VideoFullscreenControllerContext::bufferedTimeChanged):
(VideoFullscreenControllerContext::rateChanged):
(VideoFullscreenControllerContext::hasVideoChanged):
(VideoFullscreenControllerContext::videoDimensionsChanged):
(VideoFullscreenControllerContext::seekableRangesChanged):
(VideoFullscreenControllerContext::canPlayFastReverseChanged):
(VideoFullscreenControllerContext::audioMediaSelectionOptionsChanged):
(VideoFullscreenControllerContext::legibleMediaSelectionOptionsChanged):
(VideoFullscreenControllerContext::wirelessVideoPlaybackDisabledChanged):
(VideoFullscreenControllerContext::mutedChanged):
(VideoFullscreenControllerContext::volumeChanged):
(VideoFullscreenControllerContext::setUpFullscreen):
(VideoFullscreenControllerContext::exitFullscreen):

  • platform/ios/wak/WebCoreThread.mm:

(MainThreadAdoptAndRelease):
(WebThreadPostNotification):

  • platform/mac/VideoFullscreenInterfaceMac.mm:

(WebCore::VideoFullscreenInterfaceMac::setupFullscreen):

  • platform/mediastream/mac/AVCaptureDeviceManager.mm:

(-[WebCoreAVCaptureDeviceManagerObserver deviceConnectedDidChange:]):

Source/WebKit:

  • Platform/cocoa/WKPaymentAuthorizationDelegate.mm:

(-[WKPaymentAuthorizationDelegate _didRequestMerchantSession:]):

  • Shared/Cocoa/DefaultWebBrowserChecks.mm:

(WebKit::determineITPState):

  • UIProcess/API/C/mac/WKContextPrivateMac.mm:

(WKContextGetInfoForInstalledPlugIns):

  • UIProcess/API/Cocoa/NSAttributedString.mm:

(+[NSAttributedString _loadFromHTMLWithOptions:contentLoader:completionHandler:]):

  • UIProcess/API/Cocoa/WKBrowsingContextController.mm:

(+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
(+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _evaluateJavaScript:asAsyncFunction:withSourceURL:withArguments:forceUserGesture:inFrame:inWorld:completionHandler:]):
(-[WKWebView _internalDoAfterNextPresentationUpdate:withoutWaitingForPainting:withoutWaitingForAnimatedResize:]):

  • UIProcess/API/Cocoa/WKWebViewTesting.mm:

(-[WKWebView _doAfterNextVisibleContentRectUpdate:]):

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView _scheduleVisibleContentRectUpdateAfterScrollInView:]):
(-[WKWebView _updateVisibleContentRects]):
(-[WKWebView _firePresentationUpdateForPendingStableStatePresentationCallbacks]):
(-[WKWebView _doAfterNextStablePresentationUpdate:]):

  • UIProcess/Cocoa/AutomationClient.mm:

(WebKit::AutomationClient::requestAutomationSession):

  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::tryInterceptNavigation):

  • UIProcess/Cocoa/PreferenceObserver.mm:

(-[WKPreferenceObserver preferenceDidChange:key:encodedValue:]):

  • UIProcess/Cocoa/WebInspectorPreferenceObserver.mm:

(-[WKWebInspectorPreferenceObserver observeValueForKeyPath:ofObject:change:context:]):

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::requestThumbnailWithOperation):

  • UIProcess/Cocoa/WebProcessPoolCocoa.mm:

(WebKit::webProcessPoolHighDynamicRangeDidChangeCallback):

  • UIProcess/Cocoa/WebViewImpl.mm:

(-[WKDOMPasteMenuDelegate menuDidClose:]):
(WebKit::WebViewImpl::updateWindowAndViewFrames):
(WebKit::WebViewImpl::setTopContentInset):
(WebKit::WebViewImpl::didBecomeEditable):
(WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded):
(WebKit::WebViewImpl::performDragOperation):

  • UIProcess/EndowmentStateTracker.mm:

(WebKit::EndowmentStateTracker::registerMonitorIfNecessary):

  • UIProcess/_WKTouchEventGenerator.mm:

(-[_WKTouchEventGenerator _sendHIDEvent:]):
(-[_WKTouchEventGenerator _sendMarkerHIDEventWithCompletionBlock:]):

  • UIProcess/ios/ProcessAssertionIOS.mm:

(-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
(-[WKProcessAssertionBackgroundTaskManager _handleBackgroundTaskExpirationOnMainThread]):
(-[WKRBSAssertionDelegate assertion:didInvalidateWithError:]):
(WebKit::ProcessAssertion::ProcessAssertion):

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView resignFirstResponderForWebView]):

  • UIProcess/ios/WKPDFView.mm:

(-[WKPDFView pdfHostViewControllerExtensionProcessDidCrash:]):

  • UIProcess/ios/forms/WKFileUploadPanel.mm:

(-[WKFileUploadPanel imagePickerController:didFinishPickingMediaWithInfo:]):
(-[WKFileUploadPanel imagePickerController:didFinishPickingMultipleMediaWithInfo:]):

  • UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:

(-[WKFullScreenWindowController placeholderWillMoveToSuperview:]):

  • WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm:

(WebKit::PlatformCALayerRemoteCustom::clone const):

  • WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm:

(WebKit::RemoteLayerTreeDrawingArea::updateRendering):

  • WebProcess/cocoa/VideoFullscreenManager.mm:

(WebKit::VideoFullscreenManager::requestVideoContentLayer):
(WebKit::VideoFullscreenManager::returnVideoContentLayer):
(WebKit::VideoFullscreenManager::didSetupFullscreen):
(WebKit::VideoFullscreenManager::willExitFullscreen):
(WebKit::VideoFullscreenManager::didEnterFullscreen):
(WebKit::VideoFullscreenManager::didExitFullscreen):
(WebKit::VideoFullscreenManager::didCleanupFullscreen):

Source/WebKitLegacy/ios:

  • Misc/WebGeolocationProviderIOS.mm:

(-[WebGeolocationProviderIOS registerWebView:]):
(-[WebGeolocationProviderIOS unregisterWebView:]):
(-[WebGeolocationProviderIOS setEnableHighAccuracy:]):
(-[WebGeolocationProviderIOS initializeGeolocationForWebView:listener:]):

  • WebCoreSupport/WebChromeClientIOS.mm:

(WebChromeClientIOS::runOpenPanel):

  • WebCoreSupport/WebInspectorClientIOS.mm:

(WebInspectorClient::didSetSearchingForNode):

Source/WebKitLegacy/mac:

  • Plugins/npapi.mm:

(NPN_PluginThreadAsyncCall):

  • WebCoreSupport/WebEditorClient.mm:

(WebEditorClient::requestCandidatesForSelection):

  • WebCoreSupport/WebFrameLoaderClient.mm:
  • WebView/WebImmediateActionController.mm:

(-[WebImmediateActionController immediateActionRecognizerWillPrepare:]):

  • WebView/WebView.mm:

(+[WebView willEnterBackgroundWithCompletionHandler:]):
(-[_WebSafeAsyncForwarder forwardInvocation:]):
(-[WebView performDragOperation:]):
(-[WebView setEditable:]):

Source/WTF:

  • wtf/cocoa/MainThreadCocoa.mm:

(WTF::dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded):
(WTF::callOnWebThreadOrDispatchAsyncOnMainThread):

Location:
trunk/Source
Files:
53 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r271482 r271493  
     12021-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
    1212021-01-14  Per Arne Vollan  <pvollan@apple.com>
    222
  • trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm

    r263981 r271493  
    3535#import <stdio.h>
    3636#import <wtf/Assertions.h>
     37#import <wtf/BlockPtr.h>
    3738#import <wtf/HashSet.h>
    3839#import <wtf/RetainPtr.h>
     
    7475#if USE(WEB_THREAD)
    7576    if (WebCoreWebThreadIsEnabled && WebCoreWebThreadIsEnabled()) {
    76         dispatch_async(dispatch_get_main_queue(), ^{
     77        RunLoop::main().dispatch([block = makeBlockPtr(block)] {
    7778            WebCoreWebThreadLock();
    7879            block();
     
    8182    }
    8283#endif
    83     dispatch_async(dispatch_get_main_queue(), block);
     84    RunLoop::main().dispatch([block = makeBlockPtr(block)] {
     85        block();
     86    });
    8487}
    8588
     
    9295    }
    9396#endif
    94     dispatch_async(dispatch_get_main_queue(), block);
     97    RunLoop::main().dispatch([block = makeBlockPtr(block)] {
     98        block();
     99    });
    95100}
    96101
  • trunk/Source/WebCore/ChangeLog

    r271488 r271493  
     12021-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
    1822021-01-14  Youenn Fablet  <youenn@apple.com>
    283
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r271416 r271493  
    31813181    // In case anything we do by performing the press action causes an alert or other modal
    31823182    // 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)] {
    31843184        [self _accessibilityPerformPressAction];
    31853185    });
     
    32003200- (void)accessibilityPerformIncrementAction
    32013201{
    3202     dispatch_async(dispatch_get_main_queue(), ^{
     3202    RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] {
    32033203        [self _accessibilityPerformIncrementAction];
    32043204    });
     
    32193219- (void)accessibilityPerformDecrementAction
    32203220{
    3221     dispatch_async(dispatch_get_main_queue(), ^{
     3221    RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] {
    32223222        [self _accessibilityPerformDecrementAction];
    32233223    });
  • trunk/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm

    r270663 r271493  
    3737#import <pal/avfoundation/MediaTimeAVFoundation.h>
    3838#import <syslog.h>
     39#import <wtf/RunLoop.h>
    3940#import <wtf/StringPrintStream.h>
    4041
     
    8889    OSStatus err = AudioConverterNew(&m_inputDescription->streamDescription(), &m_outputDescription->streamDescription(), &m_converter);
    8990    if (err) {
    90         dispatch_async(dispatch_get_main_queue(), [this, protectedThis = makeRefPtr(*this), err] {
     91        RunLoop::main().dispatch([this, protectedThis = makeRefPtr(*this), err] {
    9192            ERROR_LOG("AudioConverterNew returned error ", err);
    9293        });
     
    162163    if (m_inputSampleOffset == MediaTime::invalidTime()) {
    163164        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)] {
    165166            ALWAYS_LOG(logIdentifier, "input sample offset is ", inputSampleOffset, ", maximumSampleCount is ", maximumSampleCount);
    166167        });
     
    239240        m_outputSampleOffset = (endFrame - sampleCount) - timeStamp;
    240241        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)] {
    242243            ALWAYS_LOG(logIdentifier, "setting new offset to ", outputSampleOffset);
    243244        });
     
    247248
    248249    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)] {
    250251            ERROR_LOG(logIdentifier, "not enough data, sample ", timeStamp, " with offset ", outputSampleOffset, ", trying to get ", sampleCount, " samples, but not completely in range [", startFrame, " .. ", endFrame, "]");
    251252        });
     
    260261            // We are too close from endFrame, let's wait for more data to be pushed.
    261262            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)] {
    263264                ALWAYS_LOG(logIdentifier, "updating offset to ", outputSampleOffset);
    264265            });
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionHelperIOS.mm

    r270681 r271493  
    4040#import <wtf/MainThread.h>
    4141#import <wtf/RetainPtr.h>
     42#import <wtf/RunLoop.h>
    4243#import <wtf/UniqueRef.h>
    4344
     
    363364
    364365    // 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([] {
    366367        BEGIN_BLOCK_OBJC_EXCEPTIONS
    367368        [[PAL::getUIApplicationClass() sharedApplication] beginReceivingRemoteControlEvents];
     
    378379#if !PLATFORM(WATCHOS)
    379380    if (!pthread_main_np()) {
    380         dispatch_async(dispatch_get_main_queue(), [routeDetector = WTFMove(_routeDetector)] () mutable {
     381        RunLoop::main().dispatch([routeDetector = WTFMove(_routeDetector)] () mutable {
    381382            LOG(Media, "safelyTearDown - dipatched to UI thread.");
    382383            BEGIN_BLOCK_OBJC_EXCEPTIONS
  • trunk/Source/WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm

    r264006 r271493  
    138138}
    139139
    140 static inline void dispatchToMainThread(void (^block)())
    141 {
    142     dispatch_async(dispatch_get_main_queue(), ^{
    143 #if PLATFORM(IOS_FAMILY)
    144         WebThreadRun(block);
    145 #else
    146         block();
    147 #endif
    148     });
    149 }
    150 
    151140void ContentFilterUnblockHandler::requestUnblockAsync(DecisionHandlerFunction decisionHandler) const
    152141{
     
    154143    if (m_webFilterEvaluator) {
    155144        [m_webFilterEvaluator unblockWithCompletion:[decisionHandler](BOOL unblocked, NSError *) {
    156             dispatchToMainThread([decisionHandler, unblocked] {
     145            callOnMainThread([decisionHandler, unblocked] {
    157146                LOG(ContentFiltering, "WebFilterEvaluator %s the unblock request.\n", unblocked ? "allowed" : "did not allow");
    158147                decisionHandler(unblocked);
     
    165154    if (m_unblockRequester) {
    166155        m_unblockRequester([decisionHandler](bool unblocked) {
    167             dispatchToMainThread([decisionHandler, unblocked] {
     156            callOnMainThread([decisionHandler, unblocked] {
    168157                decisionHandler(unblocked);
    169158            });
  • trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm

    r265056 r271493  
    3030#import <notify.h>
    3131#import <pal/spi/cocoa/IOPSLibSPI.h>
     32#import <wtf/RunLoop.h>
    3233
    3334namespace WebCore {
     
    4647    // If the current value of systemHasAC() is uncached, force a notification.
    4748    if (!cachedSystemHasAC()) {
    48         dispatch_async(dispatch_get_main_queue(), [weakThis = makeWeakPtr(*this)] {
     49        RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] {
    4950            if (weakThis)
    5051                weakThis->notifyPowerSourceChanged();
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r271219 r271493  
    943943    RetainPtr<AVPlayer> strongPlayer = m_avPlayer.get();
    944944    RetainPtr<AVPlayerItem> strongItem = item;
    945     dispatch_async(dispatch_get_main_queue(), [strongPlayer, strongItem] {
     945    RunLoop::main().dispatch([strongPlayer, strongItem] {
    946946        [strongPlayer replaceCurrentItemWithPlayerItem:strongItem.get()];
    947947    });
  • trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm

    r271388 r271493  
    373373        ASSERT(sourcePlayerLayer);
    374374
    375         dispatch_async(dispatch_get_main_queue(), ^{
     375        RunLoop::main().dispatch([destinationPlayerLayer = retainPtr(destinationPlayerLayer), sourcePlayerLayer = retainPtr(sourcePlayerLayer)] {
    376376            [destinationPlayerLayer setPlayer:[sourcePlayerLayer player]];
    377377        });
     
    10911091void PlatformCALayer::setBoundsOnMainThread(CGRect bounds)
    10921092{
    1093     CALayer *layer = m_layer.get();
    1094     dispatch_async(dispatch_get_main_queue(), ^{
     1093    RunLoop::main().dispatch([layer = m_layer, bounds] {
    10951094        BEGIN_BLOCK_OBJC_EXCEPTIONS
    10961095        [layer setBounds:bounds];
     
    11011100void PlatformCALayer::setPositionOnMainThread(CGPoint position)
    11021101{
    1103     CALayer *layer = m_layer.get();
    1104     dispatch_async(dispatch_get_main_queue(), ^{
     1102    RunLoop::main().dispatch([layer = m_layer, position] {
    11051103        BEGIN_BLOCK_OBJC_EXCEPTIONS
    11061104        [layer setPosition:position];
     
    11111109void PlatformCALayer::setAnchorPointOnMainThread(FloatPoint3D value)
    11121110{
    1113     CALayer *layer = m_layer.get();
    1114     dispatch_async(dispatch_get_main_queue(), ^{
     1111    RunLoop::main().dispatch([layer = m_layer, value] {
    11151112        BEGIN_BLOCK_OBJC_EXCEPTIONS
    11161113        [layer setAnchorPoint:CGPointMake(value.x(), value.y())];
  • trunk/Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.mm

    r264839 r271493  
    102102
    103103    RefPtr<WebCoreDecompressionSession> protectedThis { this };
    104     dispatch_async(dispatch_get_main_queue(), [protectedThis] {
     104    RunLoop::main().dispatch([protectedThis] {
    105105        if (protectedThis->m_notificationCallback)
    106106            protectedThis->m_notificationCallback();
     
    420420        return;
    421421
    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)] {
    423423        callback();
    424424    });
     
    438438    if (notificationCallback && isReadyForMoreMediaData()) {
    439439        RefPtr<WebCoreDecompressionSession> protectedThis { this };
    440         dispatch_async(dispatch_get_main_queue(), [protectedThis] {
     440        RunLoop::main().dispatch([protectedThis] {
    441441            if (protectedThis->m_notificationCallback)
    442442                protectedThis->m_notificationCallback();
     
    454454{
    455455    if (callback && m_producerQueue && !CMBufferQueueIsEmpty(m_producerQueue.get())) {
    456         dispatch_async(dispatch_get_main_queue(), [callback] {
     456        RunLoop::main().dispatch([callback] {
    457457            callback();
    458458        });
  • trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm

    r271387 r271493  
    318318
    319319    NSTimeInterval animationDuration = [CATransaction animationDuration];
    320     dispatch_async(dispatch_get_main_queue(), ^{
     320    RunLoop::main().dispatch([self, strongSelf = retainPtr(self), targetVideoFrame, animationDuration] {
    321321        [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
    322322
     
    14201420void VideoFullscreenInterfaceAVKit::finalizeSetup()
    14211421{
    1422     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
     1422    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] {
    14231423        if (m_fullscreenChangeObserver) {
    14241424            if (!m_hasVideoContentLayer && m_targetMode.hasVideo()) {
     
    15401540    m_standby = false;
    15411541
    1542     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
     1542    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] {
    15431543        if (m_fullscreenChangeObserver)
    15441544            m_fullscreenChangeObserver->didExitFullscreen();
  • trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm

    r237266 r271493  
    6262void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
    6363{
    64     dispatch_async(dispatch_get_main_queue(), [this] {
     64    RunLoop::main().dispatch([this] {
    6565        m_hysteresis.start();
    6666    });
     
    6969void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
    7070{
    71     dispatch_async(dispatch_get_main_queue(), [this] {
     71    RunLoop::main().dispatch([this] {
    7272        m_hysteresis.stop();
    7373    });
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm

    r269557 r271493  
    243243    WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable {
    244244        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] {
    246246            m_interface->setInlineRect(clientRect, clientRect != IntRect(0, 0, 0, 0));
    247247        });
     
    259259        [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)];
    260260        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] {
    262262                if (!m_interface)
    263263                    return;
     
    279279        [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)];
    280280        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] {
    282282                if (!m_interface)
    283283                    return;
     
    296296    ASSERT(isUIThread());
    297297#if PLATFORM(IOS_FAMILY)
    298     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
     298    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] {
    299299        m_interface->enterFullscreen();
    300300    });
     
    303303        [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparentBlack)];
    304304        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] {
    306306                m_interface->enterFullscreen();
    307307            });
     
    325325    ASSERT(isUIThread());
    326326#if PLATFORM(IOS_FAMILY)
    327     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
     327    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] {
    328328        m_interface->cleanupFullscreen();
    329329    });
     
    331331    WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable {
    332332        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] {
    334334                m_interface->cleanupFullscreen();
    335335            });
     
    365365    WebThreadRun([protectedThis = makeRefPtr(this), this] () mutable {
    366366        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] {
    368368            m_interface->preparedToReturnToInline(true, clientRect);
    369369        });
     
    376376{
    377377    if (WebThreadIsCurrent()) {
    378         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), duration] {
     378        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), duration] {
    379379            protectedThis->durationChanged(duration);
    380380        });
     
    389389{
    390390    if (WebThreadIsCurrent()) {
    391         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), currentTime, anchorTime] {
     391        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), currentTime, anchorTime] {
    392392            protectedThis->currentTimeChanged(currentTime, anchorTime);
    393393        });
     
    402402{
    403403    if (WebThreadIsCurrent()) {
    404         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), bufferedTime] {
     404        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), bufferedTime] {
    405405            protectedThis->bufferedTimeChanged(bufferedTime);
    406406        });
     
    415415{
    416416    if (WebThreadIsCurrent()) {
    417         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), isPlaying, playbackRate] {
     417        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), isPlaying, playbackRate] {
    418418            protectedThis->rateChanged(isPlaying, playbackRate);
    419419        });
     
    428428{
    429429    if (WebThreadIsCurrent()) {
    430         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), hasVideo] {
     430        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), hasVideo] {
    431431            protectedThis->hasVideoChanged(hasVideo);
    432432        });
     
    441441{
    442442    if (WebThreadIsCurrent()) {
    443         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), videoDimensions = videoDimensions] {
     443        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoDimensions = videoDimensions] {
    444444            protectedThis->videoDimensionsChanged(videoDimensions);
    445445        });
     
    454454{
    455455    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] {
    457457            protectedThis->seekableRangesChanged(TimeRanges::create(platformTimeRanges), lastModifiedTime, liveUpdateInterval);
    458458        });
     
    467467{
    468468    if (WebThreadIsCurrent()) {
    469         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), canPlayFastReverse] {
     469        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), canPlayFastReverse] {
    470470            protectedThis->canPlayFastReverseChanged(canPlayFastReverse);
    471471        });
     
    489489{
    490490    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] {
    492492            protectedThis->audioMediaSelectionOptionsChanged(options, selectedIndex);
    493493        });
     
    502502{
    503503    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] {
    505505            protectedThis->legibleMediaSelectionOptionsChanged(options, selectedIndex);
    506506        });
     
    529529{
    530530    if (WebThreadIsCurrent()) {
    531         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), disabled] {
     531        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), disabled] {
    532532            protectedThis->wirelessVideoPlaybackDisabledChanged(disabled);
    533533        });
     
    542542{
    543543    if (WebThreadIsCurrent()) {
    544         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), muted] {
     544        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), muted] {
    545545            protectedThis->mutedChanged(muted);
    546546        });
     
    555555{
    556556    if (WebThreadIsCurrent()) {
    557         dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), volume] {
     557        RunLoop::main().dispatch([protectedThis = makeRefPtr(this), volume] {
    558558            protectedThis->volumeChanged(volume);
    559559        });
     
    984984    FloatSize videoDimensions = { (float)videoElement.videoWidth(), (float)videoElement.videoHeight() };
    985985
    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] {
    987987        ASSERT(isUIThread());
    988988        WebThreadLock();
     
    10031003    ASSERT(WebThreadIsCurrent() || isMainThread());
    10041004    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] {
    10061006        ASSERT(isUIThread());
    10071007        m_interface->exitFullscreen(clientRect);
  • trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm

    r269658 r271493  
    290290    // We own obj at this point, so we don't need the block to implicitly
    291291    // 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];
    295294    });
    296295}
     
    438437        [[NSNotificationCenter defaultCenter] postNotificationName:name object:object userInfo:userInfo];
    439438    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()];
    442441        });
    443442    }
  • trunk/Source/WebCore/platform/mac/VideoFullscreenInterfaceMac.mm

    r270069 r271493  
    457457    [videoFullscreenInterfaceObjC() setUpPIPForVideoView:&layerHostedView withFrame:(NSRect)initialRect inWindow:parentWindow];
    458458
    459     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), this] {
     459    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), this] {
    460460        if (m_fullscreenChangeObserver)
    461461            m_fullscreenChangeObserver->didSetupFullscreen();
  • trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm

    r247489 r271493  
    261261        return;
    262262
    263     dispatch_async(dispatch_get_main_queue(), ^{
     263    RunLoop::main().dispatch([self, protectedSelf = retainPtr(self)] {
    264264        if (m_callback)
    265265            m_callback->refreshCaptureDevices();
  • trunk/Source/WebKit/ChangeLog

    r271486 r271493  
     12021-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
    1892021-01-14  Youenn Fablet  <youenn@apple.com>
    290
  • trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm

    r263426 r271493  
    136136            LOG_ERROR("PKCanMakePaymentsWithMerchantIdentifierAndDomain error %@", error);
    137137
    138         dispatch_async(dispatch_get_main_queue(), ^{
     138        RunLoop::main().dispatch([self, protectedSelf = retainPtr(self), merchantURL = retainPtr(merchantURL)] {
    139139            ASSERT(_didRequestMerchantSessionCompletion);
    140140
     
    145145            }
    146146
    147             presenter->client().presenterWillValidateMerchant(*presenter, merchantURL);
     147            presenter->client().presenterWillValidateMerchant(*presenter, merchantURL.get());
    148148        });
    149149    }];
  • trunk/Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.mm

    r271283 r271493  
    136136        g_currentITPState = determineITPStateInternal(appWasLinkedOnOrAfter, bundleIdentifier) ? ITPState::Enabled : ITPState::Disabled;
    137137
    138         dispatch_async(dispatch_get_main_queue(), ^{
     138        RunLoop::main().dispatch([] {
    139139            dispatch_release(g_itpQueue);
    140140            g_itpQueue = nullptr;
  • trunk/Source/WebKit/UIProcess/API/C/mac/WKContextPrivateMac.mm

    r269785 r271493  
    4141#import <WebCore/PluginBlocklist.h>
    4242#import <WebCore/WebGLBlocklist.h>
     43#import <wtf/BlockPtr.h>
    4344#import <wtf/RetainPtr.h>
    4445
     
    8485
    8586    WebKit::toImpl(contextRef)->ref();
    86     dispatch_async(dispatch_get_main_queue(), ^() {
     87    RunLoop::main().dispatch([block = makeBlockPtr(block), array = WTFMove(array), contextRef] {
    8788        block(WebKit::toAPI(array.get()), 0);
    8889   
  • trunk/Source/WebKit/UIProcess/API/Cocoa/NSAttributedString.mm

    r261407 r271493  
    336336        runConversion();
    337337    else
    338         dispatch_async(dispatch_get_main_queue(), runConversion);
     338        RunLoop::main().dispatch([runConversion = makeBlockPtr(runConversion)] {
     339            runConversion();
     340        });
    339341}
    340342
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm

    r268401 r271493  
    106106        WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
    107107    else {
    108         dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {
     108        RunLoop::main().dispatch([scheme = retainPtr(scheme)] {
    109109            WebKit::WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get());
    110         }).get());
     110        });
    111111    }
    112112}
     
    117117        WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
    118118    else {
    119         dispatch_async(dispatch_get_main_queue(), makeBlockPtr([scheme = retainPtr(scheme)] {
     119        RunLoop::main().dispatch([scheme = retainPtr(scheme)] {
    120120            WebKit::WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme.get());
    121         }).get());
     121        });
    122122    }
    123123}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r271424 r271493  
    10311031
    10321032        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] {
    10341034            auto rawHandler = (void (^)(id, NSError *))handler.get();
    10351035            rawHandler(nil, error.get());
     
    13461346#if PLATFORM(IOS_FAMILY)
    13471347    if (![self usesStandardContentView]) {
    1348         dispatch_async(dispatch_get_main_queue(), updateBlock);
     1348        RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] {
     1349            updateBlock();
     1350        });
    13491351        return;
    13501352    }
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm

    r270669 r271493  
    115115    [self _scheduleVisibleContentRectUpdate];
    116116#else
    117     dispatch_async(dispatch_get_main_queue(), updateBlock);
     117    RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] {
     118        updateBlock();
     119    });
    118120#endif
    119121}
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r271000 r271493  
    19421942    }
    19431943
    1944     dispatch_async(dispatch_get_main_queue(), [retainedSelf = retainPtr(self)] {
     1944    RunLoop::main().dispatch([retainedSelf = retainPtr(self)] {
    19451945        WKWebView *webView = retainedSelf.get();
    19461946        if (![webView _isValid])
     
    20802080            if (!CGPointEqualToPoint(activePoint, currentPoint)) {
    20812081                RetainPtr<WKScrollView> strongScrollView = _scrollView;
    2082                 dispatch_async(dispatch_get_main_queue(), [strongScrollView, activePoint] {
     2082                RunLoop::main().dispatch([strongScrollView, activePoint] {
    20832083                    [strongScrollView setContentOffset:activePoint animated:NO];
    20842084                });
     
    24392439    RetainPtr<WKWebView> strongSelf = self;
    24402440    [self _doAfterNextPresentationUpdate:[strongSelf] {
    2441         dispatch_async(dispatch_get_main_queue(), [strongSelf] {
     2441        RunLoop::main().dispatch([strongSelf] {
    24422442            if ([strongSelf->_stableStatePresentationUpdateCallbacks count])
    24432443                [strongSelf _firePresentationUpdateForPendingStableStatePresentationCallbacks];
     
    27202720{
    27212721    if (![self usesStandardContentView]) {
    2722         dispatch_async(dispatch_get_main_queue(), updateBlock);
     2722        RunLoop::main().dispatch([updateBlock = makeBlockPtr(updateBlock)] {
     2723            updateBlock();
     2724        });
    27232725        return;
    27242726    }
  • trunk/Source/WebKit/UIProcess/Cocoa/AutomationClient.mm

    r242339 r271493  
    8686    // deadlock because it's already taken while handling XPC messages.
    8787    NSString *requestedSessionIdentifier = sessionIdentifier;
    88     dispatch_async(dispatch_get_main_queue(), ^{
     88    RunLoop::main().dispatch([this, requestedSessionIdentifier = retainPtr(requestedSessionIdentifier), configuration = retainPtr(configuration)] {
    8989        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()];
    9191    });
    9292}
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r271264 r271493  
    452452        });
    453453        [LSAppLink openWithURL:url completionHandler:[localCompletionHandler](BOOL success, NSError *) {
    454             dispatch_async(dispatch_get_main_queue(), [localCompletionHandler, success] {
     454            RunLoop::main().dispatch([localCompletionHandler, success] {
    455455                (*localCompletionHandler)(success);
    456456                delete localCompletionHandler;
  • trunk/Source/WebKit/UIProcess/Cocoa/PreferenceObserver.mm

    r268421 r271493  
    180180{
    181181#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)] {
    183183        Optional<String> encodedString;
    184184        if (encodedValue)
    185             encodedString = String(encodedValue);
     185            encodedString = String(encodedValue.get());
    186186
    187187        for (auto* processPool : WebKit::WebProcessPool::allProcessPools())
    188             processPool->notifyPreferencesChanged(domain, key, encodedString);
     188            processPool->notifyPreferencesChanged(domain.get(), key.get(), encodedString);
    189189    });
    190190#endif
  • trunk/Source/WebKit/UIProcess/Cocoa/WebInspectorPreferenceObserver.mm

    r270035 r271493  
    6868- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
    6969{
    70     dispatch_async(dispatch_get_main_queue(), ^{
     70    RunLoop::main().dispatch([] {
    7171        for (auto* pool : WebKit::WebProcessPool::allProcessPools()) {
    7272            for (size_t i = 0; i < pool->processes().size(); ++i) {
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r271479 r271493  
    457457{
    458458    [operation setCompletionBlock:^{
    459         dispatch_async(dispatch_get_main_queue(), ^{
     459        RunLoop::main().dispatch([this, operation = retainPtr(operation)] {
    460460            auto identifier = [operation identifier];
    461461            auto convertedImage = convertPlatformImageToBitmap([operation thumbnail], WebCore::IntSize(400, 400));
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r271448 r271493  
    890890static void webProcessPoolHighDynamicRangeDidChangeCallback(CMNotificationCenterRef, const void*, CFStringRef notificationName, const void*, CFTypeRef)
    891891{
    892     dispatch_async(dispatch_get_main_queue(), ^{
     892    RunLoop::main().dispatch([] {
    893893        auto properties = WebCore::collectScreenProperties();
    894894        for (auto& pool : WebProcessPool::allProcessPools())
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r271459 r271493  
    930930- (void)menuDidClose:(NSMenu *)menu
    931931{
    932     dispatch_async(dispatch_get_main_queue(), [impl = _impl] {
     932    RunLoop::main().dispatch([impl = _impl] {
    933933        if (impl)
    934934            impl->handleDOMPasteRequestWithResult(WebCore::DOMPasteAccessResponse::DeniedForGesture);
     
    18101810    m_didScheduleWindowAndViewFrameUpdate = true;
    18111811
    1812     auto weakThis = makeWeakPtr(*this);
    1813     dispatch_async(dispatch_get_main_queue(), [weakThis] {
     1812    RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] {
    18141813        if (!weakThis)
    18151814            return;
     
    19371936    m_didScheduleSetTopContentInset = true;
    19381937
    1939     auto weakThis = makeWeakPtr(*this);
    1940     dispatch_async(dispatch_get_main_queue(), [weakThis] {
     1938    RunLoop::main().dispatch([weakThis = makeWeakPtr(*this)] {
    19411939        if (!weakThis)
    19421940            return;
     
    29412939    [m_windowVisibilityObserver startObservingFontPanel];
    29422940
    2943     dispatch_async(dispatch_get_main_queue(), [] {
     2941    RunLoop::main().dispatch([] {
    29442942        [[NSSpellChecker sharedSpellChecker] _preflightChosenSpellServer];
    29452943    });
     
    33843382    auto weakThis = makeWeakPtr(*this);
    33853383    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)] {
    33873385            if (!weakThis)
    33883386                return;
    3389             weakThis->handleRequestedCandidates(sequenceNumber, candidates);
     3387            weakThis->handleRequestedCandidates(sequenceNumber, candidates.get());
    33903388        });
    33913389    }];
     
    41304128                    return;
    41314129
    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] {
    41334131                    fileNames->append(path.get());
    41344132                    if (fileNames->size() == fileCount) {
  • trunk/Source/WebKit/UIProcess/EndowmentStateTracker.mm

    r265222 r271493  
    3232#import "RunningBoardServicesSPI.h"
    3333#include <wtf/NeverDestroyed.h>
     34#include <wtf/RunLoop.h>
    3435
    3536namespace WebKit {
     
    105106
    106107        [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 {
    108109                setState(WTFMove(state));
    109110            });
  • trunk/Source/WebKit/UIProcess/_WKTouchEventGenerator.mm

    r258478 r271493  
    3434#import <wtf/Assertions.h>
    3535#import <wtf/RetainPtr.h>
     36#import <wtf/RunLoop.h>
    3637#import <wtf/SoftLinking.h>
    3738
     
    213214
    214215    if (eventRef) {
    215         RetainPtr<IOHIDEventRef> strongEvent = eventRef;
    216         dispatch_async(dispatch_get_main_queue(), ^{
     216        RunLoop::main().dispatch([strongEvent = retainPtr(eventRef)] {
    217217ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    218218            uint32_t contextID = [UIApplication sharedApplication].keyWindow._contextId;
     
    241241   
    242242    if (markerEvent) {
    243         dispatch_async(dispatch_get_main_queue(), [markerEvent = WTFMove(markerEvent)] {
     243        RunLoop::main().dispatch([markerEvent = WTFMove(markerEvent)] {
    244244ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    245245            auto contextID = [UIApplication sharedApplication].keyWindow._contextId;
  • trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r269256 r271493  
    183183        // Release the background task asynchronously because releasing the background task may destroy the ProcessThrottler and we don't
    184184        // 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)] {
    186186            if (_assertionsNeedingBackgroundTask.computesEmpty())
    187187                [self _releaseBackgroundTask];
     
    224224    if (remainingTime == RBSProcessTimeLimitationNone) {
    225225        [self _releaseBackgroundTask];
    226         dispatch_async(dispatch_get_main_queue(), ^{
     226        RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    227227            [self _updateBackgroundTask];
    228228        });
     
    272272    RELEASE_LOG(ProcessSuspension, "%p - WKRBSAssertionDelegate: assertion was invalidated, error: %{public}@", error, self);
    273273
    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();
    279278    });
    280279}
     
    303302    , m_pid(pid)
    304303{
    305     auto weakThis = makeWeakPtr(*this);
    306304    NSString *runningBoardAssertionName = runningBoardNameForAssertionType(assertionType);
    307305    ASSERT(runningBoardAssertionName);
     
    325323    if (![m_rbsAssertion acquireWithError:&acquisitionError]) {
    326324        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)] {
    328326            if (weakThis)
    329                 processAssertionWasInvalidated();
     327                weakThis->processAssertionWasInvalidated();
    330328        });
    331329    } else
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r271445 r271493  
    14511451
    14521452        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)] {
    14541454                auto strongSelf = weakSelf.get();
    14551455                if (!strongSelf || [strongSelf isFirstResponder])
  • trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm

    r269869 r271493  
    510510{
    511511    // 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] {
    513513        if (auto page = [webView _page])
    514514            page->dispatchProcessDidTerminate(WebKit::ProcessTerminationReason::Crash);
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm

    r269869 r271493  
    684684            ASSERT([processedResults count] == 1);
    685685            _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()];
    688688            });
    689689        }
    690690        failureBlock:^{
    691             dispatch_async(dispatch_get_main_queue(), ^{
     691            RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    692692                [self _cancel];
    693693            });
     
    713713            }
    714714
    715             dispatch_async(dispatch_get_main_queue(), ^{
    716                 [self _chooseFiles:fileURLs displayString:displayString iconImage: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()];
    717717            });
    718718        }
    719719        failureBlock:^{
    720             dispatch_async(dispatch_get_main_queue(), ^{
     720            RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    721721                [self _cancel];
    722722            });
  • trunk/Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm

    r271171 r271493  
    880880        return;
    881881
    882     dispatch_async(dispatch_get_main_queue(), ^{
     882    RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    883883        if ([_webViewPlaceholder superview] == nil && [_webViewPlaceholder parent] == self)
    884884            [self close];
  • trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm

    r263323 r271493  
    113113            AVPlayerLayer *destinationPlayerLayer = static_cast<AVPlayerLayer *>(clonedLayer.get());
    114114            AVPlayerLayer *sourcePlayerLayer = static_cast<AVPlayerLayer *>(platformLayer());
    115             dispatch_async(dispatch_get_main_queue(), [destinationPlayerLayer, sourcePlayerLayer] {
     115            RunLoop::main().dispatch([destinationPlayerLayer, sourcePlayerLayer] {
    116116                [destinationPlayerLayer setPlayer:[sourcePlayerLayer player]];
    117117            });
  • trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm

    r271171 r271493  
    417417
    418418        MonotonicTime timestamp = MonotonicTime::now();
    419         dispatch_async(dispatch_get_main_queue(), [pageID, timestamp] {
     419        RunLoop::main().dispatch([pageID, timestamp] {
    420420            if (WebPage* webPage = WebProcess::singleton().webPage(pageID))
    421421                webPage->didFlushLayerTreeAtTime(timestamp);
  • trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm

    r271325 r271493  
    386386
    387387    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] {
    389389            if (protectedThis->m_page)
    390390                m_page->send(Messages::VideoFullscreenManagerProxy::SetHasVideoContentLayer(contextId, true));
     
    400400
    401401    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 {
    403403            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] {
    405405                    if (protectedThis->m_page)
    406406                        m_page->send(Messages::VideoFullscreenManagerProxy::SetHasVideoContentLayer(contextId, false));
     
    421421
    422422    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] {
    424424            if (protectedThis->m_page)
    425425                m_page->send(Messages::VideoFullscreenManagerProxy::EnterFullscreen(contextId));
     
    439439        return;
    440440
    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] {
    442442        videoElement->willExitFullscreen();
    443443        if (protectedThis->m_page)
     
    465465
    466466    // 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] {
    468468        if (protectedThis->m_page)
    469469            protectedThis->exitVideoFullscreenForVideoElement(*videoElement, [](bool) { });
     
    480480
    481481#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] {
    483483        if (protectedThis->m_page)
    484484            protectedThis->m_page->send(Messages::VideoFullscreenManagerProxy::CleanupFullscreen(contextId));
     
    486486#else
    487487    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 {
    489489            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] {
    491491                    if (interface->layerHostingContext()) {
    492492                        interface->layerHostingContext()->setRootLayer(nullptr);
     
    531531        return;
    532532
    533     dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), videoElement, mode, standby] {
     533    RunLoop::main().dispatch([protectedThis = makeRefPtr(this), videoElement, mode, standby] {
    534534        if (protectedThis->m_page)
    535535            protectedThis->enterVideoFullscreenForVideoElement(*videoElement, mode, standby);
  • trunk/Source/WebKitLegacy/ios/ChangeLog

    r269545 r271493  
     12021-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
    1272020-11-06  Sam Weinig  <weinig@apple.com>
    228
  • trunk/Source/WebKitLegacy/ios/Misc/WebGeolocationProviderIOS.mm

    r249066 r271493  
    3838#import <wtf/HashMap.h>
    3939#import <wtf/RetainPtr.h>
     40#import <wtf/RunLoop.h>
    4041#import <wtf/Vector.h>
    4142
     
    179180
    180181    if (!_isSuspended) {
    181         dispatch_async(dispatch_get_main_queue(), ^{
     182        RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    182183            if (!_coreLocationProvider) {
    183184                ASSERT(!_coreLocationUpdateListenerProxy);
     
    209210
    210211    if (_registeredWebViews.isEmpty()) {
    211         dispatch_async(dispatch_get_main_queue(), ^{
     212        RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    212213            [_coreLocationProvider stop];
    213214        });
     
    227228    ASSERT(WebThreadIsLockedOrDisabled());
    228229    _enableHighAccuracy = _enableHighAccuracy || enableHighAccuracy;
    229     dispatch_async(dispatch_get_main_queue(), ^{
     230    RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    230231        [_coreLocationProvider setEnableHighAccuracy:_enableHighAccuracy];
    231232    });
     
    242243    _trackedWebViews.add(webView);
    243244
    244     dispatch_async(dispatch_get_main_queue(), ^{
     245    RunLoop::main().dispatch([self, strongSelf = retainPtr(self)] {
    245246        if (!_coreLocationProvider) {
    246247            ASSERT(!_coreLocationUpdateListenerProxy);
  • trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebChromeClientIOS.mm

    r259843 r271493  
    147147
    148148    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()];
    151151        });
    152152    } else
  • trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebInspectorClientIOS.mm

    r257835 r271493  
    105105void WebInspectorClient::didSetSearchingForNode(bool enabled)
    106106{
    107     WebInspector *inspector = [m_inspectedWebView inspector];
    108107    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()];
    111110    });
    112111}
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r271456 r271493  
     12021-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
    1302021-01-13  Alex Christensen  <achristensen@webkit.org>
    231
  • trunk/Source/WebKitLegacy/mac/Plugins/npapi.mm

    r234685 r271493  
    3232#import "WebNetscapePluginView.h"
    3333#import "WebKitLogging.h"
     34#import <wtf/RunLoop.h>
    3435
    3536using namespace WebCore;
     
    175176    WebNetscapePluginView *pluginView = pluginViewForInstance(instance);
    176177
    177     dispatch_async(dispatch_get_main_queue(), ^{
     178    RunLoop::main().dispatch([pluginView = retainPtr(pluginView), userData, func] {
    178179        if (!pluginView || !pluginView->plugin) {
    179180            // The plug-in has already been destroyed.
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm

    r267938 r271493  
    11231123    auto weakEditor = makeWeakPtr(*this);
    11241124    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)] {
    11261126            if (!weakEditor)
    11271127                return;
    1128             weakEditor->handleRequestedCandidates(sequenceNumber, candidates);
     1128            weakEditor->handleRequestedCandidates(sequenceNumber, candidates.get());
    11291129        });
    11301130    }];
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm

    r271378 r271493  
    23732373            WebThreadRun(^{
    23742374#else
    2375             dispatch_async(dispatch_get_main_queue(), ^{
     2375            RunLoop::main().dispatch([self, strongSelf = retainPtr(self), success] {
    23762376#endif
    23772377                if (success)
  • trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm

    r268813 r271493  
    200200    if (![_immediateActionRecognizer animationController]) {
    201201        // 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)] {
    203203            [self _cancelImmediateAction];
    204204        });
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r271456 r271493  
    245245#import <pal/spi/mac/NSWindowSPI.h>
    246246#import <wtf/Assertions.h>
     247#import <wtf/BlockPtr.h>
    247248#import <wtf/FileSystem.h>
    248249#import <wtf/HashTraits.h>
     
    18921893    WebThreadRun(^{
    18931894        [WebView _releaseMemoryNow];
    1894         dispatch_async(dispatch_get_main_queue(), handler);
     1895        RunLoop::main().dispatch([handler = makeBlockPtr(handler)] {
     1896            handler();
     1897        });
    18951898    });
    18961899}
     
    50255028- (void)forwardInvocation:(NSInvocation *)invocation
    50265029{
    5027     // Store _forwarder in an ivar so it is retained by the block.
    5028     _WebSafeForwarder *forwarder = _forwarder;
    50295030    if (WebThreadIsCurrent()) {
    50305031        [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()];
    50335034        });
    50345035    } else
    5035         [forwarder forwardInvocation:invocation];
     5036        [_forwarder forwardInvocation:invocation];
    50365037}
    50375038
     
    64506451                    return;
    64516452
    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] {
    64536454                    fileNames->append(path.get());
    64546455                    if (fileNames->size() == fileCount) {
     
    79787979#if PLATFORM(MAC)
    79797980        if (flag) {
    7980             dispatch_async(dispatch_get_main_queue(), [] {
     7981            RunLoop::main().dispatch([] {
    79817982                [[NSSpellChecker sharedSpellChecker] _preflightChosenSpellServer];
    79827983            });
Note: See TracChangeset for help on using the changeset viewer.