Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: webkit/glue/plugins/plugin_lib_linux.cc

Issue 200052: linux: rewrite mime parser (Closed)
Patch Set: review comments Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/glue/plugins/plugin_lib.h ('k') | webkit/glue/plugins/plugin_lib_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
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 if (!ParseMIMEDescription(mime_description, &info->mime_types)) { 85 ParseMIMEDescription(mime_description, &info->mime_types);
86 base::UnloadNativeLibrary(dl);
87 return false;
88 }
89 }
90 86
91 // The plugin name and description live behind NP_GetValue calls. 87 // The plugin name and description live behind NP_GetValue calls.
92 typedef NPError (*NP_GetValueType)(void* unused, 88 typedef NPError (*NP_GetValueType)(void* unused,
93 nsPluginVariable variable, 89 nsPluginVariable variable,
94 void* value_out); 90 void* value_out);
95 NP_GetValueType NP_GetValue = 91 NP_GetValueType NP_GetValue =
96 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue")); 92 reinterpret_cast<NP_GetValueType>(dlsym(dl, "NP_GetValue"));
97 if (NP_GetValue) { 93 if (NP_GetValue) {
98 const char* name = NULL; 94 const char* name = NULL;
99 NP_GetValue(NULL, nsPluginVariable_NameString, &name); 95 NP_GetValue(NULL, nsPluginVariable_NameString, &name);
100 if (name) 96 if (name)
101 info->name = UTF8ToWide(name); 97 info->name = UTF8ToWide(name);
102 98
103 const char* description = NULL; 99 const char* description = NULL;
104 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description); 100 NP_GetValue(NULL, nsPluginVariable_DescriptionString, &description);
105 if (description) 101 if (description)
106 info->desc = UTF8ToWide(description); 102 info->desc = UTF8ToWide(description);
107 } 103 }
108 104
109 base::UnloadNativeLibrary(dl); 105 base::UnloadNativeLibrary(dl);
110 106
111 return true; 107 return true;
112 } 108 }
113 109
114 // static 110 // static
115 bool PluginLib::ParseMIMEDescription( 111 void PluginLib::ParseMIMEDescription(
116 const char* description, 112 const std::string& description,
117 std::vector<WebPluginMimeType>* mime_types) { 113 std::vector<WebPluginMimeType>* mime_types) {
118 // TODO(evanm): rewrite this to better match Firefox; see 114 // We parse the description here into WebPluginMimeType structures.
119 // ParsePluginMimeDescription near 115 // Naively from the NPAPI docs you'd think you could use
116 // string-splitting, but the Firefox parser turns out to do something
117 // different: find the first colon, then the second, then a semi.
118 //
119 // See ParsePluginMimeDescription near
120 // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirU tils.h#53 120 // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirU tils.h#53
121 121
122 // We parse the description here into WebPluginMimeType structures. 122 std::string::size_type ofs = 0;
123 // Description for Flash 10 looks like (all as one string): 123 for (;;) {
124 // "application/x-shockwave-flash:swf:Shockwave Flash;" 124 WebPluginMimeType mime_type;
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 125
132 std::vector<std::string> fields; 126 std::string::size_type end = description.find(':', ofs);
133 SplitString(descriptions[i], ':', &fields); 127 if (end == std::string::npos)
134 if (fields.size() != 3) { 128 break;
135 LOG(WARNING) << "Couldn't parse plugin info: " << description; 129 mime_type.mime_type = description.substr(ofs, end - ofs);
136 // This plugin's got something weird going on; abort. 130 ofs = end + 1;
137 return false; 131
132 end = description.find(':', ofs);
133 if (end == std::string::npos)
134 break;
135 const std::string extensions = description.substr(ofs, end - ofs);
136 SplitString(extensions, ',', &mime_type.file_extensions);
137 ofs = end + 1;
138
139 end = description.find(';', ofs);
140 // It's ok for end to run off the string here. If there's no
141 // trailing semicolon we consume the remainder of the string.
142 if (end != std::string::npos) {
143 mime_type.description = UTF8ToWide(description.substr(ofs, end - ofs));
144 } else {
145 mime_type.description = UTF8ToWide(description.substr(ofs));
138 } 146 }
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); 147 mime_types->push_back(mime_type);
148 if (end == std::string::npos)
149 break;
150 ofs = end + 1;
145 } 151 }
146
147 return true;
148 } 152 }
149 153
150 } // namespace NPAPI 154 } // namespace NPAPI
OLDNEW
« no previous file with comments | « webkit/glue/plugins/plugin_lib.h ('k') | webkit/glue/plugins/plugin_lib_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698