1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_
6 #define CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_
11 #include "base/callback.h"
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
24 class PluginProcessHost
;
25 class PluginServiceFilter
;
26 class ResourceContext
;
27 struct PepperPluginInfo
;
30 // This must be created on the main thread but it's only called on the IO/file
31 // thread. This is an asynchronous wrapper around the PluginList interface for
32 // querying plugin information. This must be used instead of that to avoid
33 // doing expensive disk operations on the IO/UI threads.
36 typedef base::Callback
<void(const std::vector
<WebPluginInfo
>&)>
39 // Returns the PluginService singleton.
40 CONTENT_EXPORT
static PluginService
* GetInstance();
42 // Tells all the renderer processes associated with the given browser context
43 // to throw away their cache of the plugin list, and optionally also reload
44 // all the pages with plugins. If |browser_context| is NULL, purges the cache
46 // NOTE: can only be called on the UI thread.
47 CONTENT_EXPORT
static void PurgePluginListCache(
48 BrowserContext
* browser_context
,
51 virtual ~PluginService() {}
53 // Must be called on the instance to finish initialization.
54 virtual void Init() = 0;
56 // Starts watching for changes in the list of installed plug-ins.
57 virtual void StartWatchingPlugins() = 0;
59 // Gets the plugin in the list of plugins that matches the given url and mime
60 // type. Returns true if the data is frome a stale plugin list, false if it
61 // is up to date. This can be called from any thread.
62 virtual bool GetPluginInfoArray(
64 const std::string
& mime_type
,
66 std::vector
<WebPluginInfo
>* info
,
67 std::vector
<std::string
>* actual_mime_types
) = 0;
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
,
74 ResourceContext
* context
,
77 const std::string
& mime_type
,
81 std::string
* actual_mime_type
) = 0;
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;
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;
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;
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
102 virtual PepperPluginInfo
* GetRegisteredPpapiPluginInfo(
103 const base::FilePath
& plugin_path
) = 0;
105 virtual void SetFilter(PluginServiceFilter
* filter
) = 0;
106 virtual PluginServiceFilter
* GetFilter() = 0;
108 // If the plugin with the given path is running, cleanly shuts it down.
109 virtual void ForcePluginShutdown(const base::FilePath
& plugin_path
) = 0;
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;
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;
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;
124 // Same as above, but specifies a directory in which to search for plugins.
125 virtual void AddExtraPluginDir(const base::FilePath
& path
) = 0;
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;
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;
139 // Gets a list of all the registered internal plugins.
140 virtual void GetInternalPlugins(std::vector
<WebPluginInfo
>* plugins
) = 0;
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;
146 // This is equivalent to specifying kDisablePluginsDiscovery, but is useful
148 virtual void DisablePluginsDiscoveryForTesting() = 0;
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;
163 // Returns true iff PPAPI "dev channel" methods are supported.
164 virtual bool PpapiDevChannelSupported(BrowserContext
* browser_context
,
165 const GURL
& document_url
) = 0;
168 } // namespace content
170 #endif // CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_