Changeset 272592 in webkit


Ignore:
Timestamp:
Feb 9, 2021 10:38:58 AM (3 years ago)
Author:
achristensen@apple.com
Message:

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

Reviewed by Chris Dumez.

Along the way I made all asynchronous message replies use 8 fewer bytes by using the destination ID for the listener ID
instead of encoding 0 as the destination ID and then encoding the listener ID. This was needed in order to make implementing
waitForAsyncCallbackAndDispatchImmediately possible, which looks at the destination IDs of incoming messages.
I also made it so that if we are just snapshotting the first page, we don't send a synchronous message because we already know the page count:
1!

  • Platform/IPC/Connection.cpp:

(IPC::Connection::dispatchMessage):

  • Platform/IPC/Connection.h:

(IPC::Connection::sendWithAsyncReply):
(IPC::Connection::waitForAndDispatchImmediately):
(IPC::Connection::waitForAsyncCallbackAndDispatchImmediately):

  • Platform/IPC/HandleMessage.h:

(IPC::handleMessageAsync):
(IPC::handleMessageAsyncWantsConnection):

  • Platform/IPC/JSIPCBinding.cpp:

(IPC::jsValueForDecodedArgumentValue):

  • Platform/IPC/JSIPCBinding.h:
  • Platform/IPC/MessageSender.h:

(IPC::MessageSender::sendWithAsyncReply):

  • Scripts/webkit/messages.py:
  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView createPDFWithConfiguration:completionHandler:]):

  • UIProcess/AuxiliaryProcessProxy.h:

(WebKit::AuxiliaryProcessProxy::sendWithAsyncReply):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::drawToPDF):
(WebKit::WebPageProxy::getLoadDecisionForIcon):
(WebKit::WebPageProxy::drawToPDFCallback): Deleted.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/ios/WKContentView.mm:

(-[WKContentView _processDidExit]):
(-[WKContentView _wk_pageCountForPrintFormatter:]):
(-[WKContentView _waitForDrawToPDFCallback]):
(-[WKContentView _wk_printedDocument]):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::drawToPDF):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::computePagesForPrintingiOS):
(WebKit::WebPage::drawToPDFiOS):
(WebKit::WebPage::computePagesForPrintingAndDrawToPDF): Deleted.

Location:
trunk/Source/WebKit
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r272586 r272592  
     12021-02-09  Alex Christensen  <achristensen@webkit.org>
     2
     3        Use CompletionHandler instead of DrawToPDFCallback
     4        https://bugs.webkit.org/show_bug.cgi?id=220120
     5
     6        Reviewed by Chris Dumez.
     7
     8        Along the way I made all asynchronous message replies use 8 fewer bytes by using the destination ID for the listener ID
     9        instead of encoding 0 as the destination ID and then encoding the listener ID.  This was needed in order to make implementing
     10        waitForAsyncCallbackAndDispatchImmediately possible, which looks at the destination IDs of incoming messages.
     11        I also made it so that if we are just snapshotting the first page, we don't send a synchronous message because we already know the page count:
     12        1!
     13
     14        * Platform/IPC/Connection.cpp:
     15        (IPC::Connection::dispatchMessage):
     16        * Platform/IPC/Connection.h:
     17        (IPC::Connection::sendWithAsyncReply):
     18        (IPC::Connection::waitForAndDispatchImmediately):
     19        (IPC::Connection::waitForAsyncCallbackAndDispatchImmediately):
     20        * Platform/IPC/HandleMessage.h:
     21        (IPC::handleMessageAsync):
     22        (IPC::handleMessageAsyncWantsConnection):
     23        * Platform/IPC/JSIPCBinding.cpp:
     24        (IPC::jsValueForDecodedArgumentValue):
     25        * Platform/IPC/JSIPCBinding.h:
     26        * Platform/IPC/MessageSender.h:
     27        (IPC::MessageSender::sendWithAsyncReply):
     28        * Scripts/webkit/messages.py:
     29        * UIProcess/API/Cocoa/WKWebView.mm:
     30        (-[WKWebView createPDFWithConfiguration:completionHandler:]):
     31        * UIProcess/AuxiliaryProcessProxy.h:
     32        (WebKit::AuxiliaryProcessProxy::sendWithAsyncReply):
     33        * UIProcess/WebPageProxy.cpp:
     34        (WebKit::WebPageProxy::drawToPDF):
     35        (WebKit::WebPageProxy::getLoadDecisionForIcon):
     36        (WebKit::WebPageProxy::drawToPDFCallback): Deleted.
     37        * UIProcess/WebPageProxy.h:
     38        * UIProcess/WebPageProxy.messages.in:
     39        * UIProcess/ios/WKContentView.mm:
     40        (-[WKContentView _processDidExit]):
     41        (-[WKContentView _wk_pageCountForPrintFormatter:]):
     42        (-[WKContentView _waitForDrawToPDFCallback]):
     43        (-[WKContentView _wk_printedDocument]):
     44        * UIProcess/ios/WebPageProxyIOS.mm:
     45        (WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF):
     46        * WebProcess/WebPage/WebPage.cpp:
     47        (WebKit::WebPage::drawToPDF):
     48        * WebProcess/WebPage/WebPage.h:
     49        * WebProcess/WebPage/WebPage.messages.in:
     50        * WebProcess/WebPage/ios/WebPageIOS.mm:
     51        (WebKit::WebPage::computePagesForPrintingiOS):
     52        (WebKit::WebPage::drawToPDFiOS):
     53        (WebKit::WebPage::computePagesForPrintingAndDrawToPDF): Deleted.
     54
    1552021-02-09  Per Arne  <pvollan@apple.com>
    256
  • trunk/Source/WebKit/Platform/IPC/Connection.cpp

    r271243 r272592  
    10071007    RELEASE_ASSERT(isValid());
    10081008    if (decoder.messageReceiverName() == ReceiverName::AsyncReply) {
    1009         Optional<uint64_t> listenerID;
    1010         decoder >> listenerID;
    1011         if (!listenerID) {
    1012             ASSERT_NOT_REACHED();
    1013             return;
    1014         }
    1015         auto handler = takeAsyncReplyHandler(*this, *listenerID);
     1009        auto handler = takeAsyncReplyHandler(*this, decoder.destinationID());
    10161010        if (!handler) {
    10171011            ASSERT_NOT_REACHED();
  • trunk/Source/WebKit/Platform/IPC/Connection.h

    r272058 r272592  
    226226
    227227    void postConnectionDidCloseOnConnectionWorkQueue();
    228     template<typename T, typename C> void sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID = 0, OptionSet<SendOption> = { }); // Thread-safe.
     228    template<typename T, typename C> uint64_t sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID = 0, OptionSet<SendOption> = { }); // Thread-safe.
    229229    template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<SendOption> sendOptions = { }); // Thread-safe.
    230230    // Sync senders should check the SendSyncResult for true/false in case they need to know if the result was really received.
     
    232232    using SendSyncResult = std::unique_ptr<Decoder>;
    233233    template<typename T> SendSyncResult sendSync(T&& message, typename T::Reply&& reply, uint64_t destinationID, Seconds timeout = Seconds::infinity(), OptionSet<SendSyncOption> sendSyncOptions = { }); // Main thread only.
    234     template<typename T> bool waitForAndDispatchImmediately(uint64_t destinationID, Seconds timeout, OptionSet<WaitForOption> waitForOptions = { }); // Main thread only.
    235    
     234    template<typename> bool waitForAndDispatchImmediately(uint64_t destinationID, Seconds timeout, OptionSet<WaitForOption> waitForOptions = { }); // Main thread only.
     235    template<typename> bool waitForAsyncCallbackAndDispatchImmediately(uint64_t callbackID, Seconds timeout); // Main thread only.
     236
    236237    // Thread-safe.
    237238    template<typename T, typename C, typename U>
    238     void sendWithAsyncReply(T&& message, C&& completionHandler, ObjectIdentifier<U> destinationID = { }, OptionSet<SendOption> sendOptions = { })
    239     {
    240         sendWithAsyncReply<T, C>(WTFMove(message), WTFMove(completionHandler), destinationID.toUInt64(), sendOptions);
     239    uint64_t sendWithAsyncReply(T&& message, C&& completionHandler, ObjectIdentifier<U> destinationID = { }, OptionSet<SendOption> sendOptions = { })
     240    {
     241        return sendWithAsyncReply<T, C>(WTFMove(message), WTFMove(completionHandler), destinationID.toUInt64(), sendOptions);
    241242    }
    242243   
     
    516517
    517518template<typename T, typename C>
    518 void Connection::sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<SendOption> sendOptions)
     519uint64_t Connection::sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<SendOption> sendOptions)
    519520{
    520521    COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
     
    531532    *encoder << message.arguments();
    532533    sendMessage(WTFMove(encoder), sendOptions);
     534    return listenerID;
    533535}
    534536
     
    594596}
    595597
     598template<typename T> bool Connection::waitForAsyncCallbackAndDispatchImmediately(uint64_t destinationID, Seconds timeout)
     599{
     600    RELEASE_ASSERT(RunLoop::isMain());
     601    std::unique_ptr<Decoder> decoder = waitForMessage(T::asyncMessageReplyName(), destinationID, timeout, { });
     602    if (!decoder)
     603        return false;
     604
     605    ASSERT(decoder->messageReceiverName() == ReceiverName::AsyncReply);
     606    ASSERT(decoder->destinationID() == destinationID);
     607    auto handler = takeAsyncReplyHandler(*this, decoder->destinationID());
     608    if (!handler) {
     609        ASSERT_NOT_REACHED();
     610        return false;
     611    }
     612    handler(decoder.get());
     613    return true;
     614}
     615
    596616class UnboundedSynchronousIPCScope {
    597617public:
  • trunk/Source/WebKit/Platform/IPC/HandleMessage.h

    r270573 r272592  
    174174        return;
    175175    }
    176    
     176
    177177    Optional<typename CodingType<typename T::Arguments>::Type> arguments;
    178178    decoder >> arguments;
     
    183183
    184184    typename T::AsyncReply completionHandler = [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
    185         auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), 0);
    186         *encoder << listenerID;
     185        auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), listenerID);
    187186        T::send(WTFMove(encoder), WTFMove(connection), args...);
    188187    };
     
    193192void handleMessageAsyncWantsConnection(Connection& connection, Decoder& decoder, C* object, MF function)
    194193{
    195     Optional<uint64_t> listenerID;
    196     decoder >> listenerID;
    197     if (!listenerID) {
    198         decoder.markInvalid();
    199         return;
    200     }
    201 
    202     Optional<typename CodingType<typename T::Arguments>::Type> arguments;
    203     decoder >> arguments;
    204     if (!arguments) {
    205         decoder.markInvalid();
    206         return;
    207     }
    208 
    209     typename T::AsyncReply completionHandler = [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
    210         auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), 0);
    211         *encoder << listenerID;
     194    Optional<typename CodingType<typename T::Arguments>::Type> arguments;
     195    decoder >> arguments;
     196    if (!arguments) {
     197        decoder.markInvalid();
     198        return;
     199    }
     200
     201    typename T::AsyncReply completionHandler = [listenerID = decoder.destinationID(), connection = makeRef(connection)] (auto&&... args) mutable {
     202        auto encoder = makeUnique<Encoder>(T::asyncMessageReplyName(), listenerID);
    212203        T::send(WTFMove(encoder), WTFMove(connection), args...);
    213204    };
  • trunk/Source/WebKit/Platform/IPC/JSIPCBinding.cpp

    r268946 r272592  
    158158}
    159159
     160template<>
     161JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject* globalObject, size_t value)
     162{
     163    return jsValueForDecodedNumericArgumentValue(globalObject, value, "size_t");
     164}
     165
    160166template<typename RectType>
    161167JSC::JSValue jsValueForDecodedArgumentRect(JSC::JSGlobalObject* globalObject, const RectType& value, const String& type)
  • trunk/Source/WebKit/Platform/IPC/JSIPCBinding.h

    r268946 r272592  
    8787template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, uint32_t);
    8888template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, uint64_t);
     89template<> JSC::JSValue jsValueForDecodedArgumentValue(JSC::JSGlobalObject*, size_t);
    8990
    9091template<typename U>
  • trunk/Source/WebKit/Platform/IPC/MessageSender.h

    r272058 r272592  
    8181
    8282    template<typename T, typename C>
    83     void sendWithAsyncReply(T&& message, C&& completionHandler, OptionSet<SendOption> sendOptions = { })
     83    uint64_t sendWithAsyncReply(T&& message, C&& completionHandler, OptionSet<SendOption> sendOptions = { })
    8484    {
    85         sendWithAsyncReply(WTFMove(message), WTFMove(completionHandler), messageSenderDestinationID(), sendOptions);
     85        return sendWithAsyncReply(WTFMove(message), WTFMove(completionHandler), messageSenderDestinationID(), sendOptions);
    8686    }
    8787
    8888    template<typename T, typename C>
    89     void sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<SendOption> sendOptions = { })
     89    uint64_t sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<SendOption> sendOptions = { })
    9090    {
    9191        COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
     
    101101                T::cancelReply(WTFMove(completionHandler));
    102102        }, listenerID }});
     103        return listenerID;
    103104    }
    104105
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r272475 r272592  
    129129        'int32_t',
    130130        'int64_t',
     131        'size_t',
    131132    ])
    132133
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r272425 r272592  
    14741474        floatRect = WebCore::FloatRect(pdfConfiguration.rect);
    14751475
    1476     auto handler = makeBlockPtr(completionHandler);
    1477     _page->drawToPDF(frameID, floatRect, [retainedSelf = retainPtr(self), handler = WTFMove(handler)](const IPC::DataReference& pdfData, WebKit::CallbackBase::Error error) {
    1478         if (error != WebKit::CallbackBase::Error::None) {
     1476    _page->drawToPDF(frameID, floatRect, [handler = makeBlockPtr(completionHandler)](const IPC::DataReference& pdfData) {
     1477        if (pdfData.isEmpty()) {
    14791478            handler(nil, createNSError(WKErrorUnknown).get());
    14801479            return;
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.h

    r272058 r272592  
    5858
    5959    enum class ShouldStartProcessThrottlerActivity : bool { No, Yes };
    60     template<typename T, typename C> void sendWithAsyncReply(T&&, C&&, uint64_t destinationID = 0, OptionSet<IPC::SendOption> = { }, ShouldStartProcessThrottlerActivity = ShouldStartProcessThrottlerActivity::Yes);
     60    template<typename T, typename C> uint64_t sendWithAsyncReply(T&&, C&&, uint64_t destinationID = 0, OptionSet<IPC::SendOption> = { }, ShouldStartProcessThrottlerActivity = ShouldStartProcessThrottlerActivity::Yes);
    6161   
    6262    template<typename T, typename U>
     
    183183
    184184template<typename T, typename C>
    185 void AuxiliaryProcessProxy::sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions, ShouldStartProcessThrottlerActivity shouldStartProcessThrottlerActivity)
     185uint64_t AuxiliaryProcessProxy::sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions, ShouldStartProcessThrottlerActivity shouldStartProcessThrottlerActivity)
    186186{
    187187    COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
     
    197197            T::cancelReply(WTFMove(completionHandler));
    198198    }, listenerID }}, shouldStartProcessThrottlerActivity);
     199    return listenerID;
    199200}
    200201   
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r272575 r272592  
    85998599
    86008600#if PLATFORM(COCOA)
    8601 void WebPageProxy::drawToPDF(FrameIdentifier frameID, const Optional<FloatRect>& rect, DrawToPDFCallback::CallbackFunction&& callback)
     8601void WebPageProxy::drawToPDF(FrameIdentifier frameID, const Optional<FloatRect>& rect, CompletionHandler<void(const IPC::DataReference&)>&& callback)
    86028602{
    86038603    if (!hasRunningProcess()) {
    8604         callback(IPC::DataReference(), CallbackBase::Error::OwnerWasInvalidated);
    8605         return;
    8606     }
    8607 
    8608     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::drawToPDF"_s));
    8609     send(Messages::WebPage::DrawToPDF(frameID, rect, callbackID));
    8610 }
    8611 
    8612 void WebPageProxy::drawToPDFCallback(const IPC::DataReference& pdfData, CallbackID callbackID)
    8613 {
    8614     auto callback = m_callbacks.take<DrawToPDFCallback>(callbackID);
    8615     RELEASE_ASSERT(callback);
    8616     callback->performCallbackWithReturnValue(pdfData);
     8604        callback({ });
     8605        return;
     8606    }
     8607    sendWithAsyncReply(Messages::WebPage::DrawToPDF(frameID, rect), WTFMove(callback));
    86178608}
    86188609#endif // PLATFORM(COCOA)
     
    95149505        }
    95159506
    9516         if (!callback)
    9517             return sendWithAsyncReply(Messages::WebPage::DidGetLoadDecisionForIcon(false, loadIdentifier), [](auto) { });
     9507        if (!callback) {
     9508            sendWithAsyncReply(Messages::WebPage::DidGetLoadDecisionForIcon(false, loadIdentifier), [](auto) { });
     9509            return;
     9510        }
    95189511        sendWithAsyncReply(Messages::WebPage::DidGetLoadDecisionForIcon(true, loadIdentifier), [callback = WTFMove(callback)](const IPC::DataReference& iconData) mutable {
    95199512            callback(API::Data::create(iconData).get());
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r272573 r272592  
    407407
    408408#if PLATFORM(COCOA)
    409 using DrawToPDFCallback = GenericCallback<const IPC::DataReference&>;
    410409typedef GenericCallback<bool, bool, String, double, double, uint64_t> NowPlayingInfoCallback;
    411410#endif
     
    13021301    void drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, Ref<ImageCallback>&&);
    13031302    void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, Ref<DataCallback>&&);
    1304     void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, DrawToPDFCallback::CallbackFunction&&);
    1305     void drawToPDFCallback(const IPC::DataReference& pdfData, WebKit::CallbackID);
     1303    void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::DataReference&)>&&);
    13061304#if PLATFORM(IOS_FAMILY)
    1307     uint32_t computePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier, const PrintInfo&, DrawToPDFCallback::CallbackFunction&&);
     1305    std::pair<size_t, uint64_t> computePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const IPC::DataReference&)>&&);
    13081306#endif
    13091307#elif PLATFORM(GTK)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r272573 r272592  
    192192#endif
    193193#if PLATFORM(COCOA)
    194     DrawToPDFCallback(IPC::DataReference pdfData, WebKit::CallbackID callbackID)
    195194    NowPlayingInfoCallback(bool active, bool registeredAsNowPlayingApplication, String title, double duration, double elapsedTime, uint64_t uniqueIdentifier, WebKit::CallbackID callbackID)
    196195#endif
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.mm

    r271771 r272592  
    5050#import "WebKit2Initialize.h"
    5151#import "WebPageGroup.h"
     52#import "WebPageMessages.h"
    5253#import "WebPageProxyMessages.h"
    5354#import "WebProcessPool.h"
     
    144145    RetainPtr<WKQuirkyNSUndoManager> _quirkyUndoManager;
    145146
    146     BOOL _isPrintingToPDF;
     147    uint64_t _pdfPrintCallbackID;
    147148    RetainPtr<CGPDFDocumentRef> _printedDocument;
    148149}
     
    621622#endif
    622623
    623     _isPrintingToPDF = NO;
     624    _pdfPrintCallbackID = 0;
    624625}
    625626
     
    792793- (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
    793794{
    794     if (_isPrintingToPDF)
     795    if (_pdfPrintCallbackID)
    795796        [self _waitForDrawToPDFCallback];
    796797
     
    825826    printInfo.availablePaperHeight = CGRectGetHeight(printingRect);
    826827
    827     _isPrintingToPDF = YES;
    828828    auto retainedSelf = retainPtr(self);
    829     return _page->computePagesForPrintingAndDrawToPDF(frameID, printInfo, [retainedSelf](const IPC::DataReference& pdfData, WebKit::CallbackBase::Error error) {
    830         retainedSelf->_isPrintingToPDF = NO;
    831         if (error != WebKit::CallbackBase::Error::None)
     829    auto pair = _page->computePagesForPrintingAndDrawToPDF(frameID, printInfo, [retainedSelf](const IPC::DataReference& pdfData) {
     830        retainedSelf->_pdfPrintCallbackID = 0;
     831        if (pdfData.isEmpty())
    832832            return;
    833833
     
    836836        retainedSelf->_printedDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
    837837    });
     838    _pdfPrintCallbackID = pair.second;
     839    return pair.first;
    838840}
    839841
    840842- (BOOL)_waitForDrawToPDFCallback
    841843{
    842     if (!_page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DrawToPDFCallback>(_page->webPageID(), Seconds::infinity()))
     844    ASSERT(_pdfPrintCallbackID);
     845    if (!_page->process().connection()->waitForAsyncCallbackAndDispatchImmediately<Messages::WebPage::DrawToPDFiOS>(std::exchange(_pdfPrintCallbackID, 0), Seconds::infinity()))
    843846        return false;
    844     ASSERT(!_isPrintingToPDF);
     847    ASSERT(!_pdfPrintCallbackID);
    845848    return true;
    846849}
     
    848851- (CGPDFDocumentRef)_wk_printedDocument
    849852{
    850     if (_isPrintingToPDF) {
     853    if (_pdfPrintCallbackID) {
    851854        if (![self _waitForDrawToPDFCallback])
    852855            return nullptr;
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r271969 r272592  
    10471047}
    10481048
    1049 uint32_t WebPageProxy::computePagesForPrintingAndDrawToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, DrawToPDFCallback::CallbackFunction&& callback)
    1050 {
    1051     if (!hasRunningProcess()) {
    1052         callback(IPC::DataReference(), CallbackBase::Error::OwnerWasInvalidated);
    1053         return 0;
    1054     }
    1055 
    1056     uint32_t pageCount = 0;
    1057     auto callbackID = m_callbacks.put(WTFMove(callback), m_process->throttler().backgroundActivity("WebPageProxy::computePagesForPrintingAndDrawToPDF"_s));
    1058     sendSync(Messages::WebPage::ComputePagesForPrintingAndDrawToPDF(frameID, printInfo, callbackID), Messages::WebPage::ComputePagesForPrintingAndDrawToPDF::Reply(pageCount), Seconds::infinity());
    1059     return pageCount;
     1049std::pair<size_t, uint64_t> WebPageProxy::computePagesForPrintingAndDrawToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const IPC::DataReference&)>&& callback)
     1050{
     1051    if (!hasRunningProcess()) {
     1052        callback({ });
     1053        return { 0, 0 };
     1054    }
     1055
     1056    size_t pageCount = 0;
     1057    if (printInfo.snapshotFirstPage)
     1058        pageCount = 1;
     1059    else
     1060        sendSync(Messages::WebPage::ComputePagesForPrintingiOS(frameID, printInfo), Messages::WebPage::ComputePagesForPrintingiOS::Reply(pageCount), Seconds::infinity());
     1061
     1062    auto callbackID = sendWithAsyncReply(Messages::WebPage::DrawToPDFiOS(frameID, printInfo, pageCount), WTFMove(callback));
     1063   
     1064    return { pageCount, callbackID };
    10601065}
    10611066
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r272573 r272592  
    51015101
    51025102#if PLATFORM(COCOA)
    5103 void WebPage::drawToPDF(FrameIdentifier frameID, const Optional<FloatRect>& rect, CallbackID callbackID)
     5103void WebPage::drawToPDF(FrameIdentifier frameID, const Optional<FloatRect>& rect, CompletionHandler<void(const IPC::DataReference&)>&& completionHandler)
    51045104{
    51055105    auto& frameView = *m_page->mainFrame().view();
     
    51265126    frameView.setPaintBehavior(originalPaintBehavior);
    51275127
    5128     send(Messages::WebPageProxy::DrawToPDFCallback(IPC::DataReference(CFDataGetBytePtr(pdfData.get()), CFDataGetLength(pdfData.get())), callbackID));
     5128    completionHandler(IPC::DataReference(CFDataGetBytePtr(pdfData.get()), CFDataGetLength(pdfData.get())));
    51295129}
    51305130
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r272573 r272592  
    972972
    973973#if PLATFORM(IOS_FAMILY)
    974     void computePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier, const PrintInfo&, CallbackID, Messages::WebPage::ComputePagesForPrintingAndDrawToPDFDelayedReply&&);
    975 #endif
    976 
    977     void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, CallbackID);
     974    void computePagesForPrintingiOS(WebCore::FrameIdentifier, const PrintInfo&, Messages::WebPage::ComputePagesForPrintingiOSDelayedReply&&);
     975    void drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t, Messages::WebPage::DrawToPDFiOSAsyncReply&&);
     976#endif
     977
     978    void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::DataReference&)>&&);
    978979
    979980#if PLATFORM(GTK)
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r272573 r272592  
    403403    DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, WebKit::CallbackID callbackID)
    404404#if PLATFORM(IOS_FAMILY)
    405     ComputePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebKit::CallbackID callbackID) -> (uint32_t pageCount) Synchronous
    406 #endif
    407     DrawToPDF(WebCore::FrameIdentifier frameID, Optional<WebCore::FloatRect> rect, WebKit::CallbackID callbackID)
     405    ComputePagesForPrintingiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (size_t pageCount) Synchronous
     406    DrawToPDFiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, size_t pageCount) -> (IPC::DataReference data) Async
     407#endif
     408    DrawToPDF(WebCore::FrameIdentifier frameID, Optional<WebCore::FloatRect> rect) -> (IPC::DataReference data) Async
    408409#endif
    409410#if PLATFORM(GTK)
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r272558 r272592  
    39723972#endif
    39733973
    3974 void WebPage::computePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, CallbackID callbackID, Messages::WebPage::ComputePagesForPrintingAndDrawToPDF::DelayedReply&& reply)
    3975 {
    3976     if (printInfo.snapshotFirstPage) {
    3977         reply(1);
    3978         IntSize snapshotSize { FloatSize { printInfo.availablePaperWidth, printInfo.availablePaperHeight } };
    3979         IntRect snapshotRect { {0, 0}, snapshotSize };
    3980 
    3981         auto& frameView = *m_page->mainFrame().view();
    3982         auto originalLayoutViewportOverrideRect = frameView.layoutViewportOverrideRect();
    3983         frameView.setLayoutViewportOverrideRect(LayoutRect(snapshotRect));
    3984 
    3985         auto pdfData = pdfSnapshotAtSize(snapshotRect, snapshotSize, 0);
    3986 
    3987         frameView.setLayoutViewportOverrideRect(originalLayoutViewportOverrideRect);
    3988         send(Messages::WebPageProxy::DrawToPDFCallback(IPC::DataReference(CFDataGetBytePtr(pdfData.get()), CFDataGetLength(pdfData.get())), callbackID));
    3989         return;
    3990     }
     3974void WebPage::computePagesForPrintingiOS(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, Messages::WebPage::ComputePagesForPrintingiOS::DelayedReply&& reply)
     3975{
     3976    ASSERT_WITH_MESSAGE(!printInfo.snapshotFirstPage, "If we are just snapshotting the first page, we don't need a synchronous message to determine the page count, which is 1.");
    39913977
    39923978    Vector<WebCore::IntRect> pageRects;
     
    39963982
    39973983    ASSERT(pageRects.size() >= 1);
    3998     std::size_t pageCount = pageRects.size();
    3999     ASSERT(pageCount <= std::numeric_limits<uint32_t>::max());
    4000     reply(pageCount);
     3984    reply(pageRects.size());
     3985}
     3986
     3987void WebPage::drawToPDFiOS(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, size_t pageCount, Messages::WebPage::DrawToPDFiOSAsyncReply&& reply)
     3988{
     3989    if (printInfo.snapshotFirstPage) {
     3990        IntSize snapshotSize { FloatSize { printInfo.availablePaperWidth, printInfo.availablePaperHeight } };
     3991        IntRect snapshotRect { {0, 0}, snapshotSize };
     3992
     3993        auto& frameView = *m_page->mainFrame().view();
     3994        auto originalLayoutViewportOverrideRect = frameView.layoutViewportOverrideRect();
     3995        frameView.setLayoutViewportOverrideRect(LayoutRect(snapshotRect));
     3996
     3997        auto pdfData = pdfSnapshotAtSize(snapshotRect, snapshotSize, 0);
     3998
     3999        frameView.setLayoutViewportOverrideRect(originalLayoutViewportOverrideRect);
     4000        reply(IPC::DataReference(CFDataGetBytePtr(pdfData.get()), CFDataGetLength(pdfData.get())));
     4001        return;
     4002    }
    40014003
    40024004    RetainPtr<CFMutableDataRef> pdfPageData;
    40034005    drawPagesToPDFImpl(frameID, printInfo, 0, pageCount, pdfPageData);
    4004     send(Messages::WebPageProxy::DrawToPDFCallback(IPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
     4006    reply(IPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())));
    40054007
    40064008    endPrinting();
Note: See TracChangeset for help on using the changeset viewer.