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 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 void AddPlugin(const WebPluginInfo& plugin); |
105 void AddPlugin(const WebPluginInfo& plugin, int position); | |
106 | 103 |
107 bool IsEmpty() const; | 104 // Removes a plugin from the group by its path. |
105 bool RemovePlugin(const FilePath& filename); | |
106 | |
107 // The two following functions enable/disable a plugin given its filename. The | |
108 // function returns true if the plugin could be enabled/disabled. Plugins | |
109 // might not get enabled/disabled if they are controlled by policy or are | |
110 // already in the wanted state. | |
111 bool EnablePlugin(const FilePath& filename); | |
112 bool DisablePlugin(const FilePath& filename); | |
108 | 113 |
109 // Enables/disables this group. This enables/disables all plugins in the | 114 // Enables/disables this group. This enables/disables all plugins in the |
110 // group. | 115 // group. |
111 void Enable(bool enable); | 116 bool EnableGroup(bool enable); |
117 | |
118 // Checks whether the group should be disabled/enabled by a policy and puts | |
119 // it in the needed state. Updates all contained plugins too. | |
120 void EnforceGroupPolicy(); | |
112 | 121 |
113 // Returns whether the plugin group is enabled or not. | 122 // Returns whether the plugin group is enabled or not. |
114 bool Enabled() const { return enabled_; } | 123 bool Enabled() const { return enabled_; } |
115 | 124 |
116 // Returns a unique identifier for this group, if one is defined, or the empty | 125 // Returns a unique identifier for this group, if one is defined, or the empty |
117 // string otherwise. | 126 // string otherwise. |
118 const std::string& identifier() const { return identifier_; } | 127 const std::string& identifier() const { return identifier_; } |
119 | 128 |
129 // Returns a unique identifier for this group, if one is defined, or the empty | |
130 // string otherwise. | |
131 std::string& identifier() { return identifier_; } | |
jam
2011/01/20 18:22:34
our style guide disallows non-const references. f
pastarmovj
2011/01/20 22:59:49
Done.
| |
132 | |
120 // Returns this group's name, or the filename without extension if the name | 133 // Returns this group's name, or the filename without extension if the name |
121 // is empty. | 134 // is empty. |
122 string16 GetGroupName() const; | 135 string16 GetGroupName() const; |
123 | 136 |
137 // Returns all plugins added to the group. | |
138 std::vector<WebPluginInfo>& web_info_plugins(); | |
jam
2011/01/20 18:22:34
the non const version seems dangereous to have as
pastarmovj
2011/01/20 22:59:49
Done. Sorry for the word swap there :(
| |
139 const std::vector<WebPluginInfo>& web_info_plugins() const; | |
140 | |
141 // Checks whether a plugin exists in the group with the given path. | |
142 bool ContainsPlugin(const FilePath& path) const; | |
143 | |
124 // Returns the description of the highest-priority plug-in in the group. | 144 // Returns the description of the highest-priority plug-in in the group. |
125 const string16& description() const { return description_; } | 145 const string16& description() const { return description_; } |
126 | 146 |
127 // Returns a DictionaryValue with data to display in the UI. | 147 // Returns a DictionaryValue with data to display in the UI. |
128 DictionaryValue* GetDataForUI() const; | 148 DictionaryValue* GetDataForUI() const; |
129 | 149 |
130 // Returns a DictionaryValue with data to save in the preferences. | 150 // Returns a DictionaryValue with data to save in the preferences. |
131 DictionaryValue* GetSummary() const; | 151 DictionaryValue* GetSummary() const; |
132 | 152 |
133 // Returns the update URL. | 153 // Returns the update URL. |
134 std::string GetUpdateURL() const { return update_url_; } | 154 std::string GetUpdateURL() const { return update_url_; } |
135 | 155 |
136 // Returns true if the highest-priority plugin in this group has known | 156 // Returns true if the highest-priority plugin in this group has known |
137 // security problems. | 157 // security problems. |
138 bool IsVulnerable() const; | 158 bool IsVulnerable() const; |
139 | 159 |
160 // Check if the group has no plugins. Could happen after a reload if the plug- | |
161 // in has disappeared from the pc (or in the process of updating). | |
162 bool IsEmpty() const; | |
163 | |
140 // Disables all plugins in this group that are older than the | 164 // Disables all plugins in this group that are older than the |
141 // minimum version. | 165 // minimum version. |
142 void DisableOutdatedPlugins(); | 166 void DisableOutdatedPlugins(); |
143 | 167 |
144 // Parse a version string as used by a plug-in. This method is more lenient | 168 // Parse a version string as used by a plug-in. This method is more lenient |
145 // in accepting weird version strings than Version::GetFromString(). | 169 // in accepting weird version strings than Version::GetFromString(). |
146 static Version* CreateVersionFromString(const string16& version_string); | 170 static Version* CreateVersionFromString(const string16& version_string); |
147 | 171 |
148 private: | 172 private: |
149 typedef std::map<std::string, PluginGroup*> PluginMap; | |
150 | |
151 friend class PluginList; | 173 friend class PluginList; |
174 friend class plugin_test_internal::PluginListWithoutFileIO; | |
152 friend class PluginGroupTest; | 175 friend class PluginGroupTest; |
153 friend class ::TableModelArrayControllerTest; | 176 friend class ::TableModelArrayControllerTest; |
154 friend class ::PluginExceptionsTableModelTest; | 177 friend class ::PluginExceptionsTableModelTest; |
155 | 178 |
156 // Generates the (short) identifier string for the given plugin. | 179 // Generates the (short) identifier string for the given plugin. |
157 static std::string GetIdentifier(const WebPluginInfo& wpi); | 180 static std::string GetIdentifier(const WebPluginInfo& wpi); |
158 | 181 |
159 // Generates the long identifier (based on the full file path) for the given | 182 // 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. | 183 // plugin, to be called when the short identifier is not unique. |
161 static std::string GetLongIdentifier(const WebPluginInfo& wpi); | 184 static std::string GetLongIdentifier(const WebPluginInfo& wpi); |
(...skipping 24 matching lines...) Expand all Loading... | |
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_ |
OLD | NEW |