Bug 1165163 - Ensure MediaKeySession doesn't try to use CDM after it's crashed. r=jwwang, a=lizzard
authorChris Pearce <cpearce@mozilla.com>
Mon, 18 May 2015 11:09:05 +1200
changeset 274665 a810a56634b11603fc3c9b4b0fe58c9a91c9ea4c
parent 274664 d2cc6cf1930eab185266f2de36fbaedff8051d7e
child 274666 bde7a690aba57d8f07d76db31a8e96e8242403ec
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, lizzard
bugs1165163
milestone40.0a2
Bug 1165163 - Ensure MediaKeySession doesn't try to use CDM after it's crashed. r=jwwang, a=lizzard
dom/media/eme/MediaKeySession.cpp
dom/media/eme/MediaKeySession.h
--- a/dom/media/eme/MediaKeySession.cpp
+++ b/dom/media/eme/MediaKeySession.cpp
@@ -55,17 +55,17 @@ MediaKeySession::MediaKeySession(JSConte
   , mKeyStatusMap(new MediaKeyStatusMap(aCx, aParent, aRv))
 {
   EME_LOG("MediaKeySession[%p,''] session Id set", this);
 
   MOZ_ASSERT(aParent);
   if (aRv.Failed()) {
     return;
   }
-  mClosed = mKeys->MakePromise(aRv);
+  mClosed = MakePromise(aRv);
 }
 
 void MediaKeySession::SetSessionId(const nsAString& aSessionId)
 {
   EME_LOG("MediaKeySession[%p,'%s'] session Id set",
           this, NS_ConvertUTF16toUTF8(aSessionId).get());
 
   if (NS_WARN_IF(!mSessionId.IsEmpty())) {
@@ -164,17 +164,17 @@ MediaKeySession::KeyStatuses() const
   return mKeyStatusMap;
 }
 
 already_AddRefed<Promise>
 MediaKeySession::GenerateRequest(const nsAString& aInitDataType,
                                  const ArrayBufferViewOrArrayBuffer& aInitData,
                                  ErrorResult& aRv)
 {
-  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
+  nsRefPtr<Promise> promise(MakePromise(aRv));
   if (aRv.Failed()) {
     return nullptr;
   }
 
   if (!mUninitialized) {
     EME_LOG("MediaKeySession[%p,'%s'] GenerateRequest() failed, uninitialized",
             this, NS_ConvertUTF16toUTF8(mSessionId).get());
     promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
@@ -219,17 +219,17 @@ MediaKeySession::GenerateRequest(const n
           base64InitData.get());
 
   return promise.forget();
 }
 
 already_AddRefed<Promise>
 MediaKeySession::Load(const nsAString& aSessionId, ErrorResult& aRv)
 {
-  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
+  nsRefPtr<Promise> promise(MakePromise(aRv));
   if (aRv.Failed()) {
     return nullptr;
   }
 
   if (aSessionId.IsEmpty()) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     // "The sessionId parameter is empty."
     EME_LOG("MediaKeySession[%p,''] Load() failed, no sessionId", this);
@@ -260,17 +260,17 @@ MediaKeySession::Load(const nsAString& a
     this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);
 
   return promise.forget();
 }
 
 already_AddRefed<Promise>
 MediaKeySession::Update(const ArrayBufferViewOrArrayBuffer& aResponse, ErrorResult& aRv)
 {
-  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
+  nsRefPtr<Promise> promise(MakePromise(aRv));
   if (aRv.Failed()) {
     return nullptr;
   }
   nsTArray<uint8_t> data;
   if (IsClosed() ||
       !mKeys->GetCDMProxy() ||
       !CopyArrayBufferViewOrArrayBufferData(aResponse, data)) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
@@ -305,17 +305,17 @@ MediaKeySession::Update(const ArrayBuffe
            base64Response.get());
 
   return promise.forget();
 }
 
 already_AddRefed<Promise>
 MediaKeySession::Close(ErrorResult& aRv)
 {
-  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
+  nsRefPtr<Promise> promise(MakePromise(aRv));
   if (aRv.Failed()) {
     return nullptr;
   }
   if (IsClosed() || !mKeys->GetCDMProxy()) {
     EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
             this, NS_ConvertUTF16toUTF8(mSessionId).get());
     promise->MaybeResolve(JS::UndefinedHandleValue);
     return promise.forget();
@@ -347,17 +347,17 @@ bool
 MediaKeySession::IsClosed() const
 {
   return mIsClosed;
 }
 
 already_AddRefed<Promise>
 MediaKeySession::Remove(ErrorResult& aRv)
 {
-  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
+  nsRefPtr<Promise> promise(MakePromise(aRv));
   if (aRv.Failed()) {
     return nullptr;
   }
   if (mSessionType != SessionType::Persistent) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
     // "The operation is not supported on session type sessions."
     EME_LOG("MediaKeySession[%p,'%s'] Remove() failed, sesion not persisrtent.",
             this, NS_ConvertUTF16toUTF8(mSessionId).get());
@@ -429,10 +429,22 @@ MediaKeySession::DispatchKeyStatusesChan
 }
 
 uint32_t
 MediaKeySession::Token() const
 {
   return mToken;
 }
 
+already_AddRefed<Promise>
+MediaKeySession::MakePromise(ErrorResult& aRv)
+{
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
+  if (!global) {
+    NS_WARNING("Passed non-global to MediaKeys ctor!");
+    aRv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
+  return Promise::Create(global, aRv);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/eme/MediaKeySession.h
+++ b/dom/media/eme/MediaKeySession.h
@@ -92,16 +92,17 @@ public:
 
   // Process-unique identifier.
   uint32_t Token() const;
 
 private:
   ~MediaKeySession();
 
   void UpdateKeyStatusMap();
+  already_AddRefed<Promise> MakePromise(ErrorResult& aRv);
 
   nsRefPtr<Promise> mClosed;
 
   nsRefPtr<MediaKeyError> mMediaKeyError;
   nsRefPtr<MediaKeys> mKeys;
   const nsString mKeySystem;
   nsString mSessionId;
   const SessionType mSessionType;