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/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "remoting/client/plugin/pepper_entrypoints.h" | 15 #include "remoting/client/plugin/pepper_entrypoints.h" |
15 | 16 |
| 17 PepperPluginInfo::PepperPluginInfo() : is_internal(false) { |
| 18 } |
| 19 |
16 // static | 20 // static |
17 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { | 21 PepperPluginRegistry* PepperPluginRegistry::GetInstance() { |
18 static PepperPluginRegistry registry; | 22 static PepperPluginRegistry registry; |
19 return ®istry; | 23 return ®istry; |
20 } | 24 } |
21 | 25 |
22 // static | 26 // static |
23 void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { | 27 void PepperPluginRegistry::GetList(std::vector<PepperPluginInfo>* plugins) { |
24 InternalPluginInfoList internal_plugin_info; | 28 InternalPluginInfoList internal_plugin_info; |
25 GetInternalPluginInfo(&internal_plugin_info); | 29 GetInternalPluginInfo(&internal_plugin_info); |
26 for (InternalPluginInfoList::const_iterator it = | 30 for (InternalPluginInfoList::const_iterator it = |
27 internal_plugin_info.begin(); | 31 internal_plugin_info.begin(); |
28 it != internal_plugin_info.end(); | 32 it != internal_plugin_info.end(); |
29 ++it) { | 33 ++it) { |
30 plugins->push_back(*it); | 34 plugins->push_back(*it); |
31 } | 35 } |
32 | 36 |
33 GetPluginInfoFromSwitch(plugins); | 37 GetPluginInfoFromSwitch(plugins); |
34 GetExtraPlugins(plugins); | 38 GetExtraPlugins(plugins); |
35 } | 39 } |
36 | 40 |
37 // static | 41 // static |
| 42 void PepperPluginRegistry::PreloadModules() { |
| 43 std::vector<PepperPluginInfo> plugins; |
| 44 GetList(&plugins); |
| 45 for (size_t i = 0; i < plugins.size(); ++i) { |
| 46 if (!plugins[i].is_internal) { |
| 47 base::NativeLibrary library = base::LoadNativeLibrary(plugins[i].path); |
| 48 LOG_IF(WARNING, !library) << "Unable to load plugin " |
| 49 << plugins[i].path.value(); |
| 50 } |
| 51 } |
| 52 } |
| 53 |
| 54 // static |
38 void PepperPluginRegistry::GetPluginInfoFromSwitch( | 55 void PepperPluginRegistry::GetPluginInfoFromSwitch( |
39 std::vector<PepperPluginInfo>* plugins) { | 56 std::vector<PepperPluginInfo>* plugins) { |
40 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( | 57 const std::wstring& value = CommandLine::ForCurrentProcess()->GetSwitchValue( |
41 switches::kRegisterPepperPlugins); | 58 switches::kRegisterPepperPlugins); |
42 if (value.empty()) | 59 if (value.empty()) |
43 return; | 60 return; |
44 | 61 |
45 // FORMAT: | 62 // FORMAT: |
46 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) | 63 // command-line = <plugin-entry> + *( LWS + "," + LWS + <plugin-entry> ) |
47 // plugin-entry = <file-path> + ["#" + <name> + ["#" + <description>]] + | 64 // plugin-entry = <file-path> + ["#" + <name> + ["#" + <description>]] + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 PepperPluginInfo pdf; | 99 PepperPluginInfo pdf; |
83 pdf.path = path; | 100 pdf.path = path; |
84 pdf.name = "Chrome PDF Viewer"; | 101 pdf.name = "Chrome PDF Viewer"; |
85 pdf.mime_types.push_back("application/pdf"); | 102 pdf.mime_types.push_back("application/pdf"); |
86 pdf.file_extensions = "pdf"; | 103 pdf.file_extensions = "pdf"; |
87 pdf.type_descriptions = "Portable Document Format"; | 104 pdf.type_descriptions = "Portable Document Format"; |
88 plugins->push_back(pdf); | 105 plugins->push_back(pdf); |
89 } | 106 } |
90 } | 107 } |
91 | 108 |
| 109 PepperPluginRegistry::InternalPluginInfo::InternalPluginInfo() { |
| 110 is_internal = true; |
| 111 } |
| 112 |
92 // static | 113 // static |
93 void PepperPluginRegistry::GetInternalPluginInfo( | 114 void PepperPluginRegistry::GetInternalPluginInfo( |
94 InternalPluginInfoList* plugin_info) { | 115 InternalPluginInfoList* plugin_info) { |
95 // Currently, to centralize the internal plugin registration logic, we | 116 // Currently, to centralize the internal plugin registration logic, we |
96 // hardcode the list of plugins, mimetypes, and registration information | 117 // hardcode the list of plugins, mimetypes, and registration information |
97 // in this function. This is gross, but because the GetList() function is | 118 // in this function. This is gross, but because the GetList() function is |
98 // called from both the renderer and browser the other option is to force a | 119 // called from both the renderer and browser the other option is to force a |
99 // special register function for each plugin to be called by both | 120 // special register function for each plugin to be called by both |
100 // RendererMain() and BrowserMain(). This seemed like the better tradeoff. | 121 // RendererMain() and BrowserMain(). This seemed like the better tradeoff. |
101 // | 122 // |
102 // TODO(ajwong): Think up a better way to maintain the plugin registration | 123 // TODO(ajwong): Think up a better way to maintain the plugin registration |
103 // information. Pehraps by construction of a singly linked list of | 124 // information. Pehraps by construction of a singly linked list of |
104 // plugin initializers that is built with static initializers? | 125 // plugin initializers that is built with static initializers? |
105 | 126 |
106 #if defined(ENABLE_REMOTING) | 127 #if defined(ENABLE_REMOTING) |
107 if (CommandLine::ForCurrentProcess()->HasSwitch( | 128 if (CommandLine::ForCurrentProcess()->HasSwitch( |
108 switches::kEnableChromoting)) { | 129 switches::kEnableChromoting)) { |
109 InternalPluginInfo info; | 130 InternalPluginInfo info; |
110 // Add the chromoting plugin. | 131 // Add the chromoting plugin. |
| 132 DCHECK(info.is_internal); |
111 info.path = | 133 info.path = |
112 FilePath(FILE_PATH_LITERAL("internal-chromoting")); | 134 FilePath(FILE_PATH_LITERAL("internal-chromoting")); |
113 info.mime_types.push_back("pepper-application/x-chromoting"); | 135 info.mime_types.push_back("pepper-application/x-chromoting"); |
114 info.entry_points.get_interface = remoting::PPP_GetInterface; | 136 info.entry_points.get_interface = remoting::PPP_GetInterface; |
115 info.entry_points.initialize_module = remoting::PPP_InitializeModule; | 137 info.entry_points.initialize_module = remoting::PPP_InitializeModule; |
116 info.entry_points.shutdown_module = remoting::PPP_ShutdownModule; | 138 info.entry_points.shutdown_module = remoting::PPP_ShutdownModule; |
117 | 139 |
118 plugin_info->push_back(info); | 140 plugin_info->push_back(info); |
119 } | 141 } |
120 #endif | 142 #endif |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 for (size_t i = 0; i < plugins.size(); ++i) { | 176 for (size_t i = 0; i < plugins.size(); ++i) { |
155 const FilePath& path = plugins[i].path; | 177 const FilePath& path = plugins[i].path; |
156 ModuleHandle module = pepper::PluginModule::CreateModule(path); | 178 ModuleHandle module = pepper::PluginModule::CreateModule(path); |
157 if (!module) { | 179 if (!module) { |
158 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); | 180 DLOG(ERROR) << "Failed to load pepper module: " << path.value(); |
159 continue; | 181 continue; |
160 } | 182 } |
161 modules_[path] = module; | 183 modules_[path] = module; |
162 } | 184 } |
163 } | 185 } |
OLD | NEW |