Index: webkit/glue/plugins/plugin_group.cc |
diff --git a/webkit/glue/plugins/plugin_group.cc b/webkit/glue/plugins/plugin_group.cc |
index 668621d87875cf7bb23cf477b1f44a1acae66b29..625ef3cbf2e7709ca44f1766da813bfeb45830d6 100644 |
--- a/webkit/glue/plugins/plugin_group.cc |
+++ b/webkit/glue/plugins/plugin_group.cc |
@@ -103,19 +103,21 @@ PluginGroup::PluginGroup(const string16& group_name, |
} |
void PluginGroup::InitFrom(const PluginGroup& other) { |
+ enabled_ = false; |
identifier_ = other.identifier_; |
group_name_ = other.group_name_; |
name_matcher_ = other.name_matcher_; |
- description_ = other.description_; |
update_url_ = other.update_url_; |
- enabled_ = other.enabled_; |
for (size_t i = 0; i < other.version_ranges_.size(); ++i) |
version_ranges_.push_back(other.version_ranges_[i]); |
DCHECK_EQ(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]); |
+ std::list<WebPluginInfo>::const_iterator it = other.web_plugin_infos_.begin(); |
+ std::vector<int>::const_iterator itprio = other.web_plugin_positions_.begin(); |
+ for (; it != other.web_plugin_infos_.end(); ++it, ++itprio) |
+ AddPlugin(*it, *itprio, NULL); |
if (!version_.get()) |
version_.reset(Version::GetVersionFromString("0")); |
+ enabled_ = other.enabled_; |
} |
PluginGroup::PluginGroup(const PluginGroup& other) { |
@@ -235,20 +237,37 @@ void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) { |
version_.reset(Version::GetVersionFromString("0")); |
} |
-void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) { |
+bool PluginGroup::AddPlugin( |
+ const WebPluginInfo& plugin, |
+ int position, |
+ WebPluginInfo** group_plugin_copy) { |
// 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(), |
+ for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
+ it != web_plugin_infos_.end(); ++it) { |
+ if (it->name == plugin.name && |
+ it->version == plugin.version && |
+ FilePath::CompareEqualIgnoreCase(it->path.value(), |
plugin.path.value())) { |
- return; |
+ if (group_plugin_copy) |
+ *group_plugin_copy = &(*it); |
+ return false; |
} |
} |
web_plugin_infos_.push_back(plugin); |
// The position of this plugin relative to the global list of plugins. |
web_plugin_positions_.push_back(position); |
UpdateActivePlugin(plugin); |
+ if (group_plugin_copy) |
+ *group_plugin_copy = &web_plugin_infos_.back(); |
+ return true; |
+} |
+ |
+std::list<WebPluginInfo>& PluginGroup::GetPlugins() { |
+ return web_plugin_infos_; |
+} |
+ |
+std::vector<int>& PluginGroup::GetPluginPositions() { |
+ return web_plugin_positions_; |
} |
string16 PluginGroup::GetGroupName() const { |
@@ -256,7 +275,7 @@ string16 PluginGroup::GetGroupName() const { |
return group_name_; |
DCHECK_EQ(1u, web_plugin_infos_.size()); |
FilePath::StringType path = |
- web_plugin_infos_[0].path.BaseName().RemoveExtension().value(); |
+ web_plugin_infos_.front().path.BaseName().RemoveExtension().value(); |
#if defined(OS_POSIX) |
return UTF8ToUTF16(path); |
#elif defined(OS_WIN) |
@@ -283,9 +302,11 @@ DictionaryValue* PluginGroup::GetDataForUI() const { |
bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(name); |
ListValue* plugin_files = new ListValue(); |
bool all_plugins_disabled_by_policy = true; |
- for (size_t i = 0; i < web_plugin_infos_.size(); ++i) { |
- const WebPluginInfo& web_plugin = web_plugin_infos_[i]; |
- int priority = web_plugin_positions_[i]; |
+ std::vector<int>::const_iterator itprio = web_plugin_positions_.begin(); |
+ for (std::list<WebPluginInfo>::const_iterator it = web_plugin_infos_.begin(); |
jam
2010/12/15 19:48:55
ditto, using an iterator here makes the code unnec
|
+ it != web_plugin_infos_.end(); ++it, ++itprio) { |
+ const WebPluginInfo& web_plugin = *it; |
+ int priority = *itprio; |
DictionaryValue* plugin_file = new DictionaryValue(); |
plugin_file->SetString("name", web_plugin.name); |
plugin_file->SetString("description", web_plugin.desc); |
@@ -369,37 +390,50 @@ bool PluginGroup::IsVulnerable() const { |
} |
void PluginGroup::DisableOutdatedPlugins() { |
- description_ = string16(); |
- enabled_ = false; |
+ bool first_enabled = true; |
- for (std::vector<WebPluginInfo>::iterator it = |
- web_plugin_infos_.begin(); |
- it != web_plugin_infos_.end(); ++it) { |
+ for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
+ it != web_plugin_infos_.end(); ++it) { |
scoped_ptr<Version> version(CreateVersionFromString(it->version)); |
if (version.get()) { |
+ bool plugin_is_outdated = false; |
for (size_t i = 0; i < version_ranges_.size(); ++i) { |
if (IsPluginOutdated(*version, version_ranges_[i])) { |
- it->enabled = false; |
- NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
+ NPAPI::PluginList::Singleton()->DisablePlugin(it->path, false); |
+ plugin_is_outdated = true; |
+ break; |
} |
} |
+ if (!plugin_is_outdated && first_enabled) { |
+ first_enabled = false; |
+ UpdateDescriptionAndVersion(*it); |
+ } |
} |
- UpdateActivePlugin(*it); |
} |
} |
void PluginGroup::Enable(bool enable) { |
bool enabled_plugin_exists = false; |
- for (std::vector<WebPluginInfo>::iterator it = |
- web_plugin_infos_.begin(); |
+ for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
it != web_plugin_infos_.end(); ++it) { |
- if (enable && !IsPluginNameDisabledByPolicy(it->name)) { |
+ bool policy_disabled = IsPluginNameDisabledByPolicy(it->name); |
+ if (enable && !policy_disabled) { |
NPAPI::PluginList::Singleton()->EnablePlugin(it->path); |
- it->enabled = true; |
enabled_plugin_exists = true; |
} else { |
- it->enabled = false; |
- NPAPI::PluginList::Singleton()->DisablePlugin(it->path); |
+ NPAPI::PluginList::Singleton()->DisablePlugin(it->path, policy_disabled); |
+ } |
+ } |
+ enabled_ = enabled_plugin_exists; |
+} |
+ |
+void PluginGroup::RefreshEnabledState() { |
+ bool enabled_plugin_exists = false; |
+ for (std::list<WebPluginInfo>::iterator it = web_plugin_infos_.begin(); |
+ it != web_plugin_infos_.end(); ++it) { |
+ if (it->enabled) { |
+ enabled_plugin_exists = true; |
+ break; |
} |
} |
enabled_ = enabled_plugin_exists; |