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 319792 22007e69f30a9d47b44154576bba03ffd955fa70
parent 319791 7d22628f37cf9269c288875693c788e7b5b81bc4
child 319793 a0c11c1c08c34cada800dc86cb2f78c65a4852ef
push id83254
push usercpearce@mozilla.com
push dateFri, 28 Oct 2016 02:25:15 +0000
treeherdermozilla-inbound@a0c11c1c08c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1310879
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,
   },