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 "chrome/ppapi_plugin/ppapi_thread.h" | 5 #include "chrome/ppapi_plugin/ppapi_thread.h" |
6 | 6 |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "chrome/common/child_process.h" | 8 #include "chrome/common/child_process.h" |
9 #include "ipc/ipc_channel_handle.h" | 9 #include "ipc/ipc_channel_handle.h" |
10 #include "ipc/ipc_sync_channel.h" | 10 #include "ipc/ipc_sync_channel.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnLoadPlugin) | 40 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnLoadPlugin) |
41 | 41 |
42 // The rest of the messages go to the dispatcher. | 42 // The rest of the messages go to the dispatcher. |
43 /*IPC_MESSAGE_UNHANDLED( | 43 /*IPC_MESSAGE_UNHANDLED( |
44 if (dispatcher_.get()) | 44 if (dispatcher_.get()) |
45 dispatcher_->OnMessageReceived(msg) | 45 dispatcher_->OnMessageReceived(msg) |
46 )*/ | 46 )*/ |
47 IPC_END_MESSAGE_MAP() | 47 IPC_END_MESSAGE_MAP() |
48 } | 48 } |
49 | 49 |
50 void PpapiThread::OnLoadPlugin(const FilePath& path, int renderer_id) { | 50 void PpapiThread::OnLoadPlugin(base::ProcessHandle host_process_handle, |
| 51 const FilePath& path, |
| 52 int renderer_id) { |
51 IPC::ChannelHandle channel_handle; | 53 IPC::ChannelHandle channel_handle; |
52 if (!LoadPluginLib(path) || | 54 if (!LoadPluginLib(host_process_handle, path) || |
53 !SetupRendererChannel(renderer_id, &channel_handle)) { | 55 !SetupRendererChannel(renderer_id, &channel_handle)) { |
54 // An empty channel handle indicates error. | 56 // An empty channel handle indicates error. |
55 Send(new PpapiHostMsg_PluginLoaded(IPC::ChannelHandle())); | 57 Send(new PpapiHostMsg_PluginLoaded(IPC::ChannelHandle())); |
56 return; | 58 return; |
57 } | 59 } |
58 | 60 |
59 Send(new PpapiHostMsg_PluginLoaded(channel_handle)); | 61 Send(new PpapiHostMsg_PluginLoaded(channel_handle)); |
60 } | 62 } |
61 | 63 |
62 bool PpapiThread::LoadPluginLib(const FilePath& path) { | 64 bool PpapiThread::LoadPluginLib(base::ProcessHandle host_process_handle, |
| 65 const FilePath& path) { |
63 base::ScopedNativeLibrary library(base::LoadNativeLibrary(path)); | 66 base::ScopedNativeLibrary library(base::LoadNativeLibrary(path)); |
64 if (!library.is_valid()) | 67 if (!library.is_valid()) |
65 return false; | 68 return false; |
66 | 69 |
67 // Get the GetInterface function (required). | 70 // Get the GetInterface function (required). |
68 pp::proxy::Dispatcher::GetInterfaceFunc get_interface = | 71 pp::proxy::Dispatcher::GetInterfaceFunc get_interface = |
69 reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>( | 72 reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>( |
70 library.GetFunctionPointer("PPP_GetInterface")); | 73 library.GetFunctionPointer("PPP_GetInterface")); |
71 if (!get_interface) { | 74 if (!get_interface) { |
72 LOG(WARNING) << "No PPP_GetInterface in plugin library"; | 75 LOG(WARNING) << "No PPP_GetInterface in plugin library"; |
73 return false; | 76 return false; |
74 } | 77 } |
75 | 78 |
76 // Get the InitializeModule function (required). | 79 // Get the InitializeModule function (required). |
77 pp::proxy::Dispatcher::InitModuleFunc init_module = | 80 pp::proxy::Dispatcher::InitModuleFunc init_module = |
78 reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>( | 81 reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>( |
79 library.GetFunctionPointer("PPP_InitializeModule")); | 82 library.GetFunctionPointer("PPP_InitializeModule")); |
80 if (!init_module) { | 83 if (!init_module) { |
81 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; | 84 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; |
82 return false; | 85 return false; |
83 } | 86 } |
84 | 87 |
85 // Get the ShutdownModule function (optional). | 88 // Get the ShutdownModule function (optional). |
86 pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module = | 89 pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module = |
87 reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( | 90 reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( |
88 library.GetFunctionPointer("PPP_ShutdownModule")); | 91 library.GetFunctionPointer("PPP_ShutdownModule")); |
89 | 92 |
90 library_.Reset(library.Release()); | 93 library_.Reset(library.Release()); |
91 dispatcher_.reset(new pp::proxy::PluginDispatcher(get_interface, init_module, | 94 dispatcher_.reset(new pp::proxy::PluginDispatcher( |
92 shutdown_module)); | 95 host_process_handle, get_interface, init_module, shutdown_module)); |
93 pp::proxy::PluginDispatcher::SetGlobal(dispatcher_.get()); | 96 pp::proxy::PluginDispatcher::SetGlobal(dispatcher_.get()); |
94 return true; | 97 return true; |
95 } | 98 } |
96 | 99 |
97 bool PpapiThread::SetupRendererChannel(int renderer_id, | 100 bool PpapiThread::SetupRendererChannel(int renderer_id, |
98 IPC::ChannelHandle* handle) { | 101 IPC::ChannelHandle* handle) { |
99 std::string channel_key = StringPrintf( | 102 std::string channel_key = StringPrintf( |
100 "%d.r%d", base::GetCurrentProcId(), renderer_id); | 103 "%d.r%d", base::GetCurrentProcId(), renderer_id); |
101 | 104 |
102 #if defined(OS_POSIX) | 105 #if defined(OS_POSIX) |
(...skipping 23 matching lines...) Expand all Loading... |
126 | 129 |
127 #if defined(OS_POSIX) | 130 #if defined(OS_POSIX) |
128 void PpapiThread::CloseRendererFD() { | 131 void PpapiThread::CloseRendererFD() { |
129 if (renderer_fd_ != -1) { | 132 if (renderer_fd_ != -1) { |
130 if (HANDLE_EINTR(close(renderer_fd_)) < 0) | 133 if (HANDLE_EINTR(close(renderer_fd_)) < 0) |
131 PLOG(ERROR) << "close"; | 134 PLOG(ERROR) << "close"; |
132 renderer_fd_ = -1; | 135 renderer_fd_ = -1; |
133 } | 136 } |
134 } | 137 } |
135 #endif | 138 #endif |
OLD | NEW |