blob: ee7cd8115827a4645c29abb5993f213f6b66cd5c [file] [log] [blame]
[email protected]cec1b8d2010-03-24 00:21:341// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]fd49e2d2009-02-20 17:21:305#include "build/build_config.h"
6
initial.commit09911bf2008-07-26 23:55:297#include "chrome/browser/plugin_service.h"
8
[email protected]d48f1e0c2009-02-12 20:57:549#include "base/command_line.h"
[email protected]9c49ff02010-01-27 01:20:5510#include "base/path_service.h"
[email protected]d70539de2009-06-24 22:17:0611#include "base/string_util.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/thread.h"
[email protected]be1ce6a72010-08-03 14:35:2213#include "base/utf_string_conversions.h"
[email protected]cec1b8d2010-03-24 00:21:3414#include "base/values.h"
[email protected]b547fd42009-04-23 23:16:2715#include "base/waitable_event.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/browser_process.h"
[email protected]017a7a112010-10-12 16:38:2717#include "chrome/browser/browser_thread.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/browser/chrome_plugin_host.h"
[email protected]eaa7dd182010-12-14 11:09:0019#include "chrome/browser/extensions/extension_service.h"
[email protected]0a8b1e22010-07-02 09:31:1120#include "chrome/browser/plugin_updater.h"
[email protected]37858e52010-08-26 00:22:0221#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3322#include "chrome/browser/profiles/profile.h"
[email protected]8c8657d62009-01-16 18:31:2623#include "chrome/browser/renderer_host/render_process_host.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/common/chrome_plugin_lib.h"
[email protected]9c49ff02010-01-27 01:20:5525#include "chrome/common/chrome_paths.h"
[email protected]d48f1e0c2009-02-12 20:57:5426#include "chrome/common/chrome_switches.h"
[email protected]2290cb862010-06-02 16:50:5827#include "chrome/common/default_plugin.h"
[email protected]5b1a0e22009-05-26 19:00:5828#include "chrome/common/extensions/extension.h"
[email protected]7477ea6f2009-12-22 23:28:1529#include "chrome/common/gpu_plugin.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/logging_chrome.h"
[email protected]894bb502009-05-21 22:39:5731#include "chrome/common/notification_type.h"
32#include "chrome/common/notification_service.h"
[email protected]4e0616e2010-05-28 14:55:5333#include "chrome/common/pepper_plugin_registry.h"
[email protected]4e59e812010-04-06 20:51:1634#include "chrome/common/plugin_messages.h"
[email protected]cec1b8d2010-03-24 00:21:3435#include "chrome/common/pref_names.h"
[email protected]b547fd42009-04-23 23:16:2736#include "chrome/common/render_messages.h"
[email protected]191eb3f72010-12-21 06:27:5037#include "webkit/plugins/npapi/plugin_constants_win.h"
38#include "webkit/plugins/npapi/plugin_list.h"
39#include "webkit/plugins/npapi/webplugininfo.h"
40
[email protected]d8c7cbcc2009-10-02 19:00:3141#ifndef DISABLE_NACL
[email protected]d032f492009-09-29 00:33:4642#include "native_client/src/trusted/plugin/nacl_entry_points.h"
[email protected]d8c7cbcc2009-10-02 19:00:3143#endif
[email protected]6fdd4182010-10-14 23:59:2644
45#if defined(OS_CHROMEOS)
46#include "chrome/browser/chromeos/plugin_selection_policy.h"
47#endif
initial.commit09911bf2008-07-26 23:55:2948
[email protected]a96ec6a2009-11-04 17:27:0849#if defined(OS_MACOSX)
50static void NotifyPluginsOfActivation() {
[email protected]f8b3ef82010-10-11 02:45:5251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]a96ec6a2009-11-04 17:27:0852
[email protected]d27893f62010-07-03 05:47:4253 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
[email protected]a96ec6a2009-11-04 17:27:0854 !iter.Done(); ++iter) {
55 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
56 plugin->OnAppActivation();
57 }
58}
59#endif
60
initial.commit09911bf2008-07-26 23:55:2961// static
[email protected]51549da2009-11-21 08:43:3962bool PluginService::enable_chrome_plugins_ = true;
63
[email protected]51549da2009-11-21 08:43:3964// static
[email protected]cec1b8d2010-03-24 00:21:3465void PluginService::InitGlobalInstance(Profile* profile) {
[email protected]f8b3ef82010-10-11 02:45:5266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]cec1b8d2010-03-24 00:21:3467
[email protected]0a8b1e22010-07-02 09:31:1168 // We first group the plugins and then figure out which groups to disable.
[email protected]8e8bb6d2010-12-13 08:18:5569 PluginUpdater::GetInstance()->DisablePluginGroupsFromPrefs(profile);
[email protected]7bf795d92010-05-22 00:14:2870
[email protected]cec1b8d2010-03-24 00:21:3471 // Have Chrome plugins write their data to the profile directory.
72 GetInstance()->SetChromePluginDataDir(profile->GetPath());
73}
74
75// static
initial.commit09911bf2008-07-26 23:55:2976PluginService* PluginService::GetInstance() {
77 return Singleton<PluginService>::get();
78}
79
[email protected]51549da2009-11-21 08:43:3980// static
81void PluginService::EnableChromePlugins(bool enable) {
82 enable_chrome_plugins_ = enable;
83}
84
initial.commit09911bf2008-07-26 23:55:2985PluginService::PluginService()
86 : main_message_loop_(MessageLoop::current()),
initial.commit09911bf2008-07-26 23:55:2987 resource_dispatcher_host_(NULL),
[email protected]f77d87622010-07-30 17:43:1788 ui_locale_(g_browser_process->GetApplicationLocale()) {
[email protected]4e0616e2010-05-28 14:55:5389 RegisterPepperPlugins();
90
initial.commit09911bf2008-07-26 23:55:2991 // Have the NPAPI plugin list search for Chrome plugins as well.
92 ChromePluginLib::RegisterPluginsWithNPAPI();
[email protected]9a1c4262010-06-29 21:50:2793
94 // Load any specified on the command line as well.
[email protected]d48f1e0c2009-02-12 20:57:5495 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]c4e52f0d2009-11-06 19:55:1696 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
[email protected]7bf795d92010-05-22 00:14:2897 if (!path.empty())
[email protected]191eb3f72010-12-21 06:27:5098 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]9a1c4262010-06-29 21:50:2799 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
100 if (!path.empty())
[email protected]191eb3f72010-12-21 06:27:50101 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path);
[email protected]7bf795d92010-05-22 00:14:28102
[email protected]2290cb862010-06-02 16:50:58103 chrome::RegisterInternalDefaultPlugin();
104
[email protected]7bf795d92010-05-22 00:14:28105 // Register the internal Flash and PDF, if available.
106 if (!CommandLine::ForCurrentProcess()->HasSwitch(
107 switches::kDisableInternalFlash) &&
108 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) {
[email protected]191eb3f72010-12-21 06:27:50109 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]35fa6a22009-08-15 00:04:01110 }
[email protected]d7ce4272010-03-27 01:06:01111
[email protected]d8c7cbcc2009-10-02 19:00:31112#ifndef DISABLE_NACL
[email protected]5cad70a82010-09-03 22:14:11113 if (command_line->HasSwitch(switches::kInternalNaCl)) {
114 RegisterInternalNaClPlugin();
115 }
[email protected]d8c7cbcc2009-10-02 19:00:31116#endif
[email protected]b547fd42009-04-23 23:16:27117
[email protected]6fdd4182010-10-14 23:59:26118#if defined(OS_CHROMEOS)
119 plugin_selection_policy_ = new chromeos::PluginSelectionPolicy;
120 plugin_selection_policy_->StartInit();
121#endif
122
[email protected]7477ea6f2009-12-22 23:28:15123 chrome::RegisterInternalGPUPlugin();
124
[email protected]b547fd42009-04-23 23:16:27125#if defined(OS_WIN)
126 hkcu_key_.Create(
[email protected]191eb3f72010-12-21 06:27:50127 HKEY_CURRENT_USER, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY);
[email protected]b547fd42009-04-23 23:16:27128 hklm_key_.Create(
[email protected]191eb3f72010-12-21 06:27:50129 HKEY_LOCAL_MACHINE, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY);
[email protected]b547fd42009-04-23 23:16:27130 if (hkcu_key_.StartWatching()) {
131 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
132 hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
133 }
134
135 if (hklm_key_.StartWatching()) {
136 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
137 hklm_watcher_.StartWatching(hklm_event_.get(), this);
138 }
[email protected]9c49ff02010-01-27 01:20:55139#elif defined(OS_POSIX) && !defined(OS_MACOSX)
140 // Also find plugins in a user-specific plugins dir,
141 // e.g. ~/.config/chromium/Plugins.
142 FilePath user_data_dir;
143 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
[email protected]191eb3f72010-12-21 06:27:50144 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(
[email protected]9c49ff02010-01-27 01:20:55145 user_data_dir.Append("Plugins"));
146 }
[email protected]b547fd42009-04-23 23:16:27147#endif
[email protected]894bb502009-05-21 22:39:57148
[email protected]ae09ca62009-08-21 19:46:46149 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
[email protected]894bb502009-05-21 22:39:57150 NotificationService::AllSources());
151 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
152 NotificationService::AllSources());
[email protected]a96ec6a2009-11-04 17:27:08153#if defined(OS_MACOSX)
154 // We need to know when the browser comes forward so we can bring modal plugin
155 // windows forward too.
156 registrar_.Add(this, NotificationType::APP_ACTIVATED,
157 NotificationService::AllSources());
158#endif
[email protected]5f101bbe2010-10-08 08:01:16159 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED,
160 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29161}
162
163PluginService::~PluginService() {
[email protected]b547fd42009-04-23 23:16:27164#if defined(OS_WIN)
165 // Release the events since they're owned by RegKey, not WaitableEvent.
166 hkcu_watcher_.StopWatching();
167 hklm_watcher_.StopWatching();
168 hkcu_event_->Release();
169 hklm_event_->Release();
170#endif
initial.commit09911bf2008-07-26 23:55:29171}
172
initial.commit09911bf2008-07-26 23:55:29173void PluginService::LoadChromePlugins(
174 ResourceDispatcherHost* resource_dispatcher_host) {
[email protected]51549da2009-11-21 08:43:39175 if (!enable_chrome_plugins_)
176 return;
177
initial.commit09911bf2008-07-26 23:55:29178 resource_dispatcher_host_ = resource_dispatcher_host;
179 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser());
180}
181
[email protected]f7011fcb2009-01-28 21:54:32182void PluginService::SetChromePluginDataDir(const FilePath& data_dir) {
initial.commit09911bf2008-07-26 23:55:29183 chrome_plugin_data_dir_ = data_dir;
184}
185
[email protected]f7011fcb2009-01-28 21:54:32186const FilePath& PluginService::GetChromePluginDataDir() {
initial.commit09911bf2008-07-26 23:55:29187 return chrome_plugin_data_dir_;
188}
189
[email protected]f77d87622010-07-30 17:43:17190const std::string& PluginService::GetUILocale() {
initial.commit09911bf2008-07-26 23:55:29191 return ui_locale_;
192}
193
[email protected]28ab7f92009-01-06 21:39:04194PluginProcessHost* PluginService::FindPluginProcess(
195 const FilePath& plugin_path) {
[email protected]f8b3ef82010-10-11 02:45:52196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29197
[email protected]d27893f62010-07-03 05:47:42198 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
[email protected]a436d922009-02-13 23:16:42199 !iter.Done(); ++iter) {
200 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
201 if (plugin->info().path == plugin_path)
202 return plugin;
203 }
204
initial.commit09911bf2008-07-26 23:55:29205 return NULL;
206}
207
208PluginProcessHost* PluginService::FindOrStartPluginProcess(
[email protected]610c0892009-09-08 19:46:18209 const FilePath& plugin_path) {
[email protected]f8b3ef82010-10-11 02:45:52210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29211
[email protected]8b8a554d2010-11-18 13:26:40212 PluginProcessHost* plugin_host = FindPluginProcess(plugin_path);
initial.commit09911bf2008-07-26 23:55:29213 if (plugin_host)
214 return plugin_host;
215
[email protected]191eb3f72010-12-21 06:27:50216 webkit::npapi::WebPluginInfo info;
217 if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath(
218 plugin_path, &info)) {
[email protected]a27a9382009-02-11 23:55:10219 return NULL;
220 }
221
initial.commit09911bf2008-07-26 23:55:29222 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]8b8a554d2010-11-18 13:26:40223 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost());
224 if (!new_host->Init(info, ui_locale_)) {
225 NOTREACHED(); // Init is not expected to fail
initial.commit09911bf2008-07-26 23:55:29226 return NULL;
227 }
[email protected]a436d922009-02-13 23:16:42228
[email protected]8b8a554d2010-11-18 13:26:40229 return new_host.release();
initial.commit09911bf2008-07-26 23:55:29230}
231
232void PluginService::OpenChannelToPlugin(
[email protected]610c0892009-09-08 19:46:18233 const GURL& url,
234 const std::string& mime_type,
[email protected]46b69e42010-11-02 12:26:39235 PluginProcessHost::Client* client) {
[email protected]6fdd4182010-10-14 23:59:26236 // The PluginList::GetFirstAllowedPluginInfo may need to load the
237 // plugins. Don't do it on the IO thread.
238 BrowserThread::PostTask(
239 BrowserThread::FILE, FROM_HERE,
240 NewRunnableMethod(
241 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin,
[email protected]46b69e42010-11-02 12:26:39242 url, mime_type, client));
[email protected]6fdd4182010-10-14 23:59:26243}
244
245void PluginService::GetAllowedPluginForOpenChannelToPlugin(
[email protected]6fdd4182010-10-14 23:59:26246 const GURL& url,
247 const std::string& mime_type,
[email protected]46b69e42010-11-02 12:26:39248 PluginProcessHost::Client* client) {
[email protected]6fdd4182010-10-14 23:59:26249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]191eb3f72010-12-21 06:27:50250 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26251 bool found = GetFirstAllowedPluginInfo(url, mime_type, &info, NULL);
252 FilePath plugin_path;
253 if (found && info.enabled)
254 plugin_path = FilePath(info.path);
255
256 // Now we jump back to the IO thread to finish opening the channel.
257 BrowserThread::PostTask(
258 BrowserThread::IO, FROM_HERE,
259 NewRunnableMethod(
260 this, &PluginService::FinishOpenChannelToPlugin,
[email protected]46b69e42010-11-02 12:26:39261 plugin_path, client));
[email protected]6fdd4182010-10-14 23:59:26262}
263
264void PluginService::FinishOpenChannelToPlugin(
[email protected]6fdd4182010-10-14 23:59:26265 const FilePath& plugin_path,
[email protected]46b69e42010-11-02 12:26:39266 PluginProcessHost::Client* client) {
[email protected]f8b3ef82010-10-11 02:45:52267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]20a793e2010-10-12 06:50:08268
[email protected]610c0892009-09-08 19:46:18269 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path);
[email protected]46b69e42010-11-02 12:26:39270 if (plugin_host)
271 plugin_host->OpenChannelToPlugin(client);
272 else
273 client->OnError();
initial.commit09911bf2008-07-26 23:55:29274}
275
[email protected]6fdd4182010-10-14 23:59:26276bool PluginService::GetFirstAllowedPluginInfo(
277 const GURL& url,
278 const std::string& mime_type,
[email protected]191eb3f72010-12-21 06:27:50279 webkit::npapi::WebPluginInfo* info,
[email protected]6fdd4182010-10-14 23:59:26280 std::string* actual_mime_type) {
281 // GetPluginInfoArray may need to load the plugins, so we need to be
282 // on the FILE thread.
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
284 bool allow_wildcard = true;
285#if defined(OS_CHROMEOS)
[email protected]191eb3f72010-12-21 06:27:50286 std::vector<webkit::npapi::WebPluginInfo> info_array;
[email protected]6fdd4182010-10-14 23:59:26287 std::vector<std::string> actual_mime_types;
[email protected]191eb3f72010-12-21 06:27:50288 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
[email protected]6fdd4182010-10-14 23:59:26289 url, mime_type, allow_wildcard, &info_array, &actual_mime_types);
290
291 // Now we filter by the plugin selection policy.
292 int allowed_index = plugin_selection_policy_->FindFirstAllowed(url,
293 info_array);
294 if (!info_array.empty() && allowed_index >= 0) {
295 *info = info_array[allowed_index];
296 if (actual_mime_type)
297 *actual_mime_type = actual_mime_types[allowed_index];
298 return true;
299 }
300 return false;
301#else
[email protected]191eb3f72010-12-21 06:27:50302 return webkit::npapi::PluginList::Singleton()->GetPluginInfo(
[email protected]6fdd4182010-10-14 23:59:26303 url, mime_type, allow_wildcard, info, actual_mime_type);
304#endif
305}
306
[email protected]b78e168b2009-09-21 22:05:45307static void PurgePluginListCache(bool reload_pages) {
308 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
309 !it.IsAtEnd(); it.Advance()) {
310 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages));
311 }
312}
313
[email protected]580522632009-08-17 21:55:55314void PluginService::OnWaitableEventSignaled(
315 base::WaitableEvent* waitable_event) {
[email protected]b547fd42009-04-23 23:16:27316#if defined(OS_WIN)
317 if (waitable_event == hkcu_event_.get()) {
318 hkcu_key_.StartWatching();
319 } else {
320 hklm_key_.StartWatching();
321 }
322
[email protected]191eb3f72010-12-21 06:27:50323 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
[email protected]b78e168b2009-09-21 22:05:45324 PurgePluginListCache(true);
[email protected]9de09f82009-08-17 20:13:53325#endif // defined(OS_WIN)
[email protected]b547fd42009-04-23 23:16:27326}
[email protected]894bb502009-05-21 22:39:57327
[email protected]4e59e812010-04-06 20:51:16328static void ForceShutdownPlugin(const FilePath& plugin_path) {
329 PluginProcessHost* plugin =
330 PluginService::GetInstance()->FindPluginProcess(plugin_path);
331 if (plugin)
332 plugin->ForceShutdown();
333}
334
[email protected]894bb502009-05-21 22:39:57335void PluginService::Observe(NotificationType type,
336 const NotificationSource& source,
337 const NotificationDetails& details) {
338 switch (type.value) {
[email protected]ae09ca62009-08-21 19:46:46339 case NotificationType::EXTENSION_LOADED: {
[email protected]9adb9692010-10-29 23:14:02340 const Extension* extension = Details<const Extension>(details).ptr();
[email protected]b78e168b2009-09-21 22:05:45341 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47342 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]ae09ca62009-08-21 19:46:46343 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]191eb3f72010-12-21 06:27:50344 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
345 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
[email protected]b78e168b2009-09-21 22:05:45346 plugins_changed = true;
[email protected]ae09ca62009-08-21 19:46:46347 if (!plugin.is_public)
348 private_plugins_[plugin.path] = extension->url();
[email protected]c533bb22009-06-03 19:06:11349 }
[email protected]b78e168b2009-09-21 22:05:45350 if (plugins_changed)
351 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57352 break;
353 }
354
355 case NotificationType::EXTENSION_UNLOADED: {
[email protected]a9f39a312010-12-23 22:14:27356 const Extension* extension =
357 Details<UnloadedExtensionInfo>(details)->extension;
[email protected]b78e168b2009-09-21 22:05:45358 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47359 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]b78e168b2009-09-21 22:05:45360 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f8b3ef82010-10-11 02:45:52361 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
362 NewRunnableFunction(&ForceShutdownPlugin,
363 plugin.path));
[email protected]191eb3f72010-12-21 06:27:50364 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
365 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath(
366 plugin.path);
[email protected]b78e168b2009-09-21 22:05:45367 plugins_changed = true;
368 if (!plugin.is_public)
369 private_plugins_.erase(plugin.path);
370 }
371 if (plugins_changed)
372 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57373 break;
374 }
375
[email protected]a96ec6a2009-11-04 17:27:08376#if defined(OS_MACOSX)
377 case NotificationType::APP_ACTIVATED: {
[email protected]f8b3ef82010-10-11 02:45:52378 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
379 NewRunnableFunction(&NotifyPluginsOfActivation));
[email protected]a96ec6a2009-11-04 17:27:08380 break;
381 }
382#endif
383
[email protected]5f101bbe2010-10-08 08:01:16384 case NotificationType::PLUGIN_ENABLE_STATUS_CHANGED: {
385 PurgePluginListCache(false);
386 break;
387 }
[email protected]894bb502009-05-21 22:39:57388 default:
389 DCHECK(false);
390 }
391}
[email protected]9dd9e8382009-06-05 18:23:21392
[email protected]7a13e792010-08-03 08:18:24393bool PluginService::PrivatePluginAllowedForURL(const FilePath& plugin_path,
394 const GURL& url) {
[email protected]9dd9e8382009-06-05 18:23:21395 if (url.is_empty())
396 return true; // Caller wants all plugins.
397
398 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path);
399 if (it == private_plugins_.end())
400 return true; // This plugin is not private, so it's allowed everywhere.
401
402 // We do a dumb compare of scheme and host, rather than using the domain
403 // service, since we only care about this for extensions.
404 const GURL& required_url = it->second;
405 return (url.scheme() == required_url.scheme() &&
406 url.host() == required_url.host());
407}
[email protected]4e0616e2010-05-28 14:55:53408
409void PluginService::RegisterPepperPlugins() {
410 std::vector<PepperPluginInfo> plugins;
411 PepperPluginRegistry::GetList(&plugins);
412 for (size_t i = 0; i < plugins.size(); ++i) {
[email protected]191eb3f72010-12-21 06:27:50413 webkit::npapi::PluginVersionInfo info;
[email protected]4e0616e2010-05-28 14:55:53414 info.path = plugins[i].path;
[email protected]2fb3e362010-07-02 18:05:44415 info.product_name = plugins[i].name.empty() ?
416 plugins[i].path.BaseName().ToWStringHack() :
417 ASCIIToWide(plugins[i].name);
418 info.file_description = ASCIIToWide(plugins[i].description);
419 info.file_extensions = ASCIIToWide(plugins[i].file_extensions);
420 info.file_description = ASCIIToWide(plugins[i].type_descriptions);
[email protected]4e0616e2010-05-28 14:55:53421 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|'));
422
423 // These NPAPI entry points will never be called. TODO(darin): Come up
424 // with a cleaner way to register pepper plugins with the NPAPI PluginList,
425 // or perhaps refactor the PluginList to be less specific to NPAPI.
426 memset(&info.entry_points, 0, sizeof(info.entry_points));
427
[email protected]191eb3f72010-12-21 06:27:50428 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
[email protected]4e0616e2010-05-28 14:55:53429 }
430}