blob: 23ef03b1580471589567dceb44ed4f76e20a7423 [file] [log] [blame]
[email protected]a0421732011-02-23 03:55:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
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
8#ifndef CONTENT_BROWSER_PLUGIN_SERVICE_H_
9#define CONTENT_BROWSER_PLUGIN_SERVICE_H_
10#pragma once
11
12#include <string>
[email protected]6b14feb2011-08-16 11:22:5613#include <vector>
[email protected]a0421732011-02-23 03:55:4014
15#include "base/basictypes.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]eb415bf0e2011-04-14 02:45:4222#include "content/browser/ppapi_broker_process_host.h"
[email protected]8d128d62011-09-13 22:11:5723#include "content/common/content_export.h"
[email protected]7f070d42011-03-09 20:25:3224#include "content/common/notification_observer.h"
25#include "content/common/notification_registrar.h"
[email protected]a0421732011-02-23 03:55:4026#include "googleurl/src/gurl.h"
27#include "ipc/ipc_channel_handle.h"
[email protected]91d9f3d2011-08-14 05:24:4428#include "webkit/plugins/webplugininfo.h"
[email protected]a0421732011-02-23 03:55:4029
30#if defined(OS_WIN)
[email protected]3b63f8f42011-03-28 01:54:1531#include "base/memory/scoped_ptr.h"
[email protected]a0421732011-02-23 03:55:4032#include "base/win/registry.h"
33#endif
34
[email protected]e63c4d72011-05-31 22:38:2935#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]493c8002011-04-14 16:56:0136#include "base/files/file_path_watcher.h"
[email protected]a0421732011-02-23 03:55:4037#endif
38
[email protected]a0421732011-02-23 03:55:4039struct PepperPluginInfo;
40class PluginDirWatcherDelegate;
[email protected]a0421732011-02-23 03:55:4041
[email protected]dfba8762011-09-02 12:49:5442namespace content {
43class ResourceContext;
44class PluginServiceFilter;
45}
46
[email protected]a0421732011-02-23 03:55:4047// This must be created on the main thread but it's only called on the IO/file
48// thread.
[email protected]8d128d62011-09-13 22:11:5749class CONTENT_EXPORT PluginService
[email protected]a0421732011-02-23 03:55:4050 : public base::WaitableEventWatcher::Delegate,
51 public NotificationObserver {
52 public:
53 struct OverriddenPlugin {
54 int render_process_id;
55 int render_view_id;
[email protected]6b14feb2011-08-16 11:22:5656 GURL url; // If empty, the override applies to all urls in render_view.
[email protected]91d9f3d2011-08-14 05:24:4457 webkit::WebPluginInfo plugin;
[email protected]a0421732011-02-23 03:55:4058 };
59
[email protected]a0421732011-02-23 03:55:4060 // Returns the PluginService singleton.
61 static PluginService* GetInstance();
62
[email protected]dfba8762011-09-02 12:49:5463 // Starts watching for changes in the list of installed plug-ins.
64 void StartWatchingPlugins();
65
[email protected]a0421732011-02-23 03:55:4066 // Gets the browser's UI locale.
67 const std::string& GetUILocale();
68
69 // Returns the plugin process host corresponding to the plugin process that
70 // has been started by this service. Returns NULL if no process has been
71 // started.
72 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
73 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:4274 PpapiBrokerProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
[email protected]a0421732011-02-23 03:55:4075
76 // Returns the plugin process host corresponding to the plugin process that
77 // has been started by this service. This will start a process to host the
78 // 'plugin_path' if needed. If the process fails to start, the return value
79 // is NULL. Must be called on the IO thread.
80 PluginProcessHost* FindOrStartNpapiPluginProcess(
81 const FilePath& plugin_path);
82 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
[email protected]d259a8e2011-05-18 22:31:0983 const FilePath& plugin_path,
84 PpapiPluginProcessHost::Client* client);
[email protected]eb415bf0e2011-04-14 02:45:4285 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess(
86 const FilePath& plugin_path);
[email protected]a0421732011-02-23 03:55:4087
88 // Opens a channel to a plugin process for the given mime type, starting
89 // a new plugin process if necessary. This must be called on the IO thread
90 // or else a deadlock can occur.
91 void OpenChannelToNpapiPlugin(int render_process_id,
92 int render_view_id,
93 const GURL& url,
[email protected]dfba8762011-09-02 12:49:5494 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:4095 const std::string& mime_type,
96 PluginProcessHost::Client* client);
97 void OpenChannelToPpapiPlugin(const FilePath& path,
98 PpapiPluginProcessHost::Client* client);
[email protected]eb415bf0e2011-04-14 02:45:4299 void OpenChannelToPpapiBroker(const FilePath& path,
100 PpapiBrokerProcessHost::Client* client);
[email protected]a0421732011-02-23 03:55:40101
[email protected]4befe7592011-09-14 22:49:09102 // Cancels opening a channel to a NPAPI plugin.
103 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
104
[email protected]11e1c182011-05-17 20:26:27105 // Gets the plugin in the list of plugins that matches the given url and mime
[email protected]dfba8762011-09-02 12:49:54106 // type. Must be called on the FILE thread if |use_stale| is NULL.
[email protected]11e1c182011-05-17 20:26:27107 bool GetPluginInfo(int render_process_id,
108 int render_view_id,
[email protected]dfba8762011-09-02 12:49:54109 const content::ResourceContext& context,
[email protected]11e1c182011-05-17 20:26:27110 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54111 const GURL& page_url,
[email protected]11e1c182011-05-17 20:26:27112 const std::string& mime_type,
[email protected]dfba8762011-09-02 12:49:54113 bool allow_wildcard,
114 bool* use_stale,
[email protected]91d9f3d2011-08-14 05:24:44115 webkit::WebPluginInfo* info,
[email protected]11e1c182011-05-17 20:26:27116 std::string* actual_mime_type);
[email protected]a0421732011-02-23 03:55:40117
[email protected]dfba8762011-09-02 12:49:54118 // Returns a list of all plug-ins available to the resource context. Must be
119 // called on the FILE thread.
120 void GetPlugins(const content::ResourceContext& context,
121 std::vector<webkit::WebPluginInfo>* plugins);
[email protected]2de307592011-04-05 21:16:58122
123 // Tells all the renderer processes to throw away their cache of the plugin
124 // list, and optionally also reload all the pages with plugins.
125 // NOTE: can only be called on the UI thread.
126 static void PurgePluginListCache(bool reload_pages);
127
[email protected]dfba8762011-09-02 12:49:54128 void set_filter(content::PluginServiceFilter* filter) {
129 filter_ = filter;
130 }
131
[email protected]a0421732011-02-23 03:55:40132 private:
133 friend struct DefaultSingletonTraits<PluginService>;
134
135 // Creates the PluginService object, but doesn't actually build the plugin
136 // list yet. It's generated lazily.
137 PluginService();
[email protected]3690ebe02011-05-25 09:08:19138 virtual ~PluginService();
[email protected]a0421732011-02-23 03:55:40139
140 // base::WaitableEventWatcher::Delegate implementation.
141 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event);
142
143 // NotificationObserver implementation
[email protected]432115822011-07-10 15:52:27144 virtual void Observe(int type, const NotificationSource& source,
[email protected]a0421732011-02-23 03:55:40145 const NotificationDetails& details);
146
147 void RegisterPepperPlugins();
148
[email protected]eb415bf0e2011-04-14 02:45:42149 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path);
150
[email protected]a0421732011-02-23 03:55:40151 // Helper so we can do the plugin lookup on the FILE thread.
152 void GetAllowedPluginForOpenChannelToPlugin(
153 int render_process_id,
154 int render_view_id,
155 const GURL& url,
[email protected]dfba8762011-09-02 12:49:54156 const GURL& page_url,
[email protected]a0421732011-02-23 03:55:40157 const std::string& mime_type,
158 PluginProcessHost::Client* client);
159
160 // Helper so we can finish opening the channel after looking up the
161 // plugin.
162 void FinishOpenChannelToPlugin(
163 const FilePath& plugin_path,
164 PluginProcessHost::Client* client);
165
[email protected]e63c4d72011-05-31 22:38:29166#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a0421732011-02-23 03:55:40167 // Registers a new FilePathWatcher for a given path.
168 static void RegisterFilePathWatcher(
[email protected]493c8002011-04-14 16:56:01169 base::files::FilePathWatcher* watcher,
[email protected]a0421732011-02-23 03:55:40170 const FilePath& path,
[email protected]493c8002011-04-14 16:56:01171 base::files::FilePathWatcher::Delegate* delegate);
[email protected]a0421732011-02-23 03:55:40172#endif
173
[email protected]a0421732011-02-23 03:55:40174 // The browser's UI locale.
175 const std::string ui_locale_;
176
[email protected]a0421732011-02-23 03:55:40177 NotificationRegistrar registrar_;
178
[email protected]a0421732011-02-23 03:55:40179#if defined(OS_WIN)
180 // Registry keys for getting notifications when new plugins are installed.
181 base::win::RegKey hkcu_key_;
182 base::win::RegKey hklm_key_;
183 scoped_ptr<base::WaitableEvent> hkcu_event_;
184 scoped_ptr<base::WaitableEvent> hklm_event_;
185 base::WaitableEventWatcher hkcu_watcher_;
186 base::WaitableEventWatcher hklm_watcher_;
187#endif
188
[email protected]e63c4d72011-05-31 22:38:29189#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]493c8002011-04-14 16:56:01190 ScopedVector<base::files::FilePathWatcher> file_watchers_;
[email protected]a0421732011-02-23 03:55:40191 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
192#endif
193
194 std::vector<PepperPluginInfo> ppapi_plugins_;
195
[email protected]dfba8762011-09-02 12:49:54196 // Weak pointer; outlives us.
197 content::PluginServiceFilter* filter_;
[email protected]a0421732011-02-23 03:55:40198
[email protected]4befe7592011-09-14 22:49:09199 std::set<PluginProcessHost::Client*> pending_plugin_clients_;
200
[email protected]a0421732011-02-23 03:55:40201 DISALLOW_COPY_AND_ASSIGN(PluginService);
202};
203
204DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService);
205
206#endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_