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',
},
'MediaKeys' : {
'implicitJSContext': [ 'createSession']
},
'MediaKeyStatusMap' : {
'implicitJSContext': [ 'size', 'get', 'has' ]
},

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

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

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

@ -39,7 +39,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaKeySession,
DOMEventTargetHelper)
public:
MediaKeySession(nsPIDOMWindow* aParent,
MediaKeySession(JSContext* aCx,
nsPIDOMWindow* aParent,
MediaKeys* aKeys,
const nsAString& aKeySystem,
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_END
MediaKeyStatusMap::MediaKeyStatusMap(nsPIDOMWindow* aParent)
MediaKeyStatusMap::MediaKeyStatusMap(JSContext* aCx,
nsPIDOMWindow* aParent,
ErrorResult& aRv)
: mParent(aParent)
, mUpdateError(NS_OK)
{
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(aParent))) {
mUpdateError = NS_ERROR_FAILURE;
return;
}
JSContext* cx = jsapi.cx();
mMap = JS::NewMapObject(cx);
mMap = JS::NewMapObject(aCx);
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)
{
AutoJSAPI jsapi;
if (!mMap || NS_WARN_IF(!jsapi.Init(mParent))) {
if (NS_WARN_IF(!jsapi.Init(mParent))) {
return NS_ERROR_FAILURE;
}

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

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

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

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

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

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