<!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>[188030] trunk/Source</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/188030">188030</a></dd>
<dt>Author</dt> <dd>mrajca@apple.com</dd>
<dt>Date</dt> <dd>2015-08-06 00:13:55 -0700 (Thu, 06 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Media Session: push paused state to the media session focus manager instead of polling
https://bugs.webkit.org/show_bug.cgi?id=147633

Reviewed by Simon Fraser.

WebCore:
* dom/Document.cpp:
(WebCore::Document::updateIsPlayingMedia): If a valid source element ID is passed in, set the 'IsSourcePlaying'
 flag accordingly.
* dom/Document.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::elementWithID):
(WebCore::HTMLMediaElement::setMuted): Pass along the element ID.
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged): Ditto.
(WebCore::HTMLMediaElement::setPlaying): Ditto.
* html/HTMLMediaElement.h:
* page/ChromeClient.h:
* page/MediaProducer.h:
* page/Page.cpp:
(WebCore::Page::updateIsPlayingMedia): Pass along the source element ID.
(WebCore::Page::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
* page/Page.h:

WebKit2:
* UIProcess/WebMediaSessionFocusManager.cpp:
(WebKit::WebMediaSessionFocusManager::isFocusedContentMediaElementPaused): Report whether the focused media
 element is currently playing. The callback is no longer necessary and will be removed in a future patch in
 favor of returning a value directly.
(WebKit::WebMediaSessionFocusManager::mediaElementIsPlayingDidChange): Keep track of whether the focused media
 element is currently playing.
* UIProcess/WebMediaSessionFocusManager.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::isPlayingMediaDidChange): If the focused media element begins/ends playing, keep track
 of its playing state.
(WebKit::WebPageProxy::isMediaElementPaused): Deleted. We now push media playback state changes instead of
 polling.
* UIProcess/WebPageProxy.h: isPlayingMediaDidChange is now passed the ID of the media element that triggered
 the 'playing' state change. This can be used in conjunction with the IsSourcePlaying media flag to identify
 whether the source element begin/ended playing.
* UIProcess/WebPageProxy.messages.in: Ditto.
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::setPluginIsPlayingAudio): Since a media element did not trigger this, pass in 0 for the
 source media element.
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::isPlayingMediaDidChange): isPlayingMediaDidChange is now passed the ID of the media
 element that triggered the 'playing' state change.
* WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
* WebProcess/WebPage/WebPage.h: Ditto.
* WebProcess/WebPage/WebPage.messages.in: Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</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="#trunkSourceWebCorepageChromeClienth">trunk/Source/WebCore/page/ChromeClient.h</a></li>
<li><a href="#trunkSourceWebCorepageMediaProducerh">trunk/Source/WebCore/page/MediaProducer.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebMediaSessionFocusManagercpp">trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebMediaSessionFocusManagerh">trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/ChangeLog        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2015-08-04  Matt Rajca  &lt;mrajca@apple.com&gt;
+
+        Media Session: push paused state to the media session focus manager instead of polling
+        https://bugs.webkit.org/show_bug.cgi?id=147633
+
+        Reviewed by Simon Fraser.
+
+        * dom/Document.cpp:
+        (WebCore::Document::updateIsPlayingMedia): If a valid source element ID is passed in, set the 'IsSourcePlaying'
+         flag accordingly.
+        * dom/Document.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::elementWithID):
+        (WebCore::HTMLMediaElement::setMuted): Pass along the element ID.
+        (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged): Ditto.
+        (WebCore::HTMLMediaElement::setPlaying): Ditto.
+        * html/HTMLMediaElement.h:
+        * page/ChromeClient.h:
+        * page/MediaProducer.h:
+        * page/Page.cpp:
+        (WebCore::Page::updateIsPlayingMedia): Pass along the source element ID.
+        (WebCore::Page::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
+        * page/Page.h:
+
</ins><span class="cx"> 2015-08-05  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         CharacterFallbackMapKey should be locale-specific
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/dom/Document.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -3506,19 +3506,26 @@
</span><span class="cx">     updateIsPlayingMedia();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Document::updateIsPlayingMedia()
</del><ins>+void Document::updateIsPlayingMedia(uint64_t sourceElementID)
</ins><span class="cx"> {
</span><span class="cx">     MediaProducer::MediaStateFlags state = MediaProducer::IsNotPlaying;
</span><span class="cx">     for (auto audioProducer : m_audioProducers)
</span><span class="cx">         state |= audioProducer-&gt;mediaState();
</span><span class="cx"> 
</span><ins>+#if ENABLE(MEDIA_SESSION)
+    if (HTMLMediaElement* sourceElement = HTMLMediaElement::elementWithID(sourceElementID)) {
+        if (sourceElement-&gt;isPlaying())
+            state |= MediaProducer::IsSourceElementPlaying;
+    }
+#endif
+
</ins><span class="cx">     if (state == m_mediaState)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_mediaState = state;
</span><span class="cx"> 
</span><span class="cx">     if (page())
</span><del>-        page()-&gt;updateIsPlayingMedia();
</del><ins>+        page()-&gt;updateIsPlayingMedia(sourceElementID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::pageMutedStateDidChange()
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/dom/Document.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -226,6 +226,8 @@
</span><span class="cx"> class MediaSession;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+WEBCORE_EXPORT extern const uint64_t HTMLMediaElementInvalidID;
+
</ins><span class="cx"> enum PageshowEventPersistence {
</span><span class="cx">     PageshowEventNotPersisted = 0,
</span><span class="cx">     PageshowEventPersisted = 1
</span><span class="lines">@@ -1260,7 +1262,7 @@
</span><span class="cx">     WEBCORE_EXPORT void addAudioProducer(MediaProducer*);
</span><span class="cx">     WEBCORE_EXPORT void removeAudioProducer(MediaProducer*);
</span><span class="cx">     MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
</span><del>-    WEBCORE_EXPORT void updateIsPlayingMedia();
</del><ins>+    WEBCORE_EXPORT void updateIsPlayingMedia(uint64_t = HTMLMediaElementInvalidID);
</ins><span class="cx">     void pageMutedStateDidChange();
</span><span class="cx">     WeakPtr&lt;Document&gt; createWeakPtr() { return m_weakFactory.createWeakPtr(); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -202,6 +202,8 @@
</span><span class="cx"> static const char* mediaStreamBlobProtocol = &quot;blob&quot;;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+const uint64_t HTMLMediaElementInvalidID = 0;
+
</ins><span class="cx"> using namespace HTMLNames;
</span><span class="cx"> 
</span><span class="cx"> typedef HashMap&lt;Document*, HashSet&lt;HTMLMediaElement*&gt;&gt; DocumentElementSetMap;
</span><span class="lines">@@ -299,6 +301,9 @@
</span><span class="cx"> 
</span><span class="cx"> HTMLMediaElement* HTMLMediaElement::elementWithID(uint64_t id)
</span><span class="cx"> {
</span><ins>+    if (id == HTMLMediaElementInvalidID)
+        return nullptr;
+    
</ins><span class="cx">     return elementIDsToElements().get(id);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -3164,7 +3169,12 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         scheduleEvent(eventNames().volumechangeEvent);
</span><ins>+
+#if ENABLE(MEDIA_SESSION)
+        document().updateIsPlayingMedia(m_elementID);
+#else
</ins><span class="cx">         document().updateIsPlayingMedia();
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">         updateMediaState(UpdateMediaState::Asynchronously);
</span><span class="lines">@@ -4528,7 +4538,11 @@
</span><span class="cx">     if (isPlaying() &amp;&amp; !m_mediaSession-&gt;playbackPermitted(*this))
</span><span class="cx">         pauseInternal();
</span><span class="cx"> 
</span><ins>+#if ENABLE(MEDIA_SESSION)
+    document().updateIsPlayingMedia(m_elementID);
+#else
</ins><span class="cx">     document().updateIsPlayingMedia();
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">     endProcessingMediaPlayerCallback();
</span><span class="cx"> }
</span><span class="lines">@@ -4788,7 +4802,12 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_playing = playing;
</span><ins>+
+#if ENABLE(MEDIA_SESSION)
+    document().updateIsPlayingMedia(m_elementID);
+#else
</ins><span class="cx">     document().updateIsPlayingMedia();
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span><span class="cx">     updateMediaState(UpdateMediaState::Asynchronously);
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -98,6 +98,8 @@
</span><span class="cx"> class MediaStream;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+extern const uint64_t HTMLMediaElementInvalidID;
+
</ins><span class="cx"> class HTMLMediaElement
</span><span class="cx">     : public HTMLElement
</span><span class="cx">     , private MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface , public PlatformMediaSessionClient, private MediaProducer
</span></span></pre></div>
<a id="trunkSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ChromeClient.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ChromeClient.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/page/ChromeClient.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -420,7 +420,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool shouldUseTiledBackingForFrameView(const FrameView*) const { return false; }
</span><span class="cx"> 
</span><del>-    virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags) { }
</del><ins>+    virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }
</span></span></pre></div>
<a id="trunkSourceWebCorepageMediaProducerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/MediaProducer.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/MediaProducer.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/page/MediaProducer.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx">         RequiresPlaybackTargetMonitoring = 1 &lt;&lt; 3,
</span><span class="cx">         ExternalDeviceAutoPlayCandidate = 1 &lt;&lt; 4,
</span><span class="cx">         DidPlayToEnd = 1 &lt;&lt; 5,
</span><ins>+        IsSourceElementPlaying = 1 &lt;&lt; 6,
</ins><span class="cx">     };
</span><span class="cx">     typedef unsigned MediaStateFlags;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/page/Page.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -1183,7 +1183,7 @@
</span><span class="cx">     setSessionID(privateBrowsingEnabled ? SessionID::legacyPrivateSessionID() : SessionID::defaultSessionID());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Page::updateIsPlayingMedia()
</del><ins>+void Page::updateIsPlayingMedia(uint64_t sourceElementID)
</ins><span class="cx"> {
</span><span class="cx">     MediaProducer::MediaStateFlags state = MediaProducer::IsNotPlaying;
</span><span class="cx">     for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext()) {
</span><span class="lines">@@ -1195,7 +1195,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_mediaState = state;
</span><span class="cx"> 
</span><del>-    chrome().client().isPlayingMediaDidChange(state);
</del><ins>+    chrome().client().isPlayingMediaDidChange(state, sourceElementID);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Page::setMuted(bool muted)
</span><span class="lines">@@ -1224,15 +1224,6 @@
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> }
</span><del>-
-bool Page::isMediaElementPaused(uint64_t elementID)
-{
-    if (HTMLMediaElement* element = HTMLMediaElement::elementWithID(elementID))
-        return element-&gt;paused();
-
-    ASSERT_NOT_REACHED();
-    return true;
-}
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if !ASSERT_DISABLED
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebCore/page/Page.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -436,13 +436,12 @@
</span><span class="cx">     bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
</span><span class="cx"> 
</span><span class="cx">     MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
</span><del>-    void updateIsPlayingMedia();
</del><ins>+    void updateIsPlayingMedia(uint64_t);
</ins><span class="cx">     bool isMuted() const { return m_muted; }
</span><span class="cx">     WEBCORE_EXPORT void setMuted(bool);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     WEBCORE_EXPORT void handleMediaEvent(MediaEventType);
</span><del>-    WEBCORE_EXPORT bool isMediaElementPaused(uint64_t);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WIRELESS_PLAYBACK_TARGET)
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/ChangeLog        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2015-08-04  Matt Rajca  &lt;mrajca@apple.com&gt;
+
+        Media Session: push paused state to the media session focus manager instead of polling
+        https://bugs.webkit.org/show_bug.cgi?id=147633
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/WebMediaSessionFocusManager.cpp:
+        (WebKit::WebMediaSessionFocusManager::isFocusedContentMediaElementPaused): Report whether the focused media
+         element is currently playing. The callback is no longer necessary and will be removed in a future patch in
+         favor of returning a value directly.
+        (WebKit::WebMediaSessionFocusManager::mediaElementIsPlayingDidChange): Keep track of whether the focused media
+         element is currently playing.
+        * UIProcess/WebMediaSessionFocusManager.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::isPlayingMediaDidChange): If the focused media element begins/ends playing, keep track
+         of its playing state.
+        (WebKit::WebPageProxy::isMediaElementPaused): Deleted. We now push media playback state changes instead of
+         polling.
+        * UIProcess/WebPageProxy.h: isPlayingMediaDidChange is now passed the ID of the media element that triggered
+         the 'playing' state change. This can be used in conjunction with the IsSourcePlaying media flag to identify
+         whether the source element begin/ended playing.
+        * UIProcess/WebPageProxy.messages.in: Ditto.
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::setPluginIsPlayingAudio): Since a media element did not trigger this, pass in 0 for the
+         source media element.
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::isPlayingMediaDidChange): isPlayingMediaDidChange is now passed the ID of the media
+         element that triggered the 'playing' state change.
+        * WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
+        * WebProcess/WebPage/WebPage.h: Ditto.
+        * WebProcess/WebPage/WebPage.messages.in: Ditto.
+
</ins><span class="cx"> 2015-08-05  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         PDFPlugins are clipped in link previews (and remain so when opened)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebMediaSessionFocusManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -62,12 +62,17 @@
</span><span class="cx">     if (!m_focusedMediaElement)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    RefPtr&lt;UnsignedCallback&gt; callback = UnsignedCallback::create(callbackFunction);
-    WebPageProxy* proxy = m_focusedMediaElement-&gt;first;
-    uint64_t elementID = m_focusedMediaElement-&gt;second;
-    proxy-&gt;isMediaElementPaused(elementID, callback);
</del><ins>+    callbackFunction(!m_focusedMediaElementIsPlaying, CallbackBase::Error::None);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebMediaSessionFocusManager::mediaElementIsPlayingDidChange(WebPageProxy* proxy, uint64_t elementID, bool isPlaying)
+{
+    if (m_focusedMediaElement) {
+        if (proxy == m_focusedMediaElement-&gt;first &amp;&amp; elementID == m_focusedMediaElement-&gt;second)
+            m_focusedMediaElementIsPlaying = isPlaying;
+    }
+}
+
</ins><span class="cx"> void WebMediaSessionFocusManager::setFocusedMediaElement(WebPageProxy&amp; proxy, uint64_t elementID)
</span><span class="cx"> {
</span><span class="cx">     m_focusedMediaElement = std::make_unique&lt;FocusedMediaElement&gt;(&amp;proxy, elementID);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebMediaSessionFocusManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx">     static PassRefPtr&lt;WebMediaSessionFocusManager&gt; create(WebProcessPool*);
</span><span class="cx"> 
</span><span class="cx">     void isFocusedContentMediaElementPaused(std::function&lt;void(bool, CallbackBase::Error)&gt;);
</span><ins>+    void mediaElementIsPlayingDidChange(WebPageProxy*, uint64_t, bool);
</ins><span class="cx"> 
</span><span class="cx">     void setFocusedMediaElement(WebPageProxy&amp;, uint64_t);
</span><span class="cx">     void clearFocusedMediaElement();
</span><span class="lines">@@ -59,6 +60,7 @@
</span><span class="cx">     virtual void derefWebContextSupplement() override;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;FocusedMediaElement&gt; m_focusedMediaElement;
</span><ins>+    bool m_focusedMediaElementIsPlaying { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -3882,19 +3882,6 @@
</span><span class="cx">     
</span><span class="cx">     m_process-&gt;send(Messages::WebPage::HandleMediaEvent(eventType), m_pageID);
</span><span class="cx"> }
</span><del>-
-void WebPageProxy::isMediaElementPaused(uint64_t elementID, RefPtr&lt;UnsignedCallback&gt; callback)
-{
-    if (!isValid()) {
-        callback-&gt;invalidate();
-        return;
-    }
-
-    uint64_t callbackID = callback-&gt;callbackID();
-    m_callbacks.put(callback);
-
-    m_process-&gt;send(Messages::WebPage::IsMediaElementPaused(elementID, callbackID), m_pageID);
-}
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
</span><span class="lines">@@ -5950,8 +5937,14 @@
</span><span class="cx">     m_isShowingNavigationGestureSnapshot = false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state)
</del><ins>+void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
</ins><span class="cx"> {
</span><ins>+#if ENABLE(MEDIA_SESSION)
+    WebMediaSessionFocusManager* focusManager = process().processPool().supplement&lt;WebMediaSessionFocusManager&gt;();
+    ASSERT(focusManager);
+    focusManager-&gt;mediaElementIsPlayingDidChange(this, sourceElementID, state &amp; MediaProducer::IsSourceElementPlaying);
+#endif
+
</ins><span class="cx">     if (state == m_mediaState)
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -943,7 +943,6 @@
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     bool hasMediaSessionWithActiveMediaElements() const { return m_hasMediaSessionWithActiveMediaElements; }
</span><span class="cx">     void handleMediaEvent(WebCore::MediaEventType);
</span><del>-    void isMediaElementPaused(uint64_t, RefPtr&lt;UnsignedCallback&gt;);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // WebPopupMenuProxy::Client
</span><span class="lines">@@ -1025,7 +1024,7 @@
</span><span class="cx">     bool isShowingNavigationGestureSnapshot() const { return m_isShowingNavigationGestureSnapshot; }
</span><span class="cx"> 
</span><span class="cx">     bool isPlayingAudio() const { return !!(m_mediaState &amp; WebCore::MediaProducer::IsPlayingAudio); }
</span><del>-    void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags);
</del><ins>+    void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t);
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     void hasMediaSessionWithActiveMediaElementsDidChange(bool);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -422,7 +422,7 @@
</span><span class="cx">     ContentFilterDidBlockLoadForFrame(WebCore::ContentFilterUnblockHandler unblockHandler, uint64_t frameID)
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    IsPlayingMediaDidChange(unsigned state)
</del><ins>+    IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     HasMediaSessionWithActiveMediaElementsDidChange(bool state)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -1057,9 +1057,9 @@
</span><span class="cx">     return m_page-&gt;drawingArea()-&gt;shouldUseTiledBackingForFrameView(frameView);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebChromeClient::isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags state)
</del><ins>+void WebChromeClient::isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
</ins><span class="cx"> {
</span><del>-    m_page-&gt;send(Messages::WebPageProxy::IsPlayingMediaDidChange(state));
</del><ins>+    m_page-&gt;send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -291,7 +291,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) const override;
</span><span class="cx"> 
</span><del>-    virtual void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags) override;
</del><ins>+    virtual void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) override;
</ins><span class="cx">     virtual void setPageActivityState(WebCore::PageActivityState::Flags) override;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -4076,12 +4076,6 @@
</span><span class="cx"> {
</span><span class="cx">     m_page-&gt;handleMediaEvent(static_cast&lt;MediaEventType&gt;(eventType));
</span><span class="cx"> }
</span><del>-
-void WebPage::isMediaElementPaused(uint64_t elementID, uint64_t callbackID)
-{
-    bool paused = m_page-&gt;isMediaElementPaused(elementID);
-    send(Messages::WebPageProxy::UnsignedCallback(paused, callbackID));
-}
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> void WebPage::setMayStartMediaWhenInWindow(bool mayStartMedia)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -750,7 +750,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     void handleMediaEvent(uint32_t /* WebCore::MediaEventType */);
</span><del>-    void isMediaElementPaused(uint64_t, uint64_t);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void updateMainFrameScrollOffsetPinning();
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (188029 => 188030)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2015-08-06 06:24:09 UTC (rev 188029)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2015-08-06 07:13:55 UTC (rev 188030)
</span><span class="lines">@@ -316,7 +316,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     HandleMediaEvent(uint32_t eventType)
</span><del>-    IsMediaElementPaused(uint64_t elementID, uint64_t callbackID)
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
</span></span></pre>
</div>
</div>

</body>
</html>