[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This class responds to requests from renderers for the list of plugins, and |
| 6 | // also a proxy object for plugin instances. |
| 7 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 8 | #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |
| 9 | #define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 10 | #pragma once |
| 11 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 12 | #include <map> |
[email protected] | 7dba43dc | 2011-11-10 01:57:58 | [diff] [blame] | 13 | #include <set> |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 14 | #include <vector> |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 15 | |
| 16 | #include "base/basictypes.h" |
[email protected] | bdd6deb | 2011-12-21 03:03:24 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/scoped_vector.h" |
| 19 | #include "base/memory/singleton.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 20 | #include "base/synchronization/waitable_event_watcher.h" |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 21 | #include "base/time.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 22 | #include "build/build_config.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 23 | #include "content/browser/plugin_process_host.h" |
| 24 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 25 | #include "content/common/content_export.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 26 | #include "content/public/browser/notification_observer.h" |
| 27 | #include "content/public/browser/notification_registrar.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 28 | #include "content/public/browser/plugin_service.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 29 | #include "googleurl/src/gurl.h" |
| 30 | #include "ipc/ipc_channel_handle.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 31 | |
| 32 | #if defined(OS_WIN) |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 33 | #include "base/memory/scoped_ptr.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 34 | #include "base/win/registry.h" |
| 35 | #endif |
| 36 | |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 37 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 38 | #include "base/files/file_path_watcher.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 39 | #endif |
| 40 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 41 | class PluginDirWatcherDelegate; |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 42 | class PluginLoaderPosix; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 43 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 44 | namespace base { |
| 45 | class MessageLoopProxy; |
| 46 | } |
| 47 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 48 | namespace content { |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 49 | class BrowserContext; |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame^] | 50 | class PluginServiceFilter; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 51 | class ResourceContext; |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 52 | struct PepperPluginInfo; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 55 | namespace webkit { |
| 56 | namespace npapi { |
| 57 | class PluginGroup; |
| 58 | class PluginList; |
| 59 | } |
| 60 | } |
| 61 | |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame^] | 62 | // base::Bind() has limited arity, and the filter-related methods tend to |
| 63 | // surpass that limit. |
| 64 | struct PluginServiceFilterParams { |
| 65 | int render_process_id; |
| 66 | int render_view_id; |
| 67 | GURL page_url; |
| 68 | content::ResourceContext* resource_context; |
| 69 | }; |
| 70 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 71 | class CONTENT_EXPORT PluginServiceImpl |
[email protected] | bdd6deb | 2011-12-21 03:03:24 | [diff] [blame] | 72 | : NON_EXPORTED_BASE(public content::PluginService), |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 73 | public base::WaitableEventWatcher::Delegate, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 74 | public content::NotificationObserver { |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 75 | public: |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 76 | // Returns the PluginServiceImpl singleton. |
| 77 | static PluginServiceImpl* GetInstance(); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 78 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 79 | // content::PluginService implementation: |
| 80 | virtual void Init() OVERRIDE; |
| 81 | virtual void StartWatchingPlugins() OVERRIDE; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 82 | virtual bool GetPluginInfoArray( |
| 83 | const GURL& url, |
| 84 | const std::string& mime_type, |
| 85 | bool allow_wildcard, |
| 86 | std::vector<webkit::WebPluginInfo>* info, |
| 87 | std::vector<std::string>* actual_mime_types) OVERRIDE; |
| 88 | virtual bool GetPluginInfo(int render_process_id, |
| 89 | int render_view_id, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 90 | content::ResourceContext* context, |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 91 | const GURL& url, |
| 92 | const GURL& page_url, |
| 93 | const std::string& mime_type, |
| 94 | bool allow_wildcard, |
| 95 | bool* is_stale, |
| 96 | webkit::WebPluginInfo* info, |
| 97 | std::string* actual_mime_type) OVERRIDE; |
| 98 | virtual bool GetPluginInfoByPath(const FilePath& plugin_path, |
| 99 | webkit::WebPluginInfo* info) OVERRIDE; |
| 100 | virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE; |
| 101 | virtual void GetPluginGroups( |
| 102 | const GetPluginGroupsCallback& callback) OVERRIDE; |
| 103 | virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo( |
| 104 | const FilePath& plugin_path) OVERRIDE; |
| 105 | virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE; |
| 106 | virtual content::PluginServiceFilter* GetFilter() OVERRIDE; |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 107 | virtual void ForcePluginShutdown(const FilePath& plugin_path) OVERRIDE; |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 108 | virtual bool IsPluginUnstable(const FilePath& plugin_path) OVERRIDE; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 109 | virtual void RefreshPlugins() OVERRIDE; |
| 110 | virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE; |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 111 | virtual void AddExtraPluginDir(const FilePath& path) OVERRIDE; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 112 | virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE; |
| 113 | virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE; |
| 114 | virtual void RegisterInternalPlugin( |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 115 | const webkit::WebPluginInfo& info, bool add_at_beginning) OVERRIDE; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 116 | virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE; |
| 117 | virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 118 | virtual void SetPluginListForTesting( |
| 119 | webkit::npapi::PluginList* plugin_list) OVERRIDE; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 120 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 121 | // Returns the plugin process host corresponding to the plugin process that |
| 122 | // has been started by this service. This will start a process to host the |
| 123 | // 'plugin_path' if needed. If the process fails to start, the return value |
| 124 | // is NULL. Must be called on the IO thread. |
| 125 | PluginProcessHost* FindOrStartNpapiPluginProcess( |
| 126 | const FilePath& plugin_path); |
| 127 | PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 128 | const FilePath& plugin_path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 129 | PpapiPluginProcessHost::PluginClient* client); |
| 130 | PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 131 | const FilePath& plugin_path); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 132 | |
| 133 | // Opens a channel to a plugin process for the given mime type, starting |
| 134 | // a new plugin process if necessary. This must be called on the IO thread |
| 135 | // or else a deadlock can occur. |
| 136 | void OpenChannelToNpapiPlugin(int render_process_id, |
| 137 | int render_view_id, |
| 138 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 139 | const GURL& page_url, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 140 | const std::string& mime_type, |
| 141 | PluginProcessHost::Client* client); |
| 142 | void OpenChannelToPpapiPlugin(const FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 143 | PpapiPluginProcessHost::PluginClient* client); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 144 | void OpenChannelToPpapiBroker(const FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 145 | PpapiPluginProcessHost::BrokerClient* client); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 146 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 147 | // Cancels opening a channel to a NPAPI plugin. |
| 148 | void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client); |
| 149 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 150 | // Used to monitor plug-in stability. |
| 151 | void RegisterPluginCrash(const FilePath& plugin_path); |
| 152 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 153 | private: |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 154 | friend struct DefaultSingletonTraits<PluginServiceImpl>; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 155 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 156 | // Creates the PluginServiceImpl object, but doesn't actually build the plugin |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 157 | // list yet. It's generated lazily. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 158 | PluginServiceImpl(); |
| 159 | virtual ~PluginServiceImpl(); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 160 | |
| 161 | // base::WaitableEventWatcher::Delegate implementation. |
[email protected] | edc64de | 2011-11-17 20:07:38 | [diff] [blame] | 162 | virtual void OnWaitableEventSignaled( |
| 163 | base::WaitableEvent* waitable_event) OVERRIDE; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 164 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 165 | // content::NotificationObserver implementation |
[email protected] | edc64de | 2011-11-17 20:07:38 | [diff] [blame] | 166 | virtual void Observe(int type, |
| 167 | const content::NotificationSource& source, |
| 168 | const content::NotificationDetails& details) OVERRIDE; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 169 | |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 170 | // Returns the plugin process host corresponding to the plugin process that |
| 171 | // has been started by this service. Returns NULL if no process has been |
| 172 | // started. |
| 173 | PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path); |
| 174 | PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path); |
| 175 | PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path); |
| 176 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 177 | void RegisterPepperPlugins(); |
| 178 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 179 | // Function that is run on the FILE thread to load the plugins synchronously. |
| 180 | void GetPluginsInternal(base::MessageLoopProxy* target_loop, |
| 181 | const GetPluginsCallback& callback); |
| 182 | |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 183 | // Binding directly to GetAllowedPluginForOpenChannelToPlugin() isn't possible |
| 184 | // because more arity is needed <http://crbug.com/98542>. This just forwards. |
| 185 | void ForwardGetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame^] | 186 | const PluginServiceFilterParams& params, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 187 | const GURL& url, |
| 188 | const std::string& mime_type, |
| 189 | PluginProcessHost::Client* client, |
| 190 | const std::vector<webkit::WebPluginInfo>&); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 191 | // Helper so we can do the plugin lookup on the FILE thread. |
| 192 | void GetAllowedPluginForOpenChannelToPlugin( |
| 193 | int render_process_id, |
| 194 | int render_view_id, |
| 195 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 196 | const GURL& page_url, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 197 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 198 | PluginProcessHost::Client* client, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 199 | content::ResourceContext* resource_context); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 200 | |
| 201 | // Helper so we can finish opening the channel after looking up the |
| 202 | // plugin. |
| 203 | void FinishOpenChannelToPlugin( |
| 204 | const FilePath& plugin_path, |
| 205 | PluginProcessHost::Client* client); |
| 206 | |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 207 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 208 | // Registers a new FilePathWatcher for a given path. |
| 209 | static void RegisterFilePathWatcher( |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 210 | base::files::FilePathWatcher* watcher, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 211 | const FilePath& path, |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 212 | base::files::FilePathWatcher::Delegate* delegate); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 213 | #endif |
| 214 | |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 215 | // The plugin list instance. |
| 216 | webkit::npapi::PluginList* plugin_list_; |
| 217 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 218 | content::NotificationRegistrar registrar_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 219 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 220 | #if defined(OS_WIN) |
| 221 | // Registry keys for getting notifications when new plugins are installed. |
| 222 | base::win::RegKey hkcu_key_; |
| 223 | base::win::RegKey hklm_key_; |
| 224 | scoped_ptr<base::WaitableEvent> hkcu_event_; |
| 225 | scoped_ptr<base::WaitableEvent> hklm_event_; |
| 226 | base::WaitableEventWatcher hkcu_watcher_; |
| 227 | base::WaitableEventWatcher hklm_watcher_; |
| 228 | #endif |
| 229 | |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 230 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 231 | ScopedVector<base::files::FilePathWatcher> file_watchers_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 232 | scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
| 233 | #endif |
| 234 | |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 235 | std::vector<content::PepperPluginInfo> ppapi_plugins_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 236 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 237 | // Weak pointer; outlives us. |
| 238 | content::PluginServiceFilter* filter_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 239 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 240 | std::set<PluginProcessHost::Client*> pending_plugin_clients_; |
| 241 | |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 242 | #if defined(OS_POSIX) |
| 243 | scoped_refptr<PluginLoaderPosix> plugin_loader_; |
| 244 | #endif |
| 245 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 246 | // Used to detect if a given plug-in is crashing over and over. |
| 247 | std::map<FilePath, std::vector<base::Time> > crash_times_; |
| 248 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 249 | DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 250 | }; |
| 251 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 252 | #endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |