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 <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 | 17 |
| 18 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class FilePath; | 19 class FilePath; |
| 20 class Version; | 20 class Version; |
| 21 struct WebPluginInfo; | 21 struct WebPluginInfo; |
| 22 | 22 |
| 23 namespace NPAPI { | 23 namespace NPAPI { |
| 24 class PluginList; | 24 class PluginList; |
| 25 }; | 25 }; |
| 26 | 26 namespace plugin_test_internal { |
| 27 class PluginListWithoutFileIO; | |
| 28 } | |
| 27 // Hard-coded version ranges for plugin groups. | 29 // Hard-coded version ranges for plugin groups. |
| 28 struct VersionRangeDefinition { | 30 struct VersionRangeDefinition { |
| 29 // Matcher for lowest version matched by this range (inclusive). May be empty | 31 // Matcher for lowest version matched by this range (inclusive). May be empty |
| 30 // to match everything iff |version_matcher_high| is also empty. | 32 // to match everything iff |version_matcher_high| is also empty. |
| 31 const char* version_matcher_low; | 33 const char* version_matcher_low; |
| 32 // Matcher for highest version matched by this range (exclusive). May be empty | 34 // Matcher for highest version matched by this range (exclusive). May be empty |
| 33 // to match anything higher than |version_matcher_low|. | 35 // to match anything higher than |version_matcher_low|. |
| 34 const char* version_matcher_high; | 36 const char* version_matcher_high; |
| 35 const char* min_version; // Minimum secure version. | 37 const char* min_version; // Minimum secure version. |
| 36 }; | 38 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 PluginGroup& operator=(const PluginGroup& other); | 85 PluginGroup& operator=(const PluginGroup& other); |
| 84 | 86 |
| 85 // Configures the set of plugin name patterns for disabling plugins via | 87 // Configures the set of plugin name patterns for disabling plugins via |
| 86 // enterprise configuration management. | 88 // enterprise configuration management. |
| 87 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); | 89 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); |
| 88 | 90 |
| 89 // Tests to see if a plugin is on the blacklist using its name as | 91 // Tests to see if a plugin is on the blacklist using its name as |
| 90 // the lookup key. | 92 // the lookup key. |
| 91 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); | 93 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); |
| 92 | 94 |
| 93 // Tests to see if a plugin is on the blacklist using its path as | |
| 94 // the lookup key. | |
| 95 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path); | |
| 96 | |
| 97 // Returns true if the given plugin matches this group. | 95 // Returns true if the given plugin matches this group. |
| 98 bool Match(const WebPluginInfo& plugin) const; | 96 bool Match(const WebPluginInfo& plugin) const; |
| 99 | 97 |
| 100 // Adds the given plugin to this group. Provide the position of the | 98 // Adds the given plugin to this group. |
| 101 // plugin as given by PluginList so we can display its priority. | 99 // Retuns true if plugin has been added and false if it was already contained |
| 102 void AddPlugin(const WebPluginInfo& plugin, int position); | 100 // inn the group before. |
|
Bernhard Bauer
2010/12/20 22:30:28
Nit: "in".
pastarmovj
2010/12/21 16:53:02
Done.
| |
| 101 bool AddPlugin(const WebPluginInfo& plugin, int priority); | |
| 102 | |
| 103 // Enables a plugin given its filename. The function returns true if the | |
| 104 // plugin could be enabled. Plugins might not get enabled if they are disabled | |
| 105 // by policy or are already in the disabled state. | |
| 106 bool EnablePlugin(const FilePath& filename); | |
| 107 | |
| 108 // Disables a plugin given its filename. The function returns true if the | |
| 109 // plugin could be disabled. Plugins might not get enabled if they are enabled | |
| 110 // by policy or are already in the enabled state. | |
|
Bernhard Bauer
2010/12/20 22:30:28
You could group these comments ("the two following
pastarmovj
2010/12/21 16:53:02
Done.
| |
| 111 bool DisablePlugin(const FilePath& filename); | |
| 103 | 112 |
| 104 // Enables/disables this group. This enables/disables all plugins in the | 113 // Enables/disables this group. This enables/disables all plugins in the |
| 105 // group. | 114 // group. |
| 106 void Enable(bool enable); | 115 bool EnableGroup(bool enable); |
| 107 | 116 |
| 108 // Returns whether the plugin group is enabled or not. | 117 // Returns whether the plugin group is enabled or not. |
| 109 bool Enabled() const { return enabled_; } | 118 bool Enabled() const { return enabled_; } |
| 110 | 119 |
| 111 // Returns a unique identifier for this group, if one is defined, or the empty | 120 // Returns a unique identifier for this group, if one is defined, or the empty |
| 112 // string otherwise. | 121 // string otherwise. |
| 113 const std::string& identifier() const { return identifier_; } | 122 const std::string& identifier() const { return identifier_; } |
| 114 | 123 |
| 115 // Returns this group's name, or the filename without extension if the name | 124 // Returns this group's name, or the filename without extension if the name |
| 116 // is empty. | 125 // is empty. |
| 117 string16 GetGroupName() const; | 126 string16 GetGroupName() const; |
| 118 | 127 |
| 128 const std::vector<WebPluginInfo>& GetPlugins() const; | |
| 129 | |
| 130 std::vector<WebPluginInfo>& GetPlugins() { return web_plugin_infos_; } | |
| 131 | |
| 132 bool ContainsPlugin(const FilePath& path) const; | |
| 133 | |
| 119 // Returns the description of the highest-priority plug-in in the group. | 134 // Returns the description of the highest-priority plug-in in the group. |
| 120 const string16& description() const { return description_; } | 135 const string16& description() const { return description_; } |
| 121 | 136 |
| 122 // Returns a DictionaryValue with data to display in the UI. | 137 // Returns a DictionaryValue with data to display in the UI. |
| 123 DictionaryValue* GetDataForUI() const; | 138 DictionaryValue* GetDataForUI() const; |
| 124 | 139 |
| 125 // Returns a DictionaryValue with data to save in the preferences. | 140 // Returns a DictionaryValue with data to save in the preferences. |
| 126 DictionaryValue* GetSummary() const; | 141 DictionaryValue* GetSummary() const; |
| 127 | 142 |
| 128 // Returns the update URL. | 143 // Returns the update URL. |
| 129 std::string GetUpdateURL() const { return update_url_; } | 144 std::string GetUpdateURL() const { return update_url_; } |
| 130 | 145 |
| 131 // Returns true if the highest-priority plugin in this group has known | 146 // Returns true if the highest-priority plugin in this group has known |
| 132 // security problems. | 147 // security problems. |
| 133 bool IsVulnerable() const; | 148 bool IsVulnerable() const; |
| 134 | 149 |
| 150 // Check if the group has no plugins or only non-existing pluigns | |
|
Bernhard Bauer
2010/12/20 22:30:28
Nit: plugins
pastarmovj
2010/12/21 16:53:02
Done.
| |
| 151 // (with priority 0). | |
|
Bernhard Bauer
2010/12/20 22:30:28
This priority 0 thing is definitely a step in the
pastarmovj
2010/12/21 16:53:02
I moved the priority back into the group class and
jam
2010/12/21 19:57:42
I still don't think we need a priority at all. Ca
| |
| 152 bool IsEmpty() const; | |
| 153 | |
| 135 // Disables all plugins in this group that are older than the | 154 // Disables all plugins in this group that are older than the |
| 136 // minimum version. | 155 // minimum version. |
| 137 void DisableOutdatedPlugins(); | 156 void DisableOutdatedPlugins(); |
| 138 | 157 |
| 139 // Parse a version string as used by a plug-in. This method is more lenient | 158 // Parse a version string as used by a plug-in. This method is more lenient |
| 140 // in accepting weird version strings than Version::GetFromString(). | 159 // in accepting weird version strings than Version::GetFromString(). |
| 141 static Version* CreateVersionFromString(const string16& version_string); | 160 static Version* CreateVersionFromString(const string16& version_string); |
| 142 | 161 |
| 143 private: | 162 private: |
| 144 typedef std::map<std::string, PluginGroup*> PluginMap; | 163 typedef std::map<std::string, PluginGroup*> PluginMap; |
| 145 | 164 |
| 146 friend class NPAPI::PluginList; | 165 friend class NPAPI::PluginList; |
| 166 friend class plugin_test_internal::PluginListWithoutFileIO; | |
| 147 friend class PluginGroupTest; | 167 friend class PluginGroupTest; |
| 148 friend class TableModelArrayControllerTest; | 168 friend class TableModelArrayControllerTest; |
| 149 friend class PluginExceptionsTableModelTest; | 169 friend class PluginExceptionsTableModelTest; |
| 150 | 170 |
| 151 // Generates the (short) identifier string for the given plugin. | 171 // Generates the (short) identifier string for the given plugin. |
| 152 static std::string GetIdentifier(const WebPluginInfo& wpi); | 172 static std::string GetIdentifier(const WebPluginInfo& wpi); |
| 153 | 173 |
| 154 // Generates the long identifier (based on the full file path) for the given | 174 // Generates the long identifier (based on the full file path) for the given |
| 155 // plugin, to be called when the short identifier is not unique. | 175 // plugin, to be called when the short identifier is not unique. |
| 156 static std::string GetLongIdentifier(const WebPluginInfo& wpi); | 176 static std::string GetLongIdentifier(const WebPluginInfo& wpi); |
| 157 | 177 |
| 158 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | 178 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes |
| 159 // ownership of the created PluginGroup. | 179 // ownership of the created PluginGroup. |
| 160 static PluginGroup* FromPluginGroupDefinition( | 180 static PluginGroup* FromPluginGroupDefinition( |
| 161 const PluginGroupDefinition& definition); | 181 const PluginGroupDefinition& definition); |
| 162 | 182 |
| 163 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of | 183 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of |
| 164 // the created PluginGroup. | 184 // the created PluginGroup. |
| 165 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); | 185 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); |
| 166 | 186 |
| 187 // Creates an empty PluginGroup from a given name. The caller takes | |
| 188 // ownership of the created PluginGroup. | |
| 189 static PluginGroup* CreateEmptyGroup(const string16& name); | |
| 190 | |
| 167 // Returns |true| if |version| is contained in [low, high) of |range|. | 191 // Returns |true| if |version| is contained in [low, high) of |range|. |
| 168 static bool IsVersionInRange(const Version& version, | 192 static bool IsVersionInRange(const Version& version, |
| 169 const VersionRange& range); | 193 const VersionRange& range); |
| 170 | 194 |
| 171 // Returns |true| iff |plugin_version| is both contained in |version_range| | 195 // Returns |true| iff |plugin_version| is both contained in |version_range| |
| 172 // and declared outdated (== vulnerable) by it. | 196 // and declared outdated (== vulnerable) by it. |
| 173 static bool IsPluginOutdated(const Version& plugin_version, | 197 static bool IsPluginOutdated(const Version& plugin_version, |
| 174 const VersionRange& version_range); | 198 const VersionRange& version_range); |
| 175 | 199 |
| 176 PluginGroup(const string16& group_name, | 200 PluginGroup(const string16& group_name, |
| 177 const string16& name_matcher, | 201 const string16& name_matcher, |
| 178 const std::string& update_url, | 202 const std::string& update_url, |
| 179 const std::string& identifier); | 203 const std::string& identifier); |
| 180 | 204 |
| 181 void InitFrom(const PluginGroup& other); | 205 void InitFrom(const PluginGroup& other); |
| 182 | 206 |
| 183 // Set the description and version for this plugin group from the | 207 // Set the description and version for this plugin group from the |
| 184 // given plug-in. | 208 // given plug-in. |
| 185 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); | 209 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); |
| 186 | 210 |
| 187 // Updates the active plugin in the group. The active plugin is the first | 211 // Updates the active plugin in the group. The active plugin is the first |
| 188 // enabled one, or if all plugins are disabled, simply the first one. | 212 // enabled one, or if all plugins are disabled, simply the first one. |
| 189 void UpdateActivePlugin(const WebPluginInfo& plugin); | 213 void UpdateActivePlugin(const WebPluginInfo& plugin); |
| 190 | 214 |
| 215 // Refreshes the enabled flag based on the state of its plugins. | |
| 216 void RefreshEnabledState(); | |
| 217 | |
| 191 static std::set<string16>* policy_disabled_plugin_patterns_; | 218 static std::set<string16>* policy_disabled_plugin_patterns_; |
| 192 | 219 |
| 193 std::string identifier_; | 220 std::string identifier_; |
| 194 string16 group_name_; | 221 string16 group_name_; |
| 195 string16 name_matcher_; | 222 string16 name_matcher_; |
| 196 string16 description_; | 223 string16 description_; |
| 197 std::string update_url_; | 224 std::string update_url_; |
| 198 bool enabled_; | 225 bool enabled_; |
| 199 std::vector<VersionRange> version_ranges_; | 226 std::vector<VersionRange> version_ranges_; |
| 200 scoped_ptr<Version> version_; | 227 scoped_ptr<Version> version_; |
| 201 std::vector<WebPluginInfo> web_plugin_infos_; | 228 std::vector<WebPluginInfo> web_plugin_infos_; |
| 202 std::vector<int> web_plugin_positions_; | |
| 203 }; | 229 }; |
| 204 | 230 |
| 205 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ | 231 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_GROUP_H_ |
| OLD | NEW |