Bug 1082239 - Make MediaSourceResource return the script principal of the MediaSource object - r=kinetik

This commit is contained in:
Edwin Flores 2014-10-15 14:17:03 +13:00
Родитель d0757cbfc2
Коммит 17de8a797f
7 изменённых файлов: 40 добавлений и 19 удалений

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

@ -1164,7 +1164,8 @@ nsresult HTMLMediaElement::LoadResource()
return NS_ERROR_FAILURE;
}
mMediaSource = source.forget();
nsRefPtr<MediaResource> resource = MediaSourceDecoder::CreateResource();
nsRefPtr<MediaResource> resource =
MediaSourceDecoder::CreateResource(mMediaSource->GetPrincipal());
return FinishDecoderSetup(decoder, resource, nullptr, nullptr);
}

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

@ -22,6 +22,7 @@
#include "nsDebug.h"
#include "nsError.h"
#include "nsIRunnable.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsPIDOMWindow.h"
#include "nsString.h"
#include "nsThreadUtils.h"
@ -394,12 +395,19 @@ MediaSource::MediaSource(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
, mDuration(UnspecifiedNaN<double>())
, mDecoder(nullptr)
, mPrincipal(nullptr)
, mReadyState(MediaSourceReadyState::Closed)
, mFirstSourceBufferInitialized(false)
{
MOZ_ASSERT(NS_IsMainThread());
mSourceBuffers = new SourceBufferList(this);
mActiveSourceBuffers = new SourceBufferList(this);
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
if (sop) {
mPrincipal = sop->GetPrincipal();
}
MSE_API("MediaSource(%p)::MediaSource(aWindow=%p) mSourceBuffers=%p mActiveSourceBuffers=%p",
this, aWindow, mSourceBuffers.get(), mActiveSourceBuffers.get());
}

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

@ -85,6 +85,11 @@ public:
return mDecoder;
}
nsIPrincipal* GetPrincipal()
{
return mPrincipal;
}
// Called by SourceBuffers to notify this MediaSource that data has
// been evicted from the buffered data. The start and end times
// that were evicted are provided.
@ -128,6 +133,8 @@ private:
nsRefPtr<MediaSourceDecoder> mDecoder;
nsRefPtr<nsIPrincipal> mPrincipal;
MediaSourceReadyState mReadyState;
bool mFirstSourceBufferInitialized;

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

@ -107,9 +107,9 @@ MediaSourceDecoder::Shutdown()
/*static*/
already_AddRefed<MediaResource>
MediaSourceDecoder::CreateResource()
MediaSourceDecoder::CreateResource(nsIPrincipal* aPrincipal)
{
return nsRefPtr<MediaResource>(new MediaSourceResource()).forget();
return nsRefPtr<MediaResource>(new MediaSourceResource(aPrincipal)).forget();
}
void

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

@ -41,7 +41,7 @@ public:
virtual void Shutdown() MOZ_OVERRIDE;
static already_AddRefed<MediaResource> CreateResource();
static already_AddRefed<MediaResource> CreateResource(nsIPrincipal* aPrincipal = nullptr);
void AttachMediaSource(dom::MediaSource* aMediaSource);
void DetachMediaSource();

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

@ -26,12 +26,12 @@ namespace mozilla {
class MediaSourceResource MOZ_FINAL : public MediaResource
{
public:
MediaSourceResource() {}
MediaSourceResource(nsIPrincipal* aPrincipal = nullptr)
: mPrincipal(aPrincipal) {}
virtual nsresult Close() MOZ_OVERRIDE { return NS_OK; }
virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE { UNIMPLEMENTED(); }
virtual void Resume() MOZ_OVERRIDE { UNIMPLEMENTED(); }
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE { UNIMPLEMENTED(); return nullptr; }
virtual bool CanClone() MOZ_OVERRIDE { UNIMPLEMENTED(); return false; }
virtual already_AddRefed<MediaResource> CloneData(MediaDecoder* aDecoder) MOZ_OVERRIDE { UNIMPLEMENTED(); return nullptr; }
virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE { UNIMPLEMENTED(); }
@ -52,6 +52,11 @@ public:
virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) MOZ_OVERRIDE { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE
{
return nsRefPtr<nsIPrincipal>(mPrincipal).forget();
}
virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) MOZ_OVERRIDE
{
UNIMPLEMENTED();
@ -76,6 +81,7 @@ private:
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
nsRefPtr<nsIPrincipal> mPrincipal;
const nsCString mType;
};

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

@ -649,19 +649,18 @@ var gEMETests = [
sessionType:"temporary",
duration:0.47
},
// XXX Bug 1082239
//{
// name:"gizmo-frag-cencinit.mp4",
// fragments: [ "gizmo-frag-cencinit.mp4", "gizmo-frag-cenc1.m4s", "gizmo-frag-cenc2.m4s" ],
// type:"video/mp4; codecs=\"avc1.64000d,mp4a.40.2\"",
// keys: {
// // "keyid" : "key"
// "7e571d037e571d037e571d037e571d03" : "7e5733337e5733337e5733337e573333",
// "7e571d047e571d047e571d047e571d04" : "7e5744447e5744447e5744447e574444",
// },
// sessionType:"temporary",
// duration:2.00,
//},
{
name:"gizmo-frag-cencinit.mp4",
fragments: [ "gizmo-frag-cencinit.mp4", "gizmo-frag-cenc1.m4s", "gizmo-frag-cenc2.m4s" ],
type:"video/mp4; codecs=\"avc1.64000d,mp4a.40.2\"",
keys: {
// "keyid" : "key"
"7e571d037e571d037e571d037e571d03" : "7e5733337e5733337e5733337e573333",
"7e571d047e571d047e571d047e571d04" : "7e5744447e5744447e5744447e574444",
},
sessionType:"temporary",
duration:2.00,
},
];
function checkMetadata(msg, e, test) {