Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: webkit/plugins/npapi/plugin_group.h

Issue 5699005: Policy: Re-enabled plugin still disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit tests. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
jam 2011/01/15 00:51:34 nit: why is this needed?
pastarmovj 2011/01/18 18:30:39 I need the Definition of WebPluginInfo in several
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Removes a plugin from the group by its path.
107 bool RemovePlugin(const FilePath& filename);
108
109 // The two following functions enable/disable a plugin given its filename. The
110 // function returns true if the plugin could be enabled/disabled. Plugins
111 // might not get enabled/disabled if they are controlled by policy or are
112 // already in the wanted state.
113 bool EnablePlugin(const FilePath& filename);
114 bool DisablePlugin(const FilePath& filename);
108 115
109 // Enables/disables this group. This enables/disables all plugins in the 116 // Enables/disables this group. This enables/disables all plugins in the
110 // group. 117 // group.
111 void Enable(bool enable); 118 bool EnableGroup(bool enable);
119
120 // Enables/disables this group. This enables/disables all plugins in the
121 // group.
122 void EnforceGroupPolicy();
112 123
113 // Returns whether the plugin group is enabled or not. 124 // Returns whether the plugin group is enabled or not.
114 bool Enabled() const { return enabled_; } 125 bool Enabled() const { return enabled_; }
115 126
116 // Returns a unique identifier for this group, if one is defined, or the empty 127 // Returns a unique identifier for this group, if one is defined, or the empty
117 // string otherwise. 128 // string otherwise.
118 const std::string& identifier() const { return identifier_; } 129 const std::string& identifier() const { return identifier_; }
119 130
120 // Returns this group's name, or the filename without extension if the name 131 // Returns this group's name, or the filename without extension if the name
121 // is empty. 132 // is empty.
122 string16 GetGroupName() const; 133 string16 GetGroupName() const;
123 134
135 const std::vector<WebPluginInfo>& GetPlugins() const;
136
137 bool ContainsPlugin(const FilePath& path) const;
138
124 // Returns the description of the highest-priority plug-in in the group. 139 // Returns the description of the highest-priority plug-in in the group.
125 const string16& description() const { return description_; } 140 const string16& description() const { return description_; }
126 141
127 // Returns a DictionaryValue with data to display in the UI. 142 // Returns a DictionaryValue with data to display in the UI.
128 DictionaryValue* GetDataForUI() const; 143 DictionaryValue* GetDataForUI() const;
129 144
130 // Returns a DictionaryValue with data to save in the preferences. 145 // Returns a DictionaryValue with data to save in the preferences.
131 DictionaryValue* GetSummary() const; 146 DictionaryValue* GetSummary() const;
132 147
133 // Returns the update URL. 148 // Returns the update URL.
134 std::string GetUpdateURL() const { return update_url_; } 149 std::string GetUpdateURL() const { return update_url_; }
135 150
136 // Returns true if the highest-priority plugin in this group has known 151 // Returns true if the highest-priority plugin in this group has known
137 // security problems. 152 // security problems.
138 bool IsVulnerable() const; 153 bool IsVulnerable() const;
139 154
155 // Check if the group has no plugins or only placeholder plugins.
jam 2011/01/15 00:51:34 I thought we're not adding the concept of placehol
pastarmovj 2011/01/18 18:30:39 I forgot to update the comment there. There are no
jam 2011/01/18 20:26:00 ok, so should I just wait for that before doing an
156 bool IsEmpty() const;
157
140 // Disables all plugins in this group that are older than the 158 // Disables all plugins in this group that are older than the
141 // minimum version. 159 // minimum version.
142 void DisableOutdatedPlugins(); 160 void DisableOutdatedPlugins();
143 161
144 // Parse a version string as used by a plug-in. This method is more lenient 162 // Parse a version string as used by a plug-in. This method is more lenient
145 // in accepting weird version strings than Version::GetFromString(). 163 // in accepting weird version strings than Version::GetFromString().
146 static Version* CreateVersionFromString(const string16& version_string); 164 static Version* CreateVersionFromString(const string16& version_string);
147 165
148 private: 166 private:
149 typedef std::map<std::string, PluginGroup*> PluginMap; 167 typedef std::map<std::string, PluginGroup*> PluginMap;
150 168
151 friend class PluginList; 169 friend class PluginList;
170 friend class plugin_test_internal::PluginListWithoutFileIO;
152 friend class PluginGroupTest; 171 friend class PluginGroupTest;
153 friend class ::TableModelArrayControllerTest; 172 friend class ::TableModelArrayControllerTest;
154 friend class ::PluginExceptionsTableModelTest; 173 friend class ::PluginExceptionsTableModelTest;
155 174
156 // Generates the (short) identifier string for the given plugin. 175 // Generates the (short) identifier string for the given plugin.
157 static std::string GetIdentifier(const WebPluginInfo& wpi); 176 static std::string GetIdentifier(const WebPluginInfo& wpi);
158 177
159 // Generates the long identifier (based on the full file path) for the given 178 // 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. 179 // plugin, to be called when the short identifier is not unique.
161 static std::string GetLongIdentifier(const WebPluginInfo& wpi); 180 static std::string GetLongIdentifier(const WebPluginInfo& wpi);
162 181
163 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes 182 // Creates a PluginGroup from a PluginGroupDefinition. The caller takes
164 // ownership of the created PluginGroup. 183 // ownership of the created PluginGroup.
165 static PluginGroup* FromPluginGroupDefinition( 184 static PluginGroup* FromPluginGroupDefinition(
166 const PluginGroupDefinition& definition); 185 const PluginGroupDefinition& definition);
167 186
168 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of 187 // Creates a PluginGroup from a WebPluginInfo. The caller takes ownership of
169 // the created PluginGroup. 188 // the created PluginGroup.
170 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi); 189 static PluginGroup* FromWebPluginInfo(const WebPluginInfo& wpi);
171 190
191 // Creates an empty PluginGroup from a given name. The caller takes
192 // ownership of the created PluginGroup.
193 static PluginGroup* CreateEmptyGroup(const string16& name);
jam 2011/01/15 00:51:34 ditto
pastarmovj 2011/01/18 18:30:39 Removed.
194
172 // Returns |true| if |version| is contained in [low, high) of |range|. 195 // Returns |true| if |version| is contained in [low, high) of |range|.
173 static bool IsVersionInRange(const Version& version, 196 static bool IsVersionInRange(const Version& version,
174 const VersionRange& range); 197 const VersionRange& range);
175 198
176 // Returns |true| iff |plugin_version| is both contained in |version_range| 199 // Returns |true| iff |plugin_version| is both contained in |version_range|
177 // and declared outdated (== vulnerable) by it. 200 // and declared outdated (== vulnerable) by it.
178 static bool IsPluginOutdated(const Version& plugin_version, 201 static bool IsPluginOutdated(const Version& plugin_version,
179 const VersionRange& version_range); 202 const VersionRange& version_range);
180 203
181 PluginGroup(const string16& group_name, 204 PluginGroup(const string16& group_name,
182 const string16& name_matcher, 205 const string16& name_matcher,
183 const std::string& update_url, 206 const std::string& update_url,
184 const std::string& identifier); 207 const std::string& identifier);
185 208
186 void InitFrom(const PluginGroup& other); 209 void InitFrom(const PluginGroup& other);
187 210
188 // Set the description and version for this plugin group from the 211 // Set the description and version for this plugin group from the
189 // given plug-in. 212 // given plug-in.
190 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin); 213 void UpdateDescriptionAndVersion(const WebPluginInfo& plugin);
191 214
192 // Updates the active plugin in the group. The active plugin is the first 215 // 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. 216 // enabled one, or if all plugins are disabled, simply the first one.
194 void UpdateActivePlugin(const WebPluginInfo& plugin); 217 void UpdateActivePlugin(const WebPluginInfo& plugin);
195 218
219 // Refreshes the enabled flag based on the state of its plugins.
220 void RefreshEnabledState();
221
222 // Enables the plugin if not already enabled and if policy allows it to.
223 // Returns true on success.
224 static bool Enable(WebPluginInfo* plugin, int reason);
225
226 // Disables the plugin if not already disabled and if policy allows it to.
227 // Returns true on success.
228 static bool Disable(WebPluginInfo* plugin, int reason);
229
196 static std::set<string16>* policy_disabled_plugin_patterns_; 230 static std::set<string16>* policy_disabled_plugin_patterns_;
197 231
198 std::string identifier_; 232 std::string identifier_;
199 string16 group_name_; 233 string16 group_name_;
200 string16 name_matcher_; 234 string16 name_matcher_;
201 string16 description_; 235 string16 description_;
202 std::string update_url_; 236 std::string update_url_;
203 bool enabled_; 237 bool enabled_;
204 std::vector<VersionRange> version_ranges_; 238 std::vector<VersionRange> version_ranges_;
205 scoped_ptr<Version> version_; 239 scoped_ptr<Version> version_;
206 std::vector<WebPluginInfo> web_plugin_infos_; 240 std::vector<WebPluginInfo> web_plugin_infos_;
207 std::vector<int> web_plugin_positions_;
208 }; 241 };
209 242
210 } // namespace npapi 243 } // namespace npapi
211 } // namespace webkit 244 } // namespace webkit
212 245
213 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_ 246 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_GROUP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698