Index: webkit/glue/plugins/plugin_group.cc |
diff --git a/webkit/glue/plugins/plugin_group.cc b/webkit/glue/plugins/plugin_group.cc |
index e68649c646340614bcf02ce05724475a3fe4d7c1..aa377af8d1b6c180eacfc57c7bc805ce9baf4132 100644 |
--- a/webkit/glue/plugins/plugin_group.cc |
+++ b/webkit/glue/plugins/plugin_group.cc |
@@ -157,6 +157,38 @@ PluginGroup::PluginGroup(const string16& group_name, |
min_version_.reset(Version::GetVersionFromString(min_version)); |
} |
+void PluginGroup::InitFrom(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]); |
+ if (!version_.get()) |
+ version_.reset(Version::GetVersionFromString("0")); |
+} |
+ |
+PluginGroup::PluginGroup(const PluginGroup& other) { |
+ InitFrom(other); |
+} |
+ |
+PluginGroup& PluginGroup::operator=(const PluginGroup& other) { |
+ InitFrom(other); |
+ return *this; |
+} |
+ |
+/*static*/ |
PluginGroup* PluginGroup::FromPluginGroupDefinition( |
const PluginGroupDefinition& definition) { |
return new PluginGroup(ASCIIToUTF16(definition.name), |
@@ -170,56 +202,30 @@ 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; |
- } |
- |
- // 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*/ |
+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 |
} |
-PluginGroup* PluginGroup::FindGroupMatchingPlugin( |
- const PluginMap& plugin_groups, |
- const WebPluginInfo& plugin) { |
- for (std::map<std::string, linked_ptr<PluginGroup> >::const_iterator it = |
- plugin_groups.begin(); |
- it != plugin_groups.end(); |
- ++it) { |
- if (it->second->Match(plugin)) |
- return it->second.get(); |
- } |
- return NULL; |
+/*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)); |
} |
bool PluginGroup::Match(const WebPluginInfo& plugin) const { |
@@ -287,6 +293,15 @@ 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 (web_plugin_infos_[i].name == plugin.name && |
+ web_plugin_infos_[i].version == plugin.version && |
+ 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 +422,18 @@ 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_ = enabled_plugin_exists; |
} |