OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/pepper_plugin_registry.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/string_util.h" | |
9 #include "chrome/common/chrome_switches.h" | |
10 | |
11 // static | |
12 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | |
13 static PepperPluginRegistry registry; | |
14 return ®istry; | |
15 } | |
16 | |
17 pepper::PluginModule* PepperPluginRegistry::GetModule( | |
18 const std::string& mime_type) const { | |
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( | |
27 switches::kRegisterPepperPlugins); | |
28 if (value.empty()) | |
29 return; | |
30 | |
31 // FORMAT: | |
32 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | |
33 // plugin-entry = <file-path> + *1( LWS + ";" + LWS + <mime-type> ) | |
34 | |
35 std::vector<std::wstring> modules; | |
36 SplitString(value, ',', &modules); | |
37 for (size_t i = 0; i < modules.size(); ++i) { | |
38 std::vector<std::wstring> parts; | |
39 SplitString(modules[i], ';', &parts); | |
40 if (parts.size() < 2) { | |
41 DLOG(ERROR) << "Required mime-type not found"; | |
42 continue; | |
43 } | |
44 | |
45 const FilePath& file_path = FilePath::FromWStringHack(parts[0]); | |
46 ModuleHandle module = pepper::PluginModule::CreateModule(file_path); | |
47 if (!module) { | |
48 DLOG(ERROR) << "Failed to load pepper module: " << file_path.value(); | |
49 continue; | |
50 } | |
51 | |
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 } | |
61 } | |
OLD | NEW |