| OLD | NEW |
| 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/glue/plugins/plugin_list.h" | 5 #include "webkit/glue/plugins/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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); | 466 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
| 467 it != plugins_.end(); | 467 it != plugins_.end(); |
| 468 ++it) { | 468 ++it) { |
| 469 plugins->push_back(**it); | 469 plugins->push_back(**it); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 void PluginList::GetEnabledPlugins(bool refresh, | 473 void PluginList::GetEnabledPlugins(bool refresh, |
| 474 std::vector<WebPluginInfo>* plugins) { | 474 std::vector<WebPluginInfo>* plugins) { |
| 475 LoadPlugins(refresh); | 475 LoadPlugins(refresh); |
| 476 | |
| 477 plugins->clear(); | 476 plugins->clear(); |
| 478 AutoLock lock(lock_); | 477 AutoLock lock(lock_); |
| 479 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); | 478 for (std::vector<WebPluginInfo*>::const_iterator it = plugins_.begin(); |
| 480 it != plugins_.end(); | 479 it != plugins_.end(); |
| 481 ++it) { | 480 ++it) { |
| 482 if ((*it)->enabled) | 481 if ((*it)->enabled) |
| 483 plugins->push_back(**it); | 482 plugins->push_back(**it); |
| 484 } | 483 } |
| 485 } | 484 } |
| 486 | 485 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 606 |
| 608 void PluginList::GetPluginGroups( | 607 void PluginList::GetPluginGroups( |
| 609 bool load_if_necessary, | 608 bool load_if_necessary, |
| 610 std::vector<PluginGroup>* plugin_groups) { | 609 std::vector<PluginGroup>* plugin_groups) { |
| 611 if (load_if_necessary) | 610 if (load_if_necessary) |
| 612 LoadPlugins(false); | 611 LoadPlugins(false); |
| 613 AutoLock lock(lock_); | 612 AutoLock lock(lock_); |
| 614 plugin_groups->clear(); | 613 plugin_groups->clear(); |
| 615 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); | 614 for (PluginGroup::PluginMap::const_iterator it = plugin_groups_.begin(); |
| 616 it != plugin_groups_.end(); ++it) { | 615 it != plugin_groups_.end(); ++it) { |
| 617 plugin_groups->push_back(*it->second); | 616 if (!it->second->IsEmpty()) |
| 617 plugin_groups->push_back(*it->second); |
| 618 } | 618 } |
| 619 } | 619 } |
| 620 | 620 |
| 621 const PluginGroup* PluginList::GetPluginGroup( | 621 const PluginGroup* PluginList::GetPluginGroup( |
| 622 const WebPluginInfo& web_plugin_info) { | 622 const WebPluginInfo& web_plugin_info) { |
| 623 AutoLock lock(lock_); | 623 AutoLock lock(lock_); |
| 624 return AddToPluginGroups(web_plugin_info, NULL); | 624 return AddToPluginGroups(web_plugin_info, &plugins_); |
| 625 } | 625 } |
| 626 | 626 |
| 627 string16 PluginList::GetPluginGroupName(std::string identifier) { | 627 string16 PluginList::GetPluginGroupName(std::string identifier) { |
| 628 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); | 628 PluginGroup::PluginMap::iterator it = plugin_groups_.find(identifier); |
| 629 if (it == plugin_groups_.end()) { | 629 if (it == plugin_groups_.end()) { |
| 630 return string16(); | 630 return string16(); |
| 631 } | 631 } |
| 632 return it->second->GetGroupName(); | 632 return it->second->GetGroupName(); |
| 633 } | 633 } |
| 634 | 634 |
| 635 std::string PluginList::GetPluginGroupIdentifier( | 635 std::string PluginList::GetPluginGroupIdentifier( |
| 636 const WebPluginInfo& web_plugin_info) { | 636 const WebPluginInfo& web_plugin_info) { |
| 637 AutoLock lock(lock_); | 637 AutoLock lock(lock_); |
| 638 PluginGroup* group = AddToPluginGroups(web_plugin_info, NULL); | 638 PluginGroup* group = AddToPluginGroups(web_plugin_info, &plugins_); |
| 639 return group->identifier(); | 639 return group->identifier(); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void PluginList::AddHardcodedPluginGroups() { | 642 void PluginList::AddHardcodedPluginGroups() { |
| 643 AutoLock lock(lock_); | 643 AutoLock lock(lock_); |
| 644 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); | 644 const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); |
| 645 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { | 645 for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { |
| 646 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( | 646 PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( |
| 647 definitions[i]); | 647 definitions[i]); |
| 648 ProcessGroupAfterInitialize(definition_group); |
| 648 std::string identifier = definition_group->identifier(); | 649 std::string identifier = definition_group->identifier(); |
| 649 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 650 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
| 650 plugin_groups_.insert(std::make_pair(identifier, definition_group)); | 651 plugin_groups_.insert(std::make_pair(identifier, definition_group)); |
| 651 } | 652 } |
| 652 } | 653 } |
| 653 | 654 |
| 654 PluginGroup* PluginList::AddToPluginGroups( | 655 PluginGroup* PluginList::AddToPluginGroups( |
| 655 const WebPluginInfo& web_plugin_info, | 656 const WebPluginInfo& web_plugin_info, |
| 656 std::vector<WebPluginInfo*>* plugins) { | 657 std::vector<WebPluginInfo*>* plugins) { |
| 657 PluginGroup* group = NULL; | 658 PluginGroup* group = NULL; |
| 658 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); | 659 for (PluginGroup::PluginMap::iterator it = plugin_groups_.begin(); |
| 659 it != plugin_groups_.end(); ++it) { | 660 it != plugin_groups_.end(); ++it) { |
| 660 if (it->second->Match(web_plugin_info)) | 661 if (it->second->Match(web_plugin_info)) |
| 661 group = it->second; | 662 group = it->second; |
| 662 } | 663 } |
| 663 if (!group) { | 664 if (!group) { |
| 664 group = PluginGroup::FromWebPluginInfo(web_plugin_info); | 665 group = PluginGroup::FromWebPluginInfo(web_plugin_info); |
| 666 ProcessGroupAfterInitialize(group); |
| 665 std::string identifier = group->identifier(); | 667 std::string identifier = group->identifier(); |
| 666 // If the identifier is not unique, use the full path. This means that we | 668 // If the identifier is not unique, use the full path. This means that we |
| 667 // probably won't be able to search for this group by identifier, but at | 669 // probably won't be able to search for this group by identifier, but at |
| 668 // least it's going to be in the set of plugin groups, and if there | 670 // least it's going to be in the set of plugin groups, and if there |
| 669 // is already a plug-in with the same filename, it's probably going to | 671 // is already a plug-in with the same filename, it's probably going to |
| 670 // handle the same MIME types (and it has a higher priority), so this one | 672 // handle the same MIME types (and it has a higher priority), so this one |
| 671 // is not going to run anyway. | 673 // is not going to run anyway. |
| 672 if (plugin_groups_.find(identifier) != plugin_groups_.end()) | 674 if (plugin_groups_.find(identifier) != plugin_groups_.end()) |
| 673 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); | 675 identifier = PluginGroup::GetLongIdentifier(web_plugin_info); |
| 674 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); | 676 DCHECK(plugin_groups_.find(identifier) == plugin_groups_.end()); |
| 675 plugin_groups_.insert(std::make_pair(identifier, group)); | 677 plugin_groups_.insert(std::make_pair(identifier, group)); |
| 676 } | 678 } |
| 677 WebPluginInfo* group_plugin_copy; | 679 if (plugins) { |
| 678 bool is_new_addition = group->AddPlugin( | 680 WebPluginInfo* group_plugin_copy; |
| 679 web_plugin_info, next_priority_, &group_plugin_copy); | 681 bool is_new_addition = group->AddPlugin( |
| 680 if (plugins) | 682 web_plugin_info, next_priority_, &group_plugin_copy); |
| 681 plugins->push_back(group_plugin_copy); | 683 if (is_new_addition) { |
| 682 if (is_new_addition) { | 684 plugins->push_back(group_plugin_copy); |
| 683 next_priority_++; | 685 next_priority_++; |
| 684 string16 group_name = group->GetGroupName(); | 686 string16 group_name = group->GetGroupName(); |
| 685 if (!group->Enabled() && !disabled_groups_.count(group_name)) { | 687 if (!group->Enabled() && !disabled_groups_.count(group_name)) { |
| 686 disabled_groups_.insert(DisabledGroupsListElement( | 688 disabled_groups_.insert(DisabledGroupsListElement( |
| 687 group_name, | 689 group_name, |
| 688 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? | 690 PluginGroup::IsPluginNameDisabledByPolicy(group_name) ? |
| 689 POLICY : USER)); | 691 POLICY : USER)); |
| 690 } else if (group->Enabled() && disabled_groups_.count(group_name)) { | 692 } else if (group->Enabled() && disabled_groups_.count(group_name)) { |
| 691 disabled_groups_.erase(group_name); | 693 disabled_groups_.erase(group_name); |
| 694 } |
| 692 } | 695 } |
| 693 // We don't need to protect the flag here because it is protected from the | 696 // We don't need to protect the flag here because it is protected from the |
| 694 // callers of |AddToPluginGroups|. | 697 // callers of |AddToPluginGroups|. |
| 695 } | 698 } |
| 696 return group; | 699 return group; |
| 697 } | 700 } |
| 698 | 701 |
| 699 bool PluginList::EnablePlugin(const FilePath& filename) { | 702 bool PluginList::EnablePlugin(const FilePath& filename) { |
| 700 AutoLock lock(lock_); | 703 AutoLock lock(lock_); |
| 701 | 704 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 // memory tree green. | 838 // memory tree green. |
| 836 #if defined(OS_POSIX) | 839 #if defined(OS_POSIX) |
| 837 if (RUNNING_ON_VALGRIND) { | 840 if (RUNNING_ON_VALGRIND) { |
| 838 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), | 841 STLDeleteContainerPairSecondPointers(plugin_groups_.begin(), |
| 839 plugin_groups_.end()); | 842 plugin_groups_.end()); |
| 840 } | 843 } |
| 841 #endif | 844 #endif |
| 842 } | 845 } |
| 843 | 846 |
| 844 } // namespace NPAPI | 847 } // namespace NPAPI |
| OLD | NEW |