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:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user