Skip to content

Commit

Permalink
Bug 1679314 - part2 : always use IsDocumentInvisible() to determine…
Browse files Browse the repository at this point in the history
… hidden state of wakelock. r=smaug

In order to determine the hidden status of wakelock correctly, we should always consider the PIP state.

Differential Revision: https://phabricator.services.mozilla.com/D99727
  • Loading branch information
alastor0325 committed Dec 15, 2020
1 parent caec133 commit de0cc89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dom/power/WakeLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ nsresult WakeLock::Init(const nsAString& aTopic, nsPIDOMWindowInner* aWindow) {
if (aWindow) {
nsCOMPtr<Document> doc = aWindow->GetExtantDoc();
NS_ENSURE_STATE(doc);
mHidden = doc->Hidden();
mHidden = IsDocumentInvisible(*doc);
}

AttachEventListener();
Expand Down Expand Up @@ -171,6 +171,13 @@ void WakeLock::Unlock(ErrorResult& aRv) {

void WakeLock::GetTopic(nsAString& aTopic) { aTopic.Assign(mTopic); }

bool WakeLock::IsDocumentInvisible(const Document& aDocument) const {
// If document has a child element being used in the picture in picture
// mode, which is always visible to users, then we would consider the
// document as visible as well.
return aDocument.Hidden() && !aDocument.HasPictureInPictureChildElement();
}

NS_IMETHODIMP
WakeLock::HandleEvent(Event* aEvent) {
nsAutoString type;
Expand All @@ -181,10 +188,7 @@ WakeLock::HandleEvent(Event* aEvent) {
NS_ENSURE_STATE(doc);

bool oldHidden = mHidden;
// If document has a child element being used in the picture in picture
// mode, which is always visible to users, then we would consider the
// document as visible as well.
mHidden = doc->Hidden() && !doc->HasPictureInPictureChildElement();
mHidden = IsDocumentInvisible(*doc);

if (mLocked && oldHidden != mHidden) {
hal::ModifyWakeLock(
Expand Down
4 changes: 4 additions & 0 deletions dom/power/WakeLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace mozilla {
class ErrorResult;

namespace dom {
class Document;

class WakeLock final : public nsIDOMEventListener,
public nsIObserver,
Expand Down Expand Up @@ -61,6 +62,9 @@ class WakeLock final : public nsIDOMEventListener,
void AttachEventListener();
void DetachEventListener();

// Return true if all parts of the given document are regarded as invisible.
bool IsDocumentInvisible(const Document& aDocument) const;

bool mLocked;
bool mHidden;

Expand Down

0 comments on commit de0cc89

Please sign in to comment.