OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/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" | 10 #include "base/path_service.h" |
11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "remoting/client/plugin/pepper_entrypoints.h" | 16 #include "remoting/client/plugin/pepper_entrypoints.h" |
17 | 17 |
18 const char* PepperPluginRegistry::kPDFPluginName = "Chrome PDF Viewer"; | 18 const char* PepperPluginRegistry::kPDFPluginName = "Chrome PDF Viewer"; |
19 const char* PepperPluginRegistry::kPDFPluginMimeType = "application/pdf"; | 19 const char* PepperPluginRegistry::kPDFPluginMimeType = "application/pdf"; |
20 const char* PepperPluginRegistry::kPDFPluginExtension = "pdf"; | 20 const char* PepperPluginRegistry::kPDFPluginExtension = "pdf"; |
21 const char* PepperPluginRegistry::kPDFPluginDescription = | 21 const char* PepperPluginRegistry::kPDFPluginDescription = |
22 "Portable Document Format"; | 22 "Portable Document Format"; |
23 | 23 |
24 PepperPluginInfo::PepperPluginInfo() : is_internal(false) { | 24 PepperPluginInfo::PepperPluginInfo() |
| 25 : is_internal(false), |
| 26 is_out_of_process(false) { |
25 } | 27 } |
26 | 28 |
27 PepperPluginInfo::~PepperPluginInfo() {} | 29 PepperPluginInfo::~PepperPluginInfo() {} |
28 | 30 |
29 // static | 31 // static |
30 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 32 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
31 static PepperPluginRegistry registry; | 33 static PepperPluginRegistry registry; |
32 return ®istry; | 34 return ®istry; |
33 } | 35 } |
34 | 36 |
(...skipping 10 matching lines...) Expand all Loading... |
45 | 47 |
46 GetPluginInfoFromSwitch(plugins); | 48 GetPluginInfoFromSwitch(plugins); |
47 GetExtraPlugins(plugins); | 49 GetExtraPlugins(plugins); |
48 } | 50 } |
49 | 51 |
50 // static | 52 // static |
51 void PepperPluginRegistry::PreloadModules() { | 53 void PepperPluginRegistry::PreloadModules() { |
52 std::vector<PepperPluginInfo> plugins; | 54 std::vector<PepperPluginInfo> plugins; |
53 GetList(&plugins); | 55 GetList(&plugins); |
54 for (size_t i = 0; i < plugins.size(); ++i) { | 56 for (size_t i = 0; i < plugins.size(); ++i) { |
55 if (!plugins[i].is_internal) { | 57 if (!plugins[i].is_internal && !plugins[i].is_out_of_process) { |
56 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path); | 58 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path); |
57 LOG_IF(WARNING, !library) << "Unable to load plugin " | 59 LOG_IF(WARNING, !library) << "Unable to load plugin " |
58 << plugins[i].path.value(); | 60 << plugins[i].path.value(); |
59 } | 61 } |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 // static | 65 // static |
64 void PepperPluginRegistry::GetPluginInfoFromSwitch( | 66 void PepperPluginRegistry::GetPluginInfoFromSwitch( |
65 std::vector<PepperPluginInfo>* plugins) { | 67 std::vector<PepperPluginInfo>* plugins) { |
66 const std::string value = | 68 const std::string value = |
67 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 69 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
68 switches::kRegisterPepperPlugins); | 70 switches::kRegisterPepperPlugins); |
69 if (value.empty()) | 71 if (value.empty()) |
70 return; | 72 return; |
71 | 73 |
| 74 bool out_of_process = |
| 75 CommandLine::ForCurrentProcess()->HasSwitch(switches::kPpapiOutOfProcess); |
| 76 |
72 // FORMAT: | 77 // FORMAT: |
73 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | 78 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) |
74 // plugin-entry = <file-path> + ["#" + <name> + ["#" + <description>]] + | 79 // plugin-entry = <file-path> + ["#" + <name> + ["#" + <description>]] + |
75 // *1( LWS + ";" + LWS + <mime-type> ) | 80 // *1( LWS + ";" + LWS + <mime-type> ) |
76 | 81 |
77 std::vector<std::string> modules; | 82 std::vector<std::string> modules; |
78 base::SplitString(value, ',', &modules); | 83 base::SplitString(value, ',', &modules); |
79 for (size_t i = 0; i < modules.size(); ++i) { | 84 for (size_t i = 0; i < modules.size(); ++i) { |
80 std::vector<std::string> parts; | 85 std::vector<std::string> parts; |
81 base::SplitString(modules[i], ';', &parts); | 86 base::SplitString(modules[i], ';', &parts); |
82 if (parts.size() < 2) { | 87 if (parts.size() < 2) { |
83 DLOG(ERROR) << "Required mime-type not found"; | 88 DLOG(ERROR) << "Required mime-type not found"; |
84 continue; | 89 continue; |
85 } | 90 } |
86 | 91 |
87 std::vector<std::string> name_parts; | 92 std::vector<std::string> name_parts; |
88 base::SplitString(parts[0], '#', &name_parts); | 93 base::SplitString(parts[0], '#', &name_parts); |
89 | 94 |
90 PepperPluginInfo plugin; | 95 PepperPluginInfo plugin; |
| 96 plugin.is_out_of_process = out_of_process; |
91 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
92 // This means we can't provide plugins from non-ASCII paths, but | 98 // This means we can't provide plugins from non-ASCII paths, but |
93 // since this switch is only for development I don't think that's | 99 // since this switch is only for development I don't think that's |
94 // too awful. | 100 // too awful. |
95 plugin.path = FilePath(ASCIIToUTF16(name_parts[0])); | 101 plugin.path = FilePath(ASCIIToUTF16(name_parts[0])); |
96 #else | 102 #else |
97 plugin.path = FilePath(name_parts[0]); | 103 plugin.path = FilePath(name_parts[0]); |
98 #endif | 104 #endif |
99 if (name_parts.size() > 1) | 105 if (name_parts.size() > 1) |
100 plugin.name = name_parts[1]; | 106 plugin.name = name_parts[1]; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 info.mime_types.push_back("pepper-application/x-chromoting"); | 167 info.mime_types.push_back("pepper-application/x-chromoting"); |
162 info.entry_points.get_interface = remoting::PPP_GetInterface; | 168 info.entry_points.get_interface = remoting::PPP_GetInterface; |
163 info.entry_points.initialize_module = remoting::PPP_InitializeModule; | 169 info.entry_points.initialize_module = remoting::PPP_InitializeModule; |
164 info.entry_points.shutdown_module = remoting::PPP_ShutdownModule; | 170 info.entry_points.shutdown_module = remoting::PPP_ShutdownModule; |
165 | 171 |
166 plugin_info->push_back(info); | 172 plugin_info->push_back(info); |
167 } | 173 } |
168 #endif | 174 #endif |
169 } | 175 } |
170 | 176 |
| 177 bool PepperPluginRegistry::RunOutOfProcessForPlugin( |
| 178 const FilePath& path) const { |
| 179 // TODO(brettw) don't recompute this every time. But since this Pepper |
| 180 // switch is only for development, it's OK for now. |
| 181 std::vector<PepperPluginInfo> plugins; |
| 182 GetList(&plugins); |
| 183 for (size_t i = 0; i < plugins.size(); ++i) { |
| 184 if (path == plugins[i].path) |
| 185 return plugins[i].is_out_of_process; |
| 186 } |
| 187 return false; |
| 188 } |
| 189 |
171 pepper::PluginModule* PepperPluginRegistry::GetModule( | 190 pepper::PluginModule* PepperPluginRegistry::GetModule( |
172 const FilePath& path) const { | 191 const FilePath& path) const { |
173 ModuleMap::const_iterator it = modules_.find(path); | 192 ModuleMap::const_iterator it = modules_.find(path); |
174 if (it == modules_.end()) | 193 if (it == modules_.end()) |
175 return NULL; | 194 return NULL; |
176 return it->second; | 195 return it->second; |
177 } | 196 } |
178 | 197 |
179 PepperPluginRegistry::~PepperPluginRegistry() {} | 198 PepperPluginRegistry::~PepperPluginRegistry() {} |
180 | 199 |
181 PepperPluginRegistry::PepperPluginRegistry() { | 200 PepperPluginRegistry::PepperPluginRegistry() { |
182 InternalPluginInfoList internal_plugin_info; | 201 InternalPluginInfoList internal_plugin_info; |
183 GetInternalPluginInfo(&internal_plugin_info); | 202 GetInternalPluginInfo(&internal_plugin_info); |
| 203 |
184 // Register modules for these suckers. | 204 // Register modules for these suckers. |
185 for (InternalPluginInfoList::const_iterator it = | 205 for (InternalPluginInfoList::const_iterator it = |
186 internal_plugin_info.begin(); | 206 internal_plugin_info.begin(); |
187 it != internal_plugin_info.end(); | 207 it != internal_plugin_info.end(); |
188 ++it) { | 208 ++it) { |
189 const FilePath& path = it->path; | 209 const FilePath& path = it->path; |
190 ModuleHandle module = | 210 ModuleHandle module = |
191 pepper::PluginModule::CreateInternalModule(it->entry_points); | 211 pepper::PluginModule::CreateInternalModule(it->entry_points); |
192 if (!module) { | 212 if (!module) { |
193 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); | 213 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
194 continue; | 214 continue; |
195 } | 215 } |
196 module->set_name(it->name); | 216 module->set_name(it->name); |
197 modules_[path] = module; | 217 modules_[path] = module; |
198 } | 218 } |
199 | 219 |
200 // Add the modules specified on the command line last so that they can | 220 // Add the modules specified on the command line last so that they can |
201 // override the internal plugins. | 221 // override the internal plugins. |
202 std::vector<PepperPluginInfo> plugins; | 222 std::vector<PepperPluginInfo> plugins; |
203 GetPluginInfoFromSwitch(&plugins); | 223 GetPluginInfoFromSwitch(&plugins); |
204 GetExtraPlugins(&plugins); | 224 GetExtraPlugins(&plugins); |
205 for (size_t i = 0; i < plugins.size(); ++i) { | 225 for (size_t i = 0; i < plugins.size(); ++i) { |
| 226 if (plugins[i].is_out_of_process) |
| 227 continue; // Only preload in-process plugins. |
| 228 |
206 const FilePath& path = plugins[i].path; | 229 const FilePath& path = plugins[i].path; |
207 ModuleHandle module = pepper::PluginModule::CreateModule(path); | 230 ModuleHandle module = pepper::PluginModule::CreateModule(path); |
208 if (!module) { | 231 if (!module) { |
209 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); | 232 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
210 continue; | 233 continue; |
211 } | 234 } |
212 module->set_name(plugins[i].name); | 235 module->set_name(plugins[i].name); |
213 modules_[path] = module; | 236 modules_[path] = module; |
214 } | 237 } |
215 } | 238 } |
OLD | NEW |