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