Bug 1452741. Stop using the no-arg DOMEventTargetHelper constructor in MediaTrack. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 11 Apr 2018 10:27:00 -0400
changeset 412845 a0710c21795a24888a15da8edc39699f0598c53d
parent 412844 d7d2f08e051c3c355d41dc5c1ce1bd3ca55a43b9
child 412846 38849d14221add83ac6bc32a71c781a6497fef72
push id33820
push usershindli@mozilla.com
push dateWed, 11 Apr 2018 23:46:03 +0000
treeherdermozilla-central@1a9a362b9288 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1452741
milestone61.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 1452741. Stop using the no-arg DOMEventTargetHelper constructor in MediaTrack. r=bkelly MozReview-Commit-ID: AbE3XJdj4KO
dom/html/HTMLMediaElement.cpp
dom/media/AudioTrack.cpp
dom/media/AudioTrack.h
dom/media/MediaTrack.cpp
dom/media/MediaTrack.h
dom/media/MediaTrackList.cpp
dom/media/MediaTrackList.h
dom/media/VideoTrack.cpp
dom/media/VideoTrack.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5228,36 +5228,40 @@ void HTMLMediaElement::EndSrcMediaStream
     }
     ms.mTrackPorts.Clear();
   }
 
   mSrcStream = nullptr;
 }
 
 static already_AddRefed<AudioTrack>
-CreateAudioTrack(AudioStreamTrack* aStreamTrack)
+CreateAudioTrack(AudioStreamTrack* aStreamTrack,
+                 nsIGlobalObject* aOwnerGlobal)
 {
   nsAutoString id;
   nsAutoString label;
   aStreamTrack->GetId(id);
   aStreamTrack->GetLabel(label, CallerType::System);
 
-  return MediaTrackList::CreateAudioTrack(id, NS_LITERAL_STRING("main"),
+  return MediaTrackList::CreateAudioTrack(aOwnerGlobal,
+                                          id, NS_LITERAL_STRING("main"),
                                           label, EmptyString(), true);
 }
 
 static already_AddRefed<VideoTrack>
-CreateVideoTrack(VideoStreamTrack* aStreamTrack)
+CreateVideoTrack(VideoStreamTrack* aStreamTrack,
+                 nsIGlobalObject* aOwnerGlobal)
 {
   nsAutoString id;
   nsAutoString label;
   aStreamTrack->GetId(id);
   aStreamTrack->GetLabel(label, CallerType::System);
 
-  return MediaTrackList::CreateVideoTrack(id, NS_LITERAL_STRING("main"),
+  return MediaTrackList::CreateVideoTrack(aOwnerGlobal,
+                                          id, NS_LITERAL_STRING("main"),
                                           label, EmptyString(),
                                           aStreamTrack);
 }
 
 void
 HTMLMediaElement::NotifyMediaStreamTrackAdded(const RefPtr<MediaStreamTrack>& aTrack)
 {
   MOZ_ASSERT(aTrack);
@@ -5271,24 +5275,26 @@ HTMLMediaElement::NotifyMediaStreamTrack
   aTrack->GetId(id);
 
   LOG(LogLevel::Debug, ("%p, Adding %sTrack with id %s",
                         this, aTrack->AsAudioStreamTrack() ? "Audio" : "Video",
                         NS_ConvertUTF16toUTF8(id).get()));
 #endif
 
   if (AudioStreamTrack* t = aTrack->AsAudioStreamTrack()) {
-    RefPtr<AudioTrack> audioTrack = CreateAudioTrack(t);
+    RefPtr<AudioTrack> audioTrack =
+      CreateAudioTrack(t, AudioTracks()->GetOwnerGlobal());
     AudioTracks()->AddTrack(audioTrack);
   } else if (VideoStreamTrack* t = aTrack->AsVideoStreamTrack()) {
     // TODO: Fix this per the spec on bug 1273443.
     if (!IsVideo()) {
       return;
     }
-    RefPtr<VideoTrack> videoTrack = CreateVideoTrack(t);
+    RefPtr<VideoTrack> videoTrack =
+      CreateVideoTrack(t, VideoTracks()->GetOwnerGlobal());
     VideoTracks()->AddTrack(videoTrack);
     // New MediaStreamTrack added, set the new added video track as selected
     // video track when there is no selected track.
     if (VideoTracks()->SelectedIndex() == -1) {
       MOZ_ASSERT(!mSelectedVideoStreamTrack);
       videoTrack->SetEnabledInternal(true, MediaTrack::FIRE_NO_EVENTS);
     }
   }
@@ -7685,27 +7691,30 @@ HTMLMediaElement::ConstructMediaTracks(c
     return;
   }
 
   mMediaTracksConstructed = true;
 
   AudioTrackList* audioList = AudioTracks();
   if (audioList && aInfo->HasAudio()) {
     const TrackInfo& info = aInfo->mAudio;
-    RefPtr<AudioTrack> track = MediaTrackList::CreateAudioTrack(
-    info.mId, info.mKind, info.mLabel, info.mLanguage, info.mEnabled);
+    RefPtr<AudioTrack> track =
+      MediaTrackList::CreateAudioTrack(audioList->GetOwnerGlobal(), info.mId,
+                                       info.mKind, info.mLabel, info.mLanguage,
+                                       info.mEnabled);
 
     audioList->AddTrack(track);
   }
 
   VideoTrackList* videoList = VideoTracks();
   if (videoList && aInfo->HasVideo()) {
     const TrackInfo& info = aInfo->mVideo;
-    RefPtr<VideoTrack> track = MediaTrackList::CreateVideoTrack(
-    info.mId, info.mKind, info.mLabel, info.mLanguage);
+    RefPtr<VideoTrack> track =
+      MediaTrackList::CreateVideoTrack(videoList->GetOwnerGlobal(), info.mId,
+                                       info.mKind, info.mLabel, info.mLanguage);
 
     videoList->AddTrack(track);
     track->SetEnabledInternal(info.mEnabled, MediaTrack::FIRE_NO_EVENTS);
   }
 }
 
 void
 HTMLMediaElement::RemoveMediaTracks()
--- a/dom/media/AudioTrack.cpp
+++ b/dom/media/AudioTrack.cpp
@@ -7,22 +7,23 @@
 #include "mozilla/dom/AudioTrack.h"
 #include "mozilla/dom/AudioTrackBinding.h"
 #include "mozilla/dom/AudioTrackList.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 
 namespace mozilla {
 namespace dom {
 
-AudioTrack::AudioTrack(const nsAString& aId,
+AudioTrack::AudioTrack(nsIGlobalObject* aOwnerGlobal,
+                       const nsAString& aId,
                        const nsAString& aKind,
                        const nsAString& aLabel,
                        const nsAString& aLanguage,
                        bool aEnabled)
-  : MediaTrack(aId, aKind, aLabel, aLanguage)
+  : MediaTrack(aOwnerGlobal, aId, aKind, aLabel, aLanguage)
   , mEnabled(aEnabled)
 {
 }
 
 JSObject*
 AudioTrack::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return AudioTrackBinding::Wrap(aCx, this, aGivenProto);
--- a/dom/media/AudioTrack.h
+++ b/dom/media/AudioTrack.h
@@ -10,17 +10,18 @@
 #include "MediaTrack.h"
 
 namespace mozilla {
 namespace dom {
 
 class AudioTrack : public MediaTrack
 {
 public:
-  AudioTrack(const nsAString& aId,
+  AudioTrack(nsIGlobalObject* aOwnerGlobal,
+             const nsAString& aId,
              const nsAString& aKind,
              const nsAString& aLabel,
              const nsAString& aLanguage,
              bool aEnabled);
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   AudioTrack* AsAudioTrack() override
--- a/dom/media/MediaTrack.cpp
+++ b/dom/media/MediaTrack.cpp
@@ -7,21 +7,22 @@
 #include "MediaTrack.h"
 #include "AudioTrack.h"
 #include "MediaTrackList.h"
 #include "VideoTrack.h"
 
 namespace mozilla {
 namespace dom {
 
-MediaTrack::MediaTrack(const nsAString& aId,
+MediaTrack::MediaTrack(nsIGlobalObject* aOwnerGlobal,
+                       const nsAString& aId,
                        const nsAString& aKind,
                        const nsAString& aLabel,
                        const nsAString& aLanguage)
-  : DOMEventTargetHelper()
+  : DOMEventTargetHelper(aOwnerGlobal)
   , mId(aId)
   , mKind(aKind)
   , mLabel(aLabel)
   , mLanguage(aLanguage)
 {
 }
 
 MediaTrack::~MediaTrack()
@@ -36,16 +37,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 void
 MediaTrack::SetTrackList(MediaTrackList* aList)
 {
   mList = aList;
 }
 
-void
-MediaTrack::Init(nsPIDOMWindowInner* aOwnerWindow)
-{
-  BindToOwner(aOwnerWindow);
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/MediaTrack.h
+++ b/dom/media/MediaTrack.h
@@ -28,17 +28,18 @@ class AudioTrack;
  * from its corresponding track list.
  *
  * Although AudioTrack and VideoTrack are not EventTargets, TextTrack is, and
  * TextTrack inherits from MediaTrack as well (or is going to).
  */
 class MediaTrack : public DOMEventTargetHelper
 {
 public:
-  MediaTrack(const nsAString& aId,
+  MediaTrack(nsIGlobalObject* aOwnerGlobal,
+             const nsAString& aId,
              const nsAString& aKind,
              const nsAString& aLabel,
              const nsAString& aLanguage);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaTrack, DOMEventTargetHelper)
 
   enum {
@@ -84,17 +85,16 @@ public:
   }
 
   friend class MediaTrackList;
 
 protected:
   virtual ~MediaTrack();
 
   void SetTrackList(MediaTrackList* aList);
-  void Init(nsPIDOMWindowInner* aOwnerWindow);
 
   RefPtr<MediaTrackList> mList;
   nsString mId;
   nsString mKind;
   nsString mLabel;
   nsString mLanguage;
 };
 
--- a/dom/media/MediaTrackList.cpp
+++ b/dom/media/MediaTrackList.cpp
@@ -63,18 +63,19 @@ MediaTrackList::GetTrackById(const nsASt
     }
   }
   return nullptr;
 }
 
 void
 MediaTrackList::AddTrack(MediaTrack* aTrack)
 {
+  MOZ_ASSERT(aTrack->GetOwnerGlobal() == GetOwnerGlobal(),
+             "Where is this track from?");
   mTracks.AppendElement(aTrack);
-  aTrack->Init(GetOwner());
   aTrack->SetTrackList(this);
   CreateAndDispatchTrackEventRunner(aTrack, NS_LITERAL_STRING("addtrack"));
 
   if ((!aTrack->AsAudioTrack() || !aTrack->AsAudioTrack()->Enabled()) &&
       (!aTrack->AsVideoTrack() || !aTrack->AsVideoTrack()->Selected())) {
     // Track not enabled, no need to notify media element.
     return;
   }
@@ -98,35 +99,39 @@ MediaTrackList::RemoveTracks()
 {
   while (!mTracks.IsEmpty()) {
     RefPtr<MediaTrack> track = mTracks.LastElement();
     RemoveTrack(track);
   }
 }
 
 already_AddRefed<AudioTrack>
-MediaTrackList::CreateAudioTrack(const nsAString& aId,
+MediaTrackList::CreateAudioTrack(nsIGlobalObject* aOwnerGlobal,
+                                 const nsAString& aId,
                                  const nsAString& aKind,
                                  const nsAString& aLabel,
                                  const nsAString& aLanguage,
                                  bool aEnabled)
 {
-  RefPtr<AudioTrack> track = new AudioTrack(aId, aKind, aLabel, aLanguage,
-                                              aEnabled);
+  RefPtr<AudioTrack> track = new AudioTrack(aOwnerGlobal,
+                                            aId, aKind, aLabel, aLanguage,
+                                            aEnabled);
   return track.forget();
 }
 
 already_AddRefed<VideoTrack>
-MediaTrackList::CreateVideoTrack(const nsAString& aId,
+MediaTrackList::CreateVideoTrack(nsIGlobalObject* aOwnerGlobal,
+                                 const nsAString& aId,
                                  const nsAString& aKind,
                                  const nsAString& aLabel,
                                  const nsAString& aLanguage,
                                  VideoStreamTrack* aVideoTrack)
 {
-  RefPtr<VideoTrack> track = new VideoTrack(aId, aKind, aLabel, aLanguage, aVideoTrack);
+  RefPtr<VideoTrack> track = new VideoTrack(aOwnerGlobal, aId, aKind, aLabel,
+                                            aLanguage, aVideoTrack);
   return track.forget();
 }
 
 void
 MediaTrackList::EmptyTracks()
 {
   for (uint32_t i = 0; i < mTracks.Length(); ++i) {
     mTracks[i]->SetEnabledInternal(false, MediaTrack::FIRE_NO_EVENTS);
--- a/dom/media/MediaTrackList.h
+++ b/dom/media/MediaTrackList.h
@@ -39,35 +39,38 @@ public:
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaTrackList, DOMEventTargetHelper)
 
   using DOMEventTargetHelper::DispatchTrustedEvent;
 
   // The return value is non-null, assert an error if aIndex is out of bound
   // for array mTracks.
   MediaTrack* operator[](uint32_t aIndex);
 
+  // The track must be from the same Window as this MediaTrackList.
   void AddTrack(MediaTrack* aTrack);
 
   // In remove track case, the VideoTrackList::mSelectedIndex should be updated
   // due to mTracks changed. No need to take care this in add track case.
   virtual void RemoveTrack(const RefPtr<MediaTrack>& aTrack);
 
   void RemoveTracks();
 
   static already_AddRefed<AudioTrack>
-  CreateAudioTrack(const nsAString& aId,
+  CreateAudioTrack(nsIGlobalObject* aOwnerGlobal,
+                   const nsAString& aId,
                    const nsAString& aKind,
                    const nsAString& aLabel,
                    const nsAString& aLanguage,
                    bool aEnabled);
 
   // For the case of src of HTMLMediaElement is non-MediaStream, leave the
   // aVideoTrack as default(nullptr).
   static already_AddRefed<VideoTrack>
-  CreateVideoTrack(const nsAString& aId,
+  CreateVideoTrack(nsIGlobalObject* aOwnerGlobal,
+                   const nsAString& aId,
                    const nsAString& aKind,
                    const nsAString& aLabel,
                    const nsAString& aLanguage,
                    VideoStreamTrack* aVideoTrack = nullptr);
 
   virtual void EmptyTracks();
 
   void CreateAndDispatchChangeEvent();
--- a/dom/media/VideoTrack.cpp
+++ b/dom/media/VideoTrack.cpp
@@ -8,22 +8,23 @@
 #include "mozilla/dom/VideoStreamTrack.h"
 #include "mozilla/dom/VideoTrack.h"
 #include "mozilla/dom/VideoTrackBinding.h"
 #include "mozilla/dom/VideoTrackList.h"
 
 namespace mozilla {
 namespace dom {
 
-VideoTrack::VideoTrack(const nsAString& aId,
+VideoTrack::VideoTrack(nsIGlobalObject* aOwnerGlobal,
+                       const nsAString& aId,
                        const nsAString& aKind,
                        const nsAString& aLabel,
                        const nsAString& aLanguage,
                        VideoStreamTrack* aStreamTarck)
-  : MediaTrack(aId, aKind, aLabel, aLanguage)
+  : MediaTrack(aOwnerGlobal, aId, aKind, aLabel, aLanguage)
   , mSelected(false)
   , mVideoStreamTrack(aStreamTarck)
 {
 }
 
 VideoTrack::~VideoTrack()
 {
 }
--- a/dom/media/VideoTrack.h
+++ b/dom/media/VideoTrack.h
@@ -13,17 +13,18 @@ namespace mozilla {
 namespace dom {
 
 class VideoTrackList;
 class VideoStreamTrack;
 
 class VideoTrack : public MediaTrack
 {
 public:
-  VideoTrack(const nsAString& aId,
+  VideoTrack(nsIGlobalObject* aOwnerGlobal,
+             const nsAString& aId,
              const nsAString& aKind,
              const nsAString& aLabel,
              const nsAString& aLanguage,
              VideoStreamTrack* aStreamTarck = nullptr);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(VideoTrack, MediaTrack)