Bug 1113474 - Keep MediaKeys alive until it has resolved all of its stored promises - r=cpearce
authorEdwin Flores <eflores@mozilla.com>
Wed, 11 Feb 2015 11:43:49 +1300
changeset 242211 e3b66bc377064b06a8484b04270778b210638e0e
parent 242210 6f42cfe37f5c43fd7ccc58c516f721508bd25ecd
child 242212 18ae6f259c06e373218bafb532b68c019777c055
push id649
push userwcosta@mozilla.com
push dateWed, 11 Feb 2015 16:57:44 +0000
reviewerscpearce
bugs1113474
milestone38.0a1
Bug 1113474 - Keep MediaKeys alive until it has resolved all of its stored promises - r=cpearce
dom/media/eme/MediaKeys.cpp
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -164,26 +164,32 @@ MediaKeys::MakePromise(ErrorResult& aRv)
 }
 
 PromiseId
 MediaKeys::StorePromise(Promise* aPromise)
 {
   static uint32_t sEMEPromiseCount = 1;
   MOZ_ASSERT(aPromise);
   uint32_t id = sEMEPromiseCount++;
+
+  // Keep MediaKeys alive for the lifetime of its promises. Any still-pending
+  // promises are rejected in Shutdown().
+  AddRef();
+
   mPromises.Put(id, aPromise);
   return id;
 }
 
 already_AddRefed<Promise>
 MediaKeys::RetrievePromise(PromiseId aId)
 {
   MOZ_ASSERT(mPromises.Contains(aId));
   nsRefPtr<Promise> promise;
   mPromises.Remove(aId, getter_AddRefs(promise));
+  Release();
   return promise.forget();
 }
 
 void
 MediaKeys::RejectPromise(PromiseId aId, nsresult aExceptionCode)
 {
   nsRefPtr<Promise> promise(RetrievePromise(aId));
   if (!promise) {