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
{
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
32 * [1] https://w3c.github.io/mediasession/#enumdef-mediasessionaction
34 * https://w3c.github.io/mediasession/#ref-for-active-media-session%E2%91%A1%E2%93%AA
36 class MOZ_STACK_CLASS ContentPlaybackController
{
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();
45 void SeekBackward(double aSeekOffset
);
46 void SeekForward(double aSeekOffset
);
51 void SeekTo(double aSeekTime
, bool aFastSeek
);
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
{
68 static void HandleMediaControlAction(BrowsingContext
* aContext
,
69 const MediaControlAction
& aAction
);
72 } // namespace mozilla::dom