Bug 1208371 - Pass parent window to DOMMediaStream through constructor. r=roc
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:20 +0800
changeset 348400 d169710ece91d827c1b9940c671a6bfb65c353c2
parent 348399 f5fe9e219441413c6fc8429050ca19c910b7c62a
child 348401 6a5a585f1a2b69639fb7d20eedaf0b95e34686e1
push id14828
push userpehrsons@gmail.com
push dateThu, 07 Apr 2016 12:57:27 +0000
reviewersroc
bugs1208371
milestone48.0a1
Bug 1208371 - Pass parent window to DOMMediaStream through constructor. r=roc MozReview-Commit-ID: AvBYQNADpyV
dom/camera/DOMCameraControl.cpp
dom/media/CanvasCaptureMediaStream.cpp
dom/media/CanvasCaptureMediaStream.h
dom/media/DOMMediaStream.cpp
dom/media/DOMMediaStream.h
dom/media/MediaManager.cpp
--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -245,17 +245,17 @@ nsDOMCameraControl::DiscardCachedCameraI
   sCachedCameraControl = nullptr;
 }
 #endif
 
 nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
                                        const CameraConfiguration& aInitialConfig,
                                        Promise* aPromise,
                                        nsPIDOMWindowInner* aWindow)
-  : DOMMediaStream()
+  : DOMMediaStream(aWindow)
   , mCameraControl(nullptr)
   , mAudioChannelAgent(nullptr)
   , mGetCameraPromise(aPromise)
   , mWindow(aWindow)
   , mPreviewState(CameraControlListener::kPreviewStopped)
   , mRecording(false)
   , mRecordingStoppedDeferred(false)
   , mSetInitialConfig(false)
--- a/dom/media/CanvasCaptureMediaStream.cpp
+++ b/dom/media/CanvasCaptureMediaStream.cpp
@@ -202,18 +202,20 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Canva
                                    mCanvas)
 
 NS_IMPL_ADDREF_INHERITED(CanvasCaptureMediaStream, DOMMediaStream)
 NS_IMPL_RELEASE_INHERITED(CanvasCaptureMediaStream, DOMMediaStream)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CanvasCaptureMediaStream)
 NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream)
 
-CanvasCaptureMediaStream::CanvasCaptureMediaStream(HTMLCanvasElement* aCanvas)
-  : mCanvas(aCanvas)
+CanvasCaptureMediaStream::CanvasCaptureMediaStream(nsPIDOMWindowInner* aWindow,
+                                                   HTMLCanvasElement* aCanvas)
+  : DOMMediaStream(aWindow)
+  , mCanvas(aCanvas)
   , mOutputStreamDriver(nullptr)
 {
 }
 
 CanvasCaptureMediaStream::~CanvasCaptureMediaStream()
 {
   if (mOutputStreamDriver) {
     mOutputStreamDriver->Forget();
@@ -252,21 +254,21 @@ CanvasCaptureMediaStream::Init(const dom
   }
   return NS_OK;
 }
 
 already_AddRefed<CanvasCaptureMediaStream>
 CanvasCaptureMediaStream::CreateSourceStream(nsPIDOMWindowInner* aWindow,
                                              HTMLCanvasElement* aCanvas)
 {
-  RefPtr<CanvasCaptureMediaStream> stream = new CanvasCaptureMediaStream(aCanvas);
+  RefPtr<CanvasCaptureMediaStream> stream = new CanvasCaptureMediaStream(aWindow, aCanvas);
   MediaStreamGraph* graph =
     MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
                                   AudioChannel::Normal);
-  stream->InitSourceStream(aWindow, graph);
+  stream->InitSourceStream(graph);
   return stream.forget();
 }
 
 FrameCaptureListener*
 CanvasCaptureMediaStream::FrameCaptureListener()
 {
   return mOutputStreamDriver;
 }
--- a/dom/media/CanvasCaptureMediaStream.h
+++ b/dom/media/CanvasCaptureMediaStream.h
@@ -91,17 +91,17 @@ protected:
 private:
   RefPtr<SourceMediaStream> mSourceStream;
   RefPtr<StreamListener> mStreamListener;
 };
 
 class CanvasCaptureMediaStream : public DOMMediaStream
 {
 public:
-  explicit CanvasCaptureMediaStream(HTMLCanvasElement* aCanvas);
+  CanvasCaptureMediaStream(nsPIDOMWindowInner* aWindow, HTMLCanvasElement* aCanvas);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CanvasCaptureMediaStream, DOMMediaStream)
 
   nsresult Init(const dom::Optional<double>& aFPS, const TrackID& aTrackId);
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -312,19 +312,20 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMAu
                                    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), mInputStream(nullptr), mOwnedStream(nullptr),
-    mPlaybackStream(nullptr), mOwnedPort(nullptr), mPlaybackPort(nullptr),
+DOMMediaStream::DOMMediaStream(nsPIDOMWindowInner* aWindow)
+  : mLogicalStreamStartTime(0), mWindow(aWindow),
+    mInputStream(nullptr), mOwnedStream(nullptr), mPlaybackStream(nullptr),
+    mOwnedPort(nullptr), mPlaybackPort(nullptr),
     mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false),
     mCORSMode(CORS_NONE)
 {
   nsresult rv;
   nsCOMPtr<nsIUUIDGenerator> uuidgen =
     do_GetService("@mozilla.org/uuid-generator;1", &rv);
 
   if (NS_SUCCEEDED(rv) && uuidgen) {
@@ -420,18 +421,17 @@ DOMMediaStream::Constructor(const Global
                             ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindowInner> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
   if (!ownerWindow) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  RefPtr<DOMMediaStream> newStream = new DOMMediaStream();
-  newStream->mWindow = ownerWindow;
+  RefPtr<DOMMediaStream> newStream = new DOMMediaStream(ownerWindow);
 
   for (MediaStreamTrack& track : aTracks) {
     if (!newStream->GetPlaybackStream()) {
       MOZ_RELEASE_ASSERT(track.GetStream());
       MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream());
       MOZ_RELEASE_ASSERT(track.GetStream()->GetPlaybackStream()->Graph());
       MediaStreamGraph* graph = track.GetStream()->GetPlaybackStream()->Graph();
       newStream->InitPlaybackStreamCommon(graph);
@@ -592,41 +592,34 @@ DOMMediaStream::OwnsTrack(const MediaStr
 
 bool
 DOMMediaStream::IsFinished()
 {
   return !mPlaybackStream || mPlaybackStream->IsFinished();
 }
 
 void
-DOMMediaStream::InitSourceStream(nsPIDOMWindowInner* aWindow,
-                                 MediaStreamGraph* aGraph)
+DOMMediaStream::InitSourceStream(MediaStreamGraph* aGraph)
 {
-  mWindow = aWindow;
   InitInputStreamCommon(aGraph->CreateSourceStream(nullptr), aGraph);
   InitOwnedStreamCommon(aGraph);
   InitPlaybackStreamCommon(aGraph);
 }
 
 void
-DOMMediaStream::InitTrackUnionStream(nsPIDOMWindowInner* aWindow,
-                                     MediaStreamGraph* aGraph)
+DOMMediaStream::InitTrackUnionStream(MediaStreamGraph* aGraph)
 {
-  mWindow = aWindow;
   InitInputStreamCommon(aGraph->CreateTrackUnionStream(nullptr), aGraph);
   InitOwnedStreamCommon(aGraph);
   InitPlaybackStreamCommon(aGraph);
 }
 
 void
-DOMMediaStream::InitAudioCaptureStream(nsPIDOMWindowInner* aWindow,
-                                       MediaStreamGraph* aGraph)
+DOMMediaStream::InitAudioCaptureStream(MediaStreamGraph* aGraph)
 {
-  mWindow = aWindow;
-
   const TrackID AUDIO_TRACK = 1;
 
   InitInputStreamCommon(aGraph->CreateAudioCaptureStream(this, AUDIO_TRACK), aGraph);
   InitOwnedStreamCommon(aGraph);
   InitPlaybackStreamCommon(aGraph);
   CreateOwnDOMTrack(AUDIO_TRACK, MediaSegment::AUDIO, nsString());
 }
 
@@ -672,36 +665,36 @@ DOMMediaStream::InitPlaybackStreamCommon
   LOG(LogLevel::Debug, ("DOMMediaStream %p Initiated with mInputStream=%p, mOwnedStream=%p, mPlaybackStream=%p",
                         this, mInputStream, mOwnedStream, mPlaybackStream));
 }
 
 already_AddRefed<DOMMediaStream>
 DOMMediaStream::CreateSourceStream(nsPIDOMWindowInner* aWindow,
                                    MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMMediaStream> stream = new DOMMediaStream();
-  stream->InitSourceStream(aWindow, aGraph);
+  RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow);
+  stream->InitSourceStream(aGraph);
   return stream.forget();
 }
 
 already_AddRefed<DOMMediaStream>
 DOMMediaStream::CreateTrackUnionStream(nsPIDOMWindowInner* aWindow,
                                        MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMMediaStream> stream = new DOMMediaStream();
-  stream->InitTrackUnionStream(aWindow, aGraph);
+  RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow);
+  stream->InitTrackUnionStream(aGraph);
   return stream.forget();
 }
 
 already_AddRefed<DOMMediaStream>
 DOMMediaStream::CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
                                          MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMMediaStream> stream = new DOMMediaStream();
-  stream->InitAudioCaptureStream(aWindow, aGraph);
+  RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow);
+  stream->InitAudioCaptureStream(aGraph);
   return stream.forget();
 }
 
 void
 DOMMediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
 {
   // XXX Bug 1208371 - This enables/disables the track across clones.
   if (mInputStream) {
@@ -1011,76 +1004,78 @@ DOMLocalMediaStream::StopImpl()
     mInputStream->AsSourceStream()->EndAllTrackAndFinish();
   }
 }
 
 already_AddRefed<DOMLocalMediaStream>
 DOMLocalMediaStream::CreateSourceStream(nsPIDOMWindowInner* aWindow,
                                         MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
-  stream->InitSourceStream(aWindow, aGraph);
+  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream(aWindow);
+  stream->InitSourceStream(aGraph);
   return stream.forget();
 }
 
 already_AddRefed<DOMLocalMediaStream>
 DOMLocalMediaStream::CreateTrackUnionStream(nsPIDOMWindowInner* aWindow,
                                             MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
-  stream->InitTrackUnionStream(aWindow, aGraph);
+  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream(aWindow);
+  stream->InitTrackUnionStream(aGraph);
   return stream.forget();
 }
 
 already_AddRefed<DOMLocalMediaStream>
 DOMLocalMediaStream::CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
                                               MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream();
-  stream->InitAudioCaptureStream(aWindow, aGraph);
+  RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream(aWindow);
+  stream->InitAudioCaptureStream(aGraph);
   return stream.forget();
 }
 
-DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(AudioNode* aNode)
-: mStreamNode(aNode)
+DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(nsPIDOMWindowInner* aWindow, AudioNode* aNode)
+  : DOMMediaStream(aWindow),
+    mStreamNode(aNode)
 {
 }
 
 DOMAudioNodeMediaStream::~DOMAudioNodeMediaStream()
 {
 }
 
 already_AddRefed<DOMAudioNodeMediaStream>
 DOMAudioNodeMediaStream::CreateTrackUnionStream(nsPIDOMWindowInner* aWindow,
                                                 AudioNode* aNode,
                                                 MediaStreamGraph* aGraph)
 {
-  RefPtr<DOMAudioNodeMediaStream> stream = new DOMAudioNodeMediaStream(aNode);
-  stream->InitTrackUnionStream(aWindow, aGraph);
+  RefPtr<DOMAudioNodeMediaStream> stream = new DOMAudioNodeMediaStream(aWindow, aNode);
+  stream->InitTrackUnionStream(aGraph);
   return stream.forget();
 }
 
-DOMHwMediaStream::DOMHwMediaStream()
+DOMHwMediaStream::DOMHwMediaStream(nsPIDOMWindowInner* aWindow)
+  : DOMLocalMediaStream(aWindow)
 {
 }
 
 DOMHwMediaStream::~DOMHwMediaStream()
 {
 }
 
 already_AddRefed<DOMHwMediaStream>
 DOMHwMediaStream::CreateHwStream(nsPIDOMWindowInner* aWindow,
                                  OverlayImage* aImage)
 {
-  RefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream();
+  RefPtr<DOMHwMediaStream> stream = new DOMHwMediaStream(aWindow);
 
   MediaStreamGraph* graph =
     MediaStreamGraph::GetInstance(MediaStreamGraph::SYSTEM_THREAD_DRIVER,
                                   AudioChannel::Normal);
-  stream->InitSourceStream(aWindow, graph);
+  stream->InitSourceStream(graph);
   stream->Init(stream->GetInputStream(), aImage);
 
   return stream.forget();
 }
 
 void
 DOMHwMediaStream::Init(MediaStream* stream, OverlayImage* aImage)
 {
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -278,17 +278,17 @@ public:
     RefPtr<MediaInputPort> mInputPort;
     RefPtr<MediaStreamTrack> mTrack;
 
     // Defines if we've been given ownership of the input port or if it's owned
     // externally. The owner is responsible for destroying the port.
     const InputPortOwnership mOwnership;
   };
 
- DOMMediaStream();
+  explicit DOMMediaStream(nsPIDOMWindowInner* aWindow);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMMediaStream,
                                            DOMEventTargetHelper)
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMMEDIASTREAM_IID)
 
   nsPIDOMWindowInner* GetParentObject() const
@@ -506,19 +506,19 @@ public:
 
   void RegisterTrackListener(TrackListener* aListener);
   void UnregisterTrackListener(TrackListener* aListener);
 
 protected:
   virtual ~DOMMediaStream();
 
   void Destroy();
-  void InitSourceStream(nsPIDOMWindowInner* aWindow, MediaStreamGraph* aGraph);
-  void InitTrackUnionStream(nsPIDOMWindowInner* aWindow, MediaStreamGraph* aGraph);
-  void InitAudioCaptureStream(nsPIDOMWindowInner* aWindow, MediaStreamGraph* aGraph);
+  void InitSourceStream(MediaStreamGraph* aGraph);
+  void InitTrackUnionStream(MediaStreamGraph* aGraph);
+  void InitAudioCaptureStream(MediaStreamGraph* aGraph);
 
   // Sets up aStream as mInputStream. A producer may append data to a
   // SourceMediaStream input stream, or connect another stream to a
   // TrackUnionStream input stream.
   void InitInputStreamCommon(MediaStream* aStream, MediaStreamGraph* aGraph);
 
   // Sets up a new TrackUnionStream as mOwnedStream and connects it to
   // mInputStream with a TRACK_ANY MediaInputPort if available.
@@ -624,17 +624,18 @@ NS_DEFINE_STATIC_IID_ACCESSOR(DOMMediaSt
 
 #define NS_DOMLOCALMEDIASTREAM_IID \
 { 0xb1437260, 0xec61, 0x4dfa, \
   { 0x92, 0x54, 0x04, 0x44, 0xe2, 0xb5, 0x94, 0x9c } }
 
 class DOMLocalMediaStream : public DOMMediaStream
 {
 public:
-  DOMLocalMediaStream() {}
+  explicit DOMLocalMediaStream(nsPIDOMWindowInner* aWindow)
+    : DOMMediaStream(aWindow) {}
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMLOCALMEDIASTREAM_IID)
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void Stop();
 
@@ -669,17 +670,17 @@ protected:
 
 NS_DEFINE_STATIC_IID_ACCESSOR(DOMLocalMediaStream,
                               NS_DOMLOCALMEDIASTREAM_IID)
 
 class DOMAudioNodeMediaStream : public DOMMediaStream
 {
   typedef dom::AudioNode AudioNode;
 public:
-  explicit DOMAudioNodeMediaStream(AudioNode* aNode);
+  DOMAudioNodeMediaStream(nsPIDOMWindowInner* aWindow, AudioNode* aNode);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream)
 
   /**
    * Create a DOMAudioNodeMediaStream whose underlying stream is a TrackUnionStream.
    */
   static already_AddRefed<DOMAudioNodeMediaStream>
@@ -700,17 +701,17 @@ class DOMHwMediaStream : public DOMLocal
 {
   typedef mozilla::gfx::IntSize IntSize;
   typedef layers::OverlayImage OverlayImage;
 #ifdef MOZ_WIDGET_GONK
   typedef layers::OverlayImage::Data Data;
 #endif
 
 public:
-  DOMHwMediaStream();
+  explicit DOMHwMediaStream(nsPIDOMWindowInner* aWindow);
 
   static already_AddRefed<DOMHwMediaStream> CreateHwStream(nsPIDOMWindowInner* aWindow,
                                                            OverlayImage* aImage = nullptr);
   virtual DOMHwMediaStream* AsDOMHwMediaStream() override { return this; }
   int32_t RequestOverlayId();
   void SetOverlayId(int32_t aOverlayId);
   void SetImageSize(uint32_t width, uint32_t height);
   void SetOverlayImage(OverlayImage* aImage);
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -665,26 +665,29 @@ class nsDOMUserMediaStream : public DOML
 public:
   static already_AddRefed<nsDOMUserMediaStream>
   CreateSourceStream(nsPIDOMWindowInner* aWindow,
                      GetUserMediaCallbackMediaStreamListener* aListener,
                      AudioDevice* aAudioDevice,
                      VideoDevice* aVideoDevice,
                      MediaStreamGraph* aMSG)
   {
-    RefPtr<nsDOMUserMediaStream> stream = new nsDOMUserMediaStream(aListener,
+    RefPtr<nsDOMUserMediaStream> stream = new nsDOMUserMediaStream(aWindow,
+                                                                   aListener,
                                                                    aAudioDevice,
-                                                                     aVideoDevice);
-    stream->InitSourceStream(aWindow, aMSG);
+                                                                   aVideoDevice);
+    stream->InitSourceStream(aMSG);
     return stream.forget();
   }
 
-  nsDOMUserMediaStream(GetUserMediaCallbackMediaStreamListener* aListener,
+  nsDOMUserMediaStream(nsPIDOMWindowInner* aWindow,
+                       GetUserMediaCallbackMediaStreamListener* aListener,
                        AudioDevice *aAudioDevice,
                        VideoDevice *aVideoDevice) :
+    DOMLocalMediaStream(aWindow),
     mListener(aListener),
     mAudioDevice(aAudioDevice),
     mVideoDevice(aVideoDevice)
   {}
 
   virtual ~nsDOMUserMediaStream()
   {
     StopImpl();
@@ -2285,17 +2288,17 @@ MediaManager::ToJSArray(SourceSet& aDevi
 
 already_AddRefed<MediaManager::PledgeSourceSet>
 MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
                                    MediaSourceEnum aVideoType,
                                    MediaSourceEnum aAudioType,
                                    bool aFake, bool aFakeTracks)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  nsPIDOMWindowInner* window = 
+  nsPIDOMWindowInner* window =
     nsGlobalWindow::GetInnerWindowWithId(aWindowId)->AsInner();
 
   // This function returns a pledge, a promise-like object with the future result
   RefPtr<PledgeSourceSet> pledge = new PledgeSourceSet();
   uint32_t id = mOutstandingPledges.Append(*pledge);
 
   // To get a device list anonymized for a particular origin, we must:
   // 1. Get an origin-key (for either regular or private browsing)