blob: b3fcbf9246befde610d8363d20a81085aff68312 [file] [log] [blame]
[email protected]3b48dbc2012-01-06 16:34:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a0421732011-02-23 03:55:402// 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]e67385f2011-12-21 06:00:568#ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
9#define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_
[email protected]a0421732011-02-23 03:55:4010#pragma once
11
[email protected]47214d882012-02-29 06:28:4812#include <map>
[email protected]7dba43dc2011-11-10 01:57:5813#include <set>
[email protected]47214d882012-02-29 06:28:4814#include <vector>
[email protected]a0421732011-02-23 03:55:4015
16#include "base/basictypes.h"
[email protected]bdd6deb2011-12-21 03:03:2417#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1518#include "base/memory/scoped_vector.h"
19#include "base/memory/singleton.h"
[email protected]a0421732011-02-23 03:55:4020#include "base/synchronization/waitable_event_watcher.h"
[email protected]a33fa9d2012-05-16 14:47:4921#include "base/threading/sequenced_worker_pool.h"
[email protected]47214d882012-02-29 06:28:4822#include "base/time.h"
[email protected]a0421732011-02-23 03:55:4023#include "build/build_config.h"
[email protected]a0421732011-02-23 03:55:4024#include "content/browser/plugin_process_host.h"
25#include "content/browser/ppapi_plugin_process_host.h"
[email protected]8d128d62011-09-13 22:11:5726#include "content/common/content_export.h"
[email protected]6c2381d2011-10-19 02:52:5327#include "content/public/browser/notification_observer.h"
28#include "content/public/browser/notification_registrar.h"
[email protected]3a5180ae2011-12-21 02:39:3829#include "content/public/browser/plugin_service.h"
[email protected]a0421732011-02-23 03:55:4030#include "googleurl/src/gurl.h"
31#include "ipc/ipc_channel_handle.h"
[email protected]a0421732011-02-23 03:55:4032
33#if defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1534#include "base/memory/scoped_ptr.h"
[email protected]a0421732011-02-23 03:55:4035#include "base/win/registry.h"
36#endif
37
[email protected]3b48dbc2012-01-06 16:34:1738#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:0139#include "base/files/file_path_watcher.h"
[email protected]a0421732011-02-23 03:55:4040#endif
41
[email protected]a0421732011-02-23 03:55:4042class PluginDirWatcherDelegate;
[email protected]d4af1e72011-10-21 17:45:4343class PluginLoaderPosix;
[email protected]a0421732011-02-23 03:55:4044
[email protected]d33e7cc2011-09-23 01:43:5645namespace base {
46class MessageLoopProxy;
47}
48
[email protected]dfba8762011-09-02 12:49:5449namespace content {
[email protected]45a22e62011-10-12 09:48:0250class BrowserContext;
[email protected]209f2ae2012-03-13 01:28:0851class PluginServiceFilter;
[email protected]dfba8762011-09-02 12:49:5452class ResourceContext;
[email protected]738a7212011-10-21 17:33:5253struct PepperPluginInfo;
[email protected]dfba8762011-09-02 12:49:5454}
55
[email protected]d33e7cc2011-09-23 01:43:5656namespace webkit {
57namespace npapi {
58class PluginGroup;
59class PluginList;
60}
61}
62
[email protected]209f2ae2012-03-13 01:28:0863// base::Bind() has limited arity, and the filter-related methods tend to
64// surpass that limit.
65struct PluginServiceFilterParams {
66 int render_process_id;
67 int render_view_id;
68 GURL page_url;
69 content::ResourceContext* resource_context;
70};
71
[email protected]e67385f2011-12-21 06:00:5672class CONTENT_EXPORT PluginServiceImpl
[email protected]bdd6deb2011-12-21 03:03:2473 : NON_EXPORTED_BASE(public content::PluginService),
[email protected]3a5180ae2011-12-21 02:39:3874 public base::WaitableEventWatcher::Delegate,
[email protected]6c2381d2011-10-19 02:52:5375 public content::NotificationObserver {
[email protected]a0421732011-02-23 03:55:4076 public:
[email protected]e67385f2011-12-21 06:00:5677 // Returns the PluginServiceImpl singleton.
78 static PluginServiceImpl* GetInstance();
[email protected]a0421732011-02-23 03:55:4079
[email protected]3a5180ae2011-12-21 02:39:3880 // content::PluginService implementation:
81 virtual void Init() OVERRIDE;
82 virtual void StartWatchingPlugins() OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:3883 virtual bool GetPluginInfoArray(
84 const GURL& url,
85 const std::string& mime_type,
86 bool allow_wildcard,
87 std::vector<webkit::WebPluginInfo>* info,
88 std::vector<std::string>* actual_mime_types) OVERRIDE;
89 virtual bool GetPluginInfo(int render_process_id,
90 int render_view_id,
[email protected]df02aca2012-02-09 21:03:2091 content::ResourceContext* context,
[email protected]3a5180ae2011-12-21 02:39:3892 const GURL& url,
93 const GURL& page_url,
94 const std::string& mime_type,
95 bool allow_wildcard,
96 bool* is_stale,
97 webkit::WebPluginInfo* info,
98 std::string* actual_mime_type) OVERRIDE;
99 virtual bool GetPluginInfoByPath(const FilePath& plugin_path,
100 webkit::WebPluginInfo* info) OVERRIDE;
[email protected]8be45842012-04-13 19:49:29101 virtual string16 GetPluginDisplayNameByPath(const FilePath& path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38102 virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE;
103 virtual void GetPluginGroups(
104 const GetPluginGroupsCallback& callback) OVERRIDE;
105 virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
106 const FilePath& plugin_path) OVERRIDE;
107 virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE;
108 virtual content::PluginServiceFilter* GetFilter() OVERRIDE;
[email protected]b6a2f8de2012-01-31 17:28:49109 virtual void ForcePluginShutdown(const FilePath& plugin_path) OVERRIDE;
[email protected]47214d882012-02-29 06:28:48110 virtual bool IsPluginUnstable(const FilePath& plugin_path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38111 virtual void RefreshPlugins() OVERRIDE;
112 virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE;
[email protected]c6f3dea2012-01-14 02:23:11113 virtual void AddExtraPluginDir(const FilePath& path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38114 virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE;
115 virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE;
116 virtual void RegisterInternalPlugin(
[email protected]c6f3dea2012-01-14 02:23:11117 const webkit::WebPluginInfo& info, bool add_at_beginning) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38118 virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE;
119 virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE;
[email protected]e67385f2011-12-21 06:00:56120 virtual void SetPluginListForTesting(
121 webkit::npapi::PluginList* plugin_list) OVERRIDE;
[email protected]dfba8762011-09-02 12:49:54122
[email protected]a0421732011-02-23 03:55:40123 // Returns the plugin process host corresponding to the plugin process that
124 // has been started by this service. This will start a process to host the
125 // 'plugin_path' if needed. If the process fails to start, the return value
126 // is NULL. Must be called on the IO thread.
127 PluginProcessHost* FindOrStartNpapiPluginProcess(
128 const FilePath& plugin_path);
129 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
[email protected]d259a8e2011-05-18 22:31:09130 const FilePath& plugin_path,
[email protected]a50432d2011-09-30 16:32:14131 PpapiPluginProcessHost::PluginClient* client);
132 PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess(
[email protected]eb415bf0e2011-04-14 02:45:42133 const FilePath& plugin_path);
[email protected]a0421732011-02-23 03:55:40134
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]dfba8762011-09-02 12:49:54141 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40142 const std::string& mime_type,
143 PluginProcessHost::Client* client);
144 void OpenChannelToPpapiPlugin(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14145 PpapiPluginProcessHost::PluginClient* client);
[email protected]eb415bf0e2011-04-14 02:45:42146 void OpenChannelToPpapiBroker(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14147 PpapiPluginProcessHost::BrokerClient* client);
[email protected]a0421732011-02-23 03:55:40148
[email protected]4befe7592011-09-14 22:49:09149 // Cancels opening a channel to a NPAPI plugin.
150 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
151
[email protected]47214d882012-02-29 06:28:48152 // Used to monitor plug-in stability.
153 void RegisterPluginCrash(const FilePath& plugin_path);
154
[email protected]a0421732011-02-23 03:55:40155 private:
[email protected]e67385f2011-12-21 06:00:56156 friend struct DefaultSingletonTraits<PluginServiceImpl>;
[email protected]a0421732011-02-23 03:55:40157
[email protected]e67385f2011-12-21 06:00:56158 // Creates the PluginServiceImpl object, but doesn't actually build the plugin
[email protected]a0421732011-02-23 03:55:40159 // list yet. It's generated lazily.
[email protected]e67385f2011-12-21 06:00:56160 PluginServiceImpl();
161 virtual ~PluginServiceImpl();
[email protected]a0421732011-02-23 03:55:40162
163 // base::WaitableEventWatcher::Delegate implementation.
[email protected]edc64de2011-11-17 20:07:38164 virtual void OnWaitableEventSignaled(
165 base::WaitableEvent* waitable_event) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40166
[email protected]6c2381d2011-10-19 02:52:53167 // content::NotificationObserver implementation
[email protected]edc64de2011-11-17 20:07:38168 virtual void Observe(int type,
169 const content::NotificationSource& source,
170 const content::NotificationDetails& details) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40171
[email protected]b6a2f8de2012-01-31 17:28:49172 // Returns the plugin process host corresponding to the plugin process that
173 // has been started by this service. Returns NULL if no process has been
174 // started.
175 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
176 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
177 PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
178
[email protected]a0421732011-02-23 03:55:40179 void RegisterPepperPlugins();
180
[email protected]a33fa9d2012-05-16 14:47:49181#if defined(OS_WIN)
182 // Run on the blocking pool to load the plugins synchronously.
[email protected]d33e7cc2011-09-23 01:43:56183 void GetPluginsInternal(base::MessageLoopProxy* target_loop,
184 const GetPluginsCallback& callback);
[email protected]a33fa9d2012-05-16 14:47:49185#endif
[email protected]d33e7cc2011-09-23 01:43:56186
[email protected]88ca4912011-10-12 14:00:43187 // Binding directly to GetAllowedPluginForOpenChannelToPlugin() isn't possible
188 // because more arity is needed <http://crbug.com/98542>. This just forwards.
189 void ForwardGetAllowedPluginForOpenChannelToPlugin(
[email protected]209f2ae2012-03-13 01:28:08190 const PluginServiceFilterParams& params,
[email protected]88ca4912011-10-12 14:00:43191 const GURL& url,
192 const std::string& mime_type,
193 PluginProcessHost::Client* client,
194 const std::vector<webkit::WebPluginInfo>&);
[email protected]a0421732011-02-23 03:55:40195 // Helper so we can do the plugin lookup on the FILE thread.
196 void GetAllowedPluginForOpenChannelToPlugin(
197 int render_process_id,
198 int render_view_id,
199 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54200 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40201 const std::string& mime_type,
[email protected]87c4be42011-09-16 01:10:59202 PluginProcessHost::Client* client,
[email protected]df02aca2012-02-09 21:03:20203 content::ResourceContext* resource_context);
[email protected]a0421732011-02-23 03:55:40204
205 // Helper so we can finish opening the channel after looking up the
206 // plugin.
207 void FinishOpenChannelToPlugin(
208 const FilePath& plugin_path,
209 PluginProcessHost::Client* client);
210
[email protected]3b48dbc2012-01-06 16:34:17211#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]a0421732011-02-23 03:55:40212 // Registers a new FilePathWatcher for a given path.
213 static void RegisterFilePathWatcher(
[email protected]493c8002011-04-14 16:56:01214 base::files::FilePathWatcher* watcher,
[email protected]a0421732011-02-23 03:55:40215 const FilePath& path,
[email protected]493c8002011-04-14 16:56:01216 base::files::FilePathWatcher::Delegate* delegate);
[email protected]a0421732011-02-23 03:55:40217#endif
218
[email protected]ee066172011-11-10 23:20:05219 // The plugin list instance.
220 webkit::npapi::PluginList* plugin_list_;
221
[email protected]6c2381d2011-10-19 02:52:53222 content::NotificationRegistrar registrar_;
[email protected]a0421732011-02-23 03:55:40223
[email protected]a0421732011-02-23 03:55:40224#if defined(OS_WIN)
225 // Registry keys for getting notifications when new plugins are installed.
226 base::win::RegKey hkcu_key_;
227 base::win::RegKey hklm_key_;
228 scoped_ptr<base::WaitableEvent> hkcu_event_;
229 scoped_ptr<base::WaitableEvent> hklm_event_;
230 base::WaitableEventWatcher hkcu_watcher_;
231 base::WaitableEventWatcher hklm_watcher_;
232#endif
233
[email protected]3b48dbc2012-01-06 16:34:17234#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:01235 ScopedVector<base::files::FilePathWatcher> file_watchers_;
[email protected]a0421732011-02-23 03:55:40236 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
237#endif
238
[email protected]738a7212011-10-21 17:33:52239 std::vector<content::PepperPluginInfo> ppapi_plugins_;
[email protected]a0421732011-02-23 03:55:40240
[email protected]dfba8762011-09-02 12:49:54241 // Weak pointer; outlives us.
242 content::PluginServiceFilter* filter_;
[email protected]a0421732011-02-23 03:55:40243
[email protected]4befe7592011-09-14 22:49:09244 std::set<PluginProcessHost::Client*> pending_plugin_clients_;
245
[email protected]a33fa9d2012-05-16 14:47:49246#if defined(OS_WIN)
247 // Used to sequentialize loading plug-ins from disk.
248 base::SequencedWorkerPool::SequenceToken plugin_list_token_;
249#endif
[email protected]d4af1e72011-10-21 17:45:43250#if defined(OS_POSIX)
251 scoped_refptr<PluginLoaderPosix> plugin_loader_;
252#endif
253
[email protected]47214d882012-02-29 06:28:48254 // Used to detect if a given plug-in is crashing over and over.
255 std::map<FilePath, std::vector<base::Time> > crash_times_;
256
[email protected]e67385f2011-12-21 06:00:56257 DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl);
[email protected]a0421732011-02-23 03:55:40258};
259
[email protected]e67385f2011-12-21 06:00:56260#endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_