diff --git a/dom/media/gmp/ChromiumCDMChild.h b/dom/media/gmp/ChromiumCDMChild.h index a4dc6983f562..cb790b9fda41 100644 --- a/dom/media/gmp/ChromiumCDMChild.h +++ b/dom/media/gmp/ChromiumCDMChild.h @@ -20,7 +20,9 @@ class ChromiumCDMChild : public PChromiumCDMChild, public cdm::Host_9, public cdm::Host_10 { public: - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMChild); + // Mark AddRef and Release as `final`, as they overload pure virtual + // implementations in PChromiumCDMChild. + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMChild, final); explicit ChromiumCDMChild(GMPContentChild* aPlugin); diff --git a/dom/media/gmp/ChromiumCDMParent.h b/dom/media/gmp/ChromiumCDMParent.h index 89f8115b0acf..bb8f4c3c0d94 100644 --- a/dom/media/gmp/ChromiumCDMParent.h +++ b/dom/media/gmp/ChromiumCDMParent.h @@ -36,7 +36,9 @@ class ChromiumCDMParent final : public PChromiumCDMParent, public: typedef MozPromise InitPromise; - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMParent) + // Mark AddRef and Release as `final`, as they overload pure virtual + // implementations in PChromiumCDMParent. + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMParent, final) ChromiumCDMParent(GMPContentParent* aContentParent, uint32_t aPluginId); diff --git a/dom/media/gmp/GMPContentChild.cpp b/dom/media/gmp/GMPContentChild.cpp index 7fcebc89f1a7..f1914c05cf66 100644 --- a/dom/media/gmp/GMPContentChild.cpp +++ b/dom/media/gmp/GMPContentChild.cpp @@ -61,15 +61,8 @@ bool GMPContentChild::DeallocPGMPVideoEncoderChild( return true; } -PChromiumCDMChild* GMPContentChild::AllocPChromiumCDMChild() { - ChromiumCDMChild* actor = new ChromiumCDMChild(this); - actor->AddRef(); - return actor; -} - -bool GMPContentChild::DeallocPChromiumCDMChild(PChromiumCDMChild* aActor) { - static_cast(aActor)->Release(); - return true; +already_AddRefed GMPContentChild::AllocPChromiumCDMChild() { + return MakeAndAddRef(this); } mozilla::ipc::IPCResult GMPContentChild::RecvPGMPVideoDecoderConstructor( diff --git a/dom/media/gmp/GMPContentChild.h b/dom/media/gmp/GMPContentChild.h index c2ba9b500aa8..07d952a57cdf 100644 --- a/dom/media/gmp/GMPContentChild.h +++ b/dom/media/gmp/GMPContentChild.h @@ -35,8 +35,7 @@ class GMPContentChild : public PGMPContentChild, public GMPSharedMem { PGMPVideoEncoderChild* AllocPGMPVideoEncoderChild(); bool DeallocPGMPVideoEncoderChild(PGMPVideoEncoderChild* aActor); - PChromiumCDMChild* AllocPChromiumCDMChild(); - bool DeallocPChromiumCDMChild(PChromiumCDMChild* aActor); + already_AddRefed AllocPChromiumCDMChild(); void ActorDestroy(ActorDestroyReason aWhy) override; void ProcessingError(Result aCode, const char* aReason) override; diff --git a/dom/media/gmp/GMPContentParent.cpp b/dom/media/gmp/GMPContentParent.cpp index a26c6600a2b1..2664ae22e2f5 100644 --- a/dom/media/gmp/GMPContentParent.cpp +++ b/dom/media/gmp/GMPContentParent.cpp @@ -162,11 +162,11 @@ nsCOMPtr GMPContentParent::GMPEventTarget() { already_AddRefed GMPContentParent::GetChromiumCDM() { GMP_LOG("GMPContentParent::GetChromiumCDM(this=%p)", this); - PChromiumCDMParent* actor = SendPChromiumCDMConstructor(); - if (!actor) { + + RefPtr parent = new ChromiumCDMParent(this, GetPluginId()); + if (!SendPChromiumCDMConstructor(parent)) { return nullptr; } - RefPtr parent = static_cast(actor); // TODO: Remove parent from mChromiumCDMs in ChromiumCDMParent::Destroy(). mChromiumCDMs.AppendElement(parent); @@ -209,13 +209,6 @@ nsresult GMPContentParent::GetGMPVideoEncoder(GMPVideoEncoderParent** aGMPVE) { return NS_OK; } -PChromiumCDMParent* GMPContentParent::AllocPChromiumCDMParent() { - GMP_LOG("GMPContentParent::AllocPChromiumCDMParent(this=%p)", this); - ChromiumCDMParent* parent = new ChromiumCDMParent(this, GetPluginId()); - NS_ADDREF(parent); - return parent; -} - PGMPVideoDecoderParent* GMPContentParent::AllocPGMPVideoDecoderParent( const uint32_t& aDecryptorId) { GMP_LOG("GMPContentParent::AllocPGMPVideoDecoderParent(this=%p)", this); @@ -224,14 +217,6 @@ PGMPVideoDecoderParent* GMPContentParent::AllocPGMPVideoDecoderParent( return vdp; } -bool GMPContentParent::DeallocPChromiumCDMParent(PChromiumCDMParent* aActor) { - GMP_LOG("GMPContentParent::DeallocPChromiumCDMParent(this=%p, aActor=%p)", - this, aActor); - ChromiumCDMParent* parent = static_cast(aActor); - NS_RELEASE(parent); - return true; -} - bool GMPContentParent::DeallocPGMPVideoDecoderParent( PGMPVideoDecoderParent* aActor) { GMP_LOG("GMPContentParent::DeallocPGMPVideoDecoderParent(this=%p, aActor=%p)", diff --git a/dom/media/gmp/GMPContentParent.h b/dom/media/gmp/GMPContentParent.h index fe750b81c686..f4e0c9fad58c 100644 --- a/dom/media/gmp/GMPContentParent.h +++ b/dom/media/gmp/GMPContentParent.h @@ -76,9 +76,6 @@ class GMPContentParent final : public PGMPContentParent, public GMPSharedMem { PGMPVideoEncoderParent* AllocPGMPVideoEncoderParent() override; bool DeallocPGMPVideoEncoderParent(PGMPVideoEncoderParent* aActor) override; - PChromiumCDMParent* AllocPChromiumCDMParent() override; - bool DeallocPChromiumCDMParent(PChromiumCDMParent* aActor) override; - void CloseIfUnused(); // Needed because NewRunnableMethod tried to use the class that the method // lives on to store the receiver, but PGMPContentParent isn't refcounted. diff --git a/dom/media/gmp/PChromiumCDM.ipdl b/dom/media/gmp/PChromiumCDM.ipdl index 01a2bb86cdc6..f0bb3eef2a88 100644 --- a/dom/media/gmp/PChromiumCDM.ipdl +++ b/dom/media/gmp/PChromiumCDM.ipdl @@ -9,7 +9,7 @@ include GMPTypes; namespace mozilla { namespace gmp { -async protocol PChromiumCDM +async refcounted protocol PChromiumCDM { manager PGMPContent; child: