<!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>[183998] 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/183998">183998</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-05-08 11:15:57 -0700 (Fri, 08 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Throttle RequestAnimationFrame in subframes that are outside the viewport
https://bugs.webkit.org/show_bug.cgi?id=144718
&lt;rdar://problem/20688782&gt;

Reviewed by Simon Fraser.

Source/WebCore:

Throttle RequestAnimationFrame in subframes that are outside the
viewport or have &quot;display: none&quot; for performance and power.

Tests: fast/animation/request-animation-frame-throttle-subframe-display-none.html
       fast/animation/request-animation-frame-throttle-subframe.html

* dom/Document.h:
(WebCore::Document::scriptedAnimationController):
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::setThrottled):
(WebCore::ScriptedAnimationController::isThrottled):
* dom/ScriptedAnimationController.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::open):
Call FrameView::setFrameRect() only *after* the view has been
set on the Frame. Otherwise, setFrameRect() ends up calling
viewportContentsChanged() and we hit the
ASSERT(frame().view() == this) assertion in windowClipRect()
because the Frame still has its old FrameView. This is covered
by loader/go-back-to-different-window-size.html layout test.

* page/FrameView.cpp:
(WebCore::FrameView::viewportContentsChanged):
(WebCore::FrameView::applyRecursivelyWithVisibleRect):
(WebCore::FrameView::resumeVisibleImageAnimations):
(WebCore::FrameView::updateScriptedAnimationsThrottlingState):
(WebCore::FrameView::resumeVisibleImageAnimationsIncludingSubframes):
(WebCore::FrameView::updateThrottledDOMTimersState):
(WebCore::FrameView::scrollPositionChanged): Deleted.
(WebCore::FrameView::sendResizeEventIfNeeded): Deleted.
* page/FrameView.h:
* testing/Internals.cpp:
(WebCore::Internals::isRequestAnimationFrameThrottled):
(WebCore::Internals::isTimerThrottled): Deleted.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt: Added.
* fast/animation/request-animation-frame-throttle-subframe-display-none.html: Added.
Add layout test to test that RequestAnimationFrame is properly throttled
in &quot;display: none&quot; subframes.

* fast/animation/request-animation-frame-throttle-subframe-expected.txt: Added.
* fast/animation/request-animation-frame-throttle-subframe.html: Added.
Add layout test to test that RequestAnimationFrame is properly throttled
in frames that are outside the viewport.

* fast/animation/resources/requestAnimationFrame-frame-2.html: Added.
* fast/animation/resources/requestAnimationFrame-frame.html: Added.

* platform/win/TestExpectations:
Skip the 2 new tests on Windows as requestAnimationFrame throttling is
only supported on Cocoa.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformwinTestExpectations">trunk/LayoutTests/platform/win/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomScriptedAnimationControllercpp">trunk/Source/WebCore/dom/ScriptedAnimationController.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptedAnimationControllerh">trunk/Source/WebCore/dom/ScriptedAnimationController.h</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewh">trunk/Source/WebCore/page/FrameView.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynoneexpectedtxt">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynonehtml">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframeexpectedtxt">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframehtml">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html</a></li>
<li>trunk/LayoutTests/fast/animation/resources/</li>
<li><a href="#trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframe2html">trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html</a></li>
<li><a href="#trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframehtml">trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/LayoutTests/ChangeLog        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-05-08  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Throttle RequestAnimationFrame in subframes that are outside the viewport
+        https://bugs.webkit.org/show_bug.cgi?id=144718
+        &lt;rdar://problem/20688782&gt;
+
+        Reviewed by Simon Fraser.
+
+        * fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt: Added.
+        * fast/animation/request-animation-frame-throttle-subframe-display-none.html: Added.
+        Add layout test to test that RequestAnimationFrame is properly throttled
+        in &quot;display: none&quot; subframes.
+
+        * fast/animation/request-animation-frame-throttle-subframe-expected.txt: Added.
+        * fast/animation/request-animation-frame-throttle-subframe.html: Added.
+        Add layout test to test that RequestAnimationFrame is properly throttled
+        in frames that are outside the viewport.
+
+        * fast/animation/resources/requestAnimationFrame-frame-2.html: Added.
+        * fast/animation/resources/requestAnimationFrame-frame.html: Added.
+
+        * platform/win/TestExpectations:
+        Skip the 2 new tests on Windows as requestAnimationFrame throttling is
+        only supported on Cocoa.
+
</ins><span class="cx"> 2015-05-08  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] WTR doesn't correctly handle the Escape key
</span></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynoneexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+Tests that requestAnimationFrame is throttled in subframes that are display:none
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Frame is initially visibile so requestAnimationFrame should not be throttled
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+Hiding subframe.
+testFrame.style.display = 'none';
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+Show subframe again
+testFrame.style.display = 'block';
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynonehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html                                (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+description(&quot;Tests that requestAnimationFrame is throttled in subframes that are display:none&quot;);
+window.jsTestIsAsync = true;
+
+function checkSubframeThrottled()
+{
+    shouldBeTrue(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+
+    debug(&quot;Show subframe again&quot;);
+    evalAndLog(&quot;testFrame.style.display = 'block';&quot;);
+
+    shouldBecomeEqual(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;, &quot;false&quot;, finishJSTest);
+}
+
+function hideFrame()
+{
+    shouldBeFalse(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+
+    debug(&quot;Hiding subframe.&quot;);
+    evalAndLog(&quot;testFrame.style.display = 'none';&quot;);
+
+    shouldBecomeEqual(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;, &quot;true&quot;, checkSubframeThrottled);
+}
+
+function runTest()
+{
+    testFrame = document.getElementById(&quot;testFrame&quot;);
+    debug(&quot;Frame is initially visibile so requestAnimationFrame should not be throttled&quot;);
+    shouldBecomeEqual(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;, &quot;false&quot;, hideFrame);
+}
+
+var i = 0;
+requestAnimationFrame(function() {
+    i++;
+});
+&lt;/script&gt;
+&lt;iframe id=&quot;testFrame&quot; src=&quot;resources/requestAnimationFrame-frame.html&quot; onload=&quot;runTest()&quot;&gt;&lt;/iframe&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+Tests that requestAnimationFrame is throttled in subframes that are outside the viewport
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Frame is initially outside the viewport so requestAnimationFrame should be throttled
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+Scrolling frame into view.
+RequestAnimationFrame should no longer be throttled
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+Scrolling frame out of view again.
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html                                (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,61 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+description(&quot;Tests that requestAnimationFrame is throttled in subframes that are outside the viewport&quot;);
+window.jsTestIsAsync = true;
+
+function checkSubframesThrottled()
+{
+    shouldBeTrue(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBeTrue(&quot;grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+
+    finishJSTest();
+}
+
+function scrollFrameOutOfView()
+{
+    debug(&quot;Scrolling frame out of view again.&quot;);
+    window.scroll(0, 0);
+
+    shouldBeFalse(&quot;internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBecomeEqual(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;, &quot;true&quot;, checkSubframesThrottled);
+}
+
+function scrollFrameIntoView()
+{
+    shouldBeFalse(&quot;internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBeTrue(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBeTrue(&quot;grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+
+    debug(&quot;Scrolling frame into view.&quot;);
+    window.internals.scrollElementToRect(testFrame, 0, 0, 300, 300);
+
+    debug(&quot;RequestAnimationFrame should no longer be throttled&quot;);
+    shouldBeFalse(&quot;internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBeFalse(&quot;grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+    shouldBeFalse(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;);
+
+    scrollFrameOutOfView();
+}
+
+function runTest()
+{
+    testFrame = document.getElementById(&quot;testFrame&quot;);
+    grandChildFrame = testFrame.contentDocument.getElementById(&quot;grandChildFrame&quot;);
+    debug(&quot;Frame is initially outside the viewport so requestAnimationFrame should be throttled&quot;);
+    shouldBecomeEqual(&quot;testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()&quot;, &quot;true&quot;, scrollFrameIntoView);
+}
+
+var i = 0;
+requestAnimationFrame(function() {
+    i++;
+});
+&lt;/script&gt;
+&lt;div style=&quot;position: relative; width: 1600px; height: 2400px; background-color: green;&quot;&gt;
+    &lt;iframe id=&quot;testFrame&quot; src=&quot;resources/requestAnimationFrame-frame.html&quot; style=&quot;position:absolute; left: 600px; top: 800px;&quot; onload=&quot;runTest()&quot;&gt;&lt;/iframe&gt;
+&lt;/div&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframe2html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html                                (rev 0)
+++ trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;script&gt;
+var i = 0;
+requestAnimationFrame(function() {
+  i++;
+});
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html                                (rev 0)
+++ trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;iframe id=&quot;grandChildFrame&quot; src=&quot;requestAnimationFrame-frame-2.html&quot;&gt;&lt;/iframe&gt;
+&lt;script&gt;
+var i = 0;
+requestAnimationFrame(function() {
+  i++;
+});
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformwinTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/win/TestExpectations (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/win/TestExpectations        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/LayoutTests/platform/win/TestExpectations        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -2496,6 +2496,10 @@
</span><span class="cx"> webkit.org/b/138676 imported/w3c/canvas/2d.line.join.parallel.html [ Failure ]
</span><span class="cx"> webkit.org/b/138676 imported/w3c/canvas/2d.strokeRect.zero.5.html [ Failure ]
</span><span class="cx"> 
</span><ins>+# requestAnimationFrame throttling does not work on Windows because USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) is disabled.
+webkit.org/b/144718 fast/animation/request-animation-frame-throttle-subframe-display-none.html [ Skip ]
+webkit.org/b/144718 fast/animation/request-animation-frame-throttle-subframe.html [ Skip ]
+
</ins><span class="cx"> ################################################################################
</span><span class="cx"> ######################### Start list of UNREVIEWED failures ########################
</span><span class="cx"> ################################################################################
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/ChangeLog        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2015-05-08  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Throttle RequestAnimationFrame in subframes that are outside the viewport
+        https://bugs.webkit.org/show_bug.cgi?id=144718
+        &lt;rdar://problem/20688782&gt;
+
+        Reviewed by Simon Fraser.
+
+        Throttle RequestAnimationFrame in subframes that are outside the
+        viewport or have &quot;display: none&quot; for performance and power.
+
+        Tests: fast/animation/request-animation-frame-throttle-subframe-display-none.html
+               fast/animation/request-animation-frame-throttle-subframe.html
+
+        * dom/Document.h:
+        (WebCore::Document::scriptedAnimationController):
+        * dom/ScriptedAnimationController.cpp:
+        (WebCore::ScriptedAnimationController::setThrottled):
+        (WebCore::ScriptedAnimationController::isThrottled):
+        * dom/ScriptedAnimationController.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::open):
+        Call FrameView::setFrameRect() only *after* the view has been
+        set on the Frame. Otherwise, setFrameRect() ends up calling
+        viewportContentsChanged() and we hit the
+        ASSERT(frame().view() == this) assertion in windowClipRect()
+        because the Frame still has its old FrameView. This is covered
+        by loader/go-back-to-different-window-size.html layout test.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::viewportContentsChanged):
+        (WebCore::FrameView::applyRecursivelyWithVisibleRect):
+        (WebCore::FrameView::resumeVisibleImageAnimations):
+        (WebCore::FrameView::updateScriptedAnimationsThrottlingState):
+        (WebCore::FrameView::resumeVisibleImageAnimationsIncludingSubframes):
+        (WebCore::FrameView::updateThrottledDOMTimersState):
+        (WebCore::FrameView::scrollPositionChanged): Deleted.
+        (WebCore::FrameView::sendResizeEventIfNeeded): Deleted.
+        * page/FrameView.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::isRequestAnimationFrameThrottled):
+        (WebCore::Internals::isTimerThrottled): Deleted.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
</ins><span class="cx"> 2015-05-08  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix the iOS Simulator external SDK build following &lt;http://trac.webkit.org/changeset/181918&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/Document.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -948,6 +948,9 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void postTask(Task) override final; // Executes the task on context's thread asynchronously.
</span><span class="cx"> 
</span><ins>+#if ENABLE(REQUEST_ANIMATION_FRAME)
+    ScriptedAnimationController* scriptedAnimationController() { return m_scriptedAnimationController.get(); }
+#endif
</ins><span class="cx">     void suspendScriptedAnimationControllerCallbacks();
</span><span class="cx">     void resumeScriptedAnimationControllerCallbacks();
</span><span class="cx">     void scriptedAnimationControllerSetThrottled(bool);
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptedAnimationControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptedAnimationController.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -34,6 +34,8 @@
</span><span class="cx"> #include &quot;DocumentLoader.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><span class="cx"> #include &quot;InspectorInstrumentation.h&quot;
</span><ins>+#include &quot;Logging.h&quot;
+#include &quot;MainFrame.h&quot;
</ins><span class="cx"> #include &quot;RequestAnimationFrameCallback.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &lt;wtf/Ref.h&gt;
</span><span class="lines">@@ -84,6 +86,8 @@
</span><span class="cx">     if (m_isThrottled == isThrottled)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    LOG(Animations, &quot;%p - Setting RequestAnimationFrame throttling state to %d in frame %p (isMainFrame: %d)&quot;, this, isThrottled, m_document-&gt;frame(), m_document-&gt;frame() ? m_document-&gt;frame()-&gt;isMainFrame() : 0);
+
</ins><span class="cx">     m_isThrottled = isThrottled;
</span><span class="cx">     if (m_animationTimer.isActive()) {
</span><span class="cx">         m_animationTimer.stop();
</span><span class="lines">@@ -94,6 +98,15 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool ScriptedAnimationController::isThrottled() const
+{
+#if USE(REQUEST_ANIMATION_FRAME_TIMER) &amp;&amp; USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+    return m_isThrottled;
+#else
+    return false;
+#endif
+}
+
</ins><span class="cx"> ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassRefPtr&lt;RequestAnimationFrameCallback&gt; callback)
</span><span class="cx"> {
</span><span class="cx">     ScriptedAnimationController::CallbackId id = ++m_nextCallbackId;
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptedAnimationControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptedAnimationController.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx">     void suspend();
</span><span class="cx">     void resume();
</span><span class="cx">     void setThrottled(bool);
</span><ins>+    WEBCORE_EXPORT bool isThrottled() const;
</ins><span class="cx"> 
</span><span class="cx">     void windowScreenDidChange(PlatformDisplayID);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -2068,10 +2068,12 @@
</span><span class="cx">     ASSERT(view);
</span><span class="cx">     view-&gt;setWasScrolledByUser(false);
</span><span class="cx"> 
</span><del>-    // Use the current ScrollView's frame rect.
-    if (m_frame.view())
-        view-&gt;setFrameRect(m_frame.view()-&gt;frameRect());
</del><ins>+    Optional&lt;IntRect&gt; previousViewFrameRect = m_frame.view() ?  m_frame.view()-&gt;frameRect() : Optional&lt;IntRect&gt;(Nullopt);
</ins><span class="cx">     m_frame.setView(view);
</span><ins>+
+    // Use the previous ScrollView's frame rect.
+    if (previousViewFrameRect)
+        view-&gt;setFrameRect(previousViewFrameRect.value());
</ins><span class="cx">     
</span><span class="cx">     m_frame.setDocument(document);
</span><span class="cx">     document-&gt;domWindow()-&gt;resumeFromPageCache();
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/page/FrameView.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> #include &quot;RenderWidget.h&quot;
</span><span class="cx"> #include &quot;SVGDocument.h&quot;
</span><span class="cx"> #include &quot;SVGSVGElement.h&quot;
</span><ins>+#include &quot;ScriptedAnimationController.h&quot;
</ins><span class="cx"> #include &quot;ScrollAnimator.h&quot;
</span><span class="cx"> #include &quot;ScrollingCoordinator.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="lines">@@ -1755,10 +1756,18 @@
</span><span class="cx"> 
</span><span class="cx"> void FrameView::viewportContentsChanged()
</span><span class="cx"> {
</span><ins>+    if (!frame().view()) {
+        // The frame is being destroyed.
+        return;
+    }
+
</ins><span class="cx">     // When the viewport contents changes (scroll, resize, style recalc, layout, ...),
</span><span class="cx">     // check if we should resume animated images or unthrottle DOM timers.
</span><del>-    resumeVisibleImageAnimationsIncludingSubframes();
-    updateThrottledDOMTimersState();
</del><ins>+    applyRecursivelyWithVisibleRect([] (FrameView&amp; frameView, const IntRect&amp; visibleRect) {
+        frameView.resumeVisibleImageAnimations(visibleRect);
+        frameView.updateThrottledDOMTimersState(visibleRect);
+        frameView.updateScriptedAnimationsThrottlingState(visibleRect);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool FrameView::fixedElementsLayoutRelativeToFrame() const
</span><span class="lines">@@ -2095,28 +2104,60 @@
</span><span class="cx">     viewportContentsChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FrameView::resumeVisibleImageAnimationsIncludingSubframes()
</del><ins>+void FrameView::applyRecursivelyWithVisibleRect(const std::function&lt;void (FrameView&amp; frameView, const IntRect&amp; visibleRect)&gt;&amp; apply)
</ins><span class="cx"> {
</span><del>-    auto* renderView = frame().contentRenderer();
-    if (!renderView)
-        return;
-
</del><span class="cx">     IntRect windowClipRect = this-&gt;windowClipRect();
</span><span class="cx">     auto visibleRect = windowToContents(windowClipRect);
</span><del>-    if (visibleRect.isEmpty())
-        return;
</del><ins>+    apply(*this, visibleRect);
</ins><span class="cx"> 
</span><del>-    // Resume paused image animations in this frame.
-    renderView-&gt;resumePausedImageAnimationsIfNeeded(visibleRect);
-
</del><span class="cx">     // Recursive call for subframes. We cache the current FrameView's windowClipRect to avoid recomputing it for every subframe.
</span><span class="cx">     TemporaryChange&lt;IntRect*&gt; windowClipRectCache(m_cachedWindowClipRect, &amp;windowClipRect);
</span><span class="cx">     for (Frame* childFrame = frame().tree().firstChild(); childFrame; childFrame = childFrame-&gt;tree().nextSibling()) {
</span><span class="cx">         if (auto* childView = childFrame-&gt;view())
</span><del>-            childView-&gt;resumeVisibleImageAnimationsIncludingSubframes();
</del><ins>+            childView-&gt;applyRecursivelyWithVisibleRect(apply);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void FrameView::resumeVisibleImageAnimations(const IntRect&amp; visibleRect)
+{
+    if (visibleRect.isEmpty())
+        return;
+
+    if (auto* renderView = frame().contentRenderer())
+        renderView-&gt;resumePausedImageAnimationsIfNeeded(visibleRect);
+}
+
+void FrameView::updateScriptedAnimationsThrottlingState(const IntRect&amp; visibleRect)
+{
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+    if (frame().isMainFrame())
+        return;
+
+    auto* document = frame().document();
+    if (!document)
+        return;
+
+    auto* scriptedAnimationController = document-&gt;scriptedAnimationController();
+    if (!scriptedAnimationController)
+        return;
+
+    // FIXME: This doesn't work for subframes of a &quot;display: none&quot; frame because
+    // they have a non-null ownerRenderer.
+    bool shouldThrottle = !frame().ownerRenderer() || visibleRect.isEmpty();
+    scriptedAnimationController-&gt;setThrottled(shouldThrottle);
+#else
+    UNUSED_PARAM(visibleRect);
+#endif
+}
+
+
+void FrameView::resumeVisibleImageAnimationsIncludingSubframes()
+{
+    applyRecursivelyWithVisibleRect([] (FrameView&amp; frameView, const IntRect&amp; visibleRect) {
+        frameView.resumeVisibleImageAnimations(visibleRect);
+    });
+}
+
</ins><span class="cx"> void FrameView::updateLayerPositionsAfterScrolling()
</span><span class="cx"> {
</span><span class="cx">     // If we're scrolling as a result of updating the view size after layout, we'll update widgets and layer positions soon anyway.
</span><span class="lines">@@ -3059,13 +3100,11 @@
</span><span class="cx">     m_throttledTimers.remove(timer);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FrameView::updateThrottledDOMTimersState()
</del><ins>+void FrameView::updateThrottledDOMTimersState(const IntRect&amp; visibleRect)
</ins><span class="cx"> {
</span><span class="cx">     if (m_throttledTimers.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    IntRect visibleRect = windowToContents(windowClipRect());
-
</del><span class="cx">     // Do not iterate over the HashSet because calling DOMTimer::updateThrottlingStateAfterViewportChange()
</span><span class="cx">     // may cause timers to remove themselves from it while we are iterating.
</span><span class="cx">     Vector&lt;DOMTimer*&gt; timers;
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/page/FrameView.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -596,8 +596,12 @@
</span><span class="cx">     void forceLayoutParentViewIfNeeded();
</span><span class="cx">     void performPostLayoutTasks();
</span><span class="cx">     void autoSizeIfEnabled();
</span><del>-    void updateThrottledDOMTimersState();
</del><span class="cx"> 
</span><ins>+    void applyRecursivelyWithVisibleRect(const std::function&lt;void (FrameView&amp; frameView, const IntRect&amp; visibleRect)&gt;&amp;);
+    void updateThrottledDOMTimersState(const IntRect&amp; visibleRect);
+    void resumeVisibleImageAnimations(const IntRect&amp; visibleRect);
+    void updateScriptedAnimationsThrottlingState(const IntRect&amp; visibleRect);
+
</ins><span class="cx">     void updateLayerFlushThrottling();
</span><span class="cx">     WEBCORE_EXPORT void adjustTiledBackingCoverage();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -98,6 +98,7 @@
</span><span class="cx"> #include &quot;RenderedDocumentMarker.h&quot;
</span><span class="cx"> #include &quot;RuntimeEnabledFeatures.h&quot;
</span><span class="cx"> #include &quot;SchemeRegistry.h&quot;
</span><ins>+#include &quot;ScriptedAnimationController.h&quot;
</ins><span class="cx"> #include &quot;ScrollingCoordinator.h&quot;
</span><span class="cx"> #include &quot;SerializedScriptValue.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="lines">@@ -766,6 +767,18 @@
</span><span class="cx">     return timer-&gt;m_throttleState == DOMTimer::ShouldThrottle;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Internals::isRequestAnimationFrameThrottled() const
+{
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+    auto* scriptedAnimationController = contextDocument()-&gt;scriptedAnimationController();
+    if (!scriptedAnimationController)
+        return false;
+    return scriptedAnimationController-&gt;isThrottled();
+#else
+    return false;
+#endif
+}
+
</ins><span class="cx"> String Internals::visiblePlaceholder(Element* element)
</span><span class="cx"> {
</span><span class="cx">     if (is&lt;HTMLTextFormControlElement&gt;(element)) {
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -113,6 +113,7 @@
</span><span class="cx"> 
</span><span class="cx">     // DOMTimers throttling testing.
</span><span class="cx">     bool isTimerThrottled(int timeoutId, ExceptionCode&amp;);
</span><ins>+    bool isRequestAnimationFrameThrottled() const;
</ins><span class="cx"> 
</span><span class="cx">     // Spatial Navigation testing.
</span><span class="cx">     unsigned lastSpatialNavigationCandidateCount(ExceptionCode&amp;) const;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.idl        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -279,6 +279,8 @@
</span><span class="cx">     // Query if a timer is currently throttled, to debug timer throttling.
</span><span class="cx">     [RaisesException] boolean isTimerThrottled(long timerHandle);
</span><span class="cx"> 
</span><ins>+    boolean isRequestAnimationFrameThrottled();
+
</ins><span class="cx">     [RaisesException] void startTrackingStyleRecalcs();
</span><span class="cx">     [RaisesException] unsigned long styleRecalcCount();
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>