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

Changeset 239347 in webkit


Ignore:
Timestamp:
Dec 18, 2018, 12:09:32 PM (8 years ago)
Author:
Alan Bujtas
Message:

Synchronous media query evaluation could destroy current Frame/FrameView.
​https://bugs.webkit.org/show_bug.cgi?id=192781
<rdar://problem/34416793>

Reviewed by Chris Dumez.

Source/WebCore:

Protect Frame and FrameView when coming back from printing and check if the current Frame/FrameView/FrameLoader objects are still valid.

Test: printing/print-with-media-query-destory.html

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::finishedLoading):

  • page/Frame.cpp:

(WebCore::Frame::setPrinting):

  • page/FrameView.cpp:

(WebCore::FrameView::forceLayoutForPagination):

LayoutTests:

  • printing/print-with-media-query-destory-expected.txt: Added.
  • printing/print-with-media-query-destory.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r239343 r239347  
     12018-12-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        Synchronous media query evaluation could destroy current Frame/FrameView.
     4        https://bugs.webkit.org/show_bug.cgi?id=192781
     5        <rdar://problem/34416793>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * printing/print-with-media-query-destory-expected.txt: Added.
     10        * printing/print-with-media-query-destory.html: Added.
     11
    1122018-12-18  Joseph Pecoraro  <pecoraro@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r239343 r239347  
     12018-12-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        Synchronous media query evaluation could destroy current Frame/FrameView.
     4        https://bugs.webkit.org/show_bug.cgi?id=192781
     5        <rdar://problem/34416793>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Protect Frame and FrameView when coming back from printing and check if the current Frame/FrameView/FrameLoader objects are still valid.
     10
     11        Test: printing/print-with-media-query-destory.html
     12
     13        * loader/DocumentLoader.cpp:
     14        (WebCore::DocumentLoader::finishedLoading):
     15        * page/Frame.cpp:
     16        (WebCore::Frame::setPrinting):
     17        * page/FrameView.cpp:
     18        (WebCore::FrameView::forceLayoutForPagination):
     19
    1202018-12-18  Joseph Pecoraro  <pecoraro@apple.com>
    221
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r239219 r239347  
    436436        return;
    437437    clearMainResourceLoader();
     438    if (!frameLoader())
     439        return;
    438440    if (!frameLoader()->stateMachine().creatingInitialEmptyDocument())
    439441        frameLoader()->checkLoadComplete();
  • trunk/Source/WebCore/page/Frame.cpp

    r238811 r239347  
    662662void Frame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkRatio, AdjustViewSizeOrNot shouldAdjustViewSize)
    663663{
     664    if (!view())
     665        return;
    664666    // In setting printing, we should not validate resources already cached for the document.
    665667    // See https://bugs.webkit.org/show_bug.cgi?id=43704
    … …  
    667669
    668670    m_doc->setPrinting(printing);
    669     if (auto* frameView = view()) {
    670         frameView->adjustMediaTypeForPrinting(printing);
    671 
    672         m_doc->styleScope().didChangeStyleSheetEnvironment();
    673         if (shouldUsePrintingLayout())
    674             frameView->forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
    675         else {
    676             frameView->forceLayout();
    677             if (shouldAdjustViewSize == AdjustViewSize)
    678                 frameView->adjustViewSize();
    679         }
     671    auto& frameView = *view();
     672    frameView.adjustMediaTypeForPrinting(printing);
     673
     674    m_doc->styleScope().didChangeStyleSheetEnvironment();
     675    if (shouldUsePrintingLayout())
     676        frameView.forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
     677    else {
     678        frameView.forceLayout();
     679        if (shouldAdjustViewSize == AdjustViewSize)
     680            frameView.adjustViewSize();
    680681    }
    681682
  • trunk/Source/WebCore/page/FrameView.cpp

    r238837 r239347  
    45874587void FrameView::forceLayoutForPagination(const FloatSize& pageSize, const FloatSize& originalPageSize, float maximumShrinkFactor, AdjustViewSizeOrNot shouldAdjustViewSize)
    45884588{
     4589    if (!renderView())
     4590        return;
     4591
     4592    Ref<FrameView> protectedThis(*this);
     4593    auto& renderView = *this->renderView();
     4594
    45894595    // Dumping externalRepresentation(frame().renderer()).ascii() is a good trick to see
    45904596    // the state of things before and after the layout
    4591     if (RenderView* renderView = this->renderView()) {
    4592         float pageLogicalWidth = renderView->style().isHorizontalWritingMode() ? pageSize.width() : pageSize.height();
    4593         float pageLogicalHeight = renderView->style().isHorizontalWritingMode() ? pageSize.height() : pageSize.width();
    4594 
    4595         renderView->setPageLogicalSize({ floor(pageLogicalWidth), floor(pageLogicalHeight) });
    4596         renderView->setNeedsLayoutAndPrefWidthsRecalc();
     4597    float pageLogicalWidth = renderView.style().isHorizontalWritingMode() ? pageSize.width() : pageSize.height();
     4598    float pageLogicalHeight = renderView.style().isHorizontalWritingMode() ? pageSize.height() : pageSize.width();
     4599
     4600    renderView.setPageLogicalSize({ floor(pageLogicalWidth), floor(pageLogicalHeight) });
     4601    renderView.setNeedsLayoutAndPrefWidthsRecalc();
     4602    forceLayout();
     4603    if (hasOneRef())
     4604        return;
     4605
     4606    // If we don't fit in the given page width, we'll lay out again. If we don't fit in the
     4607    // page width when shrunk, we will lay out at maximum shrink and clip extra content.
     4608    // FIXME: We are assuming a shrink-to-fit printing implementation. A cropping
     4609    // implementation should not do this!
     4610    bool horizontalWritingMode = renderView.style().isHorizontalWritingMode();
     4611    const LayoutRect& documentRect = renderView.documentRect();
     4612    LayoutUnit docLogicalWidth = horizontalWritingMode ? documentRect.width() : documentRect.height();
     4613    if (docLogicalWidth > pageLogicalWidth) {
     4614        int expectedPageWidth = std::min<float>(documentRect.width(), pageSize.width() * maximumShrinkFactor);
     4615        int expectedPageHeight = std::min<float>(documentRect.height(), pageSize.height() * maximumShrinkFactor);
     4616        FloatSize maxPageSize = frame().resizePageRectsKeepingRatio(FloatSize(originalPageSize.width(), originalPageSize.height()), FloatSize(expectedPageWidth, expectedPageHeight));
     4617        pageLogicalWidth = horizontalWritingMode ? maxPageSize.width() : maxPageSize.height();
     4618        pageLogicalHeight = horizontalWritingMode ? maxPageSize.height() : maxPageSize.width();
     4619
     4620        renderView.setPageLogicalSize({ floor(pageLogicalWidth), floor(pageLogicalHeight) });
     4621        renderView.setNeedsLayoutAndPrefWidthsRecalc();
    45974622        forceLayout();
    4598 
    4599         // If we don't fit in the given page width, we'll lay out again. If we don't fit in the
    4600         // page width when shrunk, we will lay out at maximum shrink and clip extra content.
    4601         // FIXME: We are assuming a shrink-to-fit printing implementation.  A cropping
    4602         // implementation should not do this!
    4603         bool horizontalWritingMode = renderView->style().isHorizontalWritingMode();
    4604         const LayoutRect& documentRect = renderView->documentRect();
    4605         LayoutUnit docLogicalWidth = horizontalWritingMode ? documentRect.width() : documentRect.height();
    4606         if (docLogicalWidth > pageLogicalWidth) {
    4607             int expectedPageWidth = std::min<float>(documentRect.width(), pageSize.width() * maximumShrinkFactor);
    4608             int expectedPageHeight = std::min<float>(documentRect.height(), pageSize.height() * maximumShrinkFactor);
    4609             FloatSize maxPageSize = frame().resizePageRectsKeepingRatio(FloatSize(originalPageSize.width(), originalPageSize.height()), FloatSize(expectedPageWidth, expectedPageHeight));
    4610             pageLogicalWidth = horizontalWritingMode ? maxPageSize.width() : maxPageSize.height();
    4611             pageLogicalHeight = horizontalWritingMode ? maxPageSize.height() : maxPageSize.width();
    4612 
    4613             renderView->setPageLogicalSize({ floor(pageLogicalWidth), floor(pageLogicalHeight) });
    4614             renderView->setNeedsLayoutAndPrefWidthsRecalc();
    4615             forceLayout();
    4616 
    4617             const LayoutRect& updatedDocumentRect = renderView->documentRect();
    4618             LayoutUnit docLogicalHeight = horizontalWritingMode ? updatedDocumentRect.height() : updatedDocumentRect.width();
    4619             LayoutUnit docLogicalTop = horizontalWritingMode ? updatedDocumentRect.y() : updatedDocumentRect.x();
    4620             LayoutUnit docLogicalRight = horizontalWritingMode ? updatedDocumentRect.maxX() : updatedDocumentRect.maxY();
    4621             LayoutUnit clippedLogicalLeft;
    4622             if (!renderView->style().isLeftToRightDirection())
    4623                 clippedLogicalLeft = docLogicalRight - pageLogicalWidth;
    4624             LayoutRect overflow(clippedLogicalLeft, docLogicalTop, pageLogicalWidth, docLogicalHeight);
    4625 
    4626             if (!horizontalWritingMode)
    4627                 overflow = overflow.transposedRect();
    4628             renderView->clearLayoutOverflow();
    4629             renderView->addLayoutOverflow(overflow); // This is how we clip in case we overflow again.
    4630         }
     4623        if (hasOneRef())
     4624            return;
     4625
     4626        const LayoutRect& updatedDocumentRect = renderView.documentRect();
     4627        LayoutUnit docLogicalHeight = horizontalWritingMode ? updatedDocumentRect.height() : updatedDocumentRect.width();
     4628        LayoutUnit docLogicalTop = horizontalWritingMode ? updatedDocumentRect.y() : updatedDocumentRect.x();
     4629        LayoutUnit docLogicalRight = horizontalWritingMode ? updatedDocumentRect.maxX() : updatedDocumentRect.maxY();
     4630        LayoutUnit clippedLogicalLeft;
     4631        if (!renderView.style().isLeftToRightDirection())
     4632            clippedLogicalLeft = docLogicalRight - pageLogicalWidth;
     4633        LayoutRect overflow(clippedLogicalLeft, docLogicalTop, pageLogicalWidth, docLogicalHeight);
     4634
     4635        if (!horizontalWritingMode)
     4636            overflow = overflow.transposedRect();
     4637        renderView.clearLayoutOverflow();
     4638        renderView.addLayoutOverflow(overflow); // This is how we clip in case we overflow again.
    46314639    }
    46324640
Note: See TracChangeset for help on using the changeset viewer.