<!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>[165916] 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/165916">165916</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2014-03-19 14:08:24 -0700 (Wed, 19 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make Remote Control commands testable
https://bugs.webkit.org/show_bug.cgi?id=130358
Reviewed by Jer Noble.
Source/WebCore:
Test: media/video-remote-control-playpause.html
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged): Call session->clientWillPausePlayback.
(WebCore::HTMLMediaElement::didReceiveRemoteControlCommand): Log the command.
* platform/audio/MediaSession.cpp:
(WebCore::MediaSessionClient::mediaSessionTitle): Move from header file.
(WebCore::MediaSessionClient::mediaSessionDuration): Ditto.
(WebCore::MediaSessionClient::mediaSessionCurrentTime): Ditto.
* platform/audio/MediaSession.h:
* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager): Get rid of m_activeSession.
(WebCore::MediaSessionManager::removeSession): No need to clear m_activeSession because
we use the m_sessions vector.
(WebCore::MediaSessionManager::sessionWillBeginPlayback): setCurrentSession takes a
MediaSession&.
(WebCore::MediaSessionManager::sessionWillEndPlayback): Keep m_sessions sorted so playing
sessions are before paused sessions.
(WebCore::MediaSessionManager::setCurrentSession): Move the session that is beginning to
play to the head of m_sessions.
(WebCore::MediaSessionManager::currentSession): Return m_sessions[0] or nullptr.
(WebCore::MediaSessionManager::didReceiveRemoteControlCommand):
* platform/audio/MediaSessionManager.h:
* platform/audio/ios/MediaSessionManagerIOS.mm: Include MediaPlayer.h.
* testing/Internals.cpp:
(WebCore::Internals::postRemoteControlCommand): New.
* testing/Internals.h:
* testing/Internals.idl:
LayoutTests:
* media/video-remote-control-playpause-expected.txt: Added.
* media/video-remote-control-playpause.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="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMediaSessioncpp">trunk/Source/WebCore/platform/audio/MediaSession.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMediaSessionh">trunk/Source/WebCore/platform/audio/MediaSession.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMediaSessionManagercpp">trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioMediaSessionManagerh">trunk/Source/WebCore/platform/audio/MediaSessionManager.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm">trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm</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="#trunkLayoutTestsmediavideoremotecontrolplaypauseexpectedtxt">trunk/LayoutTests/media/video-remote-control-playpause-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediavideoremotecontrolplaypausehtml">trunk/LayoutTests/media/video-remote-control-playpause.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/LayoutTests/ChangeLog        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2014-03-19 Eric Carlson <eric.carlson@apple.com>
+
+ Make Remote Control commands testable
+ https://bugs.webkit.org/show_bug.cgi?id=130358
+
+ Reviewed by Jer Noble.
+
+ * media/video-remote-control-playpause-expected.txt: Added.
+ * media/video-remote-control-playpause.html: Added.
+
</ins><span class="cx"> 2014-03-19 Thiago de Barros Lacerda <thiago.lacerda@openbossa.org>
</span><span class="cx">
</span><span class="cx"> Improving webkitGetUserMedia error handling and error messages
</span></span></pre></div>
<a id="trunkLayoutTestsmediavideoremotecontrolplaypauseexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/video-remote-control-playpause-expected.txt (0 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/video-remote-control-playpause-expected.txt         (rev 0)
+++ trunk/LayoutTests/media/video-remote-control-playpause-expected.txt        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -0,0 +1,63 @@
</span><ins>+
+Test play and pause with "remote control" interface.
+
+EVENT(canplaythrough)
+EVENT(canplaythrough)
+
+** Play both videos, the last one started (video[1]) should get focus...
+RUN(videos[0].play())
+RUN(videos[1].play())
+
+EVENT(playing)
+EVENT(playing)
+
+** Send a pause command, it should go to video[1].
+RUN(internals.postRemoteControlCommand('pause'))
+
+EVENT(pause)
+EXPECTED (event.target.id == 'two') OK
+EXPECTED (videos[0].paused == 'false') OK
+EXPECTED (videos[1].paused == 'true') OK
+
+** Pause video[0], so they both stop playing...
+RUN(videos[0].pause())
+
+EVENT(pause)
+EXPECTED (event.target.id == 'one') OK
+EXPECTED (videos[0].paused == 'true') OK
+EXPECTED (videos[1].paused == 'true') OK
+
+** Seek so video[1] will pause automatically when playback ends.
+RUN(videos[0].currentTime = 0)
+RUN(videos[1].currentTime = 5.5)
+
+EVENT(seeked)
+EVENT(seeked)
+
+** Send a play command, it should go to videos[0] because it was playing most recently.
+RUN(internals.postRemoteControlCommand('play'))
+
+EVENT(playing)
+EXPECTED (event.target.id == 'one') OK
+
+** Start videos[1], wait for it to pause at duration.
+RUN(videos[1].play())
+
+EVENT(playing)
+EXPECTED (event.target.id == 'two') OK
+
+EVENT(pause)
+EXPECTED (event.target.id == 'two') OK
+EXPECTED (videos[0].paused == 'false') OK
+EXPECTED (videos[1].paused == 'true') OK
+
+** Send a pause command, videos[0] is still playing so it should get the command.
+RUN(internals.postRemoteControlCommand('pause'))
+
+EVENT(pause)
+EXPECTED (event.target.id == 'one') OK
+EXPECTED (videos[0].paused == 'true') OK
+EXPECTED (videos[1].paused == 'true') OK
+
+END OF TEST
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediavideoremotecontrolplaypausehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/video-remote-control-playpause.html (0 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/video-remote-control-playpause.html         (rev 0)
+++ trunk/LayoutTests/media/video-remote-control-playpause.html        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -0,0 +1,146 @@
</span><ins>+<html>
+ <head>
+ <script src=media-file.js></script>
+ <script src=video-test.js></script>
+ <script>
+ var playCount = 0;
+ var pauseCount = 0;
+ var seekedCount = 0;
+ var playThroughCount = 0;
+ var videos = [];
+
+ function logEvent(evt)
+ {
+ consoleWrite("EVENT(" + evt.type + ")");
+ }
+
+ function ended(evt)
+ {
+ logEvent(evt);
+ }
+
+ function seeked(evt)
+ {
+ logEvent(evt);
+
+ switch (++seekedCount)
+ {
+ case 2:
+ consoleWrite("<br>** Send a play command, it should go to videos[0] because it was playing most recently.");
+ run("internals.postRemoteControlCommand('play')");
+ consoleWrite("");
+ break;
+ }
+ }
+
+ function pause(evt)
+ {
+ logEvent(evt);
+
+ switch (++pauseCount)
+ {
+ case 1:
+ testExpected("event.target.id", "two");
+ testExpected("videos[0].paused", false);
+ testExpected("videos[1].paused", true);
+ consoleWrite("<br>** Pause video[0], so they both stop playing...");
+ run("videos[0].pause()");
+ consoleWrite("");
+ break;
+ case 2:
+ testExpected("event.target.id", "one");
+ testExpected("videos[0].paused", true);
+ testExpected("videos[1].paused", true);
+
+ consoleWrite("<br>** Seek so video[1] will pause automatically when playback ends.");
+
+ var seekTime = (videos[1].duration - .5).toFixed(1);
+ run("videos[0].currentTime = 0");
+ run("videos[1].currentTime = " + seekTime);
+ consoleWrite("");
+ break;
+ case 3:
+ testExpected("event.target.id", "two");
+ testExpected("videos[0].paused", false);
+ testExpected("videos[1].paused", true);
+
+ consoleWrite("<br>** Send a pause command, videos[0] is still playing so it should get the command.");
+ run("internals.postRemoteControlCommand('pause')");
+ consoleWrite("");
+ break;
+ case 4:
+ testExpected("event.target.id", "one");
+ testExpected("videos[0].paused", true);
+ testExpected("videos[1].paused", true);
+ consoleWrite("");
+ endTest();
+ break;
+ case 4:
+ }
+ }
+
+ function playing(evt)
+ {
+ logEvent(evt);
+
+ switch (++playCount)
+ {
+ case 2:
+ consoleWrite("<br>** Send a pause command, it should go to video[1].");
+ run("internals.postRemoteControlCommand('pause')");
+ consoleWrite("");
+ break;
+ case 3:
+ testExpected("event.target.id", "one");
+ consoleWrite("<br>** Start videos[1], wait for it to pause at duration.");
+ run("videos[1].play()");
+ consoleWrite("");
+ break;
+ case 4:
+ testExpected("event.target.id", "two");
+ consoleWrite("");
+ break;
+ }
+ }
+
+ function canplaythrough(evt)
+ {
+ logEvent(evt);
+
+ if (++playThroughCount < 2)
+ return;
+
+ consoleWrite("<br>** Play both videos, the last one started (video[1]) should get focus...");
+ run("videos[0].play()");
+ run("videos[1].play()");
+
+ consoleWrite("");
+ }
+
+ function start()
+ {
+ if (!window.internals) {
+ failTest('This test requires window.internals.');
+ return;
+ }
+
+ videos = document.getElementsByTagName('video');
+ for (var i = 0; i < videos.length; ++i) {
+ video = videos[i];
+ video.addEventListener("canplaythrough", canplaythrough);
+ video.addEventListener('playing', playing);
+ video.addEventListener('pause', pause);
+ video.addEventListener('seeked', seeked);
+ video.addEventListener('ended');
+ video.src = findMediaFile("video", "content/test");
+ }
+ }
+ </script>
+ </head>
+
+ <body onload="start()">
+ <video controls id="one"></video>
+ <video controls id="two"></video>
+ <p>Test play and pause with "remote control" interface.</p>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/ChangeLog        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2014-03-19 Eric Carlson <eric.carlson@apple.com>
+
+ Make Remote Control commands testable
+ https://bugs.webkit.org/show_bug.cgi?id=130358
+
+ Reviewed by Jer Noble.
+
+ Test: media/video-remote-control-playpause.html
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::mediaPlayerTimeChanged): Call session->clientWillPausePlayback.
+ (WebCore::HTMLMediaElement::didReceiveRemoteControlCommand): Log the command.
+
+ * platform/audio/MediaSession.cpp:
+ (WebCore::MediaSessionClient::mediaSessionTitle): Move from header file.
+ (WebCore::MediaSessionClient::mediaSessionDuration): Ditto.
+ (WebCore::MediaSessionClient::mediaSessionCurrentTime): Ditto.
+ * platform/audio/MediaSession.h:
+
+ * platform/audio/MediaSessionManager.cpp:
+ (WebCore::MediaSessionManager::MediaSessionManager): Get rid of m_activeSession.
+ (WebCore::MediaSessionManager::removeSession): No need to clear m_activeSession because
+ we use the m_sessions vector.
+ (WebCore::MediaSessionManager::sessionWillBeginPlayback): setCurrentSession takes a
+ MediaSession&.
+ (WebCore::MediaSessionManager::sessionWillEndPlayback): Keep m_sessions sorted so playing
+ sessions are before paused sessions.
+ (WebCore::MediaSessionManager::setCurrentSession): Move the session that is beginning to
+ play to the head of m_sessions.
+ (WebCore::MediaSessionManager::currentSession): Return m_sessions[0] or nullptr.
+ (WebCore::MediaSessionManager::didReceiveRemoteControlCommand):
+ * platform/audio/MediaSessionManager.h:
+
+ * platform/audio/ios/MediaSessionManagerIOS.mm: Include MediaPlayer.h.
+
+ * testing/Internals.cpp:
+ (WebCore::Internals::postRemoteControlCommand): New.
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
</ins><span class="cx"> 2014-03-19 Thiago de Barros Lacerda <thiago.lacerda@openbossa.org>
</span><span class="cx">
</span><span class="cx"> Improving webkitGetUserMedia error handling and error messages
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -3996,6 +3996,7 @@
</span><span class="cx"> // changes paused to true and fires a simple event named pause at the media element.
</span><span class="cx"> m_paused = true;
</span><span class="cx"> scheduleEvent(eventNames().pauseEvent);
</span><ins>+ m_mediaSession->clientWillPausePlayback();
</ins><span class="cx"> }
</span><span class="cx"> // Queue a task to fire a simple event named ended at the media element.
</span><span class="cx"> if (!m_sentEndEvent) {
</span><span class="lines">@@ -5975,6 +5976,8 @@
</span><span class="cx">
</span><span class="cx"> void HTMLMediaElement::didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType command)
</span><span class="cx"> {
</span><ins>+ LOG(Media, "HTMLMediaElement::didReceiveRemoteControlCommand(%i)", static_cast<int>(command));
+
</ins><span class="cx"> switch (command) {
</span><span class="cx"> case MediaSession::PlayCommand:
</span><span class="cx"> play();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSession.cpp (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSession.cpp        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/platform/audio/MediaSession.cpp        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx">
</span><span class="cx"> #include "HTMLMediaElement.h"
</span><span class="cx"> #include "Logging.h"
</span><ins>+#include "MediaPlayer.h"
</ins><span class="cx"> #include "MediaSessionManager.h"
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -70,13 +71,13 @@
</span><span class="cx">
</span><span class="cx"> void MediaSession::setState(State state)
</span><span class="cx"> {
</span><del>- LOG(Media, "MediaSession::setState - %s", stateName(state));
</del><ins>+ LOG(Media, "MediaSession::setState(%p) - %s", this, stateName(state));
</ins><span class="cx"> m_state = state;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void MediaSession::beginInterruption()
</span><span class="cx"> {
</span><del>- LOG(Media, "MediaSession::beginInterruption");
</del><ins>+ LOG(Media, "MediaSession::beginInterruption(%p), state = %s", this, stateName(m_state));
</ins><span class="cx">
</span><span class="cx"> m_stateToRestore = state();
</span><span class="cx"> m_notifyingClient = true;
</span><span class="lines">@@ -87,7 +88,7 @@
</span><span class="cx">
</span><span class="cx"> void MediaSession::endInterruption(EndInterruptionFlags flags)
</span><span class="cx"> {
</span><del>- LOG(Media, "MediaSession::endInterruption - flags = %i, stateToRestore = %s", (int)flags, stateName(m_stateToRestore));
</del><ins>+ LOG(Media, "MediaSession::endInterruption(%p) - flags = %i, stateToRestore = %s", this, (int)flags, stateName(m_stateToRestore));
</ins><span class="cx">
</span><span class="cx"> State stateToRestore = m_stateToRestore;
</span><span class="cx"> m_stateToRestore = Idle;
</span><span class="lines">@@ -108,9 +109,12 @@
</span><span class="cx">
</span><span class="cx"> bool MediaSession::clientWillPausePlayback()
</span><span class="cx"> {
</span><ins>+ LOG(Media, "MediaSession::clientWillPausePlayback(%p)- state = %s", this, stateName(m_state));
</ins><span class="cx"> if (state() == Interrupted) {
</span><del>- if (!m_notifyingClient)
</del><ins>+ if (!m_notifyingClient) {
</ins><span class="cx"> m_stateToRestore = Paused;
</span><ins>+ LOG(Media, " setting stateToRestore to \"Paused\"");
+ }
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -121,7 +125,7 @@
</span><span class="cx">
</span><span class="cx"> void MediaSession::pauseSession()
</span><span class="cx"> {
</span><del>- LOG(Media, "MediaSession::pauseSession");
</del><ins>+ LOG(Media, "MediaSession::pauseSession(%p)", this);
</ins><span class="cx"> m_client.pausePlayback();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -154,5 +158,20 @@
</span><span class="cx"> {
</span><span class="cx"> m_client.didReceiveRemoteControlCommand(command);
</span><span class="cx"> }
</span><ins>+
+String MediaSessionClient::mediaSessionTitle() const
+{
+ return String();
+}
</ins><span class="cx">
</span><ins>+double MediaSessionClient::mediaSessionDuration() const
+{
+ return MediaPlayer::invalidTime();
</ins><span class="cx"> }
</span><ins>+
+double MediaSessionClient::mediaSessionCurrentTime() const
+{
+ return MediaPlayer::invalidTime();
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSession.h (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSession.h        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/platform/audio/MediaSession.h        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -26,8 +26,8 @@
</span><span class="cx"> #ifndef MediaSession_h
</span><span class="cx"> #define MediaSession_h
</span><span class="cx">
</span><del>-#include "MediaPlayer.h"
</del><span class="cx"> #include <wtf/Noncopyable.h>
</span><ins>+#include <wtf/text/WTFString.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="lines">@@ -109,9 +109,9 @@
</span><span class="cx"> virtual void resumePlayback() = 0;
</span><span class="cx"> virtual void pausePlayback() = 0;
</span><span class="cx">
</span><del>- virtual String mediaSessionTitle() const { return String(); }
- virtual double mediaSessionDuration() const { return MediaPlayer::invalidTime(); }
- virtual double mediaSessionCurrentTime() const { return MediaPlayer::invalidTime(); }
</del><ins>+ virtual String mediaSessionTitle() const;
+ virtual double mediaSessionDuration() const;
+ virtual double mediaSessionCurrentTime() const;
</ins><span class="cx">
</span><span class="cx"> virtual bool canReceiveRemoteControlCommands() const = 0;
</span><span class="cx"> virtual void didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -40,8 +40,7 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> MediaSessionManager::MediaSessionManager()
</span><del>- : m_activeSession(nullptr)
- , m_interrupted(false)
</del><ins>+ : m_interrupted(false)
</ins><span class="cx"> {
</span><span class="cx"> resetRestrictions();
</span><span class="cx"> }
</span><span class="lines">@@ -68,7 +67,7 @@
</span><span class="cx"> int MediaSessionManager::count(MediaSession::MediaType type) const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(type >= MediaSession::None && type <= MediaSession::WebAudio);
</span><del>-
</del><ins>+
</ins><span class="cx"> int count = 0;
</span><span class="cx"> for (auto* session : m_sessions) {
</span><span class="cx"> if (session->mediaType() == type)
</span><span class="lines">@@ -83,7 +82,8 @@
</span><span class="cx"> LOG(Media, "MediaSessionManager::beginInterruption");
</span><span class="cx">
</span><span class="cx"> m_interrupted = true;
</span><del>- for (auto* session : m_sessions)
</del><ins>+ Vector<MediaSession*> sessions = m_sessions;
+ for (auto* session : sessions)
</ins><span class="cx"> session->beginInterruption();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -92,12 +92,15 @@
</span><span class="cx"> LOG(Media, "MediaSessionManager::endInterruption");
</span><span class="cx">
</span><span class="cx"> m_interrupted = false;
</span><del>- for (auto* session : m_sessions)
</del><ins>+ Vector<MediaSession*> sessions = m_sessions;
+ for (auto* session : sessions)
</ins><span class="cx"> session->endInterruption(flags);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void MediaSessionManager::addSession(MediaSession& session)
</span><span class="cx"> {
</span><ins>+ LOG(Media, "MediaSessionManager::addSession - %p", &session);
+
</ins><span class="cx"> m_sessions.append(&session);
</span><span class="cx"> if (m_interrupted)
</span><span class="cx"> session.setState(MediaSession::Interrupted);
</span><span class="lines">@@ -115,14 +118,13 @@
</span><span class="cx">
</span><span class="cx"> void MediaSessionManager::removeSession(MediaSession& session)
</span><span class="cx"> {
</span><ins>+ LOG(Media, "MediaSessionManager::removeSession - %p", &session);
+
</ins><span class="cx"> size_t index = m_sessions.find(&session);
</span><span class="cx"> ASSERT(index != notFound);
</span><span class="cx"> if (index == notFound)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- if (m_activeSession == &session)
- setCurrentSession(nullptr);
-
</del><span class="cx"> m_sessions.remove(index);
</span><span class="cx"> updateSessionState();
</span><span class="cx">
</span><span class="lines">@@ -156,7 +158,9 @@
</span><span class="cx">
</span><span class="cx"> void MediaSessionManager::sessionWillBeginPlayback(MediaSession& session)
</span><span class="cx"> {
</span><del>- setCurrentSession(&session);
</del><ins>+ LOG(Media, "MediaSessionManager::sessionWillBeginPlayback - %p", &session);
+
+ setCurrentSession(session);
</ins><span class="cx">
</span><span class="cx"> if (!m_clients.isEmpty() && (session.mediaType() == MediaSession::Video || session.mediaType() == MediaSession::Audio)) {
</span><span class="cx"> for (auto& client : m_clients)
</span><span class="lines">@@ -168,7 +172,8 @@
</span><span class="cx"> if (!restrictions & ConcurrentPlaybackNotPermitted)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- for (auto* oneSession : m_sessions) {
</del><ins>+ Vector<MediaSession*> sessions = m_sessions;
+ for (auto* oneSession : sessions) {
</ins><span class="cx"> if (oneSession == &session)
</span><span class="cx"> continue;
</span><span class="cx"> if (oneSession->mediaType() != sessionType)
</span><span class="lines">@@ -177,7 +182,68 @@
</span><span class="cx"> oneSession->pauseSession();
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+void MediaSessionManager::sessionWillEndPlayback(MediaSession& session)
+{
+ LOG(Media, "MediaSessionManager::sessionWillEndPlayback - %p", &session);
+
+ if (m_sessions.size() < 2)
+ return;
+
+ size_t pausingSessionIndex = notFound;
+ size_t lastPlayingSessionIndex = notFound;
+ for (size_t i = 0; i < m_sessions.size(); ++i) {
+ MediaSession* oneSession = m_sessions[i];
+
+ if (oneSession == &session) {
+ pausingSessionIndex = i;
+ continue;
+ }
+ if (oneSession->state() == MediaSession::Playing) {
+ lastPlayingSessionIndex = i;
+ continue;
+ }
+ if (oneSession->state() != MediaSession::Playing)
+ break;
+ }
+ if (lastPlayingSessionIndex == notFound || pausingSessionIndex == notFound)
+ return;
+
+ if (pausingSessionIndex > lastPlayingSessionIndex)
+ return;
+
+ m_sessions.remove(pausingSessionIndex);
+ m_sessions.insert(lastPlayingSessionIndex, &session);
+
+ LOG(Media, "MediaSessionManager::sessionWillEndPlayback - session moved from index %zu to %zu", pausingSessionIndex, lastPlayingSessionIndex);
+}
</ins><span class="cx">
</span><ins>+void MediaSessionManager::setCurrentSession(MediaSession& session)
+{
+ LOG(Media, "MediaSessionManager::setCurrentSession - %p", &session);
+
+ if (m_sessions.size() < 2)
+ return;
+
+ size_t index = m_sessions.find(&session);
+ ASSERT(index != notFound);
+ if (!index || index == notFound)
+ return;
+
+ m_sessions.remove(index);
+ m_sessions.insert(0, &session);
+
+ LOG(Media, "MediaSessionManager::setCurrentSession - session moved from index %zu to 0", index);
+}
+
+MediaSession* MediaSessionManager::currentSession()
+{
+ if (!m_sessions.size())
+ return nullptr;
+
+ return m_sessions[0];
+}
+
</ins><span class="cx"> bool MediaSessionManager::sessionRestrictsInlineVideoPlayback(const MediaSession& session) const
</span><span class="cx"> {
</span><span class="cx"> MediaSession::MediaType sessionType = session.mediaType();
</span><span class="lines">@@ -190,7 +256,8 @@
</span><span class="cx"> void MediaSessionManager::applicationWillEnterBackground() const
</span><span class="cx"> {
</span><span class="cx"> LOG(Media, "MediaSessionManager::applicationWillEnterBackground");
</span><del>- for (auto* session : m_sessions) {
</del><ins>+ Vector<MediaSession*> sessions = m_sessions;
+ for (auto* session : sessions) {
</ins><span class="cx"> if (m_restrictions[session->mediaType()] & BackgroundPlaybackNotPermitted)
</span><span class="cx"> session->beginInterruption();
</span><span class="cx"> }
</span><span class="lines">@@ -199,7 +266,8 @@
</span><span class="cx"> void MediaSessionManager::applicationWillEnterForeground() const
</span><span class="cx"> {
</span><span class="cx"> LOG(Media, "MediaSessionManager::applicationWillEnterForeground");
</span><del>- for (auto* session : m_sessions) {
</del><ins>+ Vector<MediaSession*> sessions = m_sessions;
+ for (auto* session : sessions) {
</ins><span class="cx"> if (m_restrictions[session->mediaType()] & BackgroundPlaybackNotPermitted)
</span><span class="cx"> session->endInterruption(MediaSession::MayResumePlaying);
</span><span class="cx"> }
</span><span class="lines">@@ -213,9 +281,10 @@
</span><span class="cx">
</span><span class="cx"> void MediaSessionManager::didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType command)
</span><span class="cx"> {
</span><del>- if (!m_activeSession || !m_activeSession->canReceiveRemoteControlCommands())
</del><ins>+ MediaSession* activeSession = currentSession();
+ if (!activeSession || !activeSession->canReceiveRemoteControlCommands())
</ins><span class="cx"> return;
</span><del>- m_activeSession->didReceiveRemoteControlCommand(command);
</del><ins>+ activeSession->didReceiveRemoteControlCommand(command);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void MediaSessionManager::addClient(MediaSessionManagerClient* client)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.h (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSessionManager.h        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.h        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx"> virtual void resetRestrictions();
</span><span class="cx">
</span><span class="cx"> virtual void sessionWillBeginPlayback(MediaSession&);
</span><del>- virtual void sessionWillEndPlayback(MediaSession&) { }
</del><ins>+ virtual void sessionWillEndPlayback(MediaSession&);
</ins><span class="cx">
</span><span class="cx"> bool sessionRestrictsInlineVideoPlayback(const MediaSession&) const;
</span><span class="cx">
</span><span class="lines">@@ -101,8 +101,8 @@
</span><span class="cx"> void addSession(MediaSession&);
</span><span class="cx"> void removeSession(MediaSession&);
</span><span class="cx">
</span><del>- void setCurrentSession(MediaSession* session) { m_activeSession = session; }
- MediaSession* currentSession() { return m_activeSession; }
</del><ins>+ void setCurrentSession(MediaSession&);
+ MediaSession* currentSession();
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> void updateSessionState();
</span><span class="lines">@@ -112,7 +112,6 @@
</span><span class="cx"> Vector<MediaSession*> m_sessions;
</span><span class="cx"> Vector<MediaSessionManagerClient*> m_clients;
</span><span class="cx"> std::unique_ptr<RemoteCommandListener> m_remoteCommandListener;
</span><del>- MediaSession* m_activeSession;
</del><span class="cx"> bool m_interrupted;
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">
</span><span class="cx"> #import "Logging.h"
</span><ins>+#import "MediaPlayer.h"
</ins><span class="cx"> #import "MediaSession.h"
</span><span class="cx"> #import "NotImplemented.h"
</span><span class="cx"> #import "SoftLinking.h"
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/testing/Internals.cpp        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -2290,5 +2290,33 @@
</span><span class="cx">
</span><span class="cx"> MediaSessionManager::sharedManager().addRestriction(mediaType, restrictions);
</span><span class="cx"> }
</span><del>-
</del><ins>+
+void Internals::postRemoteControlCommand(const String& commandString, ExceptionCode& ec)
+{
+ MediaSession::RemoteControlCommandType command;
+
+ if (equalIgnoringCase(commandString, "Play"))
+ command = MediaSession::PlayCommand;
+ else if (equalIgnoringCase(commandString, "Pause"))
+ command = MediaSession::PauseCommand;
+ else if (equalIgnoringCase(commandString, "Stop"))
+ command = MediaSession::StopCommand;
+ else if (equalIgnoringCase(commandString, "TogglePlayPause"))
+ command = MediaSession::TogglePlayPauseCommand;
+ else if (equalIgnoringCase(commandString, "BeginSeekingBackward"))
+ command = MediaSession::BeginSeekingBackwardCommand;
+ else if (equalIgnoringCase(commandString, "EndSeekingBackward"))
+ command = MediaSession::EndSeekingBackwardCommand;
+ else if (equalIgnoringCase(commandString, "BeginSeekingForward"))
+ command = MediaSession::BeginSeekingForwardCommand;
+ else if (equalIgnoringCase(commandString, "EndSeekingForward"))
+ command = MediaSession::EndSeekingForwardCommand;
+ else {
+ ec = INVALID_ACCESS_ERR;
+ return;
+ }
+
+ MediaSessionManager::sharedManager().didReceiveRemoteControlCommand(command);
</ins><span class="cx"> }
</span><ins>+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/testing/Internals.h        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -333,7 +333,8 @@
</span><span class="cx"> void endMediaSessionInterruption(const String&);
</span><span class="cx"> void applicationWillEnterForeground() const;
</span><span class="cx"> void applicationWillEnterBackground() const;
</span><del>- void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode& ec);
</del><ins>+ void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode&);
+ void postRemoteControlCommand(const String&, ExceptionCode&);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> explicit Internals(Document*);
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (165915 => 165916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2014-03-19 21:06:38 UTC (rev 165915)
+++ trunk/Source/WebCore/testing/Internals.idl        2014-03-19 21:08:24 UTC (rev 165916)
</span><span class="lines">@@ -283,4 +283,5 @@
</span><span class="cx"> void applicationWillEnterForeground();
</span><span class="cx"> void applicationWillEnterBackground();
</span><span class="cx"> [RaisesException] void setMediaSessionRestrictions(DOMString mediaType, DOMString restrictions);
</span><ins>+ [RaisesException] void postRemoteControlCommand(DOMString command);
</ins><span class="cx"> };
</span></span></pre>
</div>
</div>
</body>
</html>