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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 library_.Reset(library.Release()); | 93 library_.Reset(library.Release()); |
94 dispatcher_.reset(new pp::proxy::PluginDispatcher( | 94 dispatcher_.reset(new pp::proxy::PluginDispatcher( |
95 host_process_handle, get_interface, init_module, shutdown_module)); | 95 host_process_handle, get_interface, init_module, shutdown_module)); |
96 pp::proxy::PluginDispatcher::SetGlobal(dispatcher_.get()); | 96 pp::proxy::PluginDispatcher::SetGlobal(dispatcher_.get()); |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 bool PpapiThread::SetupRendererChannel(int renderer_id, | 100 bool PpapiThread::SetupRendererChannel(int renderer_id, |
101 IPC::ChannelHandle* handle) { | 101 IPC::ChannelHandle* handle) { |
102 std::string channel_key = StringPrintf( | 102 IPC::ChannelHandle plugin_handle; |
103 "%d.r%d", base::GetCurrentProcId(), renderer_id); | 103 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(), |
104 | 104 renderer_id); |
105 #if defined(OS_POSIX) | |
106 // This gets called when the PluginChannel is initially created. At this | |
107 // point, create the socketpair and assign the plugin side FD to the channel | |
108 // name. Keep the renderer side FD as a member variable in the PluginChannel | |
109 // to be able to transmit it through IPC. | |
110 int plugin_fd; | |
111 if (!IPC::SocketPair(&plugin_fd, &renderer_fd_)) | |
112 return false; | |
113 IPC::AddChannelSocket(channel_key, plugin_fd); | |
114 #endif | |
115 | |
116 if (!dispatcher_->InitWithChannel( | 105 if (!dispatcher_->InitWithChannel( |
117 ChildProcess::current()->io_message_loop(), | 106 ChildProcess::current()->io_message_loop(), |
118 channel_key, false, | 107 plugin_handle, false, |
119 ChildProcess::current()->GetShutDownEvent())) | 108 ChildProcess::current()->GetShutDownEvent())) |
120 return false; | 109 return false; |
121 | 110 |
122 handle->name = channel_key; | 111 handle->name = plugin_handle.name; |
123 #if defined(OS_POSIX) | 112 #if defined(OS_POSIX) |
124 // On POSIX, pass the renderer-side FD. | 113 // On POSIX, pass the renderer-side FD. |
| 114 renderer_fd_ = dispatcher_->channel()->GetClientFileDescriptor(); |
125 handle->socket = base::FileDescriptor(renderer_fd_, false); | 115 handle->socket = base::FileDescriptor(renderer_fd_, false); |
126 #endif | 116 #endif |
127 return true; | 117 return true; |
128 } | 118 } |
129 | 119 |
130 #if defined(OS_POSIX) | 120 #if defined(OS_POSIX) |
131 void PpapiThread::CloseRendererFD() { | 121 void PpapiThread::CloseRendererFD() { |
132 if (renderer_fd_ != -1) { | 122 if (renderer_fd_ != -1) { |
133 if (HANDLE_EINTR(close(renderer_fd_)) < 0) | 123 if (HANDLE_EINTR(close(renderer_fd_)) < 0) |
134 PLOG(ERROR) << "close"; | 124 PLOG(ERROR) << "close"; |
135 renderer_fd_ = -1; | 125 renderer_fd_ = -1; |
136 } | 126 } |
137 } | 127 } |
138 #endif | 128 #endif |
OLD | NEW |