OLD | NEW |
---|---|
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> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 #endif | 17 #endif |
18 | 18 |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
24 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
27 #include "components/nacl/common/nacl.mojom.h" | |
27 #include "components/nacl/common/nacl_messages.h" | 28 #include "components/nacl/common/nacl_messages.h" |
28 #include "components/nacl/common/nacl_renderer_messages.h" | |
29 #include "components/nacl/common/nacl_switches.h" | 29 #include "components/nacl/common/nacl_switches.h" |
30 #include "components/nacl/loader/nacl_ipc_adapter.h" | 30 #include "components/nacl/loader/nacl_ipc_adapter.h" |
31 #include "components/nacl/loader/nacl_validation_db.h" | 31 #include "components/nacl/loader/nacl_validation_db.h" |
32 #include "components/nacl/loader/nacl_validation_query.h" | 32 #include "components/nacl/loader/nacl_validation_query.h" |
33 #include "content/public/common/mojo_channel_switches.h" | 33 #include "content/public/common/mojo_channel_switches.h" |
34 #include "ipc/ipc_channel_handle.h" | 34 #include "ipc/ipc_channel_handle.h" |
35 #include "ipc/ipc_sync_channel.h" | 35 #include "ipc/ipc_sync_channel.h" |
36 #include "ipc/ipc_sync_message_filter.h" | 36 #include "ipc/ipc_sync_message_filter.h" |
37 #include "mojo/edk/embedder/embedder.h" | 37 #include "mojo/edk/embedder/embedder.h" |
38 #include "mojo/edk/embedder/scoped_ipc_support.h" | 38 #include "mojo/edk/embedder/scoped_ipc_support.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
69 // We copy the length of the crash data to the start of the shared memory | 69 // We copy the length of the crash data to the start of the shared memory |
70 // segment so we know how much to copy. | 70 // segment so we know how much to copy. |
71 memcpy(g_listener->crash_info_shmem_memory(), ©_bytes, sizeof(uint32_t)); | 71 memcpy(g_listener->crash_info_shmem_memory(), ©_bytes, sizeof(uint32_t)); |
72 | 72 |
73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), | 73 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), |
74 data, | 74 data, |
75 copy_bytes); | 75 copy_bytes); |
76 } | 76 } |
77 | 77 |
78 void LoadStatusCallback(int load_status) { | 78 void LoadStatusCallback(int load_status) { |
79 g_listener->trusted_listener()->Send( | 79 g_listener->trusted_listener()->renderer_host()->ReportLoadStatus( |
80 new NaClRendererMsg_ReportLoadStatus( | 80 static_cast<NaClErrorCode>(load_status)); |
81 static_cast<NaClErrorCode>(load_status))); | |
82 } | 81 } |
83 | 82 |
84 #if defined(OS_LINUX) | 83 #if defined(OS_LINUX) |
85 | 84 |
86 int CreateMemoryObject(size_t size, int executable) { | 85 int CreateMemoryObject(size_t size, int executable) { |
87 return content::MakeSharedMemorySegmentViaIPC(size, executable); | 86 return content::MakeSharedMemorySegmentViaIPC(size, executable); |
88 } | 87 } |
89 | 88 |
90 #elif defined(OS_WIN) | 89 #elif defined(OS_WIN) |
91 int AttachDebugExceptionHandler(const void* info, size_t info_size) { | 90 int AttachDebugExceptionHandler(const void* info, size_t info_size) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 NACL_CHROME_DESC_BASE + 1, | 342 NACL_CHROME_DESC_BASE + 1, |
344 NaClIPCAdapter::ResolveFileTokenCallback(), | 343 NaClIPCAdapter::ResolveFileTokenCallback(), |
345 NaClIPCAdapter::OpenResourceCallback()); | 344 NaClIPCAdapter::OpenResourceCallback()); |
346 SetUpIPCAdapter( | 345 SetUpIPCAdapter( |
347 &manifest_service_handle, io_thread_.task_runner(), nap, | 346 &manifest_service_handle, io_thread_.task_runner(), nap, |
348 NACL_CHROME_DESC_BASE + 2, | 347 NACL_CHROME_DESC_BASE + 2, |
349 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), | 348 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)), |
350 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); | 349 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this))); |
351 | 350 |
352 mojo::MessagePipe trusted_pipe; | 351 mojo::MessagePipe trusted_pipe; |
353 trusted_listener_ = | 352 trusted_listener_ = base::MakeUnique<NaClTrustedListener>( |
354 new NaClTrustedListener(trusted_pipe.handle0.release(), | 353 mojo::MakeProxy(nacl::mojom::NaClRendererHostPtrInfo( |
355 io_thread_.task_runner().get(), &shutdown_event_); | 354 std::move(trusted_pipe.handle0), |
355 nacl::mojom::NaClRendererHost::Version_)), | |
dcheng
2016/12/20 06:49:54
Nit: can we document what "version" means somewher
Sam McNally
2016/12/20 10:02:19
Yes, it's for mojom versioning. https://www.chromi
| |
356 io_thread_.task_runner().get()); | |
356 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 357 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
357 browser_handle, ppapi_renderer_handle, trusted_pipe.handle1.release(), | 358 browser_handle, ppapi_renderer_handle, trusted_pipe.handle1.release(), |
358 manifest_service_handle))) | 359 manifest_service_handle))) |
359 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; | 360 LOG(FATAL) << "Failed to send IPC channel handle to NaClProcessHost."; |
360 | 361 |
361 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 362 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
362 if (args == NULL) { | 363 if (args == NULL) { |
363 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; | 364 LOG(FATAL) << "NaClChromeMainArgsCreate() failed"; |
364 } | 365 } |
365 | 366 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 params.nexe_file); | 440 params.nexe_file); |
440 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); | 441 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); |
441 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, | 442 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, |
442 file_path_str.c_str()); | 443 file_path_str.c_str()); |
443 | 444 |
444 int exit_status; | 445 int exit_status; |
445 if (!NaClChromeMainStart(nap, args, &exit_status)) | 446 if (!NaClChromeMainStart(nap, args, &exit_status)) |
446 NaClExit(1); | 447 NaClExit(1); |
447 | 448 |
448 // Report the plugin's exit status if the application started successfully. | 449 // Report the plugin's exit status if the application started successfully. |
449 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); | 450 trusted_listener_->renderer_host()->ReportExitStatus(exit_status); |
450 NaClExit(exit_status); | 451 NaClExit(exit_status); |
451 } | 452 } |
452 | 453 |
453 void NaClListener::ResolveFileToken( | 454 void NaClListener::ResolveFileToken( |
454 uint64_t token_lo, | 455 uint64_t token_lo, |
455 uint64_t token_hi, | 456 uint64_t token_hi, |
456 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { | 457 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { |
457 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { | 458 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { |
458 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); | 459 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); |
459 return; | 460 return; |
460 } | 461 } |
461 resolved_cb_ = cb; | 462 resolved_cb_ = cb; |
462 } | 463 } |
463 | 464 |
464 void NaClListener::OnFileTokenResolved( | 465 void NaClListener::OnFileTokenResolved( |
465 uint64_t token_lo, | 466 uint64_t token_lo, |
466 uint64_t token_hi, | 467 uint64_t token_hi, |
467 IPC::PlatformFileForTransit ipc_fd, | 468 IPC::PlatformFileForTransit ipc_fd, |
468 base::FilePath file_path) { | 469 base::FilePath file_path) { |
469 resolved_cb_.Run(ipc_fd, file_path); | 470 resolved_cb_.Run(ipc_fd, file_path); |
470 resolved_cb_.Reset(); | 471 resolved_cb_.Reset(); |
471 } | 472 } |
OLD | NEW |