From 5f47039328a8342a6f9986d2bc42828a3184e514 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Thu, 8 Aug 2019 16:06:56 +0000 Subject: [PATCH] Bug 1523638 - Part 3: Construct WindowGlobal actors using ManagedEndpoint, r=kmag Differential Revision: https://phabricator.services.mozilla.com/D37650 --HG-- extra : moz-landing-system : lando --- dom/ipc/BrowserParent.cpp | 20 ++++++++++---------- dom/ipc/BrowserParent.h | 7 +++---- dom/ipc/PBrowser.ipdl | 12 ++++++------ dom/ipc/WindowGlobalChild.cpp | 24 ++++++++++++++++++------ ipc/glue/InProcessChild.cpp | 6 ------ ipc/glue/InProcessChild.h | 3 --- ipc/glue/InProcessParent.cpp | 14 +------------- ipc/glue/InProcessParent.h | 7 ------- ipc/glue/PInProcess.ipdl | 7 ------- ipc/ipdl/ipdl/type.py | 2 +- 10 files changed, 39 insertions(+), 63 deletions(-) diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index a0999688ea9e..cb7c360f8277 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -1236,20 +1236,20 @@ IPCResult BrowserParent::RecvIndexedDBPermissionRequest( return IPC_OK(); } -IPCResult BrowserParent::RecvPWindowGlobalConstructor( - PWindowGlobalParent* aActor, const WindowGlobalInit& aInit) { - static_cast(aActor)->Init(aInit); +IPCResult BrowserParent::RecvNewWindowGlobal( + ManagedEndpoint&& aEndpoint, + const WindowGlobalInit& aInit) { + // Construct our new WindowGlobalParent, bind, and initialize it. + auto wgp = MakeRefPtr(aInit, /* inproc */ false); + + // Reference freed in DeallocPWindowGlobalParent. + BindPWindowGlobalEndpoint(std::move(aEndpoint), do_AddRef(wgp).take()); + wgp->Init(aInit); return IPC_OK(); } -PWindowGlobalParent* BrowserParent::AllocPWindowGlobalParent( - const WindowGlobalInit& aInit) { - // Reference freed in DeallocPWindowGlobalParent. - return do_AddRef(new WindowGlobalParent(aInit, /* inproc */ false)).take(); -} - bool BrowserParent::DeallocPWindowGlobalParent(PWindowGlobalParent* aActor) { - // Free reference from AllocPWindowGlobalParent. + // Free reference from RecvNewWindowGlobal. static_cast(aActor)->Release(); return true; } diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h index 1c0c0e3ad87e..b91e77134bfc 100644 --- a/dom/ipc/BrowserParent.h +++ b/dom/ipc/BrowserParent.h @@ -473,12 +473,11 @@ class BrowserParent final : public PBrowserParent, const uint64_t& aParentID, const uint32_t& aMsaaID, const IAccessibleHolder& aDocCOMProxy) override; - PWindowGlobalParent* AllocPWindowGlobalParent(const WindowGlobalInit& aInit); - bool DeallocPWindowGlobalParent(PWindowGlobalParent* aActor); - virtual mozilla::ipc::IPCResult RecvPWindowGlobalConstructor( - PWindowGlobalParent* aActor, const WindowGlobalInit& aInit) override; + mozilla::ipc::IPCResult RecvNewWindowGlobal( + ManagedEndpoint&& aEndpoint, + const WindowGlobalInit& aInit); already_AddRefed AllocPBrowserBridgeParent( const nsString& aPresentationURL, const nsString& aRemoteType, diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 2f5a0d92622d..dd48512747c1 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -203,12 +203,6 @@ parent: async PPaymentRequest(); - /** - * Construct a new WindowGlobal actor for a window global in the given - * BrowsingContext and with the given principal. - */ - async PWindowGlobal(WindowGlobalInit init); - /** * Construct a new Remote iframe actor. */ @@ -1025,6 +1019,12 @@ parent: /** Fetches the visited status for an array of URIs (Android-only). */ async QueryVisitedState(URIParams[] aURIs); + /** + * Construct a new WindowGlobal for an existing global in the content process + */ + async NewWindowGlobal(ManagedEndpoint aEndpoint, + WindowGlobalInit aInit); + /* * FIXME: write protocol! diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 16544553cdb5..6c5a2319def6 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -8,7 +8,6 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/WindowGlobalParent.h" -#include "mozilla/ipc/InProcessChild.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/MozFrameLoaderOwnerBinding.h" @@ -18,6 +17,7 @@ #include "mozilla/dom/WindowGlobalActorsBinding.h" #include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/ipc/InProcessChild.h" +#include "mozilla/ipc/InProcessParent.h" #include "nsContentUtils.h" #include "nsDocShell.h" #include "nsFrameLoaderOwner.h" @@ -90,22 +90,34 @@ already_AddRefed WindowGlobalChild::Create( return wgc.forget(); } - // Send the link constructor over PInProcessChild or PBrowser. + // Send the link constructor over PBrowser, or link over PInProcess. if (XRE_IsParentProcess()) { - InProcessChild* ipc = InProcessChild::Singleton(); - if (!ipc) { + InProcessChild* ipChild = InProcessChild::Singleton(); + InProcessParent* ipParent = InProcessParent::Singleton(); + if (!ipChild || !ipParent) { return nullptr; } // Note: ref is released in DeallocPWindowGlobalChild - ipc->SendPWindowGlobalConstructor(do_AddRef(wgc).take(), init); + ManagedEndpoint endpoint = + ipChild->OpenPWindowGlobalEndpoint(do_AddRef(wgc).take()); + + auto wgp = MakeRefPtr(init, /* aInProcess */ true); + + // Note: ref is released in DeallocPWindowGlobalParent + ipParent->BindPWindowGlobalEndpoint(std::move(endpoint), + do_AddRef(wgp).take()); + wgp->Init(init); } else { RefPtr browserChild = BrowserChild::GetFrom(static_cast(aWindow)); MOZ_ASSERT(browserChild); // Note: ref is released in DeallocPWindowGlobalChild - browserChild->SendPWindowGlobalConstructor(do_AddRef(wgc).take(), init); + ManagedEndpoint endpoint = + browserChild->OpenPWindowGlobalEndpoint(do_AddRef(wgc).take()); + + browserChild->SendNewWindowGlobal(std::move(endpoint), init); } // Register this WindowGlobal in the gWindowGlobalParentsById map. diff --git a/ipc/glue/InProcessChild.cpp b/ipc/glue/InProcessChild.cpp index 8abb37660dcb..896f7a6fb0c7 100644 --- a/ipc/glue/InProcessChild.cpp +++ b/ipc/glue/InProcessChild.cpp @@ -12,12 +12,6 @@ using namespace mozilla::dom; namespace mozilla { namespace ipc { -PWindowGlobalChild* InProcessChild::AllocPWindowGlobalChild( - const WindowGlobalInit& aInit) { - MOZ_ASSERT_UNREACHABLE("PWindowGlobalChild should not be created manually"); - return nullptr; -} - bool InProcessChild::DeallocPWindowGlobalChild(PWindowGlobalChild* aActor) { // Free IPC-held reference static_cast(aActor)->Release(); diff --git a/ipc/glue/InProcessChild.h b/ipc/glue/InProcessChild.h index 4513ea60f18d..8e673418ed15 100644 --- a/ipc/glue/InProcessChild.h +++ b/ipc/glue/InProcessChild.h @@ -44,9 +44,6 @@ class InProcessChild : public PInProcessChild { static IProtocol* ParentActorFor(IProtocol* aActor); protected: - mozilla::dom::PWindowGlobalChild* AllocPWindowGlobalChild( - const WindowGlobalInit& aInit); - bool DeallocPWindowGlobalChild(mozilla::dom::PWindowGlobalChild* aActor); private: diff --git a/ipc/glue/InProcessParent.cpp b/ipc/glue/InProcessParent.cpp index b95d73d5bf69..1e0ea7e259ef 100644 --- a/ipc/glue/InProcessParent.cpp +++ b/ipc/glue/InProcessParent.cpp @@ -14,18 +14,6 @@ namespace ipc { NS_IMPL_ISUPPORTS(InProcessParent, nsIObserver) -IPCResult InProcessParent::RecvPWindowGlobalConstructor( - PWindowGlobalParent* aActor, const WindowGlobalInit& aInit) { - static_cast(aActor)->Init(aInit); - return IPC_OK(); -} - -PWindowGlobalParent* InProcessParent::AllocPWindowGlobalParent( - const WindowGlobalInit& aInit) { - // Reference freed in DeallocPWindowGlobalParent. - return do_AddRef(new WindowGlobalParent(aInit, /* inproc */ true)).take(); -} - bool InProcessParent::DeallocPWindowGlobalParent(PWindowGlobalParent* aActor) { // Free IPC-held reference. static_cast(aActor)->Release(); @@ -33,4 +21,4 @@ bool InProcessParent::DeallocPWindowGlobalParent(PWindowGlobalParent* aActor) { } } // namespace ipc -} // namespace mozilla \ No newline at end of file +} // namespace mozilla diff --git a/ipc/glue/InProcessParent.h b/ipc/glue/InProcessParent.h index 07f83a974dfb..77f506654125 100644 --- a/ipc/glue/InProcessParent.h +++ b/ipc/glue/InProcessParent.h @@ -45,15 +45,8 @@ class InProcessParent : public nsIObserver, public PInProcessParent { static IProtocol* ChildActorFor(IProtocol* aActor); protected: - mozilla::dom::PWindowGlobalParent* AllocPWindowGlobalParent( - const WindowGlobalInit& aInit); - bool DeallocPWindowGlobalParent(mozilla::dom::PWindowGlobalParent* aActor); - virtual IPCResult RecvPWindowGlobalConstructor( - mozilla::dom::PWindowGlobalParent* aActor, - const WindowGlobalInit& aInit) override; - private: // Lifecycle management is implemented in InProcessImpl.cpp virtual void ActorDestroy(ActorDestroyReason aWhy) override; diff --git a/ipc/glue/PInProcess.ipdl b/ipc/glue/PInProcess.ipdl index 9121d10e5964..4b6296fcdaab 100644 --- a/ipc/glue/PInProcess.ipdl +++ b/ipc/glue/PInProcess.ipdl @@ -22,13 +22,6 @@ namespace ipc { async protocol PInProcess { manages PWindowGlobal; - -parent: - /** - * Construct a new WindowGlobal actor for a window global in the given - * BrowsingContext and with the given principal. - */ - async PWindowGlobal(WindowGlobalInit init); }; } // namespace ipc diff --git a/ipc/ipdl/ipdl/type.py b/ipc/ipdl/ipdl/type.py index bcf9e6b5a425..54824a32aa8b 100644 --- a/ipc/ipdl/ipdl/type.py +++ b/ipc/ipdl/ipdl/type.py @@ -983,7 +983,7 @@ class GatherDecls(TcheckVisitor): managed.manager = p managed.accept(self) - if 0 == len(p.managers) and 0 == len(p.messageDecls): + if not (p.managers or p.messageDecls or p.managesStmts): self.error(p.loc, "top-level protocol `%s' cannot be empty", p.name)