Bug 1582569 - part1 : implement 'skipad'. r=chunmin,webidl,peterv

Implement `skipad` action.

https://w3c.github.io/mediasession/#dom-mediasessionaction-skipad

Differential Revision: https://phabricator.services.mozilla.com/D82579
This commit is contained in:
alwu 2020-07-10 18:59:31 +00:00
Родитель 08fb73acf9
Коммит 8db4dcbd7c
7 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -15,6 +15,7 @@ enum MediaControlKey {
"nexttrack",
"seekbackward",
"seekforward",
"skipad",
"stop",
};

Просмотреть файл

@ -108,9 +108,7 @@ void ContentPlaybackController::NextTrack() {
}
void ContentPlaybackController::SkipAd() {
// TODO : use media session's action handler if it exists. MediaSessionAction
// doesn't support `skipad` yet.
return;
NotifyMediaSessionWhenActionIsSupported(MediaSessionAction::Skipad);
}
void ContentPlaybackController::Stop() {
@ -156,6 +154,9 @@ void ContentMediaControlKeyHandler::HandleMediaControlKey(
case MediaControlKey::Seekforward:
controller.SeekForward();
return;
case MediaControlKey::Skipad:
controller.SkipAd();
return;
default:
MOZ_ASSERT_UNREACHABLE("Invalid event.");
};

Просмотреть файл

@ -66,6 +66,9 @@ void MediaControlKeyHandler::OnKeyPressed(MediaControlKey aKey) {
case MediaControlKey::Seekforward:
controller->SeekForward();
return;
case MediaControlKey::Skipad:
controller->SkipAd();
return;
case MediaControlKey::Stop:
controller->Stop();
return;

Просмотреть файл

@ -35,6 +35,8 @@ inline const char* ToMediaControlKeyStr(MediaControlKey aKey) {
return "Seek backward";
case MediaControlKey::Seekforward:
return "Seek forward";
case MediaControlKey::Skipad:
return "Skip Ad";
case MediaControlKey::Stop:
return "Stop";
default:
@ -57,6 +59,8 @@ inline const char* ToMediaSessionActionStr(MediaSessionAction aAction) {
return "previous track";
case MediaSessionAction::Nexttrack:
return "next track";
case MediaSessionAction::Skipad:
return "skip ad";
default:
MOZ_ASSERT(aAction == MediaSessionAction::Stop);
return "stop";
@ -78,6 +82,8 @@ inline MediaControlKey ConvertMediaSessionActionToControlKey(
return MediaControlKey::Previoustrack;
case MediaSessionAction::Nexttrack:
return MediaControlKey::Nexttrack;
case MediaSessionAction::Skipad:
return MediaControlKey::Skipad;
default:
MOZ_ASSERT(aAction == MediaSessionAction::Stop);
return MediaControlKey::Stop;

Просмотреть файл

@ -116,6 +116,11 @@ void MediaController::SeekForward() {
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Seekforward);
}
void MediaController::SkipAd() {
LOG("Skip Ad");
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Skipad);
}
void MediaController::Stop() {
LOG("Stop");
UpdateMediaControlKeyToContentMediaIfNeeded(MediaControlKey::Stop);

Просмотреть файл

@ -39,6 +39,7 @@ class IMediaController {
virtual void NextTrack() = 0;
virtual void SeekBackward() = 0;
virtual void SeekForward() = 0;
virtual void SkipAd() = 0;
// Return the ID of the top level browsing context within a tab.
virtual uint64_t Id() const = 0;
@ -97,6 +98,8 @@ class MediaController final : public DOMEventTargetHelper,
void NextTrack() override;
void SeekBackward() override;
void SeekForward() override;
void SkipAd() override;
uint64_t Id() const override;
bool IsAudible() const override;
bool IsPlaying() const override;

Просмотреть файл

@ -13,7 +13,7 @@ enum MediaSessionPlaybackState {
"playing"
};
// TODO: Implement the missing seekto (bug 1621403) and skipad (bug 1582569) actions
// TODO: Implement the missing seekto (bug 1621403)
enum MediaSessionAction {
"play",
"pause",
@ -21,6 +21,7 @@ enum MediaSessionAction {
"seekforward",
"previoustrack",
"nexttrack",
"skipad",
"stop",
};