Bug 1495064 - part1 : refactor the logic of requesting wakelock. r=jya

HTMLMediaElement::UpdateWakeLock() is responsible for creating and releasing audio wakelock.
HTMLVideoElement::UpdateWakeLock() is responsible for creating and releasing video wakelock.

In addition, each platform would handle system wakelock properly depending on different requests.

Differential Revision: https://phabricator.services.mozilla.com/D7214
This commit is contained in:
alwu
2018-10-02 17:56:21 +00:00
parent 488ac5fe26
commit ab38dd17ca
4 changed files with 54 additions and 29 deletions

View File

@@ -296,32 +296,29 @@ HTMLVideoElement::GetVideoPlaybackQuality()
return playbackQuality.forget();
}
void
HTMLVideoElement::WakeLockCreate()
{
HTMLMediaElement::WakeLockCreate();
UpdateScreenWakeLock();
}
void
HTMLVideoElement::WakeLockRelease()
{
UpdateScreenWakeLock();
HTMLMediaElement::WakeLockRelease();
ReleaseVideoWakeLockIfExists();
}
void
HTMLVideoElement::UpdateScreenWakeLock()
HTMLVideoElement::UpdateWakeLock()
{
if (mScreenWakeLock && mPaused) {
ErrorResult rv;
mScreenWakeLock->Unlock(rv);
rv.SuppressException();
mScreenWakeLock = nullptr;
return;
HTMLMediaElement::UpdateWakeLock();
if (!mPaused) {
CreateVideoWakeLockIfNeeded();
} else {
ReleaseVideoWakeLockIfExists();
}
}
if (!mScreenWakeLock && !mPaused && HasVideo()) {
void
HTMLVideoElement::CreateVideoWakeLockIfNeeded()
{
if (!mScreenWakeLock && HasVideo()) {
RefPtr<power::PowerManagerService> pmService =
power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);
@@ -333,6 +330,18 @@ HTMLVideoElement::UpdateScreenWakeLock()
}
}
void
HTMLVideoElement::ReleaseVideoWakeLockIfExists()
{
if (mScreenWakeLock) {
ErrorResult rv;
mScreenWakeLock->Unlock(rv);
rv.SuppressException();
mScreenWakeLock = nullptr;
return;
}
}
void
HTMLVideoElement::Init()
{