Changeset 272628 in webkit


Ignore:
Timestamp:
Feb 9, 2021, 5:29:32 PM (4 years ago)
Author:
achristensen@apple.com
Message:

Use CompletionHandler instead of ImageCallback
https://bugs.webkit.org/show_bug.cgi?id=221626

Reviewed by Chris Dumez.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):

  • UIProcess/API/Cocoa/_WKThumbnailView.mm:

(-[_WKThumbnailView requestSnapshot]):

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):

  • UIProcess/GenericCallback.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::drawRectToImage):
(WebKit::WebPageProxy::takeSnapshot):
(WebKit::WebPageProxy::imageCallback): Deleted.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/mac/WKPrintingView.mm:

(-[WKPrintingView _drawPreview:]):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::takeSnapshot):
(WebKit::WebPage::drawRectToImage):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
Location:
trunk/Source/WebKit
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r272627 r272628  
     12021-02-09  Alex Christensen  <achristensen@webkit.org>
     2
     3        Use CompletionHandler instead of ImageCallback
     4        https://bugs.webkit.org/show_bug.cgi?id=221626
     5
     6        Reviewed by Chris Dumez.
     7
     8        * UIProcess/API/Cocoa/WKWebView.mm:
     9        (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
     10        * UIProcess/API/Cocoa/_WKThumbnailView.mm:
     11        (-[_WKThumbnailView requestSnapshot]):
     12        * UIProcess/API/ios/WKWebViewIOS.mm:
     13        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
     14        * UIProcess/GenericCallback.h:
     15        * UIProcess/WebPageProxy.cpp:
     16        (WebKit::WebPageProxy::drawRectToImage):
     17        (WebKit::WebPageProxy::takeSnapshot):
     18        (WebKit::WebPageProxy::imageCallback): Deleted.
     19        * UIProcess/WebPageProxy.h:
     20        * UIProcess/WebPageProxy.messages.in:
     21        * UIProcess/mac/WKPrintingView.mm:
     22        (-[WKPrintingView _drawPreview:]):
     23        * WebProcess/WebPage/WebPage.cpp:
     24        (WebKit::WebPage::takeSnapshot):
     25        (WebKit::WebPage::drawRectToImage):
     26        * WebProcess/WebPage/WebPage.h:
     27        * WebProcess/WebPage/WebPage.messages.in:
     28
    1292021-02-09  Alex Christensen  <achristensen@webkit.org>
    230
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r272592 r272628  
    841841}
    842842
    843 #if USE(APPKIT)
    844 static WKErrorCode callbackErrorCode(WebKit::CallbackBase::Error error)
    845 {
    846     switch (error) {
    847     case WebKit::CallbackBase::Error::None:
    848         ASSERT_NOT_REACHED();
    849         return WKErrorUnknown;
    850 
    851     case WebKit::CallbackBase::Error::Unknown:
    852         return WKErrorUnknown;
    853 
    854     case WebKit::CallbackBase::Error::ProcessExited:
    855         return WKErrorWebContentProcessTerminated;
    856 
    857     case WebKit::CallbackBase::Error::OwnerWasInvalidated:
    858         return WKErrorWebViewInvalidated;
    859     }
    860 }
    861 #endif
    862 
    863843- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
    864844{
     
    10951075    // contains recent updates. If we ever have a UI-side snapshot mechanism on macOS, we will need to factor
    10961076    // in snapshotConfiguration.afterScreenUpdates at that time.
    1097     _page->takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error errorCode) {
    1098         if (errorCode != WebKit::CallbackBase::Error::None) {
    1099             auto error = createNSError(callbackErrorCode(errorCode));
    1100             handler(nil, error.get());
    1101             return;
    1102         }
    1103 
     1077    _page->takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle& imageHandle) {
    11041078        auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
    11051079        RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKThumbnailView.mm

    r270069 r272628  
    142142    _lastSnapshotScale = _scale;
    143143    _lastSnapshotMaximumSize = _maximumSnapshotSize;
    144     _webPageProxy->takeSnapshot(snapshotRect, bitmapSize, options, [thumbnailView](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
     144    _webPageProxy->takeSnapshot(snapshotRect, bitmapSize, options, [thumbnailView](const WebKit::ShareableBitmap::Handle& imageHandle) {
    145145        auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
    146146        RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r272322 r272628  
    30893089    }
    30903090
    3091     void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
    3092     _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
    3093         if (imageHandle.isNull()) {
    3094             copiedCompletionHandler(nullptr);
    3095             [copiedCompletionHandler release];
    3096             return;
    3097         }
     3091    _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [completionHandler = makeBlockPtr(completionHandler)](const WebKit::ShareableBitmap::Handle& imageHandle) {
     3092        if (imageHandle.isNull())
     3093            return completionHandler(nil);
    30983094
    30993095        auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
    31003096
    3101         if (!bitmap) {
    3102             copiedCompletionHandler(nullptr);
    3103             [copiedCompletionHandler release];
    3104             return;
    3105         }
    3106 
    3107         RetainPtr<CGImageRef> cgImage;
    3108         cgImage = bitmap->makeCGImage();
    3109         copiedCompletionHandler(cgImage.get());
    3110         [copiedCompletionHandler release];
     3097        if (!bitmap)
     3098            return completionHandler(nil);
     3099
     3100        completionHandler(bitmap->makeCGImage().get());
    31113101    });
    31123102}
  • trunk/Source/WebKit/UIProcess/GenericCallback.h

    r272606 r272628  
    156156
    157157typedef GenericCallback<> VoidCallback;
    158 typedef GenericCallback<const ShareableBitmap::Handle&> ImageCallback;
    159158
    160159template<typename T>
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r272627 r272628  
    71177117}
    71187118
    7119 void WebPageProxy::imageCallback(const ShareableBitmap::Handle& bitmapHandle, CallbackID callbackID)
    7120 {
    7121     auto callback = m_callbacks.take<ImageCallback>(callbackID);
    7122     if (!callback) {
    7123         // FIXME: Log error or assert.
    7124         return;
    7125     }
    7126 
    7127     callback->performCallbackWithReturnValue(bitmapHandle);
    7128 }
    7129 
    71307119void WebPageProxy::stringCallback(const String& resultString, CallbackID callbackID)
    71317120{
     
    85248513
    85258514#if PLATFORM(COCOA)
    8526 void WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, Ref<ImageCallback>&& callback)
    8527 {
    8528     if (!hasRunningProcess()) {
    8529         callback->invalidate();
    8530         return;
    8531     }
    8532    
    8533     auto callbackID = callback->callbackID();
    8534     m_callbacks.put(WTFMove(callback));
    8535     send(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize, callbackID), printingSendOptions(m_isPerformingDOMPrintOperation));
     8515uint64_t WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& callback)
     8516{
     8517    return sendWithAsyncReply(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize), WTFMove(callback), printingSendOptions(m_isPerformingDOMPrintOperation));
    85368518}
    85378519
     
    89818963#endif
    89828964
    8983 void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOptions options, WTF::Function<void (const ShareableBitmap::Handle&, CallbackBase::Error)>&& callbackFunction)
    8984 {
    8985     if (!hasRunningProcess()) {
    8986         callbackFunction(ShareableBitmap::Handle(), CallbackBase::Error::Unknown);
    8987         return;
    8988     }
    8989 
    8990     auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::takeSnapshot"_s));
    8991     send(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options, callbackID));
     8965void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOptions options, CompletionHandler<void(const ShareableBitmap::Handle&)>&& callback)
     8966{
     8967    sendWithAsyncReply(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options), WTFMove(callback));
    89928968}
    89938969
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r272627 r272628  
    12941294    uint64_t computePagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&);
    12951295#if PLATFORM(COCOA)
    1296     void drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, Ref<ImageCallback>&&);
     1296    uint64_t drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
    12971297    void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, Ref<DataCallback>&&);
    12981298    void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::DataReference&)>&&);
     
    14281428    void signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challengeString, const URL&, CompletionHandler<void(String)>&&);
    14291429
    1430     void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, WTF::Function<void (const ShareableBitmap::Handle&, CallbackBase::Error)>&&);
     1430    void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, CompletionHandler<void(const ShareableBitmap::Handle&)>&&);
    14311431
    14321432    void navigationGestureDidBegin();
     
    21572157    void voidCallback(CallbackID);
    21582158    void dataCallback(const IPC::DataReference&, CallbackID);
    2159     void imageCallback(const ShareableBitmap::Handle&, CallbackID);
    21602159    void stringCallback(const String&, CallbackID);
    21612160    void invalidateStringCallback(CallbackID);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r272627 r272628  
    166166    VoidCallback(WebKit::CallbackID callbackID)
    167167    DataCallback(IPC::SharedBufferDataReference resultData, WebKit::CallbackID callbackID)
    168     ImageCallback(WebKit::ShareableBitmap::Handle bitmapHandle, WebKit::CallbackID callbackID)
    169168    StringCallback(String resultString, WebKit::CallbackID callbackID)
    170169    InvalidateStringCallback(WebKit::CallbackID callbackID)
  • trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm

    r272606 r272628  
    541541
    542542                IPCCallbackContext* context = new IPCCallbackContext;
    543                 auto callback = WebKit::ImageCallback::create([context](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
     543                auto callback = [context](const WebKit::ShareableBitmap::Handle& imageHandle) {
    544544                    std::unique_ptr<IPCCallbackContext> contextDeleter(context);
    545545                    pageDidDrawToImage(imageHandle, context);
    546                 });
    547                 _latestExpectedPreviewCallback = callback->callbackID().toInteger();
     546                };
     547                _latestExpectedPreviewCallback = _webFrame->page()->drawRectToImage(_webFrame.get(), WebKit::PrintInfo([_printOperation.get() printInfo]), scaledPrintingRect, imageSize, WTFMove(callback));
    548548                _expectedPreviewCallbacks.add(_latestExpectedPreviewCallback, scaledPrintingRect);
    549549
    550550                context->view = self;
    551                 context->callbackID = callback->callbackID().toInteger();
    552 
    553                 _webFrame->page()->drawRectToImage(_webFrame.get(), WebKit::PrintInfo([_printOperation.get() printInfo]), scaledPrintingRect, imageSize, WTFMove(callback));
     551                context->callbackID = _latestExpectedPreviewCallback;
    554552                return;
    555553            }
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r272627 r272628  
    24262426#endif // !PLATFORM(IOS_FAMILY)
    24272427
    2428 void WebPage::takeSnapshot(IntRect snapshotRect, IntSize bitmapSize, uint32_t options, CallbackID callbackID)
     2428void WebPage::takeSnapshot(IntRect snapshotRect, IntSize bitmapSize, uint32_t options, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler)
    24292429{
    24302430    SnapshotOptions snapshotOptions = static_cast<SnapshotOptions>(options);
     
    24372437        image->bitmap().createHandle(handle, SharedMemory::Protection::ReadOnly);
    24382438
    2439     send(Messages::WebPageProxy::ImageCallback(handle, callbackID));
     2439    completionHandler(handle);
    24402440}
    24412441
     
    51355135}
    51365136
    5137 void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CallbackID callbackID)
     5137void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler)
    51385138{
    51395139    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     
    51535153        if (!bitmap) {
    51545154            ASSERT_NOT_REACHED();
    5155             return;
     5155            return completionHandler({ });
    51565156        }
    51575157        auto graphicsContext = bitmap->createGraphicsContext();
     
    51825182        image->bitmap().createHandle(handle, SharedMemory::Protection::ReadOnly);
    51835183
    5184     send(Messages::WebPageProxy::ImageCallback(handle, callbackID));
     5184    completionHandler(handle);
    51855185}
    51865186
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r272627 r272628  
    966966
    967967#if PLATFORM(COCOA)
    968     void drawRectToImage(WebCore::FrameIdentifier, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CallbackID);
     968    void drawRectToImage(WebCore::FrameIdentifier, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
    969969    void drawPagesToPDF(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, CallbackID);
    970970    void drawPagesToPDFImpl(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, RetainPtr<CFMutableDataRef>& pdfPageData);
     
    15921592    void runJavaScriptInFrameInScriptWorld(WebCore::RunJavaScriptParameters&&, Optional<WebCore::FrameIdentifier>, const std::pair<ContentWorldIdentifier, String>& worldData, CompletionHandler<void(const IPC::DataReference&, const Optional<WebCore::ExceptionDetails>&)>&&);
    15931593    void forceRepaint(CompletionHandler<void()>&&);
    1594     void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CallbackID);
     1594    void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
    15951595
    15961596    void preferencesDidChange(const WebPreferencesStore&);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r272627 r272628  
    400400    ComputePagesForPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, WebCore::RectEdges<float> computedPageMargin) Async
    401401#if PLATFORM(COCOA)
    402     DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize, WebKit::CallbackID callbackID)
     402    DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize) -> (WebKit::ShareableBitmap::Handle image) Async
    403403    DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, WebKit::CallbackID callbackID)
    404404#if PLATFORM(IOS_FAMILY)
     
    492492    GetSamplingProfilerOutput(WebKit::CallbackID callbackID)
    493493   
    494     TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, WebKit::CallbackID callbackID)
     494    TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options) -> (WebKit::ShareableBitmap::Handle image) Async
    495495#if PLATFORM(MAC)
    496496    PerformImmediateActionHitTestAtLocation(WebCore::FloatPoint location)
Note: See TracChangeset for help on using the changeset viewer.