#include "chrome/common/media/cdm_host_file_path.h"
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version.h"
#if BUILDFLAG(IS_MAC)
#include "base/apple/bundle_locations.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
namespace {
const base::FilePath::CharType kSignatureFileExtension[] =
FILE_PATH_LITERAL(".sig");
base::FilePath GetSigFilePath(const base::FilePath& file_path) {
return file_path.AddExtension(kSignatureFileExtension);
}
}
void AddCdmHostFilePaths(
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
DVLOG(1) << __func__;
DCHECK(cdm_host_file_paths);
DCHECK(cdm_host_file_paths->empty());
#if BUILDFLAG(IS_WIN)
base::FilePath dir_exe;
CHECK(base::PathService::Get(base::DIR_EXE, &dir_exe));
base::FilePath chrome_exe =
dir_exe.Append(chrome::kBrowserProcessExecutableName);
base::FilePath chrome_assets_dir;
CHECK(base::PathService::Get(base::DIR_ASSETS, &chrome_assets_dir));
const auto chrome_exe_sig = GetSigFilePath(
chrome_assets_dir.Append(chrome::kBrowserProcessExecutableName));
DVLOG(2) << __func__ << ":" << chrome_exe.value() << ", signature file "
<< chrome_exe_sig.value();
cdm_host_file_paths->emplace_back(chrome_exe, chrome_exe_sig);
const auto chrome_dll =
chrome_assets_dir.Append(chrome::kBrowserResourcesDll);
const auto chrome_dll_sig = GetSigFilePath(chrome_dll);
DVLOG(2) << __func__ << ":" << chrome_dll.value() << ", signature file "
<< chrome_dll_sig.value();
cdm_host_file_paths->emplace_back(chrome_dll, chrome_dll_sig);
#elif BUILDFLAG(IS_MAC)
base::FilePath framework_dir = base::apple::FrameworkBundlePath();
base::FilePath chrome_framework_path =
framework_dir.Append(chrome::kFrameworkExecutableName);
base::FilePath widevine_signature_path = framework_dir.Append("Resources");
base::FilePath chrome_framework_sig_path = GetSigFilePath(
widevine_signature_path.Append(chrome::kFrameworkExecutableName));
DVLOG(2) << __func__
<< ": chrome_framework_path=" << chrome_framework_path.value()
<< ", signature_path=" << chrome_framework_sig_path.value();
cdm_host_file_paths->emplace_back(chrome_framework_path,
chrome_framework_sig_path);
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
base::FilePath chrome_exe_dir;
if (!base::PathService::Get(base::DIR_EXE, &chrome_exe_dir)) {
NOTREACHED();
}
base::FilePath chrome_path =
chrome_exe_dir.Append(FILE_PATH_LITERAL("chrome"));
DVLOG(2) << __func__ << ": chrome_path=" << chrome_path.value();
cdm_host_file_paths->emplace_back(chrome_path, GetSigFilePath(chrome_path));
#endif
}
#else
void AddCdmHostFilePaths(
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
NOTIMPLEMENTED() << "CDM host file paths need to be provided for the CDM to "
"verify the host.";
}
#endif