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