OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/plugin_loader_posix.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" |
| 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/common/utility_messages.h" |
| 11 #include "webkit/plugins/npapi/plugin_list.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 void RunGetPluginsCallback(const PluginService::GetPluginsCallback& callback, |
| 16 const std::vector<webkit::WebPluginInfo> plugins) { |
| 17 callback.Run(plugins); |
| 18 } |
| 19 |
| 20 } // namespace |
| 21 |
| 22 // static |
| 23 void PluginLoaderPosix::LoadPlugins( |
| 24 base::MessageLoopProxy* target_loop, |
| 25 const PluginService::GetPluginsCallback& callback) { |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 27 |
| 28 PluginLoaderPosix* client = new PluginLoaderPosix(target_loop, callback); |
| 29 UtilityProcessHost* process_host = |
| 30 new UtilityProcessHost(client, BrowserThread::IO); |
| 31 process_host->set_no_sandbox(true); |
| 32 #if defined(OS_MACOSX) |
| 33 process_host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); |
| 34 #endif |
| 35 |
| 36 std::vector<FilePath> extra_plugin_paths; |
| 37 std::vector<FilePath> extra_plugin_dirs; |
| 38 std::vector<webkit::WebPluginInfo> internal_plugins; |
| 39 webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad( |
| 40 &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins); |
| 41 |
| 42 process_host->Send(new UtilityMsg_LoadPlugins( |
| 43 extra_plugin_paths, extra_plugin_dirs, internal_plugins)); |
| 44 } |
| 45 |
| 46 bool PluginLoaderPosix::OnMessageReceived(const IPC::Message& message) { |
| 47 bool handled = true; |
| 48 IPC_BEGIN_MESSAGE_MAP(PluginLoaderPosix, message) |
| 49 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins) |
| 50 IPC_MESSAGE_UNHANDLED(handled = false) |
| 51 IPC_END_MESSAGE_MAP() |
| 52 return handled; |
| 53 } |
| 54 |
| 55 void PluginLoaderPosix::OnProcessCrashed(int exit_code) { |
| 56 LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code |
| 57 << ". You will have no plugins!"; |
| 58 // Don't leave callers hanging. |
| 59 OnGotPlugins(std::vector<webkit::WebPluginInfo>()); |
| 60 } |
| 61 |
| 62 PluginLoaderPosix::PluginLoaderPosix( |
| 63 base::MessageLoopProxy* target_loop, |
| 64 const PluginService::GetPluginsCallback& callback) |
| 65 : target_loop_(target_loop), |
| 66 callback_(callback) { |
| 67 } |
| 68 |
| 69 PluginLoaderPosix::~PluginLoaderPosix() { |
| 70 } |
| 71 |
| 72 void PluginLoaderPosix::OnGotPlugins( |
| 73 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 74 webkit::npapi::PluginList::Singleton()->SetPlugins(plugins); |
| 75 target_loop_->PostTask(FROM_HERE, |
| 76 base::Bind(&RunGetPluginsCallback, callback_, plugins)); |
| 77 } |
OLD | NEW |