| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/glue/plugins/plugin_lib.h" | 5 #include "webkit/glue/plugins/plugin_lib.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <elf.h> | 8 #include <elf.h> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // See comments in plugin_lib_mac regarding this symbol. | 75 // See comments in plugin_lib_mac regarding this symbol. |
| 76 typedef const char* (*NP_GetMimeDescriptionType)(); | 76 typedef const char* (*NP_GetMimeDescriptionType)(); |
| 77 NP_GetMimeDescriptionType NP_GetMIMEDescription = | 77 NP_GetMimeDescriptionType NP_GetMIMEDescription = |
| 78 reinterpret_cast<NP_GetMimeDescriptionType>( | 78 reinterpret_cast<NP_GetMimeDescriptionType>( |
| 79 dlsym(dl, "NP_GetMIMEDescription")); | 79 dlsym(dl, "NP_GetMIMEDescription")); |
| 80 const char* mime_description = NULL; | 80 const char* mime_description = NULL; |
| 81 if (NP_GetMIMEDescription) | 81 if (NP_GetMIMEDescription) |
| 82 mime_description = NP_GetMIMEDescription(); | 82 mime_description = NP_GetMIMEDescription(); |
| 83 | 83 |
| 84 if (mime_description) { | 84 if (mime_description) { |
| 85 // We parse the description here into WebPluginMimeType structures. | 85 if (!ParseMIMEDescription(mime_description, &info->mime_types)) { |
| 86 // Description for Flash 10 looks like (all as one string): | 86 base::UnloadNativeLibrary(dl); |
| 87 // "application/x-shockwave-flash:swf:Shockwave Flash;" | 87 return false; |
| 88 // "application/futuresplash:spl:FutureSplash Player" | |
| 89 std::vector<std::string> descriptions; | |
| 90 SplitString(mime_description, ';', &descriptions); | |
| 91 for (size_t i = 0; i < descriptions.size(); ++i) { | |
| 92 if (descriptions[i].empty()) | |
| 93 continue; // Don't warn if they have trailing semis. | |
| 94 | |
| 95 std::vector<std::string> fields; | |
| 96 SplitString(descriptions[i], ':', &fields); | |
| 97 if (fields.size() != 3) { | |
| 98 LOG(WARNING) << "Couldn't parse plugin info: " << descriptions[i]; | |
| 99 continue; | |
| 100 } | |
| 101 | |
| 102 WebPluginMimeType mime_type; | |
| 103 mime_type.mime_type = fields[0]; | |
| 104 SplitString(fields[1], ',', &mime_type.file_extensions); | |
| 105 mime_type.description = UTF8ToWide(fields[2]); | |
| 106 info->mime_types.push_back(mime_type); | |
| 107 } | 88 } |
| 108 } | 89 } |
| 109 | 90 |
| 110 // The plugin name and description live behind NP_GetValue calls. | 91 // The plugin name and description live behind NP_GetValue calls. |
| 111 typedef NPError (*NP_GetValueType)(void* unused, | 92 typedef NPError (*NP_GetValueType)(void* unused, |
| 112 nsPluginVariable variable, | 93 nsPluginVariable variable, |
| 113 void* value_out); | 94 void* value_out); |
| 114 NP_GetValueType NP_GetValue = | 95 NP_GetValueType NP_GetValue = |
| 115 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue")); | 96 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue")); |
| 116 if (NP_GetValue) { | 97 if (NP_GetValue) { |
| 117 const char* name = NULL; | 98 const char* name = NULL; |
| 118 NP_GetValue(NULL, nsPluginVariable_NameString, &name); | 99 NP_GetValue(NULL, nsPluginVariable_NameString, &name); |
| 119 if (name) | 100 if (name) |
| 120 info->name = UTF8ToWide(name); | 101 info->name = UTF8ToWide(name); |
| 121 | 102 |
| 122 const char* description = NULL; | 103 const char* description = NULL; |
| 123 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description); | 104 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description); |
| 124 if (description) | 105 if (description) |
| 125 info->desc = UTF8ToWide(description); | 106 info->desc = UTF8ToWide(description); |
| 126 } | 107 } |
| 127 | 108 |
| 128 base::UnloadNativeLibrary(dl); | 109 base::UnloadNativeLibrary(dl); |
| 129 | 110 |
| 130 return true; | 111 return true; |
| 131 } | 112 } |
| 132 | 113 |
| 114 // static |
| 115 bool PluginLib::ParseMIMEDescription( |
| 116 const char* description, |
| 117 std::vector<WebPluginMimeType>* mime_types) { |
| 118 // TODO(evanm): rewrite this to better match Firefox; see |
| 119 // ParsePluginMimeDescription near |
| 120 // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirU
tils.h#53 |
| 121 |
| 122 // We parse the description here into WebPluginMimeType structures. |
| 123 // Description for Flash 10 looks like (all as one string): |
| 124 // "application/x-shockwave-flash:swf:Shockwave Flash;" |
| 125 // "application/futuresplash:spl:FutureSplash Player" |
| 126 std::vector<std::string> descriptions; |
| 127 SplitString(description, ';', &descriptions); |
| 128 for (size_t i = 0; i < descriptions.size(); ++i) { |
| 129 if (descriptions[i].empty()) |
| 130 continue; // Don't warn if they have trailing semis. |
| 131 |
| 132 std::vector<std::string> fields; |
| 133 SplitString(descriptions[i], ':', &fields); |
| 134 if (fields.size() != 3) { |
| 135 LOG(WARNING) << "Couldn't parse plugin info: " << description; |
| 136 // This plugin's got something weird going on; abort. |
| 137 return false; |
| 138 } |
| 139 |
| 140 WebPluginMimeType mime_type; |
| 141 mime_type.mime_type = fields[0]; |
| 142 SplitString(fields[1], ',', &mime_type.file_extensions); |
| 143 mime_type.description = UTF8ToWide(fields[2]); |
| 144 mime_types->push_back(mime_type); |
| 145 } |
| 146 |
| 147 return true; |
| 148 } |
| 149 |
| 133 } // namespace NPAPI | 150 } // namespace NPAPI |
| OLD | NEW |