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