summaryrefslogtreecommitdiffstats
path: root/chrome/nacl
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 19:47:38 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 19:47:38 +0000
commit8510d2832f673410e30165cbe0ab7dfbb4710e6a (patch)
treeb51713e3264faca51726185587d7edf568dda6ed /chrome/nacl
parent031afc6601b016abd3f36cc4bdb877ae74ac2e2f (diff)
downloadchromium_src-8510d2832f673410e30165cbe0ab7dfbb4710e6a.zip
chromium_src-8510d2832f673410e30165cbe0ab7dfbb4710e6a.tar.gz
chromium_src-8510d2832f673410e30165cbe0ab7dfbb4710e6a.tar.bz2
Change NaCl IPC PPAPI proxy startup to support a NaCl-Browser process
channel. NaClProcessHost now creates an initial NaCl-Browser channel, then uses it to send a message to create the NaCl-Renderer channel. The main() for the IPC-IRT creates a PpapiDispatcher object to manage this channel and manage the PluginDispatchers for each renderer. BUG=116317 TEST=manual TBR=bbudge@chromium.org Review URL: https://chromiumcodereview.appspot.com/10912011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/nacl')
-rw-r--r--chrome/nacl/nacl_ipc_adapter.cc43
-rw-r--r--chrome/nacl/nacl_listener.cc26
2 files changed, 51 insertions, 18 deletions
diff --git a/chrome/nacl/nacl_ipc_adapter.cc b/chrome/nacl/nacl_ipc_adapter.cc
index 4f4f328..71b5cc56 100644
--- a/chrome/nacl/nacl_ipc_adapter.cc
+++ b/chrome/nacl/nacl_ipc_adapter.cc
@@ -89,9 +89,9 @@ void DeleteChannel(IPC::Channel* channel) {
delete channel;
}
-void WriteFileDescriptor(int handle_index,
- const ppapi::proxy::SerializedHandle& handle,
- IPC::Message* message) {
+void WriteHandle(int handle_index,
+ const ppapi::proxy::SerializedHandle& handle,
+ IPC::Message* message) {
ppapi::proxy::SerializedHandle::WriteHeader(handle.header(), message);
// Now write the handle itself in POSIX style.
@@ -108,7 +108,7 @@ void ConvertHandle(const ppapi::proxy::SerializedHandle& handle,
Handles* handles, IPC::Message* msg, int* handle_index) {
handles->push_back(handle);
if (msg)
- WriteFileDescriptor((*handle_index)++, handle, msg);
+ WriteHandle((*handle_index)++, handle, msg);
}
// This overload is to catch all types other than SerializedHandle. On Windows,
@@ -434,6 +434,7 @@ int NaClIPCAdapter::TakeClientFileDescriptor() {
return false; \
break; \
}
+
bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) {
{
base::AutoLock lock(lock_);
@@ -443,12 +444,21 @@ bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) {
// Pointer to the "new" message we will rewrite on Windows. On posix, this
// isn't necessary, so it will stay NULL.
IPC::Message* new_msg_ptr = NULL;
-#if defined(OS_WIN)
IPC::Message new_msg(msg.routing_id(), msg.type(), msg.priority());
+#if defined(OS_WIN)
new_msg_ptr = &new_msg;
+#else
+ // Even on POSIX, we have to rewrite messages to create channels, because
+ // these contain a handle with an invalid (place holder) descriptor. The
+ // message sending code sees this and doesn't pass the descriptor over
+ // correctly.
+ if (msg.type() == PpapiMsg_CreateNaClChannel::ID)
+ new_msg_ptr = &new_msg;
#endif
+
Handles handles;
switch (msg.type()) {
+ CASE_FOR_MESSAGE(PpapiMsg_CreateNaClChannel)
CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated)
CASE_FOR_MESSAGE(PpapiMsg_PPBAudioInput_OpenACK)
case IPC_REPLY_ID: {
@@ -502,10 +512,33 @@ bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) {
iter->descriptor().fd
#endif
));
+ break;
+ }
+ case ppapi::proxy::SerializedHandle::CHANNEL_HANDLE: {
+ // Check that this came from a PpapiMsg_CreateNaClChannel message.
+ // This code here is only appropriate for that message.
+ DCHECK(msg.type() == PpapiMsg_CreateNaClChannel::ID);
+ IPC::ChannelHandle channel_handle =
+ IPC::Channel::GenerateVerifiedChannelID("nacl");
+ scoped_refptr<NaClIPCAdapter> ipc_adapter(
+ new NaClIPCAdapter(channel_handle, task_runner_));
+#if defined(OS_POSIX)
+ channel_handle.socket = base::FileDescriptor(
+ ipc_adapter->TakeClientFileDescriptor(), true);
+#endif
+ nacl_desc.reset(factory.MakeGeneric(ipc_adapter->MakeNaClDesc()));
+ // Send back a message that the channel was created.
+ scoped_ptr<IPC::Message> response(
+ new PpapiHostMsg_ChannelCreated(channel_handle));
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this,
+ base::Passed(&response)));
+ break;
}
case ppapi::proxy::SerializedHandle::INVALID: {
// Nothing to do. TODO(dmichael): Should we log this? Or is it
// sometimes okay to pass an INVALID handle?
+ break;
}
// No default, so the compiler will warn us if new types get added.
}
diff --git a/chrome/nacl/nacl_listener.cc b/chrome/nacl/nacl_listener.cc
index 34991ec..7d1fde6 100644
--- a/chrome/nacl/nacl_listener.cc
+++ b/chrome/nacl/nacl_listener.cc
@@ -198,22 +198,22 @@ void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) {
}
if (params.enable_ipc_proxy) {
- // Create the server side of the channel and notify the process host so it
- // can reply to the renderer, which will connect as client.
- IPC::ChannelHandle channel_handle =
+ // Create the initial PPAPI IPC channel between the NaCl IRT and the
+ // browser process. The IRT uses this channel to communicate with the
+ // browser and to create additional IPC channels to renderer processes.
+ IPC::ChannelHandle handle =
IPC::Channel::GenerateVerifiedChannelID("nacl");
-
- scoped_refptr<NaClIPCAdapter> ipc_adapter(new NaClIPCAdapter(
- channel_handle, io_thread_.message_loop_proxy()));
- args->initial_ipc_desc = ipc_adapter.get()->MakeNaClDesc();
-
+ scoped_refptr<NaClIPCAdapter> ipc_adapter(
+ new NaClIPCAdapter(handle, io_thread_.message_loop_proxy()));
+ // Pass a NaClDesc to the untrusted side. This will hold a ref to the
+ // NaClIPCAdapter.
+ args->initial_ipc_desc = ipc_adapter->MakeNaClDesc();
#if defined(OS_POSIX)
- channel_handle.socket = base::FileDescriptor(
- ipc_adapter.get()->TakeClientFileDescriptor(), true);
+ handle.socket = base::FileDescriptor(
+ ipc_adapter->TakeClientFileDescriptor(), true);
#endif
-
- if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(channel_handle)))
- LOG(ERROR) << "Failed to send IPC channel handle to renderer.";
+ if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(handle)))
+ LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost.";
}
std::vector<nacl::FileDescriptor> handles = params.handles;