<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[172112] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/172112">172112</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2014-08-05 17:54:04 -0700 (Tue, 05 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS WK2] Crash going back on a specific tumblr blog (under ScrollingStateTree::removeNodeAndAllDescendants)
https://bugs.webkit.org/show_bug.cgi?id=135629
&lt;rdar://problem/17802174&gt;

Reviewed by Tim Horton.

Source/WebCore:

In <a href="http://trac.webkit.org/projects/webkit/changeset/170198">r170198</a> I added an &quot;orphan scrolling nodes&quot; code path that sets aside subtrees
of scrolling nodes into an m_orphanedSubframeNodes map, which keeps them alive until
they get reparented or destroyed. The nodes in that subtree remain in m_stateNodeMap,
which holds raw pointers to them.

However, ScrollingStateTree::commit() can clear m_orphanedSubframeNodes, which is
sometimes non-empty at this point. When that happened, we would destroy nodes which
were still referenced by m_stateNodeMap, with the result that a later query for the
same nodeID would hand back a pointer to a deleted object.

Fix by calling recursiveNodeWillBeRemoved() on nodes in the m_orphanedSubframeNodes
before clearing it, which removes them and all their descendants from the state node map.

Test: platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html

* page/scrolling/ScrollingStateTree.cpp:
(WebCore::ScrollingStateTree::clear):
(WebCore::ScrollingStateTree::commit):

LayoutTests:

Testcase with nesting of frames inside fixed inside frames, where a subframe disconnects
part of the scrolling tree.

* platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt: Added.
* platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html: Added.
* platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html: Added.
* platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateTreecpp">trunk/Source/WebCore/page/scrolling/ScrollingStateTree.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesorphanedsubtreeexpectedtxt">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesorphanedsubtreehtml">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesresourcesleafframehtml">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesresourcessubframeinsidefixedhtml">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (172111 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-08-05 23:44:24 UTC (rev 172111)
+++ trunk/LayoutTests/ChangeLog        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-08-05  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS WK2] Crash going back on a specific tumblr blog (under ScrollingStateTree::removeNodeAndAllDescendants)
+        https://bugs.webkit.org/show_bug.cgi?id=135629
+        &lt;rdar://problem/17802174&gt;
+
+        Reviewed by Tim Horton.
+        
+        Testcase with nesting of frames inside fixed inside frames, where a subframe disconnects
+        part of the scrolling tree.
+
+        * platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt: Added.
+        * platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html: Added.
+        * platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html: Added.
+        * platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html: Added.
+
</ins><span class="cx"> 2014-08-05  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         The JIT should cache property lookup misses.
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesorphanedsubtreeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt (0 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree-expected.txt        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+This test passes if it does not crash on the reload.
+
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesorphanedsubtreehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html (0 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+    &lt;script&gt;
+        if (window.testRunner) {
+            testRunner.waitUntilDone();
+            testRunner.dumpAsText();
+            window.internals.settings.setScrollingTreeIncludesFrames(true);
+        }
+
+        function childFrameTestDone()
+        {
+            // Avoid infinite reload in the non-DRT case.
+            if (window.location.search)
+                return;
+
+            window.location += '?done=true';
+        }
+        
+        function checkForDoneTest()
+        {
+            if (window.location.search) {
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }
+        }
+        
+        window.addEventListener('load', checkForDoneTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;p&gt;This test passes if it does not crash on the reload.&lt;/p&gt;
+    &lt;iframe id=&quot;iframe&quot; src=&quot;resources/subframe-inside-fixed.html&quot; scrolling=&quot;no&quot; width=&quot;500&quot; height=&quot;300&quot;&gt;&lt;/iframe&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesresourcesleafframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html (0 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/leaf-frame.html        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .box {
+            height: 100px;
+            width: 100px;
+            background-color: blue;
+            position: fixed;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div class=&quot;box&quot;&gt;&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingframesresourcessubframeinsidefixedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html (0 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/frames/resources/subframe-inside-fixed.html        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .fixed {
+            position: fixed;
+            border: 1px solid red;
+        }
+        
+        .removed {
+            display: none;
+        }
+        
+    &lt;/style&gt;
+    &lt;script&gt;
+        function subframeLoaded()
+        {
+            window.setTimeout(function() {
+                document.getElementById('container').classList.add('removed');
+                window.parent.childFrameTestDone();
+            }, 0);
+        }
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;fixed&quot; id=&quot;container&quot;&gt;
+        &lt;iframe onload=&quot;subframeLoaded()&quot; src=&quot;leaf-frame.html&quot;&gt;&lt;/iframe&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (172111 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-08-05 23:44:24 UTC (rev 172111)
+++ trunk/Source/WebCore/ChangeLog        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-08-05  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS WK2] Crash going back on a specific tumblr blog (under ScrollingStateTree::removeNodeAndAllDescendants)
+        https://bugs.webkit.org/show_bug.cgi?id=135629
+        &lt;rdar://problem/17802174&gt;
+
+        Reviewed by Tim Horton.
+        
+        In r170198 I added an &quot;orphan scrolling nodes&quot; code path that sets aside subtrees
+        of scrolling nodes into an m_orphanedSubframeNodes map, which keeps them alive until
+        they get reparented or destroyed. The nodes in that subtree remain in m_stateNodeMap,
+        which holds raw pointers to them.
+        
+        However, ScrollingStateTree::commit() can clear m_orphanedSubframeNodes, which is
+        sometimes non-empty at this point. When that happened, we would destroy nodes which
+        were still referenced by m_stateNodeMap, with the result that a later query for the
+        same nodeID would hand back a pointer to a deleted object.
+        
+        Fix by calling recursiveNodeWillBeRemoved() on nodes in the m_orphanedSubframeNodes
+        before clearing it, which removes them and all their descendants from the state node map.
+
+        Test: platform/mac-wk2/tiled-drawing/scrolling/frames/orphaned-subtree.html
+
+        * page/scrolling/ScrollingStateTree.cpp:
+        (WebCore::ScrollingStateTree::clear):
+        (WebCore::ScrollingStateTree::commit):
+
</ins><span class="cx"> 2014-08-05  Peyton Randolph  &lt;prandolph@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add the ability to force text to render in white, not just black
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateTree.cpp (172111 => 172112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateTree.cpp        2014-08-05 23:44:24 UTC (rev 172111)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateTree.cpp        2014-08-06 00:54:04 UTC (rev 172112)
</span><span class="lines">@@ -152,14 +152,19 @@
</span><span class="cx">     if (rootStateNode())
</span><span class="cx">         removeNodeAndAllDescendants(rootStateNode());
</span><span class="cx"> 
</span><del>-    ASSERT(m_stateNodeMap.isEmpty());
</del><span class="cx">     m_stateNodeMap.clear();
</span><span class="cx">     m_orphanedSubframeNodes.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassOwnPtr&lt;ScrollingStateTree&gt; ScrollingStateTree::commit(LayerRepresentation::Type preferredLayerRepresentation)
</span><span class="cx"> {
</span><del>-    m_orphanedSubframeNodes.clear();
</del><ins>+    if (!m_orphanedSubframeNodes.isEmpty()) {
+        // If we still have orphaned subtrees, remove them from m_stateNodeMap since they will be deleted 
+        // when clearing m_orphanedSubframeNodes.
+        for (auto&amp; orphanNode : m_orphanedSubframeNodes.values())
+            recursiveNodeWillBeRemoved(orphanNode.get(), SubframeNodeRemoval::Delete);
+        m_orphanedSubframeNodes.clear();
+    }
</ins><span class="cx"> 
</span><span class="cx">     // This function clones and resets the current state tree, but leaves the tree structure intact.
</span><span class="cx">     OwnPtr&lt;ScrollingStateTree&gt; treeStateClone = ScrollingStateTree::create();
</span></span></pre>
</div>
</div>

</body>
</html>