Bug 1625615 - part0 : create and set the flag suspendMediaWhenInactive on docShell. r=baku,farre

Implemecurnt a flag `suspendMediaWhenInactive` on the docShell that indicates media in that shell should be suspended when the shell is inactive. Currently, only GeckoView is using this flag.

---

The reason of implementing this flag is because in bug1577890 we remove the old way to suspend/resume the media, and I thought setting docshell to inactive is enough to suspend the media because we already have a mechanism which would suspend/resume media when document becomes inactive/active [1].

However, the active state of document is actually different from what I thought it was. Setting docshell to inactive won't change the document's active state, because that indicates if the document is the current active document for the docshell [2] (docshell can have multiple documents), instead of indicating if the docshell is active or not.

Therefore, we have to add another flag to indicate if the docshell wants to suspend its media when it's inactive, in order to use current mechanism to suspend/resume media.

[1] https://searchfox.org/mozilla-central/rev/4d2a9d5dc8f0e65807ee66e2b04c64596c643b7a/dom/html/HTMLMediaElement.cpp#6453
[2] https://searchfox.org/mozilla-central/rev/4d2a9d5dc8f0e65807ee66e2b04c64596c643b7a/dom/base/Document.h#2627-2633

Differential Revision: https://phabricator.services.mozilla.com/D69669
This commit is contained in:
alwu
2020-04-20 21:19:56 +00:00
parent 0039873a15
commit 890c6ea021
11 changed files with 134 additions and 2 deletions

View File

@@ -398,7 +398,8 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mTitleValidForCurrentURI(false),
mWillChangeProcess(false),
mWatchedByDevtools(false),
mIsNavigating(false) {
mIsNavigating(false),
mSuspendMediaWhenInactive(false) {
// If no outer window ID was provided, generate a new one.
if (aContentWindowID == 0) {
mContentWindowID = nsContentUtils::GenerateWindowId();
@@ -4640,6 +4641,18 @@ nsDocShell::GetIsOffScreenBrowser(bool* aIsOffScreen) {
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetSuspendMediaWhenInactive(bool aSuspendMediaWhenInactive) {
mSuspendMediaWhenInactive = aSuspendMediaWhenInactive;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetSuspendMediaWhenInactive(bool* aSuspendMediaWhenInactive) {
*aSuspendMediaWhenInactive = mSuspendMediaWhenInactive;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetIsActive(bool aIsActive) {
// Keep track ourselves.