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

Side by Side Diff: components/nacl/loader/nacl_listener.cc

Issue 2301103003: Use ChannelMojo for NaCl PPAPI channels. (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" 5 #include "components/nacl/loader/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 25 matching lines...) Expand all
36 #include "ipc/ipc_switches.h" 36 #include "ipc/ipc_switches.h"
37 #include "ipc/ipc_sync_channel.h" 37 #include "ipc/ipc_sync_channel.h"
38 #include "ipc/ipc_sync_message_filter.h" 38 #include "ipc/ipc_sync_message_filter.h"
39 #include "mojo/edk/embedder/embedder.h" 39 #include "mojo/edk/embedder/embedder.h"
40 #include "mojo/edk/embedder/scoped_ipc_support.h" 40 #include "mojo/edk/embedder/scoped_ipc_support.h"
41 #include "native_client/src/public/chrome_main.h" 41 #include "native_client/src/public/chrome_main.h"
42 #include "native_client/src/public/nacl_app.h" 42 #include "native_client/src/public/nacl_app.h"
43 #include "native_client/src/public/nacl_desc.h" 43 #include "native_client/src/public/nacl_desc.h"
44 44
45 #if defined(OS_POSIX) 45 #if defined(OS_POSIX)
46 #include "base/file_descriptor_posix.h"
47 #include "base/posix/global_descriptors.h" 46 #include "base/posix/global_descriptors.h"
48 #include "content/public/common/content_descriptors.h" 47 #include "content/public/common/content_descriptors.h"
49 #endif 48 #endif
50 49
51 #if defined(OS_LINUX) 50 #if defined(OS_LINUX)
52 #include "content/public/common/child_process_sandbox_support_linux.h" 51 #include "content/public/common/child_process_sandbox_support_linux.h"
53 #endif 52 #endif
54 53
55 #if defined(OS_WIN) 54 #if defined(OS_WIN)
56 #include <io.h> 55 #include <io.h>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // the given task runner runs. 110 // the given task runner runs.
112 // Also, creates and sets the corresponding NaClDesc to the given nap with 111 // Also, creates and sets the corresponding NaClDesc to the given nap with
113 // the FD #. 112 // the FD #.
114 void SetUpIPCAdapter( 113 void SetUpIPCAdapter(
115 IPC::ChannelHandle* handle, 114 IPC::ChannelHandle* handle,
116 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 115 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
117 struct NaClApp* nap, 116 struct NaClApp* nap,
118 int nacl_fd, 117 int nacl_fd,
119 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb, 118 NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb,
120 NaClIPCAdapter::OpenResourceCallback open_resource_cb) { 119 NaClIPCAdapter::OpenResourceCallback open_resource_cb) {
120 IPC::ChannelHandle client_handle;
121 IPC::Channel::GenerateMojoChannelHandlePair("nacl", handle, &client_handle);
121 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter( 122 scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter(
122 *handle, task_runner.get(), resolve_file_token_cb, open_resource_cb)); 123 client_handle, task_runner, resolve_file_token_cb, open_resource_cb));
123 ipc_adapter->ConnectChannel(); 124 ipc_adapter->ConnectChannel();
124 #if defined(OS_POSIX)
125 handle->socket =
126 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor());
127 #endif
128 125
129 // Pass a NaClDesc to the untrusted side. This will hold a ref to the 126 // Pass a NaClDesc to the untrusted side. This will hold a ref to the
130 // NaClIPCAdapter. 127 // NaClIPCAdapter.
131 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); 128 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc());
132 } 129 }
133 130
134 } // namespace 131 } // namespace
135 132
136 class BrowserValidationDBProxy : public NaClValidationDB { 133 class BrowserValidationDBProxy : public NaClValidationDB {
137 public: 134 public:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 crash_info_shmem_.reset(new base::SharedMemory( 327 crash_info_shmem_.reset(new base::SharedMemory(
331 params.crash_info_shmem_handle, false /* not readonly */)); 328 params.crash_info_shmem_handle, false /* not readonly */));
332 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 329 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
333 NaClSetFatalErrorCallback(&FatalLogHandler); 330 NaClSetFatalErrorCallback(&FatalLogHandler);
334 331
335 nap = NaClAppCreate(); 332 nap = NaClAppCreate();
336 if (nap == NULL) { 333 if (nap == NULL) {
337 LOG(FATAL) << "NaClAppCreate() failed"; 334 LOG(FATAL) << "NaClAppCreate() failed";
338 } 335 }
339 336
340 IPC::ChannelHandle browser_handle = 337 IPC::ChannelHandle browser_handle;
341 IPC::Channel::GenerateVerifiedChannelID("nacl"); 338 IPC::ChannelHandle ppapi_renderer_handle;
342 IPC::ChannelHandle ppapi_renderer_handle = 339 IPC::ChannelHandle manifest_service_handle;
343 IPC::Channel::GenerateVerifiedChannelID("nacl");
344 IPC::ChannelHandle manifest_service_handle =
345 IPC::Channel::GenerateVerifiedChannelID("nacl");
346 340
347 // Create the PPAPI IPC channels between the NaCl IRT and the host 341 // Create the PPAPI IPC channels between the NaCl IRT and the host
348 // (browser/renderer) processes. The IRT uses these channels to 342 // (browser/renderer) processes. The IRT uses these channels to
349 // communicate with the host and to initialize the IPC dispatchers. 343 // communicate with the host and to initialize the IPC dispatchers.
350 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap, 344 SetUpIPCAdapter(&browser_handle, io_thread_.task_runner(), nap,
351 NACL_CHROME_DESC_BASE, 345 NACL_CHROME_DESC_BASE,
352 NaClIPCAdapter::ResolveFileTokenCallback(), 346 NaClIPCAdapter::ResolveFileTokenCallback(),
353 NaClIPCAdapter::OpenResourceCallback()); 347 NaClIPCAdapter::OpenResourceCallback());
354 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap, 348 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.task_runner(), nap,
355 NACL_CHROME_DESC_BASE + 1, 349 NACL_CHROME_DESC_BASE + 1,
356 NaClIPCAdapter::ResolveFileTokenCallback(), 350 NaClIPCAdapter::ResolveFileTokenCallback(),
357 NaClIPCAdapter::OpenResourceCallback()); 351 NaClIPCAdapter::OpenResourceCallback());
358 SetUpIPCAdapter( 352 SetUpIPCAdapter(
359 &manifest_service_handle, io_thread_.task_runner(), nap, 353 &manifest_service_handle, io_thread_.task_runner(), nap,
360 NACL_CHROME_DESC_BASE + 2, 354 NACL_CHROME_DESC_BASE + 2,
361 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), 355 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)),
362 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); 356 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
363 357
364 trusted_listener_ = 358 IPC::ChannelHandle trusted_client;
365 new NaClTrustedListener(IPC::Channel::GenerateVerifiedChannelID("nacl"), 359 IPC::ChannelHandle trusted_server;
366 io_thread_.task_runner().get(), &shutdown_event_); 360 IPC::Channel::GenerateMojoChannelHandlePair("NaCl-trusted-listener",
361 &trusted_client, &trusted_server);
362 trusted_listener_ = new NaClTrustedListener(
363 trusted_server, io_thread_.task_runner().get(), &shutdown_event_);
367 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 364 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
368 browser_handle, 365 browser_handle, ppapi_renderer_handle, trusted_client,
369 ppapi_renderer_handle,
370 trusted_listener_->TakeClientChannelHandle(),
371 manifest_service_handle))) 366 manifest_service_handle)))
372 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; 367 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost.";
373 368
374 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); 369 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate();
375 if (args == NULL) { 370 if (args == NULL) {
376 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; 371 LOG(FATAL) << "NaClChromeMainArgsCreate() failed";
377 } 372 }
378 373
379 #if defined(OS_POSIX) 374 #if defined(OS_POSIX)
380 args->number_of_cores = number_of_cores_; 375 args->number_of_cores = number_of_cores_;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 470 }
476 471
477 void NaClListener::OnFileTokenResolved( 472 void NaClListener::OnFileTokenResolved(
478 uint64_t token_lo, 473 uint64_t token_lo,
479 uint64_t token_hi, 474 uint64_t token_hi,
480 IPC::PlatformFileForTransit ipc_fd, 475 IPC::PlatformFileForTransit ipc_fd,
481 base::FilePath file_path) { 476 base::FilePath file_path) {
482 resolved_cb_.Run(ipc_fd, file_path); 477 resolved_cb_.Run(ipc_fd, file_path);
483 resolved_cb_.Reset(); 478 resolved_cb_.Reset();
484 } 479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698