зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1634494 - part5 : not always call `play` default handler r=chunmin
`play` default handler is a special case, we don't want to run it arbitrarily in order to get a better user experience. If we have an active media session, the play should only be triggered on that session, which is something a user really wants to resume. Therefore, adding some restrictions to call default play handler only when (1) We don't have an active media session (If we have one, the play action handler should only be triggered on that session) (2) Active media session without setting action handler for `play` Differential Revision: https://phabricator.services.mozilla.com/D88107
This commit is contained in:
Родитель
6ea69ac823
Коммит
82bb886bd9
|
@ -75,6 +75,11 @@ bool ContentPlaybackController::IsMediaSessionActionSupported(
|
|||
: false;
|
||||
}
|
||||
|
||||
Maybe<uint64_t> ContentPlaybackController::GetActiveMediaSessionId() const {
|
||||
RefPtr<WindowContext> wc = mBC->GetTopWindowContext();
|
||||
return wc ? wc->GetActiveMediaSessionContextId() : Nothing();
|
||||
}
|
||||
|
||||
void ContentPlaybackController::Focus() {
|
||||
// Focus is not part of the MediaSession standard, so always use the
|
||||
// default behavior and focus the window currently playing media.
|
||||
|
@ -85,9 +90,17 @@ void ContentPlaybackController::Focus() {
|
|||
|
||||
void ContentPlaybackController::Play() {
|
||||
const MediaSessionAction action = MediaSessionAction::Play;
|
||||
RefPtr<MediaSession> session = GetMediaSession();
|
||||
if (IsMediaSessionActionSupported(action)) {
|
||||
NotifyMediaSession(action);
|
||||
} else {
|
||||
}
|
||||
// We don't want to arbitrarily call play default handler, because we want to
|
||||
// resume the frame which a user really gets interest in, not all media in the
|
||||
// same page. Therefore, we would only call default handler for `play` when
|
||||
// (1) We don't have an active media session (If we have one, the play action
|
||||
// handler should only be triggered on that session)
|
||||
// (2) Active media session without setting action handler for `play`
|
||||
else if (!GetActiveMediaSessionId() || (session && session->IsActive())) {
|
||||
NotifyContentMediaControlKeyReceiver(MediaControlKey::Play);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ class MOZ_STACK_CLASS ContentPlaybackController {
|
|||
void NotifyMediaSession(const MediaSessionActionDetails& aDetails);
|
||||
void NotifyMediaSessionWhenActionIsSupported(MediaSessionAction aAction);
|
||||
bool IsMediaSessionActionSupported(MediaSessionAction aAction) const;
|
||||
Maybe<uint64_t> GetActiveMediaSessionId() const;
|
||||
MediaSession* GetMediaSession() const;
|
||||
|
||||
RefPtr<BrowsingContext> mBC;
|
||||
|
|
Загрузка…
Ссылка в новой задаче