2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-08-27 12:48:49 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/app/electron_content_client.h"
|
2014-08-27 12:48:49 +00:00
|
|
|
|
2014-08-27 13:16:45 +00:00
|
|
|
#include <string>
|
2019-08-26 00:40:44 +00:00
|
|
|
#include <utility>
|
2014-08-27 13:16:45 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2015-04-28 15:45:58 +00:00
|
|
|
#include "base/command_line.h"
|
2015-12-16 10:06:38 +00:00
|
|
|
#include "base/files/file_util.h"
|
2019-08-24 01:14:23 +00:00
|
|
|
#include "base/path_service.h"
|
2015-05-11 22:02:42 +00:00
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2015-12-16 10:06:38 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-04-28 15:45:58 +00:00
|
|
|
#include "content/public/common/content_constants.h"
|
2020-04-01 02:33:16 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "extensions/common/constants.h"
|
2022-03-25 01:39:03 +00:00
|
|
|
#include "pdf/buildflags.h"
|
2019-10-09 17:59:37 +00:00
|
|
|
#include "ppapi/buildflags/buildflags.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2022-07-12 07:48:51 +00:00
|
|
|
#include "third_party/widevine/cdm/buildflags.h"
|
2015-12-30 05:16:22 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2018-10-22 17:04:23 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2015-12-29 08:41:44 +00:00
|
|
|
#include "url/url_constants.h"
|
2018-09-05 21:00:37 +00:00
|
|
|
// In SHARED_INTERMEDIATE_DIR.
|
2020-04-24 19:57:41 +00:00
|
|
|
#include "widevine_cdm_version.h" // NOLINT(build/include_directory)
|
2015-12-16 10:06:38 +00:00
|
|
|
|
2022-07-12 07:48:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-05 21:00:37 +00:00
|
|
|
#include "base/native_library.h"
|
|
|
|
#include "content/public/common/cdm_info.h"
|
|
|
|
#include "media/base/video_codecs.h"
|
2022-07-12 07:48:51 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2015-12-16 10:06:38 +00:00
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2022-03-30 18:55:38 +00:00
|
|
|
#include "chrome/common/pdf_util.h"
|
|
|
|
#include "components/pdf/common/internal_plugin_helpers.h"
|
2022-03-25 01:39:03 +00:00
|
|
|
#include "pdf/pdf.h" // nogncheck
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "shell/common/electron_constants.h"
|
|
|
|
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
2018-03-15 08:51:48 +00:00
|
|
|
|
2019-10-09 17:59:37 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
2022-09-07 07:46:37 +00:00
|
|
|
#include "content/public/common/content_plugin_info.h"
|
2019-10-09 17:59:37 +00:00
|
|
|
#include "ppapi/shared_impl/ppapi_permissions.h"
|
2022-03-25 01:39:03 +00:00
|
|
|
#include "ppapi/shared_impl/ppapi_switches.h" // nogncheck crbug.com/1125897
|
|
|
|
#endif // BUILDFLAG(ENABLE_PLUGINS)
|
2019-10-09 17:59:37 +00:00
|
|
|
|
2014-08-27 12:48:49 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2015-04-28 15:45:58 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
enum class WidevineCdmFileCheck {
|
|
|
|
kNotChecked,
|
|
|
|
kFound,
|
|
|
|
kNotFound,
|
|
|
|
};
|
|
|
|
|
2022-07-12 07:48:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-15 00:06:29 +00:00
|
|
|
bool IsWidevineAvailable(
|
|
|
|
base::FilePath* cdm_path,
|
|
|
|
std::vector<media::VideoCodec>* codecs_supported,
|
2018-10-02 21:40:10 +00:00
|
|
|
base::flat_set<media::CdmSessionType>* session_types_supported,
|
2018-09-15 00:06:29 +00:00
|
|
|
base::flat_set<media::EncryptionMode>* modes_supported) {
|
2020-10-27 17:51:45 +00:00
|
|
|
static WidevineCdmFileCheck widevine_cdm_file_check =
|
|
|
|
WidevineCdmFileCheck::kNotChecked;
|
2018-09-05 21:00:37 +00:00
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
if (widevine_cdm_file_check == WidevineCdmFileCheck::kNotChecked) {
|
2018-09-10 19:35:05 +00: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 17:51:45 +00:00
|
|
|
widevine_cdm_file_check = base::PathExists(*cdm_path)
|
|
|
|
? WidevineCdmFileCheck::kFound
|
|
|
|
: WidevineCdmFileCheck::kNotFound;
|
2018-09-05 21:00:37 +00:00
|
|
|
}
|
2018-09-10 19:35:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
if (widevine_cdm_file_check == WidevineCdmFileCheck::kFound) {
|
2018-09-10 19:35:05 +00: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-05 21:00:37 +00:00
|
|
|
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
2018-09-10 19:35:05 +00:00
|
|
|
codecs_supported->push_back(media::VideoCodec::kCodecH264);
|
2018-09-05 21:00:37 +00:00
|
|
|
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
|
|
|
|
2018-10-02 21:40:10 +00: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 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_CHROMEOS)
|
2018-10-02 21:40:10 +00:00
|
|
|
session_types_supported->insert(media::CdmSessionType::kPersistentLicense);
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_CHROMEOS)
|
2018-09-15 00:06:29 +00:00
|
|
|
|
|
|
|
modes_supported->insert(media::EncryptionMode::kCenc);
|
|
|
|
|
2018-09-10 19:35:05 +00:00
|
|
|
return true;
|
2018-09-05 21:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-12 07:48:51 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-05 21:00:37 +00:00
|
|
|
|
2019-08-26 00:40:44 +00:00
|
|
|
void AppendDelimitedSwitchToVector(const base::StringPiece cmd_switch,
|
|
|
|
std::vector<std::string>* append_me) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
2019-08-26 00:40:44 +00:00
|
|
|
auto switch_value = command_line->GetSwitchValueASCII(cmd_switch);
|
|
|
|
if (!switch_value.empty()) {
|
|
|
|
constexpr base::StringPiece delimiter(",", 1);
|
|
|
|
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 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 15:45:58 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronContentClient::ElectronContentClient() = default;
|
2014-08-27 12:48:49 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronContentClient::~ElectronContentClient() = default;
|
2014-08-27 12:48:49 +00:00
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string ElectronContentClient::GetLocalizedString(int message_id) {
|
2015-12-30 05:16:22 +00:00
|
|
|
return l10n_util::GetStringUTF16(message_id);
|
|
|
|
}
|
|
|
|
|
2018-10-22 17:04:23 +00:00
|
|
|
base::StringPiece ElectronContentClient::GetDataResource(
|
|
|
|
int resource_id,
|
2021-08-11 21:04:56 +00:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2018-10-22 17:04:23 +00:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
|
|
|
resource_id, scale_factor);
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
gfx::Image& ElectronContentClient::GetNativeImageNamed(int resource_id) {
|
2018-10-22 17:04:23 +00:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
|
|
|
resource_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
base::RefCountedMemory* ElectronContentClient::GetDataResourceBytes(
|
2019-07-03 01:22:09 +00:00
|
|
|
int resource_id) {
|
2018-10-22 17:04:23 +00:00
|
|
|
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
|
|
|
resource_id);
|
|
|
|
}
|
|
|
|
|
2017-04-04 04:50:44 +00:00
|
|
|
void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
2020-04-01 02:33:16 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
std::string process_type =
|
|
|
|
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
|
|
// Browser Process registration happens in
|
|
|
|
// `api::Protocol::RegisterSchemesAsPrivileged`
|
|
|
|
//
|
|
|
|
// Renderer Process registration happens in `RendererClientBase`
|
|
|
|
//
|
|
|
|
// We use this for registration to network utility process
|
|
|
|
if (process_type == ::switches::kUtilityProcess) {
|
|
|
|
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 04:50:44 +00:00
|
|
|
|
2019-09-13 14:26:59 +00:00
|
|
|
schemes->service_worker_schemes.emplace_back(url::kFileScheme);
|
2021-02-11 15:58:03 +00: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 12:48:49 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 07:46:37 +00:00
|
|
|
void ElectronContentClient::AddPlugins(
|
|
|
|
std::vector<content::ContentPluginInfo>* plugins) {
|
2023-01-25 13:57:30 +00: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 15:45:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 15:20:00 +00:00
|
|
|
void ElectronContentClient::AddContentDecryptionModules(
|
|
|
|
std::vector<content::CdmInfo>* cdms,
|
|
|
|
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
|
2018-09-05 21:00:37 +00:00
|
|
|
if (cdms) {
|
2022-07-12 07:48:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-05 21:00:37 +00:00
|
|
|
base::FilePath cdm_path;
|
|
|
|
std::vector<media::VideoCodec> video_codecs_supported;
|
2018-10-02 21:40:10 +00:00
|
|
|
base::flat_set<media::CdmSessionType> session_types_supported;
|
2018-09-15 00:06:29 +00:00
|
|
|
base::flat_set<media::EncryptionMode> encryption_modes_supported;
|
|
|
|
if (IsWidevineAvailable(&cdm_path, &video_codecs_supported,
|
2018-10-02 21:40:10 +00:00
|
|
|
&session_types_supported,
|
2018-09-15 00:06:29 +00:00
|
|
|
&encryption_modes_supported)) {
|
2018-09-05 21:00:37 +00: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-02 21:40:10 +00:00
|
|
|
content::CdmCapability capability(
|
|
|
|
video_codecs_supported, encryption_modes_supported,
|
|
|
|
session_types_supported, base::flat_set<media::CdmProxy::Protocol>());
|
|
|
|
|
2018-09-05 21:00:37 +00:00
|
|
|
cdms->push_back(content::CdmInfo(
|
|
|
|
kWidevineCdmDisplayName, kWidevineCdmGuid, version, cdm_path,
|
2018-10-02 21:40:10 +00:00
|
|
|
kWidevineCdmFileSystemId, capability, kWidevineKeySystem, false));
|
2018-09-05 21:00:37 +00:00
|
|
|
}
|
2022-07-12 07:48:51 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_WIDEVINE)
|
2018-09-05 21:00:37 +00:00
|
|
|
}
|
2018-04-12 15:20:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 12:48:49 +00:00
|
|
|
} // namespace electron
|