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 #include "webkit/plugins/npapi/webplugininfo.h" |
17 | 18 |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 class FilePath; | 20 class FilePath; |
20 class TableModelArrayControllerTest; | 21 class TableModelArrayControllerTest; |
21 class PluginExceptionsTableModelTest; | 22 class PluginExceptionsTableModelTest; |
22 class Version; | 23 class Version; |
23 | 24 |
24 namespace webkit { | 25 namespace webkit { |
25 namespace npapi { | 26 namespace npapi { |
26 | 27 |
27 class PluginList; | 28 class PluginList; |
28 struct WebPluginInfo; | 29 namespace plugin_test_internal { |
29 | 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 PluginGroup& operator=(const PluginGroup& other); | 89 PluginGroup& operator=(const PluginGroup& other); |
88 | 90 |
89 // Configures the set of plugin name patterns for disabling plugins via | 91 // Configures the set of plugin name patterns for disabling plugins via |
90 // enterprise configuration management. | 92 // enterprise configuration management. |
91 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); | 93 static void SetPolicyDisabledPluginPatterns(const std::set<string16>& set); |
92 | 94 |
93 // Tests to see if a plugin is on the blacklist using its name as | 95 // Tests to see if a plugin is on the blacklist using its name as |
94 // the lookup key. | 96 // the lookup key. |
95 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); | 97 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); |
96 | 98 |
97 // Tests to see if a plugin is on the blacklist using its path as | |
98 // the lookup key. | |
99 static bool IsPluginPathDisabledByPolicy(const FilePath& plugin_path); | |
100 | |
101 // Returns true if the given plugin matches this group. | 99 // Returns true if the given plugin matches this group. |
102 bool Match(const WebPluginInfo& plugin) const; | 100 bool Match(const WebPluginInfo& plugin) const; |
103 | 101 |
104 // Adds the given plugin to this group. Provide the position of the | 102 // Adds the given plugin to this group. |
105 // plugin as given by PluginList so we can display its priority. | 103 void AddPlugin(const WebPluginInfo& plugin); |
106 void AddPlugin(const WebPluginInfo& plugin, int position); | |
107 | 104 |
108 bool IsEmpty() const; | 105 // Removes a plugin from the group by its path. |
| 106 bool RemovePlugin(const FilePath& filename); |
| 107 |
| 108 // The two following functions enable/disable a plugin given its filename. The |
| 109 // function returns true if the plugin could be enabled/disabled. Plugins |
| 110 // might not get enabled/disabled if they are controlled by policy or are |
| 111 // already in the wanted state. |
| 112 bool EnablePlugin(const FilePath& filename); |
| 113 bool DisablePlugin(const FilePath& filename); |
109 | 114 |
110 // Enables/disables this group. This enables/disables all plugins in the | 115 // Enables/disables this group. This enables/disables all plugins in the |
111 // group. | 116 // group. |
112 void Enable(bool enable); | 117 bool EnableGroup(bool enable); |
| 118 |
| 119 // Checks whether the group should be disabled/enabled by a policy and puts |
| 120 // it in the needed state. Updates all contained plugins too. |
| 121 void EnforceGroupPolicy(); |
113 | 122 |
114 // Returns whether the plugin group is enabled or not. | 123 // Returns whether the plugin group is enabled or not. |
115 bool Enabled() const { return enabled_; } | 124 bool Enabled() const { return enabled_; } |
116 | 125 |
117 // Returns a unique identifier for this group, if one is defined, or the empty | 126 // Returns a unique identifier for this group, if one is defined, or the empty |
118 // string otherwise. | 127 // string otherwise. |
119 const std::string& identifier() const { return identifier_; } | 128 const std::string& identifier() const { return identifier_; } |
120 | 129 |
| 130 // Sets a unique identifier for this group or if none is set an empty string. |
| 131 void set_identifier(const std::string& identifier) { |
| 132 identifier_ = identifier; |
| 133 } |
| 134 |
121 // Returns this group's name, or the filename without extension if the name | 135 // Returns this group's name, or the filename without extension if the name |
122 // is empty. | 136 // is empty. |
123 string16 GetGroupName() const; | 137 string16 GetGroupName() const; |
124 | 138 |
| 139 // Returns all plugins added to the group. |
| 140 const std::vector<WebPluginInfo>& web_plugins_info() const { |
| 141 return web_plugin_infos_; |
| 142 } |
| 143 |
| 144 // Checks whether a plugin exists in the group with the given path. |
| 145 bool ContainsPlugin(const FilePath& path) const; |
| 146 |
125 // Returns the description of the highest-priority plug-in in the group. | 147 // Returns the description of the highest-priority plug-in in the group. |
126 const string16& description() const { return description_; } | 148 const string16& description() const { return description_; } |
127 | 149 |
128 // Returns a DictionaryValue with data to display in the UI. | 150 // Returns a DictionaryValue with data to display in the UI. |
129 DictionaryValue* GetDataForUI() const; | 151 DictionaryValue* GetDataForUI() const; |
130 | 152 |
131 // Returns a DictionaryValue with data to save in the preferences. | 153 // Returns a DictionaryValue with data to save in the preferences. |
132 DictionaryValue* GetSummary() const; | 154 DictionaryValue* GetSummary() const; |
133 | 155 |
134 // Returns the update URL. | 156 // Returns the update URL. |
135 std::string GetUpdateURL() const { return update_url_; } | 157 std::string GetUpdateURL() const { return update_url_; } |
136 | 158 |
137 // Returns true if the highest-priority plugin in this group has known | 159 // Returns true if the highest-priority plugin in this group has known |
138 // security problems. | 160 // security problems. |
139 bool IsVulnerable() const; | 161 bool IsVulnerable() const; |
140 | 162 |
| 163 // Check if the group has no plugins. Could happen after a reload if the plug- |
| 164 // in has disappeared from the pc (or in the process of updating). |
| 165 bool IsEmpty() const; |
| 166 |
141 // Disables all plugins in this group that are older than the | 167 // Disables all plugins in this group that are older than the |
142 // minimum version. | 168 // minimum version. |
143 void DisableOutdatedPlugins(); | 169 void DisableOutdatedPlugins(); |
144 | 170 |
145 // Parse a version string as used by a plug-in. This method is more lenient | 171 // Parse a version string as used by a plug-in. This method is more lenient |
146 // in accepting weird version strings than Version::GetFromString(). | 172 // in accepting weird version strings than Version::GetFromString(). |
147 static Version* CreateVersionFromString(const string16& version_string); | 173 static Version* CreateVersionFromString(const string16& version_string); |
148 | 174 |
149 std::vector<WebPluginInfo> web_plugin_infos() { return web_plugin_infos_; } | 175 std::vector<WebPluginInfo> web_plugin_infos() { return web_plugin_infos_; } |
150 | 176 |
151 private: | 177 private: |
152 typedef std::map<std::string, PluginGroup*> PluginMap; | |
153 | |
154 friend class PluginList; | 178 friend class PluginList; |
| 179 friend class plugin_test_internal::PluginListWithoutFileIO; |
155 friend class PluginGroupTest; | 180 friend class PluginGroupTest; |
156 friend class ::TableModelArrayControllerTest; | 181 friend class ::TableModelArrayControllerTest; |
157 friend class ::PluginExceptionsTableModelTest; | 182 friend class ::PluginExceptionsTableModelTest; |
| 183 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
158 | 184 |
159 // Generates the (short) identifier string for the given plugin. | 185 // Generates the (short) identifier string for the given plugin. |
160 static std::string GetIdentifier(const WebPluginInfo& wpi); | 186 static std::string GetIdentifier(const WebPluginInfo& wpi); |
161 | 187 |
162 // Generates the long identifier (based on the full file path) for the given | 188 // Generates the long identifier (based on the full file path) for the given |
163 // plugin, to be called when the short identifier is not unique. | 189 // plugin, to be called when the short identifier is not unique. |
164 static std::string GetLongIdentifier(const WebPluginInfo& wpi); | 190 static std::string GetLongIdentifier(const WebPluginInfo& wpi); |
165 | 191 |
166 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes | 192 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes |
167 // ownership of the created PluginGroup. | 193 // ownership of the created PluginGroup. |
(...skipping 21 matching lines...) Expand all Loading... |
189 void InitFrom(const PluginGroup& other); | 215 void InitFrom(const PluginGroup& other); |
190 | 216 |
191 // Set the description and version for this plugin group from the | 217 // Set the description and version for this plugin group from the |
192 // given plug-in. | 218 // given plug-in. |
193 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); | 219 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); |
194 | 220 |
195 // Updates the active plugin in the group. The active plugin is the first | 221 // Updates the active plugin in the group. The active plugin is the first |
196 // enabled one, or if all plugins are disabled, simply the first one. | 222 // enabled one, or if all plugins are disabled, simply the first one. |
197 void UpdateActivePlugin(const WebPluginInfo& plugin); | 223 void UpdateActivePlugin(const WebPluginInfo& plugin); |
198 | 224 |
| 225 // Refreshes the enabled flag based on the state of its plugins. |
| 226 void RefreshEnabledState(); |
| 227 |
| 228 // Enables the plugin if not already enabled and if policy allows it to. |
| 229 // Returns true on success. |
| 230 static bool Enable(WebPluginInfo* plugin, int reason); |
| 231 |
| 232 // Disables the plugin if not already disabled and if policy allows it to. |
| 233 // Returns true on success. |
| 234 static bool Disable(WebPluginInfo* plugin, int reason); |
| 235 |
| 236 // Returns a non-const vector of all plugins in the group. This is only used |
| 237 // by PluginList. |
| 238 std::vector<WebPluginInfo>& GetPluginsContainer() { |
| 239 return web_plugin_infos_; |
| 240 } |
| 241 |
199 static std::set<string16>* policy_disabled_plugin_patterns_; | 242 static std::set<string16>* policy_disabled_plugin_patterns_; |
200 | 243 |
201 std::string identifier_; | 244 std::string identifier_; |
202 string16 group_name_; | 245 string16 group_name_; |
203 string16 name_matcher_; | 246 string16 name_matcher_; |
204 string16 description_; | 247 string16 description_; |
205 std::string update_url_; | 248 std::string update_url_; |
206 bool enabled_; | 249 bool enabled_; |
207 std::vector<VersionRange> version_ranges_; | 250 std::vector<VersionRange> version_ranges_; |
208 scoped_ptr<Version> version_; | 251 scoped_ptr<Version> version_; |
209 std::vector<WebPluginInfo> web_plugin_infos_; | 252 std::vector<WebPluginInfo> web_plugin_infos_; |
210 std::vector<int> web_plugin_positions_; | |
211 }; | 253 }; |
212 | 254 |
213 } // namespace npapi | 255 } // namespace npapi |
214 } // namespace webkit | 256 } // namespace webkit |
215 | 257 |
216 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 258 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
OLD | NEW |