shell_content_client.cc 3.8 KB

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