Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: chrome/nacl/nacl_listener.cc

Issue 10214007: Add an IPC channel between the NaCl loader process and the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/nacl/nacl_listener.h" 5 #include "chrome/nacl/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "chrome/common/nacl_messages.h" 15 #include "chrome/common/nacl_messages.h"
16 #include "chrome/nacl/nacl_ipc_adapter.h"
16 #include "chrome/nacl/nacl_validation_db.h" 17 #include "chrome/nacl/nacl_validation_db.h"
17 #include "chrome/nacl/nacl_validation_query.h" 18 #include "chrome/nacl/nacl_validation_query.h"
19 #include "ipc/ipc_channel_handle.h"
20 #include "ipc/ipc_switches.h"
18 #include "ipc/ipc_sync_channel.h" 21 #include "ipc/ipc_sync_channel.h"
19 #include "ipc/ipc_sync_message_filter.h" 22 #include "ipc/ipc_sync_message_filter.h"
20 #include "ipc/ipc_switches.h"
21 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" 23 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h"
22 24
25 #if defined(OS_POSIX)
26 #include "base/file_descriptor_posix.h"
27 #endif
28
23 #if defined(OS_LINUX) 29 #if defined(OS_LINUX)
24 #include "content/public/common/child_process_sandbox_support_linux.h" 30 #include "content/public/common/child_process_sandbox_support_linux.h"
25 #endif 31 #endif
26 32
27 #if defined(OS_WIN) 33 #if defined(OS_WIN)
28 #include <fcntl.h> 34 #include <fcntl.h>
29 #include <io.h> 35 #include <io.h>
30 36
31 #include "content/public/common/sandbox_init.h" 37 #include "content/public/common/sandbox_init.h"
32 #endif 38 #endif
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return handled; 187 return handled;
182 } 188 }
183 189
184 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { 190 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) {
185 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); 191 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate();
186 if (args == NULL) { 192 if (args == NULL) {
187 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 193 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
188 return; 194 return;
189 } 195 }
190 196
197 if (params.enable_ipc_proxy) {
198 // Create the server side of the channel and notify the process host so it
199 // can reply to the renderer, which will connect as client.
200 IPC::ChannelHandle channel_handle =
201 IPC::Channel::GenerateVerifiedChannelID("nacl");
202
203 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter(
204 channel_handle, io_thread_.message_loop_proxy()));
205 args->initial_ipc_desc = ipc_adapter.get()->MakeNaClDesc();
206
207 #if defined(OS_POSIX)
208 channel_handle.socket = base::FileDescriptor(
209 ipc_adapter.get()->TakeClientFileDescriptor(), true);
210 #endif
211
212 if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(channel_handle)))
213 LOG(ERROR) << "Failed to send IPC channel handle to renderer.";
214 }
215
191 std::vector<nacl::FileDescriptor> handles = params.handles; 216 std::vector<nacl::FileDescriptor> handles = params.handles;
192 217
193 #if defined(OS_LINUX) || defined(OS_MACOSX) 218 #if defined(OS_LINUX) || defined(OS_MACOSX)
194 args->urandom_fd = dup(base::GetUrandomFD()); 219 args->urandom_fd = dup(base::GetUrandomFD());
195 if (args->urandom_fd < 0) { 220 if (args->urandom_fd < 0) {
196 LOG(ERROR) << "Failed to dup() the urandom FD"; 221 LOG(ERROR) << "Failed to dup() the urandom FD";
197 return; 222 return;
198 } 223 }
199 args->create_memory_object_func = CreateMemoryObject; 224 args->create_memory_object_func = CreateMemoryObject;
200 # if defined(OS_MACOSX) 225 # if defined(OS_MACOSX)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); 257 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]);
233 args->enable_exception_handling = params.enable_exception_handling; 258 args->enable_exception_handling = params.enable_exception_handling;
234 args->enable_debug_stub = params.enable_debug_stub; 259 args->enable_debug_stub = params.enable_debug_stub;
235 #if defined(OS_WIN) 260 #if defined(OS_WIN)
236 args->broker_duplicate_handle_func = BrokerDuplicateHandle; 261 args->broker_duplicate_handle_func = BrokerDuplicateHandle;
237 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; 262 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler;
238 #endif 263 #endif
239 NaClChromeMainStart(args); 264 NaClChromeMainStart(args);
240 NOTREACHED(); 265 NOTREACHED();
241 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698