diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 02c4ddc6e9ae..cb21d4a1c9ad 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1404,13 +1404,28 @@ void nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags, if (StaticPrefs::full_screen_api_exit_on_windowRaise() && !isElementInActiveWindow && aFlags & (FLAG_RAISE | FLAG_NONSYSTEMCALLER)) { - // TODO mActiveWindow in content process - if (Document* doc = mActiveWindow ? mActiveWindow->GetDoc() : nullptr) { - if (doc->GetFullscreenElement()) { - if (XRE_IsParentProcess()) { + if (XRE_IsParentProcess()) { + if (Document* doc = mActiveWindow ? mActiveWindow->GetDoc() : nullptr) { + if (doc->GetFullscreenElement()) { LogWarningFullscreenWindowRaise(mFocusedElement); + Document::AsyncExitFullscreen(doc); + } + } + } else { + BrowsingContext* activeBrowsingContext = GetActiveBrowsingContext(); + if (activeBrowsingContext) { + nsIDocShell* shell = activeBrowsingContext->GetDocShell(); + if (shell) { + Document* doc = shell->GetDocument(); + if (doc && doc->GetFullscreenElement()) { + Document::AsyncExitFullscreen(doc); + } + } else { + mozilla::dom::ContentChild* contentChild = + mozilla::dom::ContentChild::GetSingleton(); + MOZ_ASSERT(contentChild); + contentChild->SendMaybeExitFullscreen(activeBrowsingContext); } - Document::AsyncExitFullscreen(doc); } } } diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 2d571173ac28..fb95f1366353 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -4192,6 +4192,27 @@ mozilla::ipc::IPCResult ContentChild::RecvSetupFocusedAndActive( return IPC_OK(); } +mozilla::ipc::IPCResult ContentChild::RecvMaybeExitFullscreen( + const MaybeDiscarded& aContext) { + if (aContext.IsNullOrDiscarded()) { + MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug, + ("ChildIPC: Trying to send a message to dead or detached context")); + return IPC_OK(); + } + + nsIDocShell* shell = aContext.get()->GetDocShell(); + if (!shell) { + return IPC_OK(); + } + + Document* doc = shell->GetDocument(); + if (doc && doc->GetFullscreenElement()) { + Document::AsyncExitFullscreen(doc); + } + + return IPC_OK(); +} + mozilla::ipc::IPCResult ContentChild::RecvWindowPostMessage( const MaybeDiscarded& aContext, const ClonedMessageData& aMessage, const PostMessageData& aData) { diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 8c8030e56f5f..020304d92700 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -771,6 +771,8 @@ class ContentChild final mozilla::ipc::IPCResult RecvSetupFocusedAndActive( const MaybeDiscarded& aFocusedBrowsingContext, const MaybeDiscarded& aActiveBrowsingContext); + mozilla::ipc::IPCResult RecvMaybeExitFullscreen( + const MaybeDiscarded& aContext); mozilla::ipc::IPCResult RecvWindowPostMessage( const MaybeDiscarded& aContext, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index b421a287da37..cf5a7f934cd2 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -6358,6 +6358,25 @@ mozilla::ipc::IPCResult ContentParent::RecvBlurToParent( return IPC_OK(); } +mozilla::ipc::IPCResult ContentParent::RecvMaybeExitFullscreen( + const MaybeDiscarded& aContext) { + if (aContext.IsNullOrDiscarded()) { + MOZ_LOG( + BrowsingContext::GetLog(), LogLevel::Debug, + ("ParentIPC: Trying to send a message to dead or detached context")); + return IPC_OK(); + } + CanonicalBrowsingContext* context = aContext.get_canonical(); + + ContentProcessManager* cpm = ContentProcessManager::GetSingleton(); + + ContentParent* cp = + cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId())); + Unused << cp->SendMaybeExitFullscreen(context); + + return IPC_OK(); +} + mozilla::ipc::IPCResult ContentParent::RecvWindowPostMessage( const MaybeDiscarded& aContext, const ClonedMessageData& aMessage, const PostMessageData& aData) { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 1f30e7214708..30cb413d1947 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -670,6 +670,8 @@ class ContentParent final bool aIsLeavingDocument, bool aAdjustWidget, bool aBrowsingContextToClearHandled, bool aAncestorBrowsingContextToFocusHandled); + mozilla::ipc::IPCResult RecvMaybeExitFullscreen( + const MaybeDiscarded& aContext); mozilla::ipc::IPCResult RecvWindowPostMessage( const MaybeDiscarded& aContext, diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 3593075c2886..8cc31da084e1 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -1628,6 +1628,7 @@ child: async SetupFocusedAndActive(MaybeDiscardedBrowsingContext aFocusedBrowsingContext, MaybeDiscardedBrowsingContext aActiveBrowsingContext); both: + async MaybeExitFullscreen(MaybeDiscardedBrowsingContext aContext); async WindowPostMessage(MaybeDiscardedBrowsingContext aContext, ClonedMessageData aMessage, PostMessageData aData);