void MediaKeys::ResolvePromise(PromiseId aId) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to resolve a non-existent promise"); return; } if (mPendingSessions.Contains(aId)) { // We should only resolve LoadSession calls via this path, // not CreateSession() promises. nsRefPtr<MediaKeySession> session; if (!mPendingSessions.Get(aId, getter_AddRefs(session)) || !session || session->GetSessionId().IsEmpty()) { NS_WARNING("Received activation for non-existent session!"); promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR); mPendingSessions.Remove(aId); return; } mPendingSessions.Remove(aId); mKeySessions.Put(session->GetSessionId(), session); promise->MaybeResolve(session); } else { promise->MaybeResolve(JS::UndefinedHandleValue); } }
void MediaKeys::ResolvePromise(PromiseId aId) { EME_LOG("MediaKeys[%p]::ResolvePromise(%d)", this, aId); RefPtr<DetailedPromise> promise(RetrievePromise(aId)); if (!promise) { return; } if (mPendingSessions.Contains(aId)) { // We should only resolve LoadSession calls via this path, // not CreateSession() promises. RefPtr<MediaKeySession> session; if (!mPendingSessions.Get(aId, getter_AddRefs(session)) || !session || session->GetSessionId().IsEmpty()) { NS_WARNING("Received activation for non-existent session!"); promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR, NS_LITERAL_CSTRING("CDM LoadSession() returned a different session ID than requested")); mPendingSessions.Remove(aId); return; } mPendingSessions.Remove(aId); mKeySessions.Put(session->GetSessionId(), session); promise->MaybeResolve(session); } else { promise->MaybeResolve(JS::UndefinedHandleValue); } MOZ_ASSERT(!mPromises.Contains(aId)); }
void MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId, const uint32_t aPluginId) { RefPtr<DetailedPromise> promise(RetrievePromise(aId)); if (!promise) { return; } mNodeId = aNodeId; RefPtr<MediaKeys> keys(this); EME_LOG("MediaKeys[%p]::OnCDMCreated() resolve promise id=%d", this, aId); promise->MaybeResolve(keys); if (mCreatePromiseId == aId) { Release(); } MediaKeySystemAccess::NotifyObservers(mParent, mKeySystem, MediaKeySystemStatus::Cdm_created); if (aPluginId) { // Prepare plugin crash reporter. RefPtr<gmp::GeckoMediaPluginService> service = gmp::GeckoMediaPluginService::GetGeckoMediaPluginService(); if (NS_WARN_IF(!service)) { return; } if (NS_WARN_IF(!mParent)) { return; } service->AddPluginCrashedEventTarget(aPluginId, mParent); EME_LOG("MediaKeys[%p]::OnCDMCreated() registered crash handler for pluginId '%i'", this, aPluginId); } }
void MediaKeys::RejectPromise(PromiseId aId, nsresult aExceptionCode, const nsCString& aReason) { EME_LOG("MediaKeys[%p]::RejectPromise(%d, 0x%x)", this, aId, aExceptionCode); RefPtr<DetailedPromise> promise(RetrievePromise(aId)); if (!promise) { return; } if (mPendingSessions.Contains(aId)) { // This promise could be a createSession or loadSession promise, // so we might have a pending session waiting to be resolved into // the promise on success. We've been directed to reject to promise, // so we can throw away the corresponding session object. mPendingSessions.Remove(aId); } MOZ_ASSERT(NS_FAILED(aExceptionCode)); promise->MaybeReject(aExceptionCode, aReason); if (mCreatePromiseId == aId) { // Note: This will probably destroy the MediaKeys object! Release(); } }
void MediaKeys::OnSessionCreated(PromiseId aId, const nsAString& aSessionId) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to resolve a non-existent promise"); return; } MOZ_ASSERT(mPendingSessions.Contains(aId)); nsRefPtr<MediaKeySession> session; bool gotSession = mPendingSessions.Get(aId, getter_AddRefs(session)); // Session has completed creation/loading, remove it from mPendingSessions, // and resolve the promise with it. We store it in mKeySessions, so we can // find it again if we need to send messages to it etc. mPendingSessions.Remove(aId); if (!gotSession || !session) { NS_WARNING("Received activation for non-existent session!"); promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR); return; } session->Init(aSessionId); mKeySessions.Put(aSessionId, session); promise->MaybeResolve(session); }
void MediaKeys::OnSessionLoaded(PromiseId aId, bool aSuccess) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to resolve a non-existent promise"); return; } promise->MaybeResolve(aSuccess); }
void MediaKeys::OnSessionLoaded(PromiseId aId, bool aSuccess) { RefPtr<DetailedPromise> promise(RetrievePromise(aId)); if (!promise) { return; } EME_LOG("MediaKeys[%p]::OnSessionLoaded() resolve promise id=%d", this, aId); promise->MaybeResolve(aSuccess); }
void MediaKeys::OnCDMCreated(PromiseId aId) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to resolve a non-existent promise"); return; } nsRefPtr<MediaKeys> keys(this); promise->MaybeResolve(keys); if (mCreatePromiseId == aId) { Release(); } }
void MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to resolve a non-existent promise"); return; } mNodeId = aNodeId; nsRefPtr<MediaKeys> keys(this); promise->MaybeResolve(keys); if (mCreatePromiseId == aId) { Release(); } MediaKeySystemAccess::NotifyObservers(mParent, mKeySystem, MediaKeySystemStatus::Cdm_created); }
void MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId, const uint32_t aPluginId) { RefPtr<DetailedPromise> promise(RetrievePromise(aId)); if (!promise) { return; } mNodeId = aNodeId; RefPtr<MediaKeys> keys(this); EME_LOG("MediaKeys[%p]::OnCDMCreated() resolve promise id=%d", this, aId); promise->MaybeResolve(keys); if (mCreatePromiseId == aId) { Release(); } MediaKeySystemAccess::NotifyObservers(mParent, mKeySystem, MediaKeySystemStatus::Cdm_created); }
void MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId, const nsACString& aPluginId) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { return; } mNodeId = aNodeId; nsRefPtr<MediaKeys> keys(this); EME_LOG("MediaKeys[%p]::OnCDMCreated() resolve promise id=%d", this, aId); promise->MaybeResolve(keys); if (mCreatePromiseId == aId) { Release(); } MediaKeySystemAccess::NotifyObservers(mParent, mKeySystem, MediaKeySystemStatus::Cdm_created); if (!aPluginId.IsEmpty()) { // Prepare plugin crash reporter. nsRefPtr<gmp::GeckoMediaPluginService> service = gmp::GeckoMediaPluginService::GetGeckoMediaPluginService(); if (NS_WARN_IF(!service)) { return; } if (NS_WARN_IF(!mParent)) { return; } nsCOMPtr<nsIDocument> doc = mParent->GetExtantDoc(); if (NS_WARN_IF(!doc)) { return; } service->AddPluginCrashCallback(new CrashHandler(aPluginId, mParent, doc)); EME_LOG("MediaKeys[%p]::OnCDMCreated() registered crash handler for pluginId '%s'", this, aPluginId.Data()); } }
void MediaKeys::RejectPromise(PromiseId aId, nsresult aExceptionCode) { nsRefPtr<Promise> promise(RetrievePromise(aId)); if (!promise) { NS_WARNING("MediaKeys tried to reject a non-existent promise"); return; } if (mPendingSessions.Contains(aId)) { // This promise could be a createSession or loadSession promise, // so we might have a pending session waiting to be resolved into // the promise on success. We've been directed to reject to promise, // so we can throw away the corresponding session object. mPendingSessions.Remove(aId); } MOZ_ASSERT(NS_FAILED(aExceptionCode)); promise->MaybeReject(aExceptionCode); if (mCreatePromiseId == aId) { // Note: This will probably destroy the MediaKeys object! Release(); } }