diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 2274826a2a2..71cac9605da 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -2853,52 +2853,9 @@ Navigator::GetUserAgent(nsPIDOMWindow* aWindow, nsIURI* aURI, #ifdef MOZ_EME already_AddRefed Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem, - const Optional>& aOptions, + const Sequence& aConfigs, ErrorResult& aRv) { - nsAutoCString logMsg; - logMsg.AppendPrintf("Navigator::RequestMediaKeySystemAccess(keySystem='%s' options=[", - NS_ConvertUTF16toUTF8(aKeySystem).get()); - if (aOptions.WasPassed()) { - const Sequence& options = aOptions.Value(); - for (size_t i = 0; i < options.Length(); i++) { - const MediaKeySystemOptions& op = options[i]; - if (i > 0) { - logMsg.AppendLiteral(","); - } - logMsg.AppendLiteral("{"); - logMsg.AppendPrintf("stateful='%s'", - MediaKeysRequirementValues::strings[(size_t)op.mStateful].value); - - logMsg.AppendPrintf(", uniqueIdentifier='%s'", - MediaKeysRequirementValues::strings[(size_t)op.mUniqueidentifier].value); - - if (!op.mAudioCapability.IsEmpty()) { - logMsg.AppendPrintf(", audioCapability='%s'", - NS_ConvertUTF16toUTF8(op.mAudioCapability).get()); - } - if (!op.mAudioType.IsEmpty()) { - logMsg.AppendPrintf(", audioType='%s'", - NS_ConvertUTF16toUTF8(op.mAudioType).get()); - } - if (!op.mInitDataType.IsEmpty()) { - logMsg.AppendPrintf(", initDataType='%s'", - NS_ConvertUTF16toUTF8(op.mInitDataType).get()); - } - if (!op.mVideoCapability.IsEmpty()) { - logMsg.AppendPrintf(", videoCapability='%s'", - NS_ConvertUTF16toUTF8(op.mVideoCapability).get()); - } - if (!op.mVideoType.IsEmpty()) { - logMsg.AppendPrintf(", videoType='%s'", - NS_ConvertUTF16toUTF8(op.mVideoType).get()); - } - logMsg.AppendLiteral("}"); - } - } - logMsg.AppendPrintf("])"); - EME_LOG(logMsg.get()); - nsCOMPtr go = do_QueryInterface(mWindow); RefPtr promise = DetailedPromise::Create(go, aRv, @@ -2913,7 +2870,7 @@ Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem, mMediaKeySystemAccessManager = new MediaKeySystemAccessManager(mWindow); } - mMediaKeySystemAccessManager->Request(promise, aKeySystem, aOptions); + mMediaKeySystemAccessManager->Request(promise, aKeySystem, aConfigs); return promise.forget(); } diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 0df73ebea12..b6c592f1f23 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -353,7 +353,7 @@ public: #ifdef MOZ_EME already_AddRefed RequestMediaKeySystemAccess(const nsAString& aKeySystem, - const Optional>& aOptions, + const Sequence& aConfig, ErrorResult& aRv); private: RefPtr mMediaKeySystemAccessManager; diff --git a/dom/media/eme/MediaKeySystemAccess.cpp b/dom/media/eme/MediaKeySystemAccess.cpp index d10d2c83c4f..63937ef27c1 100644 --- a/dom/media/eme/MediaKeySystemAccess.cpp +++ b/dom/media/eme/MediaKeySystemAccess.cpp @@ -52,10 +52,12 @@ NS_INTERFACE_MAP_END MediaKeySystemAccess::MediaKeySystemAccess(nsPIDOMWindow* aParent, const nsAString& aKeySystem, - const nsAString& aCDMVersion) + const nsAString& aCDMVersion, + const MediaKeySystemConfiguration& aConfig) : mParent(aParent) , mKeySystem(aKeySystem) , mCDMVersion(aCDMVersion) + , mConfig(aConfig) { } @@ -81,6 +83,12 @@ MediaKeySystemAccess::GetKeySystem(nsString& aOutKeySystem) const ConstructKeySystem(mKeySystem, mCDMVersion, aOutKeySystem); } +void +MediaKeySystemAccess::GetConfiguration(MediaKeySystemConfiguration& aConfig) +{ + aConfig = mConfig; +} + already_AddRefed MediaKeySystemAccess::CreateMediaKeys(ErrorResult& aRv) { @@ -376,15 +384,11 @@ GMPDecryptsAndGeckoDecodesAAC(mozIGeckoMediaPluginService* aGMPService, static bool IsSupported(mozIGeckoMediaPluginService* aGMPService, const nsAString& aKeySystem, - const MediaKeySystemOptions& aConfig) + const MediaKeySystemConfiguration& aConfig) { - if (!aConfig.mInitDataType.EqualsLiteral("cenc")) { - return false; - } - if (!aConfig.mAudioCapability.IsEmpty() || - !aConfig.mVideoCapability.IsEmpty()) { - // Don't support any capabilities until we know we have a CDM with - // capabilities... + // Backwards compatibility with legacy MediaKeySystemConfiguration method. + if (!aConfig.mInitDataType.IsEmpty() && + !aConfig.mInitDataType.EqualsLiteral("cenc")) { return false; } if (!aConfig.mAudioType.IsEmpty() && @@ -405,7 +409,7 @@ IsSupported(mozIGeckoMediaPluginService* aGMPService, /* static */ bool MediaKeySystemAccess::IsSupported(const nsAString& aKeySystem, - const Sequence& aOptions) + const Sequence& aConfigs) { nsCOMPtr mps = do_GetService("@mozilla.org/gecko-media-plugin-service;1"); @@ -419,7 +423,7 @@ MediaKeySystemAccess::IsSupported(const nsAString& aKeySystem, return false; } - for (const MediaKeySystemOptions& config : aOptions) { + for (const MediaKeySystemConfiguration& config : aConfigs) { if (mozilla::dom::IsSupported(mps, aKeySystem, config)) { return true; } diff --git a/dom/media/eme/MediaKeySystemAccess.h b/dom/media/eme/MediaKeySystemAccess.h index 6123bd10f46..567fb99d279 100644 --- a/dom/media/eme/MediaKeySystemAccess.h +++ b/dom/media/eme/MediaKeySystemAccess.h @@ -31,7 +31,8 @@ public: public: explicit MediaKeySystemAccess(nsPIDOMWindow* aParent, const nsAString& aKeySystem, - const nsAString& aCDMVersion); + const nsAString& aCDMVersion, + const MediaKeySystemConfiguration& aConfig); protected: ~MediaKeySystemAccess(); @@ -43,6 +44,8 @@ public: void GetKeySystem(nsString& aRetVal) const; + void GetConfiguration(MediaKeySystemConfiguration& aConfig); + already_AddRefed CreateMediaKeys(ErrorResult& aRv); @@ -53,7 +56,7 @@ public: nsACString& aOutCdmVersion); static bool IsSupported(const nsAString& aKeySystem, - const Sequence& aOptions); + const Sequence& aConfigs); static void NotifyObservers(nsIDOMWindow* aWindow, const nsAString& aKeySystem, @@ -67,6 +70,7 @@ private: nsCOMPtr mParent; const nsString mKeySystem; const nsString mCDMVersion; + const MediaKeySystemConfiguration mConfig; }; } // namespace dom diff --git a/dom/media/eme/MediaKeySystemAccessManager.cpp b/dom/media/eme/MediaKeySystemAccessManager.cpp index 1f02d98bc8e..444b7b022e4 100644 --- a/dom/media/eme/MediaKeySystemAccessManager.cpp +++ b/dom/media/eme/MediaKeySystemAccessManager.cpp @@ -63,16 +63,14 @@ MediaKeySystemAccessManager::~MediaKeySystemAccessManager() void MediaKeySystemAccessManager::Request(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Optional>& aOptions) + const Sequence& aConfigs) { - if (aKeySystem.IsEmpty() || (aOptions.WasPassed() && aOptions.Value().IsEmpty())) { + if (aKeySystem.IsEmpty() || aConfigs.IsEmpty()) { aPromise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR, NS_LITERAL_CSTRING("Invalid keysystem type or invalid options sequence")); return; } - Sequence optionsNotPassed; - const auto& options = aOptions.WasPassed() ? aOptions.Value() : optionsNotPassed; - Request(aPromise, aKeySystem, options, RequestType::Initial); + Request(aPromise, aKeySystem, aConfigs, RequestType::Initial); } static bool @@ -91,7 +89,7 @@ ShouldTrialCreateGMP(const nsAString& aKeySystem) void MediaKeySystemAccessManager::Request(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions, + const Sequence& aConfigs, RequestType aType) { EME_LOG("MediaKeySystemAccessManager::Request %s", NS_ConvertUTF16toUTF8(aKeySystem).get()); @@ -145,7 +143,7 @@ MediaKeySystemAccessManager::Request(DetailedPromise* aPromise, // has had a new plugin added. AwaitInstall() sets a timer to fail if the // update/download takes too long or fails. if (aType == RequestType::Initial && - AwaitInstall(aPromise, aKeySystem, aOptions)) { + AwaitInstall(aPromise, aKeySystem, aConfigs)) { // Notify chrome that we're going to wait for the CDM to download/update. // Note: If we're re-trying, we don't re-send the notificaiton, // as chrome is already displaying the "we can't play, updating" @@ -174,10 +172,11 @@ MediaKeySystemAccessManager::Request(DetailedPromise* aPromise, return; } - if (aOptions.IsEmpty() || - MediaKeySystemAccess::IsSupported(keySystem, aOptions)) { + MediaKeySystemConfiguration config; + if (aConfigs.IsEmpty() || + MediaKeySystemAccess::IsSupported(keySystem, aConfigs)) { RefPtr access( - new MediaKeySystemAccess(mWindow, keySystem, NS_ConvertUTF8toUTF16(cdmVersion))); + new MediaKeySystemAccess(mWindow, keySystem, NS_ConvertUTF8toUTF16(cdmVersion), config)); if (ShouldTrialCreateGMP(keySystem)) { // Ensure we have tried creating a GMPVideoDecoder for this // keySystem, and that we can use it to decode. This ensures that we only @@ -195,11 +194,11 @@ MediaKeySystemAccessManager::Request(DetailedPromise* aPromise, MediaKeySystemAccessManager::PendingRequest::PendingRequest(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions, + const Sequence& aConfigs, nsITimer* aTimer) : mPromise(aPromise) , mKeySystem(aKeySystem) - , mOptions(aOptions) + , mConfigs(aConfigs) , mTimer(aTimer) { MOZ_COUNT_CTOR(MediaKeySystemAccessManager::PendingRequest); @@ -208,7 +207,7 @@ MediaKeySystemAccessManager::PendingRequest::PendingRequest(DetailedPromise* aPr MediaKeySystemAccessManager::PendingRequest::PendingRequest(const PendingRequest& aOther) : mPromise(aOther.mPromise) , mKeySystem(aOther.mKeySystem) - , mOptions(aOther.mOptions) + , mConfigs(aOther.mConfigs) , mTimer(aOther.mTimer) { MOZ_COUNT_CTOR(MediaKeySystemAccessManager::PendingRequest); @@ -238,7 +237,7 @@ MediaKeySystemAccessManager::PendingRequest::RejectPromise(const nsCString& aRea bool MediaKeySystemAccessManager::AwaitInstall(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions) + const Sequence& aConfigs) { EME_LOG("MediaKeySystemAccessManager::AwaitInstall %s", NS_ConvertUTF16toUTF8(aKeySystem).get()); @@ -253,7 +252,7 @@ MediaKeySystemAccessManager::AwaitInstall(DetailedPromise* aPromise, return false; } - mRequests.AppendElement(PendingRequest(aPromise, aKeySystem, aOptions, timer)); + mRequests.AppendElement(PendingRequest(aPromise, aKeySystem, aConfigs, timer)); return true; } @@ -261,7 +260,7 @@ void MediaKeySystemAccessManager::RetryRequest(PendingRequest& aRequest) { aRequest.CancelTimer(); - Request(aRequest.mPromise, aRequest.mKeySystem, aRequest.mOptions, RequestType::Subsequent); + Request(aRequest.mPromise, aRequest.mKeySystem, aRequest.mConfigs, RequestType::Subsequent); } nsresult diff --git a/dom/media/eme/MediaKeySystemAccessManager.h b/dom/media/eme/MediaKeySystemAccessManager.h index 6f2cc4d3e98..05060ba097c 100644 --- a/dom/media/eme/MediaKeySystemAccessManager.h +++ b/dom/media/eme/MediaKeySystemAccessManager.h @@ -30,14 +30,14 @@ public: void Request(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Optional>& aOptions); + const Sequence& aConfig); void Shutdown(); struct PendingRequest { PendingRequest(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions, + const Sequence& aConfig, nsITimer* aTimer); PendingRequest(const PendingRequest& aOther); ~PendingRequest(); @@ -46,7 +46,7 @@ public: RefPtr mPromise; const nsString mKeySystem; - const Sequence mOptions; + const Sequence mConfigs; nsCOMPtr mTimer; }; @@ -59,7 +59,7 @@ private: void Request(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions, + const Sequence& aConfig, RequestType aType); ~MediaKeySystemAccessManager(); @@ -68,7 +68,7 @@ private: bool AwaitInstall(DetailedPromise* aPromise, const nsAString& aKeySystem, - const Sequence& aOptions); + const Sequence& aConfig); void RetryRequest(PendingRequest& aRequest); diff --git a/dom/webidl/MediaKeySystemAccess.webidl b/dom/webidl/MediaKeySystemAccess.webidl index 33390fef246..dc8021279e4 100644 --- a/dom/webidl/MediaKeySystemAccess.webidl +++ b/dom/webidl/MediaKeySystemAccess.webidl @@ -10,25 +10,31 @@ * W3C liability, trademark and document use rules apply. */ -enum MediaKeysRequirement { - "required", - "optional", - "disallowed" +dictionary MediaKeySystemMediaCapability { + DOMString contentType = ""; + // TODO: robustness }; -dictionary MediaKeySystemOptions { +dictionary MediaKeySystemConfiguration { + DOMString label = ""; + sequence initDataTypes; + sequence audioCapabilities; + sequence videoCapabilities; + + // TODO: distinctiveIdentifier, persistentState, sessionTypes + + // For backwards compatibility with implementations using old + // MediaKeySystemOptions paradigm... DOMString initDataType = ""; DOMString audioType = ""; - DOMString audioCapability = ""; DOMString videoType = ""; - DOMString videoCapability = ""; - MediaKeysRequirement uniqueidentifier = "optional"; - MediaKeysRequirement stateful = "optional"; }; [Pref="media.eme.apiVisible"] interface MediaKeySystemAccess { readonly attribute DOMString keySystem; [NewObject] + MediaKeySystemConfiguration getConfiguration(); + [NewObject] Promise createMediaKeys(); }; diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl index f03aed9e6e0..ef76948cf22 100644 --- a/dom/webidl/Navigator.webidl +++ b/dom/webidl/Navigator.webidl @@ -447,7 +447,7 @@ partial interface Navigator { [Pref="media.eme.apiVisible", NewObject] Promise requestMediaKeySystemAccess(DOMString keySystem, - optional sequence supportedConfigurations); + sequence supportedConfigurations); }; #endif