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_LIST_H_ | 5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 // Get plugin info by plugin path (including disabled plugins). Returns true | 144 // Get plugin info by plugin path (including disabled plugins). Returns true |
145 // if the plugin is found and WebPluginInfo has been filled in |info|. | 145 // if the plugin is found and WebPluginInfo has been filled in |info|. |
146 bool GetPluginInfoByPath(const FilePath& plugin_path, | 146 bool GetPluginInfoByPath(const FilePath& plugin_path, |
147 webkit::WebPluginInfo* info); | 147 webkit::WebPluginInfo* info); |
148 | 148 |
149 // Populates the given vector with all available plugin groups. | 149 // Populates the given vector with all available plugin groups. |
150 void GetPluginGroups(bool load_if_necessary, | 150 void GetPluginGroups(bool load_if_necessary, |
151 std::vector<PluginGroup>* plugin_groups); | 151 std::vector<PluginGroup>* plugin_groups); |
152 | 152 |
153 // Returns a copy of the PluginGroup corresponding to the given WebPluginInfo. | 153 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no |
154 // If no such group exists, it is created and added to the cache. | 154 // such group exists, it is created and added to the cache. |
155 // The caller takes ownership of the returned PluginGroup. | 155 // Beware: when calling this from the Browser process, the group that the |
156 PluginGroup* GetPluginGroup(const webkit::WebPluginInfo& web_plugin_info); | 156 // returned pointer points to might disappear suddenly. This happens when |
| 157 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
| 158 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
| 159 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
| 160 // responsibility to make sure this doesn't happen. |
| 161 const PluginGroup* GetPluginGroup( |
| 162 const webkit::WebPluginInfo& web_plugin_info); |
157 | 163 |
158 // Returns the name of the PluginGroup with the given identifier. | 164 // Returns the name of the PluginGroup with the given identifier. |
159 // If no such group exists, an empty string is returned. | 165 // If no such group exists, an empty string is returned. |
160 string16 GetPluginGroupName(const std::string& identifier); | 166 string16 GetPluginGroupName(const std::string& identifier); |
161 | 167 |
162 // Returns the identifier string of the PluginGroup corresponding to the given | 168 // Returns the identifier string of the PluginGroup corresponding to the given |
163 // WebPluginInfo. If no such group exists, it is created and added to the | 169 // WebPluginInfo. If no such group exists, it is created and added to the |
164 // cache. | 170 // cache. |
165 std::string GetPluginGroupIdentifier( | 171 std::string GetPluginGroupIdentifier( |
166 const webkit::WebPluginInfo& web_plugin_info); | 172 const webkit::WebPluginInfo& web_plugin_info); |
167 | 173 |
168 // Load a specific plugin with full path. | 174 // Load a specific plugin with full path. |
169 void LoadPlugin(const FilePath& filename, | 175 void LoadPlugin(const FilePath& filename, |
170 ScopedVector<PluginGroup>* plugin_groups); | 176 ScopedVector<PluginGroup>* plugin_groups); |
171 | 177 |
| 178 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
| 179 // currently in the plugin list was actually enabled as a result; regardless |
| 180 // of return value, if a plugin is found in the future with the given name, it |
| 181 // will be enabled. |
| 182 bool EnablePlugin(const FilePath& filename); |
| 183 |
| 184 // Disable a specific plugin, specified by path. Returns |true| iff a plugin |
| 185 // currently in the plugin list was actually disabled as a result; regardless |
| 186 // of return value, if a plugin is found in the future with the given name, it |
| 187 // will be disabled. |
| 188 bool DisablePlugin(const FilePath& filename); |
| 189 |
| 190 // Enable/disable a plugin group, specified by group_name. Returns |true| iff |
| 191 // a plugin currently in the plugin list was actually enabled/disabled as a |
| 192 // result; regardless of return value, if a plugin is found in the future with |
| 193 // the given name, it will be enabled/disabled. |
| 194 bool EnableGroup(bool enable, const string16& name); |
| 195 |
172 virtual ~PluginList(); | 196 virtual ~PluginList(); |
173 | 197 |
174 protected: | 198 protected: |
175 // This constructor is used in unit tests to override the platform-dependent | 199 // This constructor is used in unit tests to override the platform-dependent |
176 // real-world plugin group definitions with custom ones. | 200 // real-world plugin group definitions with custom ones. |
177 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); | 201 PluginList(const PluginGroupDefinition* definitions, size_t num_definitions); |
178 | 202 |
179 // Adds the given WebPluginInfo to its corresponding group, creating it if | 203 // Adds the given WebPluginInfo to its corresponding group, creating it if |
180 // necessary, and returns the group. | 204 // necessary, and returns the group. |
181 // Callers need to protect calls to this method by a lock themselves. | 205 // Callers need to protect calls to this method by a lock themselves. |
(...skipping 27 matching lines...) Expand all Loading... |
209 void LoadPluginsFromDir(const FilePath& path, | 233 void LoadPluginsFromDir(const FilePath& path, |
210 ScopedVector<PluginGroup>* plugin_groups, | 234 ScopedVector<PluginGroup>* plugin_groups, |
211 std::set<FilePath>* visited_plugins); | 235 std::set<FilePath>* visited_plugins); |
212 | 236 |
213 // Returns true if we should load the given plugin, or false otherwise. | 237 // Returns true if we should load the given plugin, or false otherwise. |
214 // plugins is the list of plugins we have crawled in the current plugin | 238 // plugins is the list of plugins we have crawled in the current plugin |
215 // loading run. | 239 // loading run. |
216 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, | 240 bool ShouldLoadPlugin(const webkit::WebPluginInfo& info, |
217 ScopedVector<PluginGroup>* plugins); | 241 ScopedVector<PluginGroup>* plugins); |
218 | 242 |
| 243 // Return whether a plug-in group with the given name should be disabled, |
| 244 // either because it already is on the list of disabled groups, or because it |
| 245 // is blacklisted by a policy. In the latter case, add the plugin group to the |
| 246 // list of disabled groups as well. |
| 247 bool ShouldDisableGroup(const string16& group_name); |
| 248 |
219 // Returns true if the plugin supports |mime_type|. |mime_type| should be all | 249 // Returns true if the plugin supports |mime_type|. |mime_type| should be all |
220 // lower case. | 250 // lower case. |
221 bool SupportsType(const webkit::WebPluginInfo& plugin, | 251 bool SupportsType(const webkit::WebPluginInfo& plugin, |
222 const std::string& mime_type, | 252 const std::string& mime_type, |
223 bool allow_wildcard); | 253 bool allow_wildcard); |
224 | 254 |
225 // Returns true if the given plugin supports a given file extension. | 255 // Returns true if the given plugin supports a given file extension. |
226 // |extension| should be all lower case. If |mime_type| is not NULL, it will | 256 // |extension| should be all lower case. If |mime_type| is not NULL, it will |
227 // be set to the MIME type if found. The MIME type which corresponds to the | 257 // be set to the MIME type if found. The MIME type which corresponds to the |
228 // extension is optionally returned back. | 258 // extension is optionally returned back. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // Holds information about internal plugins. | 301 // Holds information about internal plugins. |
272 std::vector<InternalPlugin> internal_plugins_; | 302 std::vector<InternalPlugin> internal_plugins_; |
273 | 303 |
274 // Hardcoded plugin group definitions. | 304 // Hardcoded plugin group definitions. |
275 const PluginGroupDefinition* const group_definitions_; | 305 const PluginGroupDefinition* const group_definitions_; |
276 const size_t num_group_definitions_; | 306 const size_t num_group_definitions_; |
277 | 307 |
278 // Holds the currently available plugin groups. | 308 // Holds the currently available plugin groups. |
279 ScopedVector<PluginGroup> plugin_groups_; | 309 ScopedVector<PluginGroup> plugin_groups_; |
280 | 310 |
| 311 // The set of plugins that have been scheduled for disabling once they get |
| 312 // loaded. This list is used in LoadPlugins and pruned after it. Contains |
| 313 // plugins that were either disabled by the user (prefs are loaded before |
| 314 // plugins) or disabled by a policy. |
| 315 std::set<FilePath> plugins_to_disable_; |
| 316 // Equivalent to the |plugins_to_disable_| this is the set of groups |
| 317 // scheduled for disabling once they appear. This list is never completely |
| 318 // pruned but all groups that do get created are removed from it. New groups |
| 319 // might get added if they should be pruned because of plugins getting removed |
| 320 // for example. |
| 321 std::set<string16> groups_to_disable_; |
| 322 |
281 // Need synchronization for the above members since this object can be | 323 // Need synchronization for the above members since this object can be |
282 // accessed on multiple threads. | 324 // accessed on multiple threads. |
283 base::Lock lock_; | 325 base::Lock lock_; |
284 | 326 |
285 // Set to true if the default plugin is enabled. | 327 // Set to true if the default plugin is enabled. |
286 bool default_plugin_enabled_; | 328 bool default_plugin_enabled_; |
287 | 329 |
288 DISALLOW_COPY_AND_ASSIGN(PluginList); | 330 DISALLOW_COPY_AND_ASSIGN(PluginList); |
289 }; | 331 }; |
290 | 332 |
291 } // namespace npapi | 333 } // namespace npapi |
292 } // namespace webkit | 334 } // namespace webkit |
293 | 335 |
294 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ | 336 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_LIST_H_ |
OLD | NEW |