Set WebVideoFullscreenInterfaceMac up as a client of WebPlaybackSessionInterfaceMac...
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2016 23:24:36 +0000 (23:24 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2016 23:24:36 +0000 (23:24 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200157 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm
Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.h
Source/WebCore/platform/mac/WebPlaybackSessionInterfaceMac.mm
Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.h
Source/WebCore/platform/mac/WebVideoFullscreenInterfaceMac.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Cocoa/WebVideoFullscreenManagerProxy.mm
Source/WebKit2/WebProcess/cocoa/WebPlaybackSessionManager.mm
Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm

index 07db8c7..8a58cff 100644 (file)
@@ -1,3 +1,50 @@
+2016-04-26  Ada Chan  <adachan@apple.com>
+
+        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.
+
 2016-04-27  Brady Eidson  <beidson@apple.com>
 
         Modernize platform/CrossThreadCopier.h style.
index 34b6b5e..29bc6de 100644 (file)
@@ -67,7 +67,6 @@ void WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface(WebVide
         return;
 
     m_videoFullscreenInterface = interface;
-    m_playbackSessionModel->setWebPlaybackSessionInterface(interface);
 
     if (m_videoFullscreenInterface && m_videoElement)
         m_videoFullscreenInterface->setVideoDimensions(true, m_videoElement->videoWidth(), m_videoElement->videoHeight());
@@ -75,7 +74,6 @@ void WebVideoFullscreenModelVideoElement::setWebVideoFullscreenInterface(WebVide
 
 void WebVideoFullscreenModelVideoElement::setVideoElement(HTMLVideoElement* videoElement)
 {
-    m_playbackSessionModel->setMediaElement(videoElement);
     if (m_videoElement == videoElement)
         return;
 
index 18d26bb..a13b3d3 100644 (file)
@@ -40,6 +40,13 @@ namespace WebCore {
 class IntRect;
 class WebPlaybackSessionModel;
 
+class WebPlaybackSessionInterfaceMacClient {
+public:
+    virtual ~WebPlaybackSessionInterfaceMacClient() { }
+
+    virtual void rateChanged(bool isPlaying, float playbackRate) = 0;
+};
+
 class WEBCORE_EXPORT WebPlaybackSessionInterfaceMac final
     : public WebPlaybackSessionInterface
     , public RefCounted<WebPlaybackSessionInterfaceMac> {
@@ -51,6 +58,8 @@ public:
     virtual ~WebPlaybackSessionInterfaceMac();
     WebPlaybackSessionModel* webPlaybackSessionModel() const { return m_playbackSessionModel; }
     WEBCORE_EXPORT void setWebPlaybackSessionModel(WebPlaybackSessionModel*);
+    WebPlaybackSessionInterfaceMacClient* client() const { return m_client; }
+    void setClient(WebPlaybackSessionInterfaceMacClient*);
 
     WEBCORE_EXPORT void resetMediaState() final { }
     WEBCORE_EXPORT void setDuration(double) final;
@@ -70,6 +79,7 @@ public:
 private:
     WebPlaybackSessionModel* m_playbackSessionModel { nullptr };
     RetainPtr<WebPlaybackControlsManager> m_playbackControlsManager;
+    WebPlaybackSessionInterfaceMacClient* m_client { nullptr };
 };
 
 }
index e01da91..d70f7aa 100644 (file)
@@ -132,6 +132,16 @@ void WebPlaybackSessionInterfaceMac::setWebPlaybackSessionModel(WebPlaybackSessi
     m_playbackSessionModel = model;
 }
 
+void WebPlaybackSessionInterfaceMac::setClient(WebPlaybackSessionInterfaceMacClient* client)
+{
+    m_client = client;
+
+    if (m_client) {
+        float rate = [playBackControlsManager() rate];
+        m_client->rateChanged(!!rate, rate);
+    }
+}
+
 void WebPlaybackSessionInterfaceMac::setDuration(double duration)
 {
     WebPlaybackControlsManager* controlsManager = playBackControlsManager();
@@ -157,8 +167,10 @@ void WebPlaybackSessionInterfaceMac::setCurrentTime(double currentTime, double a
 void WebPlaybackSessionInterfaceMac::setRate(bool isPlaying, float playbackRate)
 {
     WebPlaybackControlsManager* controlsManager = playBackControlsManager();
-
     [controlsManager setRate:isPlaying ? playbackRate : 0.];
+
+    if (m_client)
+        m_client->rateChanged(isPlaying, playbackRate);
 }
 
 void WebPlaybackSessionInterfaceMac::setSeekableRanges(const TimeRanges& timeRanges)
index fb8cc8f..29cd1af 100644 (file)
@@ -29,6 +29,7 @@
 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
 
 #include "HTMLMediaElementEnums.h"
+#include "WebPlaybackSessionInterfaceMac.h"
 #include "WebVideoFullscreenInterface.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RetainPtr.h>
@@ -48,6 +49,7 @@ class WebVideoFullscreenModel;
 
 class WEBCORE_EXPORT WebVideoFullscreenInterfaceMac
     : public WebVideoFullscreenInterface
+    , private WebPlaybackSessionInterfaceMacClient
     , public RefCounted<WebVideoFullscreenInterfaceMac> {
 
 public:
@@ -93,6 +95,8 @@ public:
     WEBCORE_EXPORT bool mayAutomaticallyShowVideoPictureInPicture() const { return false; }
     void applicationDidBecomeActive() { }
 
+    void rateChanged(bool isPlaying, float playbackRate) override;
+
 #if USE(APPLE_INTERNAL_SDK)
     WEBCORE_EXPORT WebVideoFullscreenInterfaceMacObjC *videoFullscreenInterfaceObjC();
 #endif
index f61feff..9b24ffd 100644 (file)
@@ -51,16 +51,18 @@ namespace WebCore {
 WebVideoFullscreenInterfaceMac::WebVideoFullscreenInterfaceMac(WebPlaybackSessionInterfaceMac& playbackSessionInterface)
     : m_playbackSessionInterface(playbackSessionInterface)
 {
+    m_playbackSessionInterface->setClient(this);
 }
 
 WebVideoFullscreenInterfaceMac::~WebVideoFullscreenInterfaceMac()
 {
+    if (m_playbackSessionInterface->client() == this)
+        m_playbackSessionInterface->setClient(nullptr);
 }
 
 void WebVideoFullscreenInterfaceMac::setWebVideoFullscreenModel(WebVideoFullscreenModel* model)
 {
     m_videoFullscreenModel = model;
-    m_playbackSessionInterface->setWebPlaybackSessionModel(model);
 }
 
 void WebVideoFullscreenInterfaceMac::setWebVideoFullscreenChangeObserver(WebVideoFullscreenChangeObserver* observer)
@@ -103,9 +105,12 @@ void WebVideoFullscreenInterfaceMac::setCurrentTime(double currentTime, double a
 void WebVideoFullscreenInterfaceMac::setRate(bool isPlaying, float playbackRate)
 {
     m_playbackSessionInterface->setRate(isPlaying, playbackRate);
+}
 
+void WebVideoFullscreenInterfaceMac::rateChanged(bool isPlaying, float playbackRate)
+{
 #if USE(APPLE_INTERNAL_SDK)
-    [videoFullscreenInterfaceObjC() setRate:isPlaying ? playbackRate : 0.];
+    [videoFullscreenInterfaceObjC() updateIsPlaying:isPlaying newPlaybackRate:playbackRate];
 #endif
 }
 
index 42811b7..a7b2a6f 100644 (file)
@@ -1,3 +1,38 @@
+2016-04-26  Ada Chan  <adachan@apple.com>
+
+        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.
+
 2016-04-27  Alex Christensen  <achristensen@webkit.org>
 
         Remove download message receiver when NetworkProcess crashes
index 00c705f..608349a 100644 (file)
@@ -318,6 +318,7 @@ WebVideoFullscreenManagerProxy::ModelInterfaceTuple WebVideoFullscreenManagerPro
     Ref<WebVideoFullscreenModelContext> model = WebVideoFullscreenModelContext::create(*this, playbackSessionModel, contextId);
     auto& playbackSessionInterface = m_playbackSessionManagerProxy->ensureInterface(contextId);
     Ref<PlatformWebVideoFullscreenInterface> interface = PlatformWebVideoFullscreenInterface::create(playbackSessionInterface);
+    m_playbackSessionManagerProxy->addClientForContext(contextId);
 
     interface->setWebVideoFullscreenModel(&model.get());
     interface->setWebVideoFullscreenChangeObserver(&model.get());
@@ -359,6 +360,7 @@ void WebVideoFullscreenManagerProxy::removeClientForContext(uint64_t contextId)
     clientCount--;
 
     if (clientCount <= 0) {
+        m_playbackSessionManagerProxy->removeClientForContext(contextId);
         m_clientCounts.remove(contextId);
         m_contextMap.remove(contextId);
         return;
index 8d8f993..6bea566 100644 (file)
@@ -261,7 +261,7 @@ void WebPlaybackSessionManager::clearPlaybackControlsManager(WebCore::HTMLMediaE
     if (foundIterator == m_mediaElements.end())
         return;
 
-    if (m_controlsManagerContextId != foundIterator->value)
+    if (!m_controlsManagerContextId || m_controlsManagerContextId != foundIterator->value)
         return;
 
     removeClientForContext(m_controlsManagerContextId);
@@ -273,7 +273,9 @@ void WebPlaybackSessionManager::clearPlaybackControlsManager(WebCore::HTMLMediaE
 uint64_t WebPlaybackSessionManager::contextIdForMediaElement(WebCore::HTMLMediaElement& mediaElement)
 {
     auto addResult = m_mediaElements.ensure(&mediaElement, [&] { return nextContextId(); });
-    return addResult.iterator->value;
+    uint64_t contextId = addResult.iterator->value;
+    ensureModel(contextId).setMediaElement(&mediaElement);
+    return contextId;
 }
 
 #pragma mark Interface to WebPlaybackSessionInterfaceContext:
index 252226f..35ba752 100644 (file)
@@ -179,6 +179,7 @@ WebVideoFullscreenManager::ModelInterfaceTuple WebVideoFullscreenManager::create
     RefPtr<WebVideoFullscreenModelVideoElement> model = WebVideoFullscreenModelVideoElement::create(playbackSessionModel);
     auto& playbackSessionInterface = m_playbackSessionManager->ensureInterface(contextId);
     RefPtr<WebVideoFullscreenInterfaceContext> interface = WebVideoFullscreenInterfaceContext::create(*this, playbackSessionInterface, contextId);
+    m_playbackSessionManager->addClientForContext(contextId);
 
     interface->setLayerHostingContext(LayerHostingContext::createForExternalHostingProcess());
     model->setWebVideoFullscreenInterface(interface.get());
@@ -210,6 +211,8 @@ void WebVideoFullscreenManager::removeContext(uint64_t contextId)
     RefPtr<WebVideoFullscreenInterfaceContext> interface;
     std::tie(model, interface) = ensureModelAndInterface(contextId);
 
+    m_playbackSessionManager->removeClientForContext(contextId);
+
     RefPtr<HTMLVideoElement> videoElement = model->videoElement();
     model->setVideoElement(nullptr);
     model->setWebVideoFullscreenInterface(nullptr);