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 "webkit/plugins/npapi/plugin_lib.h" | 5 #include "webkit/plugins/npapi/plugin_lib.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #if defined(OS_OPENBSD) | 8 #if defined(OS_OPENBSD) |
9 #include <sys/exec_elf.h> | 9 #include <sys/exec_elf.h> |
10 #else | 10 #else |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 // The plugin name and description live behind NP_GetValue calls. | 179 // The plugin name and description live behind NP_GetValue calls. |
180 typedef NPError (*NP_GetValueType)(void* unused, | 180 typedef NPError (*NP_GetValueType)(void* unused, |
181 nsPluginVariable variable, | 181 nsPluginVariable variable, |
182 void* value_out); | 182 void* value_out); |
183 NP_GetValueType NP_GetValue = | 183 NP_GetValueType NP_GetValue = |
184 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue")); | 184 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue")); |
185 if (NP_GetValue) { | 185 if (NP_GetValue) { |
186 const char* name = NULL; | 186 const char* name = NULL; |
187 NP_GetValue(NULL, nsPluginVariable_NameString, &name); | 187 NP_GetValue(NULL, nsPluginVariable_NameString, &name); |
188 if (name) | 188 if (name) { |
189 info->name = UTF8ToUTF16(name); | 189 info->name = UTF8ToUTF16(name); |
| 190 ExtractVersionString(name, info); |
| 191 } |
190 | 192 |
191 const char* description = NULL; | 193 const char* description = NULL; |
192 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description); | 194 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description); |
193 if (description) | 195 if (description) { |
194 info->desc = UTF8ToUTF16(description); | 196 info->desc = UTF8ToUTF16(description); |
| 197 if (info->version.empty()) |
| 198 ExtractVersionString(description, info); |
| 199 } |
195 | 200 |
196 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 201 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
197 << "Got info for plugin " << filename.value() | 202 << "Got info for plugin " << filename.value() |
198 << " Name = \"" << UTF16ToUTF8(info->name) | 203 << " Name = \"" << UTF16ToUTF8(info->name) |
199 << "\", Description = \"" << UTF16ToUTF8(info->desc) << "\"."; | 204 << "\", Description = \"" << UTF16ToUTF8(info->desc) |
| 205 << "\", Version = \"" << UTF16ToUTF8(info->version) |
| 206 << "\"."; |
200 } else { | 207 } else { |
201 LOG_IF(ERROR, PluginList::DebugPluginLoading()) | 208 LOG_IF(ERROR, PluginList::DebugPluginLoading()) |
202 << "Plugin " << filename.value() | 209 << "Plugin " << filename.value() |
203 << " has no GetValue() and probably won't work."; | 210 << " has no GetValue() and probably won't work."; |
204 } | 211 } |
205 | 212 |
206 // Intentionally not unloading the plugin here, it can lead to crashes. | 213 // Intentionally not unloading the plugin here, it can lead to crashes. |
207 | 214 |
208 return true; | 215 return true; |
209 } | 216 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } else { | 252 } else { |
246 mime_type.description = UTF8ToUTF16(description.substr(ofs)); | 253 mime_type.description = UTF8ToUTF16(description.substr(ofs)); |
247 } | 254 } |
248 mime_types->push_back(mime_type); | 255 mime_types->push_back(mime_type); |
249 if (end == std::string::npos) | 256 if (end == std::string::npos) |
250 break; | 257 break; |
251 ofs = end + 1; | 258 ofs = end + 1; |
252 } | 259 } |
253 } | 260 } |
254 | 261 |
| 262 // static |
| 263 void PluginLib::ExtractVersionString(const std::string& desc, |
| 264 WebPluginInfo* info) { |
| 265 // This matching works by extracting a version substring, along the lines of: |
| 266 // No postfix: second match in .*<prefix>.*$ |
| 267 // With postfix: second match .*<prefix>.*<postfix> |
| 268 static const struct { |
| 269 const char* kPrefix; |
| 270 const char* kPostfix; |
| 271 } kPrePostFixes[] = { |
| 272 { "Shockwave Flash ", 0 }, |
| 273 { "Java(TM) Plug-in ", 0 }, |
| 274 { "(using IcedTea6 ", " " }, |
| 275 { 0, 0 } |
| 276 }; |
| 277 std::string version; |
| 278 for (size_t i = 0; kPrePostFixes[i].kPrefix; ++i) { |
| 279 size_t pos; |
| 280 if ((pos = desc.find(kPrePostFixes[i].kPrefix)) != std::string::npos) { |
| 281 version = desc.substr(pos + strlen(kPrePostFixes[i].kPrefix)); |
| 282 pos = std::string::npos; |
| 283 if (kPrePostFixes[i].kPostfix) |
| 284 pos = version.find(kPrePostFixes[i].kPostfix); |
| 285 if (pos != std::string::npos) |
| 286 version = version.substr(0, pos); |
| 287 break; |
| 288 } |
| 289 } |
| 290 if (!version.empty()) { |
| 291 info->version = UTF8ToUTF16(version); |
| 292 } |
| 293 } |
255 | 294 |
256 } // namespace npapi | 295 } // namespace npapi |
257 } // namespace webkit | 296 } // namespace webkit |
OLD | NEW |