blob: 6d2a703e5483d7ca6114a2a3c45d967163032891 [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
initial.commit09911bf2008-07-26 23:55:295#include "chrome/browser/plugin_service.h"
6
[email protected]ceac9972011-01-13 01:51:147#include <vector>
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"
[email protected]34b99632011-01-01 01:01:0612#include "base/threading/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]44f9c952011-01-02 06:05:3915#include "base/synchronization/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]b547fd42009-04-23 23:16:2735#include "chrome/common/render_messages.h"
[email protected]191eb3f72010-12-21 06:27:5036#include "webkit/plugins/npapi/plugin_constants_win.h"
37#include "webkit/plugins/npapi/plugin_list.h"
38#include "webkit/plugins/npapi/webplugininfo.h"
39
[email protected]d8c7cbcc2009-10-02 19:00:3140#ifndef DISABLE_NACL
[email protected]d032f492009-09-29 00:33:4641#include "native_client/src/trusted/plugin/nacl_entry_points.h"
[email protected]d8c7cbcc2009-10-02 19:00:3142#endif
[email protected]6fdd4182010-10-14 23:59:2643
44#if defined(OS_CHROMEOS)
45#include "chrome/browser/chromeos/plugin_selection_policy.h"
46#endif
initial.commit09911bf2008-07-26 23:55:2947
[email protected]a96ec6a2009-11-04 17:27:0848#if defined(OS_MACOSX)
49static void NotifyPluginsOfActivation() {
[email protected]f8b3ef82010-10-11 02:45:5250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]a96ec6a2009-11-04 17:27:0851
[email protected]d27893f62010-07-03 05:47:4252 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
[email protected]a96ec6a2009-11-04 17:27:0853 !iter.Done(); ++iter) {
54 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
55 plugin->OnAppActivation();
56 }
57}
58#endif
59
initial.commit09911bf2008-07-26 23:55:2960// static
[email protected]51549da2009-11-21 08:43:3961bool PluginService::enable_chrome_plugins_ = true;
62
63// static
[email protected]cec1b8d2010-03-24 00:21:3464void PluginService::InitGlobalInstance(Profile* profile) {
[email protected]f8b3ef82010-10-11 02:45:5265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]cec1b8d2010-03-24 00:21:3466
[email protected]0a8b1e22010-07-02 09:31:1167 // We first group the plugins and then figure out which groups to disable.
[email protected]8e8bb6d2010-12-13 08:18:5568 PluginUpdater::GetInstance()->DisablePluginGroupsFromPrefs(profile);
[email protected]7bf795d92010-05-22 00:14:2869
[email protected]cec1b8d2010-03-24 00:21:3470 // Have Chrome plugins write their data to the profile directory.
71 GetInstance()->SetChromePluginDataDir(profile->GetPath());
72}
73
74// static
initial.commit09911bf2008-07-26 23:55:2975PluginService* PluginService::GetInstance() {
76 return Singleton<PluginService>::get();
77}
78
[email protected]51549da2009-11-21 08:43:3979// static
80void PluginService::EnableChromePlugins(bool enable) {
81 enable_chrome_plugins_ = enable;
82}
83
initial.commit09911bf2008-07-26 23:55:2984PluginService::PluginService()
85 : main_message_loop_(MessageLoop::current()),
initial.commit09911bf2008-07-26 23:55:2986 resource_dispatcher_host_(NULL),
[email protected]f77d87622010-07-30 17:43:1787 ui_locale_(g_browser_process->GetApplicationLocale()) {
[email protected]4e0616e2010-05-28 14:55:5388 RegisterPepperPlugins();
89
initial.commit09911bf2008-07-26 23:55:2990 // Have the NPAPI plugin list search for Chrome plugins as well.
91 ChromePluginLib::RegisterPluginsWithNPAPI();
[email protected]9a1c4262010-06-29 21:50:2792
93 // Load any specified on the command line as well.
[email protected]d48f1e0c2009-02-12 20:57:5494 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]c4e52f0d2009-11-06 19:55:1695 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
[email protected]7bf795d92010-05-22 00:14:2896 if (!path.empty())
[email protected]191eb3f72010-12-21 06:27:5097 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]9a1c4262010-06-29 21:50:2798 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
99 if (!path.empty())
[email protected]191eb3f72010-12-21 06:27:50100 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path);
[email protected]7bf795d92010-05-22 00:14:28101
[email protected]2290cb862010-06-02 16:50:58102 chrome::RegisterInternalDefaultPlugin();
103
[email protected]7bf795d92010-05-22 00:14:28104 // Register the internal Flash and PDF, if available.
105 if (!CommandLine::ForCurrentProcess()->HasSwitch(
106 switches::kDisableInternalFlash) &&
107 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) {
[email protected]191eb3f72010-12-21 06:27:50108 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]35fa6a22009-08-15 00:04:01109 }
[email protected]d7ce4272010-03-27 01:06:01110
[email protected]d8c7cbcc2009-10-02 19:00:31111#ifndef DISABLE_NACL
[email protected]5cad70a82010-09-03 22:14:11112 if (command_line->HasSwitch(switches::kInternalNaCl)) {
113 RegisterInternalNaClPlugin();
114 }
[email protected]d8c7cbcc2009-10-02 19:00:31115#endif
[email protected]b547fd42009-04-23 23:16:27116
[email protected]6fdd4182010-10-14 23:59:26117#if defined(OS_CHROMEOS)
118 plugin_selection_policy_ = new chromeos::PluginSelectionPolicy;
119 plugin_selection_policy_->StartInit();
120#endif
121
[email protected]7477ea6f2009-12-22 23:28:15122 chrome::RegisterInternalGPUPlugin();
123
[email protected]b547fd42009-04-23 23:16:27124#if defined(OS_WIN)
125 hkcu_key_.Create(
[email protected]191eb3f72010-12-21 06:27:50126 HKEY_CURRENT_USER, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY);
[email protected]b547fd42009-04-23 23:16:27127 hklm_key_.Create(
[email protected]191eb3f72010-12-21 06:27:50128 HKEY_LOCAL_MACHINE, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY);
[email protected]b547fd42009-04-23 23:16:27129 if (hkcu_key_.StartWatching()) {
130 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
131 hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
132 }
133
134 if (hklm_key_.StartWatching()) {
135 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
136 hklm_watcher_.StartWatching(hklm_event_.get(), this);
137 }
[email protected]9c49ff02010-01-27 01:20:55138#elif defined(OS_POSIX) && !defined(OS_MACOSX)
139 // Also find plugins in a user-specific plugins dir,
140 // e.g. ~/.config/chromium/Plugins.
141 FilePath user_data_dir;
142 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
[email protected]191eb3f72010-12-21 06:27:50143 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(
[email protected]9c49ff02010-01-27 01:20:55144 user_data_dir.Append("Plugins"));
145 }
[email protected]b547fd42009-04-23 23:16:27146#endif
[email protected]894bb502009-05-21 22:39:57147
[email protected]ae09ca62009-08-21 19:46:46148 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
[email protected]894bb502009-05-21 22:39:57149 NotificationService::AllSources());
150 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
151 NotificationService::AllSources());
[email protected]a96ec6a2009-11-04 17:27:08152#if defined(OS_MACOSX)
153 // We need to know when the browser comes forward so we can bring modal plugin
154 // windows forward too.
155 registrar_.Add(this, NotificationType::APP_ACTIVATED,
156 NotificationService::AllSources());
157#endif
[email protected]5f101bbe2010-10-08 08:01:16158 registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED,
159 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:29160}
161
162PluginService::~PluginService() {
[email protected]b547fd42009-04-23 23:16:27163#if defined(OS_WIN)
164 // Release the events since they're owned by RegKey, not WaitableEvent.
165 hkcu_watcher_.StopWatching();
166 hklm_watcher_.StopWatching();
167 hkcu_event_->Release();
168 hklm_event_->Release();
169#endif
initial.commit09911bf2008-07-26 23:55:29170}
171
initial.commit09911bf2008-07-26 23:55:29172void PluginService::LoadChromePlugins(
173 ResourceDispatcherHost* resource_dispatcher_host) {
[email protected]51549da2009-11-21 08:43:39174 if (!enable_chrome_plugins_)
175 return;
176
initial.commit09911bf2008-07-26 23:55:29177 resource_dispatcher_host_ = resource_dispatcher_host;
178 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser());
179}
180
[email protected]f7011fcb2009-01-28 21:54:32181void PluginService::SetChromePluginDataDir(const FilePath& data_dir) {
initial.commit09911bf2008-07-26 23:55:29182 chrome_plugin_data_dir_ = data_dir;
183}
184
[email protected]f7011fcb2009-01-28 21:54:32185const FilePath& PluginService::GetChromePluginDataDir() {
initial.commit09911bf2008-07-26 23:55:29186 return chrome_plugin_data_dir_;
187}
188
[email protected]f77d87622010-07-30 17:43:17189const std::string& PluginService::GetUILocale() {
initial.commit09911bf2008-07-26 23:55:29190 return ui_locale_;
191}
192
[email protected]28ab7f92009-01-06 21:39:04193PluginProcessHost* PluginService::FindPluginProcess(
194 const FilePath& plugin_path) {
[email protected]f8b3ef82010-10-11 02:45:52195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29196
[email protected]d27893f62010-07-03 05:47:42197 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
[email protected]a436d922009-02-13 23:16:42198 !iter.Done(); ++iter) {
199 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
200 if (plugin->info().path == plugin_path)
201 return plugin;
202 }
203
initial.commit09911bf2008-07-26 23:55:29204 return NULL;
205}
206
207PluginProcessHost* PluginService::FindOrStartPluginProcess(
[email protected]610c0892009-09-08 19:46:18208 const FilePath& plugin_path) {
[email protected]f8b3ef82010-10-11 02:45:52209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29210
[email protected]8b8a554d2010-11-18 13:26:40211 PluginProcessHost* plugin_host = FindPluginProcess(plugin_path);
initial.commit09911bf2008-07-26 23:55:29212 if (plugin_host)
213 return plugin_host;
214
[email protected]191eb3f72010-12-21 06:27:50215 webkit::npapi::WebPluginInfo info;
216 if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath(
217 plugin_path, &info)) {
[email protected]a27a9382009-02-11 23:55:10218 return NULL;
219 }
220
initial.commit09911bf2008-07-26 23:55:29221 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]8b8a554d2010-11-18 13:26:40222 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost());
223 if (!new_host->Init(info, ui_locale_)) {
224 NOTREACHED(); // Init is not expected to fail
initial.commit09911bf2008-07-26 23:55:29225 return NULL;
226 }
[email protected]a436d922009-02-13 23:16:42227
[email protected]8b8a554d2010-11-18 13:26:40228 return new_host.release();
initial.commit09911bf2008-07-26 23:55:29229}
230
231void PluginService::OpenChannelToPlugin(
[email protected]610c0892009-09-08 19:46:18232 const GURL& url,
233 const std::string& mime_type,
[email protected]46b69e42010-11-02 12:26:39234 PluginProcessHost::Client* client) {
[email protected]6fdd4182010-10-14 23:59:26235 // The PluginList::GetFirstAllowedPluginInfo may need to load the
236 // plugins. Don't do it on the IO thread.
237 BrowserThread::PostTask(
238 BrowserThread::FILE, FROM_HERE,
239 NewRunnableMethod(
240 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin,
[email protected]46b69e42010-11-02 12:26:39241 url, mime_type, client));
[email protected]6fdd4182010-10-14 23:59:26242}
243
244void PluginService::GetAllowedPluginForOpenChannelToPlugin(
[email protected]6fdd4182010-10-14 23:59:26245 const GURL& url,
246 const std::string& mime_type,
[email protected]46b69e42010-11-02 12:26:39247 PluginProcessHost::Client* client) {
[email protected]6fdd4182010-10-14 23:59:26248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]191eb3f72010-12-21 06:27:50249 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26250 bool found = GetFirstAllowedPluginInfo(url, mime_type, &info, NULL);
251 FilePath plugin_path;
252 if (found && info.enabled)
253 plugin_path = FilePath(info.path);
254
255 // Now we jump back to the IO thread to finish opening the channel.
256 BrowserThread::PostTask(
257 BrowserThread::IO, FROM_HERE,
258 NewRunnableMethod(
259 this, &PluginService::FinishOpenChannelToPlugin,
[email protected]46b69e42010-11-02 12:26:39260 plugin_path, client));
[email protected]6fdd4182010-10-14 23:59:26261}
262
263void PluginService::FinishOpenChannelToPlugin(
[email protected]6fdd4182010-10-14 23:59:26264 const FilePath& plugin_path,
[email protected]46b69e42010-11-02 12:26:39265 PluginProcessHost::Client* client) {
[email protected]f8b3ef82010-10-11 02:45:52266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]20a793e2010-10-12 06:50:08267
[email protected]610c0892009-09-08 19:46:18268 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path);
[email protected]46b69e42010-11-02 12:26:39269 if (plugin_host)
270 plugin_host->OpenChannelToPlugin(client);
271 else
272 client->OnError();
initial.commit09911bf2008-07-26 23:55:29273}
274
[email protected]6fdd4182010-10-14 23:59:26275bool PluginService::GetFirstAllowedPluginInfo(
276 const GURL& url,
277 const std::string& mime_type,
[email protected]191eb3f72010-12-21 06:27:50278 webkit::npapi::WebPluginInfo* info,
[email protected]6fdd4182010-10-14 23:59:26279 std::string* actual_mime_type) {
280 // GetPluginInfoArray may need to load the plugins, so we need to be
281 // on the FILE thread.
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
283 bool allow_wildcard = true;
284#if defined(OS_CHROMEOS)
[email protected]191eb3f72010-12-21 06:27:50285 std::vector<webkit::npapi::WebPluginInfo> info_array;
[email protected]6fdd4182010-10-14 23:59:26286 std::vector<std::string> actual_mime_types;
[email protected]191eb3f72010-12-21 06:27:50287 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
[email protected]6fdd4182010-10-14 23:59:26288 url, mime_type, allow_wildcard, &info_array, &actual_mime_types);
289
290 // Now we filter by the plugin selection policy.
291 int allowed_index = plugin_selection_policy_->FindFirstAllowed(url,
292 info_array);
293 if (!info_array.empty() && allowed_index >= 0) {
294 *info = info_array[allowed_index];
295 if (actual_mime_type)
296 *actual_mime_type = actual_mime_types[allowed_index];
297 return true;
298 }
299 return false;
300#else
[email protected]191eb3f72010-12-21 06:27:50301 return webkit::npapi::PluginList::Singleton()->GetPluginInfo(
[email protected]6fdd4182010-10-14 23:59:26302 url, mime_type, allow_wildcard, info, actual_mime_type);
303#endif
304}
305
[email protected]b78e168b2009-09-21 22:05:45306static void PurgePluginListCache(bool reload_pages) {
307 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
308 !it.IsAtEnd(); it.Advance()) {
309 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages));
310 }
311}
312
[email protected]580522632009-08-17 21:55:55313void PluginService::OnWaitableEventSignaled(
314 base::WaitableEvent* waitable_event) {
[email protected]b547fd42009-04-23 23:16:27315#if defined(OS_WIN)
316 if (waitable_event == hkcu_event_.get()) {
317 hkcu_key_.StartWatching();
318 } else {
319 hklm_key_.StartWatching();
320 }
321
[email protected]191eb3f72010-12-21 06:27:50322 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
[email protected]b78e168b2009-09-21 22:05:45323 PurgePluginListCache(true);
[email protected]9de09f82009-08-17 20:13:53324#endif // defined(OS_WIN)
[email protected]b547fd42009-04-23 23:16:27325}
[email protected]894bb502009-05-21 22:39:57326
[email protected]4e59e812010-04-06 20:51:16327static void ForceShutdownPlugin(const FilePath& plugin_path) {
328 PluginProcessHost* plugin =
329 PluginService::GetInstance()->FindPluginProcess(plugin_path);
330 if (plugin)
331 plugin->ForceShutdown();
332}
333
[email protected]894bb502009-05-21 22:39:57334void PluginService::Observe(NotificationType type,
335 const NotificationSource& source,
336 const NotificationDetails& details) {
337 switch (type.value) {
[email protected]ae09ca62009-08-21 19:46:46338 case NotificationType::EXTENSION_LOADED: {
[email protected]9adb9692010-10-29 23:14:02339 const Extension* extension = Details<const Extension>(details).ptr();
[email protected]b78e168b2009-09-21 22:05:45340 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47341 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]ae09ca62009-08-21 19:46:46342 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]191eb3f72010-12-21 06:27:50343 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
344 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
[email protected]b78e168b2009-09-21 22:05:45345 plugins_changed = true;
[email protected]ae09ca62009-08-21 19:46:46346 if (!plugin.is_public)
347 private_plugins_[plugin.path] = extension->url();
[email protected]c533bb22009-06-03 19:06:11348 }
[email protected]b78e168b2009-09-21 22:05:45349 if (plugins_changed)
350 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57351 break;
352 }
353
354 case NotificationType::EXTENSION_UNLOADED: {
[email protected]a9f39a312010-12-23 22:14:27355 const Extension* extension =
356 Details<UnloadedExtensionInfo>(details)->extension;
[email protected]b78e168b2009-09-21 22:05:45357 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47358 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]b78e168b2009-09-21 22:05:45359 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]f8b3ef82010-10-11 02:45:52360 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
361 NewRunnableFunction(&ForceShutdownPlugin,
362 plugin.path));
[email protected]191eb3f72010-12-21 06:27:50363 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
364 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath(
365 plugin.path);
[email protected]b78e168b2009-09-21 22:05:45366 plugins_changed = true;
367 if (!plugin.is_public)
368 private_plugins_.erase(plugin.path);
369 }
370 if (plugins_changed)
371 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57372 break;
373 }
374
[email protected]a96ec6a2009-11-04 17:27:08375#if defined(OS_MACOSX)
376 case NotificationType::APP_ACTIVATED: {
[email protected]f8b3ef82010-10-11 02:45:52377 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
378 NewRunnableFunction(&NotifyPluginsOfActivation));
[email protected]a96ec6a2009-11-04 17:27:08379 break;
380 }
381#endif
382
[email protected]5f101bbe2010-10-08 08:01:16383 case NotificationType::PLUGIN_ENABLE_STATUS_CHANGED: {
384 PurgePluginListCache(false);
385 break;
386 }
[email protected]894bb502009-05-21 22:39:57387 default:
388 DCHECK(false);
389 }
390}
[email protected]9dd9e8382009-06-05 18:23:21391
[email protected]7a13e792010-08-03 08:18:24392bool PluginService::PrivatePluginAllowedForURL(const FilePath& plugin_path,
393 const GURL& url) {
[email protected]9dd9e8382009-06-05 18:23:21394 if (url.is_empty())
395 return true; // Caller wants all plugins.
396
397 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path);
398 if (it == private_plugins_.end())
399 return true; // This plugin is not private, so it's allowed everywhere.
400
401 // We do a dumb compare of scheme and host, rather than using the domain
402 // service, since we only care about this for extensions.
403 const GURL& required_url = it->second;
404 return (url.scheme() == required_url.scheme() &&
405 url.host() == required_url.host());
406}
[email protected]4e0616e2010-05-28 14:55:53407
408void PluginService::RegisterPepperPlugins() {
409 std::vector<PepperPluginInfo> plugins;
410 PepperPluginRegistry::GetList(&plugins);
411 for (size_t i = 0; i < plugins.size(); ++i) {
[email protected]191eb3f72010-12-21 06:27:50412 webkit::npapi::PluginVersionInfo info;
[email protected]4e0616e2010-05-28 14:55:53413 info.path = plugins[i].path;
[email protected]2fb3e362010-07-02 18:05:44414 info.product_name = plugins[i].name.empty() ?
415 plugins[i].path.BaseName().ToWStringHack() :
416 ASCIIToWide(plugins[i].name);
417 info.file_description = ASCIIToWide(plugins[i].description);
418 info.file_extensions = ASCIIToWide(plugins[i].file_extensions);
419 info.file_description = ASCIIToWide(plugins[i].type_descriptions);
[email protected]4e0616e2010-05-28 14:55:53420 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|'));
421
422 // These NPAPI entry points will never be called. TODO(darin): Come up
423 // with a cleaner way to register pepper plugins with the NPAPI PluginList,
424 // or perhaps refactor the PluginList to be less specific to NPAPI.
425 memset(&info.entry_points, 0, sizeof(info.entry_points));
426
[email protected]191eb3f72010-12-21 06:27:50427 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info);
[email protected]4e0616e2010-05-28 14:55:53428 }
429}