Adopt MRMediaRemoteSetParentApplication.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 01:10:18 +0000 (01:10 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 01:10:18 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162259
<rdar://problem/28376161>

Reviewed by Anders Carlsson.

Allow MediaSessionManagerMac to retrieve the correct parent application identifier
from a PlatformMediaSession so that it can pass that identifier through to MediaRemote
via MRMediaRemoteSetParentApplication.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::sourceApplicationIdentifier):
* Modules/webaudio/AudioContext.h:
* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::sourceApplicationIdentifier):
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSession::resetPlaybackSessionState): Deleted.
* platform/audio/mac/MediaSessionManagerMac.mm:
(WebCore::MediaSessionManagerMac::updateNowPlayingInfo):
* platform/mac/MediaRemoteSoftLink.cpp:
* platform/mac/MediaRemoteSoftLink.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/audio/PlatformMediaSession.cpp
Source/WebCore/platform/audio/PlatformMediaSession.h
Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm
Source/WebCore/platform/mac/MediaRemoteSoftLink.cpp
Source/WebCore/platform/mac/MediaRemoteSoftLink.h

index a094101..57da23f 100644 (file)
@@ -1,3 +1,28 @@
+2016-09-20  Jer Noble  <jer.noble@apple.com>
+
+        Adopt MRMediaRemoteSetParentApplication.
+        https://bugs.webkit.org/show_bug.cgi?id=162259
+        <rdar://problem/28376161>
+
+        Reviewed by Anders Carlsson.
+
+        Allow MediaSessionManagerMac to retrieve the correct parent application identifier
+        from a PlatformMediaSession so that it can pass that identifier through to MediaRemote
+        via MRMediaRemoteSetParentApplication.
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::sourceApplicationIdentifier):
+        * Modules/webaudio/AudioContext.h:
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::sourceApplicationIdentifier):
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSession::resetPlaybackSessionState): Deleted.
+        * platform/audio/mac/MediaSessionManagerMac.mm:
+        (WebCore::MediaSessionManagerMac::updateNowPlayingInfo):
+        * platform/mac/MediaRemoteSoftLink.cpp:
+        * platform/mac/MediaRemoteSoftLink.h:
+
+
 2016-09-20  Nan Wang  <n_wang@apple.com>
 
         AX: AppleVisUser: VO can't navigate web dialogs iOS10
index 5f0597b..a315c25 100644 (file)
 #include "EventNames.h"
 #include "ExceptionCode.h"
 #include "FFTFrame.h"
+#include "Frame.h"
 #include "GainNode.h"
 #include "GenericEventQueue.h"
 #include "HRTFDatabaseLoader.h"
 #include "HRTFPanner.h"
 #include "JSDOMPromise.h"
+#include "NetworkingContext.h"
 #include "OfflineAudioCompletionEvent.h"
 #include "OfflineAudioDestinationNode.h"
 #include "OscillatorNode.h"
@@ -353,6 +355,16 @@ const Document* AudioContext::hostingDocument() const
     return downcast<Document>(m_scriptExecutionContext);
 }
 
+String AudioContext::sourceApplicationIdentifier() const
+{
+    Document* document = this->document();
+    if (Frame* frame = document ? document->frame() : nullptr) {
+        if (NetworkingContext* networkingContext = frame->loader().networkingContext())
+            return networkingContext->sourceApplicationIdentifier();
+    }
+    return emptyString();
+}
+
 RefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
 {
     RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate);
index 586bae1..e25be97 100644 (file)
@@ -317,6 +317,7 @@ private:
     void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) override { }
     bool supportsSeeking() const override { return false; }
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
+    String sourceApplicationIdentifier() const override;
 
     // EventTarget
     void refEventTarget() override { ref(); }
index 4151025..c3379cd 100644 (file)
@@ -6518,7 +6518,7 @@ bool HTMLMediaElement::mediaPlayerShouldWaitForResponseToAuthenticationChallenge
     return true;
 }
 
-String HTMLMediaElement::mediaPlayerSourceApplicationIdentifier() const
+String HTMLMediaElement::sourceApplicationIdentifier() const
 {
     if (Frame* frame = document().frame()) {
         if (NetworkingContext* networkingContext = frame->loader().networkingContext())
index 363366f..c9cb6a8 100644 (file)
@@ -627,7 +627,8 @@ private:
 
     bool mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge&) override;
     void mediaPlayerHandlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType command) override { didReceiveRemoteControlCommand(command, nullptr); }
-    String mediaPlayerSourceApplicationIdentifier() const override;
+    String sourceApplicationIdentifier() const override;
+    String mediaPlayerSourceApplicationIdentifier() const override { return sourceApplicationIdentifier(); }
     Vector<String> mediaPlayerPreferredAudioCharacteristics() const override;
 
 #if PLATFORM(IOS)
index de5d87f..167669a 100644 (file)
@@ -289,6 +289,11 @@ void PlatformMediaSession::updateClientDataBuffering()
     m_client.setShouldBufferData(PlatformMediaSessionManager::sharedManager().sessionCanLoadMedia(*this));
 }
 
+String PlatformMediaSession::sourceApplicationIdentifier() const
+{
+    return m_client.sourceApplicationIdentifier();
+}
+
 bool PlatformMediaSession::isHidden() const
 {
     return m_client.elementIsHidden();
index 659221a..7570f47 100644 (file)
@@ -166,6 +166,7 @@ public:
 
     void scheduleClientDataBufferingCheck();
     virtual void resetPlaybackSessionState() { }
+    String sourceApplicationIdentifier() const;
 
 protected:
     PlatformMediaSessionClient& client() const { return m_client; }
@@ -224,6 +225,7 @@ public:
     virtual void setShouldPlayToPlaybackTarget(bool) { }
 
     virtual const Document* hostingDocument() const = 0;
+    virtual String sourceApplicationIdentifier() const = 0;
 
 protected:
     virtual ~PlatformMediaSessionClient() { }
index b4ea045..420e8eb 100644 (file)
@@ -112,17 +112,13 @@ void MediaSessionManagerMac::updateNowPlayingInfo()
     if (!isMediaRemoteFrameworkAvailable())
         return;
 
-    if (!MRMediaRemoteSetCanBeNowPlayingApplication(true)) {
-        LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - MRMediaRemoteSetCanBeNowPlayingApplication(true) failed");
-        return;
-    }
-
     const PlatformMediaSession* currentSession = this->nowPlayingEligibleSession();
 
     LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - currentSession = %p", currentSession);
 
     if (!currentSession) {
         if (m_nowPlayingActive) {
+            MRMediaRemoteSetCanBeNowPlayingApplication(false);
             LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - clearing now playing info");
             MRMediaRemoteSetNowPlayingInfo(nullptr);
             m_nowPlayingActive = false;
@@ -138,6 +134,11 @@ void MediaSessionManagerMac::updateNowPlayingInfo()
         return;
     }
 
+    if (!MRMediaRemoteSetCanBeNowPlayingApplication(true)) {
+        LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - MRMediaRemoteSetCanBeNowPlayingApplication(true) failed");
+        return;
+    }
+
     String title = currentSession->title();
     double duration = currentSession->duration();
     double rate = currentSession->state() == PlatformMediaSession::Playing ? 1 : 0;
@@ -172,6 +173,10 @@ void MediaSessionManagerMac::updateNowPlayingInfo()
     LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - title = \"%s\", rate = %f, duration = %f, now = %f",
         title.utf8().data(), rate, duration, currentTime);
 
+    String parentApplication = currentSession->sourceApplicationIdentifier();
+    if (canLoad_MediaRemote_MRMediaRemoteSetParentApplication() && !parentApplication.isEmpty())
+        MRMediaRemoteSetParentApplication(MRMediaRemoteGetLocalOrigin(), parentApplication.createCFString().get());
+
     m_nowPlayingActive = true;
     MRPlaybackState playbackState = (currentSession->state() == PlatformMediaSession::Playing) ? kMRPlaybackStatePlaying : kMRPlaybackStatePaused;
     MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), playbackState, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
index 9b7444e..b195ff2 100644 (file)
@@ -42,6 +42,7 @@ SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteCommandInfoSetO
 SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetCanBeNowPlayingApplication, Boolean, (Boolean flag), (flag))
 SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingInfo, void, (CFDictionaryRef info), (info))
 SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin, void, (MROriginRef origin, MRPlaybackState playbackState, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError)), (origin, playbackState, replyQ, completion))
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetParentApplication, void, (MROriginRef origin, CFStringRef parentAppDisplayID), (origin, parentAppDisplayID))
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoTitle, CFStringRef);
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoDuration, CFStringRef);
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoElapsedTime, CFStringRef);
index 50fdc40..cf8c6a8 100644 (file)
@@ -53,6 +53,8 @@ SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingIn
 #define MRMediaRemoteSetNowPlayingInfo softLink_MediaRemote_MRMediaRemoteSetNowPlayingInfo
 SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin, void, (MROriginRef origin, MRPlaybackState playbackState, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError)), (origin, playbackState, replyQ, completion))
 #define MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin softLink_MediaRemote_MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(WebCore, MediaRemote, MRMediaRemoteSetParentApplication, void, (MROriginRef origin, CFStringRef parentAppDisplayID), (origin, parentAppDisplayID))
+#define MRMediaRemoteSetParentApplication softLink_MediaRemote_MRMediaRemoteSetParentApplication
 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoTitle, CFStringRef);
 #define kMRMediaRemoteNowPlayingInfoTitle get_MediaRemote_kMRMediaRemoteNowPlayingInfoTitle()
 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoDuration, CFStringRef);