[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] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | 2fccd3f | 2013-07-18 00:10:52 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
[email protected] | 7ccb707 | 2013-06-10 20:56:28 | [diff] [blame] | 12 | #include "base/message_loop/message_loop_proxy.h" |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 13 | #include "base/metrics/histogram.h" |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 14 | #include "base/path_service.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 17 | #include "base/synchronization/waitable_event.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 18 | #include "base/threading/thread.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] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 23 | #include "content/common/plugin_list.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 24 | #include "content/common/view_messages.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 25 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 26 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 31f376c | 2012-03-13 16:43:09 | [diff] [blame] | 27 | #include "content/public/browser/plugin_service_filter.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 28 | #include "content/public/browser/resource_context.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 29 | #include "content/public/common/content_switches.h" |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 30 | #include "content/public/common/process_type.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 31 | #include "content/public/common/webplugininfo.h" |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 32 | #include "webkit/plugins/plugin_constants.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 33 | |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 34 | #if defined(OS_WIN) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 35 | #include "content/common/plugin_constants_win.h" |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 36 | #include "ui/base/win/hwnd_util.h" |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 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] | 6665571f | 2013-01-15 07:59:52 | [diff] [blame] | 44 | using ::base::FilePathWatcher; |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 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] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 50 | // This enum is used to collect Flash usage data. |
| 51 | enum FlashUsage { |
| 52 | // Number of browser processes that have started at least one NPAPI Flash |
| 53 | // process during their lifetime. |
| 54 | START_NPAPI_FLASH_AT_LEAST_ONCE, |
| 55 | // Number of browser processes that have started at least one PPAPI Flash |
| 56 | // process during their lifetime. |
| 57 | START_PPAPI_FLASH_AT_LEAST_ONCE, |
| 58 | // Total number of browser processes. |
| 59 | TOTAL_BROWSER_PROCESSES, |
| 60 | FLASH_USAGE_ENUM_COUNT |
| 61 | }; |
| 62 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 63 | bool LoadPluginListInProcess() { |
| 64 | #if defined(OS_WIN) |
| 65 | return true; |
| 66 | #else |
| 67 | // If on POSIX, we don't want to load the list of NPAPI plugins in-process as |
| 68 | // that causes instability. |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 69 | |
| 70 | // Can't load the plugins on the utility thread when in single process mode |
[email protected] | 1021245 | 2013-07-16 20:10:55 | [diff] [blame] | 71 | // since that requires GTK which can only be used on the main thread. |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 72 | if (RenderProcessHost::run_renderer_in_process()) |
| 73 | return true; |
| 74 | |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 75 | return !PluginService::GetInstance()->NPAPIPluginsSupported(); |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 76 | #endif |
| 77 | } |
| 78 | |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 79 | // Callback set on the PluginList to assert that plugin loading happens on the |
| 80 | // correct thread. |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 81 | void WillLoadPluginsCallback( |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 82 | base::SequencedWorkerPool::SequenceToken token) { |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 83 | if (LoadPluginListInProcess()) { |
| 84 | CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 85 | token)); |
| 86 | } else { |
| 87 | CHECK(false) << "Plugin loading should happen out-of-process."; |
| 88 | } |
[email protected] | a7991225 | 2012-05-16 11:52:19 | [diff] [blame] | 89 | } |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 90 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 91 | #if defined(OS_MACOSX) |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 92 | void NotifyPluginsOfActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 93 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 94 | |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 95 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) |
| 96 | iter->OnAppActivation(); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 97 | } |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 98 | #endif |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 99 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 100 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 101 | void NotifyPluginDirChanged(const base::FilePath& path, bool error) { |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 102 | if (error) { |
[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(); |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 106 | return; |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 107 | } |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 108 | VLOG(1) << "Watched path changed: " << path.value(); |
| 109 | // Make the plugin list update itself |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 110 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 111 | BrowserThread::PostTask( |
| 112 | BrowserThread::UI, FROM_HERE, |
| 113 | base::Bind(&PluginService::PurgePluginListCache, |
| 114 | static_cast<BrowserContext*>(NULL), false)); |
| 115 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 116 | #endif |
| 117 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 118 | } // namespace |
| 119 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 120 | // static |
| 121 | PluginService* PluginService::GetInstance() { |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 122 | return PluginServiceImpl::GetInstance(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
| 126 | bool reload_pages) { |
| 127 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 128 | !it.IsAtEnd(); it.Advance()) { |
| 129 | RenderProcessHost* host = it.GetCurrentValue(); |
| 130 | if (!browser_context || host->GetBrowserContext() == browser_context) |
| 131 | host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 132 | } |
| 133 | } |
| 134 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 136 | PluginServiceImpl* PluginServiceImpl::GetInstance() { |
| 137 | return Singleton<PluginServiceImpl>::get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 140 | PluginServiceImpl::PluginServiceImpl() |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 141 | : filter_(NULL) { |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 142 | // Collect the total number of browser processes (which create |
| 143 | // PluginServiceImpl objects, to be precise). The number is used to normalize |
| 144 | // the number of processes which start at least one NPAPI/PPAPI Flash process. |
| 145 | static bool counted = false; |
| 146 | if (!counted) { |
| 147 | counted = true; |
| 148 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
| 149 | FLASH_USAGE_ENUM_COUNT); |
| 150 | } |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 153 | PluginServiceImpl::~PluginServiceImpl() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 154 | #if defined(OS_WIN) |
| 155 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 156 | hkcu_watcher_.StopWatching(); |
| 157 | hklm_watcher_.StopWatching(); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 158 | if (hkcu_event_) |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 159 | hkcu_event_->Release(); |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 160 | if (hklm_event_) |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 161 | hklm_event_->Release(); |
| 162 | #endif |
| 163 | // Make sure no plugin channel requests have been leaked. |
| 164 | DCHECK(pending_plugin_clients_.empty()); |
| 165 | } |
| 166 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 167 | void PluginServiceImpl::Init() { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 168 | plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 169 | PluginList::Singleton()->set_will_load_plugins_callback( |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 170 | base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 171 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 172 | RegisterPepperPlugins(); |
| 173 | |
[email protected] | 0f7d449e | 2013-01-23 15:12:35 | [diff] [blame] | 174 | // The --site-per-process flag enables an out-of-process iframes |
| 175 | // prototype, which uses WebView for rendering. We need to register the MIME |
| 176 | // type we use with the plugin, so the renderer can instantiate it. |
| 177 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 178 | if (command_line->HasSwitch(switches::kSitePerProcess)) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 179 | WebPluginInfo webview_plugin( |
[email protected] | 0f7d449e | 2013-01-23 15:12:35 | [diff] [blame] | 180 | ASCIIToUTF16("WebView Tag"), |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 181 | base::FilePath(), |
[email protected] | 0f7d449e | 2013-01-23 15:12:35 | [diff] [blame] | 182 | ASCIIToUTF16("1.2.3.4"), |
| 183 | ASCIIToUTF16("Browser Plugin.")); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 184 | webview_plugin.type = WebPluginInfo::PLUGIN_TYPE_NPAPI; |
| 185 | WebPluginMimeType webview_plugin_mime_type; |
[email protected] | 0f7d449e | 2013-01-23 15:12:35 | [diff] [blame] | 186 | webview_plugin_mime_type.mime_type = "application/browser-plugin"; |
| 187 | webview_plugin_mime_type.file_extensions.push_back("*"); |
| 188 | webview_plugin.mime_types.push_back(webview_plugin_mime_type); |
| 189 | RegisterInternalPlugin(webview_plugin, true); |
| 190 | } |
| 191 | |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 192 | // Load any specified on the command line as well. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 193 | base::FilePath path = |
| 194 | command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 195 | if (!path.empty()) |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 196 | AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 197 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 198 | if (!path.empty()) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 199 | PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | e87ce86 | 2013-06-12 17:30:48 | [diff] [blame] | 200 | |
| 201 | if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 202 | PluginList::Singleton()->DisablePluginsDiscovery(); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 205 | void PluginServiceImpl::StartWatchingPlugins() { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 206 | // Start watching for changes in the plugin list. This means watching |
| 207 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 208 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 209 | #if defined(OS_WIN) |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 210 | if (hkcu_key_.Create(HKEY_CURRENT_USER, |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 211 | kRegistryMozillaPlugins, |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 212 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 213 | if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
| 214 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
[email protected] | 329be05 | 2013-02-04 18:14:28 | [diff] [blame] | 215 | base::WaitableEventWatcher::EventCallback callback = |
| 216 | base::Bind(&PluginServiceImpl::OnWaitableEventSignaled, |
| 217 | base::Unretained(this)); |
| 218 | hkcu_watcher_.StartWatching(hkcu_event_.get(), callback); |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 219 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 220 | } |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 221 | if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 222 | kRegistryMozillaPlugins, |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 223 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 224 | if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
| 225 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
[email protected] | 329be05 | 2013-02-04 18:14:28 | [diff] [blame] | 226 | base::WaitableEventWatcher::EventCallback callback = |
| 227 | base::Bind(&PluginServiceImpl::OnWaitableEventSignaled, |
| 228 | base::Unretained(this)); |
| 229 | hklm_watcher_.StartWatching(hklm_event_.get(), callback); |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 230 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 231 | } |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 232 | #endif |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 233 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 234 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 235 | // important plugins register themselves in the registry so no need to do that. |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 236 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 237 | // Get the list of all paths for registering the FilePathWatchers |
| 238 | // that will track and if needed reload the list of plugins on runtime. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 239 | std::vector<base::FilePath> plugin_dirs; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 240 | PluginList::Singleton()->GetPluginDirectories(&plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 241 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 242 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 243 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 244 | // We don't watch for file changes in windows now but if this should ever |
| 245 | // be extended to Windows these lines might save some time of debugging. |
| 246 | #if defined(OS_WIN) |
| 247 | if (!plugin_dirs[i].IsAbsolute()) |
| 248 | continue; |
| 249 | #endif |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 250 | FilePathWatcher* watcher = new FilePathWatcher(); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 251 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 252 | BrowserThread::PostTask( |
| 253 | BrowserThread::FILE, FROM_HERE, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 254 | base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 255 | plugin_dirs[i])); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 256 | file_watchers_.push_back(watcher); |
| 257 | } |
| 258 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 261 | PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 262 | const base::FilePath& plugin_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 263 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { |
| 264 | if (iter->info().path == plugin_path) |
| 265 | return *iter; |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 266 | } |
| 267 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 268 | return NULL; |
| 269 | } |
| 270 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 271 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 272 | const base::FilePath& plugin_path, |
| 273 | const base::FilePath& profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 274 | for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 275 | if (iter->plugin_path() == plugin_path && |
| 276 | iter->profile_data_directory() == profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 277 | return *iter; |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 278 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 279 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 280 | return NULL; |
| 281 | } |
| 282 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 283 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 284 | const base::FilePath& broker_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 285 | for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { |
| 286 | if (iter->plugin_path() == broker_path) |
| 287 | return *iter; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | return NULL; |
| 291 | } |
| 292 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 293 | PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 294 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 295 | const base::FilePath& plugin_path) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 296 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 297 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 298 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 299 | return NULL; |
| 300 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 301 | PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 302 | if (plugin_host) |
| 303 | return plugin_host; |
| 304 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 305 | WebPluginInfo info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 306 | if (!GetPluginInfoByPath(plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 307 | return NULL; |
| 308 | } |
| 309 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 310 | // Record when NPAPI Flash process is started for the first time. |
| 311 | static bool counted = false; |
| 312 | if (!counted && UTF16ToUTF8(info.name) == kFlashPluginName) { |
| 313 | counted = true; |
| 314 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", |
| 315 | START_NPAPI_FLASH_AT_LEAST_ONCE, |
| 316 | FLASH_USAGE_ENUM_COUNT); |
| 317 | } |
| 318 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | // 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] | 320 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 321 | if (!new_host->Init(info)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 322 | NOTREACHED(); // Init is not expected to fail. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 323 | return NULL; |
| 324 | } |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 325 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 328 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 329 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 330 | const base::FilePath& plugin_path, |
| 331 | const base::FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 332 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 333 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 334 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 335 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 336 | return NULL; |
| 337 | |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 338 | PpapiPluginProcessHost* plugin_host = |
| 339 | FindPpapiPluginProcess(plugin_path, profile_data_directory); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 340 | if (plugin_host) |
| 341 | return plugin_host; |
| 342 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 343 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 344 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 345 | if (!info) |
| 346 | return NULL; |
| 347 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 348 | // Record when PPAPI Flash process is started for the first time. |
| 349 | static bool counted = false; |
| 350 | if (!counted && info->name == kFlashPluginName) { |
| 351 | counted = true; |
| 352 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", |
| 353 | START_PPAPI_FLASH_AT_LEAST_ONCE, |
| 354 | FLASH_USAGE_ENUM_COUNT); |
| 355 | } |
| 356 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 357 | // 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] | 358 | return PpapiPluginProcessHost::CreatePluginHost( |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 359 | *info, profile_data_directory, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 360 | client->GetResourceContext()->GetHostResolver()); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 363 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 364 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 365 | const base::FilePath& plugin_path) { |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 366 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 367 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 368 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 369 | return NULL; |
| 370 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 371 | PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 372 | if (plugin_host) |
| 373 | return plugin_host; |
| 374 | |
| 375 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 376 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 377 | if (!info) |
| 378 | return NULL; |
| 379 | |
| 380 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 381 | // DCHECK(info->is_out_of_process); |
| 382 | |
| 383 | // 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] | 384 | return PpapiPluginProcessHost::CreateBrokerHost(*info); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 387 | void PluginServiceImpl::OpenChannelToNpapiPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 388 | int render_process_id, |
| 389 | int render_view_id, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 390 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 391 | const GURL& page_url, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 392 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 393 | PluginProcessHost::Client* client) { |
[email protected] | 76b70f9 | 2011-11-21 19:31:14 | [diff] [blame] | 394 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 395 | DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 396 | pending_plugin_clients_.insert(client); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 397 | |
| 398 | // Make sure plugins are loaded if necessary. |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 399 | PluginServiceFilterParams params = { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 400 | render_process_id, |
| 401 | render_view_id, |
| 402 | page_url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 403 | client->GetResourceContext() |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 404 | }; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 405 | GetPlugins(base::Bind( |
| 406 | &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 407 | base::Unretained(this), params, url, mime_type, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 410 | void PluginServiceImpl::OpenChannelToPpapiPlugin( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 411 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 412 | const base::FilePath& plugin_path, |
| 413 | const base::FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 414 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 415 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 416 | render_process_id, plugin_path, profile_data_directory, client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 417 | if (plugin_host) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 418 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 419 | } else { |
| 420 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 421 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 422 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 425 | void PluginServiceImpl::OpenChannelToPpapiBroker( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 426 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 427 | const base::FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 428 | PpapiPluginProcessHost::BrokerClient* client) { |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 429 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess( |
| 430 | render_process_id, path); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 431 | if (plugin_host) { |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 432 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 433 | } else { |
| 434 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 435 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 436 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 437 | } |
| 438 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 439 | void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 440 | PluginProcessHost::Client* client) { |
| 441 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 442 | DCHECK(ContainsKey(pending_plugin_clients_, client)); |
| 443 | pending_plugin_clients_.erase(client); |
| 444 | } |
| 445 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 446 | void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 447 | const PluginServiceFilterParams& params, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 448 | const GURL& url, |
| 449 | const std::string& mime_type, |
| 450 | PluginProcessHost::Client* client, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 451 | const std::vector<WebPluginInfo>&) { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 452 | GetAllowedPluginForOpenChannelToPlugin(params.render_process_id, |
| 453 | params.render_view_id, url, params.page_url, mime_type, client, |
| 454 | params.resource_context); |
| 455 | } |
| 456 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 457 | void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 458 | int render_process_id, |
| 459 | int render_view_id, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 460 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 461 | const GURL& page_url, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 462 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 463 | PluginProcessHost::Client* client, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 464 | ResourceContext* resource_context) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 465 | WebPluginInfo info; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 466 | bool allow_wildcard = true; |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 467 | bool found = GetPluginInfo( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 468 | render_process_id, render_view_id, resource_context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 469 | url, page_url, mime_type, allow_wildcard, |
| 470 | NULL, &info, NULL); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 471 | base::FilePath plugin_path; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 472 | if (found) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 473 | plugin_path = info.path; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 474 | |
| 475 | // Now we jump back to the IO thread to finish opening the channel. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 476 | BrowserThread::PostTask( |
| 477 | BrowserThread::IO, FROM_HERE, |
| 478 | base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 479 | base::Unretained(this), |
| 480 | render_process_id, |
| 481 | plugin_path, |
| 482 | client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 483 | } |
| 484 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 485 | void PluginServiceImpl::FinishOpenChannelToPlugin( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 486 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 487 | const base::FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 488 | PluginProcessHost::Client* client) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 489 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 490 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 491 | // Make sure it hasn't been canceled yet. |
| 492 | if (!ContainsKey(pending_plugin_clients_, client)) |
| 493 | return; |
| 494 | pending_plugin_clients_.erase(client); |
| 495 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 496 | PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess( |
| 497 | render_process_id, plugin_path); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 498 | if (plugin_host) { |
| 499 | client->OnFoundPluginProcessHost(plugin_host); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 500 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 501 | } else { |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 502 | client->OnError(); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 503 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 506 | bool PluginServiceImpl::GetPluginInfoArray( |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 507 | const GURL& url, |
| 508 | const std::string& mime_type, |
| 509 | bool allow_wildcard, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 510 | std::vector<WebPluginInfo>* plugins, |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 511 | std::vector<std::string>* actual_mime_types) { |
| 512 | bool use_stale = false; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 513 | PluginList::Singleton()->GetPluginInfoArray( |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 514 | url, mime_type, allow_wildcard, &use_stale, NPAPIPluginsSupported(), |
| 515 | plugins, actual_mime_types); |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 516 | return use_stale; |
| 517 | } |
| 518 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 519 | bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
| 520 | int render_view_id, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 521 | ResourceContext* context, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 522 | const GURL& url, |
| 523 | const GURL& page_url, |
| 524 | const std::string& mime_type, |
| 525 | bool allow_wildcard, |
| 526 | bool* is_stale, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 527 | WebPluginInfo* info, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 528 | std::string* actual_mime_type) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 529 | std::vector<WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 530 | std::vector<std::string> mime_types; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 531 | bool stale = GetPluginInfoArray( |
| 532 | url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 533 | if (is_stale) |
| 534 | *is_stale = stale; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 535 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 536 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 05f51128 | 2013-02-05 15:02:50 | [diff] [blame] | 537 | if (!filter_ || filter_->IsPluginAvailable(render_process_id, |
| 538 | render_view_id, |
| 539 | context, |
| 540 | url, |
| 541 | page_url, |
| 542 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 543 | *info = plugins[i]; |
| 544 | if (actual_mime_type) |
| 545 | *actual_mime_type = mime_types[i]; |
| 546 | return true; |
| 547 | } |
| 548 | } |
| 549 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 550 | } |
| 551 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 552 | bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 553 | WebPluginInfo* info) { |
| 554 | std::vector<WebPluginInfo> plugins; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 555 | PluginList::Singleton()->GetPluginsNoRefresh(&plugins); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 556 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 557 | for (std::vector<WebPluginInfo>::iterator it = plugins.begin(); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 558 | it != plugins.end(); |
| 559 | ++it) { |
| 560 | if (it->path == plugin_path) { |
| 561 | *info = *it; |
| 562 | return true; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | return false; |
| 567 | } |
| 568 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 569 | string16 PluginServiceImpl::GetPluginDisplayNameByPath( |
| 570 | const base::FilePath& path) { |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 571 | string16 plugin_name = path.LossyDisplayName(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 572 | WebPluginInfo info; |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 573 | if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) && |
| 574 | !info.name.empty()) { |
| 575 | plugin_name = info.name; |
| 576 | #if defined(OS_MACOSX) |
| 577 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 578 | // terrible, so look for that and strip it off if present. |
| 579 | const std::string kPluginExtension = ".plugin"; |
| 580 | if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) |
| 581 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 582 | #endif // OS_MACOSX |
| 583 | } |
| 584 | return plugin_name; |
| 585 | } |
| 586 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 587 | void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 588 | scoped_refptr<base::MessageLoopProxy> target_loop( |
[email protected] | dd32b127 | 2013-05-04 14:17:11 | [diff] [blame] | 589 | base::MessageLoop::current()->message_loop_proxy()); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 590 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 591 | if (LoadPluginListInProcess()) { |
| 592 | BrowserThread::GetBlockingPool()-> |
| 593 | PostSequencedWorkerTaskWithShutdownBehavior( |
| 594 | plugin_list_token_, |
| 595 | FROM_HERE, |
| 596 | base::Bind(&PluginServiceImpl::GetPluginsInternal, |
| 597 | base::Unretained(this), |
| 598 | target_loop, callback), |
| 599 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 600 | return; |
| 601 | } |
| 602 | #if defined(OS_POSIX) |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 603 | std::vector<WebPluginInfo> cached_plugins; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 604 | if (PluginList::Singleton()->GetPluginsNoRefresh(&cached_plugins)) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 605 | // Can't assume the caller is reentrant. |
| 606 | target_loop->PostTask(FROM_HERE, |
[email protected] | 00b2543 | 2012-04-07 04:21:37 | [diff] [blame] | 607 | base::Bind(callback, cached_plugins)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 608 | } else { |
[email protected] | 4bb85b9 | 2011-11-05 02:53:29 | [diff] [blame] | 609 | // If we switch back to loading plugins in process, then we need to make |
| 610 | // sure g_thread_init() gets called since plugins may call glib at load. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 611 | if (!plugin_loader_.get()) |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 612 | plugin_loader_ = new PluginLoaderPosix; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 613 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 614 | base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, |
| 615 | target_loop, callback)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 616 | } |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 617 | #else |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 618 | NOTREACHED(); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 619 | #endif |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 622 | void PluginServiceImpl::GetPluginsInternal( |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 623 | base::MessageLoopProxy* target_loop, |
| 624 | const PluginService::GetPluginsCallback& callback) { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 625 | DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 626 | plugin_list_token_)); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 627 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 628 | std::vector<WebPluginInfo> plugins; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 629 | PluginList::Singleton()->GetPlugins(&plugins, NPAPIPluginsSupported()); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 630 | |
| 631 | target_loop->PostTask(FROM_HERE, |
[email protected] | 00b2543 | 2012-04-07 04:21:37 | [diff] [blame] | 632 | base::Bind(callback, plugins)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 633 | } |
| 634 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 635 | void PluginServiceImpl::OnWaitableEventSignaled( |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 636 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 637 | #if defined(OS_WIN) |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 638 | if (waitable_event == hkcu_event_) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 639 | hkcu_key_.StartWatching(); |
| 640 | } else { |
| 641 | hklm_key_.StartWatching(); |
| 642 | } |
| 643 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 644 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 645 | PurgePluginListCache(NULL, false); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 646 | #else |
| 647 | // This event should only get signaled on a Windows machine. |
| 648 | NOTREACHED(); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 649 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 650 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 651 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 652 | void PluginServiceImpl::RegisterPepperPlugins() { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 653 | // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 654 | PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
| 655 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 656 | RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 657 | } |
| 658 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 659 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 660 | // 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] | 661 | PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 662 | const base::FilePath& plugin_path) { |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 663 | PepperPluginInfo* info = NULL; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 664 | for (size_t i = 0; i < ppapi_plugins_.size(); i++) { |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 665 | if (ppapi_plugins_[i].path == plugin_path) { |
| 666 | info = &ppapi_plugins_[i]; |
| 667 | break; |
| 668 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 669 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 670 | if (info) |
| 671 | return info; |
| 672 | // We did not find the plugin in our list. But wait! the plugin can also |
| 673 | // be a latecomer, as it happens with pepper flash. This information |
| 674 | // can be obtained from the PluginList singleton and we can use it to |
| 675 | // construct it and add it to the list. This same deal needs to be done |
| 676 | // in the renderer side in PepperPluginRegistry. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 677 | WebPluginInfo webplugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 678 | if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 679 | return NULL; |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 680 | PepperPluginInfo new_pepper_info; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 681 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 682 | return NULL; |
| 683 | ppapi_plugins_.push_back(new_pepper_info); |
| 684 | return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 685 | } |
| 686 | |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 687 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 688 | // static |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 689 | void PluginServiceImpl::RegisterFilePathWatcher(FilePathWatcher* watcher, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 690 | const base::FilePath& path) { |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 691 | bool result = watcher->Watch(path, false, |
| 692 | base::Bind(&NotifyPluginDirChanged)); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 693 | DCHECK(result); |
| 694 | } |
| 695 | #endif |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 696 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 697 | void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 698 | filter_ = filter; |
| 699 | } |
| 700 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 701 | PluginServiceFilter* PluginServiceImpl::GetFilter() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 702 | return filter_; |
| 703 | } |
| 704 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 705 | void PluginServiceImpl::ForcePluginShutdown(const base::FilePath& plugin_path) { |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 706 | if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 707 | BrowserThread::PostTask( |
| 708 | BrowserThread::IO, FROM_HERE, |
| 709 | base::Bind(&PluginServiceImpl::ForcePluginShutdown, |
| 710 | base::Unretained(this), plugin_path)); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | PluginProcessHost* plugin = FindNpapiPluginProcess(plugin_path); |
| 715 | if (plugin) |
| 716 | plugin->ForceShutdown(); |
| 717 | } |
| 718 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 719 | static const unsigned int kMaxCrashesPerInterval = 3; |
| 720 | static const unsigned int kCrashesInterval = 120; |
| 721 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 722 | void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) { |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 723 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 724 | std::map<base::FilePath, std::vector<base::Time> >::iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 725 | crash_times_.find(path); |
| 726 | if (i == crash_times_.end()) { |
| 727 | crash_times_[path] = std::vector<base::Time>(); |
| 728 | i = crash_times_.find(path); |
| 729 | } |
| 730 | if (i->second.size() == kMaxCrashesPerInterval) { |
| 731 | i->second.erase(i->second.begin()); |
| 732 | } |
| 733 | base::Time time = base::Time::Now(); |
| 734 | i->second.push_back(time); |
| 735 | } |
| 736 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 737 | bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) { |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 738 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 739 | std::map<base::FilePath, std::vector<base::Time> >::const_iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 740 | crash_times_.find(path); |
| 741 | if (i == crash_times_.end()) { |
| 742 | return false; |
| 743 | } |
| 744 | if (i->second.size() != kMaxCrashesPerInterval) { |
| 745 | return false; |
| 746 | } |
| 747 | base::TimeDelta delta = base::Time::Now() - i->second[0]; |
[email protected] | d8c7006 | 2013-04-24 00:22:34 | [diff] [blame] | 748 | return delta.InSeconds() <= kCrashesInterval; |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 751 | void PluginServiceImpl::RefreshPlugins() { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 752 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 755 | void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 756 | if (!NPAPIPluginsSupported()) { |
| 757 | // TODO(jam): remove and just have CHECK once we're sure this doesn't get |
| 758 | // triggered. |
| 759 | DLOG(INFO) << "NPAPI plugins not supported"; |
| 760 | return; |
| 761 | } |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 762 | PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 765 | void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 766 | PluginList::Singleton()->RemoveExtraPluginPath(path); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 770 | PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | void PluginServiceImpl::RegisterInternalPlugin( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 774 | const WebPluginInfo& info, |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 775 | bool add_at_beginning) { |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 776 | if (!NPAPIPluginsSupported() && |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 777 | info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 778 | DLOG(INFO) << "Don't register NPAPI plugins when they're not supported"; |
| 779 | return; |
| 780 | } |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 781 | PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 782 | } |
| 783 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 784 | void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 785 | PluginList::Singleton()->UnregisterInternalPlugin(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 786 | } |
| 787 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 788 | void PluginServiceImpl::GetInternalPlugins( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame^] | 789 | std::vector<WebPluginInfo>* plugins) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 790 | PluginList::Singleton()->GetInternalPlugins(plugins); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 793 | bool PluginServiceImpl::NPAPIPluginsSupported() { |
| 794 | #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_AURA)) |
| 795 | return true; |
| 796 | #else |
| 797 | return false; |
| 798 | #endif |
| 799 | } |
| 800 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 801 | void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 802 | PluginList::Singleton()->DisablePluginsDiscovery(); |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 805 | #if defined(OS_MACOSX) |
| 806 | void PluginServiceImpl::AppActivated() { |
| 807 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 808 | base::Bind(&NotifyPluginsOfActivation)); |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 809 | } |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 810 | #elif defined(OS_WIN) |
| 811 | |
| 812 | bool GetPluginPropertyFromWindow( |
| 813 | HWND window, const wchar_t* plugin_atom_property, |
| 814 | base::string16* plugin_property) { |
| 815 | ATOM plugin_atom = reinterpret_cast<ATOM>( |
| 816 | GetPropW(window, plugin_atom_property)); |
| 817 | if (plugin_atom != 0) { |
| 818 | WCHAR plugin_property_local[MAX_PATH] = {0}; |
| 819 | GlobalGetAtomNameW(plugin_atom, |
| 820 | plugin_property_local, |
| 821 | ARRAYSIZE(plugin_property_local)); |
| 822 | *plugin_property = plugin_property_local; |
| 823 | return true; |
| 824 | } |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | bool PluginServiceImpl::GetPluginInfoFromWindow( |
| 829 | HWND window, |
| 830 | base::string16* plugin_name, |
| 831 | base::string16* plugin_version) { |
| 832 | if (!IsPluginWindow(window)) |
| 833 | return false; |
| 834 | |
| 835 | GetPluginPropertyFromWindow( |
| 836 | window, kPluginNameAtomProperty, plugin_name); |
| 837 | GetPluginPropertyFromWindow( |
| 838 | window, kPluginVersionAtomProperty, plugin_version); |
| 839 | return true; |
| 840 | } |
| 841 | |
| 842 | bool PluginServiceImpl::IsPluginWindow(HWND window) { |
| 843 | return ui::GetClassName(window) == base::string16(kNativeWindowClassName); |
| 844 | } |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 845 | #endif |
| 846 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 847 | } // namespace content |