| Index: webkit/plugins/npapi/plugin_group.cc
|
| diff --git a/webkit/plugins/npapi/plugin_group.cc b/webkit/plugins/npapi/plugin_group.cc
|
| index 04601982d9fe0a748ae2af5ed799e39a5b3e5fc6..8f709208b775548f30695d444da15a8b3d46ca8a 100644
|
| --- a/webkit/plugins/npapi/plugin_group.cc
|
| +++ b/webkit/plugins/npapi/plugin_group.cc
|
| @@ -46,21 +46,6 @@ bool PluginGroup::IsPluginNameDisabledByPolicy(const string16& plugin_name) {
|
| return false;
|
| }
|
|
|
| -/*static*/
|
| -bool PluginGroup::IsPluginPathDisabledByPolicy(const FilePath& plugin_path) {
|
| - std::vector<WebPluginInfo> plugins;
|
| - PluginList::Singleton()->GetPlugins(false, &plugins);
|
| - for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin();
|
| - it != plugins.end();
|
| - ++it) {
|
| - if (FilePath::CompareEqualIgnoreCase(it->path.value(),
|
| - plugin_path.value()) && IsPluginNameDisabledByPolicy(it->name)) {
|
| - return true;
|
| - }
|
| - }
|
| - return false;
|
| -}
|
| -
|
| VersionRange::VersionRange(VersionRangeDefinition definition)
|
| : low_str(definition.version_matcher_low),
|
| high_str(definition.version_matcher_high),
|
| @@ -115,7 +100,8 @@ void PluginGroup::InitFrom(const PluginGroup& other) {
|
| version_ranges_ = other.version_ranges_;
|
| version_.reset(other.version_->Clone());
|
| web_plugin_infos_ = other.web_plugin_infos_;
|
| - web_plugin_positions_ = other.web_plugin_positions_;
|
| + web_plugin_priority_ = other.web_plugin_priority_;
|
| + is_plugin_placeholder_ = other.is_plugin_placeholder_;
|
| }
|
|
|
| PluginGroup::PluginGroup(const PluginGroup& other) {
|
| @@ -166,6 +152,12 @@ PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) {
|
| GetIdentifier(wpi));
|
| }
|
|
|
| +/*static*/
|
| +PluginGroup* PluginGroup::CreateEmptyGroup(const string16& name) {
|
| + // Create a matcher from the name of this plugin.
|
| + return new PluginGroup(name, name, std::string(), std::string());
|
| +}
|
| +
|
| bool PluginGroup::Match(const WebPluginInfo& plugin) const {
|
| if (name_matcher_.empty()) {
|
| return false;
|
| @@ -213,7 +205,7 @@ Version* PluginGroup::CreateVersionFromString(const string16& version_string) {
|
|
|
| void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) {
|
| // A group is enabled if any of the files are enabled.
|
| - if (plugin.enabled) {
|
| + if (WebPluginInfoUtils::IsEnabled(plugin)) {
|
| if (!enabled_) {
|
| // If this is the first enabled plugin, use its description.
|
| enabled_ = true;
|
| @@ -235,24 +227,65 @@ 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 priority) {
|
| // 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 &&
|
| + (!web_plugin_infos_[i].version.length() ||
|
| + web_plugin_infos_[i].version == plugin.version) &&
|
| FilePath::CompareEqualIgnoreCase(web_plugin_infos_[i].path.value(),
|
| plugin.path.value())) {
|
| - return;
|
| + // If no version info present or placeholder flag is set update this
|
| + // one. This was a placeholder put here by a disabled/removed plugin.
|
| + if (is_plugin_placeholder_[i]) {
|
| + // Preserve enabled flag and reason.
|
| + bool enabled = web_plugin_infos_[i].enabled;
|
| + int reason = web_plugin_infos_[i].reason;
|
| + web_plugin_infos_[i] = plugin;
|
| + web_plugin_priority_[i] = priority;
|
| + web_plugin_infos_[i].reason = reason;
|
| + web_plugin_infos_[i].enabled = enabled;
|
| + is_plugin_placeholder_[i] = false;
|
| + return true;
|
| + }
|
| + 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);
|
| + web_plugin_priority_.push_back(priority);
|
| + // Placeholders have only name and path and are used to enforce plugin state
|
| + // before the plugin has been loaded.
|
| + is_plugin_placeholder_.push_back(!plugin.desc.length());
|
| + UpdateActivePlugin(web_plugin_infos_.back());
|
| + return true;
|
| }
|
|
|
| -bool PluginGroup::IsEmpty() const {
|
| - return web_plugin_infos_.empty();
|
| +bool PluginGroup::EnablePlugin(const FilePath& filename) {
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + if (web_plugin_infos_[i].path == filename) {
|
| + bool did_enable =
|
| + WebPluginInfoUtils::Enable(&web_plugin_infos_[i],
|
| + WebPluginInfo::USER);
|
| + RefreshEnabledState();
|
| + return did_enable;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool PluginGroup::DisablePlugin(const FilePath& filename) {
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + if (web_plugin_infos_[i].path == filename) {
|
| + bool did_disable = WebPluginInfoUtils::Disable(
|
| + &web_plugin_infos_[i],
|
| + IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name) ?
|
| + WebPluginInfo::MANAGED : WebPluginInfo::USER);
|
| + RefreshEnabledState();
|
| + return did_disable;
|
| + }
|
| + }
|
| + return false;
|
| }
|
|
|
| string16 PluginGroup::GetGroupName() const {
|
| @@ -260,7 +293,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)
|
| @@ -268,6 +301,19 @@ string16 PluginGroup::GetGroupName() const {
|
| #endif
|
| }
|
|
|
| +const std::vector<WebPluginInfo>& PluginGroup::GetPlugins() const {
|
| + return web_plugin_infos_;
|
| +}
|
| +
|
| +bool PluginGroup::ContainsPlugin(const FilePath& path) const {
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + if (web_plugin_infos_[i].path == path)
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +
|
| DictionaryValue* PluginGroup::GetSummary() const {
|
| DictionaryValue* result = new DictionaryValue();
|
| result->SetString("name", GetGroupName());
|
| @@ -288,40 +334,37 @@ DictionaryValue* PluginGroup::GetDataForUI() const {
|
| 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];
|
| + int priority = web_plugin_priority_[i];
|
| DictionaryValue* plugin_file = new DictionaryValue();
|
| - plugin_file->SetString("name", web_plugin.name);
|
| - plugin_file->SetString("description", web_plugin.desc);
|
| - plugin_file->SetString("path", web_plugin.path.value());
|
| - plugin_file->SetString("version", web_plugin.version);
|
| + plugin_file->SetString("name", web_plugin_infos_[i].name);
|
| + plugin_file->SetString("description", web_plugin_infos_[i].desc);
|
| + plugin_file->SetString("path", web_plugin_infos_[i].path.value());
|
| + plugin_file->SetString("version", web_plugin_infos_[i].version);
|
| bool plugin_disabled_by_policy = group_disabled_by_policy ||
|
| - IsPluginNameDisabledByPolicy(web_plugin.name);
|
| + WebPluginInfoUtils::IsManaged(web_plugin_infos_[i]);
|
| if (plugin_disabled_by_policy) {
|
| plugin_file->SetString("enabledMode", "disabledByPolicy");
|
| } else {
|
| all_plugins_disabled_by_policy = false;
|
| - plugin_file->SetString("enabledMode",
|
| - web_plugin.enabled ? "enabled" : "disabledByUser");
|
| + plugin_file->SetString(
|
| + "enabledMode", WebPluginInfoUtils::IsEnabled(web_plugin_infos_[i]) ?
|
| + "enabled" : "disabledByUser");
|
| }
|
| plugin_file->SetInteger("priority", priority);
|
|
|
| ListValue* mime_types = new ListValue();
|
| - for (std::vector<WebPluginMimeType>::const_iterator type_it =
|
| - web_plugin.mime_types.begin();
|
| - type_it != web_plugin.mime_types.end();
|
| - ++type_it) {
|
| + const std::vector<WebPluginMimeType>& plugin_mime_types =
|
| + web_plugin_infos_[i].mime_types;
|
| + for (size_t j = 0; j < plugin_mime_types.size(); ++j) {
|
| DictionaryValue* mime_type = new DictionaryValue();
|
| - mime_type->SetString("mimeType", type_it->mime_type);
|
| - mime_type->SetString("description", type_it->description);
|
| + mime_type->SetString("mimeType", plugin_mime_types[j].mime_type);
|
| + mime_type->SetString("description", plugin_mime_types[j].description);
|
|
|
| ListValue* file_extensions = new ListValue();
|
| - for (std::vector<std::string>::const_iterator ext_it =
|
| - type_it->file_extensions.begin();
|
| - ext_it != type_it->file_extensions.end();
|
| - ++ext_it) {
|
| - file_extensions->Append(new StringValue(*ext_it));
|
| - }
|
| + const std::vector<std::string>& mime_file_extensions =
|
| + plugin_mime_types[j].file_extensions;
|
| + for (size_t k = 0; k < mime_file_extensions.size(); ++k)
|
| + file_extensions->Append(new StringValue(mime_file_extensions[k]));
|
| mime_type->Set("fileExtensions", file_extensions);
|
|
|
| mime_types->Append(mime_type);
|
| @@ -372,38 +415,85 @@ bool PluginGroup::IsVulnerable() const {
|
| return false;
|
| }
|
|
|
| +bool PluginGroup::IsEmpty() const {
|
| + if (web_plugin_infos_.size() == 0)
|
| + return true;
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + if (!is_plugin_placeholder_[i])
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +void PluginGroup::SetPluginIsPlaceholder(const WebPluginInfo& plugin,
|
| + bool status) {
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i)
|
| + if (web_plugin_infos_[i].path == plugin.path)
|
| + is_plugin_placeholder_[i] = status;
|
| +}
|
| +
|
| +bool PluginGroup::IsPluginPlaceholder(const WebPluginInfo& plugin) {
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i)
|
| + if (web_plugin_infos_[i].path == plugin.path)
|
| + return is_plugin_placeholder_[i];
|
| + // We shouldn't call be this function for unknown plugins.
|
| + NOTREACHED();
|
| + return false;
|
| +}
|
| +
|
| 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) {
|
| - scoped_ptr<Version> version(CreateVersionFromString(it->version));
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + scoped_ptr<Version> version(
|
| + CreateVersionFromString(web_plugin_infos_[i].version));
|
| if (version.get()) {
|
| - for (size_t i = 0; i < version_ranges_.size(); ++i) {
|
| - if (IsPluginOutdated(*version, version_ranges_[i])) {
|
| - it->enabled = false;
|
| - PluginList::Singleton()->DisablePlugin(it->path);
|
| + bool plugin_is_outdated = false;
|
| + for (size_t j = 0; j < version_ranges_.size(); ++j) {
|
| + if (IsPluginOutdated(*version, version_ranges_[j])) {
|
| + WebPluginInfoUtils::Disable(&web_plugin_infos_[i],
|
| + WebPluginInfo::USER);
|
| + plugin_is_outdated = true;
|
| + break;
|
| }
|
| }
|
| + if (!plugin_is_outdated && first_enabled) {
|
| + first_enabled = false;
|
| + UpdateDescriptionAndVersion(web_plugin_infos_[i]);
|
| + }
|
| }
|
| - UpdateActivePlugin(*it);
|
| }
|
| }
|
|
|
| -void PluginGroup::Enable(bool enable) {
|
| +bool PluginGroup::EnableGroup(bool enable) {
|
| 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)) {
|
| - PluginList::Singleton()->EnablePlugin(it->path);
|
| - it->enabled = true;
|
| + bool group_disabled_by_policy = IsPluginNameDisabledByPolicy(group_name_);
|
| + // We can't enable groups disabled by policy
|
| + if (group_disabled_by_policy && enable)
|
| + return false;
|
| +
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + bool policy_disabled =
|
| + IsPluginNameDisabledByPolicy(web_plugin_infos_[i].name);
|
| + if (enable && !policy_disabled) {
|
| + WebPluginInfoUtils::Enable(&web_plugin_infos_[i], WebPluginInfo::USER);
|
| enabled_plugin_exists = true;
|
| } else {
|
| - it->enabled = false;
|
| - PluginList::Singleton()->DisablePlugin(it->path);
|
| + WebPluginInfoUtils::Disable(
|
| + &web_plugin_infos_[i], policy_disabled || group_disabled_by_policy ?
|
| + WebPluginInfo::MANAGED : WebPluginInfo::USER);
|
| + }
|
| + }
|
| + enabled_ = enabled_plugin_exists;
|
| + return enabled_ == enable;
|
| +}
|
| +
|
| +void PluginGroup::RefreshEnabledState() {
|
| + bool enabled_plugin_exists = false;
|
| + for (size_t i = 0; i < web_plugin_infos_.size(); ++i) {
|
| + if (WebPluginInfoUtils::IsEnabled(web_plugin_infos_[i])) {
|
| + enabled_plugin_exists = true;
|
| + break;
|
| }
|
| }
|
| enabled_ = enabled_plugin_exists;
|
|
|