<!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>[200157] 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/200157">200157</a></dd>
<dt>Author</dt> <dd>adachan@apple.com</dd>
<dt>Date</dt> <dd>2016-04-27 16:24:36 -0700 (Wed, 27 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Set WebVideoFullscreenInterfaceMac up as a client of WebPlaybackSessionInterfaceMac to listen for playback state changes
https://bugs.webkit.org/show_bug.cgi?id=157008

Reviewed by Jer Noble.

Source/WebCore:

For WebVideoFullscreenInterfaceMac to be notified when the playback rate changes in
WebPlaybackSessionInterfaceMac, add a new WebPlaybackSessionInterfaceMacClient base
class that WebVideoFullscreenInterfaceMac implements, similar to the WebPlaybackSessionInterfaceAVKitClient
on iOS. WebVideoFullscreenInterfaceMac sets itself as a client of WebPlaybackSessionInterfaceMac
so WebPlaybackSessionInterfaceMac can notify WebVideoFullscreenInterfaceMac whenever the
playback rate changes.

* platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
(WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface):
We should not change the WebPlaybackSessionModelMediaElement's interface here since WebPlaybackSessionManager
has already set that up when creating the context for this media element.
(WebVideoFullscreenModelVideoElement::setVideoElement):
We should not change the WebPlaybackSessionModelMediaElement's media element here because
this will be called with NULL when the fullscreen context is cleaned up, but the
WebPlaybackSessionModelMediaElement might still need to stay around. We'll make sure the
WebPlaybackSessionModelMediaElement's media element is set when setting up the fullscreen
context in WebVideoFullscreenManager::enterVideoFullscreenForVideoElement().

* platform/mac/WebPlaybackSessionInterfaceMac.h:
(WebCore::WebPlaybackSessionInterfaceMacClient::~WebPlaybackSessionInterfaceMacClient):

* platform/mac/WebPlaybackSessionInterfaceMac.mm:
(WebCore::WebPlaybackSessionInterfaceMac::setClient):
Set the client. Notify the client about the current playback state.
(WebCore::WebPlaybackSessionInterfaceMac::setRate):
If a client is set, let that client know about the change in playback rate.

* platform/mac/WebVideoFullscreenInterfaceMac.h:
* platform/mac/WebVideoFullscreenInterfaceMac.mm:
(WebCore::WebVideoFullscreenInterfaceMac::WebVideoFullscreenInterfaceMac):
Set itself as a client of WebPlaybackSessionInterfaceMac.
(WebCore::WebVideoFullscreenInterfaceMac::~WebVideoFullscreenInterfaceMac):
Make sure WebPlaybackSessionInterfaceMac won't hold onto a stale pointer to itself.
(WebCore::WebVideoFullscreenInterfaceMac::setRate):
We don't have to update the WebVideoFullscreenInterfaceMac's rate here anymore. The change
in playback rate in WebPlaybackSessionInterfaceMac should trigger
WebVideoFullscreenInterfaceMac::rateChanged() to be called.
(WebCore::WebVideoFullscreenInterfaceMac::rateChanged):
Pass in both the isPlaying state and the playback rate to WebVideoFullscreenInterfaceMacObjC.

Source/WebKit2:

Since WebVideoFullscreenInterfaceMac holds onto WebPlaybackSessionInterfaceMac, we can't let
WebPlaybackSessionManagerProxy unregister the context for that media element while
WebVideoFullscreenInterfaceMac is still using it. WebVideoFullscreenInterfaceMac should add
to the client count for that WebPlaybackSession context.

* UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm:
(WebKit::WebVideoFullscreenManagerProxy::createModelAndInterface):
When the context for the media element is created with the WebVideoFullscreenManagerProxy, it should
add one to the client count for the media element context in WebPlaybackSessionManagerProxy.
(WebKit::WebVideoFullscreenManagerProxy::removeClientForContext):
When WebVideoFullscreenManagerProxy unregisters the context for this media element, it should
subtract one from the client count for the media element context in WebPlaybackSessionManagerProxy.

* WebProcess/cocoa/WebPlaybackSessionManager.mm:
(WebKit::WebPlaybackSessionManager::clearPlaybackControlsManager):
Bail early if m_controlsManagerContextId is zero. Otherwise, we'd end up sending a
ClearPlaybackControlsManager message to the UI process inadvertently.
(WebKit::WebPlaybackSessionManager::contextIdForMediaElement):
Make sure the model element for the context ID is set to the media element.

* WebProcess/cocoa/WebVideoFullscreenManager.mm:
(WebKit::WebVideoFullscreenManager::createModelAndInterface):
When the context for the media element is created with the WebVideoFullscreenManager, it should
add one to the client count for the media element context in WebPlaybackSessionManager.
(WebKit::WebVideoFullscreenManager::removeContext):
When WebVideoFullscreenManager unregisters the context for this media element, it should
subtract one from the client count for the media element context in WebPlaybackSessionManager.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementmm">trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebPlaybackSessionInterfaceMach">trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebPlaybackSessionInterfaceMacmm">trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebVideoFullscreenInterfaceMach">trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacWebVideoFullscreenInterfaceMacmm">trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymm">trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebPlaybackSessionManagermm">trunk/Source/WebKit2/WebProcess/cocoa/WebPlaybackSessionManager.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagermm">trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/ChangeLog        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2016-04-26  Ada Chan  &lt;adachan@apple.com&gt;
+
+        Set WebVideoFullscreenInterfaceMac up as a client of WebPlaybackSessionInterfaceMac to listen for playback state changes
+        https://bugs.webkit.org/show_bug.cgi?id=157008
+
+        Reviewed by Jer Noble.
+
+        For WebVideoFullscreenInterfaceMac to be notified when the playback rate changes in
+        WebPlaybackSessionInterfaceMac, add a new WebPlaybackSessionInterfaceMacClient base
+        class that WebVideoFullscreenInterfaceMac implements, similar to the WebPlaybackSessionInterfaceAVKitClient
+        on iOS. WebVideoFullscreenInterfaceMac sets itself as a client of WebPlaybackSessionInterfaceMac
+        so WebPlaybackSessionInterfaceMac can notify WebVideoFullscreenInterfaceMac whenever the
+        playback rate changes.
+
+        * platform/cocoa/WebVideoFullscreenModelVideoElement.mm:
+        (WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface):
+        We should not change the WebPlaybackSessionModelMediaElement's interface here since WebPlaybackSessionManager
+        has already set that up when creating the context for this media element.
+        (WebVideoFullscreenModelVideoElement::setVideoElement):
+        We should not change the WebPlaybackSessionModelMediaElement's media element here because
+        this will be called with NULL when the fullscreen context is cleaned up, but the
+        WebPlaybackSessionModelMediaElement might still need to stay around. We'll make sure the
+        WebPlaybackSessionModelMediaElement's media element is set when setting up the fullscreen
+        context in WebVideoFullscreenManager::enterVideoFullscreenForVideoElement().
+
+        * platform/mac/WebPlaybackSessionInterfaceMac.h:
+        (WebCore::WebPlaybackSessionInterfaceMacClient::~WebPlaybackSessionInterfaceMacClient):
+
+        * platform/mac/WebPlaybackSessionInterfaceMac.mm:
+        (WebCore::WebPlaybackSessionInterfaceMac::setClient):
+        Set the client. Notify the client about the current playback state.
+        (WebCore::WebPlaybackSessionInterfaceMac::setRate):
+        If a client is set, let that client know about the change in playback rate.
+
+        * platform/mac/WebVideoFullscreenInterfaceMac.h:
+        * platform/mac/WebVideoFullscreenInterfaceMac.mm:
+        (WebCore::WebVideoFullscreenInterfaceMac::WebVideoFullscreenInterfaceMac):
+        Set itself as a client of WebPlaybackSessionInterfaceMac.
+        (WebCore::WebVideoFullscreenInterfaceMac::~WebVideoFullscreenInterfaceMac):
+        Make sure WebPlaybackSessionInterfaceMac won't hold onto a stale pointer to itself.
+        (WebCore::WebVideoFullscreenInterfaceMac::setRate):
+        We don't have to update the WebVideoFullscreenInterfaceMac's rate here anymore. The change
+        in playback rate in WebPlaybackSessionInterfaceMac should trigger
+        WebVideoFullscreenInterfaceMac::rateChanged() to be called.
+        (WebCore::WebVideoFullscreenInterfaceMac::rateChanged):
+        Pass in both the isPlaying state and the playback rate to WebVideoFullscreenInterfaceMacObjC.
+
</ins><span class="cx"> 2016-04-27  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Modernize platform/CrossThreadCopier.h style.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaWebVideoFullscreenModelVideoElementmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -67,7 +67,6 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_videoFullscreenInterface = interface;
</span><del>-    m_playbackSessionModel-&gt;setWebPlaybackSessionInterface(interface);
</del><span class="cx"> 
</span><span class="cx">     if (m_videoFullscreenInterface &amp;&amp; m_videoElement)
</span><span class="cx">         m_videoFullscreenInterface-&gt;setVideoDimensions(true, m_videoElement-&gt;videoWidth(), m_videoElement-&gt;videoHeight());
</span><span class="lines">@@ -75,7 +74,6 @@
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenModelVideoElement::setVideoElement(HTMLVideoElement* videoElement)
</span><span class="cx"> {
</span><del>-    m_playbackSessionModel-&gt;setMediaElement(videoElement);
</del><span class="cx">     if (m_videoElement == videoElement)
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebPlaybackSessionInterfaceMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.h (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.h        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.h        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -40,6 +40,13 @@
</span><span class="cx"> class IntRect;
</span><span class="cx"> class WebPlaybackSessionModel;
</span><span class="cx"> 
</span><ins>+class WebPlaybackSessionInterfaceMacClient {
+public:
+    virtual ~WebPlaybackSessionInterfaceMacClient() { }
+
+    virtual void rateChanged(bool isPlaying, float playbackRate) = 0;
+};
+
</ins><span class="cx"> class WEBCORE_EXPORT WebPlaybackSessionInterfaceMac final
</span><span class="cx">     : public WebPlaybackSessionInterface
</span><span class="cx">     , public RefCounted&lt;WebPlaybackSessionInterfaceMac&gt; {
</span><span class="lines">@@ -51,6 +58,8 @@
</span><span class="cx">     virtual ~WebPlaybackSessionInterfaceMac();
</span><span class="cx">     WebPlaybackSessionModel* webPlaybackSessionModel() const { return m_playbackSessionModel; }
</span><span class="cx">     WEBCORE_EXPORT void setWebPlaybackSessionModel(WebPlaybackSessionModel*);
</span><ins>+    WebPlaybackSessionInterfaceMacClient* client() const { return m_client; }
+    void setClient(WebPlaybackSessionInterfaceMacClient*);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void resetMediaState() final { }
</span><span class="cx">     WEBCORE_EXPORT void setDuration(double) final;
</span><span class="lines">@@ -70,6 +79,7 @@
</span><span class="cx"> private:
</span><span class="cx">     WebPlaybackSessionModel* m_playbackSessionModel { nullptr };
</span><span class="cx">     RetainPtr&lt;WebPlaybackControlsManager&gt; m_playbackControlsManager;
</span><ins>+    WebPlaybackSessionInterfaceMacClient* m_client { nullptr };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebPlaybackSessionInterfaceMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -132,6 +132,16 @@
</span><span class="cx">     m_playbackSessionModel = model;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPlaybackSessionInterfaceMac::setClient(WebPlaybackSessionInterfaceMacClient* client)
+{
+    m_client = client;
+
+    if (m_client) {
+        float rate = [playBackControlsManager() rate];
+        m_client-&gt;rateChanged(!!rate, rate);
+    }
+}
+
</ins><span class="cx"> void WebPlaybackSessionInterfaceMac::setDuration(double duration)
</span><span class="cx"> {
</span><span class="cx">     WebPlaybackControlsManager* controlsManager = playBackControlsManager();
</span><span class="lines">@@ -157,8 +167,10 @@
</span><span class="cx"> void WebPlaybackSessionInterfaceMac::setRate(bool isPlaying, float playbackRate)
</span><span class="cx"> {
</span><span class="cx">     WebPlaybackControlsManager* controlsManager = playBackControlsManager();
</span><ins>+    [controlsManager setRate:isPlaying ? playbackRate : 0.];
</ins><span class="cx"> 
</span><del>-    [controlsManager setRate:isPlaying ? playbackRate : 0.];
</del><ins>+    if (m_client)
+        m_client-&gt;rateChanged(isPlaying, playbackRate);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPlaybackSessionInterfaceMac::setSeekableRanges(const TimeRanges&amp; timeRanges)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebVideoFullscreenInterfaceMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.h (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.h        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.h        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; ENABLE(VIDEO_PRESENTATION_MODE)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;HTMLMediaElementEnums.h&quot;
</span><ins>+#include &quot;WebPlaybackSessionInterfaceMac.h&quot;
</ins><span class="cx"> #include &quot;WebVideoFullscreenInterface.h&quot;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="lines">@@ -48,6 +49,7 @@
</span><span class="cx"> 
</span><span class="cx"> class WEBCORE_EXPORT WebVideoFullscreenInterfaceMac
</span><span class="cx">     : public WebVideoFullscreenInterface
</span><ins>+    , private WebPlaybackSessionInterfaceMacClient
</ins><span class="cx">     , public RefCounted&lt;WebVideoFullscreenInterfaceMac&gt; {
</span><span class="cx"> 
</span><span class="cx"> public:
</span><span class="lines">@@ -93,6 +95,8 @@
</span><span class="cx">     WEBCORE_EXPORT bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
</span><span class="cx">     void applicationDidBecomeActive() { }
</span><span class="cx"> 
</span><ins>+    void rateChanged(bool isPlaying, float playbackRate) override;
+
</ins><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx">     WEBCORE_EXPORT WebVideoFullscreenInterfaceMacObjC *videoFullscreenInterfaceObjC();
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacWebVideoFullscreenInterfaceMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -51,16 +51,18 @@
</span><span class="cx"> WebVideoFullscreenInterfaceMac::WebVideoFullscreenInterfaceMac(WebPlaybackSessionInterfaceMac&amp; playbackSessionInterface)
</span><span class="cx">     : m_playbackSessionInterface(playbackSessionInterface)
</span><span class="cx"> {
</span><ins>+    m_playbackSessionInterface-&gt;setClient(this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebVideoFullscreenInterfaceMac::~WebVideoFullscreenInterfaceMac()
</span><span class="cx"> {
</span><ins>+    if (m_playbackSessionInterface-&gt;client() == this)
+        m_playbackSessionInterface-&gt;setClient(nullptr);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceMac::setWebVideoFullscreenModel(WebVideoFullscreenModel* model)
</span><span class="cx"> {
</span><span class="cx">     m_videoFullscreenModel = model;
</span><del>-    m_playbackSessionInterface-&gt;setWebPlaybackSessionModel(model);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebVideoFullscreenInterfaceMac::setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver* observer)
</span><span class="lines">@@ -103,9 +105,12 @@
</span><span class="cx"> void WebVideoFullscreenInterfaceMac::setRate(bool isPlaying, float playbackRate)
</span><span class="cx"> {
</span><span class="cx">     m_playbackSessionInterface-&gt;setRate(isPlaying, playbackRate);
</span><ins>+}
</ins><span class="cx"> 
</span><ins>+void WebVideoFullscreenInterfaceMac::rateChanged(bool isPlaying, float playbackRate)
+{
</ins><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><del>-    [videoFullscreenInterfaceObjC() setRate:isPlaying ? playbackRate : 0.];
</del><ins>+    [videoFullscreenInterfaceObjC() updateIsPlaying:isPlaying newPlaybackRate:playbackRate];
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebKit2/ChangeLog        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2016-04-26  Ada Chan  &lt;adachan@apple.com&gt;
+
+        Set WebVideoFullscreenInterfaceMac up as a client of WebPlaybackSessionInterfaceMac to listen for playback state changes
+        https://bugs.webkit.org/show_bug.cgi?id=157008
+
+        Reviewed by Jer Noble.
+
+        Since WebVideoFullscreenInterfaceMac holds onto WebPlaybackSessionInterfaceMac, we can't let
+        WebPlaybackSessionManagerProxy unregister the context for that media element while
+        WebVideoFullscreenInterfaceMac is still using it. WebVideoFullscreenInterfaceMac should add
+        to the client count for that WebPlaybackSession context.
+
+        * UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm:
+        (WebKit::WebVideoFullscreenManagerProxy::createModelAndInterface):
+        When the context for the media element is created with the WebVideoFullscreenManagerProxy, it should
+        add one to the client count for the media element context in WebPlaybackSessionManagerProxy.
+        (WebKit::WebVideoFullscreenManagerProxy::removeClientForContext):
+        When WebVideoFullscreenManagerProxy unregisters the context for this media element, it should
+        subtract one from the client count for the media element context in WebPlaybackSessionManagerProxy.
+
+        * WebProcess/cocoa/WebPlaybackSessionManager.mm:
+        (WebKit::WebPlaybackSessionManager::clearPlaybackControlsManager):
+        Bail early if m_controlsManagerContextId is zero. Otherwise, we'd end up sending a
+        ClearPlaybackControlsManager message to the UI process inadvertently.
+        (WebKit::WebPlaybackSessionManager::contextIdForMediaElement):
+        Make sure the model element for the context ID is set to the media element.
+
+        * WebProcess/cocoa/WebVideoFullscreenManager.mm:
+        (WebKit::WebVideoFullscreenManager::createModelAndInterface):
+        When the context for the media element is created with the WebVideoFullscreenManager, it should
+        add one to the client count for the media element context in WebPlaybackSessionManager.
+        (WebKit::WebVideoFullscreenManager::removeContext):
+        When WebVideoFullscreenManager unregisters the context for this media element, it should
+        subtract one from the client count for the media element context in WebPlaybackSessionManager.
+
</ins><span class="cx"> 2016-04-27  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove download message receiver when NetworkProcess crashes
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebVideoFullscreenManagerProxymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -318,6 +318,7 @@
</span><span class="cx">     Ref&lt;WebVideoFullscreenModelContext&gt; model = WebVideoFullscreenModelContext::create(*this, playbackSessionModel, contextId);
</span><span class="cx">     auto&amp; playbackSessionInterface = m_playbackSessionManagerProxy-&gt;ensureInterface(contextId);
</span><span class="cx">     Ref&lt;PlatformWebVideoFullscreenInterface&gt; interface = PlatformWebVideoFullscreenInterface::create(playbackSessionInterface);
</span><ins>+    m_playbackSessionManagerProxy-&gt;addClientForContext(contextId);
</ins><span class="cx"> 
</span><span class="cx">     interface-&gt;setWebVideoFullscreenModel(&amp;model.get());
</span><span class="cx">     interface-&gt;setWebVideoFullscreenChangeObserver(&amp;model.get());
</span><span class="lines">@@ -359,6 +360,7 @@
</span><span class="cx">     clientCount--;
</span><span class="cx"> 
</span><span class="cx">     if (clientCount &lt;= 0) {
</span><ins>+        m_playbackSessionManagerProxy-&gt;removeClientForContext(contextId);
</ins><span class="cx">         m_clientCounts.remove(contextId);
</span><span class="cx">         m_contextMap.remove(contextId);
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebPlaybackSessionManagermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebPlaybackSessionManager.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/cocoa/WebPlaybackSessionManager.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebPlaybackSessionManager.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -261,7 +261,7 @@
</span><span class="cx">     if (foundIterator == m_mediaElements.end())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_controlsManagerContextId != foundIterator-&gt;value)
</del><ins>+    if (!m_controlsManagerContextId || m_controlsManagerContextId != foundIterator-&gt;value)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     removeClientForContext(m_controlsManagerContextId);
</span><span class="lines">@@ -273,7 +273,9 @@
</span><span class="cx"> uint64_t WebPlaybackSessionManager::contextIdForMediaElement(WebCore::HTMLMediaElement&amp; mediaElement)
</span><span class="cx"> {
</span><span class="cx">     auto addResult = m_mediaElements.ensure(&amp;mediaElement, [&amp;] { return nextContextId(); });
</span><del>-    return addResult.iterator-&gt;value;
</del><ins>+    uint64_t contextId = addResult.iterator-&gt;value;
+    ensureModel(contextId).setMediaElement(&amp;mediaElement);
+    return contextId;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #pragma mark Interface to WebPlaybackSessionInterfaceContext:
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebVideoFullscreenManagermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm (200156 => 200157)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm        2016-04-27 22:53:52 UTC (rev 200156)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm        2016-04-27 23:24:36 UTC (rev 200157)
</span><span class="lines">@@ -179,6 +179,7 @@
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenModelVideoElement&gt; model = WebVideoFullscreenModelVideoElement::create(playbackSessionModel);
</span><span class="cx">     auto&amp; playbackSessionInterface = m_playbackSessionManager-&gt;ensureInterface(contextId);
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceContext&gt; interface = WebVideoFullscreenInterfaceContext::create(*this, playbackSessionInterface, contextId);
</span><ins>+    m_playbackSessionManager-&gt;addClientForContext(contextId);
</ins><span class="cx"> 
</span><span class="cx">     interface-&gt;setLayerHostingContext(LayerHostingContext::createForExternalHostingProcess());
</span><span class="cx">     model-&gt;setWebVideoFullscreenInterface(interface.get());
</span><span class="lines">@@ -210,6 +211,8 @@
</span><span class="cx">     RefPtr&lt;WebVideoFullscreenInterfaceContext&gt; interface;
</span><span class="cx">     std::tie(model, interface) = ensureModelAndInterface(contextId);
</span><span class="cx"> 
</span><ins>+    m_playbackSessionManager-&gt;removeClientForContext(contextId);
+
</ins><span class="cx">     RefPtr&lt;HTMLVideoElement&gt; videoElement = model-&gt;videoElement();
</span><span class="cx">     model-&gt;setVideoElement(nullptr);
</span><span class="cx">     model-&gt;setWebVideoFullscreenInterface(nullptr);
</span></span></pre>
</div>
</div>

</body>
</html>