Bug 1423241 - Remove a rawptr in HTMLMediaElement. r=jya
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:00:55 +0000
changeset 507043 69551bbbf203a1fe303ba319639094695f887467
parent 507042 7db08b6156f234337e4a87b3f67aec6e8771bf56
child 507044 7964b0b2f8363fbf1e5d3cdcc50b1d279987f1e9
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1423241
milestone65.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 1423241 - Remove a rawptr in HTMLMediaElement. r=jya Differential Revision: https://phabricator.services.mozilla.com/D9099
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5267,52 +5267,64 @@ class HTMLMediaElement::MediaStreamTrack
 public:
   explicit MediaStreamTrackListener(HTMLMediaElement* aElement)
     : mElement(aElement)
   {
   }
 
   void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) override
   {
+    if (!mElement) {
+      return;
+    }
     mElement->NotifyMediaStreamTrackAdded(aTrack);
   }
 
   void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override
   {
+    if (!mElement) {
+      return;
+    }
     mElement->NotifyMediaStreamTrackRemoved(aTrack);
   }
 
   void NotifyActive() override
   {
+    if (!mElement) {
+      return;
+    }
     LOG(LogLevel::Debug,
         ("%p, mSrcStream %p became active",
-         mElement,
+         mElement.get(),
          mElement->mSrcStream.get()));
     mElement->CheckAutoplayDataReady();
   }
 
   void NotifyInactive() override
   {
+    if (!mElement) {
+      return;
+    }
     if (mElement->IsPlaybackEnded()) {
       return;
     }
     LOG(LogLevel::Debug,
         ("%p, mSrcStream %p became inactive",
-         mElement,
+         mElement.get(),
          mElement->mSrcStream.get()));
     MOZ_ASSERT(!mElement->mSrcStream->Active());
     if (mElement->mMediaStreamListener) {
       mElement->mMediaStreamListener->Forget();
     }
     mElement->PlaybackEnded();
     mElement->UpdateReadyStateInternal();
   }
 
 protected:
-  HTMLMediaElement* const mElement;
+  const WeakPtr<HTMLMediaElement> mElement;
 };
 
 void
 HTMLMediaElement::UpdateSrcMediaStreamPlaying(uint32_t aFlags)
 {
   if (!mSrcStream) {
     return;
   }
@@ -5399,18 +5411,18 @@ HTMLMediaElement::SetupSrcMediaStreamPla
   // That's simpler than delaying the events, but probably confusing...
   nsTArray<RefPtr<MediaStreamTrack>> tracks;
   mSrcStream->GetTracks(tracks);
   for (const RefPtr<MediaStreamTrack>& track : tracks) {
     NotifyMediaStreamTrackAdded(track);
   }
 
   mSrcStream->OnTracksAvailable(new MediaStreamTracksAvailableCallback(this));
-  mMediaStreamTrackListener = new MediaStreamTrackListener(this);
-  mSrcStream->RegisterTrackListener(mMediaStreamTrackListener);
+  mMediaStreamTrackListener = MakeUnique<MediaStreamTrackListener>(this);
+  mSrcStream->RegisterTrackListener(mMediaStreamTrackListener.get());
 
   mSrcStream->AddPrincipalChangeObserver(this);
   mSrcStreamVideoPrincipal = mSrcStream->GetVideoPrincipal();
 
   ChangeNetworkState(NETWORK_IDLE);
   ChangeDelayLoadStatus(false);
   CheckAutoplayDataReady();
 
@@ -5429,17 +5441,17 @@ HTMLMediaElement::EndSrcMediaStreamPlayb
     if (mSelectedVideoStreamTrack) {
       mSelectedVideoStreamTrack->RemoveDirectListener(mVideoFrameListener);
     }
     mVideoFrameListener->Forget();
   }
   mSelectedVideoStreamTrack = nullptr;
   mVideoFrameListener = nullptr;
 
-  mSrcStream->UnregisterTrackListener(mMediaStreamTrackListener);
+  mSrcStream->UnregisterTrackListener(mMediaStreamTrackListener.get());
   mMediaStreamTrackListener = nullptr;
   mSrcStreamTracksAvailable = false;
 
   mSrcStream->RemovePrincipalChangeObserver(this);
   mSrcStreamVideoPrincipal = nullptr;
 
   for (OutputMediaStream& ms : mOutputStreams) {
     for (auto pair : ms.mTrackPorts) {
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1759,17 +1759,17 @@ protected:
   bool mDisableVideo = false;
 
   RefPtr<TextTrackManager> mTextTrackManager;
 
   RefPtr<AudioTrackList> mAudioTrackList;
 
   RefPtr<VideoTrackList> mVideoTrackList;
 
-  nsAutoPtr<MediaStreamTrackListener> mMediaStreamTrackListener;
+  UniquePtr<MediaStreamTrackListener> mMediaStreamTrackListener;
 
   // The principal guarding mVideoFrameContainer access when playing a
   // MediaStream.
   nsCOMPtr<nsIPrincipal> mSrcStreamVideoPrincipal;
 
   // True if UnbindFromTree() is called on the element.
   // Note this flag is false when the element is in a phase after creation and
   // before attaching to the DOM tree.