MediaSession: propagate MediaSessionMetadata to WebPageProxy
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jun 2015 22:36:07 +0000 (22:36 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jun 2015 22:36:07 +0000 (22:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146282

Reviewed by Darin Adler and Tim Horton.

WebCore:
* Modules/mediasession/MediaSession.cpp:
(WebCore::MediaSession::setMetadata):

WebKit2:
* Shared/WebCoreArgumentCoders.cpp: Added ArgumentEncoder support for MediaSessionMetadata so we can send it
  through the web page proxy.
(IPC::ArgumentCoder<MediaSessionMetadata>::encode):
(IPC::ArgumentCoder<MediaSessionMetadata>::decode):
* Shared/WebCoreArgumentCoders.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::mediaSessionMetadataDidChange):
* UIProcess/WebPageProxy.h: Receive mediaSessionMetadataDidChange in the web page proxy.
* UIProcess/WebPageProxy.messages.in: Added a new MediaSessionMetadataDidChange message.
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::mediaSessionMetadataDidChange): Push a mediaSessionMetadataDidChange message through the web page proxy.
* WebProcess/WebCoreSupport/WebChromeClient.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasession/MediaSession.cpp
Source/WebCore/page/ChromeClient.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

index 99881f7..343d67c 100644 (file)
@@ -1,3 +1,13 @@
+2015-06-24  Matt Rajca  <mrajca@apple.com>
+
+        MediaSession: propagate MediaSessionMetadata to WebPageProxy
+        https://bugs.webkit.org/show_bug.cgi?id=146282
+
+        Reviewed by Darin Adler and Tim Horton.
+
+        * Modules/mediasession/MediaSession.cpp:
+        (WebCore::MediaSession::setMetadata):
+
 2015-06-24  Chris Dumez  <cdumez@apple.com>
 
         Null dereference in DocumentLoader::areAllLoadersPageCacheAcceptable()
index 1315c71..52d28af 100644 (file)
@@ -28,6 +28,8 @@
 
 #if ENABLE(MEDIA_SESSION)
 
+#include "Chrome.h"
+#include "ChromeClient.h"
 #include "Dictionary.h"
 #include "Event.h"
 #include "HTMLMediaElement.h"
@@ -99,6 +101,9 @@ void MediaSession::setMetadata(const Dictionary& metadata)
         artworkURL = m_document.completeURL(artworkPath);
 
     m_metadata = MediaSessionMetadata(title, artist, album, artworkURL);
+
+    if (Page *page = m_document.page())
+        page->chrome().client().mediaSessionMetadataDidChange(m_metadata);
 }
 
 void MediaSession::releaseSession()
index b34e953..48b35fb 100644 (file)
 #include <wtf/Forward.h>
 #include <wtf/Vector.h>
 
+#if ENABLE(MEDIA_SESSION)
+namespace WebCore {
+struct MediaSessionMetadata;
+}
+#endif
+
 #if PLATFORM(IOS)
 #include "PlatformLayer.h"
 #define NSResponder WAKResponder
@@ -412,6 +418,10 @@ public:
 
     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags) { }
 
+#if ENABLE(MEDIA_SESSION)
+    virtual void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&) { }
+#endif
+
     virtual void setPageActivityState(PageActivityState::Flags) { }
 
 #if ENABLE(SUBTLE_CRYPTO)
index 9cd6074..69f1531 100644 (file)
@@ -1,3 +1,23 @@
+2015-06-24  Matt Rajca  <mrajca@apple.com>
+
+        MediaSession: propagate MediaSessionMetadata to WebPageProxy
+        https://bugs.webkit.org/show_bug.cgi?id=146282
+
+        Reviewed by Darin Adler and Tim Horton.
+
+        * Shared/WebCoreArgumentCoders.cpp: Added ArgumentEncoder support for MediaSessionMetadata so we can send it
+          through the web page proxy.
+        (IPC::ArgumentCoder<MediaSessionMetadata>::encode):
+        (IPC::ArgumentCoder<MediaSessionMetadata>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::mediaSessionMetadataDidChange):
+        * UIProcess/WebPageProxy.h: Receive mediaSessionMetadataDidChange in the web page proxy.
+        * UIProcess/WebPageProxy.messages.in: Added a new MediaSessionMetadataDidChange message.
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::mediaSessionMetadataDidChange): Push a mediaSessionMetadataDidChange message through the web page proxy.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
 2015-06-24  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [Mac] A checkmark is briefly visible next to the webpage context menu items when they're clicked
index 8fa2a0a..f4917f0 100644 (file)
 #import <WebCore/MediaPlaybackTargetContext.h>
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+#include <WebCore/MediaSessionMetadata.h>
+#endif
+
 using namespace WebCore;
 using namespace WebKit;
 
@@ -1446,6 +1450,32 @@ bool ArgumentCoder<UserStyleSheet>::decode(ArgumentDecoder& decoder, UserStyleSh
     return true;
 }
 
+#if ENABLE(MEDIA_SESSION)
+void ArgumentCoder<MediaSessionMetadata>::encode(ArgumentEncoder& encoder, const MediaSessionMetadata& result)
+{
+    encoder << result.artist();
+    encoder << result.album();
+    encoder << result.title();
+    encoder << result.artworkURL();
+}
+
+bool ArgumentCoder<MediaSessionMetadata>::decode(ArgumentDecoder& decoder, MediaSessionMetadata& result)
+{
+    String artist, album, title;
+    URL artworkURL;
+    if (!decoder.decode(artist))
+        return false;
+    if (!decoder.decode(album))
+        return false;
+    if (!decoder.decode(title))
+        return false;
+    if (!decoder.decode(artworkURL))
+        return false;
+    result = MediaSessionMetadata(title, artist, album, artworkURL);
+    return true;
+}
+#endif
+
 void ArgumentCoder<UserScript>::encode(ArgumentEncoder& encoder, const UserScript& userScript)
 {
     encoder << userScript.source();
index f978f12..8e5c104 100644 (file)
@@ -121,6 +121,12 @@ struct MediaPlaybackTargetContext;
 }
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+namespace WebCore {
+struct MediaSessionMetadata;
+}
+#endif
+
 namespace IPC {
 
 template<> struct ArgumentCoder<WebCore::AffineTransform> {
@@ -455,6 +461,13 @@ template<> struct ArgumentCoder<WebCore::ContentFilterUnblockHandler> {
 };
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+template<> struct ArgumentCoder<WebCore::MediaSessionMetadata> {
+    static void encode(ArgumentEncoder&, const WebCore::MediaSessionMetadata&);
+    static bool decode(ArgumentDecoder&, WebCore::MediaSessionMetadata&);
+};
+#endif
+
 template<> struct ArgumentCoder<WebCore::TextIndicatorData> {
     static void encode(ArgumentEncoder&, const WebCore::TextIndicatorData&);
     static bool decode(ArgumentDecoder&, WebCore::TextIndicatorData&);
index a550e35..62d6326 100644 (file)
@@ -5770,6 +5770,12 @@ void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state)
     m_uiClient->isPlayingAudioDidChange(*this);
 }
 
+#if ENABLE(MEDIA_SESSION)
+void WebPageProxy::mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata& metadata)
+{
+}
+#endif
+
 #if PLATFORM(MAC)
 void WebPageProxy::removeNavigationGestureSnapshot()
 {
index 8e94183..8de146b 100644 (file)
 #include <WebCore/WebMediaSessionManagerClient.h>
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+namespace WebCore {
+struct MediaSessionMetadata;
+}
+#endif
+
 namespace API {
 class ContextMenuClient;
 class FindClient;
@@ -1013,6 +1019,10 @@ public:
     bool isPlayingAudio() const { return !!(m_mediaState & WebCore::MediaProducer::IsPlayingAudio); }
     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags);
 
+#if ENABLE(MEDIA_SESSION)
+    void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&);
+#endif
+
 #if PLATFORM(MAC)
     void removeNavigationGestureSnapshot();
 
index e8f5e9b..f421446 100644 (file)
@@ -423,6 +423,10 @@ messages -> WebPageProxy {
 
     IsPlayingMediaDidChange(unsigned state)
 
+#if ENABLE(MEDIA_SESSION)
+    MediaSessionMetadataDidChange(WebCore::MediaSessionMetadata metadata);
+#endif
+
 #if PLATFORM(MAC)
     DidPerformImmediateActionHitTest(struct WebKit::WebHitTestResult::Data result, bool contentPreventsDefault, WebKit::UserData userData)
 #endif
index 9918afa..9ad4782 100644 (file)
@@ -1061,6 +1061,13 @@ void WebChromeClient::isPlayingMediaDidChange(WebCore::MediaProducer::MediaState
     m_page->send(Messages::WebPageProxy::IsPlayingMediaDidChange(state));
 }
 
+#if ENABLE(MEDIA_SESSION)
+void WebChromeClient::mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata& metadata)
+{
+    m_page->send(Messages::WebPageProxy::MediaSessionMetadataDidChange(metadata));
+}
+#endif
+
 void WebChromeClient::setPageActivityState(PageActivityState::Flags activityState)
 {
     m_page->setPageActivityState(activityState);
index eb9aaeb..8964050 100644 (file)
@@ -294,6 +294,10 @@ private:
     virtual void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags) override;
     virtual void setPageActivityState(WebCore::PageActivityState::Flags) override;
 
+#if ENABLE(MEDIA_SESSION)
+    virtual void mediaSessionMetadataDidChange(const WebCore::MediaSessionMetadata&) override;
+#endif
+
 #if ENABLE(SUBTLE_CRYPTO)
     virtual bool wrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;
     virtual bool unwrapCryptoKey(const Vector<uint8_t>&, Vector<uint8_t>&) const override;