diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 64749e0e5815..bf54b993390e 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -24,11 +24,6 @@ include protocol PImageBridge; include protocol PMedia; include protocol PMemoryReportRequest; include protocol PNecko; -// FIXME This is pretty ridiculous, but we have to keep the order of the -// following 4 includes, or the parser is confused about PGMPContent -// bridging PContent and PGMP. As soon as it registers the bridge between -// PContent and PPluginModule it seems to think that PContent's parent and -// child live in the same process! include protocol PGMPContent; include protocol PGMPService; include protocol PPluginModule; diff --git a/dom/media/gmp/GMPChild.cpp b/dom/media/gmp/GMPChild.cpp index b7bd06202212..47cedcb8c86a 100644 --- a/dom/media/gmp/GMPChild.cpp +++ b/dom/media/gmp/GMPChild.cpp @@ -515,15 +515,13 @@ GMPChild::RecvCloseActive() return IPC_OK(); } -PGMPContentChild* -GMPChild::AllocPGMPContentChild(Transport* aTransport, - ProcessId aOtherPid) +mozilla::ipc::IPCResult +GMPChild::RecvInitGMPContentChild(Endpoint&& aEndpoint) { GMPContentChild* child = mGMPContentChildren.AppendElement(new GMPContentChild(this))->get(); - child->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop(), ipc::ChildSide); - - return child; + aEndpoint.Bind(child); + return IPC_OK(); } void diff --git a/dom/media/gmp/GMPChild.h b/dom/media/gmp/GMPChild.h index 9efa08243a5a..833acb2f4159 100644 --- a/dom/media/gmp/GMPChild.h +++ b/dom/media/gmp/GMPChild.h @@ -56,13 +56,13 @@ private: PGMPStorageChild* AllocPGMPStorageChild() override; bool DeallocPGMPStorageChild(PGMPStorageChild* aActor) override; - PGMPContentChild* AllocPGMPContentChild(Transport* aTransport, - ProcessId aOtherPid) override; void GMPContentChildActorDestroy(GMPContentChild* aGMPContentChild); mozilla::ipc::IPCResult RecvCrashPluginNow() override; mozilla::ipc::IPCResult RecvCloseActive() override; + mozilla::ipc::IPCResult RecvInitGMPContentChild(Endpoint&& aEndpoint) override; + void ActorDestroy(ActorDestroyReason aWhy) override; void ProcessingError(Result aCode, const char* aReason) override; diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index c0c1a23d0a4e..ba918e123907 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -892,19 +892,32 @@ GMPParent::ResolveGetContentParentPromises() } } -PGMPContentParent* -GMPParent::AllocPGMPContentParent(Transport* aTransport, ProcessId aOtherPid) +bool +GMPParent::OpenPGMPContent() { MOZ_ASSERT(GMPThread() == NS_GetCurrentThread()); MOZ_ASSERT(!mGMPContentParent); + Endpoint parent; + Endpoint child; + if (NS_FAILED(PGMPContent::CreateEndpoints(base::GetCurrentProcId(), + OtherPid(), &parent, &child))) { + return false; + } + mGMPContentParent = new GMPContentParent(this); - mGMPContentParent->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop(), - ipc::ParentSide); + + if (!parent.Bind(mGMPContentParent)) { + return false; + } + + if (!SendInitGMPContentChild(Move(child))) { + return false; + } ResolveGetContentParentPromises(); - return mGMPContentParent; + return true; } void @@ -935,7 +948,7 @@ GMPParent::GetGMPContentParent(UniquePtr>&& aPromiseHolder); already_AddRefed ForgetGMPContentParent(); bool EnsureProcessLoaded(base::ProcessId* aID); - bool Bridge(GMPServiceParent* aGMPServiceParent); + void IncrementGMPContentChildCount(); const nsTArray& GetCapabilities() const { return mCapabilities; } @@ -175,9 +177,6 @@ private: PGMPStorageParent* AllocPGMPStorageParent() override; bool DeallocPGMPStorageParent(PGMPStorageParent* aActor) override; - PGMPContentParent* AllocPGMPContentParent(Transport* aTransport, - ProcessId aOtherPid) override; - mozilla::ipc::IPCResult RecvPGMPTimerConstructor(PGMPTimerParent* actor) override; PGMPTimerParent* AllocPGMPTimerParent() override; bool DeallocPGMPTimerParent(PGMPTimerParent* aActor) override; diff --git a/dom/media/gmp/GMPServiceChild.cpp b/dom/media/gmp/GMPServiceChild.cpp index a15f0010dd83..f9ff7331b7dc 100644 --- a/dom/media/gmp/GMPServiceChild.cpp +++ b/dom/media/gmp/GMPServiceChild.cpp @@ -80,6 +80,8 @@ GeckoMediaPluginServiceChild::GetContentParent(GMPCrashHelper* aHelper, base::ProcessId otherProcess; nsCString displayName; uint32_t pluginId = 0; + ipc::Endpoint endpoint; + bool ok = child->SendLaunchGMP(nodeId, api, tags, @@ -87,7 +89,9 @@ GeckoMediaPluginServiceChild::GetContentParent(GMPCrashHelper* aHelper, &pluginId, &otherProcess, &displayName, + &endpoint, &rv); + if (helper && pluginId) { // Note: Even if the launch failed, we need to connect the crash // helper so that if the launch failed due to the plugin crashing, @@ -103,12 +107,13 @@ GeckoMediaPluginServiceChild::GetContentParent(GMPCrashHelper* aHelper, return; } - RefPtr parent; - child->GetBridgedGMPContentParent(otherProcess, getter_AddRefs(parent)); + RefPtr parent = child->GetBridgedGMPContentParent(otherProcess, + Move(endpoint)); if (!alreadyBridgedTo.Contains(otherProcess)) { parent->SetDisplayName(displayName); parent->SetPluginId(pluginId); } + RefPtr blocker(new GMPContentParent::CloseBlocker(parent)); holder->Resolve(blocker, __func__); }, @@ -339,31 +344,30 @@ GMPServiceChild::~GMPServiceChild() { } -PGMPContentParent* -GMPServiceChild::AllocPGMPContentParent(Transport* aTransport, - ProcessId aOtherPid) +already_AddRefed +GMPServiceChild::GetBridgedGMPContentParent(ProcessId aOtherPid, + ipc::Endpoint&& endpoint) { - MOZ_ASSERT(!mContentParents.GetWeak(aOtherPid)); + RefPtr parent; + mContentParents.Get(aOtherPid, getter_AddRefs(parent)); + + if (parent) { + return parent.forget(); + } + + MOZ_ASSERT(aOtherPid == endpoint.OtherPid()); nsCOMPtr mainThread = do_GetMainThread(); MOZ_ASSERT(mainThread); - RefPtr parent = new GMPContentParent(); + parent = new GMPContentParent(); - DebugOnly ok = parent->Open(aTransport, aOtherPid, - XRE_GetIOMessageLoop(), - mozilla::ipc::ParentSide); + DebugOnly ok = endpoint.Bind(parent); MOZ_ASSERT(ok); mContentParents.Put(aOtherPid, parent); - return parent; -} -void -GMPServiceChild::GetBridgedGMPContentParent(ProcessId aOtherPid, - GMPContentParent** aGMPContentParent) -{ - mContentParents.Get(aOtherPid, aGMPContentParent); + return parent.forget(); } void diff --git a/dom/media/gmp/GMPServiceChild.h b/dom/media/gmp/GMPServiceChild.h index 19da05c0767d..a4fcc443c6bb 100644 --- a/dom/media/gmp/GMPServiceChild.h +++ b/dom/media/gmp/GMPServiceChild.h @@ -70,11 +70,9 @@ public: explicit GMPServiceChild(); virtual ~GMPServiceChild(); - PGMPContentParent* AllocPGMPContentParent(Transport* aTransport, - ProcessId aOtherPid) override; + already_AddRefed GetBridgedGMPContentParent(ProcessId aOtherPid, + ipc::Endpoint&& endpoint); - void GetBridgedGMPContentParent(ProcessId aOtherPid, - GMPContentParent** aGMPContentParent); void RemoveGMPContentParent(GMPContentParent* aGMPContentParent); void GetAlreadyBridgedTo(nsTArray& aAlreadyBridgedTo); diff --git a/dom/media/gmp/GMPServiceParent.cpp b/dom/media/gmp/GMPServiceParent.cpp index fffc6365865a..3cf77c427758 100644 --- a/dom/media/gmp/GMPServiceParent.cpp +++ b/dom/media/gmp/GMPServiceParent.cpp @@ -1675,6 +1675,7 @@ GMPServiceParent::RecvLaunchGMP(const nsCString& aNodeId, uint32_t* aOutPluginId, ProcessId* aOutProcessId, nsCString* aOutDisplayName, + Endpoint* aOutEndpoint, nsresult* aOutRv) { if (mService->IsShuttingDown()) { @@ -1698,11 +1699,28 @@ GMPServiceParent::RecvLaunchGMP(const nsCString& aNodeId, *aOutDisplayName = gmp->GetDisplayName(); - if (!(aAlreadyBridgedTo.Contains(*aOutProcessId) || gmp->Bridge(this))) { + if (aAlreadyBridgedTo.Contains(*aOutProcessId)) { + *aOutRv = NS_OK; + return IPC_OK(); + } + + Endpoint parent; + Endpoint child; + if (NS_FAILED(PGMPContent::CreateEndpoints(OtherPid(), *aOutProcessId, + &parent, &child))) { *aOutRv = NS_ERROR_FAILURE; return IPC_OK(); } + *aOutEndpoint = Move(parent); + + if (!gmp->SendInitGMPContentChild(Move(child))) { + *aOutRv = NS_ERROR_FAILURE; + return IPC_OK(); + } + + gmp->IncrementGMPContentChildCount(); + *aOutRv = NS_OK; return IPC_OK(); } diff --git a/dom/media/gmp/GMPServiceParent.h b/dom/media/gmp/GMPServiceParent.h index 8b31b1d9cfff..343ead7138e5 100644 --- a/dom/media/gmp/GMPServiceParent.h +++ b/dom/media/gmp/GMPServiceParent.h @@ -234,6 +234,7 @@ public: uint32_t* aOutPluginId, ProcessId* aOutID, nsCString* aOutDisplayName, + Endpoint* aOutEndpoint, nsresult* aOutRv) override; private: diff --git a/dom/media/gmp/PGMP.ipdl b/dom/media/gmp/PGMP.ipdl index beb7931cd36f..5e6c90905626 100644 --- a/dom/media/gmp/PGMP.ipdl +++ b/dom/media/gmp/PGMP.ipdl @@ -15,8 +15,6 @@ namespace gmp { intr protocol PGMP { - parent opens PGMPContent; - manages PCrashReporter; manages PGMPTimer; manages PGMPStorage; @@ -34,6 +32,7 @@ child: async SetNodeId(nsCString nodeId); async PreloadLibs(nsCString libs); async CloseActive(); + async InitGMPContentChild(Endpoint endpoint); }; } // namespace gmp diff --git a/dom/media/gmp/PGMPContent.ipdl b/dom/media/gmp/PGMPContent.ipdl index e45c0f9f5ca8..186694bdea61 100644 --- a/dom/media/gmp/PGMPContent.ipdl +++ b/dom/media/gmp/PGMPContent.ipdl @@ -3,8 +3,6 @@ * 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 protocol PGMP; -include protocol PGMPService; include protocol PGMPVideoDecoder; include protocol PGMPVideoEncoder; include protocol PGMPDecryptor; @@ -14,8 +12,6 @@ namespace gmp { intr protocol PGMPContent { - bridges PGMPService, PGMP; - manages PGMPDecryptor; manages PGMPVideoDecoder; manages PGMPVideoEncoder; diff --git a/dom/media/gmp/PGMPService.ipdl b/dom/media/gmp/PGMPService.ipdl index 4bd01603a2b7..8d9cfb634564 100644 --- a/dom/media/gmp/PGMPService.ipdl +++ b/dom/media/gmp/PGMPService.ipdl @@ -3,7 +3,7 @@ * 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 protocol PGMP; +include protocol PGMPContent; using base::ProcessId from "base/process.h"; @@ -12,15 +12,16 @@ namespace gmp { sync protocol PGMPService { - parent spawns PGMP as child; - parent: - sync LaunchGMP(nsCString nodeId, nsCString api, nsCString[] tags, ProcessId[] alreadyBridgedTo) - returns (uint32_t pluginId, ProcessId id, nsCString displayName, nsresult aResult); + returns (uint32_t pluginId, + ProcessId id, + nsCString displayName, + Endpoint endpoint, + nsresult aResult); sync GetGMPNodeId(nsString origin, nsString topLevelOrigin, nsString gmpName) returns (nsCString id);