OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 base::AutoLock lock(lock_); | 250 base::AutoLock lock(lock_); |
251 for (size_t i = 0; i < internal_plugins_.size(); i++) { | 251 for (size_t i = 0; i < internal_plugins_.size(); i++) { |
252 if (internal_plugins_[i].info.path == path) { | 252 if (internal_plugins_[i].info.path == path) { |
253 internal_plugins_.erase(internal_plugins_.begin() + i); | 253 internal_plugins_.erase(internal_plugins_.begin() + i); |
254 return; | 254 return; |
255 } | 255 } |
256 } | 256 } |
257 NOTREACHED(); | 257 NOTREACHED(); |
258 } | 258 } |
259 | 259 |
260 void PluginList::GetInternalPlugins( | |
261 std::vector<webkit::WebPluginInfo>* internal_plugins) { | |
262 base::AutoLock lock(lock_); | |
263 | |
264 for (std::vector<InternalPlugin>::iterator it = internal_plugins_.begin(); | |
265 it != internal_plugins_.end(); | |
266 ++it) { | |
267 internal_plugins->push_back(it->info); | |
268 } | |
269 } | |
270 | |
260 bool PluginList::ReadPluginInfo(const FilePath& filename, | 271 bool PluginList::ReadPluginInfo(const FilePath& filename, |
261 webkit::WebPluginInfo* info, | 272 webkit::WebPluginInfo* info, |
262 const PluginEntryPoints** entry_points) { | 273 const PluginEntryPoints** entry_points) { |
263 { | 274 { |
264 base::AutoLock lock(lock_); | 275 base::AutoLock lock(lock_); |
265 for (size_t i = 0; i < internal_plugins_.size(); ++i) { | 276 for (size_t i = 0; i < internal_plugins_.size(); ++i) { |
266 if (filename == internal_plugins_[i].info.path) { | 277 if (filename == internal_plugins_[i].info.path) { |
267 *entry_points = &internal_plugins_[i].entry_points; | 278 *entry_points = &internal_plugins_[i].entry_points; |
268 *info = internal_plugins_[i].info; | 279 *info = internal_plugins_[i].info; |
269 return true; | 280 return true; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 const webkit::WebPluginInfo& web_plugin_info) const { | 352 const webkit::WebPluginInfo& web_plugin_info) const { |
342 for (size_t i = 0; i < hardcoded_plugin_groups_.size(); ++i) { | 353 for (size_t i = 0; i < hardcoded_plugin_groups_.size(); ++i) { |
343 const PluginGroup* group = hardcoded_plugin_groups_[i]; | 354 const PluginGroup* group = hardcoded_plugin_groups_[i]; |
344 if (group->Match(web_plugin_info)) | 355 if (group->Match(web_plugin_info)) |
345 return new PluginGroup(*group); | 356 return new PluginGroup(*group); |
346 } | 357 } |
347 return PluginGroup::FromWebPluginInfo(web_plugin_info); | 358 return PluginGroup::FromWebPluginInfo(web_plugin_info); |
348 } | 359 } |
349 | 360 |
350 void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) { | 361 void PluginList::LoadPluginsInternal(ScopedVector<PluginGroup>* plugin_groups) { |
351 // Don't want to hold the lock while loading new plugins, so we don't block | |
352 // other methods if they're called on other threads. | |
353 std::vector<FilePath> extra_plugin_paths; | |
354 std::vector<FilePath> extra_plugin_dirs; | |
355 std::vector<InternalPlugin> internal_plugins; | |
356 base::Closure will_load_callback; | 362 base::Closure will_load_callback; |
357 { | 363 { |
358 base::AutoLock lock(lock_); | 364 base::AutoLock lock(lock_); |
359 // Clear the refresh bit now, because it might get set again before we | 365 // Clear the refresh bit now, because it might get set again before we |
360 // reach the end of the method. | 366 // reach the end of the method. |
361 plugins_need_refresh_ = false; | 367 plugins_need_refresh_ = false; |
362 will_load_callback = will_load_plugins_callback_; | 368 will_load_callback = will_load_plugins_callback_; |
363 extra_plugin_paths = extra_plugin_paths_; | |
364 extra_plugin_dirs = extra_plugin_dirs_; | |
365 internal_plugins = internal_plugins_; | |
366 } | 369 } |
367 | 370 |
368 if (!will_load_callback.is_null()) | 371 if (!will_load_callback.is_null()) |
369 will_load_callback.Run(); | 372 will_load_callback.Run(); |
370 | 373 |
371 std::set<FilePath> visited_plugins; | 374 std::vector<FilePath> plugin_paths; |
375 GetPluginPathsToLoad(&plugin_paths); | |
372 | 376 |
373 std::vector<FilePath> directories_to_scan; | 377 for (std::vector<FilePath>::const_iterator it = plugin_paths.begin(); |
374 GetPluginDirectories(&directories_to_scan); | 378 it != plugin_paths.end(); |
375 | 379 ++it) { |
376 // Load internal plugins first so that, if both an internal plugin and a | 380 LoadPlugin(*it, plugin_groups); |
377 // "discovered" plugin want to handle the same type, the internal plugin | |
378 // will have precedence. | |
379 for (size_t i = 0; i < internal_plugins.size(); ++i) { | |
380 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName) | |
381 continue; | |
382 LoadPlugin(internal_plugins[i].info.path, plugin_groups); | |
383 } | 381 } |
384 | |
385 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | |
386 const FilePath& path = extra_plugin_paths[i]; | |
387 if (visited_plugins.find(path) != visited_plugins.end()) | |
388 continue; | |
389 LoadPlugin(path, plugin_groups); | |
390 visited_plugins.insert(path); | |
391 } | |
392 | |
393 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | |
394 LoadPluginsFromDir( | |
395 extra_plugin_dirs[i], plugin_groups, &visited_plugins); | |
396 } | |
397 | |
398 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | |
399 LoadPluginsFromDir( | |
400 directories_to_scan[i], plugin_groups, &visited_plugins); | |
401 } | |
402 | |
403 #if defined(OS_WIN) | |
404 LoadPluginsFromRegistry(plugin_groups, &visited_plugins); | |
405 #endif | |
406 | |
407 // Load the default plugin last. | |
408 if (default_plugin_enabled_) | |
409 LoadPlugin(FilePath(kDefaultPluginLibraryName), plugin_groups); | |
410 } | 382 } |
411 | 383 |
412 void PluginList::LoadPlugins() { | 384 void PluginList::LoadPlugins() { |
413 { | 385 { |
414 base::AutoLock lock(lock_); | 386 base::AutoLock lock(lock_); |
415 if (!plugins_need_refresh_) | 387 if (!plugins_need_refresh_) |
416 return; | 388 return; |
417 } | 389 } |
418 | 390 |
419 ScopedVector<PluginGroup> new_plugin_groups; | 391 ScopedVector<PluginGroup> new_plugin_groups; |
(...skipping 29 matching lines...) Expand all Loading... | |
449 const std::string &mime_type = plugin_info.mime_types[i].mime_type; | 421 const std::string &mime_type = plugin_info.mime_types[i].mime_type; |
450 if (mime_type == "*") | 422 if (mime_type == "*") |
451 return; | 423 return; |
452 } | 424 } |
453 } | 425 } |
454 | 426 |
455 base::AutoLock lock(lock_); | 427 base::AutoLock lock(lock_); |
456 AddToPluginGroups(plugin_info, plugin_groups); | 428 AddToPluginGroups(plugin_info, plugin_groups); |
457 } | 429 } |
458 | 430 |
459 void PluginList::GetPluginPathListsToLoad( | 431 void PluginList::GetPluginPathsToLoad(std::vector<FilePath>* plugin_paths) { |
460 std::vector<FilePath>* extra_plugin_paths, | 432 // Don't want to hold the lock while loading new plugins, so we don't block |
461 std::vector<FilePath>* extra_plugin_dirs, | 433 // other methods if they're called on other threads. |
462 std::vector<webkit::WebPluginInfo>* internal_plugins) { | 434 std::vector<FilePath> extra_plugin_paths; |
463 base::AutoLock lock(lock_); | 435 std::vector<FilePath> extra_plugin_dirs; |
464 *extra_plugin_paths = extra_plugin_paths_; | 436 std::vector<InternalPlugin> internal_plugins; |
465 *extra_plugin_dirs = extra_plugin_dirs_; | 437 { |
438 base::AutoLock lock(lock_); | |
439 extra_plugin_paths = extra_plugin_paths_; | |
440 extra_plugin_dirs = extra_plugin_dirs_; | |
441 internal_plugins = internal_plugins_; | |
442 } | |
466 | 443 |
467 *internal_plugins = std::vector<webkit::WebPluginInfo>(); | 444 std::vector<FilePath> directories_to_scan; |
468 for (std::vector<InternalPlugin>::iterator it = internal_plugins_.begin(); | 445 GetPluginDirectories(&directories_to_scan); |
469 it != internal_plugins_.end(); | 446 |
470 ++it) { | 447 // Load internal plugins first so that, if both an internal plugin and a |
471 internal_plugins->push_back(it->info); | 448 // "discovered" plugin want to handle the same type, the internal plugin |
449 // will have precedence. | |
450 for (size_t i = 0; i < internal_plugins.size(); ++i) { | |
451 if (internal_plugins[i].info.path.value() == kDefaultPluginLibraryName) | |
452 continue; | |
453 plugin_paths->push_back(internal_plugins[i].info.path); | |
472 } | 454 } |
455 | |
456 for (size_t i = 0; i < extra_plugin_paths.size(); ++i) { | |
457 const FilePath& path = extra_plugin_paths[i]; | |
458 if (std::find(plugin_paths->begin(), plugin_paths->end(), path) != | |
459 plugin_paths->end()) { | |
460 continue; | |
461 } | |
462 plugin_paths->push_back(path); | |
463 } | |
464 | |
465 for (size_t i = 0; i < extra_plugin_dirs.size(); ++i) { | |
jam
2011/10/20 00:16:16
nit: this file doesn't use brace brackets for one
Robert Sesek
2011/10/20 16:00:21
Done.
| |
466 GetPluginsInDir(extra_plugin_dirs[i], plugin_paths); | |
467 } | |
468 | |
469 for (size_t i = 0; i < directories_to_scan.size(); ++i) { | |
470 GetPluginsInDir(directories_to_scan[i], plugin_paths); | |
471 } | |
472 | |
473 #if defined(OS_WIN) | |
474 GetPluginPathsFromRegistry(plugin_paths); | |
475 #endif | |
476 | |
477 // Load the default plugin last. | |
478 if (default_plugin_enabled_) | |
479 plugin_paths->push_back(FilePath(kDefaultPluginLibraryName)); | |
473 } | 480 } |
474 | 481 |
475 void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { | 482 void PluginList::SetPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { |
476 base::AutoLock lock(lock_); | 483 base::AutoLock lock(lock_); |
477 | 484 |
478 plugins_need_refresh_ = false; | 485 plugins_need_refresh_ = false; |
479 | 486 |
480 plugin_groups_.reset(); | 487 plugin_groups_.reset(); |
481 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); | 488 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); |
482 it != plugins.end(); | 489 it != plugins.end(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 } | 717 } |
711 return false; | 718 return false; |
712 } | 719 } |
713 | 720 |
714 PluginList::~PluginList() { | 721 PluginList::~PluginList() { |
715 } | 722 } |
716 | 723 |
717 | 724 |
718 } // namespace npapi | 725 } // namespace npapi |
719 } // namespace webkit | 726 } // namespace webkit |
OLD | NEW |