diff options
author | gregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 21:46:15 +0000 |
---|---|---|
committer | gregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 21:46:15 +0000 |
commit | f08e47dbfce4823386bef263924be4836d7d8f86 (patch) | |
tree | 69bff1a47f156c22e1d06f2631e42880b2542749 | |
parent | 8ba379904681b2fbbbfc8747b9ef08bb861fdd63 (diff) | |
download | chromium_src-f08e47dbfce4823386bef263924be4836d7d8f86.zip chromium_src-f08e47dbfce4823386bef263924be4836d7d8f86.tar.gz chromium_src-f08e47dbfce4823386bef263924be4836d7d8f86.tar.bz2 |
Get the nexe name from NaCl and send the NaCl process handle and pid to the renderer
TEST=none
BUG=http://code.google.com/p/nativeclient/issues/detail?id=108
Review URL: http://codereview.chromium.org/273056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29195 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | chrome/browser/nacl_process_host.cc | 61 | ||||
-rw-r--r-- | chrome/browser/nacl_process_host.h | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 16 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 7 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/renderer/render_process.cc | 20 | ||||
-rw-r--r-- | chrome/renderer/render_process.h | 6 |
8 files changed, 87 insertions, 40 deletions
@@ -43,7 +43,7 @@ deps = { "http://v8.googlecode.com/svn/trunk@3030", "src/native_client": - "http://nativeclient.googlecode.com/svn/trunk/src/native_client@852", + "http://nativeclient.googlecode.com/svn/trunk/src/native_client@868", "src/third_party/skia": "http://skia.googlecode.com/svn/trunk@376", diff --git a/chrome/browser/nacl_process_host.cc b/chrome/browser/nacl_process_host.cc index fa9e961..133f17f 100644 --- a/chrome/browser/nacl_process_host.cc +++ b/chrome/browser/nacl_process_host.cc @@ -31,25 +31,31 @@ #endif NaClProcessHost::NaClProcessHost( - ResourceDispatcherHost *resource_dispatcher_host) + ResourceDispatcherHost *resource_dispatcher_host, + const std::wstring& url) : ChildProcessHost(NACL_PROCESS, resource_dispatcher_host), resource_dispatcher_host_(resource_dispatcher_host) { - // TODO(gregoryd): fix this to include the nexe name. - set_name(L"nexe name should appear here"); + set_name(url); } bool NaClProcessHost::Launch(ResourceMessageFilter* renderer_msg_filter, const int descriptor, - nacl::FileDescriptor* handle) { + nacl::FileDescriptor* imc_handle, + nacl::FileDescriptor* nacl_process_handle, + int* nacl_process_id) { #ifdef DISABLE_NACL NOTIMPLEMENTED() << "Native Client disabled at build time"; return false; #else nacl::Handle pair[2]; bool success = false; + + NATIVE_HANDLE(*imc_handle) = nacl::kInvalidHandle; + NATIVE_HANDLE(*nacl_process_handle) = nacl::kInvalidHandle; + *nacl_process_id = 0; + // Create a connected socket if (nacl::SocketPair(pair) == -1) { - NATIVE_HANDLE(*handle) = nacl::kInvalidHandle; return false; } @@ -58,40 +64,53 @@ bool NaClProcessHost::Launch(ResourceMessageFilter* renderer_msg_filter, if (!success) { nacl::Close(pair[0]); - NATIVE_HANDLE(*handle) = nacl::kInvalidHandle; return false; } - nacl::Handle duplicate_handle = nacl::kInvalidHandle; #if NACL_WINDOWS + // Duplicate the IMC handle DuplicateHandle(base::GetCurrentProcessHandle(), reinterpret_cast<HANDLE>(pair[0]), renderer_msg_filter->handle(), - reinterpret_cast<HANDLE*>(&duplicate_handle), + imc_handle, GENERIC_READ | GENERIC_WRITE, FALSE, DUPLICATE_CLOSE_SOURCE); - *handle = duplicate_handle; + + // Duplicate the process handle + DuplicateHandle(base::GetCurrentProcessHandle(), + handle(), + renderer_msg_filter->handle(), + nacl_process_handle, + PROCESS_DUP_HANDLE, + FALSE, + 0); + #else - duplicate_handle = pair[0]; - int flags = fcntl(duplicate_handle, F_GETFD); + int flags = fcntl(pair[0], F_GETFD); if (flags != -1) { flags |= FD_CLOEXEC; - fcntl(duplicate_handle, F_SETFD, flags); + fcntl(pair[0], F_SETFD, flags); } - // No need to dup the handle - we don't pass it anywhere else so + // No need to dup the imc_handle - we don't pass it anywhere else so // it cannot be closed. - handle->fd = duplicate_handle; - handle->auto_close = true; + imc_handle->fd = pair[0]; + imc_handle->auto_close = true; + + // Process handles are used on Windows only + NATIVE_HANDLE(*nacl_process_handle) = nacl::kInvalidHandle; #endif + // Get the pid of the NaCl process + *nacl_process_id = base::GetProcId(handle()); + return true; #endif // DISABLE_NACL } bool NaClProcessHost::LaunchSelLdr(ResourceMessageFilter* renderer_msg_filter, const int descriptor, - const nacl::Handle handle) { + const nacl::Handle imc_handle) { if (!CreateChannel()) return false; @@ -152,17 +171,17 @@ bool NaClProcessHost::LaunchSelLdr(ResourceMessageFilter* renderer_msg_filter, return false; SetHandle(process); - // send a message with duplicated handle to sel_ldr - return SendStartMessage(process, descriptor, handle); + // send a message with duplicated imc_handle to sel_ldr + return SendStartMessage(process, descriptor, imc_handle); } bool NaClProcessHost::SendStartMessage(base::ProcessHandle process, int descriptor, - nacl::Handle handle) { + nacl::Handle imc_handle) { nacl::FileDescriptor channel; #if defined(OS_WIN) if (!DuplicateHandle(GetCurrentProcess(), - reinterpret_cast<HANDLE>(handle), + reinterpret_cast<HANDLE>(imc_handle), process, reinterpret_cast<HANDLE*>(&channel), GENERIC_READ | GENERIC_WRITE, @@ -170,7 +189,7 @@ bool NaClProcessHost::SendStartMessage(base::ProcessHandle process, return false; } #else - channel.fd = dup(handle); + channel.fd = dup(imc_handle); channel.auto_close = true; #endif NaClProcessMsg_Start* msg = new NaClProcessMsg_Start(descriptor, diff --git a/chrome/browser/nacl_process_host.h b/chrome/browser/nacl_process_host.h index 59de526..6d549cf 100644 --- a/chrome/browser/nacl_process_host.h +++ b/chrome/browser/nacl_process_host.h @@ -20,13 +20,16 @@ class ResourceMessageFilter; // running in the renderer and NaCl processes. class NaClProcessHost : public ChildProcessHost { public: - explicit NaClProcessHost(ResourceDispatcherHost *resource_dispatcher_host); + NaClProcessHost(ResourceDispatcherHost *resource_dispatcher_host, + const std::wstring& url); ~NaClProcessHost() {} // Initialize the new NaCl process, returning true on success. bool Launch(ResourceMessageFilter* renderer_msg_filter, const int descriptor, - nacl::FileDescriptor *handle); + nacl::FileDescriptor* handle, + nacl::FileDescriptor* nacl_process_handle, + int* nacl_process_id); virtual void OnMessageReceived(const IPC::Message& msg); diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index cecdeaf..da1e8ad 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -603,10 +603,18 @@ void ResourceMessageFilter::OnOpenChannelToPlugin(const GURL& url, this, url, mime_type, locale, reply_msg); } -void ResourceMessageFilter::OnLaunchNaCl(int channel_descriptor, - nacl::FileDescriptor* handle) { - NaClProcessHost* nacl_host = new NaClProcessHost(resource_dispatcher_host_); - nacl_host->Launch(this, channel_descriptor, handle); +void ResourceMessageFilter::OnLaunchNaCl(const std::wstring& url, + int channel_descriptor, + nacl::FileDescriptor* imc_handle, + nacl::FileDescriptor* nacl_process_handle, + int* nacl_process_id) { + NaClProcessHost* nacl_host = new NaClProcessHost(resource_dispatcher_host_, + url); + nacl_host->Launch(this, + channel_descriptor, + imc_handle, + nacl_process_handle, + nacl_process_id); } void ResourceMessageFilter::OnCreateDedicatedWorker(const GURL& url, diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 6a12d14..34a17f3 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -153,8 +153,11 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, const std::string& mime_type, const std::wstring& locale, IPC::Message* reply_msg); - void OnLaunchNaCl(int channel_descriptor, - nacl::FileDescriptor* handle); + void OnLaunchNaCl(const std::wstring& url, + int channel_descriptor, + nacl::FileDescriptor* handle, + nacl::FileDescriptor* nacl_process_handle, + int* nacl_process_id); void OnCreateDedicatedWorker(const GURL& url, int render_view_route_id, int* route_id); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 824a773..fd2ab49 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1173,10 +1173,12 @@ IPC_BEGIN_MESSAGES(ViewHost) // A renderer sends this to the browser process when it wants to start // a new instance of the Native Client process. The browser will launch // the process and return a handle to an IMC channel. - IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_LaunchNaCl, + IPC_SYNC_MESSAGE_CONTROL2_3(ViewHostMsg_LaunchNaCl, + std::wstring /* url for the NaCl module */, int /* channel number */, - nacl::FileDescriptor /* handle - one side - of a socket pair */) + nacl::FileDescriptor /* imc channel handle */, + nacl::FileDescriptor /* NaCl process handle */, + int /* NaCl process id */) #if defined(OS_LINUX) // A renderer sends this when it needs a browser-side widget for diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc index 8dc9264..7aa36c4 100644 --- a/chrome/renderer/render_process.cc +++ b/chrome/renderer/render_process.cc @@ -100,7 +100,6 @@ RenderProcess::RenderProcess() initialized_media_library_ = media::InitializeMediaLibrary(bundle_path.Append("Libraries")); - #else FilePath module_path; initialized_media_library_ = @@ -135,16 +134,25 @@ bool RenderProcess::InProcessPlugins() { #endif } -bool RenderProcess::LaunchNaClProcess(int imc_fd, - nacl::Handle* handle) { +bool RenderProcess::LaunchNaClProcess(const char* url, + int imc_fd, + nacl::Handle* imc_handle, + nacl::Handle* nacl_process_handle, + int* nacl_process_id) { // TODO(gregoryd): nacl::FileDescriptor will be soon merged with // base::FileDescriptor - nacl::FileDescriptor descriptor; + nacl::FileDescriptor imc_descriptor; + nacl::FileDescriptor nacl_process_descriptor; if (!RenderThread::current()->Send( - new ViewHostMsg_LaunchNaCl(imc_fd, &descriptor))) { + new ViewHostMsg_LaunchNaCl(ASCIIToWide(url), + imc_fd, + &imc_descriptor, + &nacl_process_descriptor, + nacl_process_id))) { return false; } - *handle = NATIVE_HANDLE(descriptor); + *imc_handle = NATIVE_HANDLE(imc_descriptor); + *nacl_process_handle = NATIVE_HANDLE(nacl_process_descriptor); return true; } diff --git a/chrome/renderer/render_process.h b/chrome/renderer/render_process.h index 0ab9996..4c682dc 100644 --- a/chrome/renderer/render_process.h +++ b/chrome/renderer/render_process.h @@ -54,7 +54,11 @@ class RenderProcess : public ChildProcess { // Sends a message to the browser process asking to launch a new NaCl process. // Called from NaCl plugin code. - static bool LaunchNaClProcess(int imc_fd, nacl::Handle *handle); + static bool LaunchNaClProcess(const char* url, + int imc_fd, + nacl::Handle* imc_handle, + nacl::Handle* nacl_process_handle, + int* nacl_process_id); private: // Look in the shared memory cache for a suitable object to reuse. |