| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/plugin_service.h" | 7 #include "chrome/browser/plugin_service.h" |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/common/notification_service.h" | 33 #include "chrome/common/notification_service.h" |
| 34 #include "chrome/common/pepper_plugin_registry.h" | 34 #include "chrome/common/pepper_plugin_registry.h" |
| 35 #include "chrome/common/plugin_messages.h" | 35 #include "chrome/common/plugin_messages.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/render_messages.h" | 37 #include "chrome/common/render_messages.h" |
| 38 #ifndef DISABLE_NACL | 38 #ifndef DISABLE_NACL |
| 39 #include "native_client/src/trusted/plugin/nacl_entry_points.h" | 39 #include "native_client/src/trusted/plugin/nacl_entry_points.h" |
| 40 #endif | 40 #endif |
| 41 #include "webkit/glue/plugins/plugin_constants_win.h" | 41 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 42 #include "webkit/glue/plugins/plugin_list.h" | 42 #include "webkit/glue/plugins/plugin_list.h" |
| 43 #include "webkit/glue/plugins/webplugininfo.h" |
| 44 |
| 45 #if defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/chromeos/plugin_selection_policy.h" |
| 47 #endif |
| 43 | 48 |
| 44 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
| 45 static void NotifyPluginsOfActivation() { | 50 static void NotifyPluginsOfActivation() { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 47 | 52 |
| 48 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 53 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
| 49 !iter.Done(); ++iter) { | 54 !iter.Done(); ++iter) { |
| 50 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 55 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 51 plugin->OnAppActivation(); | 56 plugin->OnAppActivation(); |
| 52 } | 57 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { | 121 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { |
| 117 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); | 122 NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
| 118 } | 123 } |
| 119 | 124 |
| 120 #ifndef DISABLE_NACL | 125 #ifndef DISABLE_NACL |
| 121 if (command_line->HasSwitch(switches::kInternalNaCl)) { | 126 if (command_line->HasSwitch(switches::kInternalNaCl)) { |
| 122 RegisterInternalNaClPlugin(); | 127 RegisterInternalNaClPlugin(); |
| 123 } | 128 } |
| 124 #endif | 129 #endif |
| 125 | 130 |
| 131 #if defined(OS_CHROMEOS) |
| 132 plugin_selection_policy_ = new chromeos::PluginSelectionPolicy; |
| 133 plugin_selection_policy_->StartInit(); |
| 134 #endif |
| 135 |
| 126 chrome::RegisterInternalGPUPlugin(); | 136 chrome::RegisterInternalGPUPlugin(); |
| 127 | 137 |
| 128 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 129 hkcu_key_.Create( | 139 hkcu_key_.Create( |
| 130 HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY); | 140 HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY); |
| 131 hklm_key_.Create( | 141 hklm_key_.Create( |
| 132 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY); | 142 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY); |
| 133 if (hkcu_key_.StartWatching()) { | 143 if (hkcu_key_.StartWatching()) { |
| 134 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); | 144 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 135 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); | 145 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return NULL; | 246 return NULL; |
| 237 } | 247 } |
| 238 | 248 |
| 239 return plugin_host; | 249 return plugin_host; |
| 240 } | 250 } |
| 241 | 251 |
| 242 void PluginService::OpenChannelToPlugin( | 252 void PluginService::OpenChannelToPlugin( |
| 243 ResourceMessageFilter* renderer_msg_filter, | 253 ResourceMessageFilter* renderer_msg_filter, |
| 244 const GURL& url, | 254 const GURL& url, |
| 245 const std::string& mime_type, | 255 const std::string& mime_type, |
| 246 const std::string& locale, | 256 IPC::Message* reply_msg) { |
| 257 // The PluginList::GetFirstAllowedPluginInfo may need to load the |
| 258 // plugins. Don't do it on the IO thread. |
| 259 BrowserThread::PostTask( |
| 260 BrowserThread::FILE, FROM_HERE, |
| 261 NewRunnableMethod( |
| 262 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, |
| 263 renderer_msg_filter, url, mime_type, reply_msg)); |
| 264 } |
| 265 |
| 266 void PluginService::GetAllowedPluginForOpenChannelToPlugin( |
| 267 ResourceMessageFilter* renderer_msg_filter, |
| 268 const GURL& url, |
| 269 const std::string& mime_type, |
| 270 IPC::Message* reply_msg) { |
| 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 272 WebPluginInfo info; |
| 273 bool found = GetFirstAllowedPluginInfo(url, mime_type, &info, NULL); |
| 274 FilePath plugin_path; |
| 275 if (found && info.enabled) |
| 276 plugin_path = FilePath(info.path); |
| 277 |
| 278 // Now we jump back to the IO thread to finish opening the channel. |
| 279 BrowserThread::PostTask( |
| 280 BrowserThread::IO, FROM_HERE, |
| 281 NewRunnableMethod( |
| 282 this, &PluginService::FinishOpenChannelToPlugin, |
| 283 renderer_msg_filter, mime_type, plugin_path, reply_msg)); |
| 284 } |
| 285 |
| 286 void PluginService::FinishOpenChannelToPlugin( |
| 287 ResourceMessageFilter* renderer_msg_filter, |
| 288 const std::string& mime_type, |
| 289 const FilePath& plugin_path, |
| 247 IPC::Message* reply_msg) { | 290 IPC::Message* reply_msg) { |
| 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 249 | 292 |
| 250 bool allow_wildcard = true; | |
| 251 WebPluginInfo info; | |
| 252 FilePath plugin_path; | |
| 253 if (NPAPI::PluginList::Singleton()->GetPluginInfo( | |
| 254 url, mime_type, allow_wildcard, &info, NULL) && info.enabled) { | |
| 255 plugin_path = info.path; | |
| 256 } | |
| 257 | |
| 258 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); | 293 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); |
| 259 if (plugin_host) { | 294 if (plugin_host) { |
| 260 plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); | 295 plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); |
| 261 } else { | 296 } else { |
| 262 PluginProcessHost::ReplyToRenderer( | 297 PluginProcessHost::ReplyToRenderer( |
| 263 renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg); | 298 renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg); |
| 264 } | 299 } |
| 265 } | 300 } |
| 266 | 301 |
| 302 bool PluginService::GetFirstAllowedPluginInfo( |
| 303 const GURL& url, |
| 304 const std::string& mime_type, |
| 305 WebPluginInfo* info, |
| 306 std::string* actual_mime_type) { |
| 307 // GetPluginInfoArray may need to load the plugins, so we need to be |
| 308 // on the FILE thread. |
| 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 310 bool allow_wildcard = true; |
| 311 #if defined(OS_CHROMEOS) |
| 312 std::vector<WebPluginInfo> info_array; |
| 313 std::vector<std::string> actual_mime_types; |
| 314 NPAPI::PluginList::Singleton()->GetPluginInfoArray( |
| 315 url, mime_type, allow_wildcard, &info_array, &actual_mime_types); |
| 316 |
| 317 // Now we filter by the plugin selection policy. |
| 318 int allowed_index = plugin_selection_policy_->FindFirstAllowed(url, |
| 319 info_array); |
| 320 if (!info_array.empty() && allowed_index >= 0) { |
| 321 *info = info_array[allowed_index]; |
| 322 if (actual_mime_type) |
| 323 *actual_mime_type = actual_mime_types[allowed_index]; |
| 324 return true; |
| 325 } |
| 326 return false; |
| 327 #else |
| 328 return NPAPI::PluginList::Singleton()->GetPluginInfo( |
| 329 url, mime_type, allow_wildcard, info, actual_mime_type); |
| 330 #endif |
| 331 } |
| 332 |
| 267 static void PurgePluginListCache(bool reload_pages) { | 333 static void PurgePluginListCache(bool reload_pages) { |
| 268 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 334 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 269 !it.IsAtEnd(); it.Advance()) { | 335 !it.IsAtEnd(); it.Advance()) { |
| 270 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); | 336 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 271 } | 337 } |
| 272 } | 338 } |
| 273 | 339 |
| 274 void PluginService::OnWaitableEventSignaled( | 340 void PluginService::OnWaitableEventSignaled( |
| 275 base::WaitableEvent* waitable_event) { | 341 base::WaitableEvent* waitable_event) { |
| 276 #if defined(OS_WIN) | 342 #if defined(OS_WIN) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); | 445 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); |
| 380 | 446 |
| 381 // These NPAPI entry points will never be called. TODO(darin): Come up | 447 // These NPAPI entry points will never be called. TODO(darin): Come up |
| 382 // with a cleaner way to register pepper plugins with the NPAPI PluginList, | 448 // with a cleaner way to register pepper plugins with the NPAPI PluginList, |
| 383 // or perhaps refactor the PluginList to be less specific to NPAPI. | 449 // or perhaps refactor the PluginList to be less specific to NPAPI. |
| 384 memset(&info.entry_points, 0, sizeof(info.entry_points)); | 450 memset(&info.entry_points, 0, sizeof(info.entry_points)); |
| 385 | 451 |
| 386 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); | 452 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 387 } | 453 } |
| 388 } | 454 } |
| OLD | NEW |