<!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>[184603] branches/safari-600.1.4.16-branch/Source/WebCore</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/184603">184603</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2015-05-19 17:55:35 -0700 (Tue, 19 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/183788">r183788</a>. rdar://problem/21008265</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6001416branchSourceWebCoreChangeLog">branches/safari-600.1.4.16-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorepageFrameViewcpp">branches/safari-600.1.4.16-branch/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorerenderingRenderFrameBasecpp">branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderFrameBase.cpp</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorerenderingRenderObjectcpp">branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderObject.cpp</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorerenderingRenderViewh">branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderView.h</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorerenderingRenderWidgetcpp">branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.cpp</a></li>
<li><a href="#branchessafari6001416branchSourceWebCorerenderingRenderWidgeth">branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6001416branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/ChangeLog (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/ChangeLog        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/ChangeLog        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-05-19  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r183788.
+
+    2015-05-04  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+            RenderWidget::setWidgetGeometry() can end up destroying *this*.
+            https://bugs.webkit.org/show_bug.cgi?id=144601
+
+            Reviewed by Andreas Kling.
+
+            This is a speculative fix to ensure we don't crash on an invalid *this* renderer
+            while flattening the current iframe.
+            Calling RenderWidget::setWidgetGeometry() can result in destroying the current renderer.
+            While it is not a issue in case of normal layout flow as widget positions are updated at post layout,
+            frame flattening initiates this action in the middle of layout.
+            This patch re-introduces refcount model for RenderWidgets so that the renderer is protected during layout
+            when frame flattening is in use.
+
+            * rendering/RenderFrameBase.cpp:
+            (WebCore::RenderFrameBase::layoutWithFlattening): Let's be paranoid about child view.
+            * rendering/RenderObject.cpp:
+            (WebCore::RenderObject::destroy):
+            * rendering/FrameView.cpp:
+            (WebCore::FrameView::layout):
+            * rendering/RenderView.h:
+            * rendering/RenderWidget.cpp:
+            (WebCore::RenderWidget::~RenderWidget):
+            * rendering/RenderWidget.h:
+            (WebCore::RenderWidget::ref):
+            (WebCore::RenderWidget::deref):
+
</ins><span class="cx"> 2015-05-08  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r183649.
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/page/FrameView.cpp (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/page/FrameView.cpp        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/page/FrameView.cpp        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -1324,6 +1324,8 @@
</span><span class="cx">     if (m_needsFullRepaint)
</span><span class="cx">         root-&gt;view().repaintRootContents();
</span><span class="cx"> 
</span><ins>+    root-&gt;view().releaseProtectedRenderWidgets();
+
</ins><span class="cx">     layer-&gt;updateLayerPositionsAfterLayout(renderView()-&gt;layer(), updateLayerPositionFlags(layer, subtree, m_needsFullRepaint));
</span><span class="cx"> 
</span><span class="cx">     updateCompositingLayersAfterLayout();
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorerenderingRenderFrameBasecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderFrameBase.cpp (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderFrameBase.cpp        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderFrameBase.cpp        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -54,13 +54,13 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight)
</span><span class="cx"> {
</span><del>-    FrameView* childFrameView = childView();
-    RenderView* childRoot = childFrameView ? childFrameView-&gt;frame().contentRenderer() : 0;
</del><ins>+    view().protectRenderWidgetUntilLayoutIsDone(*this);
+    RenderView* childRoot = childView() ? childView()-&gt;frame().contentRenderer() : 0;
</ins><span class="cx"> 
</span><span class="cx">     if (!childRoot || !shouldExpandFrame(width(), height(), hasFixedWidth, hasFixedHeight)) {
</span><span class="cx">         updateWidgetPosition();
</span><del>-        if (childFrameView)
-            childFrameView-&gt;layout();
</del><ins>+        if (childView())
+            childView()-&gt;layout();
</ins><span class="cx">         clearNeedsLayout();
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -83,18 +83,20 @@
</span><span class="cx">         setWidth(std::max(width(), childRoot-&gt;minPreferredLogicalWidth() + hBorder));
</span><span class="cx">         // update again to pass the new width to the child frame
</span><span class="cx">         updateWidgetPosition();
</span><del>-        childFrameView-&gt;layout();
</del><ins>+        if (childView())
+            childView()-&gt;layout();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // expand the frame by setting frame height = content height
-    if (isScrollable || !hasFixedHeight || childRoot-&gt;isFrameSet())
-        setHeight(std::max&lt;LayoutUnit&gt;(height(), childFrameView-&gt;contentsHeight() + vBorder));
-    if (isScrollable || !hasFixedWidth || childRoot-&gt;isFrameSet())
-        setWidth(std::max&lt;LayoutUnit&gt;(width(), childFrameView-&gt;contentsWidth() + hBorder));
-
</del><ins>+    if (childView()) {
+        // expand the frame by setting frame height = content height
+        if (isScrollable || !hasFixedHeight || childRoot-&gt;isFrameSet())
+            setHeight(std::max&lt;LayoutUnit&gt;(height(), childView()-&gt;contentsHeight() + vBorder));
+        if (isScrollable || !hasFixedWidth || childRoot-&gt;isFrameSet())
+            setWidth(std::max&lt;LayoutUnit&gt;(width(), childView()-&gt;contentsWidth() + hBorder));
+    }
</ins><span class="cx">     updateWidgetPosition();
</span><span class="cx"> 
</span><del>-    ASSERT(!childFrameView-&gt;layoutPending());
</del><ins>+    ASSERT(!childView()-&gt;layoutPending());
</ins><span class="cx">     ASSERT(!childRoot-&gt;needsLayout());
</span><span class="cx">     ASSERT(!childRoot-&gt;firstChild() || !childRoot-&gt;firstChild()-&gt;firstChildSlow() || !childRoot-&gt;firstChild()-&gt;firstChildSlow()-&gt;needsLayout());
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorerenderingRenderObjectcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderObject.cpp (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderObject.cpp        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderObject.cpp        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> #include &quot;RenderScrollbarPart.h&quot;
</span><span class="cx"> #include &quot;RenderTheme.h&quot;
</span><span class="cx"> #include &quot;RenderView.h&quot;
</span><ins>+#include &quot;RenderWidget.h&quot;
</ins><span class="cx"> #include &quot;SVGRenderSupport.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;ShadowRoot.h&quot;
</span><span class="lines">@@ -2031,6 +2032,10 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     willBeDestroyed();
</span><ins>+    if (isWidget()) {
+        toRenderWidget(this)-&gt;deref();
+        return;
+    }
</ins><span class="cx">     delete this;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorerenderingRenderViewh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderView.h (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderView.h        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderView.h        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include &quot;PODFreeListArena.h&quot;
</span><span class="cx"> #include &quot;Region.h&quot;
</span><span class="cx"> #include &quot;RenderBlockFlow.h&quot;
</span><ins>+#include &quot;RenderWidget.h&quot;
</ins><span class="cx"> #include &quot;SelectionSubtreeRoot.h&quot;
</span><span class="cx"> #include &lt;memory&gt;
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="lines">@@ -249,6 +250,9 @@
</span><span class="cx">     void scheduleLazyRepaint(RenderBox&amp;);
</span><span class="cx">     void unscheduleLazyRepaint(RenderBox&amp;);
</span><span class="cx"> 
</span><ins>+    void protectRenderWidgetUntilLayoutIsDone(RenderWidget&amp; widget) { m_protectedRenderWidgets.append(&amp;widget); }
+    void releaseProtectedRenderWidgets() { m_protectedRenderWidgets.clear(); }
+
</ins><span class="cx"> protected:
</span><span class="cx">     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&amp;, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const override;
</span><span class="cx">     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&amp;) const override;
</span><span class="lines">@@ -365,6 +369,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     HashSet&lt;RenderElement*&gt; m_renderersWithPausedImageAnimation;
</span><ins>+    Vector&lt;RefPtr&lt;RenderWidget&gt;&gt; m_protectedRenderWidgets;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     SelectionRectGatherer m_selectionRectGatherer;
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorerenderingRenderWidgetcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.cpp (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.cpp        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.cpp        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx"> 
</span><span class="cx"> RenderWidget::~RenderWidget()
</span><span class="cx"> {
</span><ins>+    ASSERT(!m_refCount);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // Widgets are always placed on integer boundaries, so rounding the size is actually
</span></span></pre></div>
<a id="branchessafari6001416branchSourceWebCorerenderingRenderWidgeth"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.h (184602 => 184603)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.h        2015-05-20 00:35:52 UTC (rev 184602)
+++ branches/safari-600.1.4.16-branch/Source/WebCore/rendering/RenderWidget.h        2015-05-20 00:55:35 UTC (rev 184603)
</span><span class="lines">@@ -74,6 +74,9 @@
</span><span class="cx"> 
</span><span class="cx">     WeakPtr&lt;RenderWidget&gt; createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
</span><span class="cx"> 
</span><ins>+    void ref() { ++m_refCount; }
+    void deref();
+
</ins><span class="cx"> protected:
</span><span class="cx">     RenderWidget(HTMLFrameOwnerElement&amp;, PassRef&lt;RenderStyle&gt;);
</span><span class="cx"> 
</span><span class="lines">@@ -102,8 +105,16 @@
</span><span class="cx">     WeakPtrFactory&lt;RenderWidget&gt; m_weakPtrFactory;
</span><span class="cx">     RefPtr&lt;Widget&gt; m_widget;
</span><span class="cx">     IntRect m_clipRect; // The rectangle needs to remain correct after scrolling, so it is stored in content view coordinates, and not clipped to window.
</span><ins>+    unsigned m_refCount { 1 };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+inline void RenderWidget::deref()
+{
+    ASSERT(m_refCount);
+    if (!--m_refCount)
+        delete this;
+}
+
</ins><span class="cx"> RENDER_OBJECT_TYPE_CASTS(RenderWidget, isWidget())
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>

</body>
</html>