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

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

Issue 7497030: PluginList cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix crash Created 9 years, 4 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
« no previous file with comments | « webkit/plugins/npapi/plugin_list.h ('k') | webkit/plugins/npapi/plugin_list_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) 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 390
391 #if defined(OS_WIN) 391 #if defined(OS_WIN)
392 LoadPluginsFromRegistry(plugin_groups, &visited_plugins); 392 LoadPluginsFromRegistry(plugin_groups, &visited_plugins);
393 #endif 393 #endif
394 394
395 // Load the default plugin last. 395 // Load the default plugin last.
396 if (default_plugin_enabled_) 396 if (default_plugin_enabled_)
397 LoadPlugin(FilePath(kDefaultPluginLibraryName), plugin_groups); 397 LoadPlugin(FilePath(kDefaultPluginLibraryName), plugin_groups);
398 } 398 }
399 399
400 void PluginList::LoadPlugins(bool refresh) { 400 void PluginList::LoadPlugins() {
401 { 401 {
402 base::AutoLock lock(lock_); 402 base::AutoLock lock(lock_);
403 if (!refresh && !plugins_need_refresh_) 403 if (!plugins_need_refresh_)
404 return; 404 return;
405 } 405 }
406 406
407 ScopedVector<PluginGroup> new_plugin_groups; 407 ScopedVector<PluginGroup> new_plugin_groups;
408 AddHardcodedPluginGroups(&new_plugin_groups); 408 AddHardcodedPluginGroups(&new_plugin_groups);
409 // Do the actual loading of the plugins. 409 // Do the actual loading of the plugins.
410 LoadPluginsInternal(&new_plugin_groups); 410 LoadPluginsInternal(&new_plugin_groups);
411 411
412 base::AutoLock lock(lock_); 412 base::AutoLock lock(lock_);
413 // Grab all plugins that were found before to copy enabled statuses. 413 // Grab all plugins that were found before to copy enabled statuses.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (path.value() != kDefaultPluginLibraryName 475 if (path.value() != kDefaultPluginLibraryName
476 #if defined(OS_WIN) && !defined(NDEBUG) 476 #if defined(OS_WIN) && !defined(NDEBUG)
477 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY 477 && path.BaseName().value() != L"npspy.dll" // Make an exception for NPSPY
478 #endif 478 #endif
479 ) { 479 ) {
480 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) { 480 for (size_t i = 0; i < plugin_info.mime_types.size(); ++i) {
481 // TODO: don't load global handlers for now. 481 // TODO: don't load global handlers for now.
482 // WebKit hands to the Plugin before it tries 482 // WebKit hands to the Plugin before it tries
483 // to handle mimeTypes on its own. 483 // to handle mimeTypes on its own.
484 const std::string &mime_type = plugin_info.mime_types[i].mime_type; 484 const std::string &mime_type = plugin_info.mime_types[i].mime_type;
485 if (mime_type == "*" ) 485 if (mime_type == "*")
486 return; 486 return;
487 } 487 }
488 } 488 }
489 489
490 base::AutoLock lock(lock_); 490 base::AutoLock lock(lock_);
491 AddToPluginGroups(plugin_info, plugin_groups); 491 AddToPluginGroups(plugin_info, plugin_groups);
492 } 492 }
493 493
494 void PluginList::GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { 494 void PluginList::GetPlugins(std::vector<WebPluginInfo>* plugins) {
495 LoadPlugins(refresh); 495 LoadPlugins();
496
497 base::AutoLock lock(lock_); 496 base::AutoLock lock(lock_);
498 for (size_t i = 0; i < plugin_groups_.size(); ++i) { 497 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
499 const std::vector<WebPluginInfo>& gr_plugins = 498 const std::vector<WebPluginInfo>& gr_plugins =
500 plugin_groups_[i]->web_plugins_info(); 499 plugin_groups_[i]->web_plugins_info();
501 plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end()); 500 plugins->insert(plugins->end(), gr_plugins.begin(), gr_plugins.end());
502 } 501 }
503 } 502 }
504 503
505 void PluginList::GetEnabledPlugins(bool refresh,
506 std::vector<WebPluginInfo>* plugins) {
507 LoadPlugins(refresh);
508
509 plugins->clear();
510 base::AutoLock lock(lock_);
511 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
512 const std::vector<WebPluginInfo>& gr_plugins =
513 plugin_groups_[i]->web_plugins_info();
514 for (size_t i = 0; i < gr_plugins.size(); ++i) {
515 if (IsPluginEnabled(gr_plugins[i]))
516 plugins->push_back(gr_plugins[i]);
517 }
518 }
519 }
520
521 void PluginList::GetPluginInfoArray( 504 void PluginList::GetPluginInfoArray(
522 const GURL& url, 505 const GURL& url,
523 const std::string& mime_type, 506 const std::string& mime_type,
524 bool allow_wildcard, 507 bool allow_wildcard,
508 bool* use_stale,
525 std::vector<WebPluginInfo>* info, 509 std::vector<WebPluginInfo>* info,
526 std::vector<std::string>* actual_mime_types) { 510 std::vector<std::string>* actual_mime_types) {
527 DCHECK(mime_type == StringToLowerASCII(mime_type)); 511 DCHECK(mime_type == StringToLowerASCII(mime_type));
528 DCHECK(info); 512 DCHECK(info);
529 513
530 LoadPlugins(false); 514 if (!use_stale)
515 LoadPlugins();
531 base::AutoLock lock(lock_); 516 base::AutoLock lock(lock_);
517 if (use_stale)
518 *use_stale = plugins_need_refresh_;
532 info->clear(); 519 info->clear();
533 if (actual_mime_types) 520 if (actual_mime_types)
534 actual_mime_types->clear(); 521 actual_mime_types->clear();
535 522
536 std::set<FilePath> visited_plugins; 523 std::set<FilePath> visited_plugins;
537 524
538 // Add in enabled plugins by mime type. 525 // Add in enabled plugins by mime type.
539 for (size_t i = 0; i < plugin_groups_.size(); ++i) { 526 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
540 const std::vector<WebPluginInfo>& plugins = 527 const std::vector<WebPluginInfo>& plugins =
541 plugin_groups_[i]->web_plugins_info(); 528 plugin_groups_[i]->web_plugins_info();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 plugin_groups_[i]->web_plugins_info()[0]; 597 plugin_groups_[i]->web_plugins_info()[0];
611 if (SupportsType(default_info, mime_type, allow_wildcard)) { 598 if (SupportsType(default_info, mime_type, allow_wildcard)) {
612 info->push_back(default_info); 599 info->push_back(default_info);
613 if (actual_mime_types) 600 if (actual_mime_types)
614 actual_mime_types->push_back(mime_type); 601 actual_mime_types->push_back(mime_type);
615 } 602 }
616 } 603 }
617 } 604 }
618 } 605 }
619 606
620 bool PluginList::GetPluginInfo(const GURL& url,
621 const std::string& mime_type,
622 bool allow_wildcard,
623 WebPluginInfo* info,
624 std::string* actual_mime_type) {
625 DCHECK(info);
626 std::vector<WebPluginInfo> info_list;
627
628 // GetPluginInfoArray has slightly less work to do if we can pass
629 // NULL for the mime type list...
630 if (actual_mime_type) {
631 std::vector<std::string> mime_type_list;
632 GetPluginInfoArray(
633 url, mime_type, allow_wildcard, &info_list, &mime_type_list);
634 if (!info_list.empty()) {
635 *info = info_list[0];
636 *actual_mime_type = mime_type_list[0];
637 return true;
638 }
639 } else {
640 GetPluginInfoArray(url, mime_type, allow_wildcard, &info_list, NULL);
641 if (!info_list.empty()) {
642 *info = info_list[0];
643 return true;
644 }
645 }
646 return false;
647 }
648
649 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path, 607 bool PluginList::GetPluginInfoByPath(const FilePath& plugin_path,
650 WebPluginInfo* info) { 608 WebPluginInfo* info) {
651 LoadPlugins(false); 609 LoadPlugins();
652 base::AutoLock lock(lock_); 610 base::AutoLock lock(lock_);
653 for (size_t i = 0; i < plugin_groups_.size(); ++i) { 611 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
654 const std::vector<WebPluginInfo>& plugins = 612 const std::vector<WebPluginInfo>& plugins =
655 plugin_groups_[i]->web_plugins_info(); 613 plugin_groups_[i]->web_plugins_info();
656 for (size_t i = 0; i < plugins.size(); ++i) { 614 for (size_t i = 0; i < plugins.size(); ++i) {
657 if (plugins[i].path == plugin_path) { 615 if (plugins[i].path == plugin_path) {
658 *info = plugins[i]; 616 *info = plugins[i];
659 return true; 617 return true;
660 } 618 }
661 } 619 }
662 } 620 }
663 621
664 return false; 622 return false;
665 } 623 }
666 624
667 void PluginList::GetPluginGroups( 625 void PluginList::GetPluginGroups(
668 bool load_if_necessary, 626 bool load_if_necessary,
669 std::vector<PluginGroup>* plugin_groups) { 627 std::vector<PluginGroup>* plugin_groups) {
670 if (load_if_necessary) 628 if (load_if_necessary)
671 LoadPlugins(false); 629 LoadPlugins();
672 base::AutoLock lock(lock_); 630 base::AutoLock lock(lock_);
673 plugin_groups->clear(); 631 plugin_groups->clear();
674 for (size_t i = 0; i < plugin_groups_.size(); ++i) { 632 for (size_t i = 0; i < plugin_groups_.size(); ++i) {
675 // In some unit tests we can get confronted with empty groups but in real 633 // In some unit tests we can get confronted with empty groups but in real
676 // world code this if should never be false here. 634 // world code this if should never be false here.
677 if (!plugin_groups_[i]->IsEmpty()) 635 if (!plugin_groups_[i]->IsEmpty())
678 plugin_groups->push_back(*plugin_groups_[i]); 636 plugin_groups->push_back(*plugin_groups_[i]);
679 } 637 }
680 } 638 }
681 639
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 void PluginList::DisableOutdatedPluginGroups() { 784 void PluginList::DisableOutdatedPluginGroups() {
827 disable_outdated_plugins_ = true; 785 disable_outdated_plugins_ = true;
828 } 786 }
829 787
830 PluginList::~PluginList() { 788 PluginList::~PluginList() {
831 } 789 }
832 790
833 791
834 } // namespace npapi 792 } // namespace npapi
835 } // namespace webkit 793 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_list.h ('k') | webkit/plugins/npapi/plugin_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698