From 54b6628987f09cd921b36da77993c5b4c52ac604 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Sun, 2 Nov 2014 00:56:10 +0100 Subject: [PATCH] Bug 1078017 - Deregister track callbacks before unlinking tracks. r=jesup,jib --- dom/media/DOMMediaStream.cpp | 72 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index e639243958f..e7ec169f6bf 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -20,35 +20,6 @@ using namespace mozilla; using namespace mozilla::dom; -NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMMediaStream, - DOMEventTargetHelper, - mWindow, - mTracks, - mConsumersToKeepAlive); - -NS_IMPL_ADDREF_INHERITED(DOMMediaStream, DOMEventTargetHelper) -NS_IMPL_RELEASE_INHERITED(DOMMediaStream, DOMEventTargetHelper) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMediaStream) - NS_INTERFACE_MAP_ENTRY(DOMMediaStream) -NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) - -NS_IMPL_ADDREF_INHERITED(DOMLocalMediaStream, DOMMediaStream) -NS_IMPL_RELEASE_INHERITED(DOMLocalMediaStream, DOMMediaStream) - -NS_INTERFACE_MAP_BEGIN(DOMLocalMediaStream) - NS_INTERFACE_MAP_ENTRY(DOMLocalMediaStream) -NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream) - -NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream, - mStreamNode) - -NS_IMPL_ADDREF_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream) -NS_IMPL_RELEASE_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream) -NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream) - class DOMMediaStream::StreamListener : public MediaStreamListener { public: explicit StreamListener(DOMMediaStream* aStream) @@ -132,6 +103,49 @@ private: DOMMediaStream* mStream; }; +NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMediaStream) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMediaStream, + DOMEventTargetHelper) + if (tmp->mListener) { + // Make sure |mListener| cannot call back after |mTracks| is collected + tmp->mListener->Forget(); + } + NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mTracks) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsumersToKeepAlive) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMediaStream, + DOMEventTargetHelper) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTracks) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsumersToKeepAlive) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_ADDREF_INHERITED(DOMMediaStream, DOMEventTargetHelper) +NS_IMPL_RELEASE_INHERITED(DOMMediaStream, DOMEventTargetHelper) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMediaStream) + NS_INTERFACE_MAP_ENTRY(DOMMediaStream) +NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) + +NS_IMPL_ADDREF_INHERITED(DOMLocalMediaStream, DOMMediaStream) +NS_IMPL_RELEASE_INHERITED(DOMLocalMediaStream, DOMMediaStream) + +NS_INTERFACE_MAP_BEGIN(DOMLocalMediaStream) + NS_INTERFACE_MAP_ENTRY(DOMLocalMediaStream) +NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream) + +NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream, + mStreamNode) + +NS_IMPL_ADDREF_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream) +NS_IMPL_RELEASE_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMAudioNodeMediaStream) +NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream) + DOMMediaStream::DOMMediaStream() : mLogicalStreamStartTime(0), mStream(nullptr), mHintContents(0), mTrackTypesAvailable(0),