Bug 856361. Part 2: Block data from a non-same-origin media resource entering a MediaStream from a media element. r=cpearce

--HG--
extra : rebase_source : fd0ac711b6be627b87634b5a6c518c82ffd46448
This commit is contained in:
Robert O'Callahan 2013-07-24 21:55:23 +12:00
Родитель 2923cf289f
Коммит 2224bafd05
4 изменённых файлов: 36 добавлений и 1 удалений

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

@ -3251,9 +3251,16 @@ already_AddRefed<nsIPrincipal> HTMLMediaElement::GetCurrentPrincipal()
void HTMLMediaElement::NotifyDecoderPrincipalChanged()
{
nsRefPtr<nsIPrincipal> principal = GetCurrentPrincipal();
if (mDecoder) {
bool subsumes;
mDecoder->UpdateSameOriginStatus(
NS_SUCCEEDED(NodePrincipal()->Subsumes(principal, &subsumes)) && subsumes);
}
for (uint32_t i = 0; i < mOutputStreams.Length(); ++i) {
OutputMediaStream* ms = &mOutputStreams[i];
nsRefPtr<nsIPrincipal> principal = GetCurrentPrincipal();
ms->mStream->CombineWithPrincipal(principal);
}
}

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

@ -368,6 +368,7 @@ MediaDecoder::MediaDecoder() :
mDuration(-1),
mTransportSeekable(true),
mMediaSeekable(true),
mSameOriginMedia(false),
mReentrantMonitor("media.decoder"),
mIsDormant(false),
mPlayState(PLAY_STATE_PAUSED),
@ -842,6 +843,18 @@ void MediaDecoder::DecodeError()
Shutdown();
}
void MediaDecoder::UpdateSameOriginStatus(bool aSameOrigin)
{
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
mSameOriginMedia = aSameOrigin;
}
bool MediaDecoder::IsSameOriginMedia()
{
GetReentrantMonitor().AssertCurrentThreadIn();
return mSameOriginMedia;
}
bool MediaDecoder::IsSeeking() const
{
MOZ_ASSERT(NS_IsMainThread());

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

@ -640,6 +640,10 @@ public:
// The actual playback rate computation. The monitor must be held.
virtual double ComputePlaybackRate(bool* aReliable);
// Return true when the media is same-origin with the element. The monitor
// must be held.
bool IsSameOriginMedia();
// Returns true if we can play the entire media through without stopping
// to buffer, given the current download and playback rates.
bool CanPlayThrough();
@ -736,6 +740,9 @@ public:
// Notifies the element that decoding has failed.
virtual void DecodeError();
// Indicate whether the media is same-origin with the element.
void UpdateSameOriginStatus(bool aSameOrigin);
MediaDecoderOwner* GetOwner() MOZ_OVERRIDE;
#ifdef MOZ_RAW
@ -958,6 +965,10 @@ public:
// True if the media is seekable (i.e. supports random access).
bool mMediaSeekable;
// True if the media is same-origin with the element. Data can only be
// passed to MediaStreams when this is true.
bool mSameOriginMedia;
/******
* The following member variables can be accessed from any thread.
******/

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

@ -619,6 +619,10 @@ void MediaDecoderStateMachine::SendStreamData()
if (mState == DECODER_STATE_DECODING_METADATA)
return;
if (!mDecoder->IsSameOriginMedia()) {
return;
}
// If there's still an audio thread alive, then we can't send any stream
// data yet since both SendStreamData and the audio thread want to be in
// charge of popping the audio queue. We're waiting for the audio thread