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/renderer/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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 | 10 |
11 // static | 11 // static |
12 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 12 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
13 static PepperPluginRegistry registry; | 13 static PepperPluginRegistry registry; |
14 return ®istry; | 14 return ®istry; |
15 } | 15 } |
16 | 16 |
17 pepper::PluginModule* PepperPluginRegistry::GetModule( | 17 // static |
18 const std::string& mime_type) const { | 18 void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { |
19 ModuleMap::const_iterator it = modules_.find(mime_type); | |
20 if (it == modules_.end()) | |
21 return NULL; | |
22 return it->second; | |
23 } | |
24 | |
25 PepperPluginRegistry::PepperPluginRegistry() { | |
26 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( | 19 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( |
27 switches::kRegisterPepperPlugins); | 20 switches::kRegisterPepperPlugins); |
28 if (value.empty()) | 21 if (value.empty()) |
29 return; | 22 return; |
30 | 23 |
31 // FORMAT: | 24 // FORMAT: |
32 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | 25 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) |
33 // plugin-entry = <file-path> + *1( LWS + ";" + LWS + <mime-type> ) | 26 // plugin-entry = <file-path> + *1( LWS + ";" + LWS + <mime-type> ) |
34 | 27 |
35 std::vector<std::wstring> modules; | 28 std::vector<std::wstring> modules; |
36 SplitString(value, ',', &modules); | 29 SplitString(value, ',', &modules); |
37 for (size_t i = 0; i < modules.size(); ++i) { | 30 for (size_t i = 0; i < modules.size(); ++i) { |
38 std::vector<std::wstring> parts; | 31 std::vector<std::wstring> parts; |
39 SplitString(modules[i], ';', &parts); | 32 SplitString(modules[i], ';', &parts); |
40 if (parts.size() < 2) { | 33 if (parts.size() < 2) { |
41 DLOG(ERROR) << "Required mime-type not found"; | 34 DLOG(ERROR) << "Required mime-type not found"; |
42 continue; | 35 continue; |
43 } | 36 } |
44 | 37 |
45 const FilePath& file_path = FilePath::FromWStringHack(parts[0]); | 38 PepperPluginInfo plugin; |
46 ModuleHandle module = pepper::PluginModule::CreateModule(file_path); | 39 plugin.path = FilePath::FromWStringHack(parts[0]); |
| 40 for (size_t j = 1; j < parts.size(); ++j) |
| 41 plugin.mime_types.push_back(WideToASCII(parts[j])); |
| 42 |
| 43 plugins->push_back(plugin); |
| 44 } |
| 45 } |
| 46 |
| 47 pepper::PluginModule* PepperPluginRegistry::GetModule( |
| 48 const FilePath& path) const { |
| 49 ModuleMap::const_iterator it = modules_.find(path); |
| 50 if (it == modules_.end()) |
| 51 return NULL; |
| 52 return it->second; |
| 53 } |
| 54 |
| 55 PepperPluginRegistry::PepperPluginRegistry() { |
| 56 std::vector<PepperPluginInfo> plugins; |
| 57 GetList(&plugins); |
| 58 for (size_t i = 0; i < plugins.size(); ++i) { |
| 59 const FilePath& path = plugins[i].path; |
| 60 ModuleHandle module = pepper::PluginModule::CreateModule(path); |
47 if (!module) { | 61 if (!module) { |
48 DLOG(ERROR) << "Failed to load pepper module: " << file_path.value(); | 62 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
49 continue; | 63 continue; |
50 } | 64 } |
51 | 65 modules_[path] = module; |
52 for (size_t j = 1; j < parts.size(); ++j) { | |
53 const std::string& mime_type = WideToASCII(parts[j]); | |
54 if (modules_.find(mime_type) != modules_.end()) { | |
55 DLOG(ERROR) << "Type is already registered"; | |
56 continue; | |
57 } | |
58 modules_[mime_type] = module; | |
59 } | |
60 } | 66 } |
61 } | 67 } |
OLD | NEW |