Media Session: Add plumbing for media control event delivery.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jun 2015 21:49:49 +0000 (21:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Jun 2015 21:49:49 +0000 (21:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145859

Patch by Matt Rajca <mrajca@apple.com> on 2015-06-11
Reviewed by Anders Carlsson.

Source/WebCore:

* Modules/mediasession/MediaEventTypes.h: Added.
* WebCore.xcodeproj/project.pbxproj:
* page/Page.cpp:
(WebCore::Page::handleMediaEvent): Toggle media playback upon receiving the PlayPause event as described in the spec.
* page/Page.h:

Source/WebKit2:

* UIProcess/API/C/WKPage.cpp:
(WKPageHandleMediaEvent):
* UIProcess/API/C/WKPagePrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleMediaEvent):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::handleMediaEvent):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasession/MediaEventTypes.h [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index d7aaf90..2e08004 100644 (file)
@@ -1,3 +1,16 @@
+2015-06-11  Matt Rajca  <mrajca@apple.com>
+
+        Media Session: Add plumbing for media control event delivery.
+        https://bugs.webkit.org/show_bug.cgi?id=145859
+
+        Reviewed by Anders Carlsson.
+
+        * Modules/mediasession/MediaEventTypes.h: Added.
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/Page.cpp:
+        (WebCore::Page::handleMediaEvent): Toggle media playback upon receiving the PlayPause event as described in the spec.
+        * page/Page.h:
+
 2015-06-11  Jon Lee  <jonlee@apple.com>
 
         Update media controls JS and CSS to use picture-in-picture
diff --git a/Source/WebCore/Modules/mediasession/MediaEventTypes.h b/Source/WebCore/Modules/mediasession/MediaEventTypes.h
new file mode 100644 (file)
index 0000000..f27a568
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MediaEventTypes_h
+#define MediaEventTypes_h
+
+#if ENABLE(MEDIA_SESSION)
+
+namespace WebCore {
+
+enum MediaEventType {
+    PlayPause,
+    TrackNext,
+    TrackPrevious
+};
+
+}
+
+#endif
+
+#endif /* MediaEventTypes_h */
index 1faedea..0058786 100644 (file)
                C937FE8D1B1F6821008ECC5D /* HTMLMediaElementMediaSession.h in Headers */ = {isa = PBXBuildFile; fileRef = C968B2E61B1E72F700EF1F81 /* HTMLMediaElementMediaSession.h */; };
                C968B2E81B1E778100EF1F81 /* HTMLMediaElementMediaSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C968B2E71B1E778100EF1F81 /* HTMLMediaElementMediaSession.cpp */; };
                C9DADBCB1B1D3B97001F17D8 /* JSMediaSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */; };
+               C9F87CFE1B28F40E00979B83 /* MediaEventTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = C9F87CFD1B28E5F600979B83 /* MediaEventTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CA3BF67C10D99BAE00E6CE53 /* ScrollAnimator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */; };
                CA3BF67E10D99BAE00E6CE53 /* ScrollAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = CA3BF67D10D99BAE00E6CE53 /* ScrollAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CAE9F90F146441F000C245B0 /* CSSAspectRatioValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */; };
                C968B2E71B1E778100EF1F81 /* HTMLMediaElementMediaSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLMediaElementMediaSession.cpp; sourceTree = "<group>"; };
                C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaSession.cpp; sourceTree = "<group>"; };
                C9DADBCA1B1D3B25001F17D8 /* JSMediaSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaSession.h; sourceTree = "<group>"; };
+               C9F87CFD1B28E5F600979B83 /* MediaEventTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaEventTypes.h; sourceTree = "<group>"; };
                CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollAnimator.cpp; sourceTree = "<group>"; };
                CA3BF67D10D99BAE00E6CE53 /* ScrollAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollAnimator.h; sourceTree = "<group>"; };
                CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSAspectRatioValue.cpp; sourceTree = "<group>"; };
                                C968B2E71B1E778100EF1F81 /* HTMLMediaElementMediaSession.cpp */,
                                C968B2E61B1E72F700EF1F81 /* HTMLMediaElementMediaSession.h */,
                                C968B2E51B1E704500EF1F81 /* HTMLMediaElementMediaSession.idl */,
+                               C9F87CFD1B28E5F600979B83 /* MediaEventTypes.h */,
                                C90843CD1B18E47D00B68564 /* MediaRemoteControls.cpp */,
                                C90843CE1B18E47D00B68564 /* MediaRemoteControls.h */,
                                C93458BB1B18D77E0088EE12 /* MediaRemoteControls.idl */,
                                FD6F252D13F5EF0E0065165F /* MediaElementAudioSourceNode.h in Headers */,
                                07FE99DD18807A7D00256648 /* MediaElementSession.h in Headers */,
                                E44613AD0CD6331000FADA75 /* MediaError.h in Headers */,
+                               C9F87CFE1B28F40E00979B83 /* MediaEventTypes.h in Headers */,
                                4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */,
                                07A6D1EC1491137700051D0C /* MediaFragmentURIParser.h in Headers */,
                                A8EA800E0A19516E00A8EF5F /* MediaList.h in Headers */,
index 8fc29be..b06caa2 100644 (file)
 #include "MediaPlaybackTarget.h"
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+#include "MediaSessionManager.h"
+#endif
+
 namespace WebCore {
 
 static HashSet<Page*>* allPages;
@@ -1227,6 +1231,19 @@ void Page::setMuted(bool muted)
         frame->document()->pageMutedStateDidChange();
 }
 
+#if ENABLE(MEDIA_SESSION)
+void Page::handleMediaEvent(MediaEventType eventType)
+{
+    switch (eventType) {
+    case MediaEventType::PlayPause:
+        MediaSessionManager::singleton().togglePlayback();
+        break;
+    default:
+        break;
+    }
+}
+#endif
+
 #if !ASSERT_DISABLED
 void Page::checkSubframeCountConsistency() const
 {
index 44685f1..2d64a9c 100644 (file)
 #include <wtf/SchedulePair.h>
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+#include "MediaEventTypes.h"
+#endif
+
 namespace JSC {
 class Debugger;
 }
@@ -443,6 +447,10 @@ public:
     bool isMuted() const { return m_muted; }
     WEBCORE_EXPORT void setMuted(bool);
 
+#if ENABLE(MEDIA_SESSION)
+    WEBCORE_EXPORT void handleMediaEvent(MediaEventType);
+#endif
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     void addPlaybackTargetPickerClient(uint64_t);
     void removePlaybackTargetPickerClient(uint64_t);
index e1036c2..f059ca1 100644 (file)
@@ -1,3 +1,21 @@
+2015-06-11  Matt Rajca  <mrajca@apple.com>
+
+        Media Session: Add plumbing for media control event delivery.
+        https://bugs.webkit.org/show_bug.cgi?id=145859
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageHandleMediaEvent):
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleMediaEvent):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::handleMediaEvent):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2015-06-11  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [OS X] Decoding fonts may return nil when using force click
index b6fafbd..1447888 100644 (file)
 #include "WebVibrationProxy.h"
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+#include <WebCore/MediaEventTypes.h>
+#endif
+
 using namespace WebCore;
 using namespace WebKit;
 
@@ -2121,6 +2125,32 @@ void WKPageSetMuted(WKPageRef page, bool muted)
     toImpl(page)->setMuted(muted);
 }
 
+void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType wkEventType)
+{
+#if ENABLE(MEDIA_SESSION)
+    MediaEventType eventType;
+
+    switch (wkEventType) {
+    case kWKMediaEventTypePlayPause:
+        eventType = MediaEventType::PlayPause;
+        break;
+    case kWKMediaEventTypeTrackNext:
+        eventType = MediaEventType::TrackNext;
+        break;
+    case kWKMediaEventTypeTrackPrevious:
+        eventType = MediaEventType::TrackPrevious;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+
+    toImpl(page)->handleMediaEvent(eventType);
+#else
+    UNUSED_PARAM(page);
+    UNUSED_PARAM(wkEventType);
+#endif
+}
+
 void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
 {
     toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
index 347cc86..7fe994b 100644 (file)
@@ -111,6 +111,15 @@ WK_EXPORT void WKPageSetAddsVisitedLinks(WKPageRef page, bool visitedLinks);
 WK_EXPORT bool WKPageIsPlayingAudio(WKPageRef page);
 WK_EXPORT void WKPageSetMuted(WKPageRef page, bool muted);
 
+enum {
+    kWKMediaEventTypePlayPause,
+    kWKMediaEventTypeTrackNext,
+    kWKMediaEventTypeTrackPrevious
+};
+typedef uint32_t WKMediaEventType;
+
+WK_EXPORT void WKPageHandleMediaEvent(WKPageRef page, WKMediaEventType event);
+
 WK_EXPORT void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef page, WKURLRef url, bool shouldOpenExternalURLs);
 
 #ifdef __cplusplus
index 2a7ad63..10da691 100644 (file)
@@ -3774,6 +3774,16 @@ void WebPageProxy::setMuted(bool muted)
     m_process->send(Messages::WebPage::SetMuted(muted), m_pageID);
 }
 
+#if ENABLE(MEDIA_SESSION)
+void WebPageProxy::handleMediaEvent(MediaEventType eventType)
+{
+    if (!isValid())
+        return;
+    
+    m_process->send(Messages::WebPage::HandleMediaEvent(eventType), m_pageID);
+}
+#endif
+
 void WebPageProxy::setMayStartMediaWhenInWindow(bool mayStartMedia)
 {
     if (mayStartMedia == m_mayStartMediaWhenInWindow)
index 141ccc6..0326da9 100644 (file)
@@ -922,6 +922,10 @@ public:
     void setMayStartMediaWhenInWindow(bool);
     bool mayStartMediaWhenInWindow() const { return m_mayStartMediaWhenInWindow; }
         
+#if ENABLE(MEDIA_SESSION)
+    void handleMediaEvent(WebCore::MediaEventType);
+#endif
+
     // WebPopupMenuProxy::Client
     virtual NativeWebMouseEvent* currentlyProcessedMouseDownEvent() override;
 
index a522e93..a3c35b6 100644 (file)
@@ -4048,6 +4048,13 @@ void WebPage::setMuted(bool muted)
     m_page->setMuted(muted);
 }
 
+#if ENABLE(MEDIA_SESSION)
+void WebPage::handleMediaEvent(uint32_t eventType)
+{
+    m_page->handleMediaEvent(static_cast<MediaEventType>(eventType));
+}
+#endif
+
 void WebPage::setMayStartMediaWhenInWindow(bool mayStartMedia)
 {
     if (mayStartMedia == m_mayStartMediaWhenInWindow)
index 6cb709e..5ca1d65 100644 (file)
@@ -740,6 +740,10 @@ public:
     void setMuted(bool);
     void setMayStartMediaWhenInWindow(bool);
 
+#if ENABLE(MEDIA_SESSION)
+    void handleMediaEvent(uint32_t /* WebCore::MediaEventType */);
+#endif
+
     void updateMainFrameScrollOffsetPinning();
 
     bool mainFrameHasCustomContentProvider() const;
index f7e76d2..8082c00 100644 (file)
@@ -314,6 +314,10 @@ messages -> WebPage LegacyReceiver {
     SetMuted(bool muted)
     SetMayStartMediaWhenInWindow(bool mayStartMedia)
 
+#if ENABLE(MEDIA_SESSION)
+    HandleMediaEvent(uint32_t eventType)
+#endif
+
     // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
     // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
     Dummy() -> (bool dummyReturn)