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