ContentPlaybackController.h (2742B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_ 6 #define DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_ 7 8 #include "MediaControlKeySource.h" 9 #include "mozilla/dom/BrowsingContext.h" 10 #include "nsPIDOMWindow.h" 11 12 namespace mozilla::dom { 13 14 class MediaSession; 15 16 /** 17 * This interface is used to handle different playback control actions in the 18 * content process. Most of the methods are designed based on the 19 * MediaSessionAction values, which are defined in the media session spec [1]. 20 * 21 * The reason we need that is to explicitly separate the implementation from all 22 * different defined methods. If we want to add a new method in the future, we 23 * can do that without modifying other methods. 24 * 25 * If the active media session has a corresponding MediaSessionActionHandler, 26 * then we would invoke it, or we would do nothing. However, for certain 27 * actions, such as `play`, `pause` and `stop`, we have default action handling 28 * in order to control playback correctly even if the website doesn't use media 29 * session at all or the media session doesn't have correspending action handler 30 * [2]. 31 * 32 * [1] https://w3c.github.io/mediasession/#enumdef-mediasessionaction 33 * [2] 34 * https://w3c.github.io/mediasession/#ref-for-active-media-session%E2%91%A1%E2%93%AA 35 */ 36 class MOZ_STACK_CLASS ContentPlaybackController { 37 public: 38 explicit ContentPlaybackController(BrowsingContext* aContext); 39 ~ContentPlaybackController() = default; 40 41 // TODO: Convert Focus() to MOZ_CAN_RUN_SCRIPT 42 MOZ_CAN_RUN_SCRIPT_BOUNDARY void Focus(); 43 void Play(); 44 void Pause(); 45 void SeekBackward(double aSeekOffset); 46 void SeekForward(double aSeekOffset); 47 void PreviousTrack(); 48 void NextTrack(); 49 void SkipAd(); 50 void Stop(); 51 void SeekTo(double aSeekTime, bool aFastSeek); 52 53 private: 54 void NotifyContentMediaControlKeyReceiver( 55 MediaControlKey aKey, Maybe<SeekDetails> aDetails = Nothing()); 56 void NotifyMediaSession(MediaSessionAction aAction); 57 void NotifyMediaSession(const MediaSessionActionDetails& aDetails); 58 void NotifyMediaSessionWhenActionIsSupported(MediaSessionAction aAction); 59 bool IsMediaSessionActionSupported(MediaSessionAction aAction) const; 60 Maybe<uint64_t> GetActiveMediaSessionId() const; 61 MediaSession* GetMediaSession() const; 62 63 RefPtr<BrowsingContext> mBC; 64 }; 65 66 class ContentMediaControlKeyHandler { 67 public: 68 static void HandleMediaControlAction(BrowsingContext* aContext, 69 const MediaControlAction& aAction); 70 }; 71 72 } // namespace mozilla::dom 73 74 #endif