summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-02 00:42:39 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-02 00:42:39 +0000
commita466a0c5b21e3ecf2b5ff3f37260e167fe1b017f (patch)
tree98761cf267cf1be613e420da8e251d8cfdcf403a /chrome/common
parent10575ccb63ed99277da1b9663a71ede2be497708 (diff)
downloadchromium_src-a466a0c5b21e3ecf2b5ff3f37260e167fe1b017f.zip
chromium_src-a466a0c5b21e3ecf2b5ff3f37260e167fe1b017f.tar.gz
chromium_src-a466a0c5b21e3ecf2b5ff3f37260e167fe1b017f.tar.bz2
Don't load plugins on the UI thread for pref and group policy disabling.
BUG=57425 Review URL: http://codereview.chromium.org/3584007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/plugin_group.cc416
-rw-r--r--chrome/common/plugin_group.h175
-rw-r--r--chrome/common/plugin_group_unittest.cc187
3 files changed, 0 insertions, 778 deletions
diff --git a/chrome/common/plugin_group.cc b/chrome/common/plugin_group.cc
deleted file mode 100644
index a4930146..0000000
--- a/chrome/common/plugin_group.cc
+++ /dev/null
@@ -1,416 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/common/plugin_group.h"
-
-#include "base/linked_ptr.h"
-#include "base/string_util.h"
-#include "base/sys_string_conversions.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "base/version.h"
-#include "webkit/glue/plugins/plugin_list.h"
-#include "webkit/glue/plugins/webplugininfo.h"
-
-#if defined(OS_MACOSX)
-// Plugin Groups for Mac.
-// Plugins are listed here as soon as vulnerabilities and solutions
-// (new versions) are published.
-// TODO(panayiotis): Get the Real Player version on Mac, somehow.
-static const PluginGroupDefinition kGroupDefinitions[] = {
- { "apple-quicktime", "Quicktime", "QuickTime Plug-in", "", "", "7.6.6",
- "http://www.apple.com/quicktime/download/" },
- { "java-runtime-environment", "Java", "Java", "", "", "",
- "http://support.apple.com/kb/HT1338" },
- { "adobe-flash-player", "Flash", "Shockwave Flash", "", "", "10.1.82",
- "http://get.adobe.com/flashplayer/" },
- { "silverlight-3", "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0",
- "http://go.microsoft.com/fwlink/?LinkID=185927" },
- { "silverlight-4", "Silverlight 4", "Silverlight", "4", "5", "",
- "http://go.microsoft.com/fwlink/?LinkID=185927" },
- { "flip4mac", "Flip4Mac", "Flip4Mac", "", "", "2.2.1",
- "http://www.telestream.net/flip4mac-wmv/overview.htm" },
- { "shockwave", "Shockwave", "Shockwave for Director", "", "", "11.5.8.612",
- "http://www.adobe.com/shockwave/download/" }
-};
-
-#elif defined(OS_WIN)
-// TODO(panayiotis): We should group "RealJukebox NS Plugin" with the rest of
-// the RealPlayer files.
-static const PluginGroupDefinition kGroupDefinitions[] = {
- { "apple-quicktime", "Quicktime", "QuickTime Plug-in", "", "", "7.6.7",
- "http://www.apple.com/quicktime/download/" },
- { "java-runtime-environment", "Java 6", "Java", "", "6", "6.0.200",
- "http://www.java.com/" },
- { "adobe-reader", "Adobe Reader 9", "Adobe Acrobat", "9", "10", "9.3.3",
- "http://get.adobe.com/reader/" },
- { "adobe-reader-8", "Adobe Reader 8", "Adobe Acrobat", "0", "9", "8.2.3",
- "http://get.adobe.com/reader/" },
- { "adobe-flash-player", "Flash", "Shockwave Flash", "", "", "10.1.82",
- "http://get.adobe.com/flashplayer/" },
- { "silverlight-3", "Silverlight 3", "Silverlight", "0", "4", "3.0.50106.0",
- "http://go.microsoft.com/fwlink/?LinkID=185927" },
- { "silverlight-4", "Silverlight 4", "Silverlight", "4", "5", "",
- "http://go.microsoft.com/fwlink/?LinkID=185927" },
- { "shockwave", "Shockwave", "Shockwave for Director", "", "", "11.5.8.612",
- "http://www.adobe.com/shockwave/download/" },
- { "divx-player", "DivX Player", "DivX Web Player", "", "", "1.4.3.4",
- "http://download.divx.com/divx/autoupdate/player/"
- "DivXWebPlayerInstaller.exe" },
- // These are here for grouping, no vulnerabilies known.
- { "windows-media-player", "Windows Media Player", "Windows Media Player",
- "", "", "", "" },
- { "microsoft-office", "Microsoft Office", "Microsoft Office",
- "", "", "", "" },
- // TODO(panayiotis): The vulnerable versions are
- // (v >= 6.0.12.1040 && v <= 6.0.12.1663)
- // || v == 6.0.12.1698 || v == 6.0.12.1741
- { "realplayer", "RealPlayer", "RealPlayer", "", "", "",
- "http://www.adobe.com/shockwave/download/" },
-};
-
-#else
-static const PluginGroupDefinition kGroupDefinitions[] = {};
-#endif
-
-/*static*/
-std::set<string16>* PluginGroup::policy_disabled_plugin_patterns_;
-
-/*static*/
-const PluginGroupDefinition* PluginGroup::GetPluginGroupDefinitions() {
- return kGroupDefinitions;
-}
-
-/*static*/
-size_t PluginGroup::GetPluginGroupDefinitionsSize() {
- // TODO(viettrungluu): |arraysize()| doesn't work with zero-size arrays.
- return ARRAYSIZE_UNSAFE(kGroupDefinitions);
-}
-
-/*static*/
-void PluginGroup::SetPolicyDisabledPluginPatterns(
- const std::set<string16>& set) {
- if (!policy_disabled_plugin_patterns_)
- policy_disabled_plugin_patterns_ = new std::set<string16>(set);
- else
- *policy_disabled_plugin_patterns_ = set;
-}
-
-/*static*/
-bool PluginGroup::IsPluginNameDisabledByPolicy(const string16& plugin_name) {
- if (!policy_disabled_plugin_patterns_)
- return false;
-
- std::set<string16>::const_iterator pattern(
- policy_disabled_plugin_patterns_->begin());
- while (pattern != policy_disabled_plugin_patterns_->end()) {
- if (MatchPattern(plugin_name, *pattern))
- return true;
- ++pattern;
- }
-
- return false;
-}
-
-/*static*/
-bool PluginGroup::IsPluginPathDisabledByPolicy(const FilePath& plugin_path) {
- std::vector<WebPluginInfo> plugins;
- NPAPI::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;
-}
-
-PluginGroup::PluginGroup(const string16& group_name,
- const string16& name_matcher,
- const std::string& version_range_low,
- const std::string& version_range_high,
- const std::string& min_version,
- const std::string& update_url,
- const std::string& identifier)
- : identifier_(identifier),
- group_name_(group_name),
- name_matcher_(name_matcher),
- version_range_low_str_(version_range_low),
- version_range_high_str_(version_range_high),
- update_url_(update_url),
- enabled_(false),
- min_version_str_(min_version),
- version_(Version::GetVersionFromString("0")) {
- if (!version_range_low.empty())
- version_range_low_.reset(Version::GetVersionFromString(version_range_low));
- if (!version_range_high.empty()) {
- version_range_high_.reset(
- Version::GetVersionFromString(version_range_high));
- }
- if (!min_version.empty())
- min_version_.reset(Version::GetVersionFromString(min_version));
-}
-
-PluginGroup* PluginGroup::FromPluginGroupDefinition(
- const PluginGroupDefinition& definition) {
- return new PluginGroup(ASCIIToUTF16(definition.name),
- ASCIIToUTF16(definition.name_matcher),
- definition.version_matcher_low,
- definition.version_matcher_high,
- definition.min_version,
- definition.update_url,
- definition.identifier);
-}
-
-PluginGroup::~PluginGroup() { }
-
-PluginGroup* PluginGroup::FromWebPluginInfo(const WebPluginInfo& wpi) {
- // Create a matcher from the name of this plugin.
-#if defined(OS_POSIX)
- std::string identifier = wpi.path.BaseName().value();
-#elif defined(OS_WIN)
- std::string identifier = 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);
- }
-}
-
-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;
-}
-
-bool PluginGroup::Match(const WebPluginInfo& plugin) const {
- if (name_matcher_.empty()) {
- return false;
- }
-
- // Look for the name matcher anywhere in the plugin name.
- if (plugin.name.find(name_matcher_) == string16::npos) {
- return false;
- }
-
- if (version_range_low_.get() == NULL ||
- version_range_high_.get() == NULL) {
- return true;
- }
-
- // There's a version range, we must be in it.
- scoped_ptr<Version> plugin_version(
- Version::GetVersionFromString(UTF16ToWide(plugin.version)));
- if (plugin_version.get() == NULL) {
- // No version could be extracted, assume we don't match the range.
- return false;
- }
-
- // We match if we are in the range: [low, high)
- return (version_range_low_->CompareTo(*plugin_version) <= 0 &&
- version_range_high_->CompareTo(*plugin_version) > 0);
-}
-
-Version* PluginGroup::CreateVersionFromString(const string16& version_string) {
- // Remove spaces and ')' from the version string,
- // Replace any instances of 'r', ',' or '(' with a dot.
- std::wstring version = UTF16ToWide(version_string);
- RemoveChars(version, L") ", &version);
- std::replace(version.begin(), version.end(), 'r', '.');
- std::replace(version.begin(), version.end(), ',', '.');
- std::replace(version.begin(), version.end(), '(', '.');
-
- return Version::GetVersionFromString(version);
-}
-
-void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) {
- // A group is enabled if any of the files are enabled.
- if (plugin.enabled) {
- if (!enabled_) {
- // If this is the first enabled plugin, use its description.
- enabled_ = true;
- UpdateDescriptionAndVersion(plugin);
- }
- } else {
- // If this is the first plugin and it's disabled,
- // use its description for now.
- if (description_.empty())
- UpdateDescriptionAndVersion(plugin);
- }
-}
-
-void PluginGroup::UpdateDescriptionAndVersion(const WebPluginInfo& plugin) {
- description_ = plugin.desc;
- if (Version* new_version = CreateVersionFromString(plugin.version))
- version_.reset(new_version);
- else
- version_.reset(Version::GetVersionFromString("0"));
-}
-
-void PluginGroup::AddPlugin(const WebPluginInfo& plugin, int position) {
- 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);
-}
-
-string16 PluginGroup::GetGroupName() const {
- if (!group_name_.empty())
- return group_name_;
- DCHECK_EQ(1u, web_plugin_infos_.size());
- FilePath::StringType path =
- web_plugin_infos_[0].path.BaseName().RemoveExtension().value();
-#if defined(OS_POSIX)
- return UTF8ToUTF16(path);
-#elif defined(OS_WIN)
- return WideToUTF16(path);
-#endif
-}
-
-DictionaryValue* PluginGroup::GetSummary() const {
- DictionaryValue* result = new DictionaryValue();
- result->SetString("name", GetGroupName());
- result->SetBoolean("enabled", enabled_);
- return result;
-}
-
-DictionaryValue* PluginGroup::GetDataForUI() const {
- string16 name = GetGroupName();
- DictionaryValue* result = new DictionaryValue();
- result->SetString("name", name);
- result->SetString("description", description_);
- result->SetString("version", version_->GetString());
- result->SetString("update_url", update_url_);
- result->SetBoolean("critical", IsVulnerable());
-
- 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];
- 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);
- bool plugin_disabled_by_policy = group_disabled_by_policy ||
- IsPluginNameDisabledByPolicy(web_plugin.name);
- 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->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) {
- DictionaryValue* mime_type = new DictionaryValue();
- mime_type->SetString("mimeType", type_it->mime_type);
- mime_type->SetString("description", type_it->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));
- }
- mime_type->Set("fileExtensions", file_extensions);
-
- mime_types->Append(mime_type);
- }
- plugin_file->Set("mimeTypes", mime_types);
-
- plugin_files->Append(plugin_file);
- }
-
- if (group_disabled_by_policy || all_plugins_disabled_by_policy) {
- result->SetString("enabledMode", "disabledByPolicy");
- } else {
- result->SetString("enabledMode", enabled_ ? "enabled" : "disabledByUser");
- }
- result->Set("plugin_files", plugin_files);
-
- return result;
-}
-
-// Returns true if the latest version of this plugin group is vulnerable.
-bool PluginGroup::IsVulnerable() const {
- if (min_version_.get() == NULL || version_->GetString() == "0") {
- return false;
- }
- return version_->CompareTo(*min_version_) < 0;
-}
-
-void PluginGroup::DisableOutdatedPlugins() {
- if (!min_version_.get())
- return;
-
- description_ = string16();
- enabled_ = false;
-
- for (std::vector<WebPluginInfo>::iterator it =
- web_plugin_infos_.begin();
- it != web_plugin_infos_.end(); ++it) {
- scoped_ptr<Version> version(CreateVersionFromString(it->version));
- if (version.get() && version->CompareTo(*min_version_) < 0) {
- it->enabled = false;
- NPAPI::PluginList::Singleton()->DisablePlugin(it->path);
- }
- UpdateActivePlugin(*it);
- }
-}
-
-void PluginGroup::Enable(bool enable) {
- for (std::vector<WebPluginInfo>::const_iterator it =
- web_plugin_infos_.begin();
- it != web_plugin_infos_.end(); ++it) {
- if (enable && !IsPluginNameDisabledByPolicy(it->name)) {
- NPAPI::PluginList::Singleton()->EnablePlugin(it->path);
- } else {
- NPAPI::PluginList::Singleton()->DisablePlugin(it->path);
- }
- }
-}
diff --git a/chrome/common/plugin_group.h b/chrome/common/plugin_group.h
deleted file mode 100644
index 9691dd7..0000000
--- a/chrome/common/plugin_group.h
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_COMMON_PLUGIN_GROUP_H_
-#define CHROME_COMMON_PLUGIN_GROUP_H_
-#pragma once
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "base/gtest_prod_util.h"
-#include "base/scoped_ptr.h"
-#include "base/string16.h"
-
-class DictionaryValue;
-class FilePath;
-class Version;
-struct WebPluginInfo;
-
-template <typename T>
-class linked_ptr;
-
-// Hard-coded definitions of plugin groups.
-struct PluginGroupDefinition {
- const char* identifier; // Unique identifier for this group.
- const char* name; // Name of this group.
- const char* name_matcher; // Substring matcher for the plugin name.
- const char* version_matcher_low; // Matchers for the plugin version.
- const char* version_matcher_high;
- const char* min_version; // Minimum secure version.
- const char* update_url; // Location of latest secure version.
-};
-
-// A PluginGroup can match a range of versions of a specific plugin (as defined
-// by matching a substring of its name).
-// It contains all WebPluginInfo structs (at least one) matching its definition.
-// In addition, it knows about a security "baseline", i.e. the minimum version
-// of a plugin that is needed in order not to exhibit known security
-// vulnerabilities.
-
-class PluginGroup {
- public:
- typedef std::map<std::string, linked_ptr<PluginGroup> > PluginMap;
-
- // Creates a PluginGroup from a PluginGroupDefinition.
- static PluginGroup* FromPluginGroupDefinition(
- const PluginGroupDefinition& definition);
-
- ~PluginGroup();
-
- // Creates a PluginGroup from a WebPluginInfo -- when no hard-coded
- // definition is found.
- static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi);
-
- // Find a plugin group matching |info| in the list of hardcoded plugins and
- // returns a copy of it if found, or a new group matching exactly this plugin
- // otherwise.
- // The caller should take ownership of the return PluginGroup.
- static PluginGroup* CopyOrCreatePluginGroup(const WebPluginInfo& info);
-
- // Configures the set of plugin name patterns for disabling plugins via
- // enterprise configuration management.
- static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set);
-
- // Tests to see if a plugin is on the blacklist using its name as
- // the lookup key.
- static bool IsPluginNameDisabledByPolicy(const string16& plugin_name);
-
- // Tests to see if a plugin is on the blacklist using its path as
- // the lookup key.
- static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path);
-
- // Find the PluginGroup matching a Plugin in a list of plugin groups. Returns
- // NULL if no matching PluginGroup is found.
- static PluginGroup* FindGroupMatchingPlugin(
- const std::map<std::string, linked_ptr<PluginGroup> >& plugin_groups,
- const WebPluginInfo& plugin);
-
- // Creates a copy of this plugin group.
- PluginGroup* Copy() {
- return new PluginGroup(group_name_, name_matcher_, version_range_low_str_,
- version_range_high_str_, min_version_str_,
- update_url_, identifier_);
- }
-
- // Returns true if the given plugin matches this group.
- bool Match(const WebPluginInfo& plugin) const;
-
- // Adds the given plugin to this group. Provide the position of the
- // plugin as given by PluginList so we can display its priority.
- void AddPlugin(const WebPluginInfo& plugin, int position);
-
- // Enables/disables this group. This enables/disables all plugins in the
- // group.
- void Enable(bool enable);
-
- // Returns whether the plugin group is enabled or not.
- bool Enabled() const { return enabled_; }
-
- // Returns a unique identifier for this group, if one is defined, or the empty
- // string otherwise.
- const std::string& identifier() const { return identifier_; }
-
- // Returns this group's name, or the filename without extension if the name
- // is empty.
- string16 GetGroupName() const;
-
- // Returns the description of the highest-priority plug-in in the group.
- const string16& description() const { return description_; }
-
- // Returns a DictionaryValue with data to display in the UI.
- DictionaryValue* GetDataForUI() const;
-
- // Returns a DictionaryValue with data to save in the preferences.
- DictionaryValue* GetSummary() const;
-
- // Returns the update URL.
- std::string GetUpdateURL() const { return update_url_; }
-
- // Returns true if the highest-priority plugin in this group has known
- // security problems.
- bool IsVulnerable() const;
-
- // Disables all plugins in this group that are older than the
- // minimum version.
- void DisableOutdatedPlugins();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition);
-
- static const PluginGroupDefinition* GetPluginGroupDefinitions();
- static size_t GetPluginGroupDefinitionsSize();
-
- PluginGroup(const string16& group_name,
- const string16& name_matcher,
- const std::string& version_range_low,
- const std::string& version_range_high,
- const std::string& min_version,
- const std::string& update_url,
- const std::string& identifier);
-
- Version* CreateVersionFromString(const string16& version_string);
-
- // Set the description and version for this plugin group from the
- // given plug-in.
- void UpdateDescriptionAndVersion(const WebPluginInfo& plugin);
-
- // Updates the active plugin in the group. The active plugin is the first
- // enabled one, or if all plugins are disabled, simply the first one.
- void UpdateActivePlugin(const WebPluginInfo& plugin);
-
- static std::set<string16>* policy_disabled_plugin_patterns_;
-
- std::string identifier_;
- string16 group_name_;
- string16 name_matcher_;
- std::string version_range_low_str_;
- std::string version_range_high_str_;
- scoped_ptr<Version> version_range_low_;
- scoped_ptr<Version> version_range_high_;
- string16 description_;
- std::string update_url_;
- bool enabled_;
- std::string min_version_str_;
- scoped_ptr<Version> min_version_;
- scoped_ptr<Version> version_;
- std::vector<WebPluginInfo> web_plugin_infos_;
- std::vector<int> web_plugin_positions_;
-
- DISALLOW_COPY_AND_ASSIGN(PluginGroup);
-};
-
-#endif // CHROME_COMMON_PLUGIN_GROUP_H_
diff --git a/chrome/common/plugin_group_unittest.cc b/chrome/common/plugin_group_unittest.cc
deleted file mode 100644
index a42cbaf..0000000
--- a/chrome/common/plugin_group_unittest.cc
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/common/plugin_group.h"
-
-#include <string>
-#include <vector>
-
-#include "base/scoped_ptr.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "base/version.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/plugins/webplugininfo.h"
-
-static const PluginGroupDefinition kPluginDef = {
- "myplugin", "MyPlugin", "MyPlugin", "", "", "3.0.44", "http://latest/" };
-static const PluginGroupDefinition kPluginDef3 = {
- "myplugin-3", "MyPlugin 3", "MyPlugin", "0", "4", "3.0.44", "http://latest" };
-static const PluginGroupDefinition kPluginDef4 = {
- "myplugin-4", "MyPlugin 4", "MyPlugin", "4", "5", "4.0.44", "http://latest" };
-static const PluginGroupDefinition kPluginDefNotVulnerable = {
- "myplugin-latest", "MyPlugin", "MyPlugin", "", "", "", "http://latest" };
-
-// name, path, version, desc, mime_types, enabled.
-static WebPluginInfo kPlugin2043 = {
- ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("2.0.43"),
- ASCIIToUTF16("MyPlugin version 2.0.43"),
- std::vector<WebPluginMimeType>(), true };
-static WebPluginInfo kPlugin3043 = {
- ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.43"),
- ASCIIToUTF16("MyPlugin version 3.0.43"),
- std::vector<WebPluginMimeType>(), true };
-static WebPluginInfo kPlugin3044 = {
- ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.44"),
- ASCIIToUTF16("MyPlugin version 3.0.44"),
- std::vector<WebPluginMimeType>(), true };
-static WebPluginInfo kPlugin3045 = {
- ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("3.0.45"),
- ASCIIToUTF16("MyPlugin version 3.0.45"),
- std::vector<WebPluginMimeType>(), true };
-static WebPluginInfo kPlugin4043 = {
- ASCIIToUTF16("MyPlugin"), FilePath(), ASCIIToUTF16("4.0.43"),
- ASCIIToUTF16("MyPlugin version 4.0.43"),
- std::vector<WebPluginMimeType>(), true };
-
-class PluginGroupTest : public testing::Test {
- protected:
- virtual void TearDown() {
- PluginGroup::SetPolicyDisabledPluginPatterns(std::set<string16>());
- }
-};
-
-TEST(PluginGroupTest, PluginGroupMatch) {
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- EXPECT_TRUE(group->Match(kPlugin3045));
- group->AddPlugin(kPlugin3045, 0);
- EXPECT_FALSE(group->IsVulnerable());
-}
-
-TEST(PluginGroupTest, PluginGroupMatchCorrectVersion) {
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- EXPECT_TRUE(group->Match(kPlugin2043));
- EXPECT_TRUE(group->Match(kPlugin3043));
- EXPECT_FALSE(group->Match(kPlugin4043));
-
- group.reset(PluginGroup::FromPluginGroupDefinition(kPluginDef4));
- EXPECT_FALSE(group->Match(kPlugin2043));
- EXPECT_FALSE(group->Match(kPlugin3043));
- EXPECT_TRUE(group->Match(kPlugin4043));
-}
-
-TEST(PluginGroupTest, PluginGroupDescription) {
- string16 desc3043(ASCIIToUTF16("MyPlugin version 3.0.43"));
- string16 desc3045(ASCIIToUTF16("MyPlugin version 3.0.45"));
- WebPluginInfo plugin3043(kPlugin3043);
- WebPluginInfo plugin3045(kPlugin3045);
-
- {
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- EXPECT_TRUE(group->Match(plugin3043));
- group->AddPlugin(plugin3043, 0);
- EXPECT_EQ(desc3043, group->description());
- EXPECT_TRUE(group->IsVulnerable());
- EXPECT_TRUE(group->Match(plugin3045));
- group->AddPlugin(plugin3045, 1);
- EXPECT_EQ(desc3043, group->description());
- EXPECT_TRUE(group->IsVulnerable());
- }
-
- {
- // Disable the first plugin.
- plugin3043.enabled = false;
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- EXPECT_TRUE(group->Match(plugin3043));
- group->AddPlugin(plugin3043, 0);
- EXPECT_EQ(desc3043, group->description());
- EXPECT_TRUE(group->IsVulnerable());
- EXPECT_TRUE(group->Match(plugin3045));
- group->AddPlugin(plugin3045, 1);
- EXPECT_EQ(desc3045, group->description());
- EXPECT_FALSE(group->IsVulnerable());
- }
-
- {
- // Disable the second plugin.
- plugin3045.enabled = false;
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- EXPECT_TRUE(group->Match(plugin3043));
- group->AddPlugin(plugin3043, 1);
- EXPECT_EQ(desc3043, group->description());
- EXPECT_TRUE(group->IsVulnerable());
- EXPECT_TRUE(group->Match(plugin3045));
- group->AddPlugin(plugin3045, 0);
- EXPECT_EQ(desc3043, group->description());
- EXPECT_TRUE(group->IsVulnerable());
- }
-}
-
-TEST(PluginGroupTest, PluginGroupDefinition) {
- const PluginGroupDefinition* definitions =
- PluginGroup::GetPluginGroupDefinitions();
- for (size_t i = 0; i < PluginGroup::GetPluginGroupDefinitionsSize(); ++i) {
- scoped_ptr<PluginGroup> def_group(
- PluginGroup::FromPluginGroupDefinition(definitions[i]));
- ASSERT_TRUE(def_group.get() != NULL);
- EXPECT_FALSE(def_group->Match(kPlugin2043));
- }
-}
-
-TEST(PluginGroupTest, DisableOutdated) {
- scoped_ptr<PluginGroup> group(PluginGroup::FromPluginGroupDefinition(
- kPluginDef3));
- group->AddPlugin(kPlugin3043, 0);
- group->AddPlugin(kPlugin3045, 1);
- EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.43"), group->description());
- EXPECT_TRUE(group->IsVulnerable());
-
- group->DisableOutdatedPlugins();
- EXPECT_EQ(ASCIIToUTF16("MyPlugin version 3.0.45"), group->description());
- EXPECT_FALSE(group->IsVulnerable());
-}
-
-TEST(PluginGroupTest, VersionExtraction) {
- // Some real-world plugin versions (spaces, commata, parentheses, 'r', oh my)
- const char* versions[][2] = {
- { "7.6.6 (1671)", "7.6.6.1671" }, // Quicktime
- { "2, 0, 0, 254", "2.0.0.254" }, // DivX
- { "3, 0, 0, 0", "3.0.0.0" }, // Picasa
- { "1, 0, 0, 1", "1.0.0.1" }, // Earth
- { "10,0,45,2", "10.0.45.2" }, // Flash
- { "11.5.7r609", "11.5.7.609"} // Shockwave
- };
-
- for (size_t i = 0; i < arraysize(versions); i++) {
- const WebPluginInfo plugin = {
- ASCIIToUTF16("Blah Plugin"), FilePath(), ASCIIToUTF16(versions[i][0]),
- string16(),std::vector<WebPluginMimeType>(), true };
- scoped_ptr<PluginGroup> group(PluginGroup::FromWebPluginInfo(plugin));
- EXPECT_TRUE(group->Match(plugin));
- group->AddPlugin(plugin, 0);
- scoped_ptr<DictionaryValue> data(group->GetDataForUI());
- std::string version;
- data->GetString("version", &version);
- EXPECT_EQ(versions[i][1], version);
- }
-}
-
-TEST(PluginGroupTest, DisabledByPolicy) {
- std::set<string16> disabled_plugins;
- disabled_plugins.insert(ASCIIToUTF16("Disable this!"));
- disabled_plugins.insert(ASCIIToUTF16("*Google*"));
- PluginGroup::SetPolicyDisabledPluginPatterns(disabled_plugins);
-
- EXPECT_FALSE(PluginGroup::IsPluginNameDisabledByPolicy(ASCIIToUTF16("42")));
- EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy(
- ASCIIToUTF16("Disable this!")));
- EXPECT_TRUE(PluginGroup::IsPluginNameDisabledByPolicy(
- ASCIIToUTF16("Google Earth")));
-}