<!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>[213460] 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/213460">213460</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-03-06 11:43:27 -0800 (Mon, 06 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Disable autoplay of silent videos in low power mode
https://bugs.webkit.org/show_bug.cgi?id=168985
&lt;rdar://problem/30739051&gt;

Reviewed by Jer Noble.

Source/WebCore:

Disable autoplay of silent videos in low power mode on iOS to save battery.
We force the display of the start button when denying autoplay in low power
mode to allow the user to start playback.

Test: media/modern-media-controls/start-support/start-support-lowPowerMode.html

* Modules/mediacontrols/MediaControlsHost.cpp:
(WebCore::MediaControlsHost::shouldForceControlsDisplay):
* Modules/mediacontrols/MediaControlsHost.h:
* Modules/mediacontrols/MediaControlsHost.idl:
Add shouldForceControlsDisplay property on MediaControlsHost. This property
is set to true when we want to force the display for media controls. Currently,
this only returns true for autoplay videos, while in low power mode.

* Modules/modern-media-controls/media/controls-visibility-support.js:
(ControlsVisibilitySupport.prototype._updateControls):
Take into consideration MediaControlsHost.shouldForceControlsDisplay when
initializing shouldShowControls variable.

* Modules/modern-media-controls/media/start-support.js:
(StartSupport.prototype._shouldShowStartButton):
Show the start button when MediaControlsHost.shouldForceControlsDisplay
returns true.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
Add MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode restriction
to the session when low power mode is enabled so we know we need to force a
gesture to start playback of autoplay videos.

(WebCore::HTMLMediaElement::shouldForceControlsDisplay):
Add convenience function to decide if we should force display of media controls.
This returns true if the media element is a video with autoplay attribute and
its session has the MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode
restriction (i.e. we are in low power mode).

(WebCore::HTMLMediaElement::configureMediaControls):
Force requireControls variable to true if shouldForceControlsDisplay() returns
true. We do this here instead of inside HTMLMediaElement::controls() because
we do not want to change the value of media.controls exposed to JavaScript.

(WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture):
Add MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode to the list
of restrictions that get removed on user gesture.

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::playbackPermitted):
Deny playback for videos that have the RequireUserGestureForVideoDueToLowPowerMode
restriction unless there is a user gesture.

* html/MediaElementSession.h:
Add new MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode
restriction.

LayoutTests:

Add layout test coverage.

* media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt: Added.
* media/modern-media-controls/start-support/start-support-lowPowerMode.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorTestExpectations">trunk/LayoutTests/platform/ios-simulator/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp">trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediacontrolsMediaControlsHosth">trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h</a></li>
<li><a href="#trunkSourceWebCoreModulesmediacontrolsMediaControlsHostidl">trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl</a></li>
<li><a href="#trunkSourceWebCoreModulesmodernmediacontrolsmediacontrolsvisibilitysupportjs">trunk/Source/WebCore/Modules/modern-media-controls/media/controls-visibility-support.js</a></li>
<li><a href="#trunkSourceWebCoreModulesmodernmediacontrolsmediastartsupportjs">trunk/Source/WebCore/Modules/modern-media-controls/media/start-support.js</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessioncpp">trunk/Source/WebCore/html/MediaElementSession.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlMediaElementSessionh">trunk/Source/WebCore/html/MediaElementSession.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolsstartsupportstartsupportlowPowerModeexpectedtxt">trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolsstartsupportstartsupportlowPowerModehtml">trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/LayoutTests/ChangeLog        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-03-06  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [iOS] Disable autoplay of silent videos in low power mode
+        https://bugs.webkit.org/show_bug.cgi?id=168985
+        &lt;rdar://problem/30739051&gt;
+
+        Reviewed by Jer Noble.
+
+        Add layout test coverage.
+
+        * media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt: Added.
+        * media/modern-media-controls/start-support/start-support-lowPowerMode.html: Added.
+
</ins><span class="cx"> 2017-03-06  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Mark media/modern-media-controls/icon-button/icon-button-active-state.html as flaky.
</span></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolsstartsupportstartsupportlowPowerModeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt (0 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt                                (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode-expected.txt        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+Test that silent autoplay videos do not start playing without user gesture while in low power mode.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Received 'canplaythrough' event
+PASS !!internals.shadowRoot(media).querySelector('button.start') became true
+PASS media.controls is false
+Pressing on the start button
+Received 'play' event
+PASS media.controls is false
+PASS internals.shadowRoot(media).querySelector('button.start') became null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolsstartsupportstartsupportlowPowerModehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode.html (0 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode.html                                (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/start-support/start-support-lowPowerMode.html        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -0,0 +1,51 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script&gt;
+internals.setLowPowerModeEnabled(true);
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/media-controls-loader.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/media-controls-utils.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;video src=&quot;../../content/test.mp4&quot; style=&quot;width: 320px; height: 240px;&quot; autoplay&gt;&lt;/video&gt;
+&lt;script&gt;
+description(&quot;Test that silent autoplay videos do not start playing without user gesture while in low power mode.&quot;);
+jsTestIsAsync = true;
+
+let hasUserGesture = false;
+const media = document.querySelector(&quot;video&quot;);
+
+function endTest()
+{
+    media.remove();
+    finishJSTest();
+}
+
+media.addEventListener(&quot;canplaythrough&quot;, function() {
+    debug(&quot;Received 'canplaythrough' event&quot;);
+    // We should display the start button since we denied autoplay and the user needs a way to start playback.
+    shouldBecomeEqual(&quot;!!internals.shadowRoot(media).querySelector('button.start')&quot;, &quot;true&quot;, function() {
+        shouldBeFalse(&quot;media.controls&quot;);
+
+        debug(&quot;Pressing on the start button&quot;);
+        hasUserGesture = true;
+        pressOnElement(internals.shadowRoot(media).querySelector('button.start'));
+    });
+});
+
+media.addEventListener(&quot;play&quot;, function() {
+    debug(&quot;Received 'play' event&quot;);
+    shouldBeFalse(&quot;media.controls&quot;);
+    if (hasUserGesture) {
+        shouldBecomeEqual(&quot;internals.shadowRoot(media).querySelector('button.start')&quot;, &quot;null&quot;, endTest);
+    } else {
+        testFailed(&quot;Media started playing without user interaction&quot;);
+        endTest();
+    }
+});
+&lt;/script&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="trunkLayoutTestsplatformiossimulatorTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/TestExpectations        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -2827,6 +2827,7 @@
</span><span class="cx"> media/modern-media-controls/playback-support/playback-support-button-click.html [ Skip ]
</span><span class="cx"> media/modern-media-controls/fullscreen-support/ipad/fullscreen-support-tap.html [ Skip ]
</span><span class="cx"> media/modern-media-controls/start-support/start-support-click-to-start.html [ Skip ]
</span><ins>+media/modern-media-controls/start-support/start-support-lowPowerMode.html [ Skip ]
</ins><span class="cx"> media/modern-media-controls/button/button.html [ Skip ]
</span><span class="cx"> 
</span><span class="cx"> # AirPlay cannot be tested on iOS
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/ChangeLog        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -1,5 +1,67 @@
</span><span class="cx"> 2017-03-06  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        [iOS] Disable autoplay of silent videos in low power mode
+        https://bugs.webkit.org/show_bug.cgi?id=168985
+        &lt;rdar://problem/30739051&gt;
+
+        Reviewed by Jer Noble.
+
+        Disable autoplay of silent videos in low power mode on iOS to save battery.
+        We force the display of the start button when denying autoplay in low power
+        mode to allow the user to start playback.
+
+        Test: media/modern-media-controls/start-support/start-support-lowPowerMode.html
+
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        (WebCore::MediaControlsHost::shouldForceControlsDisplay):
+        * Modules/mediacontrols/MediaControlsHost.h:
+        * Modules/mediacontrols/MediaControlsHost.idl:
+        Add shouldForceControlsDisplay property on MediaControlsHost. This property
+        is set to true when we want to force the display for media controls. Currently,
+        this only returns true for autoplay videos, while in low power mode.
+
+        * Modules/modern-media-controls/media/controls-visibility-support.js:
+        (ControlsVisibilitySupport.prototype._updateControls):
+        Take into consideration MediaControlsHost.shouldForceControlsDisplay when
+        initializing shouldShowControls variable.
+
+        * Modules/modern-media-controls/media/start-support.js:
+        (StartSupport.prototype._shouldShowStartButton):
+        Show the start button when MediaControlsHost.shouldForceControlsDisplay
+        returns true.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement):
+        Add MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode restriction
+        to the session when low power mode is enabled so we know we need to force a
+        gesture to start playback of autoplay videos.
+
+        (WebCore::HTMLMediaElement::shouldForceControlsDisplay):
+        Add convenience function to decide if we should force display of media controls.
+        This returns true if the media element is a video with autoplay attribute and
+        its session has the MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode
+        restriction (i.e. we are in low power mode).
+
+        (WebCore::HTMLMediaElement::configureMediaControls):
+        Force requireControls variable to true if shouldForceControlsDisplay() returns
+        true. We do this here instead of inside HTMLMediaElement::controls() because
+        we do not want to change the value of media.controls exposed to JavaScript.
+
+        (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture):
+        Add MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode to the list
+        of restrictions that get removed on user gesture.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::playbackPermitted):
+        Deny playback for videos that have the RequireUserGestureForVideoDueToLowPowerMode
+        restriction unless there is a user gesture.
+
+        * html/MediaElementSession.h:
+        Add new MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode
+        restriction.
+
+2017-03-06  Chris Dumez  &lt;cdumez@apple.com&gt;
+
</ins><span class="cx">         LayoutTest fast/dom/timer-throttling-hidden-page.html is a flaky failure
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=168927
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -215,6 +215,11 @@
</span><span class="cx">     return !m_mediaElement-&gt;mediaSession().playbackPermitted(*m_mediaElement);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool MediaControlsHost::shouldForceControlsDisplay() const
+{
+    return m_mediaElement-&gt;shouldForceControlsDisplay();
+}
+
</ins><span class="cx"> String MediaControlsHost::externalDeviceDisplayName() const
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediacontrolsMediaControlsHosth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx">     bool isVideoLayerInline() const;
</span><span class="cx">     bool isInMediaDocument() const;
</span><span class="cx">     bool userGestureRequired() const;
</span><ins>+    bool shouldForceControlsDisplay() const;
</ins><span class="cx">     void setPreparedToReturnVideoLayerToInline(bool);
</span><span class="cx"> 
</span><span class="cx">     void updateCaptionDisplaySizes();
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediacontrolsMediaControlsHostidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx">     readonly attribute boolean isVideoLayerInline;
</span><span class="cx">     readonly attribute boolean userGestureRequired;
</span><span class="cx">     readonly attribute boolean isInMediaDocument;
</span><ins>+    readonly attribute boolean shouldForceControlsDisplay;
</ins><span class="cx"> 
</span><span class="cx">     readonly attribute DOMString externalDeviceDisplayName;
</span><span class="cx">     readonly attribute DeviceType externalDeviceType;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmodernmediacontrolsmediacontrolsvisibilitysupportjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/modern-media-controls/media/controls-visibility-support.js (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/modern-media-controls/media/controls-visibility-support.js        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/Modules/modern-media-controls/media/controls-visibility-support.js        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -63,7 +63,8 @@
</span><span class="cx">     _updateControls()
</span><span class="cx">     {
</span><span class="cx">         const media = this.mediaController.media;
</span><del>-        const shouldShowControls = !!media.controls;
</del><ins>+        const host = this.mediaController.host;
+        const shouldShowControls = !!(media.controls || (host &amp;&amp; host.shouldForceControlsDisplay));
</ins><span class="cx">         const isVideo = media instanceof HTMLVideoElement &amp;&amp; media.videoTracks.length &gt; 0;
</span><span class="cx"> 
</span><span class="cx">         const controls = this.mediaController.controls;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmodernmediacontrolsmediastartsupportjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/modern-media-controls/media/start-support.js (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/modern-media-controls/media/start-support.js        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/Modules/modern-media-controls/media/start-support.js        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -61,7 +61,11 @@
</span><span class="cx">     _shouldShowStartButton()
</span><span class="cx">     {
</span><span class="cx">         const media = this.mediaController.media;
</span><ins>+        const host = this.mediaController.host;
</ins><span class="cx"> 
</span><ins>+        if (host &amp;&amp; host.shouldForceControlsDisplay)
+            return true;
+
</ins><span class="cx">         if (this._hasPlayed || media.played.length)
</span><span class="cx">             return false;
</span><span class="cx"> 
</span><span class="lines">@@ -80,7 +84,6 @@
</span><span class="cx">         if (media.error)
</span><span class="cx">             return false;
</span><span class="cx"> 
</span><del>-        const host = this.mediaController.host;
</del><span class="cx">         if (!media.controls &amp;&amp; host &amp;&amp; host.allowsInlineMediaPlayback)
</span><span class="cx">             return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -456,6 +456,8 @@
</span><span class="cx">     m_sendProgressEvents = false;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    auto* page = document.page();
+
</ins><span class="cx">     if (document.settings().invisibleAutoplayNotPermitted())
</span><span class="cx">         m_mediaSession-&gt;addBehaviorRestriction(MediaElementSession::InvisibleAutoplayNotPermitted);
</span><span class="cx"> 
</span><span class="lines">@@ -470,6 +472,9 @@
</span><span class="cx">                 m_mediaSession-&gt;addBehaviorRestriction(MediaElementSession::RequireUserGestureForLoad);
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        if (page &amp;&amp; page-&gt;isLowPowerModeEnabled())
+            m_mediaSession-&gt;addBehaviorRestriction(MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode);
+
</ins><span class="cx">         if (shouldAudioPlaybackRequireUserGesture)
</span><span class="cx">             m_mediaSession-&gt;addBehaviorRestriction(MediaElementSession::RequireUserGestureForAudioRateChange);
</span><span class="cx"> 
</span><span class="lines">@@ -493,8 +498,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><del>-    if (document.page())
-        m_captionDisplayMode = document.page()-&gt;group().captionPreferences().captionDisplayMode();
</del><ins>+    if (page)
+        m_captionDisplayMode = page-&gt;group().captionPreferences().captionDisplayMode();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="lines">@@ -5931,6 +5936,12 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool HTMLMediaElement::shouldForceControlsDisplay() const
+{
+    // Always create controls for autoplay video that requires user gesture due to being in low power mode.
+    return isVideo() &amp;&amp; autoplay() &amp;&amp; m_mediaSession-&gt;hasBehaviorRestriction(MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode);
+}
+
</ins><span class="cx"> void HTMLMediaElement::configureMediaControls()
</span><span class="cx"> {
</span><span class="cx">     bool requireControls = controls();
</span><span class="lines">@@ -5939,6 +5950,9 @@
</span><span class="cx">     if (isVideo() &amp;&amp; m_mediaSession-&gt;requiresFullscreenForVideoPlayback(*this))
</span><span class="cx">         requireControls = true;
</span><span class="cx"> 
</span><ins>+    if (shouldForceControlsDisplay())
+        requireControls = true;
+
</ins><span class="cx">     // Always create controls when in full screen mode.
</span><span class="cx">     if (isFullscreen())
</span><span class="cx">         requireControls = true;
</span><span class="lines">@@ -6572,6 +6586,7 @@
</span><span class="cx">         | MediaElementSession::RequireUserGestureForVideoRateChange
</span><span class="cx">         | MediaElementSession::RequireUserGestureForAudioRateChange
</span><span class="cx">         | MediaElementSession::RequireUserGestureForFullscreen
</span><ins>+        | MediaElementSession::RequireUserGestureForVideoDueToLowPowerMode
</ins><span class="cx">         | MediaElementSession::InvisibleAutoplayNotPermitted
</span><span class="cx">         | MediaElementSession::RequireUserGestureToControlControlsManager);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -290,6 +290,8 @@
</span><span class="cx"> 
</span><span class="cx">     double percentLoaded() const;
</span><span class="cx"> 
</span><ins>+    bool shouldForceControlsDisplay() const;
+
</ins><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     ExceptionOr&lt;TextTrack&amp;&gt; addTextTrack(const String&amp; kind, const String&amp; label, const String&amp; language);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.cpp        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -174,6 +174,11 @@
</span><span class="cx">         return MediaPlaybackDenialReason::UserGestureRequired;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (m_restrictions &amp; RequireUserGestureForVideoDueToLowPowerMode &amp;&amp; element.isVideo() &amp;&amp; !ScriptController::processingUserGestureForMedia()) {
+        LOG(Media, &quot;MediaElementSession::playbackPermitted - returning FALSE because of video low power mode restriction&quot;);
+        return MediaPlaybackDenialReason::UserGestureRequired;
+    }
+
</ins><span class="cx">     return SuccessOr&lt;MediaPlaybackDenialReason&gt;();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlMediaElementSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/MediaElementSession.h (213459 => 213460)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/MediaElementSession.h        2017-03-06 19:24:48 UTC (rev 213459)
+++ trunk/Source/WebCore/html/MediaElementSession.h        2017-03-06 19:43:27 UTC (rev 213460)
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx">         OverrideUserGestureRequirementForMainContent = 1 &lt;&lt; 12,
</span><span class="cx">         RequireUserGestureToControlControlsManager = 1 &lt;&lt; 13,
</span><span class="cx">         RequirePlaybackToControlControlsManager = 1 &lt;&lt; 14,
</span><ins>+        RequireUserGestureForVideoDueToLowPowerMode = 1 &lt;&lt; 15,
</ins><span class="cx">         AllRestrictions = ~NoRestrictions,
</span><span class="cx">     };
</span><span class="cx">     typedef unsigned BehaviorRestrictions;
</span></span></pre>
</div>
</div>

</body>
</html>