Bug 1282585 - Ensure content process doesn't crash if CDM crashes before MediaKeys attaches to media element or media element loads. r=jwwang, a=gchang
authorChris Pearce <cpearce@mozilla.com>
Wed, 29 Jun 2016 16:09:24 +1200
changeset 339827 31d27613325c57cdcecad96835b75b808a087ae1
parent 339826 373f762e0b839a516317478c553be0bc8c5d6d6e
child 339828 5e8bede01474ef2af837a8ad177c0524885d5399
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, gchang
bugs1282585
milestone49.0a2
Bug 1282585 - Ensure content process doesn't crash if CDM crashes before MediaKeys attaches to media element or media element loads. r=jwwang, a=gchang MozReview-Commit-ID: 2CpiDv6u4RP
dom/html/HTMLMediaElement.cpp
dom/media/MediaDecoder.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3056,17 +3056,23 @@ nsresult HTMLMediaElement::FinishDecoder
   for (uint32_t i = 0; i < mOutputStreams.Length(); ++i) {
     OutputMediaStream* ms = &mOutputStreams[i];
     aDecoder->AddOutputStream(ms->mStream->GetInputStream()->AsProcessedStream(),
                               ms->mFinishWhenEnded);
   }
 
 #ifdef MOZ_EME
   if (mMediaKeys) {
-    mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy());
+    if (mMediaKeys->GetCDMProxy()) {
+      mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy());
+    } else {
+      // CDM must have crashed.
+      ShutdownDecoder();
+      return NS_ERROR_FAILURE;
+    }
   }
 #endif
 
   // Decoder successfully created, the decoder now owns the MediaResource
   // which owns the channel.
   mChannel = nullptr;
 
   AddMediaElementToURITable();
@@ -5347,16 +5353,22 @@ HTMLMediaElement::SetMediaKeys(mozilla::
 
     // 5.2.4 If the preceding step failed, let this object's attaching media
     // keys value be false and reject promise with a new DOMException whose
     // name is the appropriate error name.
   }
 
   // 5.3. If mediaKeys is not null, run the following steps:
   if (aMediaKeys) {
+    if (!aMediaKeys->GetCDMProxy()) {
+      promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
+        NS_LITERAL_CSTRING("CDM crashed before binding MediaKeys object to HTMLMediaElement"));
+      return promise.forget();
+    }
+
     // 5.3.1 Associate the CDM instance represented by mediaKeys with the
     // media element for decrypting media data.
     if (NS_FAILED(aMediaKeys->Bind(this))) {
       // 5.3.2 If the preceding step failed, run the following steps:
       // 5.3.2.1 Set the mediaKeys attribute to null.
       mMediaKeys = nullptr;
       // 5.3.2.2 Let this object's attaching media keys value be false.
       // 5.3.2.3 Reject promise with a new DOMException whose name is
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1659,16 +1659,17 @@ MediaDecoder::RequestCDMProxy() const
 {
   return mCDMProxyPromise;
 }
 
 void
 MediaDecoder::SetCDMProxy(CDMProxy* aProxy)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aProxy);
 
   mCDMProxyPromiseHolder.ResolveIfExists(aProxy, __func__);
 }
 #endif
 
 #ifdef MOZ_RAW
 bool
 MediaDecoder::IsRawEnabled()