diff --git a/browser/ui/content_settings/brave_widevine_bundle_util.cc b/browser/ui/content_settings/brave_widevine_bundle_util.cc index 44b1204eac06..2add8718d0fe 100644 --- a/browser/ui/content_settings/brave_widevine_bundle_util.cc +++ b/browser/ui/content_settings/brave_widevine_bundle_util.cc @@ -5,19 +5,11 @@ #include "brave/browser/ui/content_settings/brave_widevine_bundle_util.h" -#include "base/path_service.h" #include "brave/common/pref_names.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/chrome_paths.h" #include "components/prefs/pref_service.h" +#include "content/browser/media/cdm_registry_impl.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/cdm_registry.h" -#include "content/public/common/cdm_info.h" -#include "media/base/decrypt_config.h" -#include "media/base/video_codecs.h" -#include "media/media_buildflags.h" -#include "third_party/widevine/cdm/widevine_cdm_common.h" -#include "widevine_cdm_version.h" // NOLINT void MaybeRegisterWidevineCdm() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); @@ -27,34 +19,6 @@ void MaybeRegisterWidevineCdm() { if (!prefs->GetBoolean(kWidevineOptedIn)) return; - base::FilePath cdm_path; - bool success = base::PathService::Get(chrome::FILE_WIDEVINE_CDM, &cdm_path); - DCHECK(success); - content::CdmCapability capability; - const base::Version cdm_version(WIDEVINE_CDM_VERSION_STRING); - - // Add the supported codecs as if they came from the component manifest. - // This list must match the CDM that is being bundled with Chrome. - capability.video_codecs.push_back(media::VideoCodec::kCodecVP8); - capability.video_codecs.push_back(media::VideoCodec::kCodecVP9); - // TODO(xhwang): Update this and tests after Widevine CDM supports VP9 - // profile 2. - capability.supports_vp9_profile2 = false; -#if BUILDFLAG(USE_PROPRIETARY_CODECS) - capability.video_codecs.push_back(media::VideoCodec::kCodecH264); -#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) - - // Add the supported encryption schemes as if they came from the - // component manifest. This list must match the CDM that is being - // bundled with Chrome. - capability.encryption_schemes.insert(media::EncryptionMode::kCenc); - capability.encryption_schemes.insert(media::EncryptionMode::kCbcs); - - // Temporary session is always supported. - capability.session_types.insert(media::CdmSessionType::kTemporary); - - content::CdmRegistry::GetInstance()->RegisterCdm( - content::CdmInfo(kWidevineCdmDisplayName, kWidevineCdmGuid, cdm_version, - cdm_path, kWidevineCdmFileSystemId, - capability, kWidevineKeySystem, false)); + auto* cdm_registry = content::CdmRegistryImpl::GetInstance(); + cdm_registry->RegisterCdm(cdm_registry->cached_widevine_cdm_info()); } diff --git a/chromium_src/content/browser/media/cdm_registry_impl.cc b/chromium_src/content/browser/media/cdm_registry_impl.cc index 4c5036d9ba9c..f8ae89c75707 100644 --- a/chromium_src/content/browser/media/cdm_registry_impl.cc +++ b/chromium_src/content/browser/media/cdm_registry_impl.cc @@ -3,21 +3,27 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "content/browser/media/cdm_registry_impl.h" +#include "build/build_config.h" // For OS_LINUX #if defined(OS_LINUX) +#include "content/browser/media/cdm_registry_impl.h" + #include -#endif #define Init Init_ChromiumImpl -#include "../../../../../content/browser/media/cdm_registry_impl.cc" +#include "../../../../../content/browser/media/cdm_registry_impl.cc" // NOLINT #undef Init namespace content { + +namespace { +// This leaks but would be fine. +CdmInfo* g_widevine_info = nullptr; +} + void CdmRegistryImpl::Init() { Init_ChromiumImpl(); -#if defined(OS_LINUX) // On linux, we want to register widevine cdm to CdmRegistry when users opt // in. Otherwise, widevine is initialized by default w/o user accept. // So, widevine cdm is erased from |cdms_| and it is registered when users opt @@ -31,9 +37,26 @@ void CdmRegistryImpl::Init() { // widevine dependency to content module. // However, using this string directly seems fine because it would not // be changed and can avoid addtional patching for this. - return info.supported_key_system == "com.widevine.alpha"; + if (info.supported_key_system == "com.widevine.alpha") { + DCHECK(!g_widevine_info); + // Cache upstream created info to reuse when brave wants to register + // it later. + g_widevine_info = new CdmInfo(info); + return true; + } + return false; }), cdms_.end()); -#endif } + +const CdmInfo& CdmRegistryImpl::cached_widevine_cdm_info() const { + DCHECK(g_widevine_info); + return *g_widevine_info; +} + } // namespace content + +#else // OS_LINUX +// This overridden file is only used on linux. +#include "../../../../../content/browser/media/cdm_registry_impl.cc" // NOLINT +#endif diff --git a/patches/content-browser-media-cdm_registry_impl.h.patch b/patches/content-browser-media-cdm_registry_impl.h.patch index 59e1f8e87b97..20c462a37c9c 100644 --- a/patches/content-browser-media-cdm_registry_impl.h.patch +++ b/patches/content-browser-media-cdm_registry_impl.h.patch @@ -1,15 +1,16 @@ diff --git a/content/browser/media/cdm_registry_impl.h b/content/browser/media/cdm_registry_impl.h -index 303f3c59b3201ab78c84ae3803b48b37d9f8c998..3eac8905fb8ec6a4f4c050bc290f92065894b4f0 100644 +index 303f3c59b3201ab78c84ae3803b48b37d9f8c998..5dde1606f0dc421467144d813fc0f7b9431e3fe1 100644 --- a/content/browser/media/cdm_registry_impl.h +++ b/content/browser/media/cdm_registry_impl.h -@@ -32,6 +32,10 @@ class CONTENT_EXPORT CdmRegistryImpl : public CdmRegistry { - CdmRegistryImpl(); - ~CdmRegistryImpl() override; +@@ -26,6 +26,11 @@ class CONTENT_EXPORT CdmRegistryImpl : public CdmRegistry { + void RegisterCdm(const CdmInfo& info) override; + const std::vector& GetAllRegisteredCdms() override; -+#if defined(BRAVE_CHROMIUM_BUILD) ++#if defined(BRAVE_CHROMIUM_BUILD) && defined(OS_LINUX) ++ const CdmInfo& cached_widevine_cdm_info() const; + void Init_ChromiumImpl(); +#endif + - std::vector cdms_; + private: + friend class CdmRegistryImplTest; - DISALLOW_COPY_AND_ASSIGN(CdmRegistryImpl);