1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/common/shell_content_client.h"
#include <string_view>
#include "base/strings/utf_string_conversions.h"
#include "components/nacl/common/buildflags.h"
#include "extensions/common/constants.h"
#include "extensions/shell/common/version.h" // Generated file.
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#if BUILDFLAG(ENABLE_NACL)
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "components/nacl/common/nacl_constants.h" // nogncheck
#include "components/nacl/renderer/plugin/ppapi_entrypoints.h" // nogncheck
#include "content/public/common/content_plugin_info.h" // nogncheck
#include "ppapi/shared_impl/ppapi_permissions.h" // nogncheck
#endif
namespace extensions {
namespace {
#if BUILDFLAG(ENABLE_NACL)
bool GetNaClPluginPath(base::FilePath* path) {
// On Posix, plugins live in the module directory.
base::FilePath module;
if (!base::PathService::Get(base::DIR_MODULE, &module))
return false;
*path = module.Append(nacl::kInternalNaClPluginFileName);
return true;
}
#endif // BUILDFLAG(ENABLE_NACL)
} // namespace
ShellContentClient::ShellContentClient() {
}
ShellContentClient::~ShellContentClient() {
}
void ShellContentClient::AddPlugins(
std::vector<content::ContentPluginInfo>* plugins) {
#if BUILDFLAG(ENABLE_NACL)
base::FilePath path;
if (!GetNaClPluginPath(&path))
return;
content::ContentPluginInfo nacl;
// The nacl plugin is now built into the binary.
nacl.is_internal = true;
nacl.path = path;
nacl.name = nacl::kNaClPluginName;
content::WebPluginMimeType nacl_mime_type(nacl::kNaClPluginMimeType,
nacl::kNaClPluginExtension,
nacl::kNaClPluginDescription);
nacl.mime_types.push_back(nacl_mime_type);
content::WebPluginMimeType pnacl_mime_type(nacl::kPnaclPluginMimeType,
nacl::kPnaclPluginExtension,
nacl::kPnaclPluginDescription);
nacl.mime_types.push_back(pnacl_mime_type);
nacl.internal_entry_points.get_interface = nacl_plugin::PPP_GetInterface;
nacl.internal_entry_points.initialize_module =
nacl_plugin::PPP_InitializeModule;
nacl.internal_entry_points.shutdown_module =
nacl_plugin::PPP_ShutdownModule;
nacl.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV;
plugins->push_back(nacl);
#endif // BUILDFLAG(ENABLE_NACL)
}
void ShellContentClient::AddAdditionalSchemes(Schemes* schemes) {
schemes->standard_schemes.push_back(extensions::kExtensionScheme);
schemes->savable_schemes.push_back(kExtensionScheme);
schemes->secure_schemes.push_back(kExtensionScheme);
schemes->cors_enabled_schemes.push_back(kExtensionScheme);
schemes->csp_bypassing_schemes.push_back(kExtensionScheme);
}
std::u16string ShellContentClient::GetLocalizedString(int message_id) {
return l10n_util::GetStringUTF16(message_id);
}
std::string_view ShellContentClient::GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor) {
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
}
base::RefCountedMemory* ShellContentClient::GetDataResourceBytes(
int resource_id) {
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
}
gfx::Image& ShellContentClient::GetNativeImageNamed(int resource_id) {
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
resource_id);
}
} // namespace extensions
|