2014-10-31 21:17:05 +03:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-08-27 16:48:49 +04:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 23:46:59 +03:00
|
|
|
#include "shell/app/electron_content_client.h"
|
2014-08-27 16:48:49 +04:00
|
|
|
|
2014-08-27 17:16:45 +04:00
|
|
|
#include <string>
|
2024-01-11 04:00:37 +03:00
|
|
|
#include <string_view>
|
2019-08-26 03:40:44 +03:00
|
|
|
#include <utility>
|
2014-08-27 17:16:45 +04:00
|
|
|
#include <vector>
|
|
|
|
|
2015-04-28 18:45:58 +03:00
|
|
|
#include "base/command_line.h"
|
2015-12-16 13:06:38 +03:00
|
|
|
#include "base/files/file_util.h"
|
2019-08-24 04:14:23 +03:00
|
|
|
#include "base/path_service.h"
|
2015-05-12 01:02:42 +03:00
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2015-12-16 13:06:38 +03:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-04-28 18:45:58 +03:00
|
|
|
#include "content/public/common/content_constants.h"
|
2020-04-01 05:33:16 +03:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-10-01 23:00:53 +03:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2023-11-09 21:23:52 +03:00
|
|
|
#include "electron/fuses.h"
|
2020-01-14 01:55:58 +03:00
|
|
|
#include "extensions/common/constants.h"
|
2022-03-25 04:39:03 +03:00
|
|
|
#include "pdf/buildflags.h"
|
2019-10-09 20:59:37 +03:00
|
|
|
#include "ppapi/buildflags/buildflags.h"
|
2020-05-07 23:31:26 +03:00
|
|
|
#include "shell/common/electron_paths.h"
|
2019-06-19 23:46:59 +03:00
|
|
|
#include "shell/common/options_switches.h"
|
2023-06-06 11:19:13 +03:00
|
|
|
#include "shell/common/process_util.h"
|
2022-07-12 10:48:51 +03:00
|
|
|
#include "third_party/widevine/cdm/buildflags.h"
|
2015-12-30 08:16:22 +03:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2018-10-22 20:04:23 +03:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2015-12-29 11:41:44 +03:00
|
|
|
#include "url/url_constants.h"
|
2018-09-06 00:00:37 +03:00
|
|
|
// In SHARED_INTERMEDIATE_DIR.
|
2020-04-24 22:57:41 +03:00
|
|
|
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
2015-12-16 13:06:38 +03:00
|
|
|
|
2022-07-12 10:48:51 +03:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-06 00:00:37 +03:00
|
|
|
#include "base/native_library.h"
|
|
|
|
#include "content/public/common/cdm_info.h"
|
|
|
|
#include "media/base/video_codecs.h"
|
2022-07-12 10:48:51 +03:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2015-12-16 13:06:38 +03:00
|
|
|
|
2018-10-01 23:00:53 +03:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2024-05-01 03:32:11 +03:00
|
|
|
#include "components/pdf/common/constants.h" // nogncheck
|
|
|
|
#include "pdf/pdf.h" // nogncheck
|
2020-02-13 03:39:12 +03:00
|
|
|
#include "shell/common/electron_constants.h"
|
|
|
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
2018-03-15 11:51:48 +03:00
|
|
|
|
2019-10-09 20:59:37 +03:00
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
2022-09-07 10:46:37 +03:00
|
|
|
#include "content/public/common/content_plugin_info.h"
|
2019-10-09 20:59:37 +03:00
|
|
|
#include "ppapi/shared_impl/ppapi_permissions.h"
|
2022-03-25 04:39:03 +03:00
|
|
|
#include "ppapi/shared_impl/ppapi_switches.h" // nogncheck crbug.com/1125897
|
|
|
|
#endif // BUILDFLAG(ENABLE_PLUGINS)
|
2019-10-09 20:59:37 +03:00
|
|
|
|
2014-08-27 16:48:49 +04:00
|
|
|
namespace electron {
|
|
|
|
|
2015-04-28 18:45:58 +03:00
|
|
|
namespace {
|
|
|
|
|
2020-10-27 20:51:45 +03:00
|
|
|
enum class WidevineCdmFileCheck {
|
|
|
|
kNotChecked,
|
|
|
|
kFound,
|
|
|
|
kNotFound,
|
|
|
|
};
|
|
|
|
|
2022-07-12 10:48:51 +03:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-15 03:06:29 +03:00
|
|
|
bool IsWidevineAvailable(
|
|
|
|
base::FilePath* cdm_path,
|
|
|
|
std::vector<media::VideoCodec>* codecs_supported,
|
2018-10-03 00:40:10 +03:00
|
|
|
base::flat_set<media::CdmSessionType>* session_types_supported,
|
2018-09-15 03:06:29 +03:00
|
|
|
base::flat_set<media::EncryptionMode>* modes_supported) {
|
2020-10-27 20:51:45 +03:00
|
|
|
static WidevineCdmFileCheck widevine_cdm_file_check =
|
|
|
|
WidevineCdmFileCheck::kNotChecked;
|
2018-09-06 00:00:37 +03:00
|
|
|
|
2020-10-27 20:51:45 +03:00
|
|
|
if (widevine_cdm_file_check == WidevineCdmFileCheck::kNotChecked) {
|
2018-09-10 22:35:05 +03:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
*cdm_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
|
|
|
|
if (!cdm_path->empty()) {
|
|
|
|
*cdm_path = cdm_path->AppendASCII(
|
|
|
|
base::GetNativeLibraryName(kWidevineCdmLibraryName));
|
2020-10-27 20:51:45 +03:00
|
|
|
widevine_cdm_file_check = base::PathExists(*cdm_path)
|
|
|
|
? WidevineCdmFileCheck::kFound
|
|
|
|
: WidevineCdmFileCheck::kNotFound;
|
2018-09-06 00:00:37 +03:00
|
|
|
}
|
2018-09-10 22:35:05 +03:00
|
|
|
}
|
|
|
|
|
2020-10-27 20:51:45 +03:00
|
|
|
if (widevine_cdm_file_check == WidevineCdmFileCheck::kFound) {
|
2018-09-10 22:35:05 +03:00
|
|
|
// Add the supported codecs as if they came from the component manifest.
|
|
|
|
// This list must match the CDM that is being bundled with Chrome.
|
|
|
|
codecs_supported->push_back(media::VideoCodec::kCodecVP8);
|
|
|
|
codecs_supported->push_back(media::VideoCodec::kCodecVP9);
|
2018-09-06 00:00:37 +03:00
|
|
|
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2018-09-10 22:35:05 +03:00
|
|
|
codecs_supported->push_back(media::VideoCodec::kCodecH264);
|
2018-09-06 00:00:37 +03:00
|
|
|
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
|
|
|
|
2018-10-03 00:40:10 +03:00
|
|
|
// TODO(crbug.com/767941): Push persistent-license support info here once
|
|
|
|
// we check in a new CDM that supports it on Linux.
|
|
|
|
session_types_supported->insert(media::CdmSessionType::kTemporary);
|
2022-02-10 05:58:52 +03:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS)
|
2018-10-03 00:40:10 +03:00
|
|
|
session_types_supported->insert(media::CdmSessionType::kPersistentLicense);
|
2022-02-10 05:58:52 +03:00
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS)
|
2018-09-15 03:06:29 +03:00
|
|
|
|
|
|
|
modes_supported->insert(media::EncryptionMode::kCenc);
|
|
|
|
|
2018-09-10 22:35:05 +03:00
|
|
|
return true;
|
2018-09-06 00:00:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-12 10:48:51 +03:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-06 00:00:37 +03:00
|
|
|
|
2024-01-11 04:00:37 +03:00
|
|
|
void AppendDelimitedSwitchToVector(const std::string_view cmd_switch,
|
2019-08-26 03:40:44 +03:00
|
|
|
std::vector<std::string>* append_me) {
|
2018-04-18 01:41:47 +03:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2019-08-26 03:40:44 +03:00
|
|
|
auto switch_value = command_line->GetSwitchValueASCII(cmd_switch);
|
|
|
|
if (!switch_value.empty()) {
|
2024-01-11 04:00:37 +03:00
|
|
|
constexpr std::string_view delimiter{",", 1};
|
2019-08-26 03:40:44 +03:00
|
|
|
auto tokens =
|
|
|
|
base::SplitString(switch_value, delimiter, base::TRIM_WHITESPACE,
|
|
|
|
base::SPLIT_WANT_NONEMPTY);
|
|
|
|
append_me->reserve(append_me->size() + tokens.size());
|
|
|
|
std::move(std::begin(tokens), std::end(tokens),
|
|
|
|
std::back_inserter(*append_me));
|
|
|
|
}
|
2015-12-08 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:45:58 +03:00
|
|
|
} // namespace
|
|
|
|
|
2019-09-17 01:12:00 +03:00
|
|
|
ElectronContentClient::ElectronContentClient() = default;
|
2014-08-27 16:48:49 +04:00
|
|
|
|
2019-09-17 01:12:00 +03:00
|
|
|
ElectronContentClient::~ElectronContentClient() = default;
|
2014-08-27 16:48:49 +04:00
|
|
|
|
2021-03-16 19:18:45 +03:00
|
|
|
std::u16string ElectronContentClient::GetLocalizedString(int message_id) {
|
2015-12-30 08:16:22 +03:00
|
|
|
return l10n_util::GetStringUTF16(message_id);
|
|
|
|
}
|
|
|
|
|
2018-10-22 20:04:23 +03:00
|
|
|
base::StringPiece ElectronContentClient::GetDataResource(
|
|
|
|
int resource_id,
|
2021-08-12 00:04:56 +03:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2018-10-22 20:04:23 +03:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
|
|
|
resource_id, scale_factor);
|
|
|
|
}
|
|
|
|
|
2019-07-03 04:22:09 +03:00
|
|
|
gfx::Image& ElectronContentClient::GetNativeImageNamed(int resource_id) {
|
2018-10-22 20:04:23 +03:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
|
|
|
resource_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
base::RefCountedMemory* ElectronContentClient::GetDataResourceBytes(
|
2019-07-03 04:22:09 +03:00
|
|
|
int resource_id) {
|
2018-10-22 20:04:23 +03:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
|
|
|
resource_id);
|
|
|
|
}
|
|
|
|
|
2017-04-04 07:50:44 +03:00
|
|
|
void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
2020-04-01 05:33:16 +03:00
|
|
|
// Browser Process registration happens in
|
|
|
|
// `api::Protocol::RegisterSchemesAsPrivileged`
|
|
|
|
//
|
|
|
|
// Renderer Process registration happens in `RendererClientBase`
|
|
|
|
//
|
|
|
|
// We use this for registration to network utility process
|
2023-06-06 11:19:13 +03:00
|
|
|
if (IsUtilityProcess()) {
|
2020-04-01 05:33:16 +03:00
|
|
|
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
|
|
|
|
&schemes->service_worker_schemes);
|
|
|
|
AppendDelimitedSwitchToVector(switches::kStandardSchemes,
|
|
|
|
&schemes->standard_schemes);
|
|
|
|
AppendDelimitedSwitchToVector(switches::kSecureSchemes,
|
|
|
|
&schemes->secure_schemes);
|
|
|
|
AppendDelimitedSwitchToVector(switches::kBypassCSPSchemes,
|
|
|
|
&schemes->csp_bypassing_schemes);
|
|
|
|
AppendDelimitedSwitchToVector(switches::kCORSSchemes,
|
|
|
|
&schemes->cors_enabled_schemes);
|
|
|
|
}
|
2017-04-04 07:50:44 +03:00
|
|
|
|
2023-11-09 21:23:52 +03:00
|
|
|
if (electron::fuses::IsGrantFileProtocolExtraPrivilegesEnabled()) {
|
|
|
|
schemes->service_worker_schemes.emplace_back(url::kFileScheme);
|
|
|
|
}
|
2021-02-11 18:58:03 +03:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
schemes->standard_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
schemes->savable_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
schemes->secure_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
schemes->service_worker_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
schemes->cors_enabled_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
schemes->csp_bypassing_schemes.push_back(extensions::kExtensionScheme);
|
|
|
|
#endif
|
2014-08-27 16:48:49 +04:00
|
|
|
}
|
|
|
|
|
2022-09-07 10:46:37 +03:00
|
|
|
void ElectronContentClient::AddPlugins(
|
|
|
|
std::vector<content::ContentPluginInfo>* plugins) {
|
2023-01-25 16:57:30 +03:00
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
static constexpr char kPDFPluginExtension[] = "pdf";
|
|
|
|
static constexpr char kPDFPluginDescription[] = "Portable Document Format";
|
|
|
|
|
|
|
|
content::ContentPluginInfo pdf_info;
|
|
|
|
pdf_info.is_internal = true;
|
|
|
|
pdf_info.is_out_of_process = true;
|
|
|
|
pdf_info.name = kPDFInternalPluginName;
|
|
|
|
pdf_info.description = kPDFPluginDescription;
|
|
|
|
// This isn't a real file path; it's just used as a unique identifier.
|
|
|
|
pdf_info.path = base::FilePath(kPdfPluginPath);
|
|
|
|
content::WebPluginMimeType pdf_mime_type(
|
|
|
|
pdf::kInternalPluginMimeType, kPDFPluginExtension, kPDFPluginDescription);
|
|
|
|
pdf_info.mime_types.push_back(pdf_mime_type);
|
|
|
|
plugins->push_back(pdf_info);
|
|
|
|
#endif // BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_PDF_VIEWER)
|
2015-04-28 18:45:58 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 18:20:00 +03:00
|
|
|
void ElectronContentClient::AddContentDecryptionModules(
|
|
|
|
std::vector<content::CdmInfo>* cdms,
|
|
|
|
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
|
2018-09-06 00:00:37 +03:00
|
|
|
if (cdms) {
|
2022-07-12 10:48:51 +03:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-06 00:00:37 +03:00
|
|
|
base::FilePath cdm_path;
|
|
|
|
std::vector<media::VideoCodec> video_codecs_supported;
|
2018-10-03 00:40:10 +03:00
|
|
|
base::flat_set<media::CdmSessionType> session_types_supported;
|
2018-09-15 03:06:29 +03:00
|
|
|
base::flat_set<media::EncryptionMode> encryption_modes_supported;
|
|
|
|
if (IsWidevineAvailable(&cdm_path, &video_codecs_supported,
|
2018-10-03 00:40:10 +03:00
|
|
|
&session_types_supported,
|
2018-09-15 03:06:29 +03:00
|
|
|
&encryption_modes_supported)) {
|
2018-09-06 00:00:37 +03:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
auto cdm_version_string =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
|
|
|
|
// CdmInfo needs |path| to be the actual Widevine library,
|
|
|
|
// not the adapter, so adjust as necessary. It will be in the
|
|
|
|
// same directory as the installed adapter.
|
|
|
|
const base::Version version(cdm_version_string);
|
|
|
|
DCHECK(version.IsValid());
|
|
|
|
|
2018-10-03 00:40:10 +03:00
|
|
|
content::CdmCapability capability(
|
|
|
|
video_codecs_supported, encryption_modes_supported,
|
|
|
|
session_types_supported, base::flat_set<media::CdmProxy::Protocol>());
|
|
|
|
|
2018-09-06 00:00:37 +03:00
|
|
|
cdms->push_back(content::CdmInfo(
|
|
|
|
kWidevineCdmDisplayName, kWidevineCdmGuid, version, cdm_path,
|
2018-10-03 00:40:10 +03:00
|
|
|
kWidevineCdmFileSystemId, capability, kWidevineKeySystem, false));
|
2018-09-06 00:00:37 +03:00
|
|
|
}
|
2022-07-12 10:48:51 +03:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-06 00:00:37 +03:00
|
|
|
}
|
2018-04-12 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
2014-08-27 16:48:49 +04:00
|
|
|
} // namespace electron
|