| 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_GLUE_PLUGINS_PLUGIN_LIST_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <set> | 8 #include <set> |
| 10 #include <string> | 9 #include <string> |
| 11 #include <vector> | 10 #include <vector> |
| 12 #include <set> | |
| 13 | 11 |
| 14 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 15 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 16 #include "base/linked_ptr.h" | 14 #include "base/linked_ptr.h" |
| 17 #include "base/lock.h" | 15 #include "base/lock.h" |
| 18 #include "third_party/npapi/bindings/nphostapi.h" | 16 #include "third_party/npapi/bindings/nphostapi.h" |
| 19 #include "webkit/glue/plugins/plugin_group.h" | 17 #include "webkit/glue/plugins/plugin_group.h" |
| 20 #include "webkit/glue/plugins/webplugininfo.h" | 18 #include "webkit/glue/plugins/webplugininfo.h" |
| 21 | 19 |
| 22 class GURL; | 20 class GURL; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // This object is thread safe. | 71 // This object is thread safe. |
| 74 class PluginList { | 72 class PluginList { |
| 75 public: | 73 public: |
| 76 // Gets the one instance of the PluginList. | 74 // Gets the one instance of the PluginList. |
| 77 static PluginList* Singleton(); | 75 static PluginList* Singleton(); |
| 78 | 76 |
| 79 // Returns true if we're in debug-plugin-loading mode. This is controlled | 77 // Returns true if we're in debug-plugin-loading mode. This is controlled |
| 80 // by a command line switch. | 78 // by a command line switch. |
| 81 static bool DebugPluginLoading(); | 79 static bool DebugPluginLoading(); |
| 82 | 80 |
| 81 static const PluginGroupDefinition* GetPluginGroupDefinitions(); |
| 82 static size_t GetPluginGroupDefinitionsSize(); |
| 83 |
| 83 // Returns true iff the plugin list has been loaded already. | 84 // Returns true iff the plugin list has been loaded already. |
| 84 bool PluginsLoaded(); | 85 bool PluginsLoaded(); |
| 85 | 86 |
| 86 // Cause the plugin list to refresh next time they are accessed, regardless | 87 // Cause the plugin list to refresh next time they are accessed, regardless |
| 87 // of whether they are already loaded. | 88 // of whether they are already loaded. |
| 88 void RefreshPlugins(); | 89 void RefreshPlugins(); |
| 89 | 90 |
| 90 // Add/Remove an extra plugin to load when we actually do the loading. Must | 91 // Add/Remove an extra plugin to load when we actually do the loading. Must |
| 91 // be called before the plugins have been loaded. | 92 // be called before the plugins have been loaded. |
| 92 void AddExtraPluginPath(const FilePath& plugin_path); | 93 void AddExtraPluginPath(const FilePath& plugin_path); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 const std::string& mime_type, | 151 const std::string& mime_type, |
| 151 bool allow_wildcard, | 152 bool allow_wildcard, |
| 152 WebPluginInfo* info, | 153 WebPluginInfo* info, |
| 153 std::string* actual_mime_type); | 154 std::string* actual_mime_type); |
| 154 | 155 |
| 155 // Get plugin info by plugin path (including disabled plugins). Returns true | 156 // Get plugin info by plugin path (including disabled plugins). Returns true |
| 156 // if the plugin is found and WebPluginInfo has been filled in |info|. | 157 // if the plugin is found and WebPluginInfo has been filled in |info|. |
| 157 bool GetPluginInfoByPath(const FilePath& plugin_path, | 158 bool GetPluginInfoByPath(const FilePath& plugin_path, |
| 158 WebPluginInfo* info); | 159 WebPluginInfo* info); |
| 159 | 160 |
| 160 typedef std::map<std::string, linked_ptr<PluginGroup> > PluginMap; | 161 // Populates the given vector with all available plugin groups. |
| 162 void GetPluginGroups(bool load_if_necessary, |
| 163 std::vector<PluginGroup>* plugin_groups); |
| 161 | 164 |
| 162 // Fill the map from identifier to plugin group for all plugin groups. If | 165 // Returns the PluginGroup corresponding to the given WebPluginInfo. If no |
| 163 // |load_if_necessary| is set, the plugins will be loaded if they haven't | 166 // such group exists, it is created and added to the cache. |
| 164 // already been loaded, or if Refresh() has been called in the meantime; | 167 // Beware: when calling this from the Browser process, the group that the |
| 165 // otherwise a possibly empty or stale list may be returned. | 168 // returned pointer points to might disappear suddenly. This happens when |
| 166 void GetPluginGroups(bool load_if_necessary, PluginMap* plugin_groups); | 169 // |RefreshPlugins()| is called and then |LoadPlugins()| is triggered by a |
| 170 // call to |GetPlugins()|, |GetEnabledPlugins()|, |GetPluginInfoArray()|, |
| 171 // |GetPluginInfoByPath()|, or |GetPluginGroups(true, _)|. It is the caller's |
| 172 // responsibility to make sure this doesn't happen. |
| 173 const PluginGroup* GetPluginGroup(const WebPluginInfo& web_plugin_info); |
| 174 |
| 175 // Returns the name of the PluginGroup with the given identifier. |
| 176 // If no such group exists, an empty string is returned. |
| 177 string16 GetPluginGroupName(std::string identifier); |
| 178 |
| 179 // Returns the identifier string of the PluginGroup corresponding to the given |
| 180 // WebPluginInfo. If no such group exists, it is created and added to the |
| 181 // cache. |
| 182 std::string GetPluginGroupIdentifier(const WebPluginInfo& web_plugin_info); |
| 167 | 183 |
| 168 // Load a specific plugin with full path. | 184 // Load a specific plugin with full path. |
| 169 void LoadPlugin(const FilePath& filename, | 185 void LoadPlugin(const FilePath& filename, |
| 170 std::vector<WebPluginInfo>* plugins); | 186 std::vector<WebPluginInfo>* plugins); |
| 171 | 187 |
| 172 // Enable a specific plugin, specified by path. Returns |true| iff a plugin | 188 // Enable a specific plugin, specified by path. Returns |true| iff a plugin |
| 173 // currently in the plugin list was actually enabled as a result; regardless | 189 // currently in the plugin list was actually enabled as a result; regardless |
| 174 // of return value, if a plugin is found in the future with the given name, it | 190 // of return value, if a plugin is found in the future with the given name, it |
| 175 // will be enabled. Note that plugins are enabled by default as far as | 191 // will be enabled. Note that plugins are enabled by default as far as |
| 176 // |PluginList| is concerned. | 192 // |PluginList| is concerned. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 191 | 207 |
| 192 // Disable all plugins groups that are known to be outdated, according to | 208 // Disable all plugins groups that are known to be outdated, according to |
| 193 // the information hardcoded in PluginGroup, to make sure that they can't | 209 // the information hardcoded in PluginGroup, to make sure that they can't |
| 194 // be loaded on a web page and instead show a UI to update to the latest | 210 // be loaded on a web page and instead show a UI to update to the latest |
| 195 // version. | 211 // version. |
| 196 void DisableOutdatedPluginGroups(); | 212 void DisableOutdatedPluginGroups(); |
| 197 | 213 |
| 198 ~PluginList(); | 214 ~PluginList(); |
| 199 | 215 |
| 200 private: | 216 private: |
| 217 FRIEND_TEST_ALL_PREFIXES(PluginGroupTest, PluginGroupDefinition); |
| 218 |
| 201 // Constructors are private for singletons | 219 // Constructors are private for singletons |
| 202 PluginList(); | 220 PluginList(); |
| 203 | 221 |
| 222 // Creates PluginGroups for the static group definitions, and adds them to |
| 223 // the PluginGroup cache of this PluginList. |
| 224 void AddHardcodedPluginGroups(); |
| 225 |
| 226 // Adds the given WebPluginInfo to its corresponding group, creating it if |
| 227 // necessary, and returns the group. |
| 228 // Callers need to protect calls to this method by a lock themselves. |
| 229 PluginGroup* AddToPluginGroups(const WebPluginInfo& web_plugin_info); |
| 230 |
| 204 // Load all plugins from the default plugins directory | 231 // Load all plugins from the default plugins directory |
| 205 void LoadPlugins(bool refresh); | 232 void LoadPlugins(bool refresh); |
| 206 | 233 |
| 207 // Load all plugins from a specific directory. | 234 // Load all plugins from a specific directory. |
| 208 // |plugins| is updated with loaded plugin information. | 235 // |plugins| is updated with loaded plugin information. |
| 209 // |visited_plugins| is updated with paths to all plugins that were considered | 236 // |visited_plugins| is updated with paths to all plugins that were considered |
| 210 // (including those we didn't load) | 237 // (including those we didn't load) |
| 211 void LoadPluginsFromDir(const FilePath& path, | 238 void LoadPluginsFromDir(const FilePath& path, |
| 212 std::vector<WebPluginInfo>* plugins, | 239 std::vector<WebPluginInfo>* plugins, |
| 213 std::set<FilePath>* visited_plugins); | 240 std::set<FilePath>* visited_plugins); |
| 214 | 241 |
| 215 // Returns true if we should load the given plugin, or false otherwise. | 242 // Returns true if we should load the given plugin, or false otherwise. |
| 216 // plugins is the list of plugins we have crawled in the current plugin | 243 // plugins is the list of plugins we have crawled in the current plugin |
| 217 // loading run. | 244 // loading run. |
| 218 bool ShouldLoadPlugin(const WebPluginInfo& info, | 245 bool ShouldLoadPlugin(const WebPluginInfo& info, |
| 219 std::vector<WebPluginInfo>* plugins); | 246 std::vector<WebPluginInfo>* plugins); |
| 220 | 247 |
| 221 // Return whether a plug-in group with the given name should be disabled, | 248 // Return whether a plug-in group with the given name should be disabled, |
| 222 // either because it already is on the list of disabled groups, or because it | 249 // either because it already is on the list of disabled groups, or because it |
| 223 // is blacklisted by a policy. In the latter case, add the plugin group to the | 250 // is blacklisted by a policy. In the latter case, add the plugin group to the |
| 224 // list of disabled groups as well. | 251 // list of disabled groups as well. |
| 225 bool ShouldDisableGroup(const string16& group_name); | 252 bool ShouldDisableGroup(const string16& group_name); |
| 226 | 253 |
| 227 // Like GetPluginGroups above, but works on a given vector of plugins. | |
| 228 static void GetPluginGroups(const std::vector<WebPluginInfo>* plugins, | |
| 229 PluginMap* plugin_groups); | |
| 230 | |
| 231 // Returns true if the given WebPluginInfo supports "mime-type". | 254 // Returns true if the given WebPluginInfo supports "mime-type". |
| 232 // mime_type should be all lower case. | 255 // mime_type should be all lower case. |
| 233 static bool SupportsType(const WebPluginInfo& info, | 256 static bool SupportsType(const WebPluginInfo& info, |
| 234 const std::string &mime_type, | 257 const std::string &mime_type, |
| 235 bool allow_wildcard); | 258 bool allow_wildcard); |
| 236 | 259 |
| 237 // Returns true if the given WebPluginInfo supports a given file extension. | 260 // Returns true if the given WebPluginInfo supports a given file extension. |
| 238 // extension should be all lower case. | 261 // extension should be all lower case. |
| 239 // If mime_type is not NULL, it will be set to the mime type if found. | 262 // If mime_type is not NULL, it will be set to the mime type if found. |
| 240 // The mime type which corresponds to the extension is optionally returned | 263 // The mime type which corresponds to the extension is optionally returned |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 307 |
| 285 // Extra plugin directories that we want to search when loading. | 308 // Extra plugin directories that we want to search when loading. |
| 286 std::vector<FilePath> extra_plugin_dirs_; | 309 std::vector<FilePath> extra_plugin_dirs_; |
| 287 | 310 |
| 288 // Holds information about internal plugins. | 311 // Holds information about internal plugins. |
| 289 std::vector<PluginVersionInfo> internal_plugins_; | 312 std::vector<PluginVersionInfo> internal_plugins_; |
| 290 | 313 |
| 291 // Path names of plugins to disable (the default is to enable them all). | 314 // Path names of plugins to disable (the default is to enable them all). |
| 292 std::set<FilePath> disabled_plugins_; | 315 std::set<FilePath> disabled_plugins_; |
| 293 | 316 |
| 294 // Group names disable (the default is to enable them all). | 317 // Group names to disable (the default is to enable them all). |
| 295 std::set<string16> disabled_groups_; | 318 std::set<string16> disabled_groups_; |
| 296 | 319 |
| 297 bool disable_outdated_plugins_; | 320 bool disable_outdated_plugins_; |
| 298 | 321 |
| 322 // Holds the currently available plugin groups. |
| 323 PluginGroup::PluginMap plugin_groups_; |
| 324 |
| 325 int next_priority_; |
| 326 |
| 299 // Need synchronization for the above members since this object can be | 327 // Need synchronization for the above members since this object can be |
| 300 // accessed on multiple threads. | 328 // accessed on multiple threads. |
| 301 Lock lock_; | 329 Lock lock_; |
| 302 | 330 |
| 303 friend struct base::DefaultLazyInstanceTraits<PluginList>; | 331 friend struct base::DefaultLazyInstanceTraits<PluginList>; |
| 304 | 332 |
| 305 DISALLOW_COPY_AND_ASSIGN(PluginList); | 333 DISALLOW_COPY_AND_ASSIGN(PluginList); |
| 306 }; | 334 }; |
| 307 | 335 |
| 308 } // namespace NPAPI | 336 } // namespace NPAPI |
| 309 | 337 |
| 310 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ | 338 #endif // WEBKIT_GLUE_PLUGINS_PLUGIN_LIST_H_ |
| OLD | NEW |