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