Bug 1623486 - part4 : update Picture-in-Picture mode status from media element. r=chunmin,padenot

Video element can start the Picture-in-Picture mode **BEFORE** or **AFTER** we start the listener for the media cotrol, so we have to ensure we always propagate this information to the chrome process via `ContentMediaAgent`.

Differential Revision: https://phabricator.services.mozilla.com/D67712
This commit is contained in:
alwu
2020-04-01 23:04:58 +00:00
parent 024a6061d8
commit e7db5cbc07
3 changed files with 37 additions and 1 deletions

View File

@@ -472,6 +472,17 @@ class HTMLMediaElement::MediaControlEventListener final
}
}
void SetPictureInPictureModeEnabled(bool aIsEnabled) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsStarted());
if (mIsPictureInPictureEnabled == aIsEnabled) {
return;
}
mIsPictureInPictureEnabled = aIsEnabled;
mControlAgent->NotifyPictureInPictureModeChanged(
this, mIsPictureInPictureEnabled);
}
void OnKeyPressed(MediaControlKeysEvent aEvent) override {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsStarted());
@@ -528,6 +539,7 @@ class HTMLMediaElement::MediaControlEventListener final
ControlledMediaState mState = ControlledMediaState::eStopped;
WeakPtr<HTMLMediaElement> mElement;
RefPtr<ContentMediaAgent> mControlAgent;
bool mIsPictureInPictureEnabled = false;
bool mIsOwnerAudible = false;
};
@@ -7736,6 +7748,11 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
// but the audible state update could happen before that. Therefore, we have
// to manually update media's audible state as well.
mMediaControlEventListener->UpdateMediaAudibleState(IsAudible());
// Picture-in-Picture mode can be enabled before we start the listener so we
// manually update the status here in case not to forgot to propagate that.
mMediaControlEventListener->SetPictureInPictureModeEnabled(
IsBeingUsedInPictureInPictureMode());
}
void HTMLMediaElement::StopListeningMediaControlEventIfNeeded() {
@@ -7795,6 +7812,19 @@ void HTMLMediaElement::ClearStopMediaControlTimerIfNeeded() {
}
}
void HTMLMediaElement::UpdateMediaControlAfterPictureInPictureModeChanged() {
// Hasn't started to connect with media control, no need to update anything.
if (!mMediaControlEventListener || !mMediaControlEventListener->IsStarted()) {
return;
}
if (IsBeingUsedInPictureInPictureMode()) {
mMediaControlEventListener->SetPictureInPictureModeEnabled(true);
} else {
mMediaControlEventListener->SetPictureInPictureModeEnabled(false);
CreateStopMediaControlTimerIfNeeded();
}
}
bool HTMLMediaElement::IsBeingUsedInPictureInPictureMode() const {
if (!IsVideo()) {
return false;