Bug 1523638 - Part 3: Construct WindowGlobal actors using ManagedEndpoint, r=kmag
☠☠ backed out by 663f5d1ba3f3 ☠ ☠
authorNika Layzell <nika@thelayzells.com>
Tue, 16 Jul 2019 18:47:39 +0000
changeset 543496 d606d072126ccf4d3ee1a50a1cbea3f3e50776d6
parent 543495 76dc1937fc77248f707d8439c7bc19a49360ca05
child 543497 49047c3ebae94e21d861e8940b63767afa9f61ac
push id11848
push userffxbld-merge
push dateMon, 26 Aug 2019 19:26:25 +0000
treeherdermozilla-beta@9b31bfdfac10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1523638
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523638 - Part 3: Construct WindowGlobal actors using ManagedEndpoint, r=kmag Differential Revision: https://phabricator.services.mozilla.com/D37650
dom/ipc/BrowserParent.cpp
dom/ipc/BrowserParent.h
dom/ipc/PBrowser.ipdl
dom/ipc/WindowGlobalChild.cpp
ipc/glue/InProcessChild.cpp
ipc/glue/InProcessChild.h
ipc/glue/InProcessParent.cpp
ipc/glue/InProcessParent.h
ipc/glue/PInProcess.ipdl
ipc/ipdl/ipdl/type.py
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -1222,30 +1222,30 @@ IPCResult BrowserParent::RecvIndexedDBPe
 
   if (permission != indexedDB::PermissionRequestBase::kPermissionPrompt) {
     aResolve(permission);
   }
 
   return IPC_OK();
 }
 
-IPCResult BrowserParent::RecvPWindowGlobalConstructor(
-    PWindowGlobalParent* aActor, const WindowGlobalInit& aInit) {
-  static_cast<WindowGlobalParent*>(aActor)->Init(aInit);
+IPCResult BrowserParent::RecvNewWindowGlobal(
+    ManagedEndpoint<PWindowGlobalParent>&& aEndpoint,
+    const WindowGlobalInit& aInit) {
+  // Construct our new WindowGlobalParent, bind, and initialize it.
+  auto wgp = MakeRefPtr<WindowGlobalParent>(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<WindowGlobalParent*>(aActor)->Release();
   return true;
 }
 
 IPCResult BrowserParent::RecvPBrowserBridgeConstructor(
     PBrowserBridgeParent* aActor, const nsString& aName,
     const nsString& aRemoteType, BrowsingContext* aBrowsingContext,
     const uint32_t& aChromeFlags, const TabId& aTabId) {
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -462,22 +462,21 @@ class BrowserParent final : public PBrow
 
   bool DeallocPDocAccessibleParent(PDocAccessibleParent*);
 
   virtual mozilla::ipc::IPCResult RecvPDocAccessibleConstructor(
       PDocAccessibleParent* aDoc, PDocAccessibleParent* aParentDoc,
       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<PWindowGlobalParent>&& aEndpoint,
+      const WindowGlobalInit& aInit);
 
   PBrowserBridgeParent* AllocPBrowserBridgeParent(
       const nsString& aPresentationURL, const nsString& aRemoteType,
       BrowsingContext* aBrowsingContext, const uint32_t& aChromeFlags,
       const TabId& aTabId);
 
   bool DeallocPBrowserBridgeParent(PBrowserBridgeParent* aActor);
 
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -196,22 +196,16 @@ parent:
      * in e10s mode. This is always initiated from the child in response
      * to windowed plugin creation.
      */
     sync PPluginWidget();
 
     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.
      */
     async PBrowserBridge(nsString aPresentationURL, nsString aRemoteType,
                          BrowsingContext aBrowsingContext, uint32_t aChromeFlags,
                          TabId tabId);
 
     /**
      * Sends an NS_NATIVE_CHILD_OF_SHAREABLE_WINDOW to be adopted by the
@@ -1015,16 +1009,22 @@ child:
 parent:
     /** Records a history visit. */
     async VisitURI(URIParams aURI, URIParams? aLastVisitedURI,
                    uint32_t aFlags);
 
     /** 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<PWindowGlobalParent> aEndpoint,
+                          WindowGlobalInit aInit);
+
 /*
  * FIXME: write protocol!
 
 state LIVE:
     send LoadURL goto LIVE;
 //etc.
     send Destroy goto DYING;
 
--- a/dom/ipc/WindowGlobalChild.cpp
+++ b/dom/ipc/WindowGlobalChild.cpp
@@ -3,26 +3,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/WindowGlobalChild.h"
 
 #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"
 #include "mozilla/dom/BrowserChild.h"
 #include "mozilla/dom/BrowserBridgeChild.h"
 #include "mozilla/dom/ContentChild.h"
 #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"
 #include "nsGlobalWindowInner.h"
 #include "nsFrameLoaderOwner.h"
 #include "nsQueryObject.h"
 #include "nsSerializationHelper.h"
 
@@ -85,32 +85,44 @@ already_AddRefed<WindowGlobalChild> Wind
 
   // If we have already closed our browsing context, return a pre-destroyed
   // WindowGlobalChild actor.
   if (bc->IsDiscarded()) {
     wgc->ActorDestroy(FailedConstructor);
     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<PWindowGlobalParent> endpoint =
+        ipChild->OpenPWindowGlobalEndpoint(do_AddRef(wgc).take());
+
+    auto wgp = MakeRefPtr<WindowGlobalParent>(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 =
         BrowserChild::GetFrom(static_cast<mozIDOMWindow*>(aWindow));
     MOZ_ASSERT(browserChild);
 
     // Note: ref is released in DeallocPWindowGlobalChild
-    browserChild->SendPWindowGlobalConstructor(do_AddRef(wgc).take(), init);
+    ManagedEndpoint<PWindowGlobalParent> endpoint =
+        browserChild->OpenPWindowGlobalEndpoint(do_AddRef(wgc).take());
+
+    browserChild->SendNewWindowGlobal(std::move(endpoint), init);
   }
 
   // Register this WindowGlobal in the gWindowGlobalParentsById map.
   if (!gWindowGlobalChildById) {
     gWindowGlobalChildById = new WGCByIdMap();
     ClearOnShutdown(&gWindowGlobalChildById);
   }
   auto entry = gWindowGlobalChildById->LookupForAdd(wgc->mInnerWindowId);
--- a/ipc/glue/InProcessChild.cpp
+++ b/ipc/glue/InProcessChild.cpp
@@ -7,22 +7,16 @@
 #include "mozilla/ipc/InProcessChild.h"
 #include "mozilla/dom/WindowGlobalChild.h"
 
 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<WindowGlobalChild*>(aActor)->Release();
   return true;
 }
 
 }  // namespace ipc
 }  // namespace mozilla
--- a/ipc/glue/InProcessChild.h
+++ b/ipc/glue/InProcessChild.h
@@ -39,19 +39,16 @@ class InProcessChild : public PInProcess
   static InProcessChild* Singleton();
 
   // Get the parent side of the in-process child actor |aActor|. If |aActor| is
   // not an in-process actor, or is not connected, this method will return
   // |nullptr|.
   static IProtocol* ParentActorFor(IProtocol* aActor);
 
  protected:
-  mozilla::dom::PWindowGlobalChild* AllocPWindowGlobalChild(
-      const WindowGlobalInit& aInit);
-
   bool DeallocPWindowGlobalChild(mozilla::dom::PWindowGlobalChild* aActor);
 
  private:
   // NOTE: PInProcess lifecycle management is declared as staic methods and
   // state on InProcessParent, and implemented in InProcessImpl.cpp.
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
   virtual void ActorDealloc() override;
   ~InProcessChild() = default;
--- a/ipc/glue/InProcessParent.cpp
+++ b/ipc/glue/InProcessParent.cpp
@@ -9,28 +9,16 @@
 
 using namespace mozilla::dom;
 
 namespace mozilla {
 namespace ipc {
 
 NS_IMPL_ISUPPORTS(InProcessParent, nsIObserver)
 
-IPCResult InProcessParent::RecvPWindowGlobalConstructor(
-    PWindowGlobalParent* aActor, const WindowGlobalInit& aInit) {
-  static_cast<WindowGlobalParent*>(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<WindowGlobalParent*>(aActor)->Release();
   return true;
 }
 
 }  // namespace ipc
-}  // namespace mozilla
\ No newline at end of file
+}  // namespace mozilla
--- a/ipc/glue/InProcessParent.h
+++ b/ipc/glue/InProcessParent.h
@@ -40,25 +40,18 @@ class InProcessParent : public nsIObserv
   static InProcessParent* Singleton();
 
   // Get the child side of the in-process child actor |aActor|. If |aActor| is
   // not an in-process actor, or is not connected, this method will return
   // |nullptr|.
   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;
   virtual void ActorDealloc() override;
   ~InProcessParent() = default;
 
   static void Startup();
   static void Shutdown();
--- a/ipc/glue/PInProcess.ipdl
+++ b/ipc/glue/PInProcess.ipdl
@@ -17,19 +17,12 @@ namespace ipc {
  * Chrome->Chrome circumstances.
  *
  * `mozilla::ipc::InProcess{Parent, Child}::Singleton()` should be used to get
  * an instance of this actor.
  */
 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
 } // namespace mozilla
--- a/ipc/ipdl/ipdl/type.py
+++ b/ipc/ipdl/ipdl/type.py
@@ -969,17 +969,17 @@ class GatherDecls(TcheckVisitor):
             seenmgrs.add(mgr.name)
             mgr.of = p
             mgr.accept(self)
 
         for managed in p.managesStmts:
             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)
 
         setattr(self, 'currentProtocolDecl', p.decl)
         for msg in p.messageDecls:
             msg.accept(self)
         del self.currentProtocolDecl