Bug 1639577 - Only suspend GeckoView tabs that are alone in their BrowsingContextGroup r=nika,geckoview-reviewers,agi

This avoids problems where a foreground tab tries to communicate with a background
tab via `window.opener`, but is unable to because the background tab
is suspended.

Differential Revision: https://phabricator.services.mozilla.com/D83693
This commit is contained in:
James Willcox
2020-07-21 21:04:53 +00:00
parent bf4b07ff5d
commit eb86e2a780
9 changed files with 72 additions and 30 deletions

View File

@@ -43,7 +43,8 @@ already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::Create() {
return GetOrCreate(nsContentUtils::GenerateBrowsingContextId());
}
BrowsingContextGroup::BrowsingContextGroup(uint64_t aId) : mId(aId) {
BrowsingContextGroup::BrowsingContextGroup(uint64_t aId)
: mId(aId), mToplevelsSuspended(false) {
mTimerEventQueue = ThrottledEventQueue::Create(
GetMainThreadSerialEventTarget(), "BrowsingContextGroup timer queue");
@@ -147,6 +148,26 @@ void BrowsingContextGroup::EnsureSubscribed(ContentParent* aProcess) {
}
}
void BrowsingContextGroup::SetToplevelsSuspended(bool aSuspended) {
for (const auto& context : mToplevels) {
nsPIDOMWindowOuter* outer = context->GetDOMWindow();
if (outer) {
nsCOMPtr<nsPIDOMWindowInner> inner = outer->GetCurrentInnerWindow();
if (inner) {
if (aSuspended && !inner->GetWasSuspendedByGroup()) {
inner->Suspend();
inner->SetWasSuspendedByGroup(true);
} else if (!aSuspended && inner->GetWasSuspendedByGroup()) {
inner->Resume();
inner->SetWasSuspendedByGroup(false);
}
}
}
}
mToplevelsSuspended = aSuspended;
}
BrowsingContextGroup::~BrowsingContextGroup() {
UnsubscribeAllContentParents();
}