2015-07-16 17:40:01 -04:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
2012-04-03 01:34:16 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
#include "libcef/common/alloy/alloy_content_client.h"
|
2016-01-06 14:20:54 -05:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "include/cef_stream.h"
|
|
|
|
#include "include/cef_version.h"
|
2020-06-28 17:05:36 -04:00
|
|
|
#include "libcef/common/app_manager.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2015-03-25 17:22:47 -04: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-15 22:16:01 +00:00
|
|
|
#include "base/strings/string_piece.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "base/strings/string_split.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2013-06-22 02:06:32 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "chrome/common/chrome_constants.h"
|
2021-11-23 15:28:12 -05:00
|
|
|
#include "chrome/common/chrome_content_client.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-02-06 20:41:54 +00:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2021-08-09 17:18:43 -04:00
|
|
|
#include "chrome/common/media/cdm_registration.h"
|
2021-11-23 15:28:12 -05:00
|
|
|
#include "components/pdf/common/internal_plugin_helpers.h"
|
2021-08-09 17:18:43 -04:00
|
|
|
#include "content/public/common/cdm_info.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "content/public/common/content_constants.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2015-03-25 17:22:47 -04:00
|
|
|
#include "content/public/common/pepper_plugin_info.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
#include "ppapi/shared_impl/ppapi_permissions.h"
|
2018-10-02 15:14:11 +03:00
|
|
|
#include "third_party/widevine/cdm/buildflags.h"
|
2019-03-13 21:27:37 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2021-08-09 17:18:43 -04:00
|
|
|
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
|
|
|
|
#include "chrome/common/media/cdm_host_file_path.h"
|
2015-08-31 13:28:07 +02:00
|
|
|
#endif
|
|
|
|
|
2012-09-26 00:09:05 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-07-16 17:40:01 -04:00
|
|
|
// The following plugin-related methods are from
|
2015-03-25 17:22:47 -04:00
|
|
|
// chrome/common/chrome_content_client.cc
|
|
|
|
|
2015-07-16 17:40:01 -04:00
|
|
|
const char kPDFPluginExtension[] = "pdf";
|
|
|
|
const char kPDFPluginDescription[] = "Portable Document Format";
|
2017-05-17 11:29:28 +02:00
|
|
|
const uint32_t kPDFPluginPermissions =
|
2018-07-05 18:32:01 +00:00
|
|
|
ppapi::PERMISSION_PDF | ppapi::PERMISSION_DEV;
|
2015-07-16 17:40:01 -04:00
|
|
|
|
|
|
|
content::PepperPluginInfo::GetInterfaceFunc g_pdf_get_interface;
|
|
|
|
content::PepperPluginInfo::PPP_InitializeModuleFunc g_pdf_initialize_module;
|
|
|
|
content::PepperPluginInfo::PPP_ShutdownModuleFunc g_pdf_shutdown_module;
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
|
|
|
|
if (extensions::PdfExtensionEnabled()) {
|
|
|
|
content::PepperPluginInfo pdf_info;
|
|
|
|
pdf_info.is_internal = true;
|
|
|
|
pdf_info.is_out_of_process = true;
|
2021-11-23 15:28:12 -05:00
|
|
|
pdf_info.name = ChromeContentClient::kPDFInternalPluginName;
|
2015-07-16 17:40:01 -04:00
|
|
|
pdf_info.description = kPDFPluginDescription;
|
2021-11-23 15:28:12 -05:00
|
|
|
pdf_info.path = base::FilePath(ChromeContentClient::kPDFPluginPath);
|
|
|
|
content::WebPluginMimeType pdf_mime_type(pdf::kInternalPluginMimeType,
|
2017-05-17 11:29:28 +02:00
|
|
|
kPDFPluginExtension,
|
|
|
|
kPDFPluginDescription);
|
2015-07-16 17:40:01 -04:00
|
|
|
pdf_info.mime_types.push_back(pdf_mime_type);
|
|
|
|
pdf_info.internal_entry_points.get_interface = g_pdf_get_interface;
|
|
|
|
pdf_info.internal_entry_points.initialize_module = g_pdf_initialize_module;
|
|
|
|
pdf_info.internal_entry_points.shutdown_module = g_pdf_shutdown_module;
|
|
|
|
pdf_info.permissions = kPDFPluginPermissions;
|
|
|
|
plugins->push_back(pdf_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 00:09:05 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-06-28 17:05:36 -04:00
|
|
|
AlloyContentClient::AlloyContentClient() = default;
|
|
|
|
AlloyContentClient::~AlloyContentClient() = default;
|
2012-04-03 01:34:16 +00:00
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
void AlloyContentClient::AddPepperPlugins(
|
2015-03-25 17:22:47 -04:00
|
|
|
std::vector<content::PepperPluginInfo>* plugins) {
|
2015-07-16 17:40:01 -04:00
|
|
|
ComputeBuiltInPlugins(plugins);
|
2018-04-19 11:44:42 -04:00
|
|
|
}
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
void AlloyContentClient::AddContentDecryptionModules(
|
2018-04-19 11:44:42 -04:00
|
|
|
std::vector<content::CdmInfo>* cdms,
|
|
|
|
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
|
2021-08-09 17:18:43 -04:00
|
|
|
if (cdms)
|
|
|
|
RegisterCdmInfo(cdms);
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
|
|
|
|
if (cdm_host_file_paths)
|
|
|
|
AddCdmHostFilePaths(cdm_host_file_paths);
|
2016-10-14 11:56:41 -04:00
|
|
|
#endif
|
2015-03-25 17:22:47 -04:00
|
|
|
}
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
void AlloyContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
2020-06-28 17:05:36 -04:00
|
|
|
CefAppManager::Get()->AddAdditionalSchemes(schemes);
|
2012-04-24 18:01:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:34 -04:00
|
|
|
std::u16string AlloyContentClient::GetLocalizedString(int message_id) {
|
|
|
|
std::u16string value =
|
2017-10-20 13:45:20 -04:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
|
2012-04-03 01:34:16 +00:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:34 -04:00
|
|
|
std::u16string AlloyContentClient::GetLocalizedString(
|
2019-03-13 21:27:37 +00:00
|
|
|
int message_id,
|
2021-04-20 18:52:34 -04:00
|
|
|
const std::u16string& replacement) {
|
|
|
|
std::u16string value = l10n_util::GetStringFUTF16(message_id, replacement);
|
2019-07-16 13:59:21 -04:00
|
|
|
if (value.empty())
|
2019-03-13 21:27:37 +00:00
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
base::StringPiece AlloyContentClient::GetDataResource(
|
2012-05-31 15:19:33 +00:00
|
|
|
int resource_id,
|
2021-08-19 19:40:49 -04:00
|
|
|
ui::ResourceScaleFactor scale_factor) {
|
2012-05-18 15:04:56 +00:00
|
|
|
base::StringPiece value =
|
2017-10-20 13:45:20 -04:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
2012-11-05 20:18:20 +00:00
|
|
|
resource_id, scale_factor);
|
2012-04-03 01:34:16 +00:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No data resource available for id " << resource_id;
|
2012-08-04 00:59:58 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
base::RefCountedMemory* AlloyContentClient::GetDataResourceBytes(
|
2019-09-04 15:13:32 +00:00
|
|
|
int resource_id) {
|
2016-11-07 14:14:09 -05:00
|
|
|
base::RefCountedMemory* value =
|
2017-10-20 13:45:20 -04:00
|
|
|
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
|
|
|
|
resource_id);
|
2016-11-07 14:14:09 -05:00
|
|
|
if (!value)
|
|
|
|
LOG(ERROR) << "No data resource bytes available for id " << resource_id;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 14:29:44 -04:00
|
|
|
gfx::Image& AlloyContentClient::GetNativeImageNamed(int resource_id) {
|
2012-08-04 00:59:58 +00:00
|
|
|
gfx::Image& value =
|
2017-10-20 13:45:20 -04:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
|
2012-08-04 00:59:58 +00:00
|
|
|
if (value.IsEmpty())
|
|
|
|
LOG(ERROR) << "No native image available for id " << resource_id;
|
2012-04-03 01:34:16 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-07-16 17:40:01 -04:00
|
|
|
// static
|
2020-06-28 14:29:44 -04:00
|
|
|
void AlloyContentClient::SetPDFEntryFunctions(
|
2015-07-16 17:40:01 -04:00
|
|
|
content::PepperPluginInfo::GetInterfaceFunc get_interface,
|
|
|
|
content::PepperPluginInfo::PPP_InitializeModuleFunc initialize_module,
|
|
|
|
content::PepperPluginInfo::PPP_ShutdownModuleFunc shutdown_module) {
|
|
|
|
g_pdf_get_interface = get_interface;
|
|
|
|
g_pdf_initialize_module = initialize_module;
|
|
|
|
g_pdf_shutdown_module = shutdown_module;
|
|
|
|
}
|