Skip to content

Commit

Permalink
Bug 1808748 - Add a browsing context flag to force the top level chro…
Browse files Browse the repository at this point in the history
…me browsing context to remain active. r=nika

This will be useful for bug 1770429.

Differential Revision: https://phabricator.services.mozilla.com/D166105
  • Loading branch information
emilio committed Jan 9, 2023
1 parent 9a75fd9 commit aedb1cb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
42 changes: 42 additions & 0 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,48 @@ void CanonicalBrowsingContext::AddFinalDiscardListener(
mFullyDiscardedListeners.AppendElement(std::move(aListener));
}

void CanonicalBrowsingContext::SetForceAppWindowActive(bool aForceActive,
ErrorResult& aRv) {
MOZ_DIAGNOSTIC_ASSERT(IsChrome());
MOZ_DIAGNOSTIC_ASSERT(IsTop());
if (!IsChrome() || !IsTop()) {
return aRv.ThrowNotAllowedError(
"You shouldn't need to force this BrowsingContext to be active, use "
".isActive instead");
}
if (mForceAppWindowActive == aForceActive) {
return;
}
mForceAppWindowActive = aForceActive;
RecomputeAppWindowVisibility();
}

void CanonicalBrowsingContext::RecomputeAppWindowVisibility() {
MOZ_RELEASE_ASSERT(IsChrome());
MOZ_RELEASE_ASSERT(IsTop());

const bool isActive = [&] {
if (ForceAppWindowActive()) {
return true;
}
auto* docShell = GetDocShell();
if (NS_WARN_IF(!docShell)) {
return false;
}
nsCOMPtr<nsIWidget> widget;
nsDocShell::Cast(docShell)->GetMainWidget(getter_AddRefs(widget));
if (NS_WARN_IF(!widget)) {
return false;
}
if (widget->IsFullyOccluded() ||
widget->SizeMode() == nsSizeMode_Minimized) {
return false;
}
return true;
}();
SetIsActive(isActive, IgnoreErrors());
}

void CanonicalBrowsingContext::AdjustPrivateBrowsingCount(
bool aPrivateBrowsing) {
if (IsDiscarded() || !EverAttached() || IsChrome()) {
Expand Down
9 changes: 8 additions & 1 deletion docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {

void AddFinalDiscardListener(std::function<void(uint64_t)>&& aListener);

bool ForceAppWindowActive() const { return mForceAppWindowActive; }
void SetForceAppWindowActive(bool, ErrorResult&);
void RecomputeAppWindowVisibility();

protected:
// Called when the browsing context is being discarded.
void CanonicalDiscard();
Expand Down Expand Up @@ -547,11 +551,14 @@ class CanonicalBrowsingContext final : public BrowsingContext {

RefPtr<RestoreState> mRestoreState;

nsCOMPtr<nsITimer> mSessionStoreSessionStorageUpdateTimer;

// If this is a top level context, this is true if our browser ID is marked as
// active in the process priority manager.
bool mPriorityActive = false;

nsCOMPtr<nsITimer> mSessionStoreSessionStorageUpdateTimer;
// See CanonicalBrowsingContext.forceAppWindowActive.
bool mForceAppWindowActive = false;

bool mIsReplaced = false;

Expand Down
4 changes: 4 additions & 0 deletions dom/chrome-webidl/BrowsingContext.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ interface CanonicalBrowsingContext : BrowsingContext {

undefined clearRestoreState();

// Force this browsing context, which must correspond to an app window, to
// be active regardless of the window being minimized or fully occluded.
[SetterThrows] attribute boolean forceAppWindowActive;

/**
* This allows chrome to override the default choice of whether touch events
* are available in a specific BrowsingContext and its descendents.
Expand Down
16 changes: 5 additions & 11 deletions xpfe/appshell/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "nsIAppShellService.h"
#include "nsIContentViewer.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "nsPIDOMWindow.h"
#include "nsScreen.h"
#include "nsIInterfaceRequestor.h"
Expand Down Expand Up @@ -2996,18 +2997,11 @@ void AppWindow::RecomputeBrowsingContextVisibility() {
if (!mDocShell) {
return;
}
if (RefPtr bc = mDocShell->GetBrowsingContext()) {
nsCOMPtr<nsIWidget> widget;
mDocShell->GetMainWidget(getter_AddRefs(widget));
const bool isActive = [&] {
if (!widget) {
return false;
}
return widget->SizeMode() != nsSizeMode_Minimized &&
!widget->IsFullyOccluded();
}();
bc->SetIsActive(isActive, IgnoreErrors());
RefPtr bc = mDocShell->GetBrowsingContext();
if (!bc) {
return;
}
bc->Canonical()->RecomputeAppWindowVisibility();
}

void AppWindow::OcclusionStateChanged(bool aIsFullyOccluded) {
Expand Down

0 comments on commit aedb1cb

Please sign in to comment.