| 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/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "remoting/client/plugin/pepper_entrypoints.h" |
| 10 | 11 |
| 11 // static | 12 // static |
| 12 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 13 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
| 13 static PepperPluginRegistry registry; | 14 static PepperPluginRegistry registry; |
| 14 return ®istry; | 15 return ®istry; |
| 15 } | 16 } |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { | 19 void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { |
| 20 InternalPluginInfoList internal_plugin_info; |
| 21 GetInternalPluginInfo(&internal_plugin_info); |
| 22 for (InternalPluginInfoList::const_iterator it = |
| 23 internal_plugin_info.begin(); |
| 24 it != internal_plugin_info.end(); |
| 25 ++it) { |
| 26 plugins->push_back(*it); |
| 27 } |
| 28 |
| 29 GetPluginInfoFromSwitch(plugins); |
| 30 } |
| 31 |
| 32 // static |
| 33 void PepperPluginRegistry::GetPluginInfoFromSwitch( |
| 34 std::vector<PepperPluginInfo>* plugins) { |
| 19 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( | 35 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 20 switches::kRegisterPepperPlugins); | 36 switches::kRegisterPepperPlugins); |
| 21 if (value.empty()) | 37 if (value.empty()) |
| 22 return; | 38 return; |
| 23 | 39 |
| 24 // FORMAT: | 40 // FORMAT: |
| 25 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | 41 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) |
| 26 // plugin-entry = <file-path> + *1( LWS + ";" + LWS + <mime-type> ) | 42 // plugin-entry = <file-path> + *1( LWS + ";" + LWS + <mime-type> ) |
| 27 | 43 |
| 28 std::vector<std::wstring> modules; | 44 std::vector<std::wstring> modules; |
| 29 SplitString(value, ',', &modules); | 45 SplitString(value, ',', &modules); |
| 30 for (size_t i = 0; i < modules.size(); ++i) { | 46 for (size_t i = 0; i < modules.size(); ++i) { |
| 31 std::vector<std::wstring> parts; | 47 std::vector<std::wstring> parts; |
| 32 SplitString(modules[i], ';', &parts); | 48 SplitString(modules[i], ';', &parts); |
| 33 if (parts.size() < 2) { | 49 if (parts.size() < 2) { |
| 34 DLOG(ERROR) << "Required mime-type not found"; | 50 DLOG(ERROR) << "Required mime-type not found"; |
| 35 continue; | 51 continue; |
| 36 } | 52 } |
| 37 | 53 |
| 38 PepperPluginInfo plugin; | 54 PepperPluginInfo plugin; |
| 39 plugin.path = FilePath::FromWStringHack(parts[0]); | 55 plugin.path = FilePath::FromWStringHack(parts[0]); |
| 40 for (size_t j = 1; j < parts.size(); ++j) | 56 for (size_t j = 1; j < parts.size(); ++j) |
| 41 plugin.mime_types.push_back(WideToASCII(parts[j])); | 57 plugin.mime_types.push_back(WideToASCII(parts[j])); |
| 42 | 58 |
| 43 plugins->push_back(plugin); | 59 plugins->push_back(plugin); |
| 44 } | 60 } |
| 45 } | 61 } |
| 46 | 62 |
| 63 // static |
| 64 void PepperPluginRegistry::GetInternalPluginInfo( |
| 65 InternalPluginInfoList* plugin_info) { |
| 66 // Currently, to centralize the internal plugin registration logic, we |
| 67 // hardcode the list of plugins, mimetypes, and registration information |
| 68 // in this function. This is gross, but because the GetList() function is |
| 69 // called from both the renderer and browser the other option is to force a |
| 70 // special register function for each plugin to be called by both |
| 71 // RendererMain() and BrowserMain(). This seemed like the better tradeoff. |
| 72 // |
| 73 // TODO(ajwong): Think up a better way to maintain the plugin registration |
| 74 // information. Pehraps by construction of a singly linked list of |
| 75 // plugin initializers that is built with static initializers? |
| 76 |
| 77 #if defined(ENABLE_REMOTING) |
| 78 InternalPluginInfo info; |
| 79 // Add the chromoting plugin. |
| 80 info.path = |
| 81 FilePath(FILE_PATH_LITERAL("internal-chromoting")); |
| 82 info.mime_types.push_back("pepper-application/x-chromoting"); |
| 83 info.entry_points.get_interface = remoting::PPP_GetInterface; |
| 84 info.entry_points.initialize_module = remoting::PPP_InitializeModule; |
| 85 info.entry_points.shutdown_module = remoting::PPP_ShutdownModule; |
| 86 |
| 87 plugin_info->push_back(info); |
| 88 #endif |
| 89 |
| 90 } |
| 91 |
| 47 pepper::PluginModule* PepperPluginRegistry::GetModule( | 92 pepper::PluginModule* PepperPluginRegistry::GetModule( |
| 48 const FilePath& path) const { | 93 const FilePath& path) const { |
| 49 ModuleMap::const_iterator it = modules_.find(path); | 94 ModuleMap::const_iterator it = modules_.find(path); |
| 50 if (it == modules_.end()) | 95 if (it == modules_.end()) |
| 51 return NULL; | 96 return NULL; |
| 52 return it->second; | 97 return it->second; |
| 53 } | 98 } |
| 54 | 99 |
| 55 PepperPluginRegistry::PepperPluginRegistry() { | 100 PepperPluginRegistry::PepperPluginRegistry() { |
| 101 InternalPluginInfoList internal_plugin_info; |
| 102 GetInternalPluginInfo(&internal_plugin_info); |
| 103 // Register modules for these suckers. |
| 104 for (InternalPluginInfoList::const_iterator it = |
| 105 internal_plugin_info.begin(); |
| 106 it != internal_plugin_info.end(); |
| 107 ++it) { |
| 108 const FilePath& path = it->path; |
| 109 ModuleHandle module = |
| 110 pepper::PluginModule::CreateInternalModule(it->entry_points); |
| 111 if (!module) { |
| 112 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
| 113 continue; |
| 114 } |
| 115 modules_[path] = module; |
| 116 } |
| 117 |
| 118 // Add the modules specified on the command line last so that they can |
| 119 // override the internal plugins. |
| 56 std::vector<PepperPluginInfo> plugins; | 120 std::vector<PepperPluginInfo> plugins; |
| 57 GetList(&plugins); | 121 GetPluginInfoFromSwitch(&plugins); |
| 58 for (size_t i = 0; i < plugins.size(); ++i) { | 122 for (size_t i = 0; i < plugins.size(); ++i) { |
| 59 const FilePath& path = plugins[i].path; | 123 const FilePath& path = plugins[i].path; |
| 60 ModuleHandle module = pepper::PluginModule::CreateModule(path); | 124 ModuleHandle module = pepper::PluginModule::CreateModule(path); |
| 61 if (!module) { | 125 if (!module) { |
| 62 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); | 126 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
| 63 continue; | 127 continue; |
| 64 } | 128 } |
| 65 modules_[path] = module; | 129 modules_[path] = module; |
| 66 } | 130 } |
| 67 } | 131 } |
| OLD | NEW |