Title: [290186] trunk/Source
Revision
290186
Author
drou...@apple.com
Date
2022-02-18 16:44:12 -0800 (Fri, 18 Feb 2022)

Log Message

[iOS] Safari can sometimes hang while printing due to sync IPC
https://bugs.webkit.org/show_bug.cgi?id=236811
<rdar://problem/56425783>

Reviewed by Aditya Keerthi.

Source/WebKit:

* UIProcess/_WKWebViewPrintFormatter.h:
* UIProcess/_WKWebViewPrintFormatterInternal.h:
* UIProcess/_WKWebViewPrintFormatter.mm:
(-[_WKWebViewPrintFormatter requiresMainThread]): Added.
Adopt new UIKit SPI for allowing `UIPrintFormatter` to be called off the main thread.

* UIProcess/ios/WKContentView.mm:
(-[WKContentView _processDidExit]):
(-[WKContentView _wk_printFormatterRequiresMainThread]): Added.
(-[WKContentView _wk_pageCountForPrintFormatter:]):
(-[WKContentView _waitForDrawToPDFCallbackIfNeeded:]): Added.
(-[WKContentView _wk_printedDocument:]):
(-[WKContentView _waitForDrawToPDFCallback:]): Deleted.
Reorganize this code to support both sync and async flows.

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::computePagesForPrintingiOS): Added.
(WebKit::WebPageProxy::drawToPDFiOS): Added.
(WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF): Deleted.
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
Split `WebPageProxy::computePagesForPrintingAndDrawToPDF` into two methods, as the first
"part" (i.e. `computePagesForPrintingiOS`) is no longer needed with this new UIKit SPI.

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::computePagesForPrinting):
* UIProcess/API/C/WKPage.cpp:
(WKPageComputePagesForPrinting):
* UIProcess/mac/WKPrintingView.mm:
(-[WKPrintingView _askPageToComputePageRects]):
Have `WebPageProxy::computePagesForPrinting` take a `WebCore::FrameIdentifier` instead of a
`WebFrameProxy*` so that more callers (e.g. `API::FrameHandle`) can use it.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView _wk_printFormatterRequiresMainThread]): Added.
By the time `WKPDFView` is asked to print, it should already have all the data necessary to
do so, so there's no reason to not use the main thread (since there's no sync IPC).

Source/WTF:

Adopt new UIKit SPI for allowing `UIPrintFormatter` to be called off the main thread.

* wtf/PlatformHave.h:
Add a `HAVE_UIKIT_BACKGROUND_THREAD_PRINTING` to guard this new behavior.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (290185 => 290186)


--- trunk/Source/WTF/ChangeLog	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WTF/ChangeLog	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1,3 +1,16 @@
+2022-02-18  Devin Rousso  <drou...@apple.com>
+
+        [iOS] Safari can sometimes hang while printing due to sync IPC
+        https://bugs.webkit.org/show_bug.cgi?id=236811
+        <rdar://problem/56425783>
+
+        Reviewed by Aditya Keerthi.
+
+        Adopt new UIKit SPI for allowing `UIPrintFormatter` to be called off the main thread.
+
+        * wtf/PlatformHave.h:
+        Add a `HAVE_UIKIT_BACKGROUND_THREAD_PRINTING` to guard this new behavior.
+
 2022-02-18  Robert Jenner  <jen...@apple.com>
 
         Unreviewed, reverting r290149.

Modified: trunk/Source/WTF/wtf/PlatformHave.h (290185 => 290186)


--- trunk/Source/WTF/wtf/PlatformHave.h	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1218,3 +1218,7 @@
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 90000)
 #define HAVE_SAFE_BROWSING_RESULT_DETAILS 1
 #endif
+
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000)
+#define HAVE_UIKIT_BACKGROUND_THREAD_PRINTING 1
+#endif

Modified: trunk/Source/WebKit/ChangeLog (290185 => 290186)


--- trunk/Source/WebKit/ChangeLog	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/ChangeLog	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1,3 +1,51 @@
+2022-02-18  Devin Rousso  <drou...@apple.com>
+
+        [iOS] Safari can sometimes hang while printing due to sync IPC
+        https://bugs.webkit.org/show_bug.cgi?id=236811
+        <rdar://problem/56425783>
+
+        Reviewed by Aditya Keerthi.
+
+        * UIProcess/_WKWebViewPrintFormatter.h:
+        * UIProcess/_WKWebViewPrintFormatterInternal.h:
+        * UIProcess/_WKWebViewPrintFormatter.mm:
+        (-[_WKWebViewPrintFormatter requiresMainThread]): Added.
+        Adopt new UIKit SPI for allowing `UIPrintFormatter` to be called off the main thread.
+
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _processDidExit]):
+        (-[WKContentView _wk_printFormatterRequiresMainThread]): Added.
+        (-[WKContentView _wk_pageCountForPrintFormatter:]):
+        (-[WKContentView _waitForDrawToPDFCallbackIfNeeded:]): Added.
+        (-[WKContentView _wk_printedDocument:]):
+        (-[WKContentView _waitForDrawToPDFCallback:]): Deleted.
+        Reorganize this code to support both sync and async flows.
+
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::computePagesForPrintingiOS): Added.
+        (WebKit::WebPageProxy::drawToPDFiOS): Added.
+        (WebKit::WebPageProxy::computePagesForPrintingAndDrawToPDF): Deleted.
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        Split `WebPageProxy::computePagesForPrintingAndDrawToPDF` into two methods, as the first
+        "part" (i.e. `computePagesForPrintingiOS`) is no longer needed with this new UIKit SPI.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::computePagesForPrinting):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageComputePagesForPrinting):
+        * UIProcess/mac/WKPrintingView.mm:
+        (-[WKPrintingView _askPageToComputePageRects]):
+        Have `WebPageProxy::computePagesForPrinting` take a `WebCore::FrameIdentifier` instead of a
+        `WebFrameProxy*` so that more callers (e.g. `API::FrameHandle`) can use it.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView _wk_printFormatterRequiresMainThread]): Added.
+        By the time `WKPDFView` is asked to print, it should already have all the data necessary to
+        do so, so there's no reason to not use the main thread (since there's no sync IPC).
+
 2022-02-18  J Pascoe  <j_pas...@apple.com>
 
         [WebAuthn] Support for conditional mediation

Modified: trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp	2022-02-19 00:44:12 UTC (rev 290186)
@@ -2721,7 +2721,7 @@
 void WKPageComputePagesForPrinting(WKPageRef pageRef, WKFrameRef frame, WKPrintInfo printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
 {
     CRASH_IF_SUSPENDED;
-    toImpl(pageRef)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), [context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, const WebCore::FloatBoxExtent& computedPageMargin) {
+    toImpl(pageRef)->computePagesForPrinting(toImpl(frame)->frameID(), printInfoFromWKPrintInfo(printInfo), [context, callback](const Vector<WebCore::IntRect>& rects, double scaleFactor, const WebCore::FloatBoxExtent& computedPageMargin) {
         Vector<WKRect> wkRects(rects.size());
         for (size_t i = 0; i < rects.size(); ++i)
             wkRects[i] = toAPI(rects[i]);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-02-19 00:44:12 UTC (rev 290186)
@@ -9010,10 +9010,10 @@
     send(Messages::WebPage::EndPrinting(), printingSendOptions(m_isPerformingDOMPrintOperation));
 }
 
-uint64_t WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& callback)
+uint64_t WebPageProxy::computePagesForPrinting(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& callback)
 {
     m_isInPrintingMode = true;
-    return sendWithAsyncReply(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo), WTFMove(callback), printingSendOptions(m_isPerformingDOMPrintOperation));
+    return sendWithAsyncReply(Messages::WebPage::ComputePagesForPrinting(frameID, printInfo), WTFMove(callback), printingSendOptions(m_isPerformingDOMPrintOperation));
 }
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1405,7 +1405,7 @@
 
     void beginPrinting(WebFrameProxy*, const PrintInfo&);
     void endPrinting();
-    uint64_t computePagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&);
+    uint64_t computePagesForPrinting(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&);
     void getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&&);
 #if PLATFORM(COCOA)
     uint64_t drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
@@ -1412,8 +1412,11 @@
     uint64_t drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, CompletionHandler<void(API::Data*)>&&);
     void drawToPDF(WebCore::FrameIdentifier, const std::optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::SharedBufferCopy&)>&&);
 #if PLATFORM(IOS_FAMILY)
-    std::pair<size_t, uint64_t> computePagesForPrintingAndDrawToPDF(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const IPC::SharedBufferCopy&)>&&);
+#if !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+    size_t computePagesForPrintingiOS(WebCore::FrameIdentifier, const PrintInfo&);
 #endif
+    uint64_t drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t pageCount, CompletionHandler<void(const IPC::SharedBufferCopy&)>&&);
+#endif
 #elif PLATFORM(GTK)
     void drawPagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(API::Error*)>&&);
 #endif

Modified: trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatter.mm (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatter.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatter.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -44,6 +44,15 @@
     BOOL _suppressPageCountRecalc;
 }
 
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
+- (BOOL)requiresMainThread
+{
+    return self._webView._printProvider._wk_printFormatterRequiresMainThread;
+}
+
+#endif // HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
 - (_WKFrameHandle *)frameToPrint
 {
     return _frameToPrint.get();

Modified: trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatterInternal.h (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatterInternal.h	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/_WKWebViewPrintFormatterInternal.h	2022-02-19 00:44:12 UTC (rev 290186)
@@ -37,6 +37,9 @@
 @end
 
 @protocol _WKWebViewPrintProvider <NSObject>
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+@property (nonatomic, readonly) BOOL _wk_printFormatterRequiresMainThread;
+#endif
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter;
 @property (nonatomic, readonly) CGPDFDocumentRef _wk_printedDocument;
 @end

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -70,6 +70,7 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
 #import <wtf/text/TextStream.h>
+#import <wtf/threads/BinarySemaphore.h>
 #import "AppKitSoftLink.h"
 
 
@@ -147,6 +148,9 @@
     RetainPtr<NSUndoManager> _undoManager;
     RetainPtr<WKQuirkyNSUndoManager> _quirkyUndoManager;
 
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+    BinarySemaphore _pdfPrintCompletionSemaphore;
+#endif
     uint64_t _pdfPrintCallbackID;
     RetainPtr<CGPDFDocumentRef> _printedDocument;
     Vector<RetainPtr<NSURL>> _temporaryURLsToDeleteWhenDeallocated;
@@ -687,6 +691,10 @@
     [self _removeVisibilityPropagationViewForWebProcess];
 #endif
 
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+    if (_pdfPrintCallbackID)
+        _pdfPrintCompletionSemaphore.signal();
+#endif
     _pdfPrintCallbackID = 0;
 }
 
@@ -861,11 +869,23 @@
 
 @implementation WKContentView (_WKWebViewPrintFormatter)
 
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
+- (BOOL)_wk_printFormatterRequiresMainThread
+{
+    return NO;
+}
+
+#endif // HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
 {
-    if (_pdfPrintCallbackID)
-        [self _waitForDrawToPDFCallback];
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+    ASSERT(!isMainRunLoop());
+#endif
 
+    [self _waitForDrawToPDFCallbackIfNeeded];
+
     WebCore::FrameIdentifier frameID;
     if (_WKFrameHandle *handle = printFormatter.frameToPrint)
         frameID = handle->_frameHandle->frameID();
@@ -896,25 +916,56 @@
     printInfo.availablePaperWidth = CGRectGetWidth(printingRect);
     printInfo.availablePaperHeight = CGRectGetHeight(printingRect);
 
-    auto retainedSelf = retainPtr(self);
-    auto pair = _page->computePagesForPrintingAndDrawToPDF(frameID, printInfo, [retainedSelf](const IPC::SharedBufferCopy& pdfData) {
-        retainedSelf->_pdfPrintCallbackID = 0;
+    size_t pageCount;
+    if (printInfo.snapshotFirstPage)
+        pageCount = 1;
+    else {
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+        BinarySemaphore computePagesSemaphore;
+        callOnMainRunLoop([self, frameID, printInfo, &pageCount, &computePagesSemaphore]() mutable {
+            _page->computePagesForPrinting(frameID, printInfo, [&pageCount, &computePagesSemaphore](const Vector<WebCore::IntRect>& pageRects, double /* totalScaleFactorForPrinting */, const WebCore::FloatBoxExtent& /* computedPageMargin */) mutable {
+                ASSERT(pageRects.size() >= 1);
+                pageCount = pageRects.size();
+
+                computePagesSemaphore.signal();
+            });
+        });
+        computePagesSemaphore.wait();
+#else
+        pageCount = _page->computePagesForPrintingiOS(frameID, printInfo);
+#endif
+    }
+
+    // Begin generating the PDF in expectation of a (eventual) request for the drawn data.
+    _pdfPrintCallbackID = _page->drawToPDFiOS(frameID, printInfo, pageCount, [retainedSelf = retainPtr(self)](const IPC::SharedBufferCopy& pdfData) {
         if (pdfData.isEmpty())
-            return;
+            retainedSelf->_printedDocument = nullptr;
+        else {
+            auto data = ""
+            auto dataProvider = adoptCF(CGDataProviderCreateWithCFData(data.get()));
+            retainedSelf->_printedDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
+        }
 
-        auto data = ""
-        auto dataProvider = adoptCF(CGDataProviderCreateWithCFData(data.get()));
-        retainedSelf->_printedDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+        retainedSelf->_pdfPrintCompletionSemaphore.signal();
+#endif
+        retainedSelf->_pdfPrintCallbackID = 0;
     });
-    _pdfPrintCallbackID = pair.second;
-    return pair.first;
+
+    return pageCount;
 }
 
-- (BOOL)_waitForDrawToPDFCallback
+- (BOOL)_waitForDrawToPDFCallbackIfNeeded
 {
-    ASSERT(_pdfPrintCallbackID);
-    if (!_page->process().connection()->waitForAsyncCallbackAndDispatchImmediately<Messages::WebPage::DrawToPDFiOS>(std::exchange(_pdfPrintCallbackID, 0), Seconds::infinity()))
-        return false;
+    if (auto callbackID = std::exchange(_pdfPrintCallbackID, 0)) {
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+        ASSERT(!isMainRunLoop());
+        _pdfPrintCompletionSemaphore.wait();
+#else
+        if (!_page->process().connection()->waitForAsyncCallbackAndDispatchImmediately<Messages::WebPage::DrawToPDFiOS>(callbackID, Seconds::infinity()))
+            return false;
+#endif
+    }
     ASSERT(!_pdfPrintCallbackID);
     return true;
 }
@@ -921,11 +972,13 @@
 
 - (CGPDFDocumentRef)_wk_printedDocument
 {
-    if (_pdfPrintCallbackID) {
-        if (![self _waitForDrawToPDFCallback])
-            return nullptr;
-    }
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+    ASSERT(!isMainRunLoop());
+#endif
 
+    if (![self _waitForDrawToPDFCallbackIfNeeded])
+        return nullptr;
+
     return _printedDocument.get();
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -629,6 +629,15 @@
     return _documentForPrinting.get();
 }
 
+#if HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
+- (BOOL)_wk_printFormatterRequiresMainThread
+{
+    return YES;
+}
+
+#endif // HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
 {
     CGPDFDocumentRef documentForPrinting = [self _ensureDocumentForPrinting];

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1028,22 +1028,30 @@
     pageClient().handleSmartMagnificationInformationForPotentialTap(requestID, renderRect, fitEntireRect, viewportMinimumScale, viewportMaximumScale, nodeIsRootLevel);
 }
 
-std::pair<size_t, uint64_t> WebPageProxy::computePagesForPrintingAndDrawToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const IPC::SharedBufferCopy&)>&& callback)
+#if !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
+size_t WebPageProxy::computePagesForPrintingiOS(FrameIdentifier frameID, const PrintInfo& printInfo)
 {
+    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.");
+
+    if (!hasRunningProcess())
+        return 0;
+
+    size_t pageCount = 0;
+    sendSync(Messages::WebPage::ComputePagesForPrintingiOS(frameID, printInfo), Messages::WebPage::ComputePagesForPrintingiOS::Reply(pageCount), Seconds::infinity());
+    return pageCount;
+}
+
+#endif // !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
+uint64_t WebPageProxy::drawToPDFiOS(FrameIdentifier frameID, const PrintInfo& printInfo, size_t pageCount, CompletionHandler<void(const IPC::SharedBufferCopy&)>&& completionHandler)
+{
     if (!hasRunningProcess()) {
-        callback({ });
-        return { 0, 0 };
+        completionHandler({ });
+        return 0;
     }
 
-    size_t pageCount = 0;
-    if (printInfo.snapshotFirstPage)
-        pageCount = 1;
-    else
-        sendSync(Messages::WebPage::ComputePagesForPrintingiOS(frameID, printInfo), Messages::WebPage::ComputePagesForPrintingiOS::Reply(pageCount), Seconds::infinity());
-
-    auto callbackID = sendWithAsyncReply(Messages::WebPage::DrawToPDFiOS(frameID, printInfo, pageCount), WTFMove(callback));
-    
-    return { pageCount, callbackID };
+    return sendWithAsyncReply(Messages::WebPage::DrawToPDFiOS(frameID, printInfo, pageCount), WTFMove(completionHandler));
 }
 
 void WebPageProxy::contentSizeCategoryDidChange(const String& contentSizeCategory)

Modified: trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm (290185 => 290186)


--- trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -362,7 +362,7 @@
         std::unique_ptr<IPCCallbackContext> contextDeleter(context);
         pageDidComputePageRects(pageRects, totalScaleFactorForPrinting, computedPageMargin, context);
     };
-    _expectedComputedPagesCallback = _webFrame->page()->computePagesForPrinting(_webFrame.get(), WebKit::PrintInfo([_printOperation.get() printInfo]), WTFMove(callback));
+    _expectedComputedPagesCallback = _webFrame->page()->computePagesForPrinting(_webFrame->frameID(), WebKit::PrintInfo([_printOperation.get() printInfo]), WTFMove(callback));
     context->view = self;
     context->callbackID = _expectedComputedPagesCallback;
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (290185 => 290186)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-19 00:44:12 UTC (rev 290186)
@@ -1029,7 +1029,9 @@
 #endif
 
 #if PLATFORM(IOS_FAMILY)
+#if !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
     void computePagesForPrintingiOS(WebCore::FrameIdentifier, const PrintInfo&, Messages::WebPage::ComputePagesForPrintingiOSDelayedReply&&);
+#endif
     void drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t, Messages::WebPage::DrawToPDFiOSAsyncReply&&);
 #endif
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (290185 => 290186)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-19 00:44:12 UTC (rev 290186)
@@ -426,7 +426,9 @@
     DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize) -> (WebKit::ShareableBitmap::Handle image) Async
     DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count) -> (IPC::SharedBufferCopy data) Async
 #if PLATFORM(IOS_FAMILY)
+#if !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
     ComputePagesForPrintingiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (size_t pageCount) Synchronous
+#endif
     DrawToPDFiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, size_t pageCount) -> (IPC::SharedBufferCopy data) Async
 #endif
     DrawToPDF(WebCore::FrameIdentifier frameID, std::optional<WebCore::FloatRect> rect) -> (IPC::SharedBufferCopy data) Async

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (290185 => 290186)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-02-19 00:40:18 UTC (rev 290185)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-02-19 00:44:12 UTC (rev 290186)
@@ -4290,6 +4290,8 @@
 }
 #endif
 
+#if !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
 void WebPage::computePagesForPrintingiOS(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, Messages::WebPage::ComputePagesForPrintingiOS::DelayedReply&& reply)
 {
     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.");
@@ -4303,6 +4305,8 @@
     reply(pageRects.size());
 }
 
+#endif // !HAVE(UIKIT_BACKGROUND_THREAD_PRINTING)
+
 void WebPage::drawToPDFiOS(WebCore::FrameIdentifier frameID, const PrintInfo& printInfo, size_t pageCount, Messages::WebPage::DrawToPDFiOSAsyncReply&& reply)
 {
     if (printInfo.snapshotFirstPage) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to