2015-07-16 23:40:01 +02:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
2012-04-03 03:34:16 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/common/alloy/alloy_content_client.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_stream.h"
|
|
|
|
#include "include/cef_version.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "base/files/file_util.h"
|
|
|
|
#include "base/json/json_reader.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/path_service.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "base/strings/string_piece.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "chrome/common/chrome_constants.h"
|
2021-11-23 21:28:12 +01:00
|
|
|
#include "chrome/common/chrome_content_client.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2021-08-09 23:18:43 +02:00
|
|
|
#include "chrome/common/media/cdm_registration.h"
|
2021-11-23 21:28:12 +01:00
|
|
|
#include "components/pdf/common/internal_plugin_helpers.h"
|
2021-08-09 23:18:43 +02:00
|
|
|
#include "content/public/common/cdm_info.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "content/public/common/content_constants.h"
|
2022-09-26 21:30:45 +02:00
|
|
|
#include "content/public/common/content_plugin_info.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "ppapi/shared_impl/ppapi_permissions.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "third_party/widevine/cdm/buildflags.h"
|
2019-03-13 22:27:37 +01:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2021-08-09 23:18:43 +02:00
|
|
|
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
|
2022-10-04 21:54:13 +02:00
|
|
|
#include "libcef/common/cdm_host_file_path.h"
|
2015-08-31 13:28:07 +02:00
|
|
|
#endif
|
|
|
|
|
2012-09-26 02:09:05 +02:00
|
|
|
namespace {
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// The following plugin-related methods are from
|
2015-03-25 22:22:47 +01:00
|
|
|
// chrome/common/chrome_content_client.cc
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
constexpr char kPDFPluginName[] = "Chromium PDF Plugin";
|
|
|
|
constexpr char kPDFPluginExtension[] = "pdf";
|
|
|
|
constexpr char kPDFPluginDescription[] = "Portable Document Format";
|
|
|
|
constexpr uint32_t kPDFPluginPermissions =
|
2018-07-05 20:32:01 +02:00
|
|
|
ppapi::PERMISSION_PDF | ppapi::PERMISSION_DEV;
|
2015-07-16 23:40:01 +02:00
|
|
|
|
|
|
|
// Appends the known built-in plugins to the given vector. Some built-in
|
|
|
|
// plugins are "internal" which means they are compiled into the Chrome binary,
|
|
|
|
// and some are extra shared libraries distributed with the browser (these are
|
|
|
|
// not marked internal, aside from being automatically registered, they're just
|
|
|
|
// regular plugins).
|
2022-09-26 21:30:45 +02:00
|
|
|
void ComputeBuiltInPlugins(std::vector<content::ContentPluginInfo>* plugins) {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (extensions::PdfExtensionEnabled()) {
|
2022-09-26 21:30:45 +02:00
|
|
|
content::ContentPluginInfo pdf_info;
|
2015-07-16 23:40:01 +02:00
|
|
|
pdf_info.is_internal = true;
|
|
|
|
pdf_info.is_out_of_process = true;
|
2023-01-30 18:43:54 +01:00
|
|
|
pdf_info.name = kPDFPluginName;
|
2015-07-16 23:40:01 +02:00
|
|
|
pdf_info.description = kPDFPluginDescription;
|
2023-01-30 18:43:54 +01:00
|
|
|
pdf_info.path = base::FilePath(ChromeContentClient::kPDFInternalPluginPath);
|
2021-11-23 21:28:12 +01:00
|
|
|
content::WebPluginMimeType pdf_mime_type(pdf::kInternalPluginMimeType,
|
2017-05-17 11:29:28 +02:00
|
|
|
kPDFPluginExtension,
|
|
|
|
kPDFPluginDescription);
|
2015-07-16 23:40:01 +02:00
|
|
|
pdf_info.mime_types.push_back(pdf_mime_type);
|
|
|
|
pdf_info.permissions = kPDFPluginPermissions;
|
|
|
|
plugins->push_back(pdf_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 02:09:05 +02:00
|
|
|
} // namespace
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
AlloyContentClient::AlloyContentClient() = default;
|
|
|
|
AlloyContentClient::~AlloyContentClient() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
void AlloyContentClient::AddPlugins(
|
|
|
|
std::vector<content::ContentPluginInfo>* plugins) {
|
2015-07-16 23:40:01 +02:00
|
|
|
ComputeBuiltInPlugins(plugins);
|
2018-04-19 17:44:42 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentClient::AddContentDecryptionModules(
|
2018-04-19 17:44:42 +02:00
|
|
|
std::vector<content::CdmInfo>* cdms,
|
|
|
|
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cdms) {
|
2021-08-09 23:18:43 +02:00
|
|
|
RegisterCdmInfo(cdms);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-09 23:18:43 +02:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cdm_host_file_paths) {
|
2022-10-04 21:54:13 +02:00
|
|
|
cef::AddCdmHostFilePaths(cdm_host_file_paths);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-10-14 17:56:41 +02:00
|
|
|
#endif
|
2015-03-25 22:22:47 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
2020-06-28 23:05:36 +02:00
|
|
|
CefAppManager::Get()->AddAdditionalSchemes(schemes);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string AlloyContentClient::GetLocalizedString(int message_id) {
|
|
|
|
std::u16string value =
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string AlloyContentClient::GetLocalizedString(
|
2019-03-13 22:27:37 +01:00
|
|
|
int message_id,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& replacement) {
|
|
|
|
std::u16string value = l10n_util::GetStringFUTF16(message_id, replacement);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.empty()) {
|
2019-03-13 22:27:37 +01:00
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-03-13 22:27:37 +01:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
base::StringPiece AlloyContentClient::GetDataResource(
|
2012-05-31 17:19:33 +02:00
|
|
|
int resource_id,
|
2021-08-20 01:40:49 +02:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2012-05-18 17:04:56 +02:00
|
|
|
base::StringPiece value =
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
2012-11-05 21:18:20 +01:00
|
|
|
resource_id, scale_factor);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
LOG(ERROR) << "No data resource available for id " << resource_id;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-08-04 02:59:58 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
base::RefCountedMemory* AlloyContentClient::GetDataResourceBytes(
|
2019-09-04 17:13:32 +02:00
|
|
|
int resource_id) {
|
2016-11-07 20:14:09 +01:00
|
|
|
base::RefCountedMemory* value =
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
|
|
|
resource_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!value) {
|
2016-11-07 20:14:09 +01:00
|
|
|
LOG(ERROR) << "No data resource bytes available for id " << resource_id;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
gfx::Image& AlloyContentClient::GetNativeImageNamed(int resource_id) {
|
2012-08-04 02:59:58 +02:00
|
|
|
gfx::Image& value =
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.IsEmpty()) {
|
2012-08-04 02:59:58 +02:00
|
|
|
LOG(ERROR) << "No native image available for id " << resource_id;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|