Commit 6cc3336b authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Clean up CdmHostFiles

Pepper CDM support is deprecated, so is ppapi CDM adapter binary. This
CL removes all CDM adapter related code from CdmHostFiles.

Also removes all CDM related code from PpapiThread, including CDM host
verification code that uses CdmHostFiles.

Bug: 772160
Change-Id: I727063d60eeccc60330c10c2fa9339bdc72813a3
Reviewed-on: https://chromium-review.googlesource.com/947923
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarJohn Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541579}
parent c6e5f181
......@@ -64,14 +64,7 @@
#include "sandbox/win/src/sandbox.h"
#endif
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
#include "media/cdm/cdm_host_file.h"
#include "media/cdm/cdm_host_files.h"
#endif
#if defined(OS_WIN)
const char kWidevineCdmAdapterFileName[] = "widevinecdmadapter.dll";
extern sandbox::TargetServices* g_target_services;
// Used by EnumSystemLocales for warming up.
......@@ -353,36 +346,6 @@ void PpapiThread::OnLoadPlugin(const base::FilePath& path,
}
}
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
// Use a local instance of CdmHostFiles so that if we return early for any
// error, all files will be closed automatically.
media::CdmHostFiles cdm_host_files;
auto cdm_status = media::CdmHostFiles::Status::kNotCalled;
// Open CDM host files before the process is sandboxed.
if (!is_broker_ && media::IsCdm(path)) {
std::vector<media::CdmHostFilePath> cdm_host_file_paths;
GetContentClient()->AddContentDecryptionModules(nullptr,
&cdm_host_file_paths);
cdm_host_files.InitializeWithAdapter(path, cdm_host_file_paths);
#if defined(OS_WIN)
// On Windows, initialize CDM host verification unsandboxed. On other
// platforms, this is called sandboxed below.
cdm_status =
cdm_host_files.InitVerificationWithAdapter(library.get(), path);
// Ignore other failures for backward compatibility, e.g. when using an old
// CDM which doesn't implement the verification API.
if (cdm_status == media::CdmHostFiles::Status::kInitVerificationFailed) {
LOG(WARNING) << "CDM host verification failed.";
// TODO(xhwang): Add a new load result if needed.
ReportLoadResult(path, INIT_FAILED);
return;
}
#endif // defined(OS_WIN)
}
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
#if defined(OS_WIN)
// If code subsequently tries to exit using abort(), force a crash (since
// otherwise these would be silent terminations and fly under the radar).
......@@ -392,13 +355,10 @@ void PpapiThread::OnLoadPlugin(const base::FilePath& path,
// can be loaded. TODO(cpu): consider changing to the loading style of
// regular plugins.
if (g_target_services) {
// Let Flash and Widevine CDM adapter load DXVA before lockdown.
if (permissions.HasPermission(ppapi::PERMISSION_FLASH) ||
path.BaseName().MaybeAsASCII() == kWidevineCdmAdapterFileName) {
if (permissions.HasPermission(ppapi::PERMISSION_FLASH)) {
// Let Flash load DXVA before lockdown.
LoadLibraryA("dxva2.dll");
}
if (permissions.HasPermission(ppapi::PERMISSION_FLASH)) {
base::CPU cpu;
if (cpu.vendor_name() == "AuthenticAMD") {
// The AMD crypto acceleration is only AMD Bulldozer and above.
......@@ -407,7 +367,7 @@ void PpapiThread::OnLoadPlugin(const base::FilePath& path,
#else
LoadLibraryA("amdhcp32.dll");
#endif
}
}
}
// Cause advapi32 to load before the sandbox is turned on.
......@@ -459,27 +419,6 @@ void PpapiThread::OnLoadPlugin(const base::FilePath& path,
}
#endif
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
if (!is_broker_ && media::IsCdm(path)) {
#if !defined(OS_WIN)
// Now we are sandboxed, initialize CDM host verification.
cdm_status =
cdm_host_files.InitVerificationWithAdapter(library.get(), path);
// Ignore other failures for backward compatibility, e.g. when using an
// old CDM which doesn't implement the verification API.
if (cdm_status == media::CdmHostFiles::Status::kInitVerificationFailed) {
LOG(WARNING) << "CDM host verification failed.";
// TODO(xhwang): Add a new load result if needed.
ReportLoadResult(path, INIT_FAILED);
return;
}
#endif // !defined(OS_WIN)
UMA_HISTOGRAM_ENUMERATION("Media.EME.CdmHostVerificationStatus",
cdm_status,
media::CdmHostFiles::Status::kStatusCount);
}
#endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
int32_t init_error = plugin_entry_points_.initialize_module(
local_pp_module_, &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
if (init_error != PP_OK) {
......
......@@ -20,10 +20,6 @@
#include "media/cdm/api/content_decryption_module_ext.h"
#include "media/cdm/cdm_paths.h"
// Needed for finding CDM path from CDM adapter path.
// TODO(crbug.com/403462): Remove this after CDM adapter is deprecated.
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
namespace media {
namespace {
......@@ -34,68 +30,11 @@ const base::FilePath::CharType kSignatureFileExtension[] =
// Returns the signature file path given the |file_path|. This function should
// only be used when the signature file and the file are located in the same
// directory, which is the case for the CDM and CDM adapter.
// directory, which is the case for the CDM.
base::FilePath GetSigFilePath(const base::FilePath& file_path) {
return file_path.AddExtension(kSignatureFileExtension);
}
// Returns the CDM library file name given the |cdm_adapter_file_name|. Returns
// nullptr if |cdm_adapter_file_name| does not correspond to a known CDM.
const char* GetCdmFileName(const base::FilePath& cdm_adapter_file_name) {
#if defined(WIDEVINE_CDM_AVAILABLE)
if (cdm_adapter_file_name ==
base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName))
return kWidevineCdmLibraryName;
#endif
// Clear Key CDM. For test only.
if (cdm_adapter_file_name ==
base::FilePath::FromUTF8Unsafe(media::kClearKeyCdmAdapterFileName))
return media::kClearKeyCdmLibraryName;
return nullptr;
}
// Returns the path to the CDM binary given the |cdm_adapter_path|. Returns an
// empty path if |cdm_adapter_path| does not correspond to a known CDM.
base::FilePath GetCdmPath(const base::FilePath& cdm_adapter_path) {
const char* cdm_file_name = GetCdmFileName(cdm_adapter_path.BaseName());
if (!cdm_file_name)
return base::FilePath();
return cdm_adapter_path.DirName().AppendASCII(
base::GetNativeLibraryName(cdm_file_name));
}
// Gets the library where InitVerificationFunc pointer can be obtained.
// TODO(crbug.com/403462): Remove this after CDM adapter is deprecated.
base::NativeLibrary GetCdmLibrary(base::NativeLibrary cdm_adapter_library,
const base::FilePath& cdm_adapter_path) {
DCHECK(cdm_adapter_library);
base::NativeLibrary cdm_library = nullptr;
#if defined(OS_LINUX) || defined(OS_MACOSX)
// On POSIX, "the dlsym() function shall search for the named symbol in all
// objects loaded automatically as a result of loading the object referenced
// by handle". Since the CDM is loaded automatically as a result of loading
// the CDM adapter, we can just use the adapter to look for CDM symbols.
cdm_library = cdm_adapter_library;
#elif defined(OS_WIN)
// On Windows, we have manually load the CDM.
base::ScopedNativeLibrary scoped_cdm_library;
base::NativeLibraryLoadError error;
scoped_cdm_library.Reset(
base::LoadNativeLibrary(GetCdmPath(cdm_adapter_path), &error));
if (!scoped_cdm_library.is_valid())
LOG(ERROR) << "Failed to load CDM (error: " << error.ToString() << ")";
else
cdm_library = scoped_cdm_library.get();
#endif
return cdm_library;
}
} // namespace
CdmHostFiles::CdmHostFiles() {
......@@ -106,13 +45,6 @@ CdmHostFiles::~CdmHostFiles() {
DVLOG(1) << __func__;
}
void CdmHostFiles::InitializeWithAdapter(
const base::FilePath& cdm_adapter_path,
const std::vector<CdmHostFilePath>& cdm_host_file_paths) {
OpenCdmFileWithAdapter(cdm_adapter_path);
OpenCommonFiles(cdm_host_file_paths);
}
void CdmHostFiles::Initialize(
const base::FilePath& cdm_path,
const std::vector<CdmHostFilePath>& cdm_host_file_paths) {
......@@ -120,19 +52,6 @@ void CdmHostFiles::Initialize(
OpenCommonFiles(cdm_host_file_paths);
}
CdmHostFiles::Status CdmHostFiles::InitVerificationWithAdapter(
base::NativeLibrary cdm_adapter_library,
const base::FilePath& cdm_adapter_path) {
DVLOG(1) << __func__;
DCHECK(cdm_adapter_library);
base::NativeLibrary cdm_library =
GetCdmLibrary(cdm_adapter_library, cdm_adapter_path);
if (!cdm_library)
return Status::kCdmLoadFailed;
return InitVerification(cdm_library);
}
CdmHostFiles::Status CdmHostFiles::InitVerification(
base::NativeLibrary cdm_library) {
DVLOG(1) << __func__;
......@@ -199,21 +118,6 @@ void CdmHostFiles::OpenCommonFiles(
}
}
void CdmHostFiles::OpenCdmFileWithAdapter(
const base::FilePath& cdm_adapter_path) {
DCHECK(!cdm_adapter_path.empty());
cdm_specific_files_.push_back(
CdmHostFile::Create(cdm_adapter_path, GetSigFilePath(cdm_adapter_path)));
base::FilePath cdm_path = GetCdmPath(cdm_adapter_path);
if (cdm_path.empty()) {
LOG(ERROR) << "CDM path is empty.";
return;
}
OpenCdmFile(cdm_path);
}
void CdmHostFiles::OpenCdmFile(const base::FilePath& cdm_path) {
DCHECK(!cdm_path.empty());
cdm_specific_files_.push_back(
......@@ -231,10 +135,4 @@ void CdmHostFiles::TakePlatformFiles(
cdm_host_files->push_back(file->TakePlatformFile());
}
// Question(xhwang): Any better way to check whether a plugin is a CDM? Maybe
// when we register the plugin we can set some flag explicitly?
bool IsCdm(const base::FilePath& cdm_adapter_path) {
return !GetCdmPath(cdm_adapter_path).empty();
}
} // namespace media
......@@ -29,21 +29,11 @@ class FilePath;
namespace media {
// Manages all CDM host files.
// TODO(xhwang): Remove all functions suffixed with "WithAdapter" after CDM
// adapter is deprecated.
class MEDIA_EXPORT CdmHostFiles {
public:
CdmHostFiles();
~CdmHostFiles();
// Opens all common files and CDM specific files for the CDM adapter
// registered at |cdm_adapter_path|.
void InitializeWithAdapter(
const base::FilePath& cdm_adapter_path,
const std::vector<CdmHostFilePath>& cdm_host_file_paths);
// Opens all common files and CDM specific files for the CDM at |cdm_path|.
void Initialize(const base::FilePath& cdm_path,
const std::vector<CdmHostFilePath>& cdm_host_file_paths);
......@@ -63,9 +53,7 @@ class MEDIA_EXPORT CdmHostFiles {
// by the CDM. If unexpected error happens, all files will be closed.
// Otherwise, the PlatformFiles are passed to the CDM which will close the
// files later.
// NOTE: Initialize*() must be called before calling this.
Status InitVerificationWithAdapter(base::NativeLibrary cdm_adapter_library,
const base::FilePath& cdm_adapter_path);
// NOTE: Initialize() must be called before calling this.
Status InitVerification(base::NativeLibrary cdm_library);
void CloseAllFiles();
......@@ -74,9 +62,6 @@ class MEDIA_EXPORT CdmHostFiles {
// Opens common CDM host files shared by all CDMs.
void OpenCommonFiles(const std::vector<CdmHostFilePath>& cdm_host_file_paths);
// Opens the CDM file and the CDM adapter file.
void OpenCdmFileWithAdapter(const base::FilePath& cdm_adapter_path);
// Opens the CDM file.
void OpenCdmFile(const base::FilePath& cdm_path);
......@@ -89,17 +74,12 @@ class MEDIA_EXPORT CdmHostFiles {
// Files common to all CDM types, e.g. main executable.
ScopedFileVector common_files_;
// Files specific to each CDM type. When the CDM is hosted by a CDM adapter,
// this includes both the CDM adapter and the CDM. Otherwise, this only
// includes the CDM.
// Files specific to each CDM type, e.g. the CDM binary.
ScopedFileVector cdm_specific_files_;
DISALLOW_COPY_AND_ASSIGN(CdmHostFiles);
};
// Returns whether the |cdm_adapter_path| corresponds to a known CDM.
bool MEDIA_EXPORT IsCdm(const base::FilePath& cdm_adapter_path);
} // namespace media
#endif // MEDIA_CDM_CDM_HOST_FILES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment