plugin_service.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string16.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/common/content_export.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FilePath;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BrowserContext;
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PluginProcessHost;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PluginServiceFilter;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceContext;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct PepperPluginInfo;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WebPluginInfo;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This must be created on the main thread but it's only called on the IO/file
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread. This is an asynchronous wrapper around the PluginList interface for
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// querying plugin information. This must be used instead of that to avoid
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// doing expensive disk operations on the IO/UI threads.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PluginService {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(const std::vector<WebPluginInfo>&)>
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetPluginsCallback;
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the PluginService singleton.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static PluginService* GetInstance();
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tells all the renderer processes associated with the given browser context
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to throw away their cache of the plugin list, and optionally also reload
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // all the pages with plugins. If |browser_context| is NULL, purges the cache
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in all renderers.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NOTE: can only be called on the UI thread.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CONTENT_EXPORT static void PurgePluginListCache(
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      BrowserContext* browser_context,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool reload_pages);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~PluginService() {}
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Must be called on the instance to finish initialization.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Init() = 0;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Starts watching for changes in the list of installed plug-ins.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StartWatchingPlugins() = 0;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the plugin in the list of plugins that matches the given url and mime
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type. Returns true if the data is frome a stale plugin list, false if it
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is up to date. This can be called from any thread.
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool GetPluginInfoArray(
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& mime_type,
65      bool allow_wildcard,
66      std::vector<WebPluginInfo>* info,
67      std::vector<std::string>* actual_mime_types) = 0;
68
69  // Gets plugin info for an individual plugin and filters the plugins using
70  // the |context| and renderer IDs. This will report whether the data is stale
71  // via |is_stale| and returns whether or not the plugin can be found.
72  virtual bool GetPluginInfo(int render_process_id,
73                             int render_frame_id,
74                             ResourceContext* context,
75                             const GURL& url,
76                             const GURL& page_url,
77                             const std::string& mime_type,
78                             bool allow_wildcard,
79                             bool* is_stale,
80                             WebPluginInfo* info,
81                             std::string* actual_mime_type) = 0;
82
83  // Get plugin info by plugin path (including disabled plugins). Returns true
84  // if the plugin is found and WebPluginInfo has been filled in |info|. This
85  // will use cached data in the plugin list.
86  virtual bool GetPluginInfoByPath(const base::FilePath& plugin_path,
87                                   WebPluginInfo* info) = 0;
88
89  // Returns the display name for the plugin identified by the given path. If
90  // the path doesn't identify a plugin, or the plugin has no display name,
91  // this will attempt to generate a display name from the path.
92  virtual base::string16 GetPluginDisplayNameByPath(
93      const base::FilePath& plugin_path) = 0;
94
95  // Asynchronously loads plugins if necessary and then calls back to the
96  // provided function on the calling MessageLoop on completion.
97  virtual void GetPlugins(const GetPluginsCallback& callback) = 0;
98
99  // Returns information about a pepper plugin if it exists, otherwise NULL.
100  // The caller does not own the pointer, and it's not guaranteed to live past
101  // the call stack.
102  virtual PepperPluginInfo* GetRegisteredPpapiPluginInfo(
103      const base::FilePath& plugin_path) = 0;
104
105  virtual void SetFilter(PluginServiceFilter* filter) = 0;
106  virtual PluginServiceFilter* GetFilter() = 0;
107
108  // If the plugin with the given path is running, cleanly shuts it down.
109  virtual void ForcePluginShutdown(const base::FilePath& plugin_path) = 0;
110
111  // Used to monitor plug-in stability. An unstable plug-in is one that has
112  // crashed more than a set number of times in a set time period.
113  virtual bool IsPluginUnstable(const base::FilePath& plugin_path) = 0;
114
115  // Cause the plugin list to refresh next time they are accessed, regardless
116  // of whether they are already loaded.
117  virtual void RefreshPlugins() = 0;
118
119  // Add/Remove an extra plugin to load when we actually do the loading.  Must
120  // be called before the plugins have been loaded.
121  virtual void AddExtraPluginPath(const base::FilePath& path) = 0;
122  virtual void RemoveExtraPluginPath(const base::FilePath& path) = 0;
123
124  // Same as above, but specifies a directory in which to search for plugins.
125  virtual void AddExtraPluginDir(const base::FilePath& path) = 0;
126
127  // Register an internal plugin with the specified plugin information.
128  // An internal plugin must be registered before it can
129  // be loaded using PluginList::LoadPlugin().
130  // If |add_at_beginning| is true the plugin will be added earlier in
131  // the list so that it can override the MIME types of older registrations.
132  virtual void RegisterInternalPlugin(const WebPluginInfo& info,
133                                      bool add_at_beginning) = 0;
134
135  // Removes a specified internal plugin from the list. The search will match
136  // on the path from the version info previously registered.
137  virtual void UnregisterInternalPlugin(const base::FilePath& path) = 0;
138
139  // Gets a list of all the registered internal plugins.
140  virtual void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) = 0;
141
142  // Returns true iff NPAPI plugins are supported on the current platform.
143  // This can be called from any thread.
144  virtual bool NPAPIPluginsSupported() = 0;
145
146  // This is equivalent to specifying kDisablePluginsDiscovery, but is useful
147  // for unittests.
148  virtual void DisablePluginsDiscoveryForTesting() = 0;
149
150#if defined(OS_MACOSX)
151  // Called when the application is made active so that modal plugin windows can
152  // be made forward too.
153  virtual void AppActivated() = 0;
154#elif defined(OS_WIN)
155  // Returns the name and version of a plugin HWND. If the HWND isn't a valid
156  // plugin, returns false.
157  // This can be called from any thread.
158  virtual bool GetPluginInfoFromWindow(HWND window,
159                                       base::string16* plugin_name,
160                                       base::string16* plugin_version) = 0;
161#endif
162
163  // Returns true iff PPAPI "dev channel" methods are supported.
164  virtual bool PpapiDevChannelSupported(BrowserContext* browser_context,
165                                        const GURL& document_url) = 0;
166};
167
168}  // namespace content
169
170#endif  // CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_
171