[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 5 | #include "content/browser/plugin_service_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 10 | #include "base/file_path.h" |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 11 | #include "base/message_loop.h" |
| 12 | #include "base/message_loop_proxy.h" |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 13 | #include "base/path_service.h" |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 15 | #include "base/synchronization/waitable_event.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 16 | #include "base/threading/thread.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 17 | #include "base/utf_string_conversions.h" |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 18 | #include "base/values.h" |
[email protected] | 6be08ae | 2011-10-18 02:23:23 | [diff] [blame] | 19 | #include "content/browser/plugin_loader_posix.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 20 | #include "content/browser/plugin_service_filter.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 21 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 22 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 23 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 24 | #include "content/browser/resource_context.h" |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 25 | #include "content/browser/utility_process_host.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 26 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 27 | #include "content/common/plugin_messages.h" |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 28 | #include "content/common/utility_messages.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 29 | #include "content/common/view_messages.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 30 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 31 | #include "content/public/browser/content_browser_client.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 32 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 33 | #include "content/public/browser/notification_types.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 34 | #include "content/public/common/content_switches.h" |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 35 | #include "content/public/common/process_type.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 36 | #include "webkit/plugins/npapi/plugin_constants_win.h" |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 37 | #include "webkit/plugins/npapi/plugin_group.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 38 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 39 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 40 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 41 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 42 | using ::base::files::FilePathWatcher; |
| 43 | #endif |
| 44 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 45 | using content::BrowserThread; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 46 | using content::PluginService; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 47 | using content::PluginServiceFilter; |
| 48 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 49 | namespace { |
| 50 | |
| 51 | // Helper function that merely runs the callback with the result. Called on the |
| 52 | // thread on which the original GetPlugins() call was made. |
| 53 | static void RunGetPluginsCallback( |
| 54 | const PluginService::GetPluginsCallback& callback, |
| 55 | const std::vector<webkit::WebPluginInfo>& result) { |
| 56 | callback.Run(result); |
| 57 | } |
| 58 | |
| 59 | // A callback for GetPlugins() that then gets the freshly loaded plugin groups |
| 60 | // and runs the callback for GetPluginGroups(). |
| 61 | static void GetPluginsForGroupsCallback( |
| 62 | const PluginService::GetPluginGroupsCallback& callback, |
| 63 | const std::vector<webkit::WebPluginInfo>& plugins) { |
| 64 | std::vector<webkit::npapi::PluginGroup> groups; |
| 65 | webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); |
| 66 | callback.Run(groups); |
| 67 | } |
| 68 | |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 69 | // Callback set on the PluginList to assert that plugin loading happens on the |
| 70 | // correct thread. |
| 71 | void WillLoadPluginsCallback() { |
[email protected] | 6a0dc7a | 2011-11-02 14:37:07 | [diff] [blame] | 72 | #if defined(OS_WIN) |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 73 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 74 | #else |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 75 | CHECK(false) << "Plugin loading should happen out-of-process."; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 76 | #endif |
| 77 | } |
| 78 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 79 | } // namespace |
| 80 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 81 | #if defined(OS_MACOSX) |
| 82 | static void NotifyPluginsOfActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 83 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 84 | |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 85 | for (BrowserChildProcessHost::Iterator iter( |
| 86 | content::PROCESS_TYPE_PLUGIN); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 87 | !iter.Done(); ++iter) { |
| 88 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 89 | plugin->OnAppActivation(); |
| 90 | } |
| 91 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 92 | #elif defined(OS_POSIX) && !defined(OS_OPENBSD) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 93 | // Delegate class for monitoring directories. |
| 94 | class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 95 | virtual void OnFilePathChanged(const FilePath& path) OVERRIDE { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 96 | VLOG(1) << "Watched path changed: " << path.value(); |
| 97 | // Make the plugin list update itself |
| 98 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | ee6fcb2 | 2011-10-22 01:27:06 | [diff] [blame] | 99 | BrowserThread::PostTask( |
| 100 | BrowserThread::UI, FROM_HERE, |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 101 | base::Bind(&content::PluginService::PurgePluginListCache, |
[email protected] | ee6fcb2 | 2011-10-22 01:27:06 | [diff] [blame] | 102 | static_cast<content::BrowserContext*>(NULL), false)); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 103 | } |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 104 | |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 105 | virtual void OnFilePathError(const FilePath& path) OVERRIDE { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 106 | // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 107 | // stopping the watcher would be enough. Or possibly restart it. |
| 108 | NOTREACHED(); |
| 109 | } |
| 110 | }; |
| 111 | #endif |
| 112 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 113 | namespace content { |
| 114 | // static |
| 115 | PluginService* PluginService::GetInstance() { |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 116 | return PluginServiceImpl::GetInstance(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
| 120 | bool reload_pages) { |
| 121 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 122 | !it.IsAtEnd(); it.Advance()) { |
| 123 | RenderProcessHost* host = it.GetCurrentValue(); |
| 124 | if (!browser_context || host->GetBrowserContext() == browser_context) |
| 125 | host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | } // namespace content |
| 130 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 132 | PluginServiceImpl* PluginServiceImpl::GetInstance() { |
| 133 | return Singleton<PluginServiceImpl>::get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 136 | PluginServiceImpl::PluginServiceImpl() |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 137 | : plugin_list_(NULL), |
| 138 | ui_locale_( |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 139 | content::GetContentClient()->browser()->GetApplicationLocale()), |
| 140 | filter_(NULL) { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 143 | PluginServiceImpl::~PluginServiceImpl() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 144 | #if defined(OS_WIN) |
| 145 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 146 | hkcu_watcher_.StopWatching(); |
| 147 | hklm_watcher_.StopWatching(); |
| 148 | if (hkcu_event_.get()) |
| 149 | hkcu_event_->Release(); |
| 150 | if (hklm_event_.get()) |
| 151 | hklm_event_->Release(); |
| 152 | #endif |
| 153 | // Make sure no plugin channel requests have been leaked. |
| 154 | DCHECK(pending_plugin_clients_.empty()); |
| 155 | } |
| 156 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 157 | void PluginServiceImpl::Init() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 158 | if (!plugin_list_) |
| 159 | plugin_list_ = webkit::npapi::PluginList::Singleton(); |
| 160 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 161 | plugin_list_->set_will_load_plugins_callback( |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 162 | base::Bind(&WillLoadPluginsCallback)); |
| 163 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 164 | RegisterPepperPlugins(); |
| 165 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 166 | content::GetContentClient()->AddNPAPIPlugins(plugin_list_); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 167 | |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 168 | // Load any specified on the command line as well. |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 169 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 170 | FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 171 | if (!path.empty()) |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 172 | AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 173 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 174 | if (!path.empty()) |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 175 | plugin_list_->AddExtraPluginDir(path); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 176 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 177 | #if defined(OS_MACOSX) |
| 178 | // We need to know when the browser comes forward so we can bring modal plugin |
| 179 | // windows forward too. |
| 180 | registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 181 | content::NotificationService::AllSources()); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 182 | #endif |
| 183 | } |
| 184 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 185 | void PluginServiceImpl::StartWatchingPlugins() { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 186 | // Start watching for changes in the plugin list. This means watching |
| 187 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 188 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 189 | #if defined(OS_WIN) |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 190 | if (hkcu_key_.Create(HKEY_CURRENT_USER, |
| 191 | webkit::npapi::kRegistryMozillaPlugins, |
| 192 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 193 | if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
| 194 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 195 | hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| 196 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 197 | } |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 198 | if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
| 199 | webkit::npapi::kRegistryMozillaPlugins, |
| 200 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 201 | if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
| 202 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
| 203 | hklm_watcher_.StartWatching(hklm_event_.get(), this); |
| 204 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 205 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 206 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 207 | // The FilePathWatcher produces too many false positives on MacOS (access time |
| 208 | // updates?) which will lead to enforcing updates of the plugins way too often. |
| 209 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 210 | // important plugins register themselves in the registry so no need to do that. |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 211 | file_watcher_delegate_ = new PluginDirWatcherDelegate(); |
| 212 | // Get the list of all paths for registering the FilePathWatchers |
| 213 | // that will track and if needed reload the list of plugins on runtime. |
| 214 | std::vector<FilePath> plugin_dirs; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 215 | plugin_list_->GetPluginDirectories(&plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 216 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 217 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 218 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 219 | // We don't watch for file changes in windows now but if this should ever |
| 220 | // be extended to Windows these lines might save some time of debugging. |
| 221 | #if defined(OS_WIN) |
| 222 | if (!plugin_dirs[i].IsAbsolute()) |
| 223 | continue; |
| 224 | #endif |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 225 | FilePathWatcher* watcher = new FilePathWatcher(); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 226 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 227 | BrowserThread::PostTask( |
| 228 | BrowserThread::FILE, FROM_HERE, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 229 | base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher, |
[email protected] | 8105051 | 2011-12-19 19:32:51 | [diff] [blame] | 230 | plugin_dirs[i], file_watcher_delegate_)); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 231 | file_watchers_.push_back(watcher); |
| 232 | } |
| 233 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 236 | const std::string& PluginServiceImpl::GetUILocale() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | return ui_locale_; |
| 238 | } |
| 239 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 240 | PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 241 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 242 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 243 | |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 244 | for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 245 | !iter.Done(); ++iter) { |
| 246 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 247 | if (plugin->info().path == plugin_path) |
| 248 | return plugin; |
| 249 | } |
| 250 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | return NULL; |
| 252 | } |
| 253 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 254 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 255 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 256 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 257 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 258 | for (BrowserChildProcessHost::Iterator iter( |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 259 | content::PROCESS_TYPE_PPAPI_PLUGIN); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 260 | !iter.Done(); ++iter) { |
| 261 | PpapiPluginProcessHost* plugin = |
| 262 | static_cast<PpapiPluginProcessHost*>(*iter); |
| 263 | if (plugin->plugin_path() == plugin_path) |
| 264 | return plugin; |
| 265 | } |
| 266 | |
| 267 | return NULL; |
| 268 | } |
| 269 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 270 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 271 | const FilePath& broker_path) { |
| 272 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 273 | |
| 274 | for (BrowserChildProcessHost::Iterator iter( |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 275 | content::PROCESS_TYPE_PPAPI_BROKER); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 276 | !iter.Done(); ++iter) { |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 277 | PpapiPluginProcessHost* broker = |
| 278 | static_cast<PpapiPluginProcessHost*>(*iter); |
| 279 | if (broker->plugin_path() == broker_path) |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 280 | return broker; |
| 281 | } |
| 282 | |
| 283 | return NULL; |
| 284 | } |
| 285 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 286 | PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 287 | const FilePath& plugin_path) { |
| 288 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 289 | |
| 290 | PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | if (plugin_host) |
| 292 | return plugin_host; |
| 293 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 294 | webkit::WebPluginInfo info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 295 | if (!GetPluginInfoByPath(plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 296 | return NULL; |
| 297 | } |
| 298 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 299 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 300 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
| 301 | if (!new_host->Init(info, ui_locale_)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 302 | NOTREACHED(); // Init is not expected to fail. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 303 | return NULL; |
| 304 | } |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 305 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 308 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 309 | const FilePath& plugin_path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 310 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 311 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 312 | |
| 313 | PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path); |
| 314 | if (plugin_host) |
| 315 | return plugin_host; |
| 316 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 317 | // Validate that the plugin is actually registered. |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 318 | content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 319 | if (!info) |
| 320 | return NULL; |
| 321 | |
| 322 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 323 | return PpapiPluginProcessHost::CreatePluginHost( |
| 324 | *info, |
| 325 | client->GetResourceContext()->host_resolver()); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 328 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 329 | const FilePath& plugin_path) { |
| 330 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 331 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 332 | PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 333 | if (plugin_host) |
| 334 | return plugin_host; |
| 335 | |
| 336 | // Validate that the plugin is actually registered. |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 337 | content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 338 | if (!info) |
| 339 | return NULL; |
| 340 | |
| 341 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 342 | // DCHECK(info->is_out_of_process); |
| 343 | |
| 344 | // This broker isn't loaded by any broker process, so create a new process. |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 345 | return PpapiPluginProcessHost::CreateBrokerHost(*info); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 348 | void PluginServiceImpl::OpenChannelToNpapiPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 349 | int render_process_id, |
| 350 | int render_view_id, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 351 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 352 | const GURL& page_url, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 353 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 354 | PluginProcessHost::Client* client) { |
[email protected] | 76b70f9 | 2011-11-21 19:31:14 | [diff] [blame] | 355 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 356 | DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 357 | pending_plugin_clients_.insert(client); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 358 | |
| 359 | // Make sure plugins are loaded if necessary. |
| 360 | content::PluginServiceFilterParams params = { |
| 361 | render_process_id, |
| 362 | render_view_id, |
| 363 | page_url, |
| 364 | &client->GetResourceContext() |
| 365 | }; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 366 | GetPlugins(base::Bind( |
| 367 | &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 368 | base::Unretained(this), params, url, mime_type, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 371 | void PluginServiceImpl::OpenChannelToPpapiPlugin( |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 372 | const FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 373 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 374 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
| 375 | path, client); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 376 | if (plugin_host) |
| 377 | plugin_host->OpenChannelToPlugin(client); |
| 378 | else // Send error. |
| 379 | client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
| 380 | } |
| 381 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 382 | void PluginServiceImpl::OpenChannelToPpapiBroker( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 383 | const FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 384 | PpapiPluginProcessHost::BrokerClient* client) { |
| 385 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 386 | if (plugin_host) |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 387 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 388 | else // Send error. |
| 389 | client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
| 390 | } |
| 391 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 392 | void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 393 | PluginProcessHost::Client* client) { |
| 394 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 395 | DCHECK(ContainsKey(pending_plugin_clients_, client)); |
| 396 | pending_plugin_clients_.erase(client); |
| 397 | } |
| 398 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 399 | void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 400 | const content::PluginServiceFilterParams& params, |
| 401 | const GURL& url, |
| 402 | const std::string& mime_type, |
| 403 | PluginProcessHost::Client* client, |
| 404 | const std::vector<webkit::WebPluginInfo>&) { |
| 405 | GetAllowedPluginForOpenChannelToPlugin(params.render_process_id, |
| 406 | params.render_view_id, url, params.page_url, mime_type, client, |
| 407 | params.resource_context); |
| 408 | } |
| 409 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 410 | void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 411 | int render_process_id, |
| 412 | int render_view_id, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 413 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 414 | const GURL& page_url, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 415 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 416 | PluginProcessHost::Client* client, |
| 417 | const content::ResourceContext* resource_context) { |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 418 | webkit::WebPluginInfo info; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 419 | bool allow_wildcard = true; |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 420 | bool found = GetPluginInfo( |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 421 | render_process_id, render_view_id, *resource_context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 422 | url, page_url, mime_type, allow_wildcard, |
| 423 | NULL, &info, NULL); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 424 | FilePath plugin_path; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 425 | if (found) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 426 | plugin_path = info.path; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 427 | |
| 428 | // Now we jump back to the IO thread to finish opening the channel. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 429 | BrowserThread::PostTask( |
| 430 | BrowserThread::IO, FROM_HERE, |
| 431 | base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 432 | base::Unretained(this), plugin_path, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 433 | } |
| 434 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 435 | void PluginServiceImpl::FinishOpenChannelToPlugin( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 436 | const FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 437 | PluginProcessHost::Client* client) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 438 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 439 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 440 | // Make sure it hasn't been canceled yet. |
| 441 | if (!ContainsKey(pending_plugin_clients_, client)) |
| 442 | return; |
| 443 | pending_plugin_clients_.erase(client); |
| 444 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 445 | PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 446 | if (plugin_host) { |
| 447 | client->OnFoundPluginProcessHost(plugin_host); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 448 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 449 | } else { |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 450 | client->OnError(); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 451 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 454 | bool PluginServiceImpl::GetPluginInfoArray( |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 455 | const GURL& url, |
| 456 | const std::string& mime_type, |
| 457 | bool allow_wildcard, |
| 458 | std::vector<webkit::WebPluginInfo>* plugins, |
| 459 | std::vector<std::string>* actual_mime_types) { |
| 460 | bool use_stale = false; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 461 | plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard, |
| 462 | &use_stale, plugins, actual_mime_types); |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 463 | return use_stale; |
| 464 | } |
| 465 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 466 | bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
| 467 | int render_view_id, |
| 468 | const content::ResourceContext& context, |
| 469 | const GURL& url, |
| 470 | const GURL& page_url, |
| 471 | const std::string& mime_type, |
| 472 | bool allow_wildcard, |
| 473 | bool* is_stale, |
| 474 | webkit::WebPluginInfo* info, |
| 475 | std::string* actual_mime_type) { |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 476 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 477 | std::vector<std::string> mime_types; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 478 | bool stale = GetPluginInfoArray( |
| 479 | url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 480 | if (is_stale) |
| 481 | *is_stale = stale; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 482 | if (plugins.size() > 1 && |
| 483 | plugins.back().path == |
| 484 | FilePath(webkit::npapi::kDefaultPluginLibraryName)) { |
| 485 | // If there is at least one plug-in handling the required MIME type (apart |
| 486 | // from the default plug-in), we don't need the default plug-in. |
| 487 | plugins.pop_back(); |
| 488 | } |
| 489 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 490 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 491 | if (!filter_ || filter_->ShouldUsePlugin(render_process_id, |
| 492 | render_view_id, |
| 493 | &context, |
| 494 | url, |
| 495 | page_url, |
| 496 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 497 | *info = plugins[i]; |
| 498 | if (actual_mime_type) |
| 499 | *actual_mime_type = mime_types[i]; |
| 500 | return true; |
| 501 | } |
| 502 | } |
| 503 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 506 | bool PluginServiceImpl::GetPluginInfoByPath(const FilePath& plugin_path, |
| 507 | webkit::WebPluginInfo* info) { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 508 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 509 | plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 510 | |
| 511 | for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); |
| 512 | it != plugins.end(); |
| 513 | ++it) { |
| 514 | if (it->path == plugin_path) { |
| 515 | *info = *it; |
| 516 | return true; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | return false; |
| 521 | } |
| 522 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 523 | void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 524 | scoped_refptr<base::MessageLoopProxy> target_loop( |
| 525 | MessageLoop::current()->message_loop_proxy()); |
| 526 | |
[email protected] | 6a0dc7a | 2011-11-02 14:37:07 | [diff] [blame] | 527 | #if defined(OS_WIN) |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 528 | BrowserThread::PostTask( |
| 529 | BrowserThread::FILE, FROM_HERE, |
| 530 | base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this), |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 531 | target_loop, callback)); |
| 532 | #else |
| 533 | std::vector<webkit::WebPluginInfo> cached_plugins; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 534 | if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 535 | // Can't assume the caller is reentrant. |
| 536 | target_loop->PostTask(FROM_HERE, |
| 537 | base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); |
| 538 | } else { |
[email protected] | 4bb85b9 | 2011-11-05 02:53:29 | [diff] [blame] | 539 | // If we switch back to loading plugins in process, then we need to make |
| 540 | // sure g_thread_init() gets called since plugins may call glib at load. |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 541 | if (!plugin_loader_.get()) |
| 542 | plugin_loader_ = new PluginLoaderPosix; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 543 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 544 | base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, |
| 545 | target_loop, callback)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 546 | } |
| 547 | #endif |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 548 | } |
| 549 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 550 | void PluginServiceImpl::GetPluginGroups( |
| 551 | const GetPluginGroupsCallback& callback) { |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 552 | GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); |
| 553 | } |
| 554 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 555 | void PluginServiceImpl::GetPluginsInternal( |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 556 | base::MessageLoopProxy* target_loop, |
| 557 | const PluginService::GetPluginsCallback& callback) { |
| 558 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 559 | |
| 560 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 561 | plugin_list_->GetPlugins(&plugins); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 562 | |
| 563 | target_loop->PostTask(FROM_HERE, |
| 564 | base::Bind(&RunGetPluginsCallback, callback, plugins)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 565 | } |
| 566 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 567 | void PluginServiceImpl::OnWaitableEventSignaled( |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 568 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 569 | #if defined(OS_WIN) |
| 570 | if (waitable_event == hkcu_event_.get()) { |
| 571 | hkcu_key_.StartWatching(); |
| 572 | } else { |
| 573 | hklm_key_.StartWatching(); |
| 574 | } |
| 575 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 576 | plugin_list_->RefreshPlugins(); |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 577 | PurgePluginListCache(NULL, false); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 578 | #else |
| 579 | // This event should only get signaled on a Windows machine. |
| 580 | NOTREACHED(); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 581 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 582 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 583 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 584 | void PluginServiceImpl::Observe(int type, |
| 585 | const content::NotificationSource& source, |
| 586 | const content::NotificationDetails& details) { |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 587 | #if defined(OS_MACOSX) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 588 | if (type == content::NOTIFICATION_APP_ACTIVATED) { |
| 589 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 8105051 | 2011-12-19 19:32:51 | [diff] [blame] | 590 | base::Bind(&NotifyPluginsOfActivation)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 591 | return; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 592 | } |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 593 | #endif |
| 594 | NOTREACHED(); |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 595 | } |
| 596 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 597 | void PluginServiceImpl::RegisterPepperPlugins() { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 598 | // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 599 | PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
| 600 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 601 | RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo()); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 602 | } |
| 603 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 604 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 605 | // There should generally be very few plugins so a brute-force search is fine. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 606 | content::PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 607 | const FilePath& plugin_path) { |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 608 | content::PepperPluginInfo* info = NULL; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 609 | for (size_t i = 0; i < ppapi_plugins_.size(); i++) { |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 610 | if (ppapi_plugins_[i].path == plugin_path) { |
| 611 | info = &ppapi_plugins_[i]; |
| 612 | break; |
| 613 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 614 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 615 | if (info) |
| 616 | return info; |
| 617 | // We did not find the plugin in our list. But wait! the plugin can also |
| 618 | // be a latecomer, as it happens with pepper flash. This information |
| 619 | // can be obtained from the PluginList singleton and we can use it to |
| 620 | // construct it and add it to the list. This same deal needs to be done |
| 621 | // in the renderer side in PepperPluginRegistry. |
| 622 | webkit::WebPluginInfo webplugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 623 | if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 624 | return NULL; |
[email protected] | 738a721 | 2011-10-21 17:33:52 | [diff] [blame] | 625 | content::PepperPluginInfo new_pepper_info; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 626 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 627 | return NULL; |
| 628 | ppapi_plugins_.push_back(new_pepper_info); |
| 629 | return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 632 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 633 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 634 | void PluginServiceImpl::RegisterFilePathWatcher( |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 635 | FilePathWatcher *watcher, |
| 636 | const FilePath& path, |
| 637 | FilePathWatcher::Delegate* delegate) { |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 638 | bool result = watcher->Watch(path, delegate); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 639 | DCHECK(result); |
| 640 | } |
| 641 | #endif |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 642 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 643 | void PluginServiceImpl::SetFilter(content::PluginServiceFilter* filter) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 644 | filter_ = filter; |
| 645 | } |
| 646 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 647 | content::PluginServiceFilter* PluginServiceImpl::GetFilter() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 648 | return filter_; |
| 649 | } |
| 650 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 651 | void PluginServiceImpl::RefreshPlugins() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 652 | plugin_list_->RefreshPlugins(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 653 | } |
| 654 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 655 | void PluginServiceImpl::AddExtraPluginPath(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 656 | plugin_list_->AddExtraPluginPath(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 659 | void PluginServiceImpl::RemoveExtraPluginPath(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 660 | plugin_list_->RemoveExtraPluginPath(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 661 | } |
| 662 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 663 | void PluginServiceImpl::UnregisterInternalPlugin(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 664 | plugin_list_->UnregisterInternalPlugin(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 665 | } |
| 666 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 667 | void PluginServiceImpl::SetPluginListForTesting( |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 668 | webkit::npapi::PluginList* plugin_list) { |
| 669 | plugin_list_ = plugin_list; |
| 670 | } |
| 671 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 672 | void PluginServiceImpl::RegisterInternalPlugin( |
| 673 | const webkit::WebPluginInfo& info) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 674 | plugin_list_->RegisterInternalPlugin(info); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 675 | } |
| 676 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 677 | string16 PluginServiceImpl::GetPluginGroupName(const std::string& plugin_name) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 678 | return plugin_list_->GetPluginGroupName(plugin_name); |
| 679 | } |
| 680 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame^] | 681 | webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 682 | return plugin_list_; |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 683 | } |