blob: a2c3170baf5bf42479f872bca329e4ae80415950 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 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#include "content/browser/plugin_service_impl.h"
6
7#include "base/bind.h"
8#include "base/command_line.h"
9#include "base/compiler_specific.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000010#include "base/files/file_path.h"
Ben Murdoch9ab55632013-07-18 11:57:30 +010011#include "base/message_loop/message_loop.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010012#include "base/message_loop/message_loop_proxy.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013#include "base/metrics/histogram.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014#include "base/path_service.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010015#include "base/strings/string_util.h"
16#include "base/strings/utf_string_conversions.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "base/synchronization/waitable_event.h"
18#include "base/threading/thread.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019#include "content/browser/ppapi_plugin_process_host.h"
20#include "content/browser/renderer_host/render_process_host_impl.h"
21#include "content/browser/renderer_host/render_view_host_impl.h"
Ben Murdochbbcdd452013-07-25 10:06:34 +010022#include "content/common/pepper_plugin_list.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010023#include "content/common/plugin_list.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000024#include "content/common/view_messages.h"
25#include "content/public/browser/browser_thread.h"
26#include "content/public/browser/content_browser_client.h"
27#include "content/public/browser/plugin_service_filter.h"
28#include "content/public/browser/resource_context.h"
Ben Murdochba5b9a62013-08-12 14:20:17 +010029#include "content/public/common/content_constants.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030#include "content/public/common/content_switches.h"
31#include "content/public/common/process_type.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010032#include "content/public/common/webplugininfo.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000033
34#if defined(OS_WIN)
Ben Murdochca12bfa2013-07-23 11:17:05 +010035#include "content/common/plugin_constants_win.h"
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +010036#include "ui/gfx/win/hwnd_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000037#endif
38
39#if defined(OS_POSIX)
40#include "content/browser/plugin_loader_posix.h"
41#endif
42
43#if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000044using ::base::FilePathWatcher;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000045#endif
46
47namespace content {
48namespace {
49
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000050// This enum is used to collect Flash usage data.
51enum FlashUsage {
52 // Number of browser processes that have started at least one NPAPI Flash
53 // process during their lifetime.
54 START_NPAPI_FLASH_AT_LEAST_ONCE,
55 // Number of browser processes that have started at least one PPAPI Flash
56 // process during their lifetime.
57 START_PPAPI_FLASH_AT_LEAST_ONCE,
58 // Total number of browser processes.
59 TOTAL_BROWSER_PROCESSES,
60 FLASH_USAGE_ENUM_COUNT
61};
62
63bool LoadPluginListInProcess() {
64#if defined(OS_WIN)
65 return true;
66#else
67 // If on POSIX, we don't want to load the list of NPAPI plugins in-process as
68 // that causes instability.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010069
70 // Can't load the plugins on the utility thread when in single process mode
71 // since that requires GTK which can only be used on the main thread.
72 if (RenderProcessHost::run_renderer_in_process())
73 return true;
74
Ben Murdochca12bfa2013-07-23 11:17:05 +010075 return !PluginService::GetInstance()->NPAPIPluginsSupported();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000076#endif
77}
78
Torne (Richard Coles)58218062012-11-14 11:43:16 +000079// Callback set on the PluginList to assert that plugin loading happens on the
80// correct thread.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000081void WillLoadPluginsCallback(
Torne (Richard Coles)58218062012-11-14 11:43:16 +000082 base::SequencedWorkerPool::SequenceToken token) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000083 if (LoadPluginListInProcess()) {
84 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
85 token));
86 } else {
87 CHECK(false) << "Plugin loading should happen out-of-process.";
88 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000089}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000090
91#if defined(OS_MACOSX)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000092void NotifyPluginsOfActivation() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000093 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
94
95 for (PluginProcessHostIterator iter; !iter.Done(); ++iter)
96 iter->OnAppActivation();
97}
98#endif
Torne (Richard Coles)58218062012-11-14 11:43:16 +000099
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000100#if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
101void NotifyPluginDirChanged(const base::FilePath& path, bool error) {
102 if (error) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000103 // TODO(pastarmovj): Add some sensible error handling. Maybe silently
104 // stopping the watcher would be enough. Or possibly restart it.
105 NOTREACHED();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000106 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000107 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000108 VLOG(1) << "Watched path changed: " << path.value();
109 // Make the plugin list update itself
Ben Murdochca12bfa2013-07-23 11:17:05 +0100110 PluginList::Singleton()->RefreshPlugins();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000111 BrowserThread::PostTask(
112 BrowserThread::UI, FROM_HERE,
113 base::Bind(&PluginService::PurgePluginListCache,
114 static_cast<BrowserContext*>(NULL), false));
115}
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000116#endif
117
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000118void ForwardCallback(base::MessageLoopProxy* target_loop,
119 const PluginService::GetPluginsCallback& callback,
120 const std::vector<WebPluginInfo>& plugins) {
121 target_loop->PostTask(FROM_HERE, base::Bind(callback, plugins));
122}
123
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000124} // namespace
125
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000126// static
127PluginService* PluginService::GetInstance() {
128 return PluginServiceImpl::GetInstance();
129}
130
131void PluginService::PurgePluginListCache(BrowserContext* browser_context,
132 bool reload_pages) {
133 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
134 !it.IsAtEnd(); it.Advance()) {
135 RenderProcessHost* host = it.GetCurrentValue();
136 if (!browser_context || host->GetBrowserContext() == browser_context)
137 host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
138 }
139}
140
141// static
142PluginServiceImpl* PluginServiceImpl::GetInstance() {
143 return Singleton<PluginServiceImpl>::get();
144}
145
146PluginServiceImpl::PluginServiceImpl()
Ben Murdochca12bfa2013-07-23 11:17:05 +0100147 : filter_(NULL) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000148 // Collect the total number of browser processes (which create
149 // PluginServiceImpl objects, to be precise). The number is used to normalize
150 // the number of processes which start at least one NPAPI/PPAPI Flash process.
151 static bool counted = false;
152 if (!counted) {
153 counted = true;
154 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES,
155 FLASH_USAGE_ENUM_COUNT);
156 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000157}
158
159PluginServiceImpl::~PluginServiceImpl() {
160#if defined(OS_WIN)
161 // Release the events since they're owned by RegKey, not WaitableEvent.
162 hkcu_watcher_.StopWatching();
163 hklm_watcher_.StopWatching();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100164 if (hkcu_event_)
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000165 hkcu_event_->Release();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100166 if (hklm_event_)
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000167 hklm_event_->Release();
168#endif
169 // Make sure no plugin channel requests have been leaked.
170 DCHECK(pending_plugin_clients_.empty());
171}
172
173void PluginServiceImpl::Init() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000174 plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
Ben Murdochca12bfa2013-07-23 11:17:05 +0100175 PluginList::Singleton()->set_will_load_plugins_callback(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000176 base::Bind(&WillLoadPluginsCallback, plugin_list_token_));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000177
178 RegisterPepperPlugins();
179
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000180 // Load any specified on the command line as well.
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000181 const CommandLine* command_line = CommandLine::ForCurrentProcess();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000182 base::FilePath path =
183 command_line->GetSwitchValuePath(switches::kLoadPlugin);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000184 if (!path.empty())
185 AddExtraPluginPath(path);
186 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
187 if (!path.empty())
Ben Murdochca12bfa2013-07-23 11:17:05 +0100188 PluginList::Singleton()->AddExtraPluginDir(path);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100189
190 if (command_line->HasSwitch(switches::kDisablePluginsDiscovery))
Ben Murdochca12bfa2013-07-23 11:17:05 +0100191 PluginList::Singleton()->DisablePluginsDiscovery();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000192}
193
194void PluginServiceImpl::StartWatchingPlugins() {
195 // Start watching for changes in the plugin list. This means watching
196 // for changes in the Windows registry keys and on both Windows and POSIX
197 // watch for changes in the paths that are expected to contain plugins.
198#if defined(OS_WIN)
199 if (hkcu_key_.Create(HKEY_CURRENT_USER,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100200 kRegistryMozillaPlugins,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000201 KEY_NOTIFY) == ERROR_SUCCESS) {
202 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) {
203 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000204 base::WaitableEventWatcher::EventCallback callback =
205 base::Bind(&PluginServiceImpl::OnWaitableEventSignaled,
206 base::Unretained(this));
207 hkcu_watcher_.StartWatching(hkcu_event_.get(), callback);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000208 }
209 }
210 if (hklm_key_.Create(HKEY_LOCAL_MACHINE,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100211 kRegistryMozillaPlugins,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000212 KEY_NOTIFY) == ERROR_SUCCESS) {
213 if (hklm_key_.StartWatching() == ERROR_SUCCESS) {
214 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000215 base::WaitableEventWatcher::EventCallback callback =
216 base::Bind(&PluginServiceImpl::OnWaitableEventSignaled,
217 base::Unretained(this));
218 hklm_watcher_.StartWatching(hklm_event_.get(), callback);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000219 }
220 }
221#endif
222#if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
223// On ChromeOS the user can't install plugins anyway and on Windows all
224// important plugins register themselves in the registry so no need to do that.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000225
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000226 // Get the list of all paths for registering the FilePathWatchers
227 // that will track and if needed reload the list of plugins on runtime.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000228 std::vector<base::FilePath> plugin_dirs;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100229 PluginList::Singleton()->GetPluginDirectories(&plugin_dirs);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000230
231 for (size_t i = 0; i < plugin_dirs.size(); ++i) {
232 // FilePathWatcher can not handle non-absolute paths under windows.
233 // We don't watch for file changes in windows now but if this should ever
234 // be extended to Windows these lines might save some time of debugging.
235#if defined(OS_WIN)
236 if (!plugin_dirs[i].IsAbsolute())
237 continue;
238#endif
239 FilePathWatcher* watcher = new FilePathWatcher();
240 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value();
241 BrowserThread::PostTask(
242 BrowserThread::FILE, FROM_HERE,
243 base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000244 plugin_dirs[i]));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000245 file_watchers_.push_back(watcher);
246 }
247#endif
248}
249
250PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000251 const base::FilePath& plugin_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000252 for (PluginProcessHostIterator iter; !iter.Done(); ++iter) {
253 if (iter->info().path == plugin_path)
254 return *iter;
255 }
256
257 return NULL;
258}
259
260PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000261 const base::FilePath& plugin_path,
262 const base::FilePath& profile_data_directory) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000263 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
264 if (iter->plugin_path() == plugin_path &&
265 iter->profile_data_directory() == profile_data_directory) {
266 return *iter;
267 }
268 }
269 return NULL;
270}
271
272PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000273 const base::FilePath& broker_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000274 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) {
275 if (iter->plugin_path() == broker_path)
276 return *iter;
277 }
278
279 return NULL;
280}
281
282PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000283 int render_process_id,
284 const base::FilePath& plugin_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
286
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000287 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
288 return NULL;
289
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000290 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path);
291 if (plugin_host)
292 return plugin_host;
293
Ben Murdochca12bfa2013-07-23 11:17:05 +0100294 WebPluginInfo info;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000295 if (!GetPluginInfoByPath(plugin_path, &info)) {
296 return NULL;
297 }
298
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000299 // Record when NPAPI Flash process is started for the first time.
300 static bool counted = false;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000301 if (!counted && base::UTF16ToUTF8(info.name) == kFlashPluginName) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000302 counted = true;
303 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage",
304 START_NPAPI_FLASH_AT_LEAST_ONCE,
305 FLASH_USAGE_ENUM_COUNT);
306 }
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000307#if defined(OS_CHROMEOS)
308 // TODO(ihf): Move to an earlier place once crbug.com/314301 is fixed. For now
309 // we still want Plugin.FlashUsage recorded if we end up here.
310 LOG(WARNING) << "Refusing to start npapi plugin on ChromeOS.";
311 return NULL;
312#endif
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000313 // This plugin isn't loaded by any plugin process, so create a new process.
314 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost());
315 if (!new_host->Init(info)) {
316 NOTREACHED(); // Init is not expected to fail.
317 return NULL;
318 }
319 return new_host.release();
320}
321
322PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000323 int render_process_id,
324 const base::FilePath& plugin_path,
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100325 const base::FilePath& profile_data_directory) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
327
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000328 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) {
329 VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000330 return NULL;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000331 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000332
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000333 PpapiPluginProcessHost* plugin_host =
334 FindPpapiPluginProcess(plugin_path, profile_data_directory);
335 if (plugin_host)
336 return plugin_host;
337
338 // Validate that the plugin is actually registered.
339 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000340 if (!info) {
341 VLOG(1) << "Unable to find ppapi plugin registration for: "
342 << plugin_path.MaybeAsASCII();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000343 return NULL;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000344 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000345
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000346 // Record when PPAPI Flash process is started for the first time.
347 static bool counted = false;
348 if (!counted && info->name == kFlashPluginName) {
349 counted = true;
350 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage",
351 START_PPAPI_FLASH_AT_LEAST_ONCE,
352 FLASH_USAGE_ENUM_COUNT);
353 }
354
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000355 // This plugin isn't loaded by any plugin process, so create a new process.
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000356 plugin_host = PpapiPluginProcessHost::CreatePluginHost(
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100357 *info, profile_data_directory);
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000358 if (!plugin_host) {
359 VLOG(1) << "Unable to create ppapi plugin process for: "
360 << plugin_path.MaybeAsASCII();
361 }
362
363 return plugin_host;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000364}
365
366PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000367 int render_process_id,
368 const base::FilePath& plugin_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
370
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000371 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
372 return NULL;
373
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000374 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path);
375 if (plugin_host)
376 return plugin_host;
377
378 // Validate that the plugin is actually registered.
379 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
380 if (!info)
381 return NULL;
382
383 // TODO(ddorwin): Uncomment once out of process is supported.
384 // DCHECK(info->is_out_of_process);
385
386 // This broker isn't loaded by any broker process, so create a new process.
387 return PpapiPluginProcessHost::CreateBrokerHost(*info);
388}
389
390void PluginServiceImpl::OpenChannelToNpapiPlugin(
391 int render_process_id,
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000392 int render_frame_id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000393 const GURL& url,
394 const GURL& page_url,
395 const std::string& mime_type,
396 PluginProcessHost::Client* client) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
398 DCHECK(!ContainsKey(pending_plugin_clients_, client));
399 pending_plugin_clients_.insert(client);
400
401 // Make sure plugins are loaded if necessary.
402 PluginServiceFilterParams params = {
403 render_process_id,
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000404 render_frame_id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000405 page_url,
406 client->GetResourceContext()
407 };
408 GetPlugins(base::Bind(
409 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin,
410 base::Unretained(this), params, url, mime_type, client));
411}
412
413void PluginServiceImpl::OpenChannelToPpapiPlugin(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000414 int render_process_id,
415 const base::FilePath& plugin_path,
416 const base::FilePath& profile_data_directory,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000417 PpapiPluginProcessHost::PluginClient* client) {
418 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100419 render_process_id, plugin_path, profile_data_directory);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000420 if (plugin_host) {
421 plugin_host->OpenChannelToPlugin(client);
422 } else {
423 // Send error.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000424 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000425 }
426}
427
428void PluginServiceImpl::OpenChannelToPpapiBroker(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000429 int render_process_id,
430 const base::FilePath& path,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000431 PpapiPluginProcessHost::BrokerClient* client) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000432 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(
433 render_process_id, path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000434 if (plugin_host) {
435 plugin_host->OpenChannelToPlugin(client);
436 } else {
437 // Send error.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000438 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000439 }
440}
441
442void PluginServiceImpl::CancelOpenChannelToNpapiPlugin(
443 PluginProcessHost::Client* client) {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
445 DCHECK(ContainsKey(pending_plugin_clients_, client));
446 pending_plugin_clients_.erase(client);
447}
448
449void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin(
450 const PluginServiceFilterParams& params,
451 const GURL& url,
452 const std::string& mime_type,
453 PluginProcessHost::Client* client,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100454 const std::vector<WebPluginInfo>&) {
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000455 GetAllowedPluginForOpenChannelToPlugin(
456 params.render_process_id, params.render_frame_id, url, params.page_url,
457 mime_type, client, params.resource_context);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000458}
459
460void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin(
461 int render_process_id,
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000462 int render_frame_id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000463 const GURL& url,
464 const GURL& page_url,
465 const std::string& mime_type,
466 PluginProcessHost::Client* client,
467 ResourceContext* resource_context) {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100468 WebPluginInfo info;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000469 bool allow_wildcard = true;
470 bool found = GetPluginInfo(
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000471 render_process_id, render_frame_id, resource_context,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000472 url, page_url, mime_type, allow_wildcard,
473 NULL, &info, NULL);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000474 base::FilePath plugin_path;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000475 if (found)
476 plugin_path = info.path;
477
478 // Now we jump back to the IO thread to finish opening the channel.
479 BrowserThread::PostTask(
480 BrowserThread::IO, FROM_HERE,
481 base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000482 base::Unretained(this),
483 render_process_id,
484 plugin_path,
485 client));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000486}
487
488void PluginServiceImpl::FinishOpenChannelToPlugin(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000489 int render_process_id,
490 const base::FilePath& plugin_path,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000491 PluginProcessHost::Client* client) {
492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
493
494 // Make sure it hasn't been canceled yet.
495 if (!ContainsKey(pending_plugin_clients_, client))
496 return;
497 pending_plugin_clients_.erase(client);
498
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000499 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(
500 render_process_id, plugin_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000501 if (plugin_host) {
502 client->OnFoundPluginProcessHost(plugin_host);
503 plugin_host->OpenChannelToPlugin(client);
504 } else {
505 client->OnError();
506 }
507}
508
509bool PluginServiceImpl::GetPluginInfoArray(
510 const GURL& url,
511 const std::string& mime_type,
512 bool allow_wildcard,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100513 std::vector<WebPluginInfo>* plugins,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000514 std::vector<std::string>* actual_mime_types) {
515 bool use_stale = false;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100516 PluginList::Singleton()->GetPluginInfoArray(
517 url, mime_type, allow_wildcard, &use_stale, NPAPIPluginsSupported(),
518 plugins, actual_mime_types);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000519 return use_stale;
520}
521
522bool PluginServiceImpl::GetPluginInfo(int render_process_id,
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000523 int render_frame_id,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000524 ResourceContext* context,
525 const GURL& url,
526 const GURL& page_url,
527 const std::string& mime_type,
528 bool allow_wildcard,
529 bool* is_stale,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100530 WebPluginInfo* info,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000531 std::string* actual_mime_type) {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100532 std::vector<WebPluginInfo> plugins;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000533 std::vector<std::string> mime_types;
534 bool stale = GetPluginInfoArray(
535 url, mime_type, allow_wildcard, &plugins, &mime_types);
536 if (is_stale)
537 *is_stale = stale;
538
539 for (size_t i = 0; i < plugins.size(); ++i) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000540 if (!filter_ || filter_->IsPluginAvailable(render_process_id,
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000541 render_frame_id,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000542 context,
543 url,
544 page_url,
545 &plugins[i])) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000546 *info = plugins[i];
547 if (actual_mime_type)
548 *actual_mime_type = mime_types[i];
549 return true;
550 }
551 }
552 return false;
553}
554
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000555bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path,
Ben Murdochca12bfa2013-07-23 11:17:05 +0100556 WebPluginInfo* info) {
557 std::vector<WebPluginInfo> plugins;
558 PluginList::Singleton()->GetPluginsNoRefresh(&plugins);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000559
Ben Murdochca12bfa2013-07-23 11:17:05 +0100560 for (std::vector<WebPluginInfo>::iterator it = plugins.begin();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000561 it != plugins.end();
562 ++it) {
563 if (it->path == plugin_path) {
564 *info = *it;
565 return true;
566 }
567 }
568
569 return false;
570}
571
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000572base::string16 PluginServiceImpl::GetPluginDisplayNameByPath(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000573 const base::FilePath& path) {
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000574 base::string16 plugin_name = path.LossyDisplayName();
Ben Murdochca12bfa2013-07-23 11:17:05 +0100575 WebPluginInfo info;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000576 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) &&
577 !info.name.empty()) {
578 plugin_name = info.name;
579#if defined(OS_MACOSX)
580 // Many plugins on the Mac have .plugin in the actual name, which looks
581 // terrible, so look for that and strip it off if present.
582 const std::string kPluginExtension = ".plugin";
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000583 if (EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension), true))
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000584 plugin_name.erase(plugin_name.length() - kPluginExtension.length());
585#endif // OS_MACOSX
586 }
587 return plugin_name;
588}
589
590void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) {
591 scoped_refptr<base::MessageLoopProxy> target_loop(
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100592 base::MessageLoop::current()->message_loop_proxy());
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000593
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000594 if (LoadPluginListInProcess()) {
595 BrowserThread::GetBlockingPool()->
596 PostSequencedWorkerTaskWithShutdownBehavior(
597 plugin_list_token_,
598 FROM_HERE,
599 base::Bind(&PluginServiceImpl::GetPluginsInternal,
600 base::Unretained(this),
601 target_loop, callback),
602 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
603 return;
604 }
605#if defined(OS_POSIX)
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000606 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
607 base::Bind(&PluginServiceImpl::GetPluginsOnIOThread,
608 base::Unretained(this), target_loop, callback));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000609#else
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000610 NOTREACHED();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000611#endif
612}
613
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000614void PluginServiceImpl::GetPluginsInternal(
615 base::MessageLoopProxy* target_loop,
616 const PluginService::GetPluginsCallback& callback) {
617 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
618 plugin_list_token_));
619
Ben Murdochca12bfa2013-07-23 11:17:05 +0100620 std::vector<WebPluginInfo> plugins;
621 PluginList::Singleton()->GetPlugins(&plugins, NPAPIPluginsSupported());
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000622
623 target_loop->PostTask(FROM_HERE,
624 base::Bind(callback, plugins));
625}
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000626
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000627#if defined(OS_POSIX)
628void PluginServiceImpl::GetPluginsOnIOThread(
629 base::MessageLoopProxy* target_loop,
630 const GetPluginsCallback& callback) {
631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
632
633 // If we switch back to loading plugins in process, then we need to make
634 // sure g_thread_init() gets called since plugins may call glib at load.
635
636 if (!plugin_loader_)
637 plugin_loader_ = new PluginLoaderPosix;
638
639 plugin_loader_->GetPlugins(
640 base::Bind(&ForwardCallback, make_scoped_refptr(target_loop), callback));
641}
642#endif
643
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000644void PluginServiceImpl::OnWaitableEventSignaled(
645 base::WaitableEvent* waitable_event) {
646#if defined(OS_WIN)
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100647 if (waitable_event == hkcu_event_) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000648 hkcu_key_.StartWatching();
649 } else {
650 hklm_key_.StartWatching();
651 }
652
Ben Murdochca12bfa2013-07-23 11:17:05 +0100653 PluginList::Singleton()->RefreshPlugins();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000654 PurgePluginListCache(NULL, false);
655#else
656 // This event should only get signaled on a Windows machine.
657 NOTREACHED();
658#endif // defined(OS_WIN)
659}
660
661void PluginServiceImpl::RegisterPepperPlugins() {
Ben Murdochbbcdd452013-07-25 10:06:34 +0100662 ComputePepperPluginList(&ppapi_plugins_);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000663 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
664 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true);
665 }
666}
667
668// There should generally be very few plugins so a brute-force search is fine.
669PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000670 const base::FilePath& plugin_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000671 PepperPluginInfo* info = NULL;
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +0100672 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000673 if (ppapi_plugins_[i].path == plugin_path) {
674 info = &ppapi_plugins_[i];
675 break;
676 }
677 }
678 if (info)
679 return info;
680 // We did not find the plugin in our list. But wait! the plugin can also
681 // be a latecomer, as it happens with pepper flash. This information
682 // can be obtained from the PluginList singleton and we can use it to
683 // construct it and add it to the list. This same deal needs to be done
684 // in the renderer side in PepperPluginRegistry.
Ben Murdochca12bfa2013-07-23 11:17:05 +0100685 WebPluginInfo webplugin_info;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000686 if (!GetPluginInfoByPath(plugin_path, &webplugin_info))
687 return NULL;
688 PepperPluginInfo new_pepper_info;
689 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
690 return NULL;
691 ppapi_plugins_.push_back(new_pepper_info);
692 return &ppapi_plugins_[ppapi_plugins_.size() - 1];
693}
694
695#if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID)
696// static
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000697void PluginServiceImpl::RegisterFilePathWatcher(FilePathWatcher* watcher,
698 const base::FilePath& path) {
699 bool result = watcher->Watch(path, false,
700 base::Bind(&NotifyPluginDirChanged));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000701 DCHECK(result);
702}
703#endif
704
705void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) {
706 filter_ = filter;
707}
708
709PluginServiceFilter* PluginServiceImpl::GetFilter() {
710 return filter_;
711}
712
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000713void PluginServiceImpl::ForcePluginShutdown(const base::FilePath& plugin_path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000714 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
715 BrowserThread::PostTask(
716 BrowserThread::IO, FROM_HERE,
717 base::Bind(&PluginServiceImpl::ForcePluginShutdown,
718 base::Unretained(this), plugin_path));
719 return;
720 }
721
722 PluginProcessHost* plugin = FindNpapiPluginProcess(plugin_path);
723 if (plugin)
724 plugin->ForceShutdown();
725}
726
727static const unsigned int kMaxCrashesPerInterval = 3;
728static const unsigned int kCrashesInterval = 120;
729
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000730void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000732 std::map<base::FilePath, std::vector<base::Time> >::iterator i =
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000733 crash_times_.find(path);
734 if (i == crash_times_.end()) {
735 crash_times_[path] = std::vector<base::Time>();
736 i = crash_times_.find(path);
737 }
738 if (i->second.size() == kMaxCrashesPerInterval) {
739 i->second.erase(i->second.begin());
740 }
741 base::Time time = base::Time::Now();
742 i->second.push_back(time);
743}
744
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000745bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000747 std::map<base::FilePath, std::vector<base::Time> >::const_iterator i =
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000748 crash_times_.find(path);
749 if (i == crash_times_.end()) {
750 return false;
751 }
752 if (i->second.size() != kMaxCrashesPerInterval) {
753 return false;
754 }
755 base::TimeDelta delta = base::Time::Now() - i->second[0];
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100756 return delta.InSeconds() <= kCrashesInterval;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000757}
758
759void PluginServiceImpl::RefreshPlugins() {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100760 PluginList::Singleton()->RefreshPlugins();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000761}
762
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000763void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) {
Torne (Richard Coles)0de60732014-05-15 12:16:31 +0100764 if (!NPAPIPluginsSupported()) {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100765 // TODO(jam): remove and just have CHECK once we're sure this doesn't get
766 // triggered.
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000767 DVLOG(0) << "NPAPI plugins not supported";
Ben Murdochca12bfa2013-07-23 11:17:05 +0100768 return;
769 }
770 PluginList::Singleton()->AddExtraPluginPath(path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000771}
772
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000773void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100774 PluginList::Singleton()->RemoveExtraPluginPath(path);
775}
776
777void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) {
778 PluginList::Singleton()->AddExtraPluginDir(path);
779}
780
781void PluginServiceImpl::RegisterInternalPlugin(
782 const WebPluginInfo& info,
783 bool add_at_beginning) {
784 if (!NPAPIPluginsSupported() &&
785 info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) {
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000786 DVLOG(0) << "Don't register NPAPI plugins when they're not supported";
Ben Murdochca12bfa2013-07-23 11:17:05 +0100787 return;
788 }
789 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000790}
791
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000792void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) {
Ben Murdochca12bfa2013-07-23 11:17:05 +0100793 PluginList::Singleton()->UnregisterInternalPlugin(path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000794}
795
Ben Murdochca12bfa2013-07-23 11:17:05 +0100796void PluginServiceImpl::GetInternalPlugins(
797 std::vector<WebPluginInfo>* plugins) {
798 PluginList::Singleton()->GetInternalPlugins(plugins);
799}
800
801bool PluginServiceImpl::NPAPIPluginsSupported() {
Torne (Richard Coles)0de60732014-05-15 12:16:31 +0100802#if defined(OS_WIN) || defined(OS_MACOSX)
Ben Murdochca12bfa2013-07-23 11:17:05 +0100803 return true;
804#else
805 return false;
806#endif
807}
808
809void PluginServiceImpl::DisablePluginsDiscoveryForTesting() {
810 PluginList::Singleton()->DisablePluginsDiscovery();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000811}
812
813#if defined(OS_MACOSX)
814void PluginServiceImpl::AppActivated() {
815 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000816 base::Bind(&NotifyPluginsOfActivation));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000817}
Ben Murdochca12bfa2013-07-23 11:17:05 +0100818#elif defined(OS_WIN)
819
820bool GetPluginPropertyFromWindow(
821 HWND window, const wchar_t* plugin_atom_property,
822 base::string16* plugin_property) {
823 ATOM plugin_atom = reinterpret_cast<ATOM>(
824 GetPropW(window, plugin_atom_property));
825 if (plugin_atom != 0) {
826 WCHAR plugin_property_local[MAX_PATH] = {0};
827 GlobalGetAtomNameW(plugin_atom,
828 plugin_property_local,
829 ARRAYSIZE(plugin_property_local));
830 *plugin_property = plugin_property_local;
831 return true;
832 }
833 return false;
834}
835
836bool PluginServiceImpl::GetPluginInfoFromWindow(
837 HWND window,
838 base::string16* plugin_name,
839 base::string16* plugin_version) {
840 if (!IsPluginWindow(window))
841 return false;
842
843 GetPluginPropertyFromWindow(
844 window, kPluginNameAtomProperty, plugin_name);
845 GetPluginPropertyFromWindow(
846 window, kPluginVersionAtomProperty, plugin_version);
847 return true;
848}
849
850bool PluginServiceImpl::IsPluginWindow(HWND window) {
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +0100851 return gfx::GetClassName(window) == base::string16(kNativeWindowClassName);
Ben Murdochca12bfa2013-07-23 11:17:05 +0100852}
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000853#endif
854
Torne (Richard Coles)6d86b772014-06-25 10:30:53 +0100855bool PluginServiceImpl::PpapiDevChannelSupported(
856 BrowserContext* browser_context,
857 const GURL& document_url) {
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000858 return content::GetContentClient()->browser()->
Torne (Richard Coles)6d86b772014-06-25 10:30:53 +0100859 IsPluginAllowedToUseDevChannelAPIs(browser_context, document_url);
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000860}
861
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000862} // namespace content