Skip to content

Commit

Permalink
Fixes Widevine on Linux.
Browse files Browse the repository at this point in the history
Chromium changes:

https://chromium.googlesource.com/chromium/src/+/54c6ac50650c82426bcb363a57b18dc47a1dedc4

commit 54c6ac50650c82426bcb363a57b18dc47a1dedc4
Author: John Rummell <jrummell@chromium.org>
Date:   Tue Sep 24 23:52:06 2019 +0000

    Use manifest.json to determine features supported by Widevine CDM on Linux

    Use the manifest.json file bundled with Widevine CDM (on Linux) to
    determine the features supported by Widevine rather than have them
    explicitly specified in code. This is handled by the component updater
    for Windows and Mac, so extending it to Linux now that the Widevine CDM
    for Linux is in a separate directory.

    Bug: 971433

https://chromium.googlesource.com/chromium/src/+/a539416c1f041af93e054d1cd397f895762022bc

commit a539416c1f041af93e054d1cd397f895762022bc
Author: John Rummell <jrummell@chromium.org>
Date:   Thu Oct 3 21:39:30 2019 +0000

    Enable component updated Widevine CDM on desktop Linux

    On Linux the Widevine CDM is loaded into the zygote at startup. When the
    component updater runs sometime later and finds a newer version of the
    Widevine CDM, don't register it as the newer version can't be used.
    Instead, similar to Flash, save the path to the new Widevine CDM in the
    file latest-component-updated-widevine-cdm. Next time at startup this
    file will be checked, and if it references a usable Widevine CDM, use
    this version instead of the bundled CDM.

    Tested this by running Chrome built with an older version of the
    Widevine CDM, and then checking chrome://components for a newer (QA)
    version. As there is one, it gets updated. When restarting Chrome, the
    newer version is loaded. In both cases Widevine content was played using
    Shaka.

    Bug: 971433
  • Loading branch information
mkarolin committed Nov 13, 2019
1 parent ad6c822 commit ca6ad4d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
bool ret = ChromeMainDelegate::BasicStartupComplete(exit_code);

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
// Override chrome::FILE_WIDEVINE_CDM path because we install it in user data
// dir. Must call after ChromeMainDelegate::BasicStartupComplete() to use
// chrome paths.
// Override chrome::DIR_BUNDLED_WIDEVINE_CDM path because we install it in
// user data dir. Must call after ChromeMainDelegate::BasicStartupComplete()
// to use chrome paths.
brave::OverridePath();
#endif

Expand Down
1 change: 1 addition & 0 deletions browser/widevine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ source_set("widevine") {
"//components/prefs",
"//components/pref_registry",
"//components/services/unzip/public/cpp",
"//media/cdm:cdm_paths",
"//services/network/public/cpp",
"//services/service_manager/public/cpp",
"//third_party/widevine/cdm:headers",
Expand Down
38 changes: 28 additions & 10 deletions browser/widevine/brave_widevine_bundle_unzipper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "brave/browser/widevine/brave_widevine_bundle_unzipper.h"

#include <map>
#include <utility>

#include "base/bind.h"
Expand All @@ -14,6 +15,7 @@
#include "components/services/unzip/content/unzip_service.h"
#include "components/services/unzip/public/cpp/unzip.h"
#include "content/public/browser/browser_thread.h"
#include "media/cdm/cdm_paths.h"
#include "third_party/widevine/cdm/widevine_cdm_common.h"

namespace {
Expand All @@ -22,8 +24,10 @@ namespace {
bool IsWidevineCdmFile(const base::FilePath& file_path) {
CHECK(!file_path.IsAbsolute());
return base::FilePath::CompareEqualIgnoreCase(
file_path.value(),
base::GetNativeLibraryName(kWidevineCdmLibraryName));
file_path.value(),
base::GetNativeLibraryName(kWidevineCdmLibraryName)) ||
base::FilePath::CompareEqualIgnoreCase(file_path.value(),
"manifest.json");
}

base::Optional<base::FilePath> GetTempDirForUnzip() {
Expand Down Expand Up @@ -106,16 +110,30 @@ void BraveWidevineBundleUnzipper::OnUnzippedInTempDir(bool status) {
}

std::string BraveWidevineBundleUnzipper::MoveUnzippedLibFromTempToTargetDir() {
const base::FilePath source = temp_unzip_dir_.AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName));
DCHECK(base::PathExists(source));

const base::FilePath target = target_unzip_dir_.AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName));
// Lib should go into the platform specific directory, whereas the manifest
// goes to the top directory.
const base::FilePath widevine_lib_dir =
media::GetPlatformSpecificDirectory(target_unzip_dir_);
base::CreateDirectory(widevine_lib_dir);
const std::string widevine_lib_name =
base::GetNativeLibraryName(kWidevineCdmLibraryName);

const std::map<const base::StringPiece, const base::FilePath> files = {
{widevine_lib_name, widevine_lib_dir},
{"manifest.json", target_unzip_dir_}};

std::string error;
if (!base::Move(source, target))
error = "widevine lib move failed";
for (auto const& file : files) {
const base::FilePath source = temp_unzip_dir_.AppendASCII(file.first);
DCHECK(base::PathExists(source));
const base::FilePath target = file.second.AppendASCII(file.first);

if (!base::Move(source, target)) {
error = std::string("widevine lib failed to move: ") +
source.value() + " to " + target.value();
break;
}
}

base::DeleteFile(temp_unzip_dir_, true);

Expand Down
2 changes: 1 addition & 1 deletion browser/widevine/widevine_permission_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GURL WidevinePermissionRequest::GetOrigin() const {
}

void WidevinePermissionRequest::PermissionGranted() {
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
EnableWidevineCdmComponent(web_contents_);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest, BubbleTest) {

// OptedInPref of bundling tests are done by
// BraveWidevineBundleManagerBrowserTest.
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest,
CheckOptedInPrefStateForComponent) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
Expand Down
6 changes: 3 additions & 3 deletions browser/widevine/widevine_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#endif

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
#include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
#include "chrome/browser/profiles/profile_manager.h"
#endif
Expand Down Expand Up @@ -67,7 +67,7 @@ void OnWidevineInstallDone(const std::string& error) {
int GetWidevinePermissionRequestTextFrangmentResourceId() {
int message_id = -1;

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
message_id = IDS_WIDEVINE_PERMISSION_REQUEST_TEXT_FRAGMENT;
#endif

Expand All @@ -85,7 +85,7 @@ void RequestWidevinePermission(content::WebContents* web_contents) {
new WidevinePermissionRequest(web_contents));
}

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
void EnableWidevineCdmComponent(content::WebContents* web_contents) {
DCHECK(web_contents);

Expand Down
2 changes: 1 addition & 1 deletion browser/widevine/widevine_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void RequestWidevinePermission(content::WebContents* web_contents);
void InstallBundleOrRestartBrowser();
#endif

#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && !defined(OS_LINUX)
void EnableWidevineCdmComponent(content::WebContents* web_contents);
#endif

Expand Down
11 changes: 4 additions & 7 deletions common/brave_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ void RegisterPathProvider() {
void OverridePath() {
#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
// Brave downloads cdm lib to user dir when user accepts instead of shippig by
// default. So, override |FILE_WIDEVINE_CDM| to new path in user dir.
// default. So, override |DIR_BUNDLED_WIDEVINE_CDM| to new path in user dir.
base::FilePath widevine_cdm_path;
if (base::PathService::Get(chrome::DIR_USER_DATA, &widevine_cdm_path)) {
widevine_cdm_path =
widevine_cdm_path.AppendASCII(kWidevineCdmBaseDirectory)
.AppendASCII(base::GetNativeLibraryName(kWidevineCdmLibraryName));
base::PathService::OverrideAndCreateIfNeeded(chrome::FILE_WIDEVINE_CDM,
widevine_cdm_path,
true,
false);
widevine_cdm_path.AppendASCII(kWidevineCdmBaseDirectory);
base::PathService::OverrideAndCreateIfNeeded(
chrome::DIR_BUNDLED_WIDEVINE_CDM, widevine_cdm_path, true, false);
}
#endif
}
Expand Down

0 comments on commit ca6ad4d

Please sign in to comment.