Skip to content

Commit

Permalink
Only registers widevine cdm to CdmRegistry when users opted in
Browse files Browse the repository at this point in the history
With this, widevine cdm is initialized when users allowed to use
widevine cdm via content settings bubble.
  • Loading branch information
simonhong committed Jan 29, 2019
1 parent d4e81d7 commit 2529475
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions browser/brave_browser_main_extra_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "brave/browser/brave_browser_main_extra_parts.h"

#include "brave/browser/ui/content_settings/brave_widevine_bundle_util.h"
#include "chrome/browser/first_run/first_run.h"

BraveBrowserMainExtraParts::BraveBrowserMainExtraParts() {
Expand All @@ -14,4 +15,7 @@ BraveBrowserMainExtraParts::~BraveBrowserMainExtraParts() {

void BraveBrowserMainExtraParts::PreMainMessageLoopRun() {
brave::AutoImportMuon();
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
RegisterWidevineCdmToCdmRegistry();
#endif
}
7 changes: 7 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ source_set("ui") {
]
}

if (bundle_widevine_cdm) {
sources += [
"content_settings/brave_widevine_bundle_util.cc",
"content_settings/brave_widevine_bundle_util.h",
]
}

if (is_mac || is_win || is_chromeos) {
sources += [
"views/frame/brave_browser_frame.cc",
Expand Down
59 changes: 59 additions & 0 deletions browser/ui/content_settings/brave_widevine_bundle_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 "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/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"

void RegisterWidevineCdmToCdmRegistry() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// Only registers widevine cdm when user explicitly requested.
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));
}
14 changes: 14 additions & 0 deletions browser/ui/content_settings/brave_widevine_bundle_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_
#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_

#include "third_party/widevine/cdm/buildflags.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
void RegisterWidevineCdmToCdmRegistry();
#endif

#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_WIDEVINE_BUNDLE_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "third_party/widevine/cdm/buildflags.h"
#include "ui/base/l10n/l10n_util.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
#include "brave/browser/ui/content_settings/brave_widevine_bundle_util.h"
#endif

BraveWidevineContentSettingPluginBubbleModel::BraveWidevineContentSettingPluginBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents) :
Expand Down Expand Up @@ -57,6 +61,11 @@ void BraveWidevineContentSettingPluginBubbleModel::RunPluginsOnPage() {
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
RegisterWidevineCdmComponent(g_brave_browser_process->component_updater());
#endif

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
RegisterWidevineCdmToCdmRegistry();
#endif

ChromeSubresourceFilterClient::FromWebContents(web_contents())
->OnReloadRequested();
}
Expand Down
20 changes: 20 additions & 0 deletions patches/content-browser-media-cdm_registry_impl.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/content/browser/media/cdm_registry_impl.cc b/content/browser/media/cdm_registry_impl.cc
index 81936b7601aa72effc5f99a188da72f8b9469568..e030f292f44e9e731ed5c10b404d3156e482dd44 100644
--- a/content/browser/media/cdm_registry_impl.cc
+++ b/content/browser/media/cdm_registry_impl.cc
@@ -27,8 +27,15 @@ CdmRegistryImpl::CdmRegistryImpl() {}
CdmRegistryImpl::~CdmRegistryImpl() {}

void CdmRegistryImpl::Init() {
+ // In linux, we want to register widevine cdm to CdmRegistry when users opted
+ // in. If not, widevine is initialized by default.
+ // Instead, we tries to register it in
+ // BraveBrowserMainExtraParts::PreMainMessageLoopRun() by checking opted in
+ // prefs.
+#if defined(BRAVE_CHROMIUM_BUILD) && !defined(OS_LINUX)
// Let embedders register CDMs.
GetContentClient()->AddContentDecryptionModules(&cdms_, nullptr);
+#endif
}

void CdmRegistryImpl::RegisterCdm(const CdmInfo& info) {

0 comments on commit 2529475

Please sign in to comment.