Chromium Code Reviews| Index: webkit/glue/plugins/plugin_group.cc |
| diff --git a/webkit/glue/plugins/plugin_group.cc b/webkit/glue/plugins/plugin_group.cc |
| index 5dddbce4591f581a90f1546e090d806346799470..3d4a5389b4fed0b4ce07a253c674550b5c04b25c 100644 |
| --- a/webkit/glue/plugins/plugin_group.cc |
| +++ b/webkit/glue/plugins/plugin_group.cc |
| @@ -157,6 +157,53 @@ PluginGroup::PluginGroup(const string16& group_name, |
| min_version_.reset(Version::GetVersionFromString(min_version)); |
| } |
| +PluginGroup::PluginGroup(const PluginGroup& other) |
| + : identifier_(other.identifier_), |
| + group_name_(other.group_name_), |
| + name_matcher_(other.name_matcher_), |
| + version_range_low_str_(other.version_range_low_str_), |
| + version_range_high_str_(other.version_range_high_str_), |
| + version_range_low_(Version::GetVersionFromString(version_range_low_str_)), |
| + version_range_high_( |
| + Version::GetVersionFromString(version_range_high_str_)), |
| + description_(other.description_), |
| + update_url_(other.update_url_), |
| + enabled_(other.enabled_), |
| + min_version_str_(other.min_version_str_), |
| + min_version_(Version::GetVersionFromString(min_version_str_)) { |
| + DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); |
|
Bernhard Bauer
2010/12/03 16:13:28
You could pull this and the version_ constructor c
Jakob Kummerow
2010/12/06 18:21:12
Done. Good idea.
|
| + for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) |
| + AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); |
| + if (!version_.get()) |
| + version_.reset(Version::GetVersionFromString("0")); |
| + DCHECK(enabled_ == other.enabled_); |
| +} |
| + |
| +PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
| + identifier_ = other.identifier_; |
| + group_name_ = other.group_name_; |
| + name_matcher_ = other.name_matcher_; |
| + version_range_low_str_ = other.version_range_low_str_; |
| + version_range_high_str_ = other.version_range_high_str_; |
| + version_range_low_.reset( |
| + Version::GetVersionFromString(version_range_low_str_)); |
| + version_range_high_.reset( |
| + Version::GetVersionFromString(version_range_high_str_)); |
| + description_ = other.description_; |
| + update_url_ = other.update_url_; |
| + enabled_ = other.enabled_; |
| + min_version_str_ = other.min_version_str_; |
| + min_version_.reset(Version::GetVersionFromString(min_version_str_)); |
| + DCHECK(other.web_plugin_infos_.size() == other.web_plugin_positions_.size()); |
| + for (size_t i = 0; i < other.web_plugin_infos_.size(); ++i) |
| + AddPlugin(other.web_plugin_infos_[i], other.web_plugin_positions_[i]); |
| + DCHECK(web_plugin_infos_.size() == other.web_plugin_infos_.size()); |
| + if (!version_.get()) |
| + version_.reset(Version::GetVersionFromString("0")); |
| + return *this; |
| +} |
| + |
| +/*static*/ |
| PluginGroup* PluginGroup::FromPluginGroupDefinition( |
| const PluginGroupDefinition& definition) { |
| return new PluginGroup(ASCIIToUTF16(definition.name), |
| @@ -170,54 +217,41 @@ PluginGroup* PluginGroup::FromPluginGroupDefinition( |
| PluginGroup::~PluginGroup() { } |
| -PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
| - // Create a matcher from the name of this plugin. |
| +/*static*/ |
| +std::string PluginGroup::GetIdentifier(const WebPluginInfo& wpi) { |
| #if defined(OS_POSIX) |
| - std::string identifier = wpi.path.BaseName().value(); |
| + return wpi.path.BaseName().value(); |
| #elif defined(OS_WIN) |
| - std::string identifier = base::SysWideToUTF8(wpi.path.BaseName().value()); |
| + return base::SysWideToUTF8(wpi.path.BaseName().value()); |
| #endif |
| - return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), |
| - std::string(), std::string(), identifier); |
| } |
| -PluginGroup* PluginGroup::CopyOrCreatePluginGroup( |
| - const WebPluginInfo& info) { |
| - static PluginMap* hardcoded_plugin_groups = NULL; |
| - if (!hardcoded_plugin_groups) { |
| - PluginMap* groups = new PluginMap(); |
| - const PluginGroupDefinition* definitions = GetPluginGroupDefinitions(); |
| - for (size_t i = 0; i < GetPluginGroupDefinitionsSize(); ++i) { |
| - PluginGroup* definition_group = PluginGroup::FromPluginGroupDefinition( |
| - definitions[i]); |
| - std::string identifier = definition_group->identifier(); |
| - DCHECK(groups->find(identifier) == groups->end()); |
| - (*groups)[identifier] = linked_ptr<PluginGroup>(definition_group); |
| - } |
| - hardcoded_plugin_groups = groups; |
| - } |
| +/*static*/ |
| +std::string PluginGroup::GetLongIdentifier(const WebPluginInfo& wpi) { |
| +#if defined(OS_POSIX) |
| + return wpi.path.value(); |
| +#elif defined(OS_WIN) |
| + return base::SysWideToUTF8(wpi.path.value()); |
| +#endif |
| +} |
| - // See if this plugin matches any of the hardcoded groups. |
| - PluginGroup* hardcoded_group = FindGroupMatchingPlugin( |
| - *hardcoded_plugin_groups, info); |
| - if (hardcoded_group) { |
| - // Make a copy. |
| - return hardcoded_group->Copy(); |
| - } else { |
| - // Not found in our hardcoded list, create a new one. |
| - return PluginGroup::FromWebPluginInfo(info); |
| - } |
| +/*static*/ |
| +PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) { |
| + // Create a matcher from the name of this plugin. |
| + return new PluginGroup(wpi.name, wpi.name, std::string(), std::string(), |
| + std::string(), std::string(), |
| + GetIdentifier(wpi)); |
| } |
| +/*static*/ |
| PluginGroup* PluginGroup::FindGroupMatchingPlugin( |
| - const PluginMap& plugin_groups, |
| + const PluginMap* plugin_groups, |
|
Bernhard Bauer
2010/12/03 16:13:28
If you remove the const here, you can get rid of t
Jakob Kummerow
2010/12/06 18:21:12
Done.
|
| const WebPluginInfo& plugin) { |
| - for (std::map<std::string, linked_ptr<PluginGroup> >::const_iterator it = |
| - plugin_groups.begin(); |
| - it != plugin_groups.end(); |
| + for (PluginMap::const_iterator it = plugin_groups->begin(); |
| + it != plugin_groups->end(); |
| ++it) { |
| if (it->second->Match(plugin)) |
| - return it->second.get(); |
| + return const_cast<PluginGroup*>(it->second); |
| } |
| return NULL; |
| } |
| @@ -287,6 +321,13 @@ void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
| } |
| void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
| + // Check if this group already contains this plugin. |
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
| + if (FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(), |
| + plugin.path.value())) { |
| + return; |
| + } |
| + } |
| web_plugin_infos_.push_back(plugin); |
| // The position of this plugin relative to the global list of plugins. |
| web_plugin_positions_.push_back(position); |
| @@ -407,13 +448,19 @@ void PluginGroup::DisableOutdatedPlugins() { |
| } |
| void PluginGroup::Enable(bool enable) { |
| - for (std::vector<WebPluginInfo>::const_iterator it = |
| + bool enabled_plugin_exists = false; |
| + for (std::vector<WebPluginInfo>::iterator it = |
| web_plugin_infos_.begin(); |
| it != web_plugin_infos_.end(); ++it) { |
| if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
| NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
| + it->enabled = true; |
| + enabled_plugin_exists = true; |
| } else { |
| + it->enabled = false; |
| NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
| } |
| } |
| + enabled_ = enable && enabled_plugin_exists; |
|
Bernhard Bauer
2010/12/03 16:13:28
Nit: I think you can leave out the |enable &&| her
Jakob Kummerow
2010/12/06 18:21:12
Done.
I agree that |enable &&| is superfluous; I l
|
| + LOG(WARNING) << "Group " << GetGroupName() << " is now enabled: " << enabled_; |
|
Bernhard Bauer
2010/12/03 16:13:28
Nit: Remove logging plz :-)
Jakob Kummerow
2010/12/06 18:21:12
Done.
(Of course -- that was just a leftover I for
|
| } |