blob: 602ca647f76d167e653fee4297230e3b0a01952f [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]7dba43dc2011-11-10 01:57:5812#include <set>
[email protected]a0421732011-02-23 03:55:4013
14#include "base/basictypes.h"
[email protected]bdd6deb2011-12-21 03:03:2415#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_vector.h"
17#include "base/memory/singleton.h"
[email protected]a0421732011-02-23 03:55:4018#include "base/synchronization/waitable_event_watcher.h"
19#include "build/build_config.h"
[email protected]a0421732011-02-23 03:55:4020#include "content/browser/plugin_process_host.h"
21#include "content/browser/ppapi_plugin_process_host.h"
[email protected]8d128d62011-09-13 22:11:5722#include "content/common/content_export.h"
[email protected]6c2381d2011-10-19 02:52:5323#include "content/public/browser/notification_observer.h"
24#include "content/public/browser/notification_registrar.h"
[email protected]3a5180ae2011-12-21 02:39:3825#include "content/public/browser/plugin_service.h"
[email protected]a0421732011-02-23 03:55:4026#include "googleurl/src/gurl.h"
27#include "ipc/ipc_channel_handle.h"
[email protected]a0421732011-02-23 03:55:4028
29#if defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1530#include "base/memory/scoped_ptr.h"
[email protected]a0421732011-02-23 03:55:4031#include "base/win/registry.h"
32#endif
33
[email protected]3b48dbc2012-01-06 16:34:1734#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:0135#include "base/files/file_path_watcher.h"
[email protected]a0421732011-02-23 03:55:4036#endif
37
[email protected]a0421732011-02-23 03:55:4038class PluginDirWatcherDelegate;
[email protected]d4af1e72011-10-21 17:45:4339class PluginLoaderPosix;
[email protected]a0421732011-02-23 03:55:4040
[email protected]d33e7cc2011-09-23 01:43:5641namespace base {
42class MessageLoopProxy;
43}
44
[email protected]dfba8762011-09-02 12:49:5445namespace content {
[email protected]45a22e62011-10-12 09:48:0246class BrowserContext;
[email protected]dfba8762011-09-02 12:49:5447class ResourceContext;
[email protected]738a7212011-10-21 17:33:5248struct PepperPluginInfo;
[email protected]dfba8762011-09-02 12:49:5449class PluginServiceFilter;
[email protected]88ca4912011-10-12 14:00:4350struct PluginServiceFilterParams;
[email protected]dfba8762011-09-02 12:49:5451}
52
[email protected]d33e7cc2011-09-23 01:43:5653namespace webkit {
54namespace npapi {
55class PluginGroup;
56class PluginList;
57}
58}
59
[email protected]e67385f2011-12-21 06:00:5660class CONTENT_EXPORT PluginServiceImpl
[email protected]bdd6deb2011-12-21 03:03:2461 : NON_EXPORTED_BASE(public content::PluginService),
[email protected]3a5180ae2011-12-21 02:39:3862 public base::WaitableEventWatcher::Delegate,
[email protected]6c2381d2011-10-19 02:52:5363 public content::NotificationObserver {
[email protected]a0421732011-02-23 03:55:4064 public:
[email protected]e67385f2011-12-21 06:00:5665 // Returns the PluginServiceImpl singleton.
66 static PluginServiceImpl* GetInstance();
[email protected]a0421732011-02-23 03:55:4067
[email protected]3a5180ae2011-12-21 02:39:3868 // content::PluginService implementation:
69 virtual void Init() OVERRIDE;
70 virtual void StartWatchingPlugins() OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:3871 virtual bool GetPluginInfoArray(
72 const GURL& url,
73 const std::string& mime_type,
74 bool allow_wildcard,
75 std::vector<webkit::WebPluginInfo>* info,
76 std::vector<std::string>* actual_mime_types) OVERRIDE;
77 virtual bool GetPluginInfo(int render_process_id,
78 int render_view_id,
[email protected]df02aca2012-02-09 21:03:2079 content::ResourceContext* context,
[email protected]3a5180ae2011-12-21 02:39:3880 const GURL& url,
81 const GURL& page_url,
82 const std::string& mime_type,
83 bool allow_wildcard,
84 bool* is_stale,
85 webkit::WebPluginInfo* info,
86 std::string* actual_mime_type) OVERRIDE;
87 virtual bool GetPluginInfoByPath(const FilePath& plugin_path,
88 webkit::WebPluginInfo* info) OVERRIDE;
89 virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE;
90 virtual void GetPluginGroups(
91 const GetPluginGroupsCallback& callback) OVERRIDE;
92 virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
93 const FilePath& plugin_path) OVERRIDE;
94 virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE;
95 virtual content::PluginServiceFilter* GetFilter() OVERRIDE;
[email protected]b6a2f8de2012-01-31 17:28:4996 virtual void ForcePluginShutdown(const FilePath& plugin_path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:3897 virtual void RefreshPlugins() OVERRIDE;
98 virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE;
[email protected]c6f3dea2012-01-14 02:23:1199 virtual void AddExtraPluginDir(const FilePath& path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38100 virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE;
101 virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE;
102 virtual void RegisterInternalPlugin(
[email protected]c6f3dea2012-01-14 02:23:11103 const webkit::WebPluginInfo& info, bool add_at_beginning) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38104 virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE;
105 virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE;
[email protected]e67385f2011-12-21 06:00:56106 virtual void SetPluginListForTesting(
107 webkit::npapi::PluginList* plugin_list) OVERRIDE;
[email protected]dfba8762011-09-02 12:49:54108
[email protected]a0421732011-02-23 03:55:40109 // Returns the plugin process host corresponding to the plugin process that
110 // has been started by this service. This will start a process to host the
111 // 'plugin_path' if needed. If the process fails to start, the return value
112 // is NULL. Must be called on the IO thread.
113 PluginProcessHost* FindOrStartNpapiPluginProcess(
114 const FilePath& plugin_path);
115 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
[email protected]d259a8e2011-05-18 22:31:09116 const FilePath& plugin_path,
[email protected]a50432d2011-09-30 16:32:14117 PpapiPluginProcessHost::PluginClient* client);
118 PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess(
[email protected]eb415bf0e2011-04-14 02:45:42119 const FilePath& plugin_path);
[email protected]a0421732011-02-23 03:55:40120
121 // Opens a channel to a plugin process for the given mime type, starting
122 // a new plugin process if necessary. This must be called on the IO thread
123 // or else a deadlock can occur.
124 void OpenChannelToNpapiPlugin(int render_process_id,
125 int render_view_id,
126 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54127 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40128 const std::string& mime_type,
129 PluginProcessHost::Client* client);
130 void OpenChannelToPpapiPlugin(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14131 PpapiPluginProcessHost::PluginClient* client);
[email protected]eb415bf0e2011-04-14 02:45:42132 void OpenChannelToPpapiBroker(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14133 PpapiPluginProcessHost::BrokerClient* client);
[email protected]a0421732011-02-23 03:55:40134
[email protected]4befe7592011-09-14 22:49:09135 // Cancels opening a channel to a NPAPI plugin.
136 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
137
[email protected]a0421732011-02-23 03:55:40138 private:
[email protected]e67385f2011-12-21 06:00:56139 friend struct DefaultSingletonTraits<PluginServiceImpl>;
[email protected]a0421732011-02-23 03:55:40140
[email protected]e67385f2011-12-21 06:00:56141 // Creates the PluginServiceImpl object, but doesn't actually build the plugin
[email protected]a0421732011-02-23 03:55:40142 // list yet. It's generated lazily.
[email protected]e67385f2011-12-21 06:00:56143 PluginServiceImpl();
144 virtual ~PluginServiceImpl();
[email protected]a0421732011-02-23 03:55:40145
146 // base::WaitableEventWatcher::Delegate implementation.
[email protected]edc64de2011-11-17 20:07:38147 virtual void OnWaitableEventSignaled(
148 base::WaitableEvent* waitable_event) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40149
[email protected]6c2381d2011-10-19 02:52:53150 // content::NotificationObserver implementation
[email protected]edc64de2011-11-17 20:07:38151 virtual void Observe(int type,
152 const content::NotificationSource& source,
153 const content::NotificationDetails& details) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40154
[email protected]b6a2f8de2012-01-31 17:28:49155 // Returns the plugin process host corresponding to the plugin process that
156 // has been started by this service. Returns NULL if no process has been
157 // started.
158 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
159 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
160 PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
161
[email protected]a0421732011-02-23 03:55:40162 void RegisterPepperPlugins();
163
[email protected]d33e7cc2011-09-23 01:43:56164 // Function that is run on the FILE thread to load the plugins synchronously.
165 void GetPluginsInternal(base::MessageLoopProxy* target_loop,
166 const GetPluginsCallback& callback);
167
[email protected]88ca4912011-10-12 14:00:43168 // Binding directly to GetAllowedPluginForOpenChannelToPlugin() isn't possible
169 // because more arity is needed <http://crbug.com/98542>. This just forwards.
170 void ForwardGetAllowedPluginForOpenChannelToPlugin(
171 const content::PluginServiceFilterParams& params,
172 const GURL& url,
173 const std::string& mime_type,
174 PluginProcessHost::Client* client,
175 const std::vector<webkit::WebPluginInfo>&);
[email protected]a0421732011-02-23 03:55:40176 // Helper so we can do the plugin lookup on the FILE thread.
177 void GetAllowedPluginForOpenChannelToPlugin(
178 int render_process_id,
179 int render_view_id,
180 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54181 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40182 const std::string& mime_type,
[email protected]87c4be42011-09-16 01:10:59183 PluginProcessHost::Client* client,
[email protected]df02aca2012-02-09 21:03:20184 content::ResourceContext* resource_context);
[email protected]a0421732011-02-23 03:55:40185
186 // Helper so we can finish opening the channel after looking up the
187 // plugin.
188 void FinishOpenChannelToPlugin(
189 const FilePath& plugin_path,
190 PluginProcessHost::Client* client);
191
[email protected]3b48dbc2012-01-06 16:34:17192#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]a0421732011-02-23 03:55:40193 // Registers a new FilePathWatcher for a given path.
194 static void RegisterFilePathWatcher(
[email protected]493c8002011-04-14 16:56:01195 base::files::FilePathWatcher* watcher,
[email protected]a0421732011-02-23 03:55:40196 const FilePath& path,
[email protected]493c8002011-04-14 16:56:01197 base::files::FilePathWatcher::Delegate* delegate);
[email protected]a0421732011-02-23 03:55:40198#endif
199
[email protected]ee066172011-11-10 23:20:05200 // The plugin list instance.
201 webkit::npapi::PluginList* plugin_list_;
202
[email protected]6c2381d2011-10-19 02:52:53203 content::NotificationRegistrar registrar_;
[email protected]a0421732011-02-23 03:55:40204
[email protected]a0421732011-02-23 03:55:40205#if defined(OS_WIN)
206 // Registry keys for getting notifications when new plugins are installed.
207 base::win::RegKey hkcu_key_;
208 base::win::RegKey hklm_key_;
209 scoped_ptr<base::WaitableEvent> hkcu_event_;
210 scoped_ptr<base::WaitableEvent> hklm_event_;
211 base::WaitableEventWatcher hkcu_watcher_;
212 base::WaitableEventWatcher hklm_watcher_;
213#endif
214
[email protected]3b48dbc2012-01-06 16:34:17215#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:01216 ScopedVector<base::files::FilePathWatcher> file_watchers_;
[email protected]a0421732011-02-23 03:55:40217 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
218#endif
219
[email protected]738a7212011-10-21 17:33:52220 std::vector<content::PepperPluginInfo> ppapi_plugins_;
[email protected]a0421732011-02-23 03:55:40221
[email protected]dfba8762011-09-02 12:49:54222 // Weak pointer; outlives us.
223 content::PluginServiceFilter* filter_;
[email protected]a0421732011-02-23 03:55:40224
[email protected]4befe7592011-09-14 22:49:09225 std::set<PluginProcessHost::Client*> pending_plugin_clients_;
226
[email protected]d4af1e72011-10-21 17:45:43227#if defined(OS_POSIX)
228 scoped_refptr<PluginLoaderPosix> plugin_loader_;
229#endif
230
[email protected]e67385f2011-12-21 06:00:56231 DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl);
[email protected]a0421732011-02-23 03:55:40232};
233
[email protected]e67385f2011-12-21 06:00:56234#endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_