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

Changeset 275549 in webkit


Ignore:
Timestamp:
Apr 6, 2021, 1:57:44 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

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.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r275546 r275549  
     12021-04-06  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Delay the end of printing while PrintContext is in use.
     4        https://bugs.webkit.org/show_bug.cgi?id=224229
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Added a new RAII object, PrintContextAccessScope, to delay the call to endPrinting
     9        and deployed in various IPC messages used during printing.
     10
     11        * WebProcess/WebPage/WebPage.cpp:
     12        (WebKit::WebPage::beginPrinting): Deployed PrintContextAccessScope.
     13        (WebKit::WebPage::endPrinting): Exit early without ending printing if there is an active
     14        PrintContextAccessScope in the stack.
     15        (WebKit::WebPage::endPrintingImmediately): Extracted from endPrintingImmediately.
     16        (WebKit::WebPage::computePagesForPrinting): Deployed PrintContextAccessScope.
     17        (WebKit::WebPage::computePagesForPrintingImpl): Ditto.
     18        (WebKit::WebPage::drawRectToImage): Ditto.
     19        (WebKit::WebPage::drawPagesToPDF): Ditto.
     20        * WebProcess/WebPage/WebPage.h:
     21        (WebKit::WebPage::PrintContextAccessScope): Added.
     22        (WebKit::WebPage::PrintContextAccessScope::PrintContextAccessScope): Added.
     23        (WebKit::WebPage::PrintContextAccessScope::~PrintContextAccessScope): Added.
     24
    1252021-04-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    226
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r275527 r275549  
    50955095void WebPage::beginPrinting(FrameIdentifier frameID, const PrintInfo& printInfo)
    50965096{
     5097    PrintContextAccessScope scope { *this };
     5098
    50975099    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
    50985100    if (!frame)
    … …  
    51165118
    51175119    auto computedPageSize = m_printContext->computedPageSize(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight), printInfo.margin);
     5120
    51185121    m_printContext->begin(computedPageSize.width(), computedPageSize.height());
    51195122
    … …  
    51375140void WebPage::endPrinting()
    51385141{
     5142    if (m_inActivePrintContextAccessScope) {
     5143        m_shouldEndPrintingImmediately = true;
     5144        return;
     5145    }
     5146    endPrintingImmediately();
     5147}
     5148
     5149void WebPage::endPrintingImmediately()
     5150{
     5151    RELEASE_ASSERT(!m_inActivePrintContextAccessScope);
     5152    m_shouldEndPrintingImmediately = false;
     5153
    51395154    unfreezeLayerTree(LayerTreeFreezeReason::Printing);
    51405155
    … …  
    51475162void WebPage::computePagesForPrinting(FrameIdentifier frameID, const PrintInfo& printInfo, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&& completionHandler)
    51485163{
     5164    PrintContextAccessScope scope { *this };
    51495165    Vector<IntRect> resultPageRects;
    51505166    double resultTotalScaleFactorForPrinting = 1;
    … …  
    51615177
    51625178    if (m_printContext) {
     5179        PrintContextAccessScope scope { *this };
    51635180        resultPageRects = m_printContext->pageRects();
    51645181        computedPageMargin = m_printContext->computedPageMargin(printInfo.margin);
    … …  
    52075224void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler)
    52085225{
     5226    PrintContextAccessScope scope { *this };
    52095227    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
    52105228    Frame* coreFrame = frame ? frame->coreFrame() : 0;
    … …  
    52575275void WebPage::drawPagesToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, CompletionHandler<void(const IPC::DataReference&)>&& callback)
    52585276{
     5277    PrintContextAccessScope scope { *this };
    52595278    RetainPtr<CFMutableDataRef> pdfPageData;
    52605279    drawPagesToPDFImpl(frameID, printInfo, first, count, pdfPageData);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r275485 r275549  
    16601660#endif
    16611661
     1662    void endPrintingImmediately();
     1663
    16621664#if HAVE(APP_ACCENT_COLORS)
    16631665    void setAccentColor(WebCore::Color);
    … …  
    20362038
    20372039    std::unique_ptr<WebCore::PrintContext> m_printContext;
     2040    bool m_inActivePrintContextAccessScope { false };
     2041    bool m_shouldEndPrintingImmediately { false };
     2042
     2043    class PrintContextAccessScope {
     2044    public:
     2045        PrintContextAccessScope(WebPage& webPage)
     2046            : m_webPage { webPage }
     2047            , m_wasInActivePrintContextAccessScope { webPage.m_inActivePrintContextAccessScope }
     2048        {
     2049            m_webPage->m_inActivePrintContextAccessScope = true;
     2050        }
     2051
     2052        ~PrintContextAccessScope()
     2053        {
     2054            m_webPage->m_inActivePrintContextAccessScope = m_wasInActivePrintContextAccessScope;
     2055            if (!m_wasInActivePrintContextAccessScope && m_webPage->m_shouldEndPrintingImmediately)
     2056                m_webPage->endPrintingImmediately();
     2057        }
     2058    private:
     2059        Ref<WebPage> m_webPage;
     2060        const bool m_wasInActivePrintContextAccessScope;
     2061    };
     2062
     2063    friend class PrintContextAccessScope;
     2064
    20382065#if PLATFORM(GTK)
    20392066    RefPtr<WebPrintOperationGtk> m_printOperation;
Note: See TracChangeset for help on using the changeset viewer.