Index: components/nacl/loader/nacl_trusted_listener.cc |
diff --git a/components/nacl/loader/nacl_trusted_listener.cc b/components/nacl/loader/nacl_trusted_listener.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9851521463b696f98788ac5c9843fd4138d51090 |
--- /dev/null |
+++ b/components/nacl/loader/nacl_trusted_listener.cc |
@@ -0,0 +1,89 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/nacl/loader/nacl_trusted_listener.h" |
+ |
+#include <fcntl.h> |
+ |
+#include "components/nacl/common/nacl_messages.h" |
+#include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
+#include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
+#include "native_client/src/trusted/service_runtime/sel_main_chrome.h" |
+ |
+NaClTrustedListener::NaClTrustedListener( |
+ const IPC::ChannelHandle& handle, |
+ struct NaClApp* nacl_app, |
+ int irt_fd, |
+ base::MessageLoopProxy* message_loop_proxy, |
+ base::WaitableEvent* shutdown_event) |
+ : nacl_app_(nacl_app), |
+ irt_fd_(irt_fd), |
+ chrome_main_thread_("NaCl_MainThread") { |
+ channel_.reset(new IPC::SyncChannel(handle, IPC::Channel::MODE_SERVER, this, |
+ message_loop_proxy, true, |
+ shutdown_event)); |
+ fprintf(stderr, "NaClTrustedListener created\n"); |
+} |
+ |
+#if defined(OS_POSIX) |
+int NaClTrustedListener::TakeClientFileDescriptor() { |
+ return channel_->TakeClientFileDescriptor(); |
+} |
+#endif |
+ |
+bool NaClTrustedListener::OnMessageReceived(const IPC::Message& msg) { |
+ fprintf(stderr, "NaClTrustedListener::OnMessageReceived\n"); |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(NaClTrustedListener, msg) |
+ IPC_MESSAGE_HANDLER(NaClProcessMsg_LoadModule, OnLoadModule) |
+ IPC_MESSAGE_HANDLER(NaClProcessMsg_StartModule, OnStartModule) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void NaClTrustedListener::OnChannelConnected(int32 peer_pid) { |
+ fprintf(stderr, "NaClTrustedListener::OnChannelConnected, peer_pid=%d\n", |
+ peer_pid); |
+} |
+ |
+void NaClTrustedListener::OnChannelError() { |
+ fprintf(stderr, "NaClTrustedListener::OnChannelError\n"); |
+ channel_->Close(); |
+} |
+ |
+bool NaClTrustedListener::Send(IPC::Message* msg) { |
+ return channel_->Send(msg); |
+} |
+ |
+extern "C" |
+void NaClAppLoadModule( |
+ struct NaClApp* nap, |
+ struct NaClDesc* nexe, |
+ char *aux_info, |
+ void (*load_cb)(void *instance_data, |
+ NaClErrorCode status), |
+ void *instance_data); |
+ |
+void NaClTrustedListener::OnLoadModule( |
+ const IPC::PlatformFileForTransit& platform_file_for_transit, |
+ NaClErrorCode *output_code) { |
+ fprintf(stderr, "NaClTrustedListener::OnLoadModule\n"); |
+ |
+ base::PlatformFile platform_file = |
+ IPC::PlatformFileForTransitToPlatformFile(platform_file_for_transit); |
+ nacl::DescWrapperFactory desc_wrapper_factory; |
+ nacl::DescWrapper* wrapper = |
+ desc_wrapper_factory.MakeFileDesc(platform_file, O_RDONLY); |
+ |
+ *output_code = NaClChromeMainLoadModule(nacl_app_, wrapper->desc()); |
+} |
+ |
+void NaClTrustedListener::OnStartModule() { |
+ fprintf(stderr, "NaClTrustedListener::OnStartModule\n"); |
+ chrome_main_thread_.Start(); |
+ chrome_main_thread_.message_loop()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&NaClChromeMainStartModule, nacl_app_, irt_fd_)); |
+} |