Bug 1208371 - Turn DOMMediaStream::PrincipalChangeObserver into PrincipalChangeObserver<DOMMediaStream>. r?mt
MozReview-Commit-ID: JkBUEGdavZX
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -788,23 +788,25 @@ DOMMediaStream::NotifyPrincipalChanged()
{
for (uint32_t i = 0; i < mPrincipalChangeObservers.Length(); ++i) {
mPrincipalChangeObservers[i]->PrincipalChanged(this);
}
}
bool
-DOMMediaStream::AddPrincipalChangeObserver(PrincipalChangeObserver* aObserver)
+DOMMediaStream::AddPrincipalChangeObserver(
+ PrincipalChangeObserver<DOMMediaStream>* aObserver)
{
return mPrincipalChangeObservers.AppendElement(aObserver) != nullptr;
}
bool
-DOMMediaStream::RemovePrincipalChangeObserver(PrincipalChangeObserver* aObserver)
+DOMMediaStream::RemovePrincipalChangeObserver(
+ PrincipalChangeObserver<DOMMediaStream>* aObserver)
{
return mPrincipalChangeObservers.RemoveElement(aObserver);
}
MediaStreamTrack*
DOMMediaStream::CreateOwnDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
const nsString& aLabel,
MediaStreamTrackSource* aSource)
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -11,16 +11,17 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "StreamBuffer.h"
#include "nsIDOMWindow.h"
#include "nsIPrincipal.h"
#include "mozilla/PeerIdentity.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/CORSMode.h"
+#include "PrincipalChangeObserver.h"
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
// GetTickCount() and conflicts with NS_DECL_NSIDOMMEDIASTREAM, containing
// currentTime getter.
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
// X11 has a #define for CurrentTime. Unbelievable :-(.
@@ -451,27 +452,18 @@ public:
/**
* This is used in WebRTC to move from a protected state (nsNullPrincipal) to
* one where the stream is accessible to script. Don't call this.
* CombineWithPrincipal is almost certainly more appropriate.
*/
void SetPrincipal(nsIPrincipal* aPrincipal);
- /**
- * Used to learn about dynamic changes in principal occur.
- * Operations relating to these observers must be confined to the main thread.
- */
- class PrincipalChangeObserver
- {
- public:
- virtual void PrincipalChanged(DOMMediaStream* aMediaStream) = 0;
- };
- bool AddPrincipalChangeObserver(PrincipalChangeObserver* aObserver);
- bool RemovePrincipalChangeObserver(PrincipalChangeObserver* aObserver);
+ bool AddPrincipalChangeObserver(dom::PrincipalChangeObserver<DOMMediaStream>* aObserver);
+ bool RemovePrincipalChangeObserver(dom::PrincipalChangeObserver<DOMMediaStream>* aObserver);
/**
* Called when this stream's MediaStreamGraph has been shut down. Normally
* MSGs are only shut down when all streams have been removed, so this
* will only be called during a forced shutdown due to application exit.
*/
void NotifyMediaStreamGraphShutdown();
/**
@@ -647,17 +639,17 @@ protected:
nsTArray<RefPtr<TrackListener>> mTrackListeners;
private:
void NotifyPrincipalChanged();
// Principal identifying who may access the contents of this stream.
// If null, this stream can be used by anyone because it has no content yet.
nsCOMPtr<nsIPrincipal> mPrincipal;
- nsTArray<PrincipalChangeObserver*> mPrincipalChangeObservers;
+ nsTArray<dom::PrincipalChangeObserver<DOMMediaStream>*> mPrincipalChangeObservers;
// this is used in gUM and WebRTC to identify peers that this stream
// is allowed to be sent to
nsAutoPtr<PeerIdentity> mPeerIdentity;
CORSMode mCORSMode;
};
NS_DEFINE_STATIC_IID_ACCESSOR(DOMMediaStream,
NS_DOMMEDIASTREAM_IID)
--- a/dom/media/imagecapture/CaptureTask.h
+++ b/dom/media/imagecapture/CaptureTask.h
@@ -23,31 +23,31 @@ class ImageCapture;
* class into MediaStream and retrieves an image in MediaStreamGraph thread.
* Once the image is retrieved, it will be sent to ImageEncoder and the encoded
* blob will be sent out via encoder callback in main thread.
*
* CaptureTask holds a reference of ImageCapture to ensure ImageCapture won't be
* released during the period of the capturing process described above.
*/
class CaptureTask : public MediaStreamListener,
- public DOMMediaStream::PrincipalChangeObserver
+ public dom::PrincipalChangeObserver<DOMMediaStream>
{
public:
// MediaStreamListener methods.
void NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
StreamTime aTrackOffset,
uint32_t aTrackEvents,
const MediaSegment& aQueuedMedia,
MediaStream* aInputStream,
TrackID aInputTrackID) override;
void NotifyEvent(MediaStreamGraph* aGraph,
MediaStreamGraphEvent aEvent) override;
- // DOMMediaStream::PrincipalChangeObserver method.
+ // PrincipalChangeObserver<DOMMediaStream> method.
void PrincipalChanged(DOMMediaStream* aMediaStream) override;
// CaptureTask methods.
// It is called when aBlob is ready to post back to script in company with
// aRv == NS_OK. If aRv is not NS_OK, it will post an error event to script.
//
// Note:
--- a/dom/media/imagecapture/ImageCapture.cpp
+++ b/dom/media/imagecapture/ImageCapture.cpp
@@ -73,17 +73,17 @@ ImageCapture::GetVideoStreamTrack() cons
}
nsresult
ImageCapture::TakePhotoByMediaEngine()
{
// Callback for TakPhoto(), it also monitor the principal. If principal
// changes, it returns PHOTO_ERROR with security error.
class TakePhotoCallback : public MediaEnginePhotoCallback,
- public DOMMediaStream::PrincipalChangeObserver
+ public PrincipalChangeObserver<DOMMediaStream>
{
public:
TakePhotoCallback(VideoStreamTrack* aVideoTrack, ImageCapture* aImageCapture)
: mVideoTrack(aVideoTrack)
, mImageCapture(aImageCapture)
, mPrincipalChanged(false)
{
MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/webaudio/MediaStreamAudioSourceNode.h
+++ b/dom/media/webaudio/MediaStreamAudioSourceNode.h
@@ -36,17 +36,17 @@ public:
}
}
private:
bool mEnabled;
};
class MediaStreamAudioSourceNode : public AudioNode,
- public DOMMediaStream::PrincipalChangeObserver
+ public PrincipalChangeObserver<DOMMediaStream>
{
public:
static already_AddRefed<MediaStreamAudioSourceNode>
Create(AudioContext* aContext, DOMMediaStream* aStream, ErrorResult& aRv);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamAudioSourceNode, AudioNode)
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -244,17 +244,17 @@ class RTCStatsQuery {
nsresult res = CheckApiState(assert_ice_ready); \
if (NS_FAILED(res)) return; \
} while(0)
#define PC_AUTO_ENTER_API_CALL_NO_CHECK() CheckThread()
class PeerConnectionImpl final : public nsISupports,
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
public mozilla::DataChannelConnection::DataConnectionListener,
- public DOMMediaStream::PrincipalChangeObserver,
+ public dom::PrincipalChangeObserver<DOMMediaStream>,
#endif
public sigslot::has_slots<>
{
struct Internal; // Avoid exposing c includes to bindings
public:
explicit PeerConnectionImpl(const mozilla::dom::GlobalObject* aGlobal = nullptr);