Diff
Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/ChangeLog 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog 2017-06-01 19:51:58 UTC (rev 217676)
@@ -1,3 +1,45 @@
+2017-06-01 Matthew Hanson <[email protected]>
+
+ Cherry-pick r210226. rdar://problem/32080671
+
+ 2017-01-02 Andreas Kling <[email protected]>
+
+ Drop the render tree for documents in the page cache.
+ <https://webkit.org/b/121798>
+
+ Reviewed by Antti Koivisto.
+
+ To save memory and reduce complexity, have documents tear down their render tree
+ when entering the page cache. I've wanted to do this for a long time and it seems
+ like we can actually do it now.
+
+ This patch will enable a number of clean-ups since it's no longer valid for renderers
+ to exist while the document is in page cache.
+
+ * dom/Document.cpp:
+ (WebCore::Document::destroyRenderTree): Remove assertion that we're not in the page cache
+ since we will now be tearing down render trees right as they enter the page cache.
+
+ * dom/PageCache.cpp:
+ (WebCore::destroyRenderTree):
+ (WebCore::PageCache::addIfCacheable): Tear down the render tree right before setting
+ the in-cache flag. The render tree is destroyed in bottom-up order to ensure that the
+ main frame renderers die last.
+
+ * history/CachedFrame.cpp:
+ (WebCore::CachedFrameBase::restore):
+ * page/FrameView.h:
+ * page/FrameView.cpp:
+ (WebCore::FrameView::didRestoreFromPageCache): Update the scollable area set after restoring
+ a frame from the page cache. This dirties the scrolling tree, which was covered by tests.
+
+ * page/animation/AnimationBase.cpp:
+ (WebCore::AnimationBase::setNeedsStyleRecalc):
+ * page/animation/AnimationController.cpp:
+ (WebCore::AnimationController::cancelAnimations): Make these no-ops if called
+ while the render tree is being torn down. This fixes some assertion failures
+ on layout tests and avoids pointless style invalidation.
+
2017-05-25 Jason Marcell <[email protected]>
Cherry-pick r217439. rdar://problem/32089229
Modified: branches/safari-603-branch/Source/WebCore/dom/Document.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/dom/Document.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/dom/Document.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -2237,7 +2237,6 @@
void Document::destroyRenderTree()
{
ASSERT(hasLivingRenderTree());
- ASSERT(m_pageCacheState != InPageCache);
FrameView* frameView = frame()->document() == this ? frame()->view() : nullptr;
Modified: branches/safari-603-branch/Source/WebCore/history/CachedFrame.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/history/CachedFrame.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/history/CachedFrame.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -120,6 +120,7 @@
m_document->page()->chrome().client().needTouchEvents(true);
#endif
+ frame.view()->didRestoreFromPageCache();
}
CachedFrame::CachedFrame(Frame& frame)
Modified: branches/safari-603-branch/Source/WebCore/history/PageCache.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/history/PageCache.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/history/PageCache.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -377,6 +377,20 @@
}
}
+// When entering page cache, tear down the render tree before setting the in-cache flag.
+// This maintains the invariant that render trees are never present in the page cache.
+// Note that destruction happens bottom-up so that the main frame's tree dies last.
+static void destroyRenderTree(MainFrame& mainFrame)
+{
+ for (Frame* frame = mainFrame.tree().traversePreviousWithWrap(true); frame; frame = frame->tree().traversePreviousWithWrap(false)) {
+ if (!frame->document())
+ continue;
+ auto& document = *frame->document();
+ if (document.hasLivingRenderTree())
+ document.destroyRenderTree();
+ }
+}
+
static void firePageHideEventRecursively(Frame& frame)
{
auto* document = frame.document();
@@ -420,6 +434,8 @@
return;
}
+ destroyRenderTree(page->mainFrame());
+
setPageCacheState(*page, Document::InPageCache);
// Make sure we no longer fire any JS events past this point.
Modified: branches/safari-603-branch/Source/WebCore/page/FrameView.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/page/FrameView.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/page/FrameView.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -657,6 +657,13 @@
ASSERT(!frame().animation().hasAnimations());
}
+void FrameView::didRestoreFromPageCache()
+{
+ // When restoring from page cache, the main frame stays in place while subframes get swapped in.
+ // We update the scrollable area set to ensure that scrolling data structures get invalidated.
+ updateScrollableAreaSet();
+}
+
void FrameView::setContentsSize(const IntSize& size)
{
if (size == contentsSize())
Modified: branches/safari-603-branch/Source/WebCore/page/FrameView.h (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/page/FrameView.h 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/page/FrameView.h 2017-06-01 19:51:58 UTC (rev 217676)
@@ -595,6 +595,8 @@
void willDestroyRenderTree();
void didDestroyRenderTree();
+ void didRestoreFromPageCache();
+
protected:
bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) override;
void scrollContentsSlowPath(const IntRect& updateRect) override;
Modified: branches/safari-603-branch/Source/WebCore/page/animation/AnimationBase.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/page/animation/AnimationBase.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/page/animation/AnimationBase.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -89,9 +89,11 @@
void AnimationBase::setNeedsStyleRecalc(Element* element)
{
- ASSERT(!element || element->document().pageCacheState() == Document::NotInPageCache);
- if (element)
- element->invalidateStyleAndLayerComposition();
+ if (!element || element->document().renderTreeBeingDestroyed())
+ return;
+
+ ASSERT(element->document().pageCacheState() == Document::NotInPageCache);
+ element->invalidateStyleAndLayerComposition();
}
double AnimationBase::duration() const
Modified: branches/safari-603-branch/Source/WebCore/page/animation/AnimationController.cpp (217675 => 217676)
--- branches/safari-603-branch/Source/WebCore/page/animation/AnimationController.cpp 2017-06-01 19:51:51 UTC (rev 217675)
+++ branches/safari-603-branch/Source/WebCore/page/animation/AnimationController.cpp 2017-06-01 19:51:58 UTC (rev 217676)
@@ -588,9 +588,10 @@
return;
Element* element = renderer.element();
- ASSERT(!element || element->document().pageCacheState() == Document::NotInPageCache);
- if (element)
- element->invalidateStyleAndLayerComposition();
+ if (!element || element->document().renderTreeBeingDestroyed())
+ return;
+ ASSERT(element->document().pageCacheState() == Document::NotInPageCache);
+ element->invalidateStyleAndLayerComposition();
}
bool AnimationController::updateAnimations(RenderElement& renderer, const RenderStyle& newStyle, std::unique_ptr<RenderStyle>& animatedStyle)