blob: 165ca52de9d6524c15f1876fd803b4b4885f350d [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]cec1b8d2010-03-24 00:21:3413#include "base/values.h"
[email protected]b547fd42009-04-23 23:16:2714#include "base/waitable_event.h"
initial.commit09911bf2008-07-26 23:55:2915#include "chrome/browser/browser_process.h"
16#include "chrome/browser/chrome_plugin_host.h"
17#include "chrome/browser/chrome_thread.h"
[email protected]894bb502009-05-21 22:39:5718#include "chrome/browser/extensions/extensions_service.h"
[email protected]6eaddcc2009-02-23 21:03:0419#include "chrome/browser/plugin_process_host.h"
[email protected]cec1b8d2010-03-24 00:21:3420#include "chrome/browser/pref_service.h"
21#include "chrome/browser/profile.h"
[email protected]8c8657d62009-01-16 18:31:2622#include "chrome/browser/renderer_host/render_process_host.h"
initial.commit09911bf2008-07-26 23:55:2923#include "chrome/common/chrome_plugin_lib.h"
[email protected]9c49ff02010-01-27 01:20:5524#include "chrome/common/chrome_paths.h"
[email protected]d48f1e0c2009-02-12 20:57:5425#include "chrome/common/chrome_switches.h"
[email protected]2290cb862010-06-02 16:50:5826#include "chrome/common/default_plugin.h"
[email protected]5b1a0e22009-05-26 19:00:5827#include "chrome/common/extensions/extension.h"
[email protected]7477ea6f2009-12-22 23:28:1528#include "chrome/common/gpu_plugin.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/logging_chrome.h"
[email protected]894bb502009-05-21 22:39:5730#include "chrome/common/notification_type.h"
31#include "chrome/common/notification_service.h"
[email protected]4e0616e2010-05-28 14:55:5332#include "chrome/common/pepper_plugin_registry.h"
[email protected]4e59e812010-04-06 20:51:1633#include "chrome/common/plugin_messages.h"
[email protected]cec1b8d2010-03-24 00:21:3434#include "chrome/common/pref_names.h"
[email protected]b547fd42009-04-23 23:16:2735#include "chrome/common/render_messages.h"
[email protected]d8c7cbcc2009-10-02 19:00:3136#ifndef DISABLE_NACL
[email protected]d032f492009-09-29 00:33:4637#include "native_client/src/trusted/plugin/nacl_entry_points.h"
[email protected]d8c7cbcc2009-10-02 19:00:3138#endif
[email protected]b547fd42009-04-23 23:16:2739#include "webkit/glue/plugins/plugin_constants_win.h"
initial.commit09911bf2008-07-26 23:55:2940#include "webkit/glue/plugins/plugin_list.h"
41
[email protected]a96ec6a2009-11-04 17:27:0842#if defined(OS_MACOSX)
43static void NotifyPluginsOfActivation() {
44 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
45
46 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
47 !iter.Done(); ++iter) {
48 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
49 plugin->OnAppActivation();
50 }
51}
52#endif
53
initial.commit09911bf2008-07-26 23:55:2954// static
[email protected]51549da2009-11-21 08:43:3955bool PluginService::enable_chrome_plugins_ = true;
[email protected]7bf795d92010-05-22 00:14:2856bool PluginService::enable_internal_pdf_ = false;
[email protected]51549da2009-11-21 08:43:3957
58// static
[email protected]cec1b8d2010-03-24 00:21:3459void PluginService::InitGlobalInstance(Profile* profile) {
60 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
61
[email protected]388dd3a2010-05-05 22:47:2762 bool update_internal_dir = false;
63 FilePath last_internal_dir =
64 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory);
65 FilePath cur_internal_dir;
[email protected]7bf795d92010-05-22 00:14:2866 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) &&
67 cur_internal_dir != last_internal_dir) {
68 update_internal_dir = true;
69 profile->GetPrefs()->SetFilePath(
70 prefs::kPluginsLastInternalDirectory, cur_internal_dir);
71 }
72
73 bool found_internal_pdf = false;
74 bool force_enable_internal_pdf = false;
75 FilePath pdf_path;
76 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
77 FilePath::StringType pdf_path_str = pdf_path.value();
78 if (enable_internal_pdf_ &&
79 !profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) {
80 // We switched to the internal pdf plugin being on by default, and so we
81 // need to force it to be enabled. We only want to do it this once though,
82 // i.e. we don't want to enable it again if the user disables it afterwards.
83 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true);
84 force_enable_internal_pdf = true;
85 }
[email protected]388dd3a2010-05-05 22:47:2786
[email protected]cec1b8d2010-03-24 00:21:3487 // Disable plugins listed as disabled in prefs.
[email protected]7bf795d92010-05-22 00:14:2888 if (ListValue* saved_plugins_list =
89 profile->GetPrefs()->GetMutableList(prefs::kPluginsPluginsList)) {
[email protected]cec1b8d2010-03-24 00:21:3490 for (ListValue::const_iterator it = saved_plugins_list->begin();
91 it != saved_plugins_list->end();
92 ++it) {
93 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) {
94 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList;
95 continue; // Oops, don't know what to do with this item.
96 }
97
98 DictionaryValue* plugin = static_cast<DictionaryValue*>(*it);
99 FilePath::StringType path;
[email protected]7bf795d92010-05-22 00:14:28100 if (!plugin->GetString(L"path", &path))
101 continue;
102
[email protected]cec1b8d2010-03-24 00:21:34103 bool enabled = true;
104 plugin->GetBoolean(L"enabled", &enabled);
[email protected]388dd3a2010-05-05 22:47:27105
[email protected]31938592010-05-24 22:51:02106 if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) {
[email protected]7bf795d92010-05-22 00:14:28107 found_internal_pdf = true;
108 if (!enabled && force_enable_internal_pdf) {
109 enabled = true;
110 plugin->SetBoolean(L"enabled", true);
[email protected]388dd3a2010-05-05 22:47:27111 }
112 }
[email protected]7bf795d92010-05-22 00:14:28113
114 FilePath plugin_path(path);
[email protected]31938592010-05-24 22:51:02115 if (update_internal_dir &&
116 FilePath::CompareIgnoreCase(plugin_path.DirName().value(),
117 last_internal_dir.value()) == 0) {
[email protected]7bf795d92010-05-22 00:14:28118 // If the internal plugin directory has changed and if the plugin looks
119 // internal, update its path in the prefs.
120 plugin_path = cur_internal_dir.Append(plugin_path.BaseName());
121 plugin->SetString(L"path", plugin_path.value());
122 }
123
124 if (!enabled)
125 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path);
[email protected]cec1b8d2010-03-24 00:21:34126 }
127 }
128
[email protected]7bf795d92010-05-22 00:14:28129 if (!enable_internal_pdf_ && !found_internal_pdf) {
130 // The internal PDF plugin is disabled by default, and the user hasn't
131 // overridden the default.
132 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path);
133 }
134
[email protected]cec1b8d2010-03-24 00:21:34135 // Have Chrome plugins write their data to the profile directory.
136 GetInstance()->SetChromePluginDataDir(profile->GetPath());
137}
138
139// static
initial.commit09911bf2008-07-26 23:55:29140PluginService* PluginService::GetInstance() {
141 return Singleton<PluginService>::get();
142}
143
[email protected]51549da2009-11-21 08:43:39144// static
145void PluginService::EnableChromePlugins(bool enable) {
146 enable_chrome_plugins_ = enable;
147}
148
initial.commit09911bf2008-07-26 23:55:29149PluginService::PluginService()
150 : main_message_loop_(MessageLoop::current()),
initial.commit09911bf2008-07-26 23:55:29151 resource_dispatcher_host_(NULL),
[email protected]d70539de2009-06-24 22:17:06152 ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) {
[email protected]4e0616e2010-05-28 14:55:53153 RegisterPepperPlugins();
154
initial.commit09911bf2008-07-26 23:55:29155 // Have the NPAPI plugin list search for Chrome plugins as well.
156 ChromePluginLib::RegisterPluginsWithNPAPI();
[email protected]d48f1e0c2009-02-12 20:57:54157 // Load the one specified on the command line as well.
158 const CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]c4e52f0d2009-11-06 19:55:16159 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
[email protected]7bf795d92010-05-22 00:14:28160 if (!path.empty())
161 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
162
[email protected]2290cb862010-06-02 16:50:58163 chrome::RegisterInternalDefaultPlugin();
164
[email protected]7bf795d92010-05-22 00:14:28165 // Register the internal Flash and PDF, if available.
166 if (!CommandLine::ForCurrentProcess()->HasSwitch(
167 switches::kDisableInternalFlash) &&
168 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) {
[email protected]c4e52f0d2009-11-06 19:55:16169 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]35fa6a22009-08-15 00:04:01170 }
[email protected]d7ce4272010-03-27 01:06:01171
[email protected]7bf795d92010-05-22 00:14:28172 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path))
173 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
[email protected]d7ce4272010-03-27 01:06:01174
[email protected]d8c7cbcc2009-10-02 19:00:31175#ifndef DISABLE_NACL
[email protected]d032f492009-09-29 00:33:46176 if (command_line->HasSwitch(switches::kInternalNaCl))
177 RegisterInternalNaClPlugin();
[email protected]d8c7cbcc2009-10-02 19:00:31178#endif
[email protected]b547fd42009-04-23 23:16:27179
[email protected]7477ea6f2009-12-22 23:28:15180 chrome::RegisterInternalGPUPlugin();
181
[email protected]b547fd42009-04-23 23:16:27182#if defined(OS_WIN)
183 hkcu_key_.Create(
184 HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY);
185 hklm_key_.Create(
186 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY);
187 if (hkcu_key_.StartWatching()) {
188 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
189 hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
190 }
191
192 if (hklm_key_.StartWatching()) {
193 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event()));
194 hklm_watcher_.StartWatching(hklm_event_.get(), this);
195 }
[email protected]9c49ff02010-01-27 01:20:55196#elif defined(OS_POSIX) && !defined(OS_MACOSX)
197 // Also find plugins in a user-specific plugins dir,
198 // e.g. ~/.config/chromium/Plugins.
199 FilePath user_data_dir;
200 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
201 NPAPI::PluginList::Singleton()->AddExtraPluginDir(
202 user_data_dir.Append("Plugins"));
203 }
[email protected]b547fd42009-04-23 23:16:27204#endif
[email protected]894bb502009-05-21 22:39:57205
[email protected]ae09ca62009-08-21 19:46:46206 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
[email protected]894bb502009-05-21 22:39:57207 NotificationService::AllSources());
208 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
209 NotificationService::AllSources());
[email protected]a96ec6a2009-11-04 17:27:08210#if defined(OS_MACOSX)
211 // We need to know when the browser comes forward so we can bring modal plugin
212 // windows forward too.
213 registrar_.Add(this, NotificationType::APP_ACTIVATED,
214 NotificationService::AllSources());
215#endif
initial.commit09911bf2008-07-26 23:55:29216}
217
218PluginService::~PluginService() {
[email protected]b547fd42009-04-23 23:16:27219#if defined(OS_WIN)
220 // Release the events since they're owned by RegKey, not WaitableEvent.
221 hkcu_watcher_.StopWatching();
222 hklm_watcher_.StopWatching();
223 hkcu_event_->Release();
224 hklm_event_->Release();
225#endif
initial.commit09911bf2008-07-26 23:55:29226}
227
initial.commit09911bf2008-07-26 23:55:29228void PluginService::LoadChromePlugins(
229 ResourceDispatcherHost* resource_dispatcher_host) {
[email protected]51549da2009-11-21 08:43:39230 if (!enable_chrome_plugins_)
231 return;
232
initial.commit09911bf2008-07-26 23:55:29233 resource_dispatcher_host_ = resource_dispatcher_host;
234 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser());
235}
236
[email protected]f7011fcb2009-01-28 21:54:32237void PluginService::SetChromePluginDataDir(const FilePath& data_dir) {
initial.commit09911bf2008-07-26 23:55:29238 chrome_plugin_data_dir_ = data_dir;
239}
240
[email protected]f7011fcb2009-01-28 21:54:32241const FilePath& PluginService::GetChromePluginDataDir() {
initial.commit09911bf2008-07-26 23:55:29242 return chrome_plugin_data_dir_;
243}
244
245const std::wstring& PluginService::GetUILocale() {
246 return ui_locale_;
247}
248
[email protected]28ab7f92009-01-06 21:39:04249PluginProcessHost* PluginService::FindPluginProcess(
250 const FilePath& plugin_path) {
[email protected]d85cf072009-10-27 03:59:31251 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
initial.commit09911bf2008-07-26 23:55:29252
[email protected]28ab7f92009-01-06 21:39:04253 if (plugin_path.value().empty()) {
254 NOTREACHED() << "should only be called if we have a plugin to load";
initial.commit09911bf2008-07-26 23:55:29255 return NULL;
256 }
257
[email protected]6dffde322009-02-18 03:47:48258 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS);
[email protected]a436d922009-02-13 23:16:42259 !iter.Done(); ++iter) {
260 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
261 if (plugin->info().path == plugin_path)
262 return plugin;
263 }
264
initial.commit09911bf2008-07-26 23:55:29265 return NULL;
266}
267
268PluginProcessHost* PluginService::FindOrStartPluginProcess(
[email protected]610c0892009-09-08 19:46:18269 const FilePath& plugin_path) {
[email protected]d85cf072009-10-27 03:59:31270 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
initial.commit09911bf2008-07-26 23:55:29271
[email protected]28ab7f92009-01-06 21:39:04272 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path);
initial.commit09911bf2008-07-26 23:55:29273 if (plugin_host)
274 return plugin_host;
275
[email protected]a27a9382009-02-11 23:55:10276 WebPluginInfo info;
[email protected]35fa6a22009-08-15 00:04:01277 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
278 plugin_path, &info)) {
[email protected]a27a9382009-02-11 23:55:10279 DCHECK(false);
280 return NULL;
281 }
282
initial.commit09911bf2008-07-26 23:55:29283 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]dabe6072009-03-17 00:52:35284 plugin_host = new PluginProcessHost();
[email protected]610c0892009-09-08 19:46:18285 if (!plugin_host->Init(info, ui_locale_)) {
initial.commit09911bf2008-07-26 23:55:29286 DCHECK(false); // Init is not expected to fail
287 delete plugin_host;
288 return NULL;
289 }
[email protected]a436d922009-02-13 23:16:42290
initial.commit09911bf2008-07-26 23:55:29291 return plugin_host;
initial.commit09911bf2008-07-26 23:55:29292}
293
294void PluginService::OpenChannelToPlugin(
[email protected]610c0892009-09-08 19:46:18295 ResourceMessageFilter* renderer_msg_filter,
296 const GURL& url,
297 const std::string& mime_type,
298 const std::wstring& locale,
299 IPC::Message* reply_msg) {
[email protected]d85cf072009-10-27 03:59:31300 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
[email protected]9dd9e8382009-06-05 18:23:21301 // We don't need a policy URL here because that was already checked by a
302 // previous call to GetPluginPath.
303 GURL policy_url;
[email protected]610c0892009-09-08 19:46:18304 FilePath plugin_path = GetPluginPath(url, policy_url, mime_type, NULL);
305 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path);
initial.commit09911bf2008-07-26 23:55:29306 if (plugin_host) {
307 plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg);
308 } else {
[email protected]610c0892009-09-08 19:46:18309 PluginProcessHost::ReplyToRenderer(
310 renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg);
initial.commit09911bf2008-07-26 23:55:29311 }
312}
313
[email protected]690a99c2009-01-06 16:48:45314FilePath PluginService::GetPluginPath(const GURL& url,
[email protected]9dd9e8382009-06-05 18:23:21315 const GURL& policy_url,
[email protected]690a99c2009-01-06 16:48:45316 const std::string& mime_type,
[email protected]690a99c2009-01-06 16:48:45317 std::string* actual_mime_type) {
initial.commit09911bf2008-07-26 23:55:29318 bool allow_wildcard = true;
319 WebPluginInfo info;
[email protected]610c0892009-09-08 19:46:18320 if (NPAPI::PluginList::Singleton()->GetPluginInfo(
321 url, mime_type, allow_wildcard, &info, actual_mime_type) &&
[email protected]9dd9e8382009-06-05 18:23:21322 PluginAllowedForURL(info.path, policy_url)) {
323 return info.path;
324 }
325
326 return FilePath();
initial.commit09911bf2008-07-26 23:55:29327}
328
[email protected]b78e168b2009-09-21 22:05:45329static void PurgePluginListCache(bool reload_pages) {
330 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
331 !it.IsAtEnd(); it.Advance()) {
332 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages));
333 }
334}
335
[email protected]580522632009-08-17 21:55:55336void PluginService::OnWaitableEventSignaled(
337 base::WaitableEvent* waitable_event) {
[email protected]b547fd42009-04-23 23:16:27338#if defined(OS_WIN)
339 if (waitable_event == hkcu_event_.get()) {
340 hkcu_key_.StartWatching();
341 } else {
342 hklm_key_.StartWatching();
343 }
344
[email protected]4e59e812010-04-06 20:51:16345 NPAPI::PluginList::Singleton()->RefreshPlugins();
[email protected]b78e168b2009-09-21 22:05:45346 PurgePluginListCache(true);
[email protected]9de09f82009-08-17 20:13:53347#endif // defined(OS_WIN)
[email protected]b547fd42009-04-23 23:16:27348}
[email protected]894bb502009-05-21 22:39:57349
[email protected]4e59e812010-04-06 20:51:16350static void ForceShutdownPlugin(const FilePath& plugin_path) {
351 PluginProcessHost* plugin =
352 PluginService::GetInstance()->FindPluginProcess(plugin_path);
353 if (plugin)
354 plugin->ForceShutdown();
355}
356
[email protected]894bb502009-05-21 22:39:57357void PluginService::Observe(NotificationType type,
358 const NotificationSource& source,
359 const NotificationDetails& details) {
360 switch (type.value) {
[email protected]ae09ca62009-08-21 19:46:46361 case NotificationType::EXTENSION_LOADED: {
[email protected]ae09ca62009-08-21 19:46:46362 Extension* extension = Details<Extension>(details).ptr();
[email protected]b78e168b2009-09-21 22:05:45363 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47364 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]ae09ca62009-08-21 19:46:46365 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]4e59e812010-04-06 20:51:16366 NPAPI::PluginList::Singleton()->RefreshPlugins();
[email protected]ae09ca62009-08-21 19:46:46367 NPAPI::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
[email protected]b78e168b2009-09-21 22:05:45368 plugins_changed = true;
[email protected]ae09ca62009-08-21 19:46:46369 if (!plugin.is_public)
370 private_plugins_[plugin.path] = extension->url();
[email protected]c533bb22009-06-03 19:06:11371 }
[email protected]b78e168b2009-09-21 22:05:45372 if (plugins_changed)
373 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57374 break;
375 }
376
377 case NotificationType::EXTENSION_UNLOADED: {
[email protected]b78e168b2009-09-21 22:05:45378 Extension* extension = Details<Extension>(details).ptr();
379 bool plugins_changed = false;
[email protected]ee5e3792009-10-13 23:23:47380 for (size_t i = 0; i < extension->plugins().size(); ++i) {
[email protected]b78e168b2009-09-21 22:05:45381 const Extension::PluginInfo& plugin = extension->plugins()[i];
[email protected]4e59e812010-04-06 20:51:16382 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
383 NewRunnableFunction(&ForceShutdownPlugin,
384 plugin.path));
385 NPAPI::PluginList::Singleton()->RefreshPlugins();
[email protected]b78e168b2009-09-21 22:05:45386 NPAPI::PluginList::Singleton()->RemoveExtraPluginPath(plugin.path);
387 plugins_changed = true;
388 if (!plugin.is_public)
389 private_plugins_.erase(plugin.path);
390 }
391 if (plugins_changed)
392 PurgePluginListCache(false);
[email protected]894bb502009-05-21 22:39:57393 break;
394 }
395
[email protected]a96ec6a2009-11-04 17:27:08396#if defined(OS_MACOSX)
397 case NotificationType::APP_ACTIVATED: {
398 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
399 NewRunnableFunction(&NotifyPluginsOfActivation));
400 break;
401 }
402#endif
403
[email protected]894bb502009-05-21 22:39:57404 default:
405 DCHECK(false);
406 }
407}
[email protected]9dd9e8382009-06-05 18:23:21408
409bool PluginService::PluginAllowedForURL(const FilePath& plugin_path,
410 const GURL& url) {
411 if (url.is_empty())
412 return true; // Caller wants all plugins.
413
414 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path);
415 if (it == private_plugins_.end())
416 return true; // This plugin is not private, so it's allowed everywhere.
417
418 // We do a dumb compare of scheme and host, rather than using the domain
419 // service, since we only care about this for extensions.
420 const GURL& required_url = it->second;
421 return (url.scheme() == required_url.scheme() &&
422 url.host() == required_url.host());
423}
[email protected]4e0616e2010-05-28 14:55:53424
425void PluginService::RegisterPepperPlugins() {
426 std::vector<PepperPluginInfo> plugins;
427 PepperPluginRegistry::GetList(&plugins);
428 for (size_t i = 0; i < plugins.size(); ++i) {
429 NPAPI::PluginVersionInfo info;
430 info.path = plugins[i].path;
431 info.product_name = plugins[i].path.BaseName().ToWStringHack();
432 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|'));
433
434 // These NPAPI entry points will never be called. TODO(darin): Come up
435 // with a cleaner way to register pepper plugins with the NPAPI PluginList,
436 // or perhaps refactor the PluginList to be less specific to NPAPI.
437 memset(&info.entry_points, 0, sizeof(info.entry_points));
438
439 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info);
440 }
441}