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

Side by Side Diff: webkit/plugins/npapi/plugin_list.cc

Issue 6162008: plugins: drop PluginVersionInfo for internal plugins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more comments Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
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_list.h" 5 #include "webkit/plugins/npapi/plugin_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 void PluginList::AddExtraPluginDir(const FilePath& plugin_dir) { 211 void PluginList::AddExtraPluginDir(const FilePath& plugin_dir) {
212 // Chrome OS only loads plugins from /opt/google/chrome/plugins. 212 // Chrome OS only loads plugins from /opt/google/chrome/plugins.
213 #if !defined(OS_CHROMEOS) 213 #if !defined(OS_CHROMEOS)
214 AutoLock lock(lock_); 214 AutoLock lock(lock_);
215 extra_plugin_dirs_.push_back(plugin_dir); 215 extra_plugin_dirs_.push_back(plugin_dir);
216 #endif 216 #endif
217 } 217 }
218 218
219 void PluginList::RegisterInternalPlugin(const PluginVersionInfo& info) { 219 void PluginList::RegisterInternalPlugin(const WebPluginInfo& info) {
220 PluginEntryPoints entry_points = {0};
221 InternalPlugin plugin = { info, entry_points };
222
220 AutoLock lock(lock_); 223 AutoLock lock(lock_);
221 internal_plugins_.push_back(info); 224 internal_plugins_.push_back(plugin);
222 }
223
224 void PluginList::RegisterInternalPlugin(const FilePath& path) {
225 webkit::npapi::PluginVersionInfo info;
226 info.path = path;
227 memset(&info.entry_points, 0, sizeof(info.entry_points));
228 RegisterInternalPlugin(info);
229 } 225 }
230 226
231 void PluginList::RegisterInternalPlugin(const FilePath& filename, 227 void PluginList::RegisterInternalPlugin(const FilePath& filename,
232 const std::string& name, 228 const std::string& name,
233 const std::string& description, 229 const std::string& description,
234 const std::string& mime_type, 230 const std::string& mime_type_str,
235 const PluginEntryPoints& entry_points) { 231 const PluginEntryPoints& entry_points) {
236 webkit::npapi::PluginVersionInfo info = { 232 InternalPlugin plugin;
237 filename, 233 plugin.info.path = filename;
238 ASCIIToWide(name), 234 plugin.info.name = ASCIIToUTF16(name);
239 ASCIIToWide(description), 235 plugin.info.version = ASCIIToUTF16("1");
240 L"1", 236 plugin.info.desc = ASCIIToUTF16(description);
pastarmovj 2011/01/13 13:36:08 You should be setting the enabled flag to true her
241 ASCIIToWide(mime_type), 237 WebPluginMimeType mime_type;
242 L"", 238 mime_type.mime_type = mime_type_str;
243 L"", 239 plugin.info.mime_types.push_back(mime_type);
244 entry_points 240 plugin.entry_points = entry_points;
245 }; 241
246 RegisterInternalPlugin(info); 242 AutoLock lock(lock_);
243 internal_plugins_.push_back(plugin);
247 } 244 }
248 245
249 void PluginList::UnregisterInternalPlugin(const FilePath& path) { 246 void PluginList::UnregisterInternalPlugin(const FilePath& path) {
250 AutoLock lock(lock_); 247 AutoLock lock(lock_);
251 for (size_t i = 0; i < internal_plugins_.size(); i++) { 248 for (size_t i = 0; i < internal_plugins_.size(); i++) {
252 if (internal_plugins_[i].path == path) { 249 if (internal_plugins_[i].info.path == path) {
253 internal_plugins_.erase(internal_plugins_.begin() + i); 250 internal_plugins_.erase(internal_plugins_.begin() + i);
254 return; 251 return;
255 } 252 }
256 } 253 }
257 NOTREACHED(); 254 NOTREACHED();
258 } 255 }
259 256
260 bool PluginList::ReadPluginInfo(const FilePath& filename, 257 bool PluginList::ReadPluginInfo(const FilePath& filename,
261 WebPluginInfo* info, 258 WebPluginInfo* info,
262 const PluginEntryPoints** entry_points) { 259 const PluginEntryPoints** entry_points) {
263 { 260 {
264 AutoLock lock(lock_); 261 AutoLock lock(lock_);
265 for (size_t i = 0; i < internal_plugins_.size(); ++i) { 262 for (size_t i = 0; i < internal_plugins_.size(); ++i) {
266 if (filename == internal_plugins_[i].path) { 263 if (filename == internal_plugins_[i].info.path) {
267 *entry_points = &internal_plugins_[i].entry_points; 264 *entry_points = &internal_plugins_[i].entry_points;
268 return CreateWebPluginInfo(internal_plugins_[i], info); 265 *info = internal_plugins_[i].info;
266 return true;
269 } 267 }
270 } 268 }
271 } 269 }
272 270
273 // Not an internal plugin. 271 // Not an internal plugin.
274 *entry_points = NULL; 272 *entry_points = NULL;
275 273
276 return PluginLib::ReadWebPluginInfo(filename, info); 274 return PluginLib::ReadWebPluginInfo(filename, info);
277 } 275 }
278 276
279 bool PluginList::CreateWebPluginInfo(const PluginVersionInfo& pvi, 277 // static
280 WebPluginInfo* info) { 278 bool PluginList::ParseMimeTypes(
279 const std::string& mime_types_str,
280 const std::string& file_extensions_str,
281 const string16& mime_type_descriptions_str,
282 std::vector<WebPluginMimeType>* parsed_mime_types) {
281 std::vector<std::string> mime_types, file_extensions; 283 std::vector<std::string> mime_types, file_extensions;
282 std::vector<string16> descriptions; 284 std::vector<string16> descriptions;
283 base::SplitString(WideToUTF8(pvi.mime_types), '|', &mime_types); 285 base::SplitString(mime_types_str, '|', &mime_types);
284 base::SplitString(WideToUTF8(pvi.file_extensions), '|', &file_extensions); 286 base::SplitString(file_extensions_str, '|', &file_extensions);
285 base::SplitString(WideToUTF16(pvi.type_descriptions), '|', &descriptions); 287 base::SplitString(mime_type_descriptions_str, '|', &descriptions);
286 288
287 info->mime_types.clear(); 289 parsed_mime_types->clear();
288 290
289 if (mime_types.empty()) { 291 if (mime_types.empty())
290 LOG_IF(ERROR, PluginList::DebugPluginLoading())
291 << "Plugin " << pvi.product_name << " has no MIME types, skipping";
292 return false; 292 return false;
293 }
294
295 info->name = WideToUTF16(pvi.product_name);
296 info->desc = WideToUTF16(pvi.file_description);
297 info->version = WideToUTF16(pvi.file_version);
298 info->path = pvi.path;
299 info->enabled = true;
300 293
301 for (size_t i = 0; i < mime_types.size(); ++i) { 294 for (size_t i = 0; i < mime_types.size(); ++i) {
302 WebPluginMimeType mime_type; 295 WebPluginMimeType mime_type;
303 mime_type.mime_type = StringToLowerASCII(mime_types[i]); 296 mime_type.mime_type = StringToLowerASCII(mime_types[i]);
304 if (file_extensions.size() > i) 297 if (file_extensions.size() > i)
305 base::SplitString(file_extensions[i], ',', &mime_type.file_extensions); 298 base::SplitString(file_extensions[i], ',', &mime_type.file_extensions);
306 299
307 if (descriptions.size() > i) { 300 if (descriptions.size() > i) {
308 mime_type.description = descriptions[i]; 301 mime_type.description = descriptions[i];
309 302
310 // On Windows, the description likely has a list of file extensions 303 // On Windows, the description likely has a list of file extensions
311 // embedded in it (e.g. "SurfWriter file (*.swr)"). Remove an extension 304 // embedded in it (e.g. "SurfWriter file (*.swr)"). Remove an extension
312 // list from the description if it is present. 305 // list from the description if it is present.
313 size_t ext = mime_type.description.find(ASCIIToUTF16("(*")); 306 size_t ext = mime_type.description.find(ASCIIToUTF16("(*"));
314 if (ext != string16::npos) { 307 if (ext != string16::npos) {
315 if (ext > 1 && mime_type.description[ext -1] == ' ') 308 if (ext > 1 && mime_type.description[ext - 1] == ' ')
316 ext--; 309 ext--;
317 310
318 mime_type.description.erase(ext); 311 mime_type.description.erase(ext);
319 } 312 }
320 } 313 }
321 314
322 info->mime_types.push_back(mime_type); 315 parsed_mime_types->push_back(mime_type);
323 } 316 }
324 317
325 return true; 318 return true;
326 } 319 }
327 320
328 PluginList::PluginList() 321 PluginList::PluginList()
329 : plugins_loaded_(false), 322 : plugins_loaded_(false),
330 plugins_need_refresh_(false), 323 plugins_need_refresh_(false),
331 disable_outdated_plugins_(false), 324 disable_outdated_plugins_(false),
332 next_priority_(0) { 325 next_priority_(0) {
333 PlatformInit(); 326 PlatformInit();
334 AddHardcodedPluginGroups(); 327 AddHardcodedPluginGroups();
335 } 328 }
336 329
337 bool PluginList::ShouldDisableGroup(const string16& group_name) { 330 bool PluginList::ShouldDisableGroup(const string16& group_name) {
338 AutoLock lock(lock_); 331 AutoLock lock(lock_);
339 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) { 332 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) {
340 disabled_groups_.insert(group_name); 333 disabled_groups_.insert(group_name);
341 return true; 334 return true;
342 } 335 }
343 return disabled_groups_.count(group_name) > 0; 336 return disabled_groups_.count(group_name) > 0;
344 } 337 }
345 338
346 void PluginList::LoadPlugins(bool refresh) { 339 void PluginList::LoadPlugins(bool refresh) {
347 // Don't want to hold the lock while loading new plugins, so we don't block 340 // Don't want to hold the lock while loading new plugins, so we don't block
348 // other methods if they're called on other threads. 341 // other methods if they're called on other threads.
349 std::vector<FilePath> extra_plugin_paths; 342 std::vector<FilePath> extra_plugin_paths;
350 std::vector<FilePath> extra_plugin_dirs; 343 std::vector<FilePath> extra_plugin_dirs;
351 std::vector<PluginVersionInfo> internal_plugins; 344 std::vector<InternalPlugin> internal_plugins;
352 { 345 {
353 AutoLock lock(lock_); 346 AutoLock lock(lock_);
354 if (plugins_loaded_ && !refresh && !plugins_need_refresh_) 347 if (plugins_loaded_ && !refresh && !plugins_need_refresh_)
355 return; 348 return;
356 349
357 // Clear the refresh bit now, because it might get set again before we 350 // Clear the refresh bit now, because it might get set again before we
358 // reach the end of the method. 351 // reach the end of the method.
359 plugins_need_refresh_ = false; 352 plugins_need_refresh_ = false;
360 extra_plugin_paths = extra_plugin_paths_; 353 extra_plugin_paths = extra_plugin_paths_;
361 extra_plugin_dirs = extra_plugin_dirs_; 354 extra_plugin_dirs = extra_plugin_dirs_;
362 internal_plugins = internal_plugins_; 355 internal_plugins = internal_plugins_;
363 } 356 }
364 357
365 std::vector<WebPluginInfo> new_plugins; 358 std::vector<WebPluginInfo> new_plugins;
366 std::set<FilePath> visited_plugins; 359 std::set<FilePath> visited_plugins;
367 360
368 std::vector<FilePath> directories_to_scan; 361 std::vector<FilePath> directories_to_scan;
369 GetPluginDirectories(&directories_to_scan); 362 GetPluginDirectories(&directories_to_scan);
370 363
371 // Load internal plugins first so that, if both an internal plugin and a 364 // Load internal plugins first so that, if both an internal plugin and a
372 // "discovered" plugin want to handle the same type, the internal plugin 365 // "discovered" plugin want to handle the same type, the internal plugin
373 // will have precedence. 366 // will have precedence.
374 for (size_t i = 0; i < internal_plugins.size(); ++i) { 367 for (size_t i = 0; i < internal_plugins.size(); ++i) {
375 if (internal_plugins[i].path.value() == kDefaultPluginLibraryName) 368 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName)
376 continue; 369 continue;
377 LoadPlugin(internal_plugins[i].path, &new_plugins); 370 LoadPlugin(internal_plugins[i].info.path, &new_plugins);
378 } 371 }
379 372
380 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { 373 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) {
381 const FilePath& path = extra_plugin_paths[i]; 374 const FilePath& path = extra_plugin_paths[i];
382 if (visited_plugins.find(path) != visited_plugins.end()) 375 if (visited_plugins.find(path) != visited_plugins.end())
383 continue; 376 continue;
384 LoadPlugin(path, &new_plugins); 377 LoadPlugin(path, &new_plugins);
385 visited_plugins.insert(path); 378 visited_plugins.insert(path);
386 } 379 }
387 380
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 Shutdown(); 804 Shutdown();
812 } 805 }
813 806
814 void PluginList::Shutdown() { 807 void PluginList::Shutdown() {
815 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), 808 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(),
816 plugin_groups_.end()); 809 plugin_groups_.end());
817 } 810 }
818 811
819 } // namespace npapi 812 } // namespace npapi
820 } // namespace webkit 813 } // namespace webkit
OLDNEW
« webkit/plugins/npapi/plugin_list.h ('K') | « webkit/plugins/npapi/plugin_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698