Bug 1208371 - Make remaining DOMMediaStream principal sources use MediaStreamTrack. r=mt

MozReview-Commit-ID: 1hgHp5dlBZJ

--HG--
extra : rebase_source : 30d7d5bccc663ef00a640b4f385278a336191088
This commit is contained in:
Andreas Pehrson 2016-02-01 22:46:34 +08:00
Родитель 4ce83c6b90
Коммит 58ac7b5fd2
7 изменённых файлов: 33 добавлений и 45 удалений

Просмотреть файл

@ -331,11 +331,6 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
// we are not user/DOM facing anyway.
CreateAndAddPlaybackStreamListener(mInput);
MOZ_ASSERT(mWindow, "Shouldn't be created with a null window!");
if (mWindow->GetExtantDoc()) {
CombineWithPrincipal(mWindow->GetExtantDoc()->NodePrincipal());
}
// Register a listener for camera events.
mListener = new DOMCameraControlListener(this, mInput);
mCameraControl->AddListener(mListener);
@ -526,11 +521,17 @@ nsDOMCameraControl::GetCameraStream() const
void
nsDOMCameraControl::TrackCreated(TrackID aTrackID) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(mWindow, "Shouldn't have been created with a null window!");
nsIPrincipal* principal = mWindow->GetExtantDoc()
? mWindow->GetExtantDoc()->NodePrincipal()
: nullptr;
// This track is not connected through a port.
MediaInputPort* inputPort = nullptr;
dom::VideoStreamTrack* track =
new dom::VideoStreamTrack(this, aTrackID, aTrackID, nsString(),
new BasicUnstoppableTrackSource());
new BasicUnstoppableTrackSource(principal));
RefPtr<TrackPort> port =
new TrackPort(inputPort, track,
TrackPort::InputPortOwnership::OWNED);

Просмотреть файл

@ -673,9 +673,6 @@ HTMLCanvasElement::CaptureStream(const Optional<double>& aFrameRate,
return nullptr;
}
RefPtr<nsIPrincipal> principal = NodePrincipal();
stream->CombineWithPrincipal(principal);
TrackID videoTrackId = 1;
nsresult rv = stream->Init(aFrameRate, videoTrackId);
if (NS_FAILED(rv)) {
@ -683,8 +680,9 @@ HTMLCanvasElement::CaptureStream(const Optional<double>& aFrameRate,
return nullptr;
}
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
stream->CreateOwnDOMTrack(videoTrackId, MediaSegment::VIDEO, nsString(),
new BasicUnstoppableTrackSource());
new BasicUnstoppableTrackSource(principal));
rv = RegisterFrameCaptureListener(stream->FrameCaptureListener());
if (NS_FAILED(rv)) {

Просмотреть файл

@ -148,7 +148,10 @@ public:
}
if (!source) {
NS_ASSERTION(false, "Dynamic track created without an explicit TrackSource");
source = new BasicUnstoppableTrackSource();
nsPIDOMWindowInner* window = mStream->GetParentObject();
nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
nsIPrincipal* principal = doc ? doc->NodePrincipal() : nullptr;
source = new BasicUnstoppableTrackSource(principal);
}
track = mStream->CreateOwnDOMTrack(aTrackID, aType, nsString(), source);
}
@ -656,12 +659,12 @@ DOMMediaStream::InitTrackUnionStream(MediaStreamGraph* aGraph)
}
void
DOMMediaStream::InitAudioCaptureStream(MediaStreamGraph* aGraph)
DOMMediaStream::InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGraph* aGraph)
{
const TrackID AUDIO_TRACK = 1;
RefPtr<BasicUnstoppableTrackSource> audioCaptureSource =
new BasicUnstoppableTrackSource(MediaSourceEnum::AudioCapture);
new BasicUnstoppableTrackSource(aPrincipal, MediaSourceEnum::AudioCapture);
AudioCaptureStream* audioCaptureStream =
static_cast<AudioCaptureStream*>(aGraph->CreateAudioCaptureStream(this, AUDIO_TRACK));
@ -737,11 +740,13 @@ DOMMediaStream::CreateTrackUnionStream(nsPIDOMWindowInner* aWindow,
already_AddRefed<DOMMediaStream>
DOMMediaStream::CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal,
MediaStreamGraph* aGraph)
{
// Audio capture doesn't create tracks dynamically
MediaStreamTrackSourceGetter* getter = nullptr;
RefPtr<DOMMediaStream> stream = new DOMMediaStream(aWindow, getter);
stream->InitAudioCaptureStream(aGraph);
stream->InitAudioCaptureStream(aPrincipal, aGraph);
return stream.forget();
}
@ -1108,17 +1113,6 @@ DOMLocalMediaStream::CreateTrackUnionStream(nsPIDOMWindowInner* aWindow,
return stream.forget();
}
already_AddRefed<DOMLocalMediaStream>
DOMLocalMediaStream::CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
MediaStreamGraph* aGraph)
{
// AudioCapture doesn't create tracks dynamically
MediaStreamTrackSourceGetter* getter = nullptr;
RefPtr<DOMLocalMediaStream> stream = new DOMLocalMediaStream(aWindow, getter);
stream->InitAudioCaptureStream(aGraph);
return stream.forget();
}
DOMAudioNodeMediaStream::DOMAudioNodeMediaStream(nsPIDOMWindowInner* aWindow, AudioNode* aNode)
: DOMMediaStream(aWindow, nullptr),
mStreamNode(aNode)

Просмотреть файл

@ -512,7 +512,9 @@ public:
* AudioCaptureStream.
*/
static already_AddRefed<DOMMediaStream>
CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow, MediaStreamGraph* aGraph);
CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aPrincipal,
MediaStreamGraph* aGraph);
void SetLogicalStreamStartTime(StreamTime aTime)
{
@ -559,7 +561,7 @@ protected:
void Destroy();
void InitSourceStream(MediaStreamGraph* aGraph);
void InitTrackUnionStream(MediaStreamGraph* aGraph);
void InitAudioCaptureStream(MediaStreamGraph* aGraph);
void InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGraph* aGraph);
// Sets up aStream as mInputStream. A producer may append data to a
// SourceMediaStream input stream, or connect another stream to a
@ -710,13 +712,6 @@ public:
MediaStreamGraph* aGraph,
MediaStreamTrackSourceGetter* aTrackSourceGetter = nullptr);
/**
* Create an nsDOMLocalMediaStream whose underlying stream is an
* AudioCaptureStream. */
static already_AddRefed<DOMLocalMediaStream>
CreateAudioCaptureStream(nsPIDOMWindowInner* aWindow,
MediaStreamGraph* aGraph);
protected:
virtual ~DOMLocalMediaStream();

Просмотреть файл

@ -891,7 +891,7 @@ public:
MediaStreamGraph::GetInstance(graphDriverType,
dom::AudioChannel::Normal);
RefPtr<DOMLocalMediaStream> domStream;
RefPtr<DOMMediaStream> domStream;
RefPtr<SourceMediaStream> stream;
// AudioCapture is a special case, here, in the sense that we're not really
// using the audio source and the SourceMediaStream, which acts as
@ -899,10 +899,12 @@ public:
// them down instead.
if (mAudioDevice &&
mAudioDevice->GetMediaSource() == MediaSourceEnum::AudioCapture) {
domStream = DOMLocalMediaStream::CreateAudioCaptureStream(window, msg);
// It should be possible to pipe the capture stream to anything. CORS is
// not a problem here, we got explicit user content.
domStream->SetPrincipal(window->GetExtantDoc()->NodePrincipal());
nsCOMPtr<nsIPrincipal> principal = window->GetExtantDoc()->NodePrincipal();
domStream =
DOMMediaStream::CreateAudioCaptureStream(window, principal, msg);
stream = msg->CreateSourceStream(nullptr); // Placeholder
msg->RegisterCaptureStreamForWindow(
mWindowID, domStream->GetInputStream()->AsProcessedStream());

Просмотреть файл

@ -143,9 +143,10 @@ protected:
class BasicUnstoppableTrackSource : public MediaStreamTrackSource
{
public:
explicit BasicUnstoppableTrackSource(const MediaSourceEnum aMediaSource =
explicit BasicUnstoppableTrackSource(nsIPrincipal* aPrincipal,
const MediaSourceEnum aMediaSource =
MediaSourceEnum::Other)
: MediaStreamTrackSource(nullptr, true), mMediaSource(aMediaSource) {}
: MediaStreamTrackSource(aPrincipal, true), mMediaSource(aMediaSource) {}
MediaSourceEnum GetMediaSource() const override { return mMediaSource; }

Просмотреть файл

@ -35,8 +35,10 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* a
aContext->Graph()))
{
// Ensure an audio track with the correct ID is exposed to JS
nsIDocument* doc = aContext->GetParentObject()->GetExtantDoc();
RefPtr<MediaStreamTrackSource> source =
new BasicUnstoppableTrackSource(MediaSourceEnum::AudioCapture);
new BasicUnstoppableTrackSource(doc->NodePrincipal(),
MediaSourceEnum::AudioCapture);
mDOMStream->CreateOwnDOMTrack(AudioNodeStream::AUDIO_TRACK,
MediaSegment::AUDIO, nsString(), source);
@ -46,11 +48,6 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* a
mStream = AudioNodeStream::Create(aContext, engine,
AudioNodeStream::EXTERNAL_OUTPUT);
mPort = outputStream->AllocateInputPort(mStream, AudioNodeStream::AUDIO_TRACK);
nsIDocument* doc = aContext->GetParentObject()->GetExtantDoc();
if (doc) {
mDOMStream->CombineWithPrincipal(doc->NodePrincipal());
}
}
MediaStreamAudioDestinationNode::~MediaStreamAudioDestinationNode()