Bug 785671 - nsHTMLMediaElement::mSrcStreamListener should be an nsRefPtr r=roc
authorDavid Zbarsky <dzbarsky@gmail.com>
Sun, 26 Aug 2012 19:33:56 -0400
changeset 105546 1c013be9911e51315e0f55f39306fb6e2fea5134
parent 105545 0fdd937d7a81faad224139abdfa1d1e5eb4d4558
child 105547 9c6cebe4aa59d4c75f6fe013ae26137715133045
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersroc
bugs785671
milestone17.0a1
Bug 785671 - nsHTMLMediaElement::mSrcStreamListener should be an nsRefPtr r=roc
content/html/content/public/nsHTMLMediaElement.h
content/html/content/src/nsHTMLMediaElement.cpp
--- a/content/html/content/public/nsHTMLMediaElement.h
+++ b/content/html/content/public/nsHTMLMediaElement.h
@@ -642,18 +642,18 @@ protected:
   // Holds references to the DOM wrappers for the MediaStreams that we're
   // writing to.
   struct OutputMediaStream {
     nsRefPtr<nsDOMMediaStream> mStream;
     bool mFinishWhenEnded;
   };
   nsTArray<OutputMediaStream> mOutputStreams;
 
-  // Holds a reference to the MediaStreamListener attached to mSrcStream. STRONG!
-  StreamListener* mSrcStreamListener;
+  // Holds a reference to the MediaStreamListener attached to mSrcStream.
+  nsRefPtr<StreamListener> mSrcStreamListener;
 
   // Holds a reference to the first channel we open to the media resource.
   // Once the decoder is created, control over the channel passes to the
   // decoder, and we null out this reference. We must store this in case
   // we need to cancel the channel before control of it passes to the decoder.
   nsCOMPtr<nsIChannel> mChannel;
 
   // Error attribute
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -2596,17 +2596,16 @@ private:
 void nsHTMLMediaElement::SetupSrcMediaStreamPlayback()
 {
   NS_ASSERTION(!mSrcStream && !mSrcStreamListener, "Should have been ended already");
 
   mSrcStream = mSrcAttrStream;
   // XXX if we ever support capturing the output of a media element which is
   // playing a stream, we'll need to add a CombineWithPrincipal call here.
   mSrcStreamListener = new StreamListener(this);
-  NS_ADDREF(mSrcStreamListener);
   GetSrcMediaStream()->AddListener(mSrcStreamListener);
   if (mPaused) {
     GetSrcMediaStream()->ChangeExplicitBlockerCount(1);
   }
   if (mPausedForInactiveDocument) {
     GetSrcMediaStream()->ChangeExplicitBlockerCount(1);
   }
   ChangeDelayLoadStatus(false);
@@ -2622,17 +2621,17 @@ void nsHTMLMediaElement::SetupSrcMediaSt
   ResourceLoaded();
 }
 
 void nsHTMLMediaElement::EndSrcMediaStreamPlayback()
 {
   GetSrcMediaStream()->RemoveListener(mSrcStreamListener);
   // Kill its reference to this element
   mSrcStreamListener->Forget();
-  NS_RELEASE(mSrcStreamListener); // sets to null
+  mSrcStreamListener = nullptr;
   GetSrcMediaStream()->RemoveAudioOutput(this);
   VideoFrameContainer* container = GetVideoFrameContainer();
   if (container) {
     GetSrcMediaStream()->RemoveVideoOutput(container);
     container->GetImageContainer()->SetCurrentImage(nullptr);
   }
   if (mPaused) {
     GetSrcMediaStream()->ChangeExplicitBlockerCount(-1);