From bae8ed95b185ce5755581387f6ff1fa8e2009fd0 Mon Sep 17 00:00:00 2001 From: alwu Date: Tue, 5 Dec 2023 01:13:48 +0000 Subject: [PATCH] Bug 1846848 - part6 : display GMPCDM capabilities in `about:support`. r=jolin ClearKey and Widevine L3 are used in the GMP process, so comparing with MFCDM, we need to use another different way to access their capabilities. Differential Revision: https://phabricator.services.mozilla.com/D194932 --- dom/base/ChromeUtils.cpp | 13 +++++++++++++ dom/base/ChromeUtils.h | 3 +++ dom/chrome-webidl/ChromeUtils.webidl | 7 +++++++ dom/media/eme/KeySystemConfig.cpp | 24 ++++++++++++++++++++++++ dom/media/eme/KeySystemConfig.h | 1 + toolkit/content/aboutSupport.js | 9 +++++++-- 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index 7a37501d19e4..08c5c551032b 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -1944,4 +1944,17 @@ already_AddRefed ChromeUtils::GetWMFContentDecryptionModuleInformation( } #endif +already_AddRefed ChromeUtils::GetGMPContentDecryptionModuleInformation( + GlobalObject& aGlobal, ErrorResult& aRv) { + nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); + MOZ_ASSERT(global); + RefPtr domPromise = Promise::Create(global, aRv); + if (NS_WARN_IF(aRv.Failed())) { + return nullptr; + } + MOZ_ASSERT(domPromise); + KeySystemConfig::GetGMPKeySystemConfigs(domPromise); + return domPromise.forget(); +} + } // namespace mozilla::dom diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index c89bc4ef30af..0737f0ae33e8 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -313,6 +313,9 @@ class ChromeUtils { GlobalObject& aGlobal, ErrorResult& aRv); #endif + static already_AddRefed GetGMPContentDecryptionModuleInformation( + GlobalObject& aGlobal, ErrorResult& aRv); + private: // Number of DevTools session debugging the current process static std::atomic sDevToolsOpenedCount; diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index 053da6e20571..2e3209a4b5c3 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -306,6 +306,13 @@ namespace ChromeUtils { Promise> getWMFContentDecryptionModuleInformation(); #endif + /** + * Returns the information about the GMP based content decryption + * modules, which would include key system names and their capabilities. + */ + [NewObject] + Promise> getGMPContentDecryptionModuleInformation(); + /** * IF YOU ADD NEW METHODS HERE, MAKE SURE THEY ARE THREAD-SAFE. */ diff --git a/dom/media/eme/KeySystemConfig.cpp b/dom/media/eme/KeySystemConfig.cpp index b3fe3feee8b2..65e90cd57a7b 100644 --- a/dom/media/eme/KeySystemConfig.cpp +++ b/dom/media/eme/KeySystemConfig.cpp @@ -211,6 +211,30 @@ bool KeySystemConfig::IsSameKeySystem(const nsAString& aKeySystem) const { return mKeySystem.Equals(aKeySystem); } +/* static */ +void KeySystemConfig::GetGMPKeySystemConfigs(dom::Promise* aPromise) { + MOZ_ASSERT(aPromise); + nsTArray keySystemConfigs; + const nsTArray keySystemNames{ + NS_ConvertUTF8toUTF16(kClearKeyKeySystemName), + NS_ConvertUTF8toUTF16(kWidevineKeySystemName), + }; + FallibleTArray cdmInfo; + for (const auto& name : keySystemNames) { + if (KeySystemConfig::CreateKeySystemConfigs(name, keySystemConfigs)) { + auto* info = cdmInfo.AppendElement(fallible); + if (!info) { + aPromise->MaybeReject(NS_ERROR_OUT_OF_MEMORY); + return; + } + MOZ_ASSERT(keySystemConfigs.Length() == cdmInfo.Length()); + info->mKeySystemName = name; + info->mCapabilities = keySystemConfigs.LastElement().GetDebugInfo(); + } + } + aPromise->MaybeResolve(cdmInfo); +} + nsString KeySystemConfig::GetDebugInfo() const { nsString debugInfo; debugInfo.AppendLiteral(" key-system="); diff --git a/dom/media/eme/KeySystemConfig.h b/dom/media/eme/KeySystemConfig.h index 111875bc6d21..103d711bdf1b 100644 --- a/dom/media/eme/KeySystemConfig.h +++ b/dom/media/eme/KeySystemConfig.h @@ -124,6 +124,7 @@ struct KeySystemConfig { static bool Supports(const nsAString& aKeySystem); static bool CreateKeySystemConfigs(const nsAString& aKeySystem, nsTArray& aOutConfigs); + static void GetGMPKeySystemConfigs(dom::Promise* aPromise); KeySystemConfig() = default; ~KeySystemConfig() = default; diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index 5db0e3b59c85..121b3b885686 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -1182,10 +1182,15 @@ var snapshotFormatters = { async function insertContentDecryptionModuleInfo() { let rows = []; + // Retrieve information from GMPCDM + let cdmInfo = + await ChromeUtils.getGMPContentDecryptionModuleInformation(); + for (let info of cdmInfo) { + rows.push(createCDMInfoRow(info)); + } // Retrieve information from WMFCDM, only works when MOZ_WMF_CDM is true if (ChromeUtils.getWMFContentDecryptionModuleInformation !== undefined) { - const cdmInfo = - await ChromeUtils.getWMFContentDecryptionModuleInformation(); + cdmInfo = await ChromeUtils.getWMFContentDecryptionModuleInformation(); for (let info of cdmInfo) { rows.push(createCDMInfoRow(info)); }