shell_content_client.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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 5#include "extensions/shell/common/shell_content_client.h" 6 7#include "base/strings/string_piece.h" 8#include "base/strings/utf_string_conversions.h" 9#include "content/public/common/user_agent.h" 10#include "extensions/common/constants.h" 11#include "ui/base/l10n/l10n_util.h" 12#include "ui/base/resource/resource_bundle.h" 13 14#if !defined(DISABLE_NACL) 15#include "base/base_paths.h" 16#include "base/files/file_path.h" 17#include "base/path_service.h" 18#include "components/nacl/common/nacl_constants.h" 19#include "content/public/common/pepper_plugin_info.h" 20#include "ppapi/native_client/src/trusted/plugin/ppapi_entrypoints.h" 21#include "ppapi/shared_impl/ppapi_permissions.h" 22#endif 23 24namespace extensions { 25namespace { 26 27#if !defined(DISABLE_NACL) 28bool GetNaClPluginPath(base::FilePath* path) { 29 // On Posix, plugins live in the module directory. 30 base::FilePath module; 31 if (!PathService::Get(base::DIR_MODULE, &module)) 32 return false; 33 *path = module.Append(nacl::kInternalNaClPluginFileName); 34 return true; 35} 36#endif // !defined(DISABLE_NACL) 37 38} // namespace 39 40ShellContentClient::ShellContentClient() { 41} 42 43ShellContentClient::~ShellContentClient() { 44} 45 46void ShellContentClient::AddPepperPlugins( 47 std::vector<content::PepperPluginInfo>* plugins) { 48#if !defined(DISABLE_NACL) 49 base::FilePath path; 50 if (!GetNaClPluginPath(&path)) 51 return; 52 53 content::PepperPluginInfo nacl; 54 // The nacl plugin is now built into the binary. 55 nacl.is_internal = true; 56 nacl.path = path; 57 nacl.name = nacl::kNaClPluginName; 58 content::WebPluginMimeType nacl_mime_type(nacl::kNaClPluginMimeType, 59 nacl::kNaClPluginExtension, 60 nacl::kNaClPluginDescription); 61 nacl.mime_types.push_back(nacl_mime_type); 62 content::WebPluginMimeType pnacl_mime_type(nacl::kPnaclPluginMimeType, 63 nacl::kPnaclPluginExtension, 64 nacl::kPnaclPluginDescription); 65 nacl.mime_types.push_back(pnacl_mime_type); 66 nacl.internal_entry_points.get_interface = nacl_plugin::PPP_GetInterface; 67 nacl.internal_entry_points.initialize_module = 68 nacl_plugin::PPP_InitializeModule; 69 nacl.internal_entry_points.shutdown_module = 70 nacl_plugin::PPP_ShutdownModule; 71 nacl.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV; 72 plugins->push_back(nacl); 73#endif // !defined(DISABLE_NACL) 74} 75 76void ShellContentClient::AddAdditionalSchemes( 77 std::vector<std::string>* standard_schemes, 78 std::vector<std::string>* savable_schemes) { 79 standard_schemes->push_back(kExtensionScheme); 80 savable_schemes->push_back(kExtensionScheme); 81 standard_schemes->push_back(kExtensionResourceScheme); 82 savable_schemes->push_back(kExtensionResourceScheme); 83} 84 85std::string ShellContentClient::GetUserAgent() const { 86 // TODO(derat): Figure out what this should be for app_shell and determine 87 // whether we need to include a version number to placate browser sniffing. 88 return content::BuildUserAgentFromProduct("Chrome"); 89} 90 91base::string16 ShellContentClient::GetLocalizedString(int message_id) const { 92 return l10n_util::GetStringUTF16(message_id); 93} 94 95base::StringPiece ShellContentClient::GetDataResource( 96 int resource_id, 97 ui::ScaleFactor scale_factor) const { 98 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( 99 resource_id, scale_factor); 100} 101 102base::RefCountedStaticMemory* ShellContentClient::GetDataResourceBytes( 103 int resource_id) const { 104 return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id); 105} 106 107gfx::Image& ShellContentClient::GetNativeImageNamed(int resource_id) const { 108 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); 109} 110 111} // namespace extensions 112