<!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>[165552] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/165552">165552</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2014-03-13 11:24:06 -0700 (Thu, 13 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Sync media playback with now playing
https://bugs.webkit.org/show_bug.cgi?id=130172

Reviewed by Jer Noble.
        
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::play): Move clientWillBeginPlayback to
    playInternal so it is called every time playback begins.
(WebCore::HTMLMediaElement::playInternal): Call clientWillBeginPlayback.
(WebCore::HTMLMediaElement::pause): Move clientWillPausePlayback to
    playInternal so it is called every time playback begins.
(WebCore::HTMLMediaElement::playInternal): Call clientWillPausePlayback.
(WebCore::HTMLMediaElement::mediaSessionTitle): New. Return the 'title' attribute,
    or currenSrc if that is empty.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::mediaSessionDuration): Return duration.
(WebCore::HTMLMediaElement::mediaSessionCurrentTime): Return current time.

* platform/audio/MediaSession.cpp:
(WebCore::MediaSession::clientWillPausePlayback): New, passthrough to the
    media element.
(WebCore::MediaSession::title): Ditto.
(WebCore::MediaSession::duration): Ditto.
(WebCore::MediaSession::currentTime): Ditto.
* platform/audio/MediaSession.h:
(WebCore::MediaSessionClient::mediaSessionTitle):
(WebCore::MediaSessionClient::mediaSessionDuration):
(WebCore::MediaSessionClient::mediaSessionCurrentTime):

* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager): Initialize m_activeSession.
(WebCore::MediaSessionManager::removeSession): Set m_activeSession if the session
    being removed is currently active.
(WebCore::MediaSessionManager::sessionWillBeginPlayback): Set m_activeSession.
* platform/audio/MediaSessionManager.h:
(WebCore::MediaSessionManager::sessionWillEndPlayback):
(WebCore::MediaSessionManager::setCurrentSession):
(WebCore::MediaSessionManager::currentSession):

* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::sessionWillBeginPlayback): Call updateNowPlayingInfo. 
(WebCore::MediaSessionManageriOS::sessionWillEndPlayback): Ditto.
(WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Update MPNowPlayingInfoCenter
    with the current media item's title, duration, and current time.
(-[WebMediaSessionHelper initWithCallback:]): Turn on deliver of remote control
    events, even though we don't respond to them yet, or Now Playing won't work.</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</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="#trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSh">trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm">trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/ChangeLog        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -1,3 +1,53 @@
</span><ins>+2014-03-12  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [iOS] Sync media playback with now playing
+        https://bugs.webkit.org/show_bug.cgi?id=130172
+
+        Reviewed by Jer Noble.
+        
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::play): Move clientWillBeginPlayback to
+            playInternal so it is called every time playback begins.
+        (WebCore::HTMLMediaElement::playInternal): Call clientWillBeginPlayback.
+        (WebCore::HTMLMediaElement::pause): Move clientWillPausePlayback to
+            playInternal so it is called every time playback begins.
+        (WebCore::HTMLMediaElement::playInternal): Call clientWillPausePlayback.
+        (WebCore::HTMLMediaElement::mediaSessionTitle): New. Return the 'title' attribute,
+            or currenSrc if that is empty.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::mediaSessionDuration): Return duration.
+        (WebCore::HTMLMediaElement::mediaSessionCurrentTime): Return current time.
+
+        * platform/audio/MediaSession.cpp:
+        (WebCore::MediaSession::clientWillPausePlayback): New, passthrough to the
+            media element.
+        (WebCore::MediaSession::title): Ditto.
+        (WebCore::MediaSession::duration): Ditto.
+        (WebCore::MediaSession::currentTime): Ditto.
+        * platform/audio/MediaSession.h:
+        (WebCore::MediaSessionClient::mediaSessionTitle):
+        (WebCore::MediaSessionClient::mediaSessionDuration):
+        (WebCore::MediaSessionClient::mediaSessionCurrentTime):
+
+        * platform/audio/MediaSessionManager.cpp:
+        (WebCore::MediaSessionManager::MediaSessionManager): Initialize m_activeSession.
+        (WebCore::MediaSessionManager::removeSession): Set m_activeSession if the session
+            being removed is currently active.
+        (WebCore::MediaSessionManager::sessionWillBeginPlayback): Set m_activeSession.
+        * platform/audio/MediaSessionManager.h:
+        (WebCore::MediaSessionManager::sessionWillEndPlayback):
+        (WebCore::MediaSessionManager::setCurrentSession):
+        (WebCore::MediaSessionManager::currentSession):
+
+        * platform/audio/ios/MediaSessionManagerIOS.h:
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::sessionWillBeginPlayback): Call updateNowPlayingInfo. 
+        (WebCore::MediaSessionManageriOS::sessionWillEndPlayback): Ditto.
+        (WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Update MPNowPlayingInfoCenter
+            with the current media item's title, duration, and current time.
+        (-[WebMediaSessionHelper initWithCallback:]): Turn on deliver of remote control
+            events, even though we don't respond to them yet, or Now Playing won't work.
+
</ins><span class="cx"> 2014-03-13  Radu Stavila  &lt;stavila@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Webkit not building on XCode 5.1 due to garbage collection no longer being supported
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -2684,18 +2684,18 @@
</span><span class="cx">     if (ScriptController::processingUserGesture())
</span><span class="cx">         removeBehaviorsRestrictionsAfterFirstUserGesture();
</span><span class="cx"> 
</span><del>-    if (!m_mediaSession-&gt;clientWillBeginPlayback()) {
-        LOG(Media, &quot;  returning because of interruption&quot;);
-        return;
-    }
-    
</del><span class="cx">     playInternal();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLMediaElement::playInternal()
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;HTMLMediaElement::playInternal&quot;);
</span><del>-
</del><ins>+    
+    if (!m_mediaSession-&gt;clientWillBeginPlayback()) {
+        LOG(Media, &quot;  returning because of interruption&quot;);
+        return;
+    }
+    
</ins><span class="cx">     // 4.8.10.9. Playing the media resource
</span><span class="cx">     if (!m_player || m_networkState == NETWORK_EMPTY)
</span><span class="cx">         scheduleDelayedAction(LoadMediaResource);
</span><span class="lines">@@ -2731,11 +2731,6 @@
</span><span class="cx">     if (!m_mediaSession-&gt;playbackPermitted(*this))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!m_mediaSession-&gt;clientWillPausePlayback()) {
-        LOG(Media, &quot;  returning because of interruption&quot;);
-        return;
-    }
-
</del><span class="cx">     pauseInternal();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2744,6 +2739,11 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(Media, &quot;HTMLMediaElement::pauseInternal&quot;);
</span><span class="cx"> 
</span><ins>+    if (!m_mediaSession-&gt;clientWillPausePlayback()) {
+        LOG(Media, &quot;  returning because of interruption&quot;);
+        return;
+    }
+    
</ins><span class="cx">     // 4.8.10.9. Playing the media resource
</span><span class="cx">     if (!m_player || m_networkState == NETWORK_EMPTY) {
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -5878,6 +5878,14 @@
</span><span class="cx">     if (paused())
</span><span class="cx">         play();
</span><span class="cx"> }
</span><ins>+    
+String HTMLMediaElement::mediaSessionTitle() const
+{
+    if (fastHasAttribute(titleAttr))
+        return fastGetAttribute(titleAttr);
+    
+    return m_currentSrc;
+}
</ins><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -690,9 +690,13 @@
</span><span class="cx">     bool ensureMediaControlsInjectedScript();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    // MediaSessionClient Overrides
</ins><span class="cx">     virtual MediaSession::MediaType mediaType() const override;
</span><span class="cx">     virtual void pausePlayback() override;
</span><span class="cx">     virtual void resumePlayback() override;
</span><ins>+    virtual String mediaSessionTitle() const override;
+    virtual double mediaSessionDuration() const override { return duration(); }
+    virtual double mediaSessionCurrentTime() const override { return currentTime(); }
</ins><span class="cx"> 
</span><span class="cx">     Timer&lt;HTMLMediaElement&gt; m_loadTimer;
</span><span class="cx">     Timer&lt;HTMLMediaElement&gt; m_progressEventTimer;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSession.cpp (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSession.cpp        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/MediaSession.cpp        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -115,6 +115,7 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     setState(Paused);
</span><ins>+    MediaSessionManager::sharedManager().sessionWillEndPlayback(*this);
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -128,5 +129,20 @@
</span><span class="cx"> {
</span><span class="cx">     return m_client.mediaType();
</span><span class="cx"> }
</span><ins>+
+String MediaSession::title() const
+{
+    return m_client.mediaSessionTitle();
+}
+
+double MediaSession::duration() const
+{
+    return m_client.mediaSessionDuration();
+}
+
+double MediaSession::currentTime() const
+{
+    return m_client.mediaSessionCurrentTime();
+}
</ins><span class="cx">     
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSession.h (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSession.h        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/MediaSession.h        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #ifndef MediaSession_h
</span><span class="cx"> #define MediaSession_h
</span><span class="cx"> 
</span><ins>+#include &quot;MediaPlayer.h&quot;
</ins><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -70,6 +71,10 @@
</span><span class="cx">     bool clientWillPausePlayback();
</span><span class="cx"> 
</span><span class="cx">     void pauseSession();
</span><ins>+    
+    String title() const;
+    double duration() const;
+    double currentTime() const;
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     MediaSessionClient&amp; client() const { return m_client; }
</span><span class="lines">@@ -89,7 +94,11 @@
</span><span class="cx">     virtual MediaSession::MediaType mediaType() const = 0;
</span><span class="cx">     virtual void resumePlayback() = 0;
</span><span class="cx">     virtual void pausePlayback() = 0;
</span><del>-
</del><ins>+    
+    virtual String mediaSessionTitle() const { return String(); }
+    virtual double mediaSessionDuration() const { return MediaPlayer::invalidTime(); }
+    virtual double mediaSessionCurrentTime() const { return MediaPlayer::invalidTime(); }
+    
</ins><span class="cx"> protected:
</span><span class="cx">     virtual ~MediaSessionClient() { }
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.cpp        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -40,7 +40,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> MediaSessionManager::MediaSessionManager()
</span><del>-    : m_interrupted(false)
</del><ins>+    : m_activeSession(nullptr)
+    , m_interrupted(false)
</ins><span class="cx"> {
</span><span class="cx">     resetRestrictions();
</span><span class="cx"> }
</span><span class="lines">@@ -109,7 +110,10 @@
</span><span class="cx">     ASSERT(index != notFound);
</span><span class="cx">     if (index == notFound)
</span><span class="cx">         return;
</span><del>-
</del><ins>+    
+    if (m_activeSession == &amp;session)
+        setCurrentSession(nullptr);
+    
</ins><span class="cx">     m_sessions.remove(index);
</span><span class="cx">     updateSessionState();
</span><span class="cx"> }
</span><span class="lines">@@ -132,8 +136,10 @@
</span><span class="cx">     return m_restrictions[type];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MediaSessionManager::sessionWillBeginPlayback(const MediaSession&amp; session) const
</del><ins>+void MediaSessionManager::sessionWillBeginPlayback(const MediaSession&amp; session)
</ins><span class="cx"> {
</span><ins>+    setCurrentSession(&amp;session);
+    
</ins><span class="cx">     MediaSession::MediaType sessionType = session.mediaType();
</span><span class="cx">     SessionRestrictions restrictions = m_restrictions[sessionType];
</span><span class="cx">     if (!restrictions &amp; ConcurrentPlaybackNotPermitted)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioMediaSessionManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/MediaSessionManager.h (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/MediaSessionManager.h        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/MediaSessionManager.h        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -65,8 +65,9 @@
</span><span class="cx">     SessionRestrictions restrictions(MediaSession::MediaType);
</span><span class="cx">     virtual void resetRestrictions();
</span><span class="cx"> 
</span><del>-    void sessionWillBeginPlayback(const MediaSession&amp;) const;
-
</del><ins>+    virtual void sessionWillBeginPlayback(const MediaSession&amp;);
+    virtual void sessionWillEndPlayback(const MediaSession&amp;) { }
+    
</ins><span class="cx">     bool sessionRestrictsInlineVideoPlayback(const MediaSession&amp;) const;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(IOS_AIRPLAY)
</span><span class="lines">@@ -79,13 +80,17 @@
</span><span class="cx"> 
</span><span class="cx">     void addSession(MediaSession&amp;);
</span><span class="cx">     void removeSession(MediaSession&amp;);
</span><del>-
</del><ins>+    
+    void setCurrentSession(const MediaSession* session) { m_activeSession = session; }
+    const MediaSession* currentSession() { return m_activeSession; }
+    
</ins><span class="cx"> private:
</span><span class="cx">     void updateSessionState();
</span><span class="cx"> 
</span><span class="cx">     SessionRestrictions m_restrictions[MediaSession::WebAudio + 1];
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;MediaSession*&gt; m_sessions;
</span><ins>+    const MediaSession* m_activeSession;
</ins><span class="cx">     bool m_interrupted;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -48,6 +48,11 @@
</span><span class="cx"> private:
</span><span class="cx">     friend class MediaSessionManager;
</span><span class="cx"> 
</span><ins>+    virtual void sessionWillBeginPlayback(const MediaSession&amp;) override;
+    virtual void sessionWillEndPlayback(const MediaSession&amp;) override;
+    
+    void updateNowPlayingInfo();
+    
</ins><span class="cx">     virtual void resetRestrictions() override;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(IOS_AIRPLAY)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (165551 => 165552)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2014-03-13 18:12:52 UTC (rev 165551)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2014-03-13 18:24:06 UTC (rev 165552)
</span><span class="lines">@@ -35,30 +35,46 @@
</span><span class="cx"> #import &quot;WebCoreSystemInterface.h&quot;
</span><span class="cx"> #import &quot;WebCoreThreadRun.h&quot;
</span><span class="cx"> #import &lt;AVFoundation/AVAudioSession.h&gt;
</span><ins>+#import &lt;MediaPlayer/MPMediaItem.h&gt;
+#import &lt;MediaPlayer/MPNowPlayingInfoCenter.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIApplication.h&gt;
</span><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(AVFoundation)
</span><del>-SOFT_LINK_FRAMEWORK(UIKit)
-
</del><span class="cx"> SOFT_LINK_CLASS(AVFoundation, AVAudioSession)
</span><del>-
</del><span class="cx"> SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionNotification, NSString *)
</span><span class="cx"> SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionTypeKey, NSString *)
</span><span class="cx"> SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionOptionKey, NSString *)
</span><del>-SOFT_LINK_POINTER(UIKit, UIApplicationWillResignActiveNotification, NSString *)
-SOFT_LINK_POINTER(UIKit, UIApplicationWillEnterForegroundNotification, NSString *)
-SOFT_LINK_POINTER(UIKit, UIApplicationDidBecomeActiveNotification, NSString *)
</del><span class="cx"> 
</span><span class="cx"> #define AVAudioSession getAVAudioSessionClass()
</span><span class="cx"> #define AVAudioSessionInterruptionNotification getAVAudioSessionInterruptionNotification()
</span><span class="cx"> #define AVAudioSessionInterruptionTypeKey getAVAudioSessionInterruptionTypeKey()
</span><span class="cx"> #define AVAudioSessionInterruptionOptionKey getAVAudioSessionInterruptionOptionKey()
</span><ins>+
+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK_CLASS(UIKit, UIApplication)
+SOFT_LINK_POINTER(UIKit, UIApplicationWillResignActiveNotification, NSString *)
+SOFT_LINK_POINTER(UIKit, UIApplicationWillEnterForegroundNotification, NSString *)
+SOFT_LINK_POINTER(UIKit, UIApplicationDidBecomeActiveNotification, NSString *)
+
+#define UIApplication getUIApplicationClass()
</ins><span class="cx"> #define UIApplicationWillResignActiveNotification getUIApplicationWillResignActiveNotification()
</span><span class="cx"> #define UIApplicationWillEnterForegroundNotification getUIApplicationWillEnterForegroundNotification()
</span><span class="cx"> #define UIApplicationDidBecomeActiveNotification getUIApplicationDidBecomeActiveNotification()
</span><span class="cx"> 
</span><ins>+SOFT_LINK_FRAMEWORK(MediaPlayer)
+SOFT_LINK_CLASS(MediaPlayer, MPNowPlayingInfoCenter)
+SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyTitle, NSString *)
+SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyPlaybackDuration, NSString *)
+SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyElapsedPlaybackTime, NSString *)
+SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyPlaybackRate, NSString *)
+
+#define MPMediaItemPropertyTitle getMPMediaItemPropertyTitle()
+#define MPMediaItemPropertyPlaybackDuration getMPMediaItemPropertyPlaybackDuration()
+#define MPNowPlayingInfoPropertyElapsedPlaybackTime getMPNowPlayingInfoPropertyElapsedPlaybackTime()
+#define MPNowPlayingInfoPropertyPlaybackRate getMPNowPlayingInfoPropertyPlaybackRate()
+
</ins><span class="cx"> NSString* WebUIApplicationWillResignActiveNotification = @&quot;WebUIApplicationWillResignActiveNotification&quot;;
</span><span class="cx"> NSString* WebUIApplicationWillEnterForegroundNotification = @&quot;WebUIApplicationWillEnterForegroundNotification&quot;;
</span><span class="cx"> NSString* WebUIApplicationDidBecomeActiveNotification = @&quot;WebUIApplicationDidBecomeActiveNotification&quot;;
</span><span class="lines">@@ -119,6 +135,46 @@
</span><span class="cx">     notImplemented();
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><ins>+    
+void MediaSessionManageriOS::sessionWillBeginPlayback(const MediaSession&amp; session)
+{
+    MediaSessionManager::sessionWillBeginPlayback(session);
+    updateNowPlayingInfo();
+}
+    
+void MediaSessionManageriOS::sessionWillEndPlayback(const MediaSession&amp; session)
+{
+    MediaSessionManager::sessionWillEndPlayback(session);
+    updateNowPlayingInfo();
+}
+    
+void MediaSessionManageriOS::updateNowPlayingInfo()
+{
+    MPNowPlayingInfoCenter *nowPlaying = (MPNowPlayingInfoCenter *)[getMPNowPlayingInfoCenterClass() defaultCenter];
+    const MediaSession* currentSession = this-&gt;currentSession();
+    
+    if (!currentSession) {
+        [nowPlaying setNowPlayingInfo:nil];
+        return;
+    }
+    
+    RetainPtr&lt;NSMutableDictionary&gt; info = adoptNS([[NSMutableDictionary alloc] init]);
+    
+    String title = currentSession-&gt;title();
+    if (!title.isEmpty())
+        [info setValue:static_cast&lt;NSString *&gt;(title) forKey:MPMediaItemPropertyTitle];
+    
+    double duration = currentSession-&gt;duration();
+    if (std::isfinite(duration) &amp;&amp; duration != MediaPlayer::invalidTime())
+        [info setValue:@(duration) forKey:MPMediaItemPropertyPlaybackDuration];
+    
+    double currentTime = currentSession-&gt;currentTime();
+    if (std::isfinite(currentTime))
+        [info setValue:@(currentTime) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
+    
+    [info setValue:(currentSession-&gt;state() == MediaSession::Playing ? @YES : @NO) forKey:MPNowPlayingInfoPropertyPlaybackRate];
+    [nowPlaying setNowPlayingInfo:info.get()];
+}
</ins><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="lines">@@ -134,14 +190,16 @@
</span><span class="cx">     NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
</span><span class="cx">     [center addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
</span><span class="cx"> 
</span><del>-    // FIXME: These need to be piped through from the UI process in WK2 mode.
</del><span class="cx">     [center addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
</span><span class="cx">     [center addObserver:self selector:@selector(applicationWillEnterForeground:) name:WebUIApplicationWillEnterForegroundNotification object:nil];
</span><span class="cx">     [center addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
</span><span class="cx">     [center addObserver:self selector:@selector(applicationDidBecomeActive:) name:WebUIApplicationDidBecomeActiveNotification object:nil];
</span><span class="cx">     [center addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
</span><span class="cx">     [center addObserver:self selector:@selector(applicationWillResignActive:) name:WebUIApplicationWillResignActiveNotification object:nil];
</span><del>-
</del><ins>+    
+    // Now playing won't work unless we turn on the delivery of remote control events.
+    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
+    
</ins><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>