Title: [282496] releases/WebKitGTK/webkit-2.32/Source/WebKit
Revision
282496
Author
[email protected]
Date
2021-09-16 01:00:07 -0700 (Thu, 16 Sep 2021)

Log Message

Merge r275549 - Delay the end of printing while PrintContext is in use.
https://bugs.webkit.org/show_bug.cgi?id=224229

Reviewed by Antti Koivisto.

Added a new RAII object, PrintContextAccessScope, to delay the call to endPrinting
and deployed in various IPC messages used during printing.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::beginPrinting): Deployed PrintContextAccessScope.
(WebKit::WebPage::endPrinting): Exit early without ending printing if there is an active
PrintContextAccessScope in the stack.
(WebKit::WebPage::endPrintingImmediately): Extracted from endPrintingImmediately.
(WebKit::WebPage::computePagesForPrinting): Deployed PrintContextAccessScope.
(WebKit::WebPage::computePagesForPrintingImpl): Ditto.
(WebKit::WebPage::drawRectToImage): Ditto.
(WebKit::WebPage::drawPagesToPDF): Ditto.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::PrintContextAccessScope): Added.
(WebKit::WebPage::PrintContextAccessScope::PrintContextAccessScope): Added.
(WebKit::WebPage::PrintContextAccessScope::~PrintContextAccessScope): Added.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog (282495 => 282496)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog	2021-09-16 08:00:00 UTC (rev 282495)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog	2021-09-16 08:00:07 UTC (rev 282496)
@@ -1,3 +1,27 @@
+2021-04-06  Ryosuke Niwa  <[email protected]>
+
+        Delay the end of printing while PrintContext is in use.
+        https://bugs.webkit.org/show_bug.cgi?id=224229
+
+        Reviewed by Antti Koivisto.
+
+        Added a new RAII object, PrintContextAccessScope, to delay the call to endPrinting
+        and deployed in various IPC messages used during printing.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::beginPrinting): Deployed PrintContextAccessScope.
+        (WebKit::WebPage::endPrinting): Exit early without ending printing if there is an active
+        PrintContextAccessScope in the stack.
+        (WebKit::WebPage::endPrintingImmediately): Extracted from endPrintingImmediately.
+        (WebKit::WebPage::computePagesForPrinting): Deployed PrintContextAccessScope.
+        (WebKit::WebPage::computePagesForPrintingImpl): Ditto.
+        (WebKit::WebPage::drawRectToImage): Ditto.
+        (WebKit::WebPage::drawPagesToPDF): Ditto.
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::PrintContextAccessScope): Added.
+        (WebKit::WebPage::PrintContextAccessScope::PrintContextAccessScope): Added.
+        (WebKit::WebPage::PrintContextAccessScope::~PrintContextAccessScope): Added.
+
 2021-03-09  Chris Dumez  <[email protected]>
 
         [IPC Hardening] Protect against bad input in WebProcessProxy::createSpeechRecognitionServer() and MessageReceiverMap

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.cpp (282495 => 282496)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-09-16 08:00:00 UTC (rev 282495)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-09-16 08:00:07 UTC (rev 282496)
@@ -5100,6 +5100,8 @@
 
 void WebPage::beginPrinting(FrameIdentifier frameID, const PrintInfo& printInfo)
 {
+    PrintContextAccessScope scope { *this };
+
     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     if (!frame)
         return;
@@ -5121,6 +5123,7 @@
     freezeLayerTree(LayerTreeFreezeReason::Printing);
 
     auto computedPageSize = m_printContext->computedPageSize(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight), printInfo.margin);
+
     m_printContext->begin(computedPageSize.width(), computedPageSize.height());
 
     // PrintContext::begin() performed a synchronous layout which might have executed a
@@ -5142,6 +5145,18 @@
 
 void WebPage::endPrinting()
 {
+    if (m_inActivePrintContextAccessScope) {
+        m_shouldEndPrintingImmediately = true;
+        return;
+    }
+    endPrintingImmediately();
+}
+
+void WebPage::endPrintingImmediately()
+{
+    RELEASE_ASSERT(!m_inActivePrintContextAccessScope);
+    m_shouldEndPrintingImmediately = false;
+
     unfreezeLayerTree(LayerTreeFreezeReason::Printing);
 
     if (m_printContext) {
@@ -5152,6 +5167,7 @@
 
 void WebPage::computePagesForPrinting(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& completionHandler)
 {
+    PrintContextAccessScope scope { *this };
     Vector<IntRect> resultPageRects;
     double resultTotalScaleFactorForPrinting = 1;
     auto computedPageMargin = printInfo.margin;
@@ -5166,6 +5182,7 @@
     beginPrinting(frameID, printInfo);
 
     if (m_printContext) {
+        PrintContextAccessScope scope { *this };
         resultPageRects = m_printContext->pageRects();
         computedPageMargin = m_printContext->computedPageMargin(printInfo.margin);
         auto computedPageSize = m_printContext->computedPageSize(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight), printInfo.margin);
@@ -5212,6 +5229,7 @@
 
 void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler)
 {
+    PrintContextAccessScope scope { *this };
     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     Frame* coreFrame = frame ? frame->coreFrame() : 0;
 
@@ -5262,6 +5280,7 @@
 
 void WebPage::drawPagesToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, CompletionHandler<void(const IPC::DataReference&)>&& callback)
 {
+    PrintContextAccessScope scope { *this };
     RetainPtr<CFMutableDataRef> pdfPageData;
     drawPagesToPDFImpl(frameID, printInfo, first, count, pdfPageData);
     callback({ CFDataGetBytePtr(pdfPageData.get()), static_cast<size_t>(CFDataGetLength(pdfPageData.get())) });

Modified: releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.h (282495 => 282496)


--- releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-09-16 08:00:00 UTC (rev 282495)
+++ releases/WebKitGTK/webkit-2.32/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-09-16 08:00:07 UTC (rev 282496)
@@ -1640,6 +1640,8 @@
     void drawPagesToPDFFromPDFDocument(CGContextRef, PDFDocument *, const PrintInfo&, uint32_t first, uint32_t count);
 #endif
 
+    void endPrintingImmediately();
+
 #if HAVE(APP_ACCENT_COLORS)
     void setAccentColor(WebCore::Color);
 #endif
@@ -2010,6 +2012,31 @@
 #endif
 
     std::unique_ptr<WebCore::PrintContext> m_printContext;
+    bool m_inActivePrintContextAccessScope { false };
+    bool m_shouldEndPrintingImmediately { false };
+
+    class PrintContextAccessScope {
+    public:
+        PrintContextAccessScope(WebPage& webPage)
+            : m_webPage { webPage }
+            , m_wasInActivePrintContextAccessScope { webPage.m_inActivePrintContextAccessScope }
+        {
+            m_webPage->m_inActivePrintContextAccessScope = true;
+        }
+
+        ~PrintContextAccessScope()
+        {
+            m_webPage->m_inActivePrintContextAccessScope = m_wasInActivePrintContextAccessScope;
+            if (!m_wasInActivePrintContextAccessScope && m_webPage->m_shouldEndPrintingImmediately)
+                m_webPage->endPrintingImmediately();
+        }
+    private:
+        Ref<WebPage> m_webPage;
+        const bool m_wasInActivePrintContextAccessScope;
+    };
+
+    friend class PrintContextAccessScope;
+
 #if PLATFORM(GTK)
     RefPtr<WebPrintOperationGtk> m_printOperation;
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to