зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
a9f8a2b1e9
Коммит
1c18fb5f4d
|
@ -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>,
|
||||
|
|
|
@ -192,8 +192,6 @@ enum class ExplicitActiveStatus : uint8_t {
|
|||
FIELD(MediumOverride, nsString) \
|
||||
FIELD(PrefersColorSchemeOverride, mozilla::dom::PrefersColorSchemeOverride) \
|
||||
FIELD(DisplayMode, mozilla::dom::DisplayMode) \
|
||||
/* True if the top level browsing context owns a main media controller */ \
|
||||
FIELD(HasMainMediaController, bool) \
|
||||
/* The number of entries added to the session history because of this \
|
||||
* browsing context. */ \
|
||||
FIELD(HistoryEntryCount, uint32_t) \
|
||||
|
@ -203,7 +201,11 @@ enum class ExplicitActiveStatus : uint8_t {
|
|||
FIELD(SessionStoreEpoch, uint32_t) \
|
||||
/* Whether we can execute scripts in this BrowsingContext. Has no effect \
|
||||
* unless scripts are also allowed in the parent WindowContext. */ \
|
||||
FIELD(AllowJavascript, bool)
|
||||
FIELD(AllowJavascript, bool) \
|
||||
/* The count of request that are used to prevent the browsing context tree \
|
||||
* from being suspended, which would ONLY be modified on the top level \
|
||||
* context in the chrome process because that's a non-atomic counter */ \
|
||||
FIELD(PageAwakeRequestCount, uint32_t)
|
||||
|
||||
// BrowsingContext, in this context, is the cross process replicated
|
||||
// environment in which information about documents is stored. In
|
||||
|
@ -861,6 +863,14 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
|
|||
|
||||
uint32_t DefaultLoadFlags() const { return GetDefaultLoadFlags(); }
|
||||
|
||||
// When request for page awake, it would increase a count that is used to
|
||||
// prevent whole browsing context tree from being suspended. The request can
|
||||
// be called multiple times. When calling the revoke, it would decrease the
|
||||
// count and once the count reaches to zero, the browsing context tree could
|
||||
// be suspended when the tree is inactive.
|
||||
void RequestForPageAwake();
|
||||
void RevokeForPageAwake();
|
||||
|
||||
protected:
|
||||
virtual ~BrowsingContext();
|
||||
BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup,
|
||||
|
@ -1081,9 +1091,9 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
|
|||
bool CanSet(FieldIndex<IDX_PendingInitialization>, bool aNewValue,
|
||||
ContentParent* aSource);
|
||||
|
||||
CanSetResult CanSet(FieldIndex<IDX_HasMainMediaController>, bool aNewValue,
|
||||
bool CanSet(FieldIndex<IDX_PageAwakeRequestCount>, uint32_t aNewValue,
|
||||
ContentParent* aSource);
|
||||
void DidSet(FieldIndex<IDX_HasMainMediaController>, bool aOldValue);
|
||||
void DidSet(FieldIndex<IDX_PageAwakeRequestCount>, uint32_t aOldValue);
|
||||
|
||||
CanSetResult CanSet(FieldIndex<IDX_AllowJavascript>, bool aValue,
|
||||
ContentParent* aSource);
|
||||
|
|
|
@ -2513,6 +2513,20 @@ void CanonicalBrowsingContext::SetTouchEventsOverride(
|
|||
SetTouchEventsOverrideInternal(aOverride, aRv);
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::AddPageAwakeRequest() {
|
||||
MOZ_ASSERT(IsTop());
|
||||
auto count = GetPageAwakeRequestCount();
|
||||
MOZ_ASSERT(count < UINT32_MAX);
|
||||
Unused << SetPageAwakeRequestCount(++count);
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::RemovePageAwakeRequest() {
|
||||
MOZ_ASSERT(IsTop());
|
||||
auto count = GetPageAwakeRequestCount();
|
||||
MOZ_ASSERT(count > 0);
|
||||
Unused << SetPageAwakeRequestCount(--count);
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::CloneDocumentTreeInto(
|
||||
CanonicalBrowsingContext* aSource, const nsACString& aRemoteType,
|
||||
embedding::PrintData&& aPrintData) {
|
||||
|
|
|
@ -326,6 +326,14 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
|||
void ClearPermanentKey() { mPermanentKey.setNull(); }
|
||||
void MaybeSetPermanentKey(Element* aEmbedder);
|
||||
|
||||
// When request for page awake, it would increase a count that is used to
|
||||
// prevent whole browsing context tree from being suspended. The request can
|
||||
// be called multiple times. When calling the revoke, it would decrease the
|
||||
// count and once the count reaches to zero, the browsing context tree could
|
||||
// be suspended when the tree is inactive.
|
||||
void AddPageAwakeRequest();
|
||||
void RemovePageAwakeRequest();
|
||||
|
||||
void CloneDocumentTreeInto(CanonicalBrowsingContext* aSource,
|
||||
const nsACString& aRemoteType,
|
||||
embedding::PrintData&& aPrintData);
|
||||
|
|
|
@ -542,13 +542,13 @@ CopyableTArray<MediaControlKey> MediaController::GetSupportedMediaKeys() const {
|
|||
|
||||
void MediaController::Select() const {
|
||||
if (RefPtr<BrowsingContext> bc = BrowsingContext::Get(Id())) {
|
||||
Unused << bc->SetHasMainMediaController(true);
|
||||
bc->Canonical()->AddPageAwakeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void MediaController::Unselect() const {
|
||||
if (RefPtr<BrowsingContext> bc = BrowsingContext::Get(Id())) {
|
||||
Unused << bc->SetHasMainMediaController(false);
|
||||
bc->Canonical()->RemovePageAwakeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче