Bug 1313202 - Update MediaKeySession.close() to match EME spec. r=gerald
authorChris Pearce <cpearce@mozilla.com>
Thu, 27 Oct 2016 11:37:27 +1300
changeset 346349 2017b66912e8489447929d54bb4ba26f981c998d
parent 346348 6f6ae961e35406c7d0384ce9cdb437bf3a4c8c1e
child 346350 b3275f223e26df0a672e3cdbc2a27602e7570dc6
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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;