Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 16 | 17 |
| 17 class DictionaryValue; | 18 class DictionaryValue; |
| 18 class FilePath; | 19 class FilePath; |
| 19 class Version; | 20 class Version; |
| 20 struct WebPluginInfo; | 21 struct WebPluginInfo; |
| 21 | 22 |
| 22 namespace NPAPI { | 23 namespace NPAPI { |
| 23 class PluginList; | 24 class PluginList; |
| 24 }; | 25 }; |
| 25 | 26 namespace plugin_test_internal { |
| 26 template <typename T> | 27 class PluginExceptionsTableModelTest; |
| 27 class linked_ptr; | 28 } |
| 28 | 29 |
| 29 // Hard-coded definitions of plugin groups. | 30 // Hard-coded definitions of plugin groups. |
| 30 struct PluginGroupDefinition { | 31 struct PluginGroupDefinition { |
| 31 const char* identifier; // Unique identifier for this group. | 32 const char* identifier; // Unique identifier for this group. |
| 32 const char* name; // Name of this group. | 33 const char* name; // Name of this group. |
| 33 const char* name_matcher; // Substring matcher for the plugin name. | 34 const char* name_matcher; // Substring matcher for the plugin name. |
| 34 const char* version_matcher_low; // Matchers for the plugin version. | 35 const char* version_matcher_low; // Matchers for the plugin version. |
| 35 const char* version_matcher_high; | 36 const char* version_matcher_high; |
| 36 const char* min_version; // Minimum secure version. | 37 const char* min_version; // Minimum secure version. |
| 37 const char* update_url; // Location of latest secure version. | 38 const char* update_url; // Location of latest secure version. |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // A PluginGroup can match a range of versions of a specific plugin (as defined | 41 // A PluginGroup can match a range of versions of a specific plugin (as defined |
| 41 // by matching a substring of its name). | 42 // by matching a substring of its name). |
| 42 // It contains all WebPluginInfo structs (at least one) matching its definition. | 43 // It contains all WebPluginInfo structs (at least one) matching its definition. |
| 43 // In addition, it knows about a security "baseline", i.e. the minimum version | 44 // In addition, it knows about a security "baseline", i.e. the minimum version |
| 44 // of a plugin that is needed in order not to exhibit known security | 45 // of a plugin that is needed in order not to exhibit known security |
| 45 // vulnerabilities. | 46 // vulnerabilities. |
| 46 | 47 |
| 47 class PluginGroup { | 48 class PluginGroup { |
| 48 public: | 49 public: |
| 49 // Used by about:plugins to disable Reader plugin when internal PDF viewer is | 50 // Used by about:plugins to disable Reader plugin when internal PDF viewer is |
| 50 // enabled. | 51 // enabled. |
| 51 static const char* kAdobeReader8GroupName; | 52 static const char* kAdobeReader8GroupName; |
| 52 static const char* kAdobeReader9GroupName; | 53 static const char* kAdobeReader9GroupName; |
| 53 | 54 |
| 54 typedef std::map<std::string, linked_ptr<PluginGroup> > PluginMap; | 55 PluginGroup(const PluginGroup& other); |
| 55 | |
| 56 // Creates a PluginGroup from a PluginGroupDefinition. | |
| 57 static PluginGroup* FromPluginGroupDefinition( | |
| 58 const PluginGroupDefinition& definition); | |
| 59 | 56 |
| 60 ~PluginGroup(); | 57 ~PluginGroup(); |
| 61 | 58 |
| 62 // Creates a PluginGroup from a WebPluginInfo -- when no hard-coded | 59 PluginGroup& operator=(const PluginGroup& other); |
| 63 // definition is found. | |
| 64 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); | |
| 65 | |
| 66 // Find a plugin group matching |info| in the list of hardcoded plugins and | |
| 67 // returns a copy of it if found, or a new group matching exactly this plugin | |
| 68 // otherwise. | |
| 69 // The caller should take ownership of the return PluginGroup. | |
| 70 static PluginGroup* CopyOrCreatePluginGroup(const WebPluginInfo& info); | |
| 71 | 60 |
| 72 // Configures the set of plugin name patterns for disabling plugins via | 61 // Configures the set of plugin name patterns for disabling plugins via |
| 73 // enterprise configuration management. | 62 // enterprise configuration management. |
| 74 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); | 63 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); |
| 75 | 64 |
| 76 // Tests to see if a plugin is on the blacklist using its name as | 65 // Tests to see if a plugin is on the blacklist using its name as |
| 77 // the lookup key. | 66 // the lookup key. |
| 78 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); | 67 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); |
| 79 | 68 |
| 80 // Tests to see if a plugin is on the blacklist using its path as | 69 // Tests to see if a plugin is on the blacklist using its path as |
| 81 // the lookup key. | 70 // the lookup key. |
| 82 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path); | 71 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path); |
| 83 | 72 |
| 84 // Find the PluginGroup matching a Plugin in a list of plugin groups. Returns | |
| 85 // NULL if no matching PluginGroup is found. | |
| 86 static PluginGroup* FindGroupMatchingPlugin( | |
| 87 const std::map<std::string, linked_ptr<PluginGroup> >& plugin_groups, | |
| 88 const WebPluginInfo& plugin); | |
| 89 | |
| 90 // Creates a copy of this plugin group. | |
| 91 PluginGroup* Copy() { | |
| 92 return new PluginGroup(group_name_, name_matcher_, version_range_low_str_, | |
| 93 version_range_high_str_, min_version_str_, | |
| 94 update_url_, identifier_); | |
| 95 } | |
| 96 | |
| 97 // Returns true if the given plugin matches this group. | 73 // Returns true if the given plugin matches this group. |
| 98 bool Match(const WebPluginInfo& plugin) const; | 74 bool Match(const WebPluginInfo& plugin) const; |
| 99 | 75 |
| 100 // Adds the given plugin to this group. Provide the position of the | 76 // Adds the given plugin to this group. Provide the position of the |
| 101 // plugin as given by PluginList so we can display its priority. | 77 // plugin as given by PluginList so we can display its priority. |
| 102 void AddPlugin(const WebPluginInfo& plugin, int position); | 78 void AddPlugin(const WebPluginInfo& plugin, int position); |
| 103 | 79 |
| 104 // Enables/disables this group. This enables/disables all plugins in the | 80 // Enables/disables this group. This enables/disables all plugins in the |
| 105 // group. | 81 // group. |
| 106 void Enable(bool enable); | 82 void Enable(bool enable); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 130 | 106 |
| 131 // Returns true if the highest-priority plugin in this group has known | 107 // Returns true if the highest-priority plugin in this group has known |
| 132 // security problems. | 108 // security problems. |
| 133 bool IsVulnerable() const; | 109 bool IsVulnerable() const; |
| 134 | 110 |
| 135 // Disables all plugins in this group that are older than the | 111 // Disables all plugins in this group that are older than the |
| 136 // minimum version. | 112 // minimum version. |
| 137 void DisableOutdatedPlugins(); | 113 void DisableOutdatedPlugins(); |
| 138 | 114 |
| 139 private: | 115 private: |
| 116 typedef std::map<std::string, PluginGroup*> PluginMap; | |
| 117 | |
| 118 friend class NPAPI::PluginList; | |
| 119 friend class PluginGroupTest; | |
| 140 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); | 120 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
|
Bernhard Bauer
2010/12/07 10:32:05
I think this is unnecessary now.
| |
| 121 friend class TableModelArrayControllerTest; | |
| 122 friend class plugin_test_internal::PluginExceptionsTableModelTest; | |
| 141 | 123 |
| 142 static const PluginGroupDefinition* GetPluginGroupDefinitions(); | 124 static const PluginGroupDefinition* GetPluginGroupDefinitions(); |
| 143 static size_t GetPluginGroupDefinitionsSize(); | 125 static size_t GetPluginGroupDefinitionsSize(); |
| 144 | 126 |
| 127 // Generates the (short) identifier string for the given plugin. | |
| 128 static std::string GetIdentifier(const WebPluginInfo& wpi); | |
| 129 | |
| 130 // Generates the long identifier (based on the full file path) for the given | |
| 131 // plugin, to be called when the short identifier is not unique. | |
| 132 static std::string GetLongIdentifier(const WebPluginInfo& wpi); | |
| 133 | |
| 134 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | |
| 135 // ownership of the created PluginGroup. | |
| 136 static PluginGroup* FromPluginGroupDefinition( | |
| 137 const PluginGroupDefinition& definition); | |
| 138 | |
| 139 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of | |
| 140 // the created PluginGroup. | |
| 141 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); | |
| 142 | |
| 145 PluginGroup(const string16& group_name, | 143 PluginGroup(const string16& group_name, |
| 146 const string16& name_matcher, | 144 const string16& name_matcher, |
| 147 const std::string& version_range_low, | 145 const std::string& version_range_low, |
| 148 const std::string& version_range_high, | 146 const std::string& version_range_high, |
| 149 const std::string& min_version, | 147 const std::string& min_version, |
| 150 const std::string& update_url, | 148 const std::string& update_url, |
| 151 const std::string& identifier); | 149 const std::string& identifier); |
| 152 | 150 |
| 151 void InitFrom(const PluginGroup& other); | |
| 152 | |
| 153 Version* CreateVersionFromString(const string16& version_string); | 153 Version* CreateVersionFromString(const string16& version_string); |
| 154 | 154 |
| 155 // Set the description and version for this plugin group from the | 155 // Set the description and version for this plugin group from the |
| 156 // given plug-in. | 156 // given plug-in. |
| 157 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); | 157 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); |
| 158 | 158 |
| 159 // Updates the active plugin in the group. The active plugin is the first | 159 // Updates the active plugin in the group. The active plugin is the first |
| 160 // enabled one, or if all plugins are disabled, simply the first one. | 160 // enabled one, or if all plugins are disabled, simply the first one. |
| 161 void UpdateActivePlugin(const WebPluginInfo& plugin); | 161 void UpdateActivePlugin(const WebPluginInfo& plugin); |
| 162 | 162 |
| 163 static std::set<string16>* policy_disabled_plugin_patterns_; | 163 static std::set<string16>* policy_disabled_plugin_patterns_; |
| 164 | 164 |
| 165 std::string identifier_; | 165 std::string identifier_; |
| 166 string16 group_name_; | 166 string16 group_name_; |
| 167 string16 name_matcher_; | 167 string16 name_matcher_; |
| 168 std::string version_range_low_str_; | 168 std::string version_range_low_str_; |
| 169 std::string version_range_high_str_; | 169 std::string version_range_high_str_; |
| 170 scoped_ptr<Version> version_range_low_; | 170 scoped_ptr<Version> version_range_low_; |
| 171 scoped_ptr<Version> version_range_high_; | 171 scoped_ptr<Version> version_range_high_; |
| 172 string16 description_; | 172 string16 description_; |
| 173 std::string update_url_; | 173 std::string update_url_; |
| 174 bool enabled_; | 174 bool enabled_; |
| 175 std::string min_version_str_; | 175 std::string min_version_str_; |
| 176 scoped_ptr<Version> min_version_; | 176 scoped_ptr<Version> min_version_; |
| 177 scoped_ptr<Version> version_; | 177 scoped_ptr<Version> version_; |
| 178 std::vector<WebPluginInfo> web_plugin_infos_; | 178 std::vector<WebPluginInfo> web_plugin_infos_; |
| 179 std::vector<int> web_plugin_positions_; | 179 std::vector<int> web_plugin_positions_; |
| 180 | |
| 181 DISALLOW_COPY_AND_ASSIGN(PluginGroup); | |
| 182 }; | 180 }; |
| 183 | 181 |
| 184 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ | 182 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ |
| OLD | NEW |