Bug 1495064 - part2 : don't request wakelock for video without audio track. r=jya

There are often websites using videos without an audio track as background image or as GIF-like image. For these cases,
we don't want to hold a wakelock.

Differential Revision: https://phabricator.services.mozilla.com/D7215
This commit is contained in:
alwu
2018-10-02 17:55:50 +00:00
parent ab38dd17ca
commit b0f3c40d6a
3 changed files with 12 additions and 1 deletions

View File

@@ -315,10 +315,19 @@ HTMLVideoElement::UpdateWakeLock()
}
}
bool
HTMLVideoElement::ShouldCreateVideoWakeLock() const
{
// Make sure we only request wake lock for video with audio track, because
// video without audio track is often used as background image which seems no
// need to hold a wakelock.
return HasVideo() && HasAudio();
}
void
HTMLVideoElement::CreateVideoWakeLockIfNeeded()
{
if (!mScreenWakeLock && HasVideo()) {
if (!mScreenWakeLock && ShouldCreateVideoWakeLock()) {
RefPtr<power::PowerManagerService> pmService =
power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);