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

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, 7 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 "chrome/common/nacl_messages.h" 14 #include "chrome/common/nacl_messages.h"
15 #include "chrome/nacl/nacl_ipc_adapter.h"
15 #include "chrome/nacl/nacl_validation_db.h" 16 #include "chrome/nacl/nacl_validation_db.h"
16 #include "chrome/nacl/nacl_validation_query.h" 17 #include "chrome/nacl/nacl_validation_query.h"
18 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_switches.h"
17 #include "ipc/ipc_sync_channel.h" 20 #include "ipc/ipc_sync_channel.h"
18 #include "ipc/ipc_sync_message_filter.h" 21 #include "ipc/ipc_sync_message_filter.h"
19 #include "ipc/ipc_switches.h"
20 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" 22 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h"
21 23
22 #if defined(OS_LINUX) 24 #if defined(OS_LINUX)
23 #include "content/public/common/child_process_sandbox_support_linux.h" 25 #include "content/public/common/child_process_sandbox_support_linux.h"
24 #endif 26 #endif
25 27
28 #if defined(OS_POSIX)
29 #include "base/file_descriptor_posix.h"
30 #endif
31
26 #if defined(OS_WIN) 32 #if defined(OS_WIN)
27 #include <fcntl.h> 33 #include <fcntl.h>
28 #include <io.h> 34 #include <io.h>
29 35
30 #include "content/public/common/sandbox_init.h" 36 #include "content/public/common/sandbox_init.h"
31 #endif 37 #endif
32 38
33 namespace { 39 namespace {
34 #if defined(OS_MACOSX) 40 #if defined(OS_MACOSX)
35 41
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 141
136 private: 142 private:
137 // The listener never dies, otherwise this might be a dangling reference. 143 // The listener never dies, otherwise this might be a dangling reference.
138 NaClListener* listener_; 144 NaClListener* listener_;
139 }; 145 };
140 146
141 147
142 NaClListener::NaClListener() : shutdown_event_(true, false), 148 NaClListener::NaClListener() : shutdown_event_(true, false),
143 io_thread_("NaCl_IOThread"), 149 io_thread_("NaCl_IOThread"),
144 main_loop_(NULL), 150 main_loop_(NULL),
151 nacl_ppapi_channel_(NULL),
145 debug_enabled_(false) { 152 debug_enabled_(false) {
146 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); 153 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0));
147 #if defined(OS_WIN) 154 #if defined(OS_WIN)
148 DCHECK(g_listener == NULL); 155 DCHECK(g_listener == NULL);
149 g_listener = this; 156 g_listener = this;
150 #endif 157 #endif
151 } 158 }
152 159
153 NaClListener::~NaClListener() { 160 NaClListener::~NaClListener() {
154 NOTREACHED(); 161 NOTREACHED();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return handled; 198 return handled;
192 } 199 }
193 200
194 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { 201 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) {
195 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); 202 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate();
196 if (args == NULL) { 203 if (args == NULL) {
197 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 204 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
198 return; 205 return;
199 } 206 }
200 207
208 if (params.enable_ipc_proxy) {
209 // Create the server side of the channel and notify the process host so it
210 // can reply to the renderer, which will then try to connect as client.
211 IPC::ChannelHandle channel_handle =
212 IPC::Channel::GenerateVerifiedChannelID("nacl");
213
214 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter(
215 channel_handle, io_thread_.message_loop_proxy()));
216 nacl_ppapi_channel_ = ipc_adapter.get()->MakeNaClDesc();
217
218 #if defined (OS_POSIX)
219 channel_handle.socket = base::FileDescriptor(
220 ipc_adapter.get()->TakeClientFileDescriptor(), true);
221 #endif
222
223 Send(new NaClProcessHostMsg_PpapiChannelCreated(channel_handle));
224 }
225
201 std::vector<nacl::FileDescriptor> handles = params.handles; 226 std::vector<nacl::FileDescriptor> handles = params.handles;
202 227
203 #if defined(OS_LINUX) || defined(OS_MACOSX) 228 #if defined(OS_LINUX) || defined(OS_MACOSX)
204 args->create_memory_object_func = CreateMemoryObject; 229 args->create_memory_object_func = CreateMemoryObject;
205 # if defined(OS_MACOSX) 230 # if defined(OS_MACOSX)
206 CHECK(handles.size() >= 1); 231 CHECK(handles.size() >= 1);
207 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); 232 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]);
208 handles.pop_back(); 233 handles.pop_back();
209 # endif 234 # endif
210 #endif 235 #endif
(...skipping 25 matching lines...) Expand all
236 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); 261 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]);
237 args->enable_exception_handling = params.enable_exception_handling; 262 args->enable_exception_handling = params.enable_exception_handling;
238 args->enable_debug_stub = debug_enabled_; 263 args->enable_debug_stub = debug_enabled_;
239 #if defined(OS_WIN) 264 #if defined(OS_WIN)
240 args->broker_duplicate_handle_func = BrokerDuplicateHandle; 265 args->broker_duplicate_handle_func = BrokerDuplicateHandle;
241 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; 266 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler;
242 #endif 267 #endif
243 NaClChromeMainStart(args); 268 NaClChromeMainStart(args);
244 NOTREACHED(); 269 NOTREACHED();
245 } 270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698