Bug 1877879 - Implement isActiveInTab and use it for PromptParent. r=smaug,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D200245
This commit is contained in:
Andrew McCreight 2024-02-05 16:16:22 +00:00
parent ce1354921c
commit cb6d45ee22
4 changed files with 25 additions and 1 deletions

View File

@ -132,7 +132,7 @@ export class PromptParent extends JSWindowActorParent {
switch (message.name) {
case "Prompt:Open":
if (!this.windowContext.isCurrentGlobal) {
if (!this.windowContext.isActiveInTab) {
return undefined;
}

View File

@ -66,6 +66,11 @@ interface WindowGlobalParent : WindowContext {
readonly attribute boolean isCurrentGlobal;
// This should return true if the window is currently visible in its tab.
// (A more technically accurate name would be something like
// "isActiveInRootNavigable".)
readonly attribute boolean isActiveInTab;
readonly attribute unsigned long long outerWindowId;
readonly attribute unsigned long long contentParentId;

View File

@ -661,6 +661,23 @@ bool WindowGlobalParent::IsCurrentGlobal() {
return CanSend() && BrowsingContext()->GetCurrentWindowGlobal() == this;
}
bool WindowGlobalParent::IsActiveInTab() {
if (!CanSend()) {
return false;
}
CanonicalBrowsingContext* bc = BrowsingContext();
if (!bc || bc->GetCurrentWindowGlobal() != this) {
return false;
}
// We check the top BC so we don't need to worry about getting a stale value.
// That may not be necessary.
MOZ_ASSERT(bc->Top()->IsInBFCache() == bc->IsInBFCache(),
"BFCache bit out of sync?");
return bc->AncestorsAreCurrent() && !bc->Top()->IsInBFCache();
}
namespace {
class ShareHandler final : public PromiseNativeHandler {

View File

@ -145,6 +145,8 @@ class WindowGlobalParent final : public WindowContext,
bool IsCurrentGlobal();
bool IsActiveInTab();
bool IsProcessRoot();
uint32_t ContentBlockingEvents();