Bug 1310879 - Check that only supported session types are instantiated. r=gerald
authorChris Pearce <cpearce@mozilla.com>
Fri, 28 Oct 2016 11:43:26 +1300
changeset 319904 22007e69f30a9d47b44154576bba03ffd955fa70
parent 319903 7d22628f37cf9269c288875693c788e7b5b81bc4
child 319905 a0c11c1c08c34cada800dc86cb2f78c65a4852ef
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1310879
milestone52.0a1
Bug 1310879 - Check that only supported session types are instantiated. r=gerald MozReview-Commit-ID: 6XkToIXzZL8
dom/media/eme/MediaKeys.cpp
dom/media/test/test_eme_initDataTypes.html
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -436,21 +436,49 @@ MediaKeys::OnCDMCreated(PromiseId aId, c
 
   MediaKeySystemAccess::NotifyObservers(mParent,
                                         mKeySystem,
                                         MediaKeySystemStatus::Cdm_created);
 
   Telemetry::Accumulate(Telemetry::VIDEO_CDM_CREATED, ToCDMTypeTelemetryEnum(mKeySystem));
 }
 
+static bool
+IsSessionTypeSupported(const MediaKeySessionType aSessionType,
+                       const MediaKeySystemConfiguration& aConfig)
+{
+  if (aSessionType == MediaKeySessionType::Temporary) {
+    // Temporary is always supported.
+    return true;
+  }
+  if (!aConfig.mSessionTypes.WasPassed()) {
+    // No other session types supported.
+    return false;
+  }
+  using MediaKeySessionTypeValues::strings;
+  const char* sessionType = strings[static_cast<uint32_t>(aSessionType)].value;
+  for (const nsString& s : aConfig.mSessionTypes.Value()) {
+    if (s.EqualsASCII(sessionType)) {
+      return true;
+    }
+  }
+  return false;
+}
+
 already_AddRefed<MediaKeySession>
 MediaKeys::CreateSession(JSContext* aCx,
                          MediaKeySessionType aSessionType,
                          ErrorResult& aRv)
 {
+  if (!IsSessionTypeSupported(aSessionType, mConfig)) {
+    EME_LOG("MediaKeys[%p,'%s'] CreateSession() failed, unsupported session type", this);
+    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+    return nullptr;
+  }
+
   if (!mProxy) {
     NS_WARNING("Tried to use a MediaKeys which lost its CDM");
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
   EME_LOG("MediaKeys[%p] Creating session", this);
 
--- a/dom/media/test/test_eme_initDataTypes.html
+++ b/dom/media/test/test_eme_initDataTypes.html
@@ -37,17 +37,17 @@ var tests = [
     expectPass: true,
   },
   {
     name: "Two keyIds, persistent session, type before kids",
     initDataType: 'keyids',
     initData: '{"type":"persistent-license", "kids":["LwVHf8JLtPrv2GUXFW2v_A", "0DdtU9od-Bh5L3xbv0Xf_A"]}',
     expectedRequest: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A","0DdtU9od-Bh5L3xbv0Xf_A"],"type":"persistent-license"}',
     sessionType: 'persistent-license',
-    expectPass: true,
+    expectPass: false,
   },
   {
     name: "Invalid keyId",
     initDataType: 'keyids',
     initData: '{"kids":["0"]}',
     sessionType: 'temporary',
     expectPass: false,
   },