<!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>[167339] 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/167339">167339</a></dd>
<dt>Author</dt> <dd>roger_fong@apple.com</dd>
<dt>Date</dt> <dd>2014-04-15 17:26:11 -0700 (Tue, 15 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Snapshotted plugins may need to be restarted if style properties are changed after initial load of plugin.
https://bugs.webkit.org/show_bug.cgi?id=131553.
&lt;rdar://problem/15443375&gt;

Reviewed by Timothy Horton.

Test: plugins/snapshotting/set-plugin-size-to-tiny.html

When updating embedded objects during our post layout checks, check for certain style changes
that may result in the plugin needing to be restarted.

* html/HTMLPlugInImageElement.h: 
Add m_plugInDimensionsSpecified field to keep track of whether or not dimensions on the plugin’s renderer have been specified.
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement):
Initialize m_plugInDimensionsSpecified.
(WebCore::isSmallerThanTinySizingThreshold):
Refactoring, move check for whether or not plugin is smaller than the tiny plugin size threshold to this method.
(WebCore::HTMLPlugInImageElement::isTopLevelFullPage): 
Refactoring, move check for whether or not plugin is top level full page to this method.
(WebCore::HTMLPlugInImageElement::checkSnapshotStatus): 
Use refactored checks here as well to determine whether or not we need to restart the snapshotted plugin.
(WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Use refactored checks.
If plugin dimensions were specified, set m_plugInDimensionsSpecified to true.
* platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt: Added.
* plugins/snapshotting/set-plugin-size-to-tiny.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="#trunkSourceWebCorehtmlHTMLPlugInImageElementcpp">trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLPlugInImageElementh">trunk/Source/WebCore/html/HTMLPlugInImageElement.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformmacwk2pluginssnapshottingsetpluginsizetotinyexpectedtxt">trunk/LayoutTests/platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt</a></li>
<li><a href="#trunkLayoutTestspluginssnapshottingsetpluginsizetotinyhtml">trunk/LayoutTests/plugins/snapshotting/set-plugin-size-to-tiny.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (167338 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-04-16 00:01:33 UTC (rev 167338)
+++ trunk/LayoutTests/ChangeLog        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2014-04-14  Roger Fong  &lt;roger_fong@apple.com&gt;
+
+        Snapshotted plugins may need to be restarted if style properties are changed after initial load of plugin.
+        https://bugs.webkit.org/show_bug.cgi?id=131553.
+        &lt;rdar://problem/15443375&gt;
+
+        Reviewed by Timothy Horton.
+
+        * platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt: Added.
+        * plugins/snapshotting/set-plugin-size-to-tiny.html: Added.
+
</ins><span class="cx"> 2014-04-14  Morten Stenshorne  &lt;mstensho@opera.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [New Multicolumn] Add support for column-span:all
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2pluginssnapshottingsetpluginsizetotinyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt (0 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/plugins/snapshotting/set-plugin-size-to-tiny-expected.txt        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 642x18
+          text run at (0,0) width 642: &quot;This test ensures that if we have set a plugin to be too small after the initial load that it still gets played.&quot;
+      RenderBlock {P} at (0,34) size 784x18
+        RenderText {#text} at (0,0) size 701x18
+          text run at (0,0) width 701: &quot;Also ensure that the plugin remains snapshotted if the size was initially specified but made too small afterwards.&quot;
+      RenderBlock (anonymous) at (0,68) size 784x44
+        RenderText {#text} at (40,26) size 4x18
+          text run at (40,26) width 4: &quot; &quot;
+        RenderSnapshottedPlugIn {EMBED} at (44,0) size 40x40
+        RenderText {#text} at (0,0) size 0x0
+layer at (8,76) size 40x40
+  RenderEmbeddedObject {EMBED} at (0,0) size 40x40
+layer at (52,76) size 40x40
+  RenderBlock (relative positioned) {DIV} at (0,0) size 40x40
+layer at (57,81) size 30x30
+  RenderFlexibleBox {DIV} at (5,5) size 30x30 [bgcolor=#FFFFFFBF]
+    RenderBlock {DIV} at (0,-3) size 30x36
+layer at (57,78) size 30x18 scrollWidth 139
+  RenderBlock {DIV} at (0,0) size 30x18
+    RenderText {#text} at (0,0) size 139x18
+      text run at (0,0) width 139: &quot;Snapshotted Plug-In&quot;
+layer at (57,96) size 30x18 scrollWidth 94
+  RenderBlock {DIV} at (0,18) size 30x18 [color=#444444]
+    RenderText {#text} at (0,0) size 94x18
+      text run at (0,0) width 94: &quot;Click to restart&quot;
</ins></span></pre></div>
<a id="trunkLayoutTestspluginssnapshottingsetpluginsizetotinyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/plugins/snapshotting/set-plugin-size-to-tiny.html (0 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/plugins/snapshotting/set-plugin-size-to-tiny.html                                (rev 0)
+++ trunk/LayoutTests/plugins/snapshotting/set-plugin-size-to-tiny.html        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+&lt;p&gt;This test ensures that if we have set a plugin to be too small after the initial load that it still gets played.&lt;/p&gt;
+&lt;p&gt;Also ensure that the plugin remains snapshotted if the size was initially specified but made too small afterwards.&lt;/p&gt;
+&lt;script&gt;
+if (window.testRunner) {
+    window.internals.settings.setPlugInSnapshottingEnabled(true);
+    window.internals.settings.setMaximumPlugInSnapshotAttempts(0);
+    testRunner.waitUntilDone();
+    setTimeout(function () {
+        var embedElement = document.getElementById(&quot;embed&quot;);
+        embedElement.style.width = 40;
+        embedElement.style.height = 40;
+        var embedElement2 = document.getElementById(&quot;embed2&quot;);
+        embedElement2.style.width = 40;
+        embedElement2.style.height = 40;
+        testRunner.notifyDone();
+    }, 2000);
+}
+&lt;/script&gt;
+&lt;embed id=&quot;embed&quot; src=&quot;../resources/lines.swf&quot;&gt;&lt;/embed&gt;
+&lt;embed id=&quot;embed2&quot; src=&quot;../resources/lines.swf&quot; style=&quot;width:300px; height:300px&quot;&gt;&lt;/embed&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167338 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-16 00:01:33 UTC (rev 167338)
+++ trunk/Source/WebCore/ChangeLog        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-04-10  Roger Fong  &lt;roger_fong@apple.com&gt;
+
+        Snapshotted plugins may need to be restarted if style properties are changed after initial load of plugin.
+        https://bugs.webkit.org/show_bug.cgi?id=131553.
+        &lt;rdar://problem/15443375&gt;
+
+        Reviewed by Timothy Horton.
+
+        Test: plugins/snapshotting/set-plugin-size-to-tiny.html
+
+        When updating embedded objects during our post layout checks, check for certain style changes
+        that may result in the plugin needing to be restarted.
+
+        * html/HTMLPlugInImageElement.h: 
+        Add m_plugInDimensionsSpecified field to keep track of whether or not dimensions on the plugin’s renderer have been specified.
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement):
+        Initialize m_plugInDimensionsSpecified.
+        (WebCore::isSmallerThanTinySizingThreshold):
+        Refactoring, move check for whether or not plugin is smaller than the tiny plugin size threshold to this method.
+        (WebCore::HTMLPlugInImageElement::isTopLevelFullPage): 
+        Refactoring, move check for whether or not plugin is top level full page to this method.
+        (WebCore::HTMLPlugInImageElement::checkSnapshotStatus): 
+        Use refactored checks here as well to determine whether or not we need to restart the snapshotted plugin.
+        (WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Use refactored checks.
+        If plugin dimensions were specified, set m_plugInDimensionsSpecified to true.
+
</ins><span class="cx"> 2014-04-15  Andreas Kling  &lt;akling@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS WebKit2] Listen for system memory pressure notifications.
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLPlugInImageElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (167338 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp        2014-04-16 00:01:33 UTC (rev 167338)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -121,6 +121,7 @@
</span><span class="cx">     , m_plugInWasCreated(false)
</span><span class="cx">     , m_deferredPromotionToPrimaryPlugIn(false)
</span><span class="cx">     , m_snapshotDecision(SnapshotNotYetDecided)
</span><ins>+    , m_plugInDimensionsSpecified(false)
</ins><span class="cx"> {
</span><span class="cx">     setHasCustomStyleResolveCallbacks();
</span><span class="cx"> }
</span><span class="lines">@@ -352,18 +353,6 @@
</span><span class="cx">         renderer()-&gt;repaint();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void HTMLPlugInImageElement::checkSnapshotStatus()
-{
-    if (!renderer()-&gt;isSnapshottedPlugIn()) {
-        if (displayState() == Playing)
-            checkSizeChangeForSnapshotting();
-        return;
-    }
-
-    // Notify the shadow root that the size changed so that we may update the overlay layout.
-    ensureUserAgentShadowRoot().dispatchEvent(Event::create(eventNames().resizeEvent, true, false));
-}
-
</del><span class="cx"> static DOMWrapperWorld&amp; plugInImageElementIsolatedWorld()
</span><span class="cx"> {
</span><span class="cx">     static DOMWrapperWorld&amp; isolatedWorld = *DOMWrapperWorld::create(JSDOMWindow::commonVM()).leakRef();
</span><span class="lines">@@ -612,7 +601,56 @@
</span><span class="cx"> {
</span><span class="cx">     return length.isPercentNotCalculated() &amp;&amp; length.percent() == 100;
</span><span class="cx"> }
</span><del>-
</del><ins>+    
+static inline bool isSmallerThanTinySizingThreshold(const RenderEmbeddedObject&amp; renderer)
+{
+    LayoutRect contentRect = renderer.contentBoxRect();
+    return contentRect.width() &lt;= sizingTinyDimensionThreshold || contentRect.height() &lt;= sizingTinyDimensionThreshold;
+}
+    
+bool HTMLPlugInImageElement::isTopLevelFullPagePlugin(const RenderEmbeddedObject&amp; renderer) const
+{
+    Frame&amp; frame = *document().frame();
+    if (!frame.isMainFrame())
+        return false;
+    
+    auto&amp; style = renderer.style();
+    IntSize visibleSize = frame.view()-&gt;visibleSize();
+    LayoutRect contentRect = renderer.contentBoxRect();
+    int contentWidth = contentRect.width();
+    int contentHeight = contentRect.height();
+    return is100Percent(style.width()) &amp;&amp; is100Percent(style.height()) &amp;&amp; contentWidth * contentHeight &gt; visibleSize.area() * sizingFullPageAreaRatioThreshold;
+}
+    
+void HTMLPlugInImageElement::checkSnapshotStatus()
+{
+    if (!renderer()-&gt;isSnapshottedPlugIn()) {
+        if (displayState() == Playing)
+            checkSizeChangeForSnapshotting();
+        return;
+    }
+    
+    // If width and height styles were previously not set and we've snapshotted the plugin we may need to restart the plugin so that its state can be updated appropriately.
+    if (!document().page()-&gt;settings().snapshotAllPlugIns() &amp;&amp; displayState() &lt;= DisplayingSnapshot &amp;&amp; !m_plugInDimensionsSpecified) {
+        RenderSnapshottedPlugIn&amp; renderer = toRenderSnapshottedPlugIn(*this-&gt;renderer());
+        if (!renderer.style().logicalWidth().isSpecified() &amp;&amp; !renderer.style().logicalHeight().isSpecified())
+            return;
+        
+        m_plugInDimensionsSpecified = true;
+        if (isTopLevelFullPagePlugin(renderer)) {
+            m_snapshotDecision = NeverSnapshot;
+            restartSnapshottedPlugIn();
+        } else if (isSmallerThanTinySizingThreshold(renderer)) {
+            m_snapshotDecision = MaySnapshotWhenResized;
+            restartSnapshottedPlugIn();
+        }
+        return;
+    }
+    
+    // Notify the shadow root that the size changed so that we may update the overlay layout.
+    ensureUserAgentShadowRoot().dispatchEvent(Event::create(eventNames().resizeEvent, true, false));
+}
+    
</ins><span class="cx"> void HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn(const URL&amp; url)
</span><span class="cx"> {
</span><span class="cx">     LOG(Plugins, &quot;%p Plug-in URL: %s&quot;, this, m_url.utf8().data());
</span><span class="lines">@@ -696,26 +734,21 @@
</span><span class="cx">         m_snapshotDecision = NeverSnapshot;
</span><span class="cx">         return;
</span><span class="cx">     }
</span><del>-
</del><ins>+    
</ins><span class="cx">     auto&amp; renderer = toRenderEmbeddedObject(*this-&gt;renderer());
</span><span class="cx">     LayoutRect contentRect = renderer.contentBoxRect();
</span><span class="cx">     int contentWidth = contentRect.width();
</span><span class="cx">     int contentHeight = contentRect.height();
</span><del>-
-    if (inMainFrame) {
-        auto&amp; style = renderer.style();
-        bool isFullPage = is100Percent(style.width()) &amp;&amp; is100Percent(style.height());
-        IntSize visibleViewSize = document().frame()-&gt;view()-&gt;visibleSize();
-        float contentArea = contentWidth * contentHeight;
-        float visibleArea = visibleViewSize.width() * visibleViewSize.height();
-        if (isFullPage &amp;&amp; contentArea &gt; visibleArea * sizingFullPageAreaRatioThreshold) {
-            LOG(Plugins, &quot;%p Plug-in is top level full page, set to play&quot;, this);
-            m_snapshotDecision = NeverSnapshot;
-            return;
-        }
</del><ins>+    
+    m_plugInDimensionsSpecified = renderer.style().logicalWidth().isSpecified() || renderer.style().logicalHeight().isSpecified();
+    
+    if (isTopLevelFullPagePlugin(renderer)) {
+        LOG(Plugins, &quot;%p Plug-in is top level full page, set to play&quot;, this);
+        m_snapshotDecision = NeverSnapshot;
+        return;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (contentWidth &lt;= sizingTinyDimensionThreshold || contentHeight &lt;= sizingTinyDimensionThreshold) {
</del><ins>+    if (isSmallerThanTinySizingThreshold(renderer)) {
</ins><span class="cx">         LOG(Plugins, &quot;%p Plug-in is very small %dx%d, set to play&quot;, this, contentWidth, contentHeight);
</span><span class="cx">         m_sizeWhenSnapshotted = IntSize(contentWidth, contentHeight);
</span><span class="cx">         m_snapshotDecision = MaySnapshotWhenResized;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLPlugInImageElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.h (167338 => 167339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLPlugInImageElement.h        2014-04-16 00:01:33 UTC (rev 167338)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.h        2014-04-16 00:26:11 UTC (rev 167339)
</span><span class="lines">@@ -141,6 +141,7 @@
</span><span class="cx"> 
</span><span class="cx">     void restartSimilarPlugIns();
</span><span class="cx">     void removeSnapshotTimerFired(Timer&lt;HTMLPlugInImageElement&gt;&amp;);
</span><ins>+    bool isTopLevelFullPagePlugin(const RenderEmbeddedObject&amp;) const;
</ins><span class="cx"> 
</span><span class="cx">     URL m_loadedUrl;
</span><span class="cx">     bool m_needsWidgetUpdate;
</span><span class="lines">@@ -157,6 +158,7 @@
</span><span class="cx">     bool m_deferredPromotionToPrimaryPlugIn;
</span><span class="cx">     IntSize m_sizeWhenSnapshotted;
</span><span class="cx">     SnapshotDecision m_snapshotDecision;
</span><ins>+    bool m_plugInDimensionsSpecified;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> void isHTMLPlugInImageElement(const HTMLPlugInImageElement&amp;); // Catch unnecessary runtime check of type known at compile time.
</span></span></pre>
</div>
</div>

</body>
</html>