Changeset 272445 in webkit
- Timestamp:
- Feb 5, 2021 3:18:55 PM (18 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 31 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/mediasession/MediaImage.h (modified) (2 diffs)
-
Source/WebCore/Modules/mediasession/MediaMetadata.cpp (modified) (5 diffs)
-
Source/WebCore/Modules/mediasession/MediaMetadata.h (modified) (5 diffs)
-
Source/WebCore/Modules/mediasession/MediaMetadataInit.h (modified) (2 diffs)
-
Source/WebCore/Modules/mediasession/MediaSession.cpp (modified) (7 diffs)
-
Source/WebCore/Modules/mediasession/MediaSession.h (modified) (4 diffs)
-
Source/WebCore/PAL/ChangeLog (modified) (1 diff)
-
Source/WebCore/PAL/pal/spi/mac/MediaRemoteSPI.h (modified) (3 diffs)
-
Source/WebCore/WebCore.xcodeproj/project.pbxproj (modified) (3 diffs)
-
Source/WebCore/html/HTMLMediaElement.cpp (modified) (3 diffs)
-
Source/WebCore/html/MediaElementSession.cpp (modified) (4 diffs)
-
Source/WebCore/html/MediaElementSession.h (modified) (2 diffs)
-
Source/WebCore/page/ChromeClient.h (modified) (1 diff)
-
Source/WebCore/platform/RemoteCommandListener.cpp (modified) (2 diffs)
-
Source/WebCore/platform/RemoteCommandListener.h (modified) (4 diffs)
-
Source/WebCore/platform/audio/NowPlayingInfo.h (modified) (4 diffs)
-
Source/WebCore/platform/audio/PlatformMediaSession.cpp (modified) (3 diffs)
-
Source/WebCore/platform/audio/PlatformMediaSession.h (modified) (2 diffs)
-
Source/WebCore/platform/audio/PlatformMediaSessionManager.h (modified) (2 diffs)
-
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h (modified) (2 diffs)
-
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (modified) (4 diffs)
-
Source/WebCore/platform/mac/MediaRemoteSoftLink.h (modified) (3 diffs)
-
Source/WebCore/platform/mac/MediaRemoteSoftLink.mm (modified) (3 diffs)
-
Source/WebCore/platform/mac/RemoteCommandListenerMac.h (modified) (2 diffs)
-
Source/WebCore/platform/mac/RemoteCommandListenerMac.mm (modified) (7 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (8 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaSession.mm (added)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/media-remote.html (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r272439 r272445 1 2021-02-05 Eric Carlson <eric.carlson@apple.com> 2 3 [Mac] Connect MediaSession with MediaRemote and NowPlaying 4 https://bugs.webkit.org/show_bug.cgi?id=221431 5 <rdar://problem/74000363> 6 7 Reviewed by Jer Noble. 8 9 Route all remote control commands to navigator.mediaSession when it has any 10 registered action handlers, and pass navigator.mediaSession.metadata to NowPlaying. 11 12 Tested with new API tests in Tools/TestWebKitAPI/Tests/WebKitCocoa/MediaSession.mm. 13 14 * Modules/mediasession/MediaImage.h: 15 (WebCore::MediaImage::encode const): 16 (WebCore::MediaImage::decode): 17 * Modules/mediasession/MediaMetadata.cpp: 18 (WebCore::MediaMetadata::setTitle): 19 (WebCore::MediaMetadata::setArtist): 20 (WebCore::MediaMetadata::setAlbum): 21 (WebCore::MediaMetadata::setArtwork): 22 * Modules/mediasession/MediaMetadata.h: 23 (WebCore::MediaMetadata::title const): 24 (WebCore::MediaMetadata::artist const): 25 (WebCore::MediaMetadata::album const): 26 (WebCore::MediaMetadata::artwork const): 27 (WebCore::MediaMetadata::metadata const): 28 * Modules/mediasession/MediaMetadataInit.h: 29 (WebCore::MediaMetadataInit::encode const): 30 (WebCore::MediaMetadataInit::decode): 31 * Modules/mediasession/MediaSession.cpp: 32 (WebCore::nextLogIdentifier): 33 (WebCore::logChannel): 34 (WebCore::logClassName): 35 (WebCore::platformCommandForMediaSessionAction): 36 (WebCore::MediaSession::MediaSession): 37 (WebCore::MediaSession::setMetadata): 38 (WebCore::MediaSession::setPlaybackState): 39 (WebCore::MediaSession::setActionHandler): 40 (WebCore::MediaSession::setPositionState): 41 * Modules/mediasession/MediaSession.h: 42 (WebCore::MediaSession::hasActiveActionHandlers const): 43 (WebCore::MediaSession::logger const): 44 (WebCore::MediaSession::logIdentifier const): 45 (WTF::LogArgument<WebCore::MediaSessionPlaybackState>::toString): 46 (WTF::LogArgument<WebCore::MediaSessionAction>::toString): 47 * WebCore.xcodeproj/project.pbxproj: 48 * html/HTMLMediaElement.cpp: 49 (WebCore::HTMLMediaElement::didReceiveRemoteControlCommand): 50 * html/MediaElementSession.cpp: 51 (WebCore::MediaElementSession::didReceiveRemoteControlCommand): 52 (WebCore::MediaElementSession::nowPlayingInfo const): 53 * html/MediaElementSession.h: 54 * page/ChromeClient.h: 55 * platform/RemoteCommandListener.cpp: 56 (WebCore::RemoteCommandListener::scheduleSupportedCommandsUpdate): 57 (WebCore::RemoteCommandListener::addSupportedCommand): 58 (WebCore::RemoteCommandListener::removeSupportedCommand): 59 * platform/RemoteCommandListener.h: 60 * platform/audio/NowPlayingInfo.h: 61 (WebCore::NowPlayingInfo::decode): 62 * platform/audio/PlatformMediaSession.cpp: 63 (WebCore::convertEnumerationToString): 64 * platform/audio/PlatformMediaSession.h: 65 * platform/audio/PlatformMediaSessionManager.h: 66 (WebCore::PlatformMediaSessionManager::addSupportedCommand): 67 (WebCore::PlatformMediaSessionManager::removeSupportedCommand): 68 * platform/audio/cocoa/MediaSessionManagerCocoa.h: 69 * platform/audio/cocoa/MediaSessionManagerCocoa.mm: 70 (WebCore::MediaSessionManagerCocoa::scheduleSessionStatusUpdate): 71 (WebCore::MediaSessionManagerCocoa::sessionCanProduceAudioChanged): 72 (WebCore::MediaSessionManagerCocoa::addSupportedCommand): 73 (WebCore::MediaSessionManagerCocoa::removeSupportedCommand): 74 (WebCore::MediaSessionManagerCocoa::setNowPlayingInfo): 75 * platform/mac/MediaRemoteSoftLink.cpp: 76 * platform/mac/MediaRemoteSoftLink.h: 77 * platform/mac/RemoteCommandListenerMac.h: 78 * platform/mac/RemoteCommandListenerMac.mm: 79 (WebCore::mediaRemoteCommandForPlatformCommand): 80 (WebCore::RemoteCommandListenerMac::defaultCommands): 81 (WebCore::isSeekCommand): 82 (WebCore::RemoteCommandListenerMac::updateSupportedCommands): 83 (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): 84 1 85 2021-02-05 Jer Noble <jer.noble@apple.com> 2 86 -
trunk/Source/WebCore/Modules/mediasession/MediaImage.h
r268735 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 34 34 String sizes; 35 35 String type; 36 37 template<class Encoder> void encode(Encoder&) const; 38 template<class Decoder> static Optional<MediaImage> decode(Decoder&); 36 39 }; 40 41 template<class Encoder> inline void MediaImage::encode(Encoder& encoder) const 42 { 43 encoder << src << sizes << type; 44 } 45 46 template<class Decoder> inline Optional<MediaImage> MediaImage::decode(Decoder& decoder) 47 { 48 String src; 49 if (!decoder.decode(src)) 50 return { }; 51 52 String sizes; 53 if (!decoder.decode(sizes)) 54 return { }; 55 56 String type; 57 if (!decoder.decode(type)) 58 return { }; 59 60 return MediaImage { WTFMove(src), WTFMove(sizes), WTFMove(type) }; 61 } 37 62 38 63 } -
trunk/Source/WebCore/Modules/mediasession/MediaMetadata.cpp
r268735 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 65 65 void MediaMetadata::setTitle(const String& title) 66 66 { 67 if (m_ title == title)67 if (m_metadata.title == title) 68 68 return; 69 m_title = title; 69 70 m_metadata.title = title; 70 71 metadataUpdated(); 71 72 } … … 73 74 void MediaMetadata::setArtist(const String& artist) 74 75 { 75 if (m_ artist == artist)76 if (m_metadata.artist == artist) 76 77 return; 77 m_artist = artist; 78 79 m_metadata.artist = artist; 78 80 metadataUpdated(); 79 81 } … … 81 83 void MediaMetadata::setAlbum(const String& album) 82 84 { 83 if (m_ album == album)85 if (m_metadata.album == album) 84 86 return; 85 m_album = album; 87 88 m_metadata.album = album; 86 89 metadataUpdated(); 87 90 } … … 98 101 } 99 102 100 m_ artwork = WTFMove(resolvedArtwork);103 m_metadata.artwork = WTFMove(resolvedArtwork); 101 104 metadataUpdated(); 102 105 return { }; -
trunk/Source/WebCore/Modules/mediasession/MediaMetadata.h
r268735 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #if ENABLE(MEDIA_SESSION) 29 29 30 #include "MediaMetadataInit.h" 30 31 #include "MediaSession.h" 31 32 #include <wtf/Optional.h> … … 35 36 namespace WebCore { 36 37 37 class Document;38 class MediaSession;39 38 struct MediaImage; 40 struct MediaMetadataInit; 39 40 using MediaSessionMetadata = MediaMetadataInit; 41 41 42 42 class MediaMetadata : public RefCounted<MediaMetadata> { … … 48 48 void resetMediaSession(); 49 49 50 const String& title() const { return m_ title; }50 const String& title() const { return m_metadata.title; } 51 51 void setTitle(const String&); 52 52 53 const String& artist() const { return m_ artist; }53 const String& artist() const { return m_metadata.artist; } 54 54 void setArtist(const String&); 55 55 56 const String& album() const { return m_ album; }56 const String& album() const { return m_metadata.album; } 57 57 void setAlbum(const String&); 58 58 59 const Vector<MediaImage>& artwork() const { return m_ artwork; }59 const Vector<MediaImage>& artwork() const { return m_metadata.artwork; } 60 60 ExceptionOr<void> setArtwork(ScriptExecutionContext&, Vector<MediaImage>&&); 61 62 const MediaSessionMetadata& metadata() const { return m_metadata; } 61 63 62 64 private: … … 65 67 66 68 WeakPtr<MediaSession> m_session; 67 String m_title; 68 String m_artist; 69 String m_album; 70 Vector<MediaImage> m_artwork; 69 MediaSessionMetadata m_metadata; 71 70 }; 72 71 -
trunk/Source/WebCore/Modules/mediasession/MediaMetadataInit.h
r268735 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 37 37 String album; 38 38 Vector<MediaImage> artwork; 39 40 template<class Encoder> void encode(Encoder&) const; 41 template<class Decoder> static Optional<MediaMetadataInit> decode(Decoder&); 39 42 }; 43 44 template<class Encoder> inline void MediaMetadataInit::encode(Encoder& encoder) const 45 { 46 encoder << title << artist << album << artwork; 47 } 48 49 template<class Decoder> inline Optional<MediaMetadataInit> MediaMetadataInit::decode(Decoder& decoder) 50 { 51 String title; 52 if (!decoder.decode(title)) 53 return { }; 54 55 String artist; 56 if (!decoder.decode(artist)) 57 return { }; 58 59 String album; 60 if (!decoder.decode(album)) 61 return { }; 62 63 Vector<MediaImage> artwork; 64 if (!decoder.decode(artwork)) 65 return { }; 66 67 return MediaMetadataInit { WTFMove(title), WTFMove(artist), WTFMove(album), WTFMove(artwork) }; 68 } 40 69 41 70 } -
trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp
r268769 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #if ENABLE(MEDIA_SESSION) 30 30 31 #include "Logging.h" 31 32 #include "MediaMetadata.h" 32 33 #include "Navigator.h" 34 #include "PlatformMediaSessionManager.h" 33 35 34 36 namespace WebCore { 37 38 static const void* nextLogIdentifier() 39 { 40 static uint64_t logIdentifier = cryptographicallyRandomNumber(); 41 return reinterpret_cast<const void*>(++logIdentifier); 42 } 43 44 static WTFLogChannel& logChannel() { return LogMedia; } 45 static const char* logClassName() { return "MediaSession"; } 46 47 static PlatformMediaSession::RemoteControlCommandType platformCommandForMediaSessionAction(MediaSessionAction action) 48 { 49 static const auto commandMap = makeNeverDestroyed([] { 50 using ActionToCommandMap = HashMap<MediaSessionAction, PlatformMediaSession::RemoteControlCommandType, WTF::IntHash<MediaSessionAction>, WTF::StrongEnumHashTraits<MediaSessionAction>>; 51 52 return ActionToCommandMap { 53 { MediaSessionAction::Play, PlatformMediaSession::PlayCommand }, 54 { MediaSessionAction::Pause, PlatformMediaSession::PauseCommand }, 55 { MediaSessionAction::Seekforward, PlatformMediaSession::SkipForwardCommand }, 56 { MediaSessionAction::Seekbackward, PlatformMediaSession::SkipBackwardCommand }, 57 { MediaSessionAction::Previoustrack, PlatformMediaSession::NextTrackCommand }, 58 { MediaSessionAction::Nexttrack, PlatformMediaSession::PreviousTrackCommand }, 59 { MediaSessionAction::Stop, PlatformMediaSession::StopCommand }, 60 { MediaSessionAction::Seekto, PlatformMediaSession::SeekToPlaybackPositionCommand }, 61 }; 62 }()); 63 64 auto it = commandMap.get().find(action); 65 if (it != commandMap.get().end()) 66 return it->value; 67 68 return PlatformMediaSession::NoCommand; 69 } 35 70 36 71 Ref<MediaSession> MediaSession::create(Navigator& navigator) … … 42 77 : m_navigator(makeWeakPtr(navigator)) 43 78 { 79 m_logger = makeRefPtr(Document::sharedLogger()); 80 m_logIdentifier = nextLogIdentifier(); 81 82 ALWAYS_LOG(LOGIDENTIFIER); 44 83 } 45 84 … … 48 87 void MediaSession::setMetadata(RefPtr<MediaMetadata>&& metadata) 49 88 { 89 ALWAYS_LOG(LOGIDENTIFIER); 90 50 91 if (m_metadata) 51 92 m_metadata->resetMediaSession(); … … 61 102 return; 62 103 104 ALWAYS_LOG(LOGIDENTIFIER, state); 105 63 106 auto currentPosition = this->currentPosition(); 64 107 if (m_positionState && currentPosition) { … … 71 114 void MediaSession::setActionHandler(MediaSessionAction action, RefPtr<MediaSessionActionHandler>&& handler) 72 115 { 73 if (handler) 116 if (handler) { 117 ALWAYS_LOG(LOGIDENTIFIER, "adding ", action); 74 118 m_actionHandlers.set(action, handler); 75 else 76 m_actionHandlers.remove(action); 119 PlatformMediaSessionManager::sharedManager().addSupportedCommand(platformCommandForMediaSessionAction(action)); 120 } else { 121 if (m_actionHandlers.contains(action)) { 122 ALWAYS_LOG(LOGIDENTIFIER, "removing ", action); 123 m_actionHandlers.remove(action); 124 } 125 PlatformMediaSessionManager::sharedManager().removeSupportedCommand(platformCommandForMediaSessionAction(action)); 126 } 127 77 128 actionHandlersUpdated(); 78 129 } … … 90 141 ExceptionOr<void> MediaSession::setPositionState(Optional<MediaPositionState>&& state) 91 142 { 143 ALWAYS_LOG(LOGIDENTIFIER); 144 92 145 if (!state) { 93 146 m_positionState = WTF::nullopt; -
trunk/Source/WebCore/Modules/mediasession/MediaSession.h
r268769 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #if ENABLE(MEDIA_SESSION) 29 29 30 #include "JSMediaPositionState.h" 31 #include "JSMediaSessionAction.h" 32 #include "JSMediaSessionPlaybackState.h" 30 33 #include "MediaPositionState.h" 31 34 #include "MediaSessionAction.h" 32 35 #include "MediaSessionActionHandler.h" 33 36 #include "MediaSessionPlaybackState.h" 37 #include <wtf/Logger.h> 34 38 #include <wtf/MonotonicTime.h> 35 39 #include <wtf/Optional.h> … … 58 62 59 63 void metadataUpdated(); 64 60 65 void actionHandlersUpdated(); 61 66 bool hasActionHandler(MediaSessionAction) const; 62 67 WEBCORE_EXPORT RefPtr<MediaSessionActionHandler> handlerForAction(MediaSessionAction) const; 68 bool hasActiveActionHandlers() const { return !m_actionHandlers.isEmpty(); } 63 69 64 70 private: 65 71 explicit MediaSession(Navigator&); 72 73 const Logger& logger() const { return *m_logger.get(); } 74 const void* logIdentifier() const { return m_logIdentifier; } 66 75 67 76 WeakPtr<Navigator> m_navigator; … … 72 81 MonotonicTime m_timeAtLastPositionUpdate; 73 82 HashMap<MediaSessionAction, RefPtr<MediaSessionActionHandler>, WTF::IntHash<MediaSessionAction>, WTF::StrongEnumHashTraits<MediaSessionAction>> m_actionHandlers; 83 RefPtr<const Logger> m_logger; 84 const void* m_logIdentifier; 85 }; 86 87 } 88 89 namespace WTF { 90 91 template<> struct LogArgument<WebCore::MediaSessionPlaybackState> { 92 static String toString(WebCore::MediaSessionPlaybackState state) { return convertEnumerationToString(state); } 93 }; 94 95 template<> struct LogArgument<WebCore::MediaSessionAction> { 96 static String toString(WebCore::MediaSessionAction action) { return convertEnumerationToString(action); } 74 97 }; 75 98 -
trunk/Source/WebCore/PAL/ChangeLog
r272188 r272445 1 2021-02-05 Eric Carlson <eric.carlson@apple.com> 2 3 [Mac] Connect MediaSession with MediaRemote and NowPlaying 4 https://bugs.webkit.org/show_bug.cgi?id=221431 5 <rdar://problem/74000363> 6 7 Reviewed by Jer Noble. 8 9 * pal/spi/mac/MediaRemoteSPI.h: 10 1 11 2021-02-01 Jer Noble <jer.noble@apple.com> 2 12 -
trunk/Source/WebCore/PAL/pal/spi/mac/MediaRemoteSPI.h
r261110 r272445 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 93 93 94 94 typedef uint32_t MRMediaRemoteError; 95 typedef uint32_t MRSendCommandAppOptions; 96 typedef uint32_t MRSendCommandError; 95 97 typedef struct _MROrigin *MROriginRef; 96 98 typedef struct _MRMediaRemoteCommandInfo *MRMediaRemoteCommandInfoRef; … … 104 106 void* MRMediaRemoteAddAsyncCommandHandlerBlock(MRMediaRemoteAsyncCommandHandlerBlock); 105 107 void MRMediaRemoteRemoveCommandHandlerBlock(void *observer); 106 void MRMediaRemoteSetSupportedCommands(CFArrayRef commands, MROriginRef, dispatch_queue_t replyQ, void(^completion)(MRMediaRemoteError err)); 108 void MRMediaRemoteSetSupportedCommands(CFArrayRef, MROriginRef, dispatch_queue_t, void(^completion)(MRMediaRemoteError)); 109 void MRMediaRemoteGetSupportedCommandsForOrigin(MROriginRef, dispatch_queue_t, void(^completion)(CFArrayRef)); 107 110 void MRMediaRemoteSetNowPlayingVisibility(MROriginRef, MRNowPlayingClientVisibility); 111 Boolean MRMediaRemoteSendCommandToApp(MRMediaRemoteCommand, CFDictionaryRef, MROriginRef, CFStringRef, MRSendCommandAppOptions, dispatch_queue_t, void(^completion)(MRSendCommandError, CFArrayRef)); 108 112 109 113 #pragma mark - MROrigin -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r272396 r272445 140 140 077B64131B94F12E003E9AD5 /* MediaPlaybackTargetPickerMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 077B64111B94F12E003E9AD5 /* MediaPlaybackTargetPickerMock.h */; settings = {ATTRIBUTES = (Private, ); }; }; 141 141 077B64171B95F703003E9AD5 /* MediaPlaybackTargetMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 077B64151B95F703003E9AD5 /* MediaPlaybackTargetMock.h */; settings = {ATTRIBUTES = (Private, ); }; }; 142 0782894825C23FE500A7BA03 /* MediaMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDDEA2D2538CE0400A1300C /* MediaMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; }; 143 0782894A25C36FCF00A7BA03 /* MediaSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDDEA232538CD8000A1300C /* MediaSession.h */; }; 144 0782894B25C36FED00A7BA03 /* MediaImage.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDDEA322538CE3500A1300C /* MediaImage.h */; }; 145 0782894C25C3700B00A7BA03 /* MediaMetadataInit.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDDEA302538CE1E00A1300C /* MediaMetadataInit.h */; }; 142 146 0783228518013ED800999E0C /* MediaStreamAudioSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 0783228318013ED800999E0C /* MediaStreamAudioSource.h */; }; 143 147 07846343145B151A00A58DF1 /* JSTrackEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 07846341145B151A00A58DF1 /* JSTrackEvent.h */; }; … … 33703 33707 4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */, 33704 33708 07A6D1EC1491137700051D0C /* MediaFragmentURIParser.h in Headers */, 33709 0782894B25C36FED00A7BA03 /* MediaImage.h in Headers */, 33705 33710 CDF4B71A1E01D3D000E235A2 /* MediaKeySessionType.idl in Headers */, 33706 33711 CDF4B7281E03C57300E235A2 /* MediaKeysRequirement.idl in Headers */, 33707 33712 CDF4B7181E01CB9100E235A2 /* MediaKeysRestrictions.h in Headers */, 33708 33713 A8EA800E0A19516E00A8EF5F /* MediaList.h in Headers */, 33714 0782894825C23FE500A7BA03 /* MediaMetadata.h in Headers */, 33715 0782894C25C3700B00A7BA03 /* MediaMetadataInit.h in Headers */, 33709 33716 5EBB89311C7777FF00C65D41 /* MediaPayload.h in Headers */, 33710 33717 07E3DFD11A9E786500764CA8 /* MediaPlaybackTarget.h in Headers */, … … 33747 33754 CDBEAEAD19D92B6C00BEBA88 /* MediaSelectionGroupAVFObjC.h in Headers */, 33748 33755 A17D275E1EAC579800BF01E7 /* MediaSelectionOption.h in Headers */, 33756 0782894A25C36FCF00A7BA03 /* MediaSession.h in Headers */, 33749 33757 416ECAE525B58CC400B34DA5 /* MediaSessionGroupIdentifier.h in Headers */, 33750 33758 CDA9593F2412BAE000910EEF /* MediaSessionHelperIOS.h in Headers */, -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r272429 r272445 1 1 /* 2 * Copyright (C) 2007-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2007-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 7520 7520 7521 7521 UserGestureIndicator remoteControlUserGesture(ProcessingUserGesture, &document()); 7522 double offset = 15; 7522 7523 switch (command) { 7523 7524 case PlatformMediaSession::PlayCommand: … … 7541 7542 endScanning(); 7542 7543 break; 7544 case PlatformMediaSession::SkipForwardCommand: 7545 if (argument) 7546 offset = argument->asDouble; 7547 handleSeekToPlaybackPosition(offset); 7548 break; 7549 case PlatformMediaSession::SkipBackwardCommand: 7550 if (argument) 7551 offset = argument->asDouble; 7552 handleSeekToPlaybackPosition(0 - offset); 7553 break; 7543 7554 case PlatformMediaSession::SeekToPlaybackPositionCommand: 7544 7555 ASSERT(argument); -
trunk/Source/WebCore/html/MediaElementSession.cpp
r271870 r272445 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 55 55 #include <wtf/text/StringBuilder.h> 56 56 57 #if ENABLE(MEDIA_SESSION) 58 #include "MediaMetadata.h" 59 #include "MediaSession.h" 60 #include "NavigatorMediaSession.h" 61 #endif 62 57 63 #if PLATFORM(IOS_FAMILY) 58 64 #include "AudioSession.h" … … 1022 1028 } 1023 1029 1030 #if ENABLE(MEDIA_SESSION) 1031 void MediaElementSession::didReceiveRemoteControlCommand(RemoteControlCommandType commandType, const RemoteCommandArgument* argument) 1032 { 1033 auto* window = m_element.document().domWindow(); 1034 auto* session = window ? &NavigatorMediaSession::mediaSession(window->navigator()) : nullptr; 1035 if (!session || !session->hasActiveActionHandlers()) { 1036 PlatformMediaSession::didReceiveRemoteControlCommand(commandType, argument); 1037 return; 1038 } 1039 1040 MediaSessionActionDetails actionDetails; 1041 switch (commandType) { 1042 case NoCommand: 1043 return; 1044 case PlayCommand: 1045 actionDetails.action = MediaSessionAction::Play; 1046 break; 1047 case PauseCommand: 1048 actionDetails.action = MediaSessionAction::Pause; 1049 break; 1050 case StopCommand: 1051 actionDetails.action = MediaSessionAction::Stop; 1052 break; 1053 case TogglePlayPauseCommand: 1054 actionDetails.action = m_element.paused() ? MediaSessionAction::Play : MediaSessionAction::Pause; 1055 break; 1056 case SeekToPlaybackPositionCommand: 1057 ASSERT(argument); 1058 if (!argument) 1059 return; 1060 actionDetails.action = MediaSessionAction::Seekto; 1061 actionDetails.seekTime = argument->asDouble; 1062 break; 1063 case SkipForwardCommand: 1064 if (argument) 1065 actionDetails.seekOffset = argument->asDouble; 1066 actionDetails.action = MediaSessionAction::Seekforward; 1067 break; 1068 case SkipBackwardCommand: 1069 if (argument) 1070 actionDetails.seekOffset = argument->asDouble; 1071 actionDetails.action = MediaSessionAction::Seekbackward; 1072 break; 1073 case NextTrackCommand: 1074 actionDetails.action = MediaSessionAction::Nexttrack; 1075 break; 1076 case PreviousTrackCommand: 1077 actionDetails.action = MediaSessionAction::Previoustrack; 1078 break; 1079 case BeginSeekingBackwardCommand: 1080 case EndSeekingBackwardCommand: 1081 case BeginSeekingForwardCommand: 1082 case EndSeekingForwardCommand: 1083 ASSERT_NOT_REACHED(); 1084 break; 1085 } 1086 1087 if (auto handler = session->handlerForAction(actionDetails.action)) 1088 handler->handleEvent(actionDetails); 1089 else 1090 ALWAYS_LOG(LOGIDENTIFIER, "Ignoring command, no action handler registered for ", actionDetails.action); 1091 } 1092 #endif 1093 1024 1094 Optional<NowPlayingInfo> MediaElementSession::nowPlayingInfo() const 1025 1095 { … … 1033 1103 currentTime = MediaPlayer::invalidTime(); 1034 1104 1035 return NowPlayingInfo { m_element.mediaSessionTitle(), m_element.sourceApplicationIdentifier(), duration, currentTime, supportsSeeking, m_element.mediaSessionUniqueIdentifier(), isPlaying, allowsNowPlayingControlsVisibility }; 1105 #if ENABLE(MEDIA_SESSION) 1106 auto* window = m_element.document().domWindow(); 1107 auto* sessionMetadata = window ? NavigatorMediaSession::mediaSession(window->navigator()).metadata() : nullptr; 1108 if (sessionMetadata) 1109 return NowPlayingInfo { sessionMetadata->title(), sessionMetadata->artist(), sessionMetadata->album(), m_element.sourceApplicationIdentifier(), duration, currentTime, supportsSeeking, m_element.mediaSessionUniqueIdentifier(), isPlaying, allowsNowPlayingControlsVisibility }; 1110 #endif 1111 1112 return NowPlayingInfo { m_element.mediaSessionTitle(), emptyString(), emptyString(), m_element.sourceApplicationIdentifier(), duration, currentTime, supportsSeeking, m_element.mediaSessionUniqueIdentifier(), isPlaying, allowsNowPlayingControlsVisibility }; 1036 1113 } 1037 1114 -
trunk/Source/WebCore/html/MediaElementSession.h
r271870 r272445 1 1 /* 2 * Copyright (C) 2014-20 15Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 175 175 #endif 176 176 177 #if ENABLE(MEDIA_SESSION) 178 void didReceiveRemoteControlCommand(RemoteControlCommandType, const RemoteCommandArgument* = nullptr) final; 179 #endif 180 177 181 private: 178 182 -
trunk/Source/WebCore/page/ChromeClient.h
r272236 r272445 102 102 class HitTestResult; 103 103 class IntRect; 104 class MediaSessionMetadata;105 104 class NavigationAction; 106 105 class Node; -
trunk/Source/WebCore/platform/RemoteCommandListener.cpp
r261093 r272445 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 38 38 #endif 39 39 40 void RemoteCommandListener::scheduleSupportedCommandsUpdate() 41 { 42 if (!m_updateCommandsTask.hasPendingTask()) { 43 m_updateCommandsTask.scheduleTask([this] () { 44 updateSupportedCommands(); 45 }); 46 } 40 47 } 48 49 void RemoteCommandListener::addSupportedCommand(PlatformMediaSession::RemoteControlCommandType command) 50 { 51 m_registeredCommands.add(command); 52 scheduleSupportedCommandsUpdate(); 53 } 54 55 void RemoteCommandListener::removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType command) 56 { 57 m_registeredCommands.remove(command); 58 scheduleSupportedCommandsUpdate(); 59 } 60 61 } -
trunk/Source/WebCore/platform/RemoteCommandListener.h
r233650 r272445 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #define RemoteCommandListener_h 28 28 29 #include "DeferrableTask.h" 29 30 #include "PlatformMediaSession.h" 30 31 … … 46 47 virtual ~RemoteCommandListener() = default; 47 48 49 void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType); 50 void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType); 48 51 virtual void updateSupportedCommands() { } 52 void scheduleSupportedCommandsUpdate(); 49 53 50 54 RemoteCommandListenerClient& client() const { return m_client; } … … 52 56 protected: 53 57 RemoteCommandListenerClient& m_client; 58 59 using RemoteCommandsSet = HashSet<PlatformMediaSession::RemoteControlCommandType, WTF::IntHash<PlatformMediaSession::RemoteControlCommandType>, WTF::StrongEnumHashTraits<PlatformMediaSession::RemoteControlCommandType>>; 60 RemoteCommandsSet m_registeredCommands; 61 62 DeferrableTask<Timer> m_updateCommandsTask; 54 63 }; 55 64 -
trunk/Source/WebCore/platform/audio/NowPlayingInfo.h
r258024 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 33 33 struct NowPlayingInfo { 34 34 String title; 35 String artist; 36 String album; 35 37 String sourceApplicationIdentifier; 36 38 double duration { 0 }; … … 54 56 String title; 55 57 if (!decoder.decode(title)) 58 return { }; 59 60 String artist; 61 if (!decoder.decode(artist)) 62 return { }; 63 64 String album; 65 if (!decoder.decode(album)) 56 66 return { }; 57 67 … … 84 94 return { }; 85 95 86 return NowPlayingInfo { WTFMove(title), WTFMove( sourceApplicationIdentifier), duration, currentTime, supportsSeeking, uniqueIdentifier, isPlaying, allowsNowPlayingControlsVisibility };96 return NowPlayingInfo { WTFMove(title), WTFMove(artist), WTFMove(album), WTFMove(sourceApplicationIdentifier), duration, currentTime, supportsSeeking, uniqueIdentifier, isPlaying, allowsNowPlayingControlsVisibility }; 87 97 } 88 98 -
trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp
r271698 r272445 1 1 /* 2 * Copyright (C) 2014-20 15Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 94 94 MAKE_STATIC_STRING_IMPL("EndSeekingForwardCommand"), 95 95 MAKE_STATIC_STRING_IMPL("SeekToPlaybackPositionCommand"), 96 MAKE_STATIC_STRING_IMPL("SkipForwardCommand"), 97 MAKE_STATIC_STRING_IMPL("SkipBackwardCommand"), 98 MAKE_STATIC_STRING_IMPL("NextTrackCommand"), 99 MAKE_STATIC_STRING_IMPL("PreviousTrackCommand"), 96 100 }; 97 101 static_assert(!static_cast<size_t>(PlatformMediaSession::NoCommand), "PlatformMediaSession::NoCommand is not 0 as expected"); … … 105 109 static_assert(static_cast<size_t>(PlatformMediaSession::EndSeekingForwardCommand) == 8, "PlatformMediaSession::EndSeekingForwardCommand is not 8 as expected"); 106 110 static_assert(static_cast<size_t>(PlatformMediaSession::SeekToPlaybackPositionCommand) == 9, "PlatformMediaSession::SeekToPlaybackPositionCommand is not 9 as expected"); 111 static_assert(static_cast<size_t>(PlatformMediaSession::SkipForwardCommand) == 10, "PlatformMediaSession::SkipForwardCommand is not 10 as expected"); 112 static_assert(static_cast<size_t>(PlatformMediaSession::SkipBackwardCommand) == 11, "PlatformMediaSession::SkipBackwardCommand is not 11 as expected"); 113 static_assert(static_cast<size_t>(PlatformMediaSession::NextTrackCommand) == 12, "PlatformMediaSession::NextTrackCommand is not 12 as expected"); 114 static_assert(static_cast<size_t>(PlatformMediaSession::PreviousTrackCommand) == 13, "PlatformMediaSession::PreviousTrackCommand is not 13 as expected"); 107 115 ASSERT(static_cast<size_t>(command) < WTF_ARRAY_LENGTH(values)); 108 116 return values[static_cast<size_t>(command)]; -
trunk/Source/WebCore/platform/audio/PlatformMediaSession.h
r271643 r272445 1 1 /* 2 * Copyright (C) 2014-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 131 131 EndSeekingForwardCommand, 132 132 SeekToPlaybackPositionCommand, 133 SkipForwardCommand, 134 SkipBackwardCommand, 135 NextTrackCommand, 136 PreviousTrackCommand, 133 137 }; 134 138 bool canReceiveRemoteControlCommands() const; 135 v oid didReceiveRemoteControlCommand(RemoteControlCommandType, const RemoteCommandArgument* argument= nullptr);139 virtual void didReceiveRemoteControlCommand(RemoteControlCommandType, const RemoteCommandArgument* = nullptr); 136 140 bool supportsSeeking() const; 137 141 -
trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h
r271643 r272445 1 1 /* 2 * Copyright (C) 2013-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2013-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 153 153 bool hasNoSession() const; 154 154 155 virtual void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType) { }; 156 virtual void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType) { }; 157 155 158 protected: 156 159 friend class PlatformMediaSession; -
trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h
r266121 r272445 1 1 /* 2 * Copyright (C) 2020 Apple Inc. All rights reserved.2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 85 85 GenericTaskQueue<Timer>& taskQueue() { return m_taskQueue; } 86 86 87 void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType) final; 88 void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType) final; 89 87 90 private: 88 91 #if !RELEASE_LOG_DISABLED -
trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
r270943 r272445 1 1 /* 2 * Copyright (C) 2013-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2013-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 154 154 { 155 155 m_taskQueue.enqueueTask([this] () mutable { 156 if (m_remoteCommandListener) 157 m_remoteCommandListener->updateSupportedCommands(); 158 156 159 updateNowPlayingInfo(); 157 160 … … 233 236 void MediaSessionManagerCocoa::sessionCanProduceAudioChanged() 234 237 { 238 ALWAYS_LOG(LOGIDENTIFIER); 235 239 PlatformMediaSessionManager::sessionCanProduceAudioChanged(); 236 240 scheduleSessionStatusUpdate(); 241 } 242 243 void MediaSessionManagerCocoa::addSupportedCommand(PlatformMediaSession::RemoteControlCommandType command) 244 { 245 if (m_remoteCommandListener) 246 m_remoteCommandListener->addSupportedCommand(command); 247 } 248 249 void MediaSessionManagerCocoa::removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType command) 250 { 251 if (m_remoteCommandListener) 252 m_remoteCommandListener->removeSupportedCommand(command); 237 253 } 238 254 … … 261 277 auto info = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 262 278 279 if (!nowPlayingInfo.artist.isEmpty()) 280 CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoArtist, nowPlayingInfo.artist.createCFString().get()); 281 282 if (!nowPlayingInfo.album.isEmpty()) 283 CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoAlbum, nowPlayingInfo.album.createCFString().get()); 284 263 285 if (!nowPlayingInfo.title.isEmpty()) 264 286 CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoTitle, nowPlayingInfo.title.createCFString().get()); -
trunk/Source/WebCore/platform/mac/MediaRemoteSoftLink.h
r261110 r272445 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 59 59 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoTitle, CFStringRef); 60 60 #define kMRMediaRemoteNowPlayingInfoTitle get_MediaRemote_kMRMediaRemoteNowPlayingInfoTitle() 61 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtist, CFStringRef); 62 #define kMRMediaRemoteNowPlayingInfoArtist get_MediaRemote_kMRMediaRemoteNowPlayingInfoArtist() 63 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoAlbum, CFStringRef); 64 #define kMRMediaRemoteNowPlayingInfoAlbum get_MediaRemote_kMRMediaRemoteNowPlayingInfoAlbum() 65 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtworkData, CFStringRef); 66 #define kMRMediaRemoteNowPlayingInfoArtworkData get_MediaRemote_kMRMediaRemoteNowPlayingInfoArtworkData() 67 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtworkMIMEType, CFStringRef); 68 #define kMRMediaRemoteNowPlayingInfoArtworkMIMEType get_MediaRemote_kMRMediaRemoteNowPlayingInfoArtworkMIMEType() 61 69 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoDuration, CFStringRef); 62 70 #define kMRMediaRemoteNowPlayingInfoDuration get_MediaRemote_kMRMediaRemoteNowPlayingInfoDuration() … … 69 77 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoUniqueIdentifier, CFStringRef); 70 78 #define kMRMediaRemoteNowPlayingInfoUniqueIdentifier get_MediaRemote_kMRMediaRemoteNowPlayingInfoUniqueIdentifier() 79 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, MediaRemote, kMRMediaRemoteOptionSkipInterval, CFStringRef); 80 #define kMRMediaRemoteOptionSkipInterval get_MediaRemote_kMRMediaRemoteOptionSkipInterval() 71 81 72 82 #if PLATFORM(IOS_FAMILY) -
trunk/Source/WebCore/platform/mac/MediaRemoteSoftLink.mm
r271982 r272445 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 45 45 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebCore, MediaRemote, MRMediaRemoteSetParentApplication, void, (MROriginRef origin, CFStringRef parentAppDisplayID), (origin, parentAppDisplayID)) 46 46 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoTitle, CFStringRef); 47 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtist, CFStringRef); 48 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoAlbum, CFStringRef); 49 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtworkData, CFStringRef); 50 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoArtworkMIMEType, CFStringRef); 47 51 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoDuration, CFStringRef); 48 52 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoElapsedTime, CFStringRef); … … 50 54 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteOptionPlaybackPosition, CFStringRef); 51 55 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteNowPlayingInfoUniqueIdentifier, CFStringRef); 56 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, MediaRemote, kMRMediaRemoteOptionSkipInterval, CFStringRef); 52 57 53 58 #if PLATFORM(IOS_FAMILY) -
trunk/Source/WebCore/platform/mac/RemoteCommandListenerMac.h
r232613 r272445 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 40 40 41 41 protected: 42 void updateSupportedCommands() override;42 void updateSupportedCommands() final; 43 43 44 44 void* m_commandHandler { nullptr }; 45 46 const RemoteCommandsSet& defaultCommands(); 47 RemoteCommandsSet m_currentCommands; 48 bool m_supportsSeeking { false }; 45 49 }; 46 50 -
trunk/Source/WebCore/platform/mac/RemoteCommandListenerMac.mm
r261110 r272445 1 1 /* 2 * Copyright (C) 2016 Apple Inc. All rights reserved.2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 36 36 namespace WebCore { 37 37 38 static Optional<MRMediaRemoteCommand> mediaRemoteCommandForPlatformCommand(PlatformMediaSession::RemoteControlCommandType command) 39 { 40 static const auto commandMap = makeNeverDestroyed([] { 41 using CommandToActionMap = HashMap<PlatformMediaSession::RemoteControlCommandType, MRMediaRemoteCommand, WTF::IntHash<PlatformMediaSession::RemoteControlCommandType>, WTF::StrongEnumHashTraits<PlatformMediaSession::RemoteControlCommandType>>; 42 43 return CommandToActionMap { 44 { PlatformMediaSession::PlayCommand, MRMediaRemoteCommandPlay }, 45 { PlatformMediaSession::PauseCommand, MRMediaRemoteCommandPause }, 46 { PlatformMediaSession::StopCommand, MRMediaRemoteCommandStop }, 47 { PlatformMediaSession::TogglePlayPauseCommand, MRMediaRemoteCommandTogglePlayPause }, 48 { PlatformMediaSession::BeginSeekingBackwardCommand, MRMediaRemoteCommandBeginRewind }, 49 { PlatformMediaSession::EndSeekingBackwardCommand, MRMediaRemoteCommandEndRewind }, 50 { PlatformMediaSession::BeginSeekingForwardCommand, MRMediaRemoteCommandBeginFastForward }, 51 { PlatformMediaSession::EndSeekingForwardCommand, MRMediaRemoteCommandEndFastForward }, 52 { PlatformMediaSession::SeekToPlaybackPositionCommand, MRMediaRemoteCommandSeekToPlaybackPosition }, 53 { PlatformMediaSession::SkipForwardCommand, MRMediaRemoteCommandSkipForward }, 54 { PlatformMediaSession::SkipBackwardCommand, MRMediaRemoteCommandSkipBackward }, 55 { PlatformMediaSession::NextTrackCommand, MRMediaRemoteCommandNextTrack }, 56 { PlatformMediaSession::PreviousTrackCommand, MRMediaRemoteCommandPreviousTrack }, 57 }; 58 }()); 59 60 auto it = commandMap.get().find(command); 61 if (it != commandMap.get().end()) 62 return { it->value }; 63 64 return { }; 65 } 66 38 67 std::unique_ptr<RemoteCommandListener> RemoteCommandListener::create(RemoteCommandListenerClient& client) 39 68 { 40 69 return makeUnique<RemoteCommandListenerMac>(client); 70 } 71 72 const RemoteCommandListener::RemoteCommandsSet& RemoteCommandListenerMac::defaultCommands() 73 { 74 static NeverDestroyed<RemoteCommandsSet> commands(std::initializer_list<PlatformMediaSession::RemoteControlCommandType> { 75 PlatformMediaSession::PlayCommand, 76 PlatformMediaSession::PauseCommand, 77 PlatformMediaSession::TogglePlayPauseCommand, 78 PlatformMediaSession::BeginSeekingForwardCommand, 79 PlatformMediaSession::EndSeekingForwardCommand, 80 PlatformMediaSession::BeginSeekingBackwardCommand, 81 PlatformMediaSession::EndSeekingBackwardCommand, 82 PlatformMediaSession::SeekToPlaybackPositionCommand, 83 PlatformMediaSession::SkipForwardCommand, 84 PlatformMediaSession::SkipBackwardCommand, 85 }); 86 87 return commands; 88 } 89 90 static bool isSeekCommand(PlatformMediaSession::RemoteControlCommandType command) 91 { 92 return command == PlatformMediaSession::SeekToPlaybackPositionCommand 93 || command == PlatformMediaSession::SkipForwardCommand 94 || command == PlatformMediaSession::SkipBackwardCommand 95 || command == PlatformMediaSession::BeginSeekingForwardCommand 96 || command == PlatformMediaSession::BeginSeekingBackwardCommand; 41 97 } 42 98 … … 46 102 return; 47 103 48 static const MRMediaRemoteCommand supportedCommands[] = {49 MRMediaRemoteCommandPlay,50 MRMediaRemoteCommandPause,51 MRMediaRemoteCommandTogglePlayPause, 52 MRMediaRemoteCommandBeginFastForward,53 MRMediaRemoteCommandEndFastForward,54 MRMediaRemoteCommandBeginRewind,55 MRMediaRemoteCommandEndRewind,56 MRMediaRemoteCommandSeekToPlaybackPosition, 57 };58 59 auto commandInfoArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, sizeof(supportedCommands) / sizeof(MRMediaRemoteCommand), &kCFTypeArrayCallBacks));60 61 for (auto command : supportedCommands) { 104 auto& supportedCommands = !m_registeredCommands.isEmpty() ? m_registeredCommands : defaultCommands(); 105 if (m_supportsSeeking == client().supportsSeeking() && m_currentCommands == supportedCommands) 106 return; 107 108 auto commandInfoArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, supportedCommands.size(), &kCFTypeArrayCallBacks)); 109 for (auto platformCommand : supportedCommands) { 110 if (isSeekCommand(platformCommand) && !client().supportsSeeking()) 111 continue; 112 113 auto command = mediaRemoteCommandForPlatformCommand(platformCommand); 114 ASSERT(command); 115 if (!command) 116 continue; 117 62 118 auto commandInfo = adoptCF(MRMediaRemoteCommandInfoCreate(kCFAllocatorDefault)); 63 MRMediaRemoteCommandInfoSetCommand(commandInfo.get(), command );119 MRMediaRemoteCommandInfoSetCommand(commandInfo.get(), command.value()); 64 120 MRMediaRemoteCommandInfoSetEnabled(commandInfo.get(), true); 65 121 CFArrayAppendValue(commandInfoArray.get(), commandInfo.get()); 66 122 } 67 123 68 auto seekCommandInfo = adoptCF(MRMediaRemoteCommandInfoCreate(kCFAllocatorDefault));69 MRMediaRemoteCommandInfoSetCommand(seekCommandInfo.get(), MRMediaRemoteCommandSeekToPlaybackPosition);70 MRMediaRemoteCommandInfoSetEnabled(seekCommandInfo.get(), client().supportsSeeking());71 CFArrayAppendValue(commandInfoArray.get(), seekCommandInfo.get());72 73 124 MRMediaRemoteSetSupportedCommands(commandInfoArray.get(), MRMediaRemoteGetLocalOrigin(), nullptr, nullptr); 125 m_currentCommands = supportedCommands; 126 m_supportsSeeking = client().supportsSeeking(); 74 127 } 75 128 … … 80 133 return; 81 134 82 updateSupportedCommands();135 scheduleSupportedCommandsUpdate(); 83 136 84 137 auto weakThis = makeWeakPtr(*this); … … 89 142 PlatformMediaSession::RemoteControlCommandType platformCommand { PlatformMediaSession::NoCommand }; 90 143 PlatformMediaSession::RemoteCommandArgument argument { 0 }; 144 PlatformMediaSession::RemoteCommandArgument* argumentPtr = nullptr; 91 145 MRMediaRemoteCommandHandlerStatus status = MRMediaRemoteCommandHandlerStatusSuccess; 92 146 … … 129 183 130 184 CFNumberGetValue(positionRef, kCFNumberDoubleType, &argument.asDouble); 185 argumentPtr = &argument; 131 186 platformCommand = PlatformMediaSession::SeekToPlaybackPositionCommand; 132 187 break; 133 188 } 189 case MRMediaRemoteCommandSkipForward: 190 case MRMediaRemoteCommandSkipBackward: 191 if (!client.supportsSeeking()) { 192 status = MRMediaRemoteCommandHandlerStatusCommandFailed; 193 break; 194 } 195 196 if (auto positionRef = static_cast<CFNumberRef>(CFDictionaryGetValue(options, kMRMediaRemoteOptionSkipInterval))) { 197 CFNumberGetValue(positionRef, kCFNumberDoubleType, &argument.asDouble); 198 argumentPtr = &argument; 199 } 200 201 platformCommand = (command == MRMediaRemoteCommandSkipForward) ? PlatformMediaSession::SkipForwardCommand : PlatformMediaSession::SkipBackwardCommand; 202 break; 203 case MRMediaRemoteCommandNextTrack: 204 platformCommand = PlatformMediaSession::NextTrackCommand; 205 break; 206 case MRMediaRemoteCommandPreviousTrack: 207 platformCommand = PlatformMediaSession::PreviousTrackCommand; 208 break; 134 209 default: 135 210 LOG(Media, "RemoteCommandListenerMac::RemoteCommandListenerMac - command %u not supported!", command); … … 138 213 139 214 if (weakThis && status != MRMediaRemoteCommandHandlerStatusCommandFailed) 140 weakThis->m_client.didReceiveRemoteControlCommand(platformCommand, &argument);215 weakThis->m_client.didReceiveRemoteControlCommand(platformCommand, argumentPtr); 141 216 142 217 completion((__bridge CFArrayRef)@[@(status)]); -
trunk/Source/WebKit/ChangeLog
r272434 r272445 1 2021-02-05 Eric Carlson <eric.carlson@apple.com> 2 3 [Mac] Connect MediaSession with MediaRemote and NowPlaying 4 https://bugs.webkit.org/show_bug.cgi?id=221431 5 <rdar://problem/74000363> 6 7 Reviewed by Jer Noble. 8 9 Add a private preference so the new MediaSession API test can enable the feature. 10 11 * UIProcess/API/Cocoa/WKPreferences.mm: 12 (-[WKPreferences _mediaSessionEnabled]): 13 (-[WKPreferences _setMediaSessionEnabled:]): 14 * UIProcess/API/Cocoa/WKPreferencesPrivate.h: 15 1 16 2021-02-05 Youenn Fablet <youenn@apple.com> 2 17 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
r271219 r272445 1480 1480 } 1481 1481 1482 - (BOOL)_mediaSessionEnabled 1483 { 1484 return _preferences->mediaSessionEnabled(); 1485 } 1486 1487 - (void)_setMediaSessionEnabled:(BOOL)mediaSessionEnabled 1488 { 1489 _preferences->setMediaSessionEnabled(mediaSessionEnabled); 1490 } 1491 1482 1492 @end 1483 1493 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
r271813 r272445 171 171 @property (nonatomic, setter=_setPrivateClickMeasurementEnabled:) BOOL _privateClickMeasurementEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 172 172 @property (nonatomic, setter=_setPitchCorrectionAlgorithm:) _WKPitchCorrectionAlgorithm _pitchCorrectionAlgorithm WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 173 @property (nonatomic, setter=_setMediaSessionEnabled:) BOOL _mediaSessionEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 173 174 174 175 #if !TARGET_OS_IPHONE -
trunk/Tools/ChangeLog
r272436 r272445 1 2021-02-05 Eric Carlson <eric.carlson@apple.com> 2 3 [Mac] Connect MediaSession with MediaRemote and NowPlaying 4 https://bugs.webkit.org/show_bug.cgi?id=221431 5 <rdar://problem/74000363> 6 7 Reviewed by Jer Noble. 8 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 10 * TestWebKitAPI/Tests/WebKitCocoa/MediaSession.mm: Added. 11 (TestWebKitAPI::MediaSessionTest::webView): 12 (TestWebKitAPI::MediaSessionTest::webViewPid): 13 (TestWebKitAPI::MediaSessionTest::getNowPlayingClient): 14 (TestWebKitAPI::MediaSessionTest::getNowPlayingClientPid): 15 (TestWebKitAPI::MediaSessionTest::loadPageAndBecomeNowPlaying): 16 (TestWebKitAPI::MediaSessionTest::runScriptWithUserGesture): 17 (TestWebKitAPI::MediaSessionTest::play): 18 (TestWebKitAPI::MediaSessionTest::pause): 19 (TestWebKitAPI::MediaSessionTest::sendMediaRemoteCommand): 20 (TestWebKitAPI::MediaSessionTest::sendMediaRemoteSeekCommand): 21 (TestWebKitAPI::MediaSessionTest::listenForEventMessages): 22 (TestWebKitAPI::MediaSessionTest::eventListenerWasCalled): 23 (TestWebKitAPI::MediaSessionTest::waitForEventListenerToBeCalled): 24 (TestWebKitAPI::MediaSessionTest::listenForSessionHandlerMessages): 25 (TestWebKitAPI::MediaSessionTest::sessionHandlerWasCalled): 26 (TestWebKitAPI::MediaSessionTest::waitForSessionHandlerToBeCalled): 27 (TestWebKitAPI::MediaSessionTest::getSupportedCommands): 28 (TestWebKitAPI::TEST_F): 29 * TestWebKitAPI/Tests/WebKitCocoa/media-remote.html: Added. 30 1 31 2021-02-05 Sam Weinig <weinig@apple.com> 2 32 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r271969 r272445 57 57 076E507F1F4513D6006E9F5A /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076E507E1F45031E006E9F5A /* Logging.cpp */; }; 58 58 077A5AF3230638A600A7105C /* AccessibilityTestPlugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0746645822FF630500E3451A /* AccessibilityTestPlugin.mm */; }; 59 0794740D25CA0BDE00C597EB /* MediaSession.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0794740C25CA0BDE00C597EB /* MediaSession.mm */; }; 60 0794742D25CB33FD00C597EB /* media-remote.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0794742C25CB33B000C597EB /* media-remote.html */; }; 59 61 0799C3491EBA2D7B003B7532 /* UserMediaDisabled.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07EDEFAC1EB9400C00D43292 /* UserMediaDisabled.mm */; }; 60 62 0799C34B1EBA3301003B7532 /* disableGetUserMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0799C34A1EBA32F4003B7532 /* disableGetUserMedia.html */; }; … … 1560 1562 7772ECE122FE06C60009A799 /* many-same-origin-iframes.html in Copy Resources */, 1561 1563 CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */, 1564 0794742D25CB33FD00C597EB /* media-remote.html in Copy Resources */, 1562 1565 CDA3159A1ED548F1009F60D3 /* MediaPlaybackSleepAssertion.html in Copy Resources */, 1563 1566 CDC9442F1EF205D60059C3C4 /* mediastreamtrack-detached.html in Copy Resources */, … … 1723 1726 0766DD1F1A5AD5200023E3BB /* PendingAPIRequestURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PendingAPIRequestURL.cpp; sourceTree = "<group>"; }; 1724 1727 076E507E1F45031E006E9F5A /* Logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Logging.cpp; sourceTree = "<group>"; }; 1728 0794740C25CA0BDE00C597EB /* MediaSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaSession.mm; sourceTree = "<group>"; }; 1729 0794742C25CB33B000C597EB /* media-remote.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "media-remote.html"; sourceTree = "<group>"; }; 1725 1730 0799C34A1EBA32F4003B7532 /* disableGetUserMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = disableGetUserMedia.html; sourceTree = "<group>"; }; 1726 1731 07C046C91E42573E007201E7 /* CARingBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CARingBuffer.cpp; sourceTree = "<group>"; }; … … 3360 3365 CD0370E224A44B7A00BA3CAE /* MediaLoading.mm */, 3361 3366 07EF76D42540FC060053ED53 /* MediaMutedState.mm */, 3367 0794740C25CA0BDE00C597EB /* MediaSession.mm */, 3362 3368 51BE9E652376089500B4E117 /* MediaType.mm */, 3363 3369 5165FE03201EE617009F7EC3 /* MessagePortProviders.mm */, … … 3923 3929 46C519E41D35629600DAA51A /* LocalStorageNullEntries.localstorage-shm */, 3924 3930 7A6A2C711DCCFB0200C0D085 /* LocalStorageQuirkEnabled.html */, 3931 0794742C25CB33B000C597EB /* media-remote.html */, 3925 3932 9B59F12920340854009E63D5 /* mso-list-compat-mode.html */, 3926 3933 9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */, … … 5384 5391 07EF76D52540FC060053ED53 /* MediaMutedState.mm in Sources */, 5385 5392 CDA315981ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm in Sources */, 5393 0794740D25CA0BDE00C597EB /* MediaSession.mm in Sources */, 5386 5394 CDC9442E1EF1FC080059C3C4 /* MediaStreamTrackDetached.mm in Sources */, 5387 5395 51BE9E662376089F00B4E117 /* MediaType.mm in Sources */, … … 5422 5430 CEBCA12F1E3A660100C73293 /* OverrideContentSecurityPolicy.mm in Sources */, 5423 5431 2DA2586F225C67DC00B45C1C /* OverrideViewportArguments.mm in Sources */, 5432 953ABB3525C0D682004C8B73 /* PageExtendedBackgroundColor.mm in Sources */, 5424 5433 7CCB4DA91C83AE7300CC6918 /* PageGroup.cpp in Sources */, 5425 5434 7CCE7F071A411AE600447C4C /* PageLoadBasic.cpp in Sources */, … … 5465 5474 FEC2A85624CEB65F00ADBC35 /* PropertySlot.cpp in Sources */, 5466 5475 7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */, 5467 953ABB3525C0D682004C8B73 /* PageExtendedBackgroundColor.mm in Sources */,5468 5476 5CFACF65226FD2DC0056C7D0 /* Proxy.mm in Sources */, 5469 5477 041A1E34216FFDBC00789E0A /* PublicSuffix.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.