Bug 1656642 - part2 : prevent to start controller for non-playable media even if it enters fullscreen/PIP mode. r=chunmin

When a media without src or with error enters fullscreen or PIP mode, we don't want to control it. Therefore, we shouldn't start the listener for it.

In addition, updating PIP/fullscreen state no matter the listener starts or not. See following example.

1. Play a media and it enter PIP/fullscreen (it would update `state=true`)
2. abort the current src (that would stop the listener)
3. leave PIP/fullscreen (in this case, we don't have src, so the listener won't start, but we still need to update the `state` to `false`)

Differential Revision: https://phabricator.services.mozilla.com/D85785
This commit is contained in:
alwu 2020-08-13 19:16:18 +00:00
Родитель 4b67a9b41d
Коммит 917df3ddbb
2 изменённых файлов: 21 добавлений и 4 удалений

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

@ -6656,9 +6656,11 @@ void HTMLMediaElement::NotifyFullScreenChanged() {
const bool isInFullScreen = IsInFullScreen();
if (isInFullScreen) {
StartMediaControlKeyListenerIfNeeded();
MOZ_ASSERT(mMediaControlKeyListener->IsStarted(),
"Failed to start the listener when entering fullscreen!");
if (!mMediaControlKeyListener->IsStarted()) {
MEDIACONTROL_LOG("Failed to start the listener when entering fullscreen");
}
}
// Updating controller fullscreen state no matter the listener starts or not.
BrowsingContext* bc = OwnerDoc()->GetBrowsingContext();
if (RefPtr<IMediaInfoUpdater> updater = ContentMediaAgent::Get(bc)) {
updater->NotifyMediaFullScreenState(bc->Id(), isInFullScreen);
@ -7919,7 +7921,16 @@ bool HTMLMediaElement::IsInFullScreen() const {
return State().HasState(NS_EVENT_STATE_FULLSCREEN);
}
bool HTMLMediaElement::IsPlayable() const {
return (mDecoder || mSrcStream) && !HasError();
}
bool HTMLMediaElement::ShouldStartMediaControlKeyListener() const {
if (!IsPlayable()) {
MEDIACONTROL_LOG("Not start listener because media is not playable");
return false;
}
if (IsBeingUsedInPictureInPictureMode()) {
MEDIACONTROL_LOG("Start listener because of being used in PiP mode");
return true;
@ -7965,8 +7976,10 @@ void HTMLMediaElement::UpdateMediaControlAfterPictureInPictureModeChanged() {
// When media enters PIP mode, we should ensure that the listener has been
// started because we always want to control PIP video.
StartMediaControlKeyListenerIfNeeded();
MOZ_ASSERT(mMediaControlKeyListener->IsStarted(),
"Failed to start listener when entering PIP mode");
if (!mMediaControlKeyListener->IsStarted()) {
MEDIACONTROL_LOG("Failed to start listener when entering PIP mode");
}
// Updating controller PIP state no matter the listener starts or not.
mMediaControlKeyListener->SetPictureInPictureModeEnabled(true);
} else {
mMediaControlKeyListener->SetPictureInPictureModeEnabled(false);

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

@ -1932,6 +1932,10 @@ class HTMLMediaElement : public nsGenericHTMLElement,
MozPromiseRequestHolder<ResumeDelayedPlaybackAgent::ResumePromise>
mResumePlaybackRequest;
// Return true if we have already a decoder or a src stream and don't have any
// error.
bool IsPlayable() const;
// Return true if the media qualifies for being controlled by media control
// keys.
bool ShouldStartMediaControlKeyListener() const;