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

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_validation_db.h" 15 #include "chrome/nacl/nacl_validation_db.h"
16 #include "chrome/nacl/nacl_validation_query.h" 16 #include "chrome/nacl/nacl_validation_query.h"
17 #include "ipc/ipc_channel_handle.h"
18 #include "ipc/ipc_switches.h"
17 #include "ipc/ipc_sync_channel.h" 19 #include "ipc/ipc_sync_channel.h"
18 #include "ipc/ipc_sync_message_filter.h" 20 #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" 21 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h"
21 22
22 #if defined(OS_LINUX) 23 #if defined(OS_LINUX)
23 #include "content/public/common/child_process_sandbox_support_linux.h" 24 #include "content/public/common/child_process_sandbox_support_linux.h"
24 #endif 25 #endif
25 26
26 #if defined(OS_WIN) 27 #if defined(OS_WIN)
27 #include <fcntl.h> 28 #include <fcntl.h>
28 #include <io.h> 29 #include <io.h>
29 30
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 167
167 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 168 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
168 bool handled = true; 169 bool handled = true;
169 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 170 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
170 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnMsgStart) 171 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnMsgStart)
171 IPC_MESSAGE_UNHANDLED(handled = false) 172 IPC_MESSAGE_UNHANDLED(handled = false)
172 IPC_END_MESSAGE_MAP() 173 IPC_END_MESSAGE_MAP()
173 return handled; 174 return handled;
174 } 175 }
175 176
177 class MyListener : public IPC::Channel::Listener
178 {
179 virtual bool OnMessageReceived(const IPC::Message& message) {
180 return true;
181 }
182
183 virtual void OnChannelConnected(int32 peer_pid) {
184 }
185
186 virtual void OnChannelError() {
187 }
188 };
189
190 class MyFilter : public IPC::ChannelProxy::MessageFilter
191 {
192 virtual bool OnMessageReceived(const IPC::Message& message) {
193 return true;
194 }
195 };
196
197 static MyListener test_listener;
dmichael (off chromium) 2012/05/04 22:51:42 Does it make sense for this to be a file-scope sta
bbudge 2012/05/07 18:08:53 This is just experimental hacking to verify that t
198
176 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { 199 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) {
177 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); 200 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate();
178 if (args == NULL) { 201 if (args == NULL) {
179 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 202 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
180 return; 203 return;
181 } 204 }
182 205
206 // Create the server side of the channel and notify the process host so it
207 // can reply to the renderer, which will then try to connect as client.
208 IPC::ChannelHandle channel_handle =
209 IPC::Channel::GenerateVerifiedChannelID("nacl");
210 ppapi_channel_.reset(
211 new IPC::SyncChannel(&test_listener, io_thread_.message_loop_proxy(),
212 &shutdown_event_));
213 ppapi_channel_->AddFilter(new MyFilter);
214 ppapi_channel_->Init(channel_handle, IPC::Channel::MODE_SERVER, true);
215
216 Send(new NaClProcessHostMsg_PpapiChannelCreated(channel_handle));
217
183 std::vector<nacl::FileDescriptor> handles = params.handles; 218 std::vector<nacl::FileDescriptor> handles = params.handles;
184 219
185 #if defined(OS_LINUX) || defined(OS_MACOSX) 220 #if defined(OS_LINUX) || defined(OS_MACOSX)
186 args->create_memory_object_func = CreateMemoryObject; 221 args->create_memory_object_func = CreateMemoryObject;
187 # if defined(OS_MACOSX) 222 # if defined(OS_MACOSX)
188 CHECK(handles.size() >= 1); 223 CHECK(handles.size() >= 1);
189 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); 224 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]);
190 handles.pop_back(); 225 handles.pop_back();
191 # endif 226 # endif
192 #endif 227 #endif
(...skipping 24 matching lines...) Expand all
217 CHECK(handles.size() == 1); 252 CHECK(handles.size() == 1);
218 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); 253 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]);
219 args->enable_exception_handling = params.enable_exception_handling; 254 args->enable_exception_handling = params.enable_exception_handling;
220 args->enable_debug_stub = debug_enabled_; 255 args->enable_debug_stub = debug_enabled_;
221 #if defined(OS_WIN) 256 #if defined(OS_WIN)
222 args->broker_duplicate_handle_func = BrokerDuplicateHandle; 257 args->broker_duplicate_handle_func = BrokerDuplicateHandle;
223 #endif 258 #endif
224 NaClChromeMainStart(args); 259 NaClChromeMainStart(args);
225 NOTREACHED(); 260 NOTREACHED();
226 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698