Bug 1719183 - part1 : use a count to generalize the usage of preventing page from being suspended. r=nika

To support more cases, change this value to more general name and use a count instead, if the count is larger than zero, then we would not suspend the page.

In addition, this value now can be set in any processes (but still for the top level only), which is different from before where we would only set the value from the chrome process.

Differential Revision: https://phabricator.services.mozilla.com/D119837
This commit is contained in:
alwu
2021-08-03 21:32:26 +00:00
parent d9fd48765c
commit ea440ffd35
5 changed files with 51 additions and 23 deletions

View File

@@ -2626,18 +2626,14 @@ void BrowsingContext::DidSet(FieldIndex<IDX_ExplicitActive>,
});
}
auto BrowsingContext::CanSet(FieldIndex<IDX_HasMainMediaController>,
bool aNewValue, ContentParent* aSource)
-> CanSetResult {
if (!IsTop()) {
return CanSetResult::Deny;
}
return LegacyRevertIfNotOwningOrParentProcess(aSource);
bool BrowsingContext::CanSet(FieldIndex<IDX_PageAwakeRequestCount>,
uint32_t aNewValue, ContentParent* aSource) {
return IsTop() && XRE_IsParentProcess() && !aSource;
}
void BrowsingContext::DidSet(FieldIndex<IDX_HasMainMediaController>,
bool aOldValue) {
if (!IsTop() || aOldValue == GetHasMainMediaController()) {
void BrowsingContext::DidSet(FieldIndex<IDX_PageAwakeRequestCount>,
uint32_t aOldValue) {
if (!IsTop() || aOldValue == GetPageAwakeRequestCount()) {
return;
}
Group()->UpdateToplevelsSuspendedIfNeeded();
@@ -2684,11 +2680,11 @@ bool BrowsingContext::InactiveForSuspend() const {
if (!StaticPrefs::dom_suspend_inactive_enabled()) {
return false;
}
// We should suspend a page only when it's inactive and doesn't have a main
// media controller. Having a main controller in context means it might be
// playing media, or waiting media keys to control media (could be not playing
// anything currently)
return !IsActive() && !GetHasMainMediaController();
// We should suspend a page only when it's inactive and doesn't have any awake
// request that is used to prevent page from being suspended because web page
// might still need to run their script. Eg. waiting for media keys to resume
// media, playing web audio, waiting in a video call conference room.
return !IsActive() && GetPageAwakeRequestCount() == 0;
}
bool BrowsingContext::CanSet(FieldIndex<IDX_TouchEventsOverrideInternal>,