Skip to content

Commit

Permalink
Delete copied logic for creating widevine CdmInfo
Browse files Browse the repository at this point in the history
Instead, use cached CdmInfo from CdmRegistryImpl.
  • Loading branch information
simonhong committed Feb 1, 2019
1 parent 9a814a0 commit 81ca1a1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 52 deletions.
42 changes: 3 additions & 39 deletions browser/ui/content_settings/brave_widevine_bundle_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
35 changes: 29 additions & 6 deletions chromium_src/content/browser/media/cdm_registry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#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
Expand All @@ -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
15 changes: 8 additions & 7 deletions patches/content-browser-media-cdm_registry_impl.h.patch
Original file line number Diff line number Diff line change
@@ -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<CdmInfo>& 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<CdmInfo> cdms_;
private:
friend class CdmRegistryImplTest;

DISALLOW_COPY_AND_ASSIGN(CdmRegistryImpl);

0 comments on commit 81ca1a1

Please sign in to comment.