From 2a0d22e4288e2dd8f0a262bebaea69a007ee6bc8 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Fri, 19 Jul 2019 19:53:53 +0000 Subject: [PATCH] Bug 1523638 - Part 10: Implement WindowGlobalParent::GetRootFrameLoader in terms of Top()->GetEmbedderElement(), r=farre Differential Revision: https://phabricator.services.mozilla.com/D38552 --HG-- extra : moz-landing-system : lando --- dom/ipc/WindowGlobalParent.cpp | 44 ++++++++++------------------------ dom/ipc/WindowGlobalParent.h | 3 +-- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index d9755b3c0c98..1173250a5d67 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -64,7 +64,6 @@ WindowGlobalParent::WindowGlobalParent(const WindowGlobalInit& aInit, void WindowGlobalParent::Init(const WindowGlobalInit& aInit) { MOZ_ASSERT(Manager(), "Should have a manager!"); - MOZ_ASSERT(!mFrameLoader, "Cannot Init() a WindowGlobalParent twice!"); // Register this WindowGlobal in the gWindowGlobalParentsById map. if (!gWindowGlobalParentsById) { @@ -97,35 +96,6 @@ void WindowGlobalParent::Init(const WindowGlobalInit& aInit) { mBrowsingContext->SetCurrentWindowGlobal(this); } - // Determine what toplevel frame element our WindowGlobalParent is being - // embedded in. - RefPtr frameElement; - if (mInProcess) { - // In the in-process case, we can get it from the other side's - // WindowGlobalChild. - MOZ_ASSERT(Manager()->GetProtocolId() == PInProcessMsgStart); - RefPtr otherSide = GetChildActor(); - if (otherSide && otherSide->WindowGlobal()) { - // Get the toplevel window from the other side. - RefPtr docShell = - nsDocShell::Cast(otherSide->WindowGlobal()->GetDocShell()); - if (docShell) { - docShell->GetTopFrameElement(getter_AddRefs(frameElement)); - } - } - } else { - // In the cross-process case, we can get the frame element from our manager. - MOZ_ASSERT(Manager()->GetProtocolId() == PBrowserMsgStart); - frameElement = static_cast(Manager())->GetOwnerElement(); - } - - // Extract the nsFrameLoader from the current frame element. We may not have a - // nsFrameLoader if we are a chrome document. - RefPtr flOwner = do_QueryObject(frameElement); - if (flOwner) { - mFrameLoader = flOwner->GetFrameLoader(); - } - // Ensure we have a document URI if (!mDocumentURI) { NS_NewURI(getter_AddRefs(mDocumentURI), "about:blank"); @@ -161,6 +131,17 @@ already_AddRefed WindowGlobalParent::GetBrowserParent() { return do_AddRef(static_cast(Manager())); } +already_AddRefed WindowGlobalParent::GetRootFrameLoader() { + dom::BrowsingContext* top = BrowsingContext()->Top(); + + RefPtr frameLoaderOwner = + do_QueryObject(top->GetEmbedderElement()); + if (frameLoaderOwner) { + return frameLoaderOwner->GetFrameLoader(); + } + return nullptr; +} + uint64_t WindowGlobalParent::ContentParentId() { RefPtr browserParent = GetBrowserParent(); return browserParent ? browserParent->Manager()->ChildID() : 0; @@ -474,8 +455,7 @@ nsIGlobalObject* WindowGlobalParent::GetParentObject() { } NS_IMPL_CYCLE_COLLECTION_INHERITED(WindowGlobalParent, WindowGlobalActor, - mFrameLoader, mBrowsingContext, - mWindowActors) + mBrowsingContext, mWindowActors) NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WindowGlobalParent, WindowGlobalActor) diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index 0b692b3e43b2..9b0074b455b6 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -90,7 +90,7 @@ class WindowGlobalParent final : public WindowGlobalActor, // which this WindowGlobal is a part of. This will be the nsFrameLoader // holding the BrowserParent for remote tabs, and the root content frameloader // for non-remote tabs. - nsFrameLoader* GetRootFrameLoader() { return mFrameLoader; } + already_AddRefed GetRootFrameLoader(); // The current URI which loaded in the document. nsIURI* GetDocumentURI() override { return mDocumentURI; } @@ -165,7 +165,6 @@ class WindowGlobalParent final : public WindowGlobalActor, // mutations which may have been made in the actual document. nsCOMPtr mDocumentPrincipal; nsCOMPtr mDocumentURI; - RefPtr mFrameLoader; RefPtr mBrowsingContext; nsRefPtrHashtable mWindowActors; uint64_t mInnerWindowId;