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