Bug 1128379 - improve error handling in MediaKeys::CreateSession. r=bz

This commit is contained in:
JW Wang 2015-02-01 19:12:00 +01:00
Родитель f8b3431622
Коммит a5730f41d2
7 изменённых файлов: 31 добавлений и 18 удалений

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

@ -633,6 +633,10 @@ DOMInterfaces = {
'headerFile': 'nsIMediaList.h', 'headerFile': 'nsIMediaList.h',
}, },
'MediaKeys' : {
'implicitJSContext': [ 'createSession']
},
'MediaKeyStatusMap' : { 'MediaKeyStatusMap' : {
'implicitJSContext': [ 'size', 'get', 'has' ] 'implicitJSContext': [ 'size', 'get', 'has' ]
}, },

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

@ -36,7 +36,8 @@ NS_IMPL_RELEASE_INHERITED(MediaKeySession, DOMEventTargetHelper)
// unique token. // unique token.
static uint32_t sMediaKeySessionNum = 0; static uint32_t sMediaKeySessionNum = 0;
MediaKeySession::MediaKeySession(nsPIDOMWindow* aParent, MediaKeySession::MediaKeySession(JSContext* aCx,
nsPIDOMWindow* aParent,
MediaKeys* aKeys, MediaKeys* aKeys,
const nsAString& aKeySystem, const nsAString& aKeySystem,
SessionType aSessionType, SessionType aSessionType,
@ -48,9 +49,12 @@ MediaKeySession::MediaKeySession(nsPIDOMWindow* aParent,
, mToken(sMediaKeySessionNum++) , mToken(sMediaKeySessionNum++)
, mIsClosed(false) , mIsClosed(false)
, mUninitialized(true) , mUninitialized(true)
, mKeyStatusMap(new MediaKeyStatusMap(aParent)) , mKeyStatusMap(new MediaKeyStatusMap(aCx, aParent, aRv))
{ {
MOZ_ASSERT(aParent); MOZ_ASSERT(aParent);
if (aRv.Failed()) {
return;
}
mClosed = mKeys->MakePromise(aRv); mClosed = mKeys->MakePromise(aRv);
} }

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

@ -39,7 +39,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession,
DOMEventTargetHelper) DOMEventTargetHelper)
public: public:
MediaKeySession(nsPIDOMWindow* aParent, MediaKeySession(JSContext* aCx,
nsPIDOMWindow* aParent,
MediaKeys* aKeys, MediaKeys* aKeys,
const nsAString& aKeySystem, const nsAString& aKeySystem,
SessionType aSessionType, SessionType aSessionType,

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

@ -37,20 +37,15 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MediaKeyStatusMap)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMap) NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMap)
NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_TRACE_END
MediaKeyStatusMap::MediaKeyStatusMap(nsPIDOMWindow* aParent) MediaKeyStatusMap::MediaKeyStatusMap(JSContext* aCx,
nsPIDOMWindow* aParent,
ErrorResult& aRv)
: mParent(aParent) : mParent(aParent)
, mUpdateError(NS_OK) , mUpdateError(NS_OK)
{ {
AutoJSAPI jsapi; mMap = JS::NewMapObject(aCx);
if (NS_WARN_IF(!jsapi.Init(aParent))) {
mUpdateError = NS_ERROR_FAILURE;
return;
}
JSContext* cx = jsapi.cx();
mMap = JS::NewMapObject(cx);
if (NS_WARN_IF(!mMap)) { if (NS_WARN_IF(!mMap)) {
mUpdateError = NS_ERROR_FAILURE; aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
} }
} }
@ -209,7 +204,7 @@ nsresult
MediaKeyStatusMap::UpdateInternal(const nsTArray<CDMCaps::KeyStatus>& keys) MediaKeyStatusMap::UpdateInternal(const nsTArray<CDMCaps::KeyStatus>& keys)
{ {
AutoJSAPI jsapi; AutoJSAPI jsapi;
if (!mMap || NS_WARN_IF(!jsapi.Init(mParent))) { if (NS_WARN_IF(!jsapi.Init(mParent))) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

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

@ -30,7 +30,9 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeyStatusMap) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeyStatusMap)
public: public:
explicit MediaKeyStatusMap(nsPIDOMWindow* aParent); explicit MediaKeyStatusMap(JSContext* aCx,
nsPIDOMWindow* aParent,
ErrorResult& aRv);
protected: protected:
~MediaKeyStatusMap(); ~MediaKeyStatusMap();

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

@ -359,15 +359,21 @@ MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId)
} }
already_AddRefed<MediaKeySession> already_AddRefed<MediaKeySession>
MediaKeys::CreateSession(SessionType aSessionType, MediaKeys::CreateSession(JSContext* aCx,
SessionType aSessionType,
ErrorResult& aRv) ErrorResult& aRv)
{ {
nsRefPtr<MediaKeySession> session = new MediaKeySession(GetParentObject(), nsRefPtr<MediaKeySession> session = new MediaKeySession(aCx,
GetParentObject(),
this, this,
mKeySystem, mKeySystem,
aSessionType, aSessionType,
aRv); aRv);
if (aRv.Failed()) {
return nullptr;
}
// Add session to the set of sessions awaiting their sessionId being ready. // Add session to the set of sessions awaiting their sessionId being ready.
mPendingSessions.Put(session->Token(), session); mPendingSessions.Put(session->Token(), session);

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

@ -65,7 +65,8 @@ public:
void GetKeySystem(nsString& retval) const; void GetKeySystem(nsString& retval) const;
// JavaScript: MediaKeys.createSession() // JavaScript: MediaKeys.createSession()
already_AddRefed<MediaKeySession> CreateSession(SessionType aSessionType, already_AddRefed<MediaKeySession> CreateSession(JSContext* aCx,
SessionType aSessionType,
ErrorResult& aRv); ErrorResult& aRv);
// JavaScript: MediaKeys.SetServerCertificate() // JavaScript: MediaKeys.SetServerCertificate()