From 4b25c4e6a48650edca3129984089e0638d82f3ad Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Wed, 19 Feb 2025 09:42:18 +0000 Subject: [PATCH] Bug 1937603 - Do not handle screen orientation on windowless browser; r=smaug This patch reuses the existing but unused `mWindowless` flag. The flag is now propagated to the BrowsingContext created under the windowless browser. Differential Revision: https://phabricator.services.mozilla.com/D238584 --- docshell/base/BrowsingContext.cpp | 5 +++-- docshell/base/BrowsingContext.h | 4 +++- docshell/base/nsDocShell.cpp | 3 ++- dom/base/nsFrameLoader.cpp | 4 +++- xpfe/appshell/AppWindow.cpp | 2 +- xpfe/appshell/nsAppShellService.cpp | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index ab8ec9436c5e46..2425779a7767e9 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -494,6 +494,7 @@ already_AddRefed BrowsingContext::CreateDetached( new BrowsingContext(parentWC, group, id, aType, std::move(fields)); } + context->mWindowless = aOptions.windowless; context->mEmbeddedByThisProcess = XRE_IsParentProcess() || aParent; context->mCreatedDynamically = aOptions.createdDynamically; if (inherit) { @@ -517,13 +518,13 @@ already_AddRefed BrowsingContext::CreateDetached( } already_AddRefed BrowsingContext::CreateIndependent( - Type aType) { + Type aType, bool aWindowless) { MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(), "BCs created in the content process must be related to " "some BrowserChild"); RefPtr bc( CreateDetached(nullptr, nullptr, nullptr, u""_ns, aType, {})); - bc->mWindowless = bc->IsContent(); + bc->mWindowless = aWindowless; bc->mEmbeddedByThisProcess = true; bc->EnsureAttached(); return bc.forget(); diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 2d27484a40fba9..eb183cb5c0751e 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -338,7 +338,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { // // The process which created this BrowsingContext is responsible for detaching // it. - static already_AddRefed CreateIndependent(Type aType); + static already_AddRefed CreateIndependent(Type aType, + bool aWindowless); // Options which can be passed to CreateDetached. struct CreateDetachedOptions { @@ -346,6 +347,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { bool createdDynamically = false; bool topLevelCreatedByWebContent = false; bool isForPrinting = false; + bool windowless = false; }; // Create a brand-new BrowsingContext object, but does not immediately attach diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 4dc2023d04b393..32c537d6be9024 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4741,7 +4741,8 @@ void nsDocShell::ActivenessMaybeChanged() { mScriptGlobal->SetIsBackground(!isActive); if (RefPtr doc = mScriptGlobal->GetExtantDoc()) { // Update orientation when the top-level browsing context becomes active. - if (isActive && mBrowsingContext->IsTop()) { + if (isActive && mBrowsingContext->IsTop() && + !mBrowsingContext->Windowless()) { // We only care about the top-level browsing context. auto orientation = mBrowsingContext->GetOrientationLock(); ScreenOrientation::UpdateActiveOrientationLock(orientation); diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index b87ec98510049e..eb128f9353db69 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -344,6 +344,7 @@ static already_AddRefed CreateBrowsingContext( options.topLevelCreatedByWebContent = aOpenWindowInfo->GetIsTopLevelCreatedByWebContent(); } + options.windowless = parentBC->Windowless(); // Create toplevel context without a parent & as Type::Content. return BrowsingContext::CreateDetached( @@ -358,7 +359,8 @@ static already_AddRefed CreateBrowsingContext( "Can't force BrowsingContextGroup for non-toplevel context"); return BrowsingContext::CreateDetached( parentInner, nullptr, nullptr, frameName, parentBC->GetType(), - {.createdDynamically = !aNetworkCreated}); + {.createdDynamically = !aNetworkCreated, + .windowless = parentBC->Windowless()}); } static bool InitialLoadIsRemote(Element* aOwner) { diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index 912f97610c75d1..a5e57d3086c57c 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -225,7 +225,7 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener, // to pass in the opener window here. The opener is set later, if needed, by // nsWindowWatcher. RefPtr browsingContext = - BrowsingContext::CreateIndependent(BrowsingContext::Type::Chrome); + BrowsingContext::CreateIndependent(BrowsingContext::Type::Chrome, false); // Create web shell mDocShell = nsDocShell::Create(browsingContext); diff --git a/xpfe/appshell/nsAppShellService.cpp b/xpfe/appshell/nsAppShellService.cpp index 97192c8f795ef5..1f11b5436f4d1e 100644 --- a/xpfe/appshell/nsAppShellService.cpp +++ b/xpfe/appshell/nsAppShellService.cpp @@ -414,7 +414,8 @@ nsAppShellService::CreateWindowlessBrowser(bool aIsChrome, uint32_t aChromeMask, // Create a BrowsingContext for our windowless browser. RefPtr browsingContext = BrowsingContext::CreateIndependent( aIsChrome ? BrowsingContext::Type::Chrome - : BrowsingContext::Type::Content); + : BrowsingContext::Type::Content, + true); if (aChromeMask & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW) { browsingContext->SetRemoteTabs(true);