blob: bc8f1129020e273c4287d6ea3bb0e28d2de0ab96 [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]47214d882012-02-29 06:28:4821#include "base/time.h"
[email protected]a0421732011-02-23 03:55:4022#include "build/build_config.h"
[email protected]a0421732011-02-23 03:55:4023#include "content/browser/plugin_process_host.h"
24#include "content/browser/ppapi_plugin_process_host.h"
[email protected]8d128d62011-09-13 22:11:5725#include "content/common/content_export.h"
[email protected]6c2381d2011-10-19 02:52:5326#include "content/public/browser/notification_observer.h"
27#include "content/public/browser/notification_registrar.h"
[email protected]3a5180ae2011-12-21 02:39:3828#include "content/public/browser/plugin_service.h"
[email protected]a0421732011-02-23 03:55:4029#include "googleurl/src/gurl.h"
30#include "ipc/ipc_channel_handle.h"
[email protected]a0421732011-02-23 03:55:4031
32#if defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1533#include "base/memory/scoped_ptr.h"
[email protected]a0421732011-02-23 03:55:4034#include "base/win/registry.h"
35#endif
36
[email protected]3b48dbc2012-01-06 16:34:1737#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:0138#include "base/files/file_path_watcher.h"
[email protected]a0421732011-02-23 03:55:4039#endif
40
[email protected]a0421732011-02-23 03:55:4041class PluginDirWatcherDelegate;
[email protected]d4af1e72011-10-21 17:45:4342class PluginLoaderPosix;
[email protected]a0421732011-02-23 03:55:4043
[email protected]d33e7cc2011-09-23 01:43:5644namespace base {
45class MessageLoopProxy;
46}
47
[email protected]dfba8762011-09-02 12:49:5448namespace content {
[email protected]45a22e62011-10-12 09:48:0249class BrowserContext;
[email protected]209f2ae2012-03-13 01:28:0850class PluginServiceFilter;
[email protected]dfba8762011-09-02 12:49:5451class ResourceContext;
[email protected]738a7212011-10-21 17:33:5252struct PepperPluginInfo;
[email protected]dfba8762011-09-02 12:49:5453}
54
[email protected]d33e7cc2011-09-23 01:43:5655namespace webkit {
56namespace npapi {
57class PluginGroup;
58class PluginList;
59}
60}
61
[email protected]209f2ae2012-03-13 01:28:0862// base::Bind() has limited arity, and the filter-related methods tend to
63// surpass that limit.
64struct PluginServiceFilterParams {
65 int render_process_id;
66 int render_view_id;
67 GURL page_url;
68 content::ResourceContext* resource_context;
69};
70
[email protected]e67385f2011-12-21 06:00:5671class CONTENT_EXPORT PluginServiceImpl
[email protected]bdd6deb2011-12-21 03:03:2472 : NON_EXPORTED_BASE(public content::PluginService),
[email protected]3a5180ae2011-12-21 02:39:3873 public base::WaitableEventWatcher::Delegate,
[email protected]6c2381d2011-10-19 02:52:5374 public content::NotificationObserver {
[email protected]a0421732011-02-23 03:55:4075 public:
[email protected]e67385f2011-12-21 06:00:5676 // Returns the PluginServiceImpl singleton.
77 static PluginServiceImpl* GetInstance();
[email protected]a0421732011-02-23 03:55:4078
[email protected]3a5180ae2011-12-21 02:39:3879 // content::PluginService implementation:
80 virtual void Init() OVERRIDE;
81 virtual void StartWatchingPlugins() OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:3882 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]df02aca2012-02-09 21:03:2090 content::ResourceContext* context,
[email protected]3a5180ae2011-12-21 02:39:3891 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;
[email protected]8be45842012-04-13 19:49:29100 virtual string16 GetPluginDisplayNameByPath(const FilePath& path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38101 virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE;
102 virtual void GetPluginGroups(
103 const GetPluginGroupsCallback& callback) OVERRIDE;
104 virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
105 const FilePath& plugin_path) OVERRIDE;
106 virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE;
107 virtual content::PluginServiceFilter* GetFilter() OVERRIDE;
[email protected]b6a2f8de2012-01-31 17:28:49108 virtual void ForcePluginShutdown(const FilePath& plugin_path) OVERRIDE;
[email protected]47214d882012-02-29 06:28:48109 virtual bool IsPluginUnstable(const FilePath& plugin_path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38110 virtual void RefreshPlugins() OVERRIDE;
111 virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE;
[email protected]c6f3dea2012-01-14 02:23:11112 virtual void AddExtraPluginDir(const FilePath& path) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38113 virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE;
114 virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE;
115 virtual void RegisterInternalPlugin(
[email protected]c6f3dea2012-01-14 02:23:11116 const webkit::WebPluginInfo& info, bool add_at_beginning) OVERRIDE;
[email protected]3a5180ae2011-12-21 02:39:38117 virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE;
118 virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE;
[email protected]e67385f2011-12-21 06:00:56119 virtual void SetPluginListForTesting(
120 webkit::npapi::PluginList* plugin_list) OVERRIDE;
[email protected]dfba8762011-09-02 12:49:54121
[email protected]a0421732011-02-23 03:55:40122 // 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]d259a8e2011-05-18 22:31:09129 const FilePath& plugin_path,
[email protected]a50432d2011-09-30 16:32:14130 PpapiPluginProcessHost::PluginClient* client);
131 PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess(
[email protected]eb415bf0e2011-04-14 02:45:42132 const FilePath& plugin_path);
[email protected]a0421732011-02-23 03:55:40133
134 // Opens a channel to a plugin process for the given mime type, starting
135 // a new plugin process if necessary. This must be called on the IO thread
136 // or else a deadlock can occur.
137 void OpenChannelToNpapiPlugin(int render_process_id,
138 int render_view_id,
139 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54140 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40141 const std::string& mime_type,
142 PluginProcessHost::Client* client);
143 void OpenChannelToPpapiPlugin(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14144 PpapiPluginProcessHost::PluginClient* client);
[email protected]eb415bf0e2011-04-14 02:45:42145 void OpenChannelToPpapiBroker(const FilePath& path,
[email protected]a50432d2011-09-30 16:32:14146 PpapiPluginProcessHost::BrokerClient* client);
[email protected]a0421732011-02-23 03:55:40147
[email protected]4befe7592011-09-14 22:49:09148 // Cancels opening a channel to a NPAPI plugin.
149 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
150
[email protected]47214d882012-02-29 06:28:48151 // Used to monitor plug-in stability.
152 void RegisterPluginCrash(const FilePath& plugin_path);
153
[email protected]a0421732011-02-23 03:55:40154 private:
[email protected]e67385f2011-12-21 06:00:56155 friend struct DefaultSingletonTraits<PluginServiceImpl>;
[email protected]a0421732011-02-23 03:55:40156
[email protected]e67385f2011-12-21 06:00:56157 // Creates the PluginServiceImpl object, but doesn't actually build the plugin
[email protected]a0421732011-02-23 03:55:40158 // list yet. It's generated lazily.
[email protected]e67385f2011-12-21 06:00:56159 PluginServiceImpl();
160 virtual ~PluginServiceImpl();
[email protected]a0421732011-02-23 03:55:40161
162 // base::WaitableEventWatcher::Delegate implementation.
[email protected]edc64de2011-11-17 20:07:38163 virtual void OnWaitableEventSignaled(
164 base::WaitableEvent* waitable_event) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40165
[email protected]6c2381d2011-10-19 02:52:53166 // content::NotificationObserver implementation
[email protected]edc64de2011-11-17 20:07:38167 virtual void Observe(int type,
168 const content::NotificationSource& source,
169 const content::NotificationDetails& details) OVERRIDE;
[email protected]a0421732011-02-23 03:55:40170
[email protected]b6a2f8de2012-01-31 17:28:49171 // Returns the plugin process host corresponding to the plugin process that
172 // has been started by this service. Returns NULL if no process has been
173 // started.
174 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
175 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
176 PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
177
[email protected]a0421732011-02-23 03:55:40178 void RegisterPepperPlugins();
179
[email protected]d33e7cc2011-09-23 01:43:56180 // Function that is run on the FILE thread to load the plugins synchronously.
181 void GetPluginsInternal(base::MessageLoopProxy* target_loop,
182 const GetPluginsCallback& callback);
183
[email protected]88ca4912011-10-12 14:00:43184 // Binding directly to GetAllowedPluginForOpenChannelToPlugin() isn't possible
185 // because more arity is needed <http://crbug.com/98542>. This just forwards.
186 void ForwardGetAllowedPluginForOpenChannelToPlugin(
[email protected]209f2ae2012-03-13 01:28:08187 const PluginServiceFilterParams& params,
[email protected]88ca4912011-10-12 14:00:43188 const GURL& url,
189 const std::string& mime_type,
190 PluginProcessHost::Client* client,
191 const std::vector<webkit::WebPluginInfo>&);
[email protected]a0421732011-02-23 03:55:40192 // Helper so we can do the plugin lookup on the FILE thread.
193 void GetAllowedPluginForOpenChannelToPlugin(
194 int render_process_id,
195 int render_view_id,
196 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54197 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40198 const std::string& mime_type,
[email protected]87c4be42011-09-16 01:10:59199 PluginProcessHost::Client* client,
[email protected]df02aca2012-02-09 21:03:20200 content::ResourceContext* resource_context);
[email protected]a0421732011-02-23 03:55:40201
202 // Helper so we can finish opening the channel after looking up the
203 // plugin.
204 void FinishOpenChannelToPlugin(
205 const FilePath& plugin_path,
206 PluginProcessHost::Client* client);
207
[email protected]3b48dbc2012-01-06 16:34:17208#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]a0421732011-02-23 03:55:40209 // Registers a new FilePathWatcher for a given path.
210 static void RegisterFilePathWatcher(
[email protected]493c8002011-04-14 16:56:01211 base::files::FilePathWatcher* watcher,
[email protected]a0421732011-02-23 03:55:40212 const FilePath& path,
[email protected]493c8002011-04-14 16:56:01213 base::files::FilePathWatcher::Delegate* delegate);
[email protected]a0421732011-02-23 03:55:40214#endif
215
[email protected]ee066172011-11-10 23:20:05216 // The plugin list instance.
217 webkit::npapi::PluginList* plugin_list_;
218
[email protected]6c2381d2011-10-19 02:52:53219 content::NotificationRegistrar registrar_;
[email protected]a0421732011-02-23 03:55:40220
[email protected]a0421732011-02-23 03:55:40221#if defined(OS_WIN)
222 // Registry keys for getting notifications when new plugins are installed.
223 base::win::RegKey hkcu_key_;
224 base::win::RegKey hklm_key_;
225 scoped_ptr<base::WaitableEvent> hkcu_event_;
226 scoped_ptr<base::WaitableEvent> hklm_event_;
227 base::WaitableEventWatcher hkcu_watcher_;
228 base::WaitableEventWatcher hklm_watcher_;
229#endif
230
[email protected]3b48dbc2012-01-06 16:34:17231#if defined(OS_POSIX) && !defined(OS_OPENBSD)
[email protected]493c8002011-04-14 16:56:01232 ScopedVector<base::files::FilePathWatcher> file_watchers_;
[email protected]a0421732011-02-23 03:55:40233 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
234#endif
235
[email protected]738a7212011-10-21 17:33:52236 std::vector<content::PepperPluginInfo> ppapi_plugins_;
[email protected]a0421732011-02-23 03:55:40237
[email protected]dfba8762011-09-02 12:49:54238 // Weak pointer; outlives us.
239 content::PluginServiceFilter* filter_;
[email protected]a0421732011-02-23 03:55:40240
[email protected]4befe7592011-09-14 22:49:09241 std::set<PluginProcessHost::Client*> pending_plugin_clients_;
242
[email protected]d4af1e72011-10-21 17:45:43243#if defined(OS_POSIX)
244 scoped_refptr<PluginLoaderPosix> plugin_loader_;
245#endif
246
[email protected]47214d882012-02-29 06:28:48247 // Used to detect if a given plug-in is crashing over and over.
248 std::map<FilePath, std::vector<base::Time> > crash_times_;
249
[email protected]e67385f2011-12-21 06:00:56250 DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl);
[email protected]a0421732011-02-23 03:55:40251};
252
[email protected]e67385f2011-12-21 06:00:56253#endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_