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"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/pdf_extension_util.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"
|
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "content/public/common/content_constants.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
#include "content/public/common/pepper_plugin_info.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"
|
|
|
|
|
2016-10-14 17:56:41 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/common/widevine_loader.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
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
const char kPDFPluginExtension[] = "pdf";
|
|
|
|
const char kPDFPluginDescription[] = "Portable Document Format";
|
2017-05-17 11:29:28 +02:00
|
|
|
const char kPDFPluginOutOfProcessMimeType[] = "application/x-google-chrome-pdf";
|
|
|
|
const 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
|
|
|
|
|
|
|
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;
|
|
|
|
pdf_info.name = extensions::pdf_extension_util::kPdfPluginName;
|
|
|
|
pdf_info.description = kPDFPluginDescription;
|
|
|
|
pdf_info.path =
|
2020-06-28 20:29:44 +02:00
|
|
|
base::FilePath::FromUTF8Unsafe(AlloyContentClient::kPDFPluginPath);
|
2017-05-17 11:29:28 +02:00
|
|
|
content::WebPluginMimeType pdf_mime_type(kPDFPluginOutOfProcessMimeType,
|
|
|
|
kPDFPluginExtension,
|
|
|
|
kPDFPluginDescription);
|
2015-07-16 23:40:01 +02: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 02:09:05 +02:00
|
|
|
} // namespace
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
const char AlloyContentClient::kPDFPluginPath[] = "internal-pdf-viewer";
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
AlloyContentClient::AlloyContentClient() = default;
|
|
|
|
AlloyContentClient::~AlloyContentClient() = default;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentClient::AddPepperPlugins(
|
2015-03-25 22:22:47 +01:00
|
|
|
std::vector<content::PepperPluginInfo>* 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) {
|
2016-10-14 17:56:41 +02:00
|
|
|
#if defined(OS_LINUX)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if BUILDFLAG(ENABLE_WIDEVINE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
2018-04-19 17:44:42 +02:00
|
|
|
CefWidevineLoader::AddContentDecryptionModules(cdms, cdm_host_file_paths);
|
2016-10-14 17:56:41 +02:00
|
|
|
#endif
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
base::string16 AlloyContentClient::GetLocalizedString(int message_id) {
|
2013-12-17 23:04:35 +01:00
|
|
|
base::string16 value =
|
2017-10-20 19:45:20 +02:00
|
|
|
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
base::string16 AlloyContentClient::GetLocalizedString(
|
2019-03-13 22:27:37 +01:00
|
|
|
int message_id,
|
2019-09-04 17:13:32 +02:00
|
|
|
const base::string16& replacement) {
|
2019-03-13 22:27:37 +01:00
|
|
|
base::string16 value = l10n_util::GetStringFUTF16(message_id, replacement);
|
2019-07-16 19:59:21 +02:00
|
|
|
if (value.empty())
|
2019-03-13 22:27:37 +01:00
|
|
|
LOG(ERROR) << "No localized string available for id " << message_id;
|
|
|
|
|
|
|
|
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,
|
2019-09-04 17:13:32 +02:00
|
|
|
ui::ScaleFactor 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);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (value.empty())
|
|
|
|
LOG(ERROR) << "No data resource available for id " << resource_id;
|
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);
|
2016-11-07 20:14:09 +01:00
|
|
|
if (!value)
|
|
|
|
LOG(ERROR) << "No data resource bytes available for id " << resource_id;
|
|
|
|
|
|
|
|
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);
|
2012-08-04 02:59:58 +02:00
|
|
|
if (value.IsEmpty())
|
|
|
|
LOG(ERROR) << "No native image available for id " << resource_id;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// static
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyContentClient::SetPDFEntryFunctions(
|
2015-07-16 23:40:01 +02: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;
|
|
|
|
}
|