From 08bdd39606fa4d03c5e245c00113b8a4f79d0714 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Fri, 28 Oct 2016 11:43:26 +1300 Subject: [PATCH] Bug 1310879 - Check that only supported session types are instantiated. r=gerald MozReview-Commit-ID: 6XkToIXzZL8 --HG-- extra : source : d1c0a7a2ff25005de82033081bee5eb10adea0c8 --- dom/media/eme/MediaKeys.cpp | 28 ++++++++++++++++++++++ dom/media/test/test_eme_initDataTypes.html | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/dom/media/eme/MediaKeys.cpp b/dom/media/eme/MediaKeys.cpp index c0623c026832..87ce1c9ac808 100644 --- a/dom/media/eme/MediaKeys.cpp +++ b/dom/media/eme/MediaKeys.cpp @@ -441,11 +441,39 @@ MediaKeys::OnCDMCreated(PromiseId aId, const nsACString& aNodeId, const uint32_t 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(aSessionType)].value; + for (const nsString& s : aConfig.mSessionTypes.Value()) { + if (s.EqualsASCII(sessionType)) { + return true; + } + } + return false; +} + already_AddRefed 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); diff --git a/dom/media/test/test_eme_initDataTypes.html b/dom/media/test/test_eme_initDataTypes.html index 312a7f110523..4821c3cb82eb 100644 --- a/dom/media/test/test_eme_initDataTypes.html +++ b/dom/media/test/test_eme_initDataTypes.html @@ -42,7 +42,7 @@ var tests = [ 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",