Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / media / mediacontrol / ContentPlaybackController.h
bloba2b474e492a4a0857e8ba84c04c34204c9f41dbf
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/. */
5 #ifndef DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_
6 #define DOM_MEDIA_MEDIACONTROL_CONTENTPLAYBACKCONTROLLER_H_
8 #include "MediaControlKeySource.h"
9 #include "nsPIDOMWindow.h"
10 #include "mozilla/dom/BrowsingContext.h"
12 namespace mozilla::dom {
14 class MediaSession;
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].
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.
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].
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
36 class MOZ_STACK_CLASS ContentPlaybackController {
37 public:
38 explicit ContentPlaybackController(BrowsingContext* aContext);
39 ~ContentPlaybackController() = default;
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);
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;
63 RefPtr<BrowsingContext> mBC;
66 class ContentMediaControlKeyHandler {
67 public:
68 static void HandleMediaControlAction(BrowsingContext* aContext,
69 const MediaControlAction& aAction);
72 } // namespace mozilla::dom
74 #endif