| Index: components/nacl/renderer/ppb_nacl_private_impl.cc
|
| diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc
|
| index 3000716426210064b42efb31e8fdcedb38b43b0b..edecff95fb3f664d38a8e04567b3f92e5190dfdc 100644
|
| --- a/components/nacl/renderer/ppb_nacl_private_impl.cc
|
| +++ b/components/nacl/renderer/ppb_nacl_private_impl.cc
|
| @@ -11,8 +11,10 @@
|
| #include "base/logging.h"
|
| #include "base/rand_util.h"
|
| #include "components/nacl/common/nacl_host_messages.h"
|
| +#include "components/nacl/common/nacl_messages.h"
|
| #include "components/nacl/common/nacl_types.h"
|
| #include "components/nacl/renderer/pnacl_translation_resource_host.h"
|
| +#include "components/nacl/renderer/trusted_plugin_channel.h"
|
| #include "content/public/common/content_client.h"
|
| #include "content/public/common/content_switches.h"
|
| #include "content/public/common/sandbox_init.h"
|
| @@ -67,6 +69,12 @@ typedef std::map<PP_Instance, InstanceInfo> InstanceInfoMap;
|
| base::LazyInstance<InstanceInfoMap> g_instance_info =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| +typedef std::map<PP_Instance, nacl::TrustedPluginChannel*>
|
| +InstanceTrustedChannelMap;
|
| +
|
| +base::LazyInstance<InstanceTrustedChannelMap> g_channel_map =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| static int GetRoutingID(PP_Instance instance) {
|
| // Check that we are on the main renderer thread.
|
| DCHECK(content::RenderThread::Get());
|
| @@ -78,16 +86,17 @@ static int GetRoutingID(PP_Instance instance) {
|
| }
|
|
|
| // Launch NaCl's sel_ldr process.
|
| -PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
|
| - const char* alleged_url,
|
| - PP_Bool uses_irt,
|
| - PP_Bool uses_ppapi,
|
| - PP_Bool enable_ppapi_dev,
|
| - PP_Bool enable_dyncode_syscalls,
|
| - PP_Bool enable_exception_handling,
|
| - PP_Bool enable_crash_throttling,
|
| - void* imc_handle,
|
| - struct PP_Var* error_message) {
|
| +void LaunchSelLdr(PP_Instance instance,
|
| + const char* alleged_url,
|
| + PP_Bool uses_irt,
|
| + PP_Bool uses_ppapi,
|
| + PP_Bool enable_ppapi_dev,
|
| + PP_Bool enable_dyncode_syscalls,
|
| + PP_Bool enable_exception_handling,
|
| + PP_Bool enable_crash_throttling,
|
| + void* imc_handle,
|
| + struct PP_Var* error_message,
|
| + PP_CompletionCallback callback) {
|
| nacl::FileDescriptor result_socket;
|
| IPC::Sender* sender = content::RenderThread::Get();
|
| DCHECK(sender);
|
| @@ -99,8 +108,10 @@ PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
|
| // so those nexes can skip finding a routing_id.
|
| if (uses_ppapi) {
|
| routing_id = GetRoutingID(instance);
|
| - if (!routing_id)
|
| - return PP_EXTERNAL_PLUGIN_FAILED;
|
| + if (!routing_id) {
|
| + PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
|
| + return;
|
| + }
|
| }
|
|
|
| InstanceInfo instance_info;
|
| @@ -127,14 +138,16 @@ PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
|
| PP_ToBool(enable_crash_throttling)),
|
| &launch_result,
|
| &error_message_string))) {
|
| - return PP_EXTERNAL_PLUGIN_FAILED;
|
| + PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
|
| + return;
|
| }
|
| if (!error_message_string.empty()) {
|
| *error_message = ppapi::StringVar::StringToPPVar(error_message_string);
|
| - return PP_EXTERNAL_PLUGIN_FAILED;
|
| + PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
|
| + return;
|
| }
|
| result_socket = launch_result.imc_channel_handle;
|
| - instance_info.channel_handle = launch_result.ipc_channel_handle;
|
| + instance_info.channel_handle = launch_result.untrusted_ipc_channel_handle;
|
| instance_info.plugin_pid = launch_result.plugin_pid;
|
| instance_info.plugin_child_id = launch_result.plugin_child_id;
|
| // Don't save instance_info if channel handle is invalid.
|
| @@ -146,10 +159,21 @@ PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
|
| if (!invalid_handle)
|
| g_instance_info.Get()[instance] = instance_info;
|
|
|
| - *(static_cast<NaClHandle*>(imc_handle)) =
|
| - nacl::ToNativeHandle(result_socket);
|
| + // Stash the trusted handle as well.
|
| + invalid_handle = launch_result.trusted_ipc_channel_handle.name.empty();
|
| +#if defined(OS_POSIX)
|
| + if (!invalid_handle)
|
| + invalid_handle = (launch_result.trusted_ipc_channel_handle.socket.fd == -1);
|
| +#endif
|
|
|
| - return PP_EXTERNAL_PLUGIN_OK;
|
| + if (!invalid_handle) {
|
| + g_channel_map.Get()[instance] = new nacl::TrustedPluginChannel(
|
| + launch_result.trusted_ipc_channel_handle, callback);
|
| + *(static_cast<NaClHandle*>(imc_handle)) =
|
| + nacl::ToNativeHandle(result_socket);
|
| + } else {
|
| + PP_RunCompletionCallback(&callback, PP_ERROR_FAILED);
|
| + }
|
| }
|
|
|
| PP_ExternalPluginResult StartPpapiProxy(PP_Instance instance) {
|
| @@ -409,6 +433,48 @@ void SetReadOnlyProperty(PP_Instance instance,
|
| plugin_instance->SetEmbedProperty(key, value);
|
| }
|
|
|
| +PP_Bool LoadModule(PP_Instance instance, PP_FileHandle handle,
|
| + uint32_t *nacl_error_code) {
|
| + fprintf(stderr, "PPB_NaCl_Private LoadModule()\n");
|
| + // We can't use PepperPluginInstance here because it doesn't have sufficient
|
| + // DEPS to see the NaClProcessMsg_LoadModule message. Therefore, we must do
|
| + // our own accounting and keep a channel map here.
|
| +
|
| + InstanceTrustedChannelMap::iterator it = g_channel_map.Get().find(instance);
|
| + if (it == g_channel_map.Get().end()) {
|
| + NOTREACHED();
|
| + return PP_FALSE;
|
| + }
|
| + nacl::TrustedPluginChannel* channel = it->second;
|
| + IPC::PlatformFileForTransit platform_file_for_transit;
|
| +#if defined(OS_WIN)
|
| + platform_file_for_transit = handle;
|
| +#elif defined(OS_POSIX)
|
| + platform_file_for_transit = base::FileDescriptor(handle, false);
|
| +#endif
|
| + fprintf(stderr, "sending NaClProcessMsg_LoadModule\n");
|
| + NaClErrorCode code;
|
| + bool ok = channel->Send(
|
| + new NaClProcessMsg_LoadModule(platform_file_for_transit,
|
| + &code));
|
| + *nacl_error_code = code;
|
| + fprintf(stderr, "sent NaClProcessMsg_LoadModule\n");
|
| + return PP_FromBool(ok);
|
| +}
|
| +
|
| +PP_Bool StartModule(PP_Instance instance) {
|
| + InstanceTrustedChannelMap::iterator it = g_channel_map.Get().find(instance);
|
| + if (it == g_channel_map.Get().end()) {
|
| + NOTREACHED();
|
| + return PP_FALSE;
|
| + }
|
| + nacl::TrustedPluginChannel* channel = it->second;
|
| + fprintf(stderr, "sending NaClProcessMsg_StartModule\n");
|
| + bool ok = channel->Send(new NaClProcessMsg_StartModule());
|
| + fprintf(stderr, "sent NaClProcessMsg_StartModule\n");
|
| + return PP_FromBool(ok);
|
| +}
|
| +
|
| const PPB_NaCl_Private nacl_interface = {
|
| &LaunchSelLdr,
|
| &StartPpapiProxy,
|
| @@ -422,7 +488,9 @@ const PPB_NaCl_Private nacl_interface = {
|
| &ReportNaClError,
|
| &OpenNaClExecutable,
|
| &DispatchEvent,
|
| - &SetReadOnlyProperty
|
| + &SetReadOnlyProperty,
|
| + &LoadModule,
|
| + &StartModule
|
| };
|
|
|
| } // namespace
|
|
|