OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | |
10 #include <set> | |
11 #include <string> | 9 #include <string> |
12 #include <vector> | 10 #include <vector> |
13 | 11 |
14 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
15 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
16 #include "base/string16.h" | 14 #include "base/string16.h" |
17 #include "webkit/plugins/webplugininfo.h" | 15 #include "webkit/plugins/webplugininfo.h" |
18 | 16 |
19 class FilePath; | 17 class FilePath; |
20 class PluginExceptionsTableModelTest; | 18 class PluginExceptionsTableModelTest; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 static const char* kRealPlayerGroupName; | 88 static const char* kRealPlayerGroupName; |
91 static const char* kSilverlightGroupName; | 89 static const char* kSilverlightGroupName; |
92 static const char* kWindowsMediaPlayerGroupName; | 90 static const char* kWindowsMediaPlayerGroupName; |
93 | 91 |
94 PluginGroup(const PluginGroup& other); | 92 PluginGroup(const PluginGroup& other); |
95 | 93 |
96 ~PluginGroup(); | 94 ~PluginGroup(); |
97 | 95 |
98 PluginGroup& operator=(const PluginGroup& other); | 96 PluginGroup& operator=(const PluginGroup& other); |
99 | 97 |
100 // Configures the set of plugin name patterns for enabling and disabling | |
101 // plugins via enterprise configuration management. | |
102 static void SetPolicyEnforcedPluginPatterns( | |
103 const std::set<string16>& plugins_disabled, | |
104 const std::set<string16>& plugins_disabled_exceptions, | |
105 const std::set<string16>& plugins_enabled); | |
106 | |
107 // Tests whether |plugin_name| is disabled by policy. | |
108 static bool IsPluginNameDisabledByPolicy(const string16& plugin_name); | |
109 | |
110 // Tests whether |plugin_name| within the plugin group |group_name| is | |
111 // disabled by policy. | |
112 static bool IsPluginFileNameDisabledByPolicy(const string16& plugin_name, | |
113 const string16& group_name); | |
114 | |
115 // Tests whether |plugin_name| is enabled by policy. | |
116 static bool IsPluginNameEnabledByPolicy(const string16& plugin_name); | |
117 | |
118 // Returns true if the given plugin matches this group. | 98 // Returns true if the given plugin matches this group. |
119 bool Match(const webkit::WebPluginInfo& plugin) const; | 99 bool Match(const webkit::WebPluginInfo& plugin) const; |
120 | 100 |
121 // Adds the given plugin to this group. | 101 // Adds the given plugin to this group. |
122 void AddPlugin(const webkit::WebPluginInfo& plugin); | 102 void AddPlugin(const webkit::WebPluginInfo& plugin); |
123 | 103 |
124 // Removes a plugin from the group by its path. | 104 // Removes a plugin from the group by its path. |
125 bool RemovePlugin(const FilePath& filename); | 105 bool RemovePlugin(const FilePath& filename); |
126 | 106 |
127 // The two following functions enable/disable a plugin given its filename. The | |
128 // function returns true if the plugin could be enabled/disabled. Plugins | |
129 // might not get enabled/disabled if they are controlled by policy or are | |
130 // already in the wanted state. | |
131 bool EnablePlugin(const FilePath& filename); | |
132 bool DisablePlugin(const FilePath& filename); | |
133 | |
134 // Enables/disables this group. This enables/disables all plugins in the | |
135 // group. | |
136 bool EnableGroup(bool enable); | |
137 | |
138 // Checks whether the group should be disabled/enabled by a policy and puts | |
139 // it in the needed state. Updates all contained plugins too. | |
140 void EnforceGroupPolicy(); | |
141 | |
142 // Returns whether the plugin group is enabled or not. | |
143 bool Enabled() const { return enabled_; } | |
144 | |
145 // Returns a unique identifier for this group, if one is defined, or the empty | 107 // Returns a unique identifier for this group, if one is defined, or the empty |
146 // string otherwise. | 108 // string otherwise. |
147 const std::string& identifier() const { return identifier_; } | 109 const std::string& identifier() const { return identifier_; } |
148 | 110 |
149 // Sets a unique identifier for this group or if none is set an empty string. | 111 // Sets a unique identifier for this group or if none is set an empty string. |
150 void set_identifier(const std::string& identifier) { | 112 void set_identifier(const std::string& identifier) { |
151 identifier_ = identifier; | 113 identifier_ = identifier; |
152 } | 114 } |
153 | 115 |
154 // Returns this group's name, or the filename without extension if the name | 116 // Returns this group's name, or the filename without extension if the name |
155 // is empty. | 117 // is empty. |
156 string16 GetGroupName() const; | 118 string16 GetGroupName() const; |
157 | 119 |
158 // Returns all plugins added to the group. | |
159 const std::vector<webkit::WebPluginInfo>& web_plugins_info() const { | |
160 return web_plugin_infos_; | |
161 } | |
162 | |
163 // Checks whether a plugin exists in the group with the given path. | 120 // Checks whether a plugin exists in the group with the given path. |
164 bool ContainsPlugin(const FilePath& path) const; | 121 bool ContainsPlugin(const FilePath& path) const; |
165 | 122 |
166 // Returns the description of the highest-priority plug-in in the group. | |
167 const string16& description() const { return description_; } | |
168 | |
169 // Returns a DictionaryValue with data to display in the UI. | |
170 base::DictionaryValue* GetDataForUI() const; | |
171 | |
172 // Returns a DictionaryValue with data to save in the preferences. | |
173 base::DictionaryValue* GetSummary() const; | |
174 | |
175 // Returns the update URL. | 123 // Returns the update URL. |
176 std::string GetUpdateURL() const { return update_url_; } | 124 std::string GetUpdateURL() const { return update_url_; } |
177 | 125 |
178 // Returns true if this plugin group is whitelisted. | 126 // Returns true if this plugin group is whitelisted. |
179 bool IsWhitelisted() const; | 127 bool IsWhitelisted() const; |
180 | 128 |
181 // Returns true if the highest-priority plugin in this group has known | 129 // Returns true if |plugin| in this group has known security problems. |
182 // security problems. | 130 bool IsVulnerable(const WebPluginInfo& plugin) const; |
183 bool IsVulnerable() const; | |
184 | 131 |
185 // Returns true if this plug-in group always requires user authorization | 132 // Returns true if |plugin| in this plug-in group always requires user |
186 // to run. | 133 // authorization to run. |
187 bool RequiresAuthorization() const; | 134 bool RequiresAuthorization(const WebPluginInfo& plugin) const; |
188 | 135 |
189 // Check if the group has no plugins. Could happen after a reload if the plug- | 136 // Check if the group has no plugins. Could happen after a reload if the plug- |
190 // in has disappeared from the pc (or in the process of updating). | 137 // in has disappeared from the pc (or in the process of updating). |
191 bool IsEmpty() const; | 138 bool IsEmpty() const; |
192 | 139 |
193 // Parse a version string as used by a plug-in. This method is more lenient | 140 // Parse a version string as used by a plug-in. This method is more lenient |
194 // in accepting weird version strings than Version::GetFromString(). | 141 // in accepting weird version strings than Version::GetFromString(). |
195 static Version* CreateVersionFromString(const string16& version_string); | 142 static Version* CreateVersionFromString(const string16& version_string); |
196 | 143 |
197 std::vector<webkit::WebPluginInfo> web_plugin_infos() { | 144 const std::vector<webkit::WebPluginInfo>& web_plugin_infos() const { |
198 return web_plugin_infos_; | 145 return web_plugin_infos_; |
199 } | 146 } |
200 | 147 |
201 private: | 148 private: |
202 friend class PluginList; | 149 friend class PluginList; |
203 friend class MockPluginList; | 150 friend class MockPluginList; |
204 friend class PluginGroupTest; | 151 friend class PluginGroupTest; |
205 friend class ::PluginExceptionsTableModelTest; | 152 friend class ::PluginExceptionsTableModelTest; |
206 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); | 153 FRIEND_TEST_ALL_PREFIXES(PluginListTest, DisableOutdated); |
207 | 154 |
(...skipping 22 matching lines...) Expand all Loading... |
230 static bool IsPluginOutdated(const Version& plugin_version, | 177 static bool IsPluginOutdated(const Version& plugin_version, |
231 const VersionRange& version_range); | 178 const VersionRange& version_range); |
232 | 179 |
233 PluginGroup(const string16& group_name, | 180 PluginGroup(const string16& group_name, |
234 const string16& name_matcher, | 181 const string16& name_matcher, |
235 const std::string& update_url, | 182 const std::string& update_url, |
236 const std::string& identifier); | 183 const std::string& identifier); |
237 | 184 |
238 void InitFrom(const PluginGroup& other); | 185 void InitFrom(const PluginGroup& other); |
239 | 186 |
240 // Set the description and version for this plugin group from the | |
241 // given plug-in. | |
242 void UpdateDescriptionAndVersion(const webkit::WebPluginInfo& plugin); | |
243 | |
244 // Updates the active plugin in the group. The active plugin is the first | |
245 // enabled one, or if all plugins are disabled, simply the first one. | |
246 void UpdateActivePlugin(const webkit::WebPluginInfo& plugin); | |
247 | |
248 // Resets the group state to its default value (as if the group was empty). | |
249 // After calling this method, calling |UpdateActivePlugin| with all plugins | |
250 // in a row will correctly set the group state. | |
251 void ResetGroupState(); | |
252 | |
253 // Enables the plugin if not already enabled and if policy allows it to. | |
254 // Returns true on success. Does not update the group state. | |
255 static bool Enable(webkit::WebPluginInfo* plugin, int reason); | |
256 | |
257 // Disables the plugin if not already disabled and if policy allows it to. | |
258 // Returns true on success. Does not update the group state. | |
259 static bool Disable(webkit::WebPluginInfo* plugin, int reason); | |
260 | |
261 // Helper function to implement the functions above. | |
262 static bool SetPluginState(webkit::WebPluginInfo* plugin, | |
263 int new_reason, | |
264 bool state_changes); | |
265 | |
266 // Returns a non-const vector of all plugins in the group. This is only used | 187 // Returns a non-const vector of all plugins in the group. This is only used |
267 // by PluginList. | 188 // by PluginList. |
268 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { | 189 std::vector<webkit::WebPluginInfo>& GetPluginsContainer() { |
269 return web_plugin_infos_; | 190 return web_plugin_infos_; |
270 } | 191 } |
271 | 192 |
272 // Checks if |name| matches any of the patterns in |pattern_set|. | |
273 static bool IsStringMatchedInSet(const string16& name, | |
274 const std::set<string16>* pattern_set); | |
275 | |
276 static std::set<string16>* policy_disabled_plugin_patterns_; | |
277 static std::set<string16>* policy_disabled_plugin_exception_patterns_; | |
278 static std::set<string16>* policy_enabled_plugin_patterns_; | |
279 | |
280 std::string identifier_; | 193 std::string identifier_; |
281 string16 group_name_; | 194 string16 group_name_; |
282 string16 name_matcher_; | 195 string16 name_matcher_; |
283 string16 description_; | |
284 std::string update_url_; | 196 std::string update_url_; |
285 bool enabled_; | |
286 std::vector<VersionRange> version_ranges_; | 197 std::vector<VersionRange> version_ranges_; |
287 scoped_ptr<Version> version_; | |
288 std::vector<webkit::WebPluginInfo> web_plugin_infos_; | 198 std::vector<webkit::WebPluginInfo> web_plugin_infos_; |
289 }; | 199 }; |
290 | 200 |
291 } // namespace npapi | 201 } // namespace npapi |
292 } // namespace webkit | 202 } // namespace webkit |
293 | 203 |
294 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ | 204 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ |
OLD | NEW |