Bug 1313202 - Update MediaKeySession.close() to match EME spec. r=gerald draft
authorChris Pearce <cpearce@mozilla.com>
Thu, 27 Oct 2016 11:37:27 +1300
changeset 429983 35ce6986bdc7e486b757df53fc59a63fb97014c3
parent 429982 4eb210a5816981a26e9792e3141564e6b235ea20
child 429984 445bd30414d5aa49f7424afff993aae8f8fe0ab5
push id33714
push usercpearce@mozilla.com
push dateThu, 27 Oct 2016 01:09:28 +0000
reviewersgerald
bugs1313202
milestone52.0a1
Bug 1313202 - Update MediaKeySession.close() to match EME spec. r=gerald MozReview-Commit-ID: JgzOaACDUfc
dom/media/eme/MediaKeySession.cpp
--- a/dom/media/eme/MediaKeySession.cpp
+++ b/dom/media/eme/MediaKeySession.cpp
@@ -472,36 +472,52 @@ MediaKeySession::Update(const ArrayBuffe
 already_AddRefed<Promise>
 MediaKeySession::Close(ErrorResult& aRv)
 {
   RefPtr<DetailedPromise> promise(MakePromise(aRv,
     NS_LITERAL_CSTRING("MediaKeySession.close")));
   if (aRv.Failed()) {
     return nullptr;
   }
+  // 1. Let session be the associated MediaKeySession object.
+  // 2. If session is closed, return a resolved promise.
+  if (IsClosed()) {
+    EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
+            this, NS_ConvertUTF16toUTF8(mSessionId).get());
+    promise->MaybeResolveWithUndefined();
+    return promise.forget();
+  }
+  // 3. If session's callable value is false, return a promise rejected
+  // with an InvalidStateError.
   if (!IsCallable()) {
-    // If this object's callable value is false, return a promise rejected
-    // with a new DOMException whose name is InvalidStateError.
     EME_LOG("MediaKeySession[%p,''] Close() called before sessionId set by CDM", this);
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
       NS_LITERAL_CSTRING("MediaKeySession.Close() called before sessionId set by CDM"));
     return promise.forget();
   }
-  if (IsClosed() || !mKeys->GetCDMProxy()) {
-    EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
+  if (!mKeys->GetCDMProxy()) {
+    EME_LOG("MediaKeySession[%p,'%s'] Close() null CDMProxy",
             this, NS_ConvertUTF16toUTF8(mSessionId).get());
-    promise->MaybeResolveWithUndefined();
+    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
+      NS_LITERAL_CSTRING("MediaKeySession.Close() lost reference to CDM"));
     return promise.forget();
   }
+  // 4. Let promise be a new promise.
   PromiseId pid = mKeys->StorePromise(promise);
+  // 5. Run the following steps in parallel:
+  // 5.1 Let cdm be the CDM instance represented by session's cdm instance value.
+  // 5.2 Use cdm to close the session associated with session.
   mKeys->GetCDMProxy()->CloseSession(mSessionId, pid);
 
   EME_LOG("MediaKeySession[%p,'%s'] Close() sent to CDM, promiseId=%d",
           this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);
 
+  // Session Closed algorithm is run when CDM causes us to run OnSessionClosed().
+
+  // 6. Return promise.
   return promise.forget();
 }
 
 void
 MediaKeySession::OnClosed()
 {
   if (IsClosed()) {
     return;