OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/pepper_plugin_registry.h" | 5 #include "content/common/pepper_plugin_registry.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/native_library.h" | 9 #include "base/native_library.h" |
10 #include "base/path_service.h" | |
11 #include "base/string_split.h" | 10 #include "base/string_split.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
14 #include "chrome/common/chrome_paths.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "content/common/child_process.h" | 13 #include "content/common/child_process.h" |
| 14 #include "content/common/content_client.h" |
17 #include "content/common/content_switches.h" | 15 #include "content/common/content_switches.h" |
18 #include "remoting/client/plugin/pepper_entrypoints.h" | |
19 #include "webkit/plugins/npapi/plugin_list.h" | 16 #include "webkit/plugins/npapi/plugin_list.h" |
20 | 17 |
21 namespace { | 18 namespace { |
22 | 19 |
23 const char* kPDFPluginName = "Chrome PDF Viewer"; | |
24 const char* kPDFPluginMimeType = "application/pdf"; | |
25 const char* kPDFPluginExtension = "pdf"; | |
26 const char* kPDFPluginDescription = "Portable Document Format"; | |
27 | |
28 const char* kNaClPluginName = "Chrome NaCl"; | |
29 const char* kNaClPluginMimeType = "application/x-nacl"; | |
30 const char* kNaClPluginExtension = "nexe"; | |
31 const char* kNaClPluginDescription = "Native Client Executable"; | |
32 | |
33 #if defined(ENABLE_REMOTING) | |
34 const char* kRemotingPluginMimeType = "pepper-application/x-chromoting"; | |
35 #endif | |
36 | |
37 const char* kFlashPluginName = "Shockwave Flash"; | |
38 const char* kFlashPluginSwfMimeType = "application/x-shockwave-flash"; | |
39 const char* kFlashPluginSwfExtension = "swf"; | |
40 const char* kFlashPluginSwfDescription = "Shockwave Flash"; | |
41 const char* kFlashPluginSplMimeType = "application/futuresplash"; | |
42 const char* kFlashPluginSplExtension = "spl"; | |
43 const char* kFlashPluginSplDescription = "FutureSplash Player"; | |
44 | |
45 // Appends the known built-in plugins to the given vector. Some built-in | |
46 // plugins are "internal" which means they are compiled into the Chrome binary, | |
47 // and some are extra shared libraries distributed with the browser (these are | |
48 // not marked internal, aside from being automatically registered, they're just | |
49 // regular plugins). | |
50 void ComputeBuiltInPlugins(std::vector<PepperPluginInfo>* plugins) { | |
51 // PDF. | |
52 // | |
53 // Once we're sandboxed, we can't know if the PDF plugin is available or not; | |
54 // but (on Linux) this function is always called once before we're sandboxed. | |
55 // So the first time through test if the file is available and then skip the | |
56 // check on subsequent calls if yes. | |
57 static bool skip_pdf_file_check = false; | |
58 FilePath path; | |
59 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) { | |
60 if (skip_pdf_file_check || file_util::PathExists(path)) { | |
61 PepperPluginInfo pdf; | |
62 pdf.path = path; | |
63 pdf.name = kPDFPluginName; | |
64 webkit::npapi::WebPluginMimeType pdf_mime_type(kPDFPluginMimeType, | |
65 kPDFPluginExtension, | |
66 kPDFPluginDescription); | |
67 pdf.mime_types.push_back(pdf_mime_type); | |
68 plugins->push_back(pdf); | |
69 | |
70 skip_pdf_file_check = true; | |
71 } | |
72 } | |
73 | |
74 // Handle the Native Client plugin just like the PDF plugin. | |
75 static bool skip_nacl_file_check = false; | |
76 if (PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) { | |
77 if (skip_nacl_file_check || file_util::PathExists(path)) { | |
78 PepperPluginInfo nacl; | |
79 nacl.path = path; | |
80 nacl.name = kNaClPluginName; | |
81 webkit::npapi::WebPluginMimeType nacl_mime_type(kNaClPluginMimeType, | |
82 kNaClPluginExtension, | |
83 kNaClPluginDescription); | |
84 nacl.mime_types.push_back(nacl_mime_type); | |
85 plugins->push_back(nacl); | |
86 | |
87 skip_nacl_file_check = true; | |
88 } | |
89 } | |
90 | |
91 // Remoting. | |
92 #if defined(ENABLE_REMOTING) | |
93 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
94 switches::kEnableRemoting)) { | |
95 PepperPluginInfo info; | |
96 info.is_internal = true; | |
97 info.path = FilePath(FILE_PATH_LITERAL("internal-chromoting")); | |
98 webkit::npapi::WebPluginMimeType remoting_mime_type(kRemotingPluginMimeType, | |
99 std::string(), | |
100 std::string()); | |
101 info.mime_types.push_back(remoting_mime_type); | |
102 info.internal_entry_points.get_interface = remoting::PPP_GetInterface; | |
103 info.internal_entry_points.initialize_module = | |
104 remoting::PPP_InitializeModule; | |
105 info.internal_entry_points.shutdown_module = remoting::PPP_ShutdownModule; | |
106 | |
107 plugins->push_back(info); | |
108 } | |
109 #endif | |
110 } | |
111 | |
112 // Appends any plugins from the command line to the given vector. | 20 // Appends any plugins from the command line to the given vector. |
113 void ComputePluginsFromCommandLine(std::vector<PepperPluginInfo>* plugins) { | 21 void ComputePluginsFromCommandLine(std::vector<PepperPluginInfo>* plugins) { |
114 // Flash being out of process is handled separately than general plugins | |
115 // for testing purposes. | |
116 bool out_of_process = | 22 bool out_of_process = |
117 CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiOutOfProcess); | 23 CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiOutOfProcess); |
118 bool flash_out_of_process = !CommandLine::ForCurrentProcess()->HasSwitch( | |
119 switches::kPpapiFlashInProcess); | |
120 | |
121 // Handle any Pepper Flash first. | |
122 const CommandLine::StringType flash_path = | |
123 CommandLine::ForCurrentProcess()->GetSwitchValueNative( | |
124 switches::kPpapiFlashPath); | |
125 if (!flash_path.empty()) { | |
126 PepperPluginInfo plugin; | |
127 plugin.is_out_of_process = flash_out_of_process; | |
128 plugin.path = FilePath(flash_path); | |
129 plugin.name = kFlashPluginName; | |
130 | |
131 const std::string flash_version = | |
132 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
133 switches::kPpapiFlashVersion); | |
134 std::vector<std::string> flash_version_numbers; | |
135 base::SplitString(flash_version, '.', &flash_version_numbers); | |
136 if (flash_version_numbers.size() < 1) | |
137 flash_version_numbers.push_back("10"); | |
138 // |SplitString()| puts in an empty string given an empty string. :( | |
139 else if (flash_version_numbers[0].empty()) | |
140 flash_version_numbers[0] = "10"; | |
141 if (flash_version_numbers.size() < 2) | |
142 flash_version_numbers.push_back("2"); | |
143 if (flash_version_numbers.size() < 3) | |
144 flash_version_numbers.push_back("999"); | |
145 if (flash_version_numbers.size() < 4) | |
146 flash_version_numbers.push_back("999"); | |
147 // E.g., "Shockwave Flash 10.2 r154": | |
148 plugin.description = plugin.name + " " + flash_version_numbers[0] + "." + | |
149 flash_version_numbers[1] + " r" + flash_version_numbers[2]; | |
150 plugin.version = JoinString(flash_version_numbers, '.'); | |
151 webkit::npapi::WebPluginMimeType swf_mime_type(kFlashPluginSwfMimeType, | |
152 kFlashPluginSwfExtension, | |
153 kFlashPluginSwfDescription); | |
154 plugin.mime_types.push_back(swf_mime_type); | |
155 webkit::npapi::WebPluginMimeType spl_mime_type(kFlashPluginSplMimeType, | |
156 kFlashPluginSplExtension, | |
157 kFlashPluginSplDescription); | |
158 plugin.mime_types.push_back(spl_mime_type); | |
159 plugins->push_back(plugin); | |
160 } | |
161 | |
162 // Handle other plugins. | |
163 const std::string value = | 24 const std::string value = |
164 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 25 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
165 switches::kRegisterPepperPlugins); | 26 switches::kRegisterPepperPlugins); |
166 if (value.empty()) | 27 if (value.empty()) |
167 return; | 28 return; |
168 | 29 |
169 // FORMAT: | 30 // FORMAT: |
170 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | 31 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) |
171 // plugin-entry = | 32 // plugin-entry = |
172 // <file-path> + | 33 // <file-path> + |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 plugin.description); | 69 plugin.description); |
209 plugin.mime_types.push_back(mime_type); | 70 plugin.mime_types.push_back(mime_type); |
210 } | 71 } |
211 | 72 |
212 plugins->push_back(plugin); | 73 plugins->push_back(plugin); |
213 } | 74 } |
214 } | 75 } |
215 | 76 |
216 } // namespace | 77 } // namespace |
217 | 78 |
218 const char* PepperPluginRegistry::kPDFPluginName = ::kPDFPluginName; | |
219 | |
220 webkit::npapi::WebPluginInfo PepperPluginInfo::ToWebPluginInfo() const { | 79 webkit::npapi::WebPluginInfo PepperPluginInfo::ToWebPluginInfo() const { |
221 webkit::npapi::WebPluginInfo info; | 80 webkit::npapi::WebPluginInfo info; |
222 | 81 |
223 info.name = name.empty() ? path.BaseName().LossyDisplayName() : | 82 info.name = name.empty() ? path.BaseName().LossyDisplayName() : |
224 ASCIIToUTF16(name); | 83 ASCIIToUTF16(name); |
225 info.path = path; | 84 info.path = path; |
226 info.version = ASCIIToUTF16(version); | 85 info.version = ASCIIToUTF16(version); |
227 info.desc = ASCIIToUTF16(description); | 86 info.desc = ASCIIToUTF16(description); |
228 info.mime_types = mime_types; | 87 info.mime_types = mime_types; |
229 | 88 |
230 webkit::npapi::WebPluginInfo::EnabledStates enabled_state = | 89 webkit::npapi::WebPluginInfo::EnabledStates enabled_state = |
231 webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; | 90 webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; |
232 | 91 |
233 // Enable the Native Client Plugin based on the command line. | 92 if (!enabled) { |
234 // TODO(abarth): This is the wrong place to do this work! | 93 enabled_state = |
235 if (name == kNaClPluginName) { | |
236 bool nacl_enabled = | |
237 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl); | |
238 enabled_state = nacl_enabled ? | |
239 webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED : | |
240 webkit::npapi::WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; | 94 webkit::npapi::WebPluginInfo::USER_DISABLED_POLICY_UNMANAGED; |
241 } | 95 } |
| 96 |
242 info.enabled = enabled_state; | 97 info.enabled = enabled_state; |
243 return info; | 98 return info; |
244 } | 99 } |
245 | 100 |
246 PepperPluginInfo::PepperPluginInfo() | 101 PepperPluginInfo::PepperPluginInfo() |
247 : is_internal(false), | 102 : is_internal(false), |
248 is_out_of_process(false) { | 103 is_out_of_process(false), |
| 104 enabled(true) { |
249 } | 105 } |
250 | 106 |
251 PepperPluginInfo::~PepperPluginInfo() { | 107 PepperPluginInfo::~PepperPluginInfo() { |
252 } | 108 } |
253 | 109 |
254 NaClModuleInfo::NaClModuleInfo() { | |
255 } | |
256 | |
257 NaClModuleInfo::~NaClModuleInfo() { | |
258 } | |
259 | |
260 // static | 110 // static |
261 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 111 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
262 static PepperPluginRegistry* registry = NULL; | 112 static PepperPluginRegistry* registry = NULL; |
263 // This object leaks. It is a temporary hack to work around a crash. | 113 // This object leaks. It is a temporary hack to work around a crash. |
264 // http://code.google.com/p/chromium/issues/detail?id=63234 | 114 // http://code.google.com/p/chromium/issues/detail?id=63234 |
265 if (!registry) | 115 if (!registry) |
266 registry = new PepperPluginRegistry; | 116 registry = new PepperPluginRegistry; |
267 return registry; | 117 return registry; |
268 } | 118 } |
269 | 119 |
270 // static | 120 // static |
271 void PepperPluginRegistry::ComputeList(std::vector<PepperPluginInfo>* plugins) { | 121 void PepperPluginRegistry::ComputeList(std::vector<PepperPluginInfo>* plugins) { |
272 ComputeBuiltInPlugins(plugins); | 122 content::GetContentClient()->AddPepperPlugins(plugins); |
273 ComputePluginsFromCommandLine(plugins); | 123 ComputePluginsFromCommandLine(plugins); |
274 } | 124 } |
275 | 125 |
276 // static | 126 // static |
277 void PepperPluginRegistry::PreloadModules() { | 127 void PepperPluginRegistry::PreloadModules() { |
278 std::vector<PepperPluginInfo> plugins; | 128 std::vector<PepperPluginInfo> plugins; |
279 ComputeList(&plugins); | 129 ComputeList(&plugins); |
280 for (size_t i = 0; i < plugins.size(); ++i) { | 130 for (size_t i = 0; i < plugins.size(); ++i) { |
281 if (!plugins[i].is_internal) { | 131 if (!plugins[i].is_internal) { |
282 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path); | 132 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 224 |
375 base::WaitableEvent* PepperPluginRegistry::GetShutdownEvent() { | 225 base::WaitableEvent* PepperPluginRegistry::GetShutdownEvent() { |
376 DCHECK(ChildProcess::current()) << "Must be in the renderer."; | 226 DCHECK(ChildProcess::current()) << "Must be in the renderer."; |
377 return ChildProcess::current()->GetShutDownEvent(); | 227 return ChildProcess::current()->GetShutDownEvent(); |
378 } | 228 } |
379 | 229 |
380 std::set<PP_Instance>* PepperPluginRegistry::GetGloballySeenInstanceIDSet() { | 230 std::set<PP_Instance>* PepperPluginRegistry::GetGloballySeenInstanceIDSet() { |
381 // This function is not needed on the host side of the proxy. | 231 // This function is not needed on the host side of the proxy. |
382 return NULL; | 232 return NULL; |
383 } | 233 } |
384 | |
385 void PepperPluginRegistry::RegisterNaClModule(const GURL& url, | |
386 const std::string& mime_type) { | |
387 NaClModuleInfo info; | |
388 info.url = url; | |
389 info.mime_type = mime_type; | |
390 | |
391 DCHECK(FindNaClModule(url) == nacl_module_list_.end()); | |
392 nacl_module_list_.push_front(info); | |
393 } | |
394 | |
395 void PepperPluginRegistry::UnregisterNaClModule(const GURL& url) { | |
396 NaClModuleInfoList::iterator iter = FindNaClModule(url); | |
397 DCHECK(iter != nacl_module_list_.end()); | |
398 nacl_module_list_.erase(iter); | |
399 } | |
400 | |
401 void PepperPluginRegistry::UpdatePluginListWithNaClModules() { | |
402 FilePath path; | |
403 PathService::Get(chrome::FILE_NACL_PLUGIN, &path); | |
404 | |
405 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path); | |
406 | |
407 const PepperPluginInfo* pepper_info = GetInfoForPlugin(path); | |
408 webkit::npapi::WebPluginInfo info = pepper_info->ToWebPluginInfo(); | |
409 | |
410 DCHECK(nacl_module_list_.size() <= 1); | |
411 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | |
412 iter != nacl_module_list_.end(); ++iter) { | |
413 webkit::npapi::WebPluginMimeType mime_type_info; | |
414 mime_type_info.mime_type = iter->mime_type; | |
415 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); | |
416 mime_type_info.additional_param_values.push_back( | |
417 UTF8ToUTF16(iter->url.spec())); | |
418 info.mime_types.push_back(mime_type_info); | |
419 } | |
420 | |
421 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | |
422 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); | |
423 } | |
424 | |
425 PepperPluginRegistry::NaClModuleInfoList::iterator | |
426 PepperPluginRegistry::FindNaClModule(const GURL& url) { | |
427 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | |
428 iter != nacl_module_list_.end(); ++iter) { | |
429 if (iter->url == url) | |
430 return iter; | |
431 } | |
432 return nacl_module_list_.end(); | |
433 } | |
OLD | NEW |