| 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 5a1dcdbbf81945f25fc38492d92bfa3e436b804d..b9e34c7b8dc8ec2bf0e7ae8b53765095b4158477 100644
|
| --- a/components/nacl/renderer/ppb_nacl_private_impl.cc
|
| +++ b/components/nacl/renderer/ppb_nacl_private_impl.cc
|
| @@ -30,8 +30,7 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "build/build_config.h"
|
| -#include "components/nacl/common/nacl_host_messages.h"
|
| -#include "components/nacl/common/nacl_messages.h"
|
| +#include "components/nacl/common/nacl.mojom.h"
|
| #include "components/nacl/common/nacl_nonsfi_util.h"
|
| #include "components/nacl/common/nacl_switches.h"
|
| #include "components/nacl/common/nacl_types.h"
|
| @@ -62,6 +61,7 @@
|
| #include "ppapi/shared_impl/var.h"
|
| #include "ppapi/shared_impl/var_tracker.h"
|
| #include "ppapi/thunk/enter.h"
|
| +#include "services/service_manager/public/cpp/interface_provider.h"
|
| #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
|
| #include "third_party/WebKit/public/platform/WebURLRequest.h"
|
| #include "third_party/WebKit/public/platform/WebURLResponse.h"
|
| @@ -84,18 +84,36 @@ const char* const kPortableArch = "portable";
|
| // The base URL for resources used by the PNaCl translator processes.
|
| const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/";
|
|
|
| -base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> >
|
| +base::LazyInstance<std::unique_ptr<PnaclTranslationResourceHost>>
|
| g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER;
|
|
|
| +class NaClHostConnectionHolder {
|
| + public:
|
| + NaClHostConnectionHolder() {
|
| + content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface(&host_);
|
| + }
|
| +
|
| + mojom::NaClHost* host() { return host_.get(); }
|
| +
|
| + private:
|
| + mojom::NaClHostPtr host_;
|
| +};
|
| +
|
| +// A renderer-process-wide connection to the browser side. PPBNaClPrivate is a
|
| +// collection of static methods so a global is required to store a persistent
|
| +// connection.
|
| +base::LazyInstance<NaClHostConnectionHolder>::Leaky g_nacl_host_connection =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| bool InitializePnaclResourceHost() {
|
| // Must run on the main thread.
|
| content::RenderThread* render_thread = content::RenderThread::Get();
|
| if (!render_thread)
|
| return false;
|
| - if (!g_pnacl_resource_host.Get().get()) {
|
| + if (!g_pnacl_resource_host.Get()) {
|
| g_pnacl_resource_host.Get() =
|
| - new PnaclTranslationResourceHost(render_thread->GetIOTaskRunner());
|
| - render_thread->AddFilter(g_pnacl_resource_host.Get().get());
|
| + base::MakeUnique<PnaclTranslationResourceHost>(
|
| + g_nacl_host_connection.Get().host());
|
| }
|
| return true;
|
| }
|
| @@ -129,7 +147,8 @@ struct InstanceInfo {
|
| class NaClPluginInstance {
|
| public:
|
| explicit NaClPluginInstance(PP_Instance instance)
|
| - : nexe_load_manager(instance), pexe_size(0) {}
|
| + : nexe_load_manager(instance, g_nacl_host_connection.Get().host()),
|
| + pexe_size(0) {}
|
| ~NaClPluginInstance() {
|
| // Make sure that we do not leak a mojo handle if the NaCl loader
|
| // process never called ppapi_start() to initialize PPAPI.
|
| @@ -401,14 +420,13 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| PP_CompletionCallback callback) {
|
| CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->
|
| BelongsToCurrentThread());
|
| + base::File nexe_file(nexe_file_info->handle);
|
| NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type);
|
| // Create the manifest service proxy here, so on error case, it will be
|
| // destructed (without passing it to ManifestServiceChannel).
|
| std::unique_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy(
|
| new ManifestServiceProxy(instance, process_type));
|
|
|
| - IPC::Sender* sender = content::RenderThread::Get();
|
| - DCHECK(sender);
|
| int routing_id = GetRoutingID(instance);
|
| NexeLoadManager* load_manager = GetNexeLoadManager(instance);
|
| DCHECK(load_manager);
|
| @@ -416,9 +434,6 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| content::PepperPluginInstance::Get(instance);
|
| DCHECK(plugin_instance);
|
| if (!routing_id || !load_manager || !plugin_instance) {
|
| - if (nexe_file_info->handle != PP_kInvalidFileHandle) {
|
| - base::File closer(nexe_file_info->handle);
|
| - }
|
| ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
|
| FROM_HERE, base::Bind(callback.func, callback.user_data,
|
| static_cast<int32_t>(PP_ERROR_FAILED)));
|
| @@ -454,33 +469,14 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| }
|
| }
|
|
|
| - IPC::PlatformFileForTransit nexe_for_transit =
|
| - IPC::InvalidPlatformFileForTransit();
|
| -#if defined(OS_POSIX)
|
| - if (nexe_file_info->handle != PP_kInvalidFileHandle)
|
| - nexe_for_transit = base::FileDescriptor(nexe_file_info->handle, true);
|
| -#elif defined(OS_WIN)
|
| - nexe_for_transit = IPC::PlatformFileForTransit(nexe_file_info->handle,
|
| - base::GetCurrentProcId());
|
| -#else
|
| -# error Unsupported target platform.
|
| -#endif
|
| -
|
| std::string error_message_string;
|
| - NaClLaunchResult launch_result;
|
| - if (!sender->Send(new NaClHostMsg_LaunchNaCl(
|
| - NaClLaunchParams(
|
| - instance_info.url.spec(),
|
| - nexe_for_transit,
|
| - nexe_file_info->token_lo,
|
| - nexe_file_info->token_hi,
|
| - resource_prefetch_request_list,
|
| - routing_id,
|
| - perm_bits,
|
| - PP_ToBool(uses_nonsfi_mode),
|
| - process_type),
|
| - &launch_result,
|
| - &error_message_string))) {
|
| + mojom::NaClLaunchResultPtr launch_result;
|
| + if (!g_nacl_host_connection.Get().host()->LaunchNaCl(
|
| + mojom::NaClLaunchParams::New(
|
| + instance_info.url, std::move(nexe_file), nexe_file_info->token_lo,
|
| + nexe_file_info->token_hi, resource_prefetch_request_list,
|
| + routing_id, perm_bits, PP_ToBool(uses_nonsfi_mode), process_type),
|
| + &launch_result, &error_message_string)) {
|
| ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
|
| FROM_HERE,
|
| base::Bind(callback.func, callback.user_data,
|
| @@ -491,13 +487,6 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| load_manager->set_nonsfi(PP_ToBool(uses_nonsfi_mode));
|
|
|
| if (!error_message_string.empty()) {
|
| - // Even on error, some FDs/handles may be passed to here.
|
| - // We must release those resources.
|
| - // See also nacl_process_host.cc.
|
| - if (base::SharedMemory::IsHandleValid(
|
| - launch_result.crash_info_shmem_handle))
|
| - base::SharedMemory::CloseHandle(launch_result.crash_info_shmem_handle);
|
| -
|
| if (PP_ToBool(main_service_runtime)) {
|
| load_manager->ReportLoadError(PP_NACL_ERROR_SEL_LDR_LAUNCH,
|
| "ServiceRuntime: failed to start",
|
| @@ -509,10 +498,12 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| static_cast<int32_t>(PP_ERROR_FAILED)));
|
| return;
|
| }
|
| + DCHECK(launch_result);
|
|
|
| - instance_info.channel_handle = launch_result.ppapi_ipc_channel_handle;
|
| - instance_info.plugin_pid = launch_result.plugin_pid;
|
| - instance_info.plugin_child_id = launch_result.plugin_child_id;
|
| + instance_info.channel_handle =
|
| + launch_result->ppapi_ipc_channel_handle.release();
|
| + 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.
|
| if (IsValidChannelHandle(instance_info.channel_handle)) {
|
| @@ -534,17 +525,14 @@ void PPBNaClPrivate::LaunchSelLdr(
|
|
|
| // Store the crash information shared memory handle.
|
| load_manager->set_crash_info_shmem_handle(
|
| - launch_result.crash_info_shmem_handle);
|
| + std::move(launch_result->crash_info_shmem_handle));
|
|
|
| // Create the trusted plugin channel.
|
| - if (IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) {
|
| + if (launch_result->trusted_ipc_channel_handle.is_pending()) {
|
| bool is_helper_nexe = !PP_ToBool(main_service_runtime);
|
| std::unique_ptr<TrustedPluginChannel> trusted_plugin_channel(
|
| new TrustedPluginChannel(
|
| - load_manager,
|
| - mojo::MakeRequest<mojom::NaClRendererHost>(
|
| - mojo::ScopedMessagePipeHandle(
|
| - launch_result.trusted_ipc_channel_handle.mojo_handle)),
|
| + load_manager, std::move(launch_result->trusted_ipc_channel_handle),
|
| is_helper_nexe));
|
| load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel));
|
| } else {
|
| @@ -553,10 +541,10 @@ void PPBNaClPrivate::LaunchSelLdr(
|
| }
|
|
|
| // Create the manifest service handle as well.
|
| - if (IsValidChannelHandle(launch_result.manifest_service_ipc_channel_handle)) {
|
| + if (launch_result->manifest_service_ipc_channel_handle.is_valid()) {
|
| std::unique_ptr<ManifestServiceChannel> manifest_service_channel(
|
| new ManifestServiceChannel(
|
| - launch_result.manifest_service_ipc_channel_handle,
|
| + launch_result->manifest_service_ipc_channel_handle.release(),
|
| base::Bind(&PostPPCompletionCallback, callback),
|
| std::move(manifest_service_proxy),
|
| content::RenderThread::Get()->GetShutdownEvent()));
|
| @@ -639,18 +627,12 @@ PP_FileHandle GetReadonlyPnaclFd(const char* url,
|
| uint64_t* nonce_lo,
|
| uint64_t* nonce_hi) {
|
| std::string filename = PnaclComponentURLToFilename(url);
|
| - IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit();
|
| - IPC::Sender* sender = content::RenderThread::Get();
|
| - DCHECK(sender);
|
| - if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD(
|
| - std::string(filename), is_executable,
|
| - &out_fd, nonce_lo, nonce_hi))) {
|
| + base::File file;
|
| + if (!g_nacl_host_connection.Get().host()->GetReadonlyPnaclFd(
|
| + filename, is_executable, &file, nonce_lo, nonce_hi)) {
|
| return PP_kInvalidFileHandle;
|
| }
|
| - if (out_fd == IPC::InvalidPlatformFileForTransit()) {
|
| - return PP_kInvalidFileHandle;
|
| - }
|
| - return IPC::PlatformFileForTransitToPlatformFile(out_fd);
|
| + return file.TakePlatformFile();
|
| }
|
|
|
| } // namespace
|
| @@ -666,28 +648,20 @@ void PPBNaClPrivate::GetReadExecPnaclFd(const char* url,
|
|
|
| // static
|
| PP_FileHandle PPBNaClPrivate::CreateTemporaryFile(PP_Instance instance) {
|
| - IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit();
|
| - IPC::Sender* sender = content::RenderThread::Get();
|
| - DCHECK(sender);
|
| - if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile(
|
| - &transit_fd))) {
|
| + base::File file;
|
| + if (!g_nacl_host_connection.Get().host()->NaClCreateTemporaryFile(&file)) {
|
| return PP_kInvalidFileHandle;
|
| }
|
| -
|
| - if (transit_fd == IPC::InvalidPlatformFileForTransit()) {
|
| - return PP_kInvalidFileHandle;
|
| - }
|
| -
|
| - return IPC::PlatformFileForTransitToPlatformFile(transit_fd);
|
| + return file.TakePlatformFile();
|
| }
|
|
|
| // static
|
| int32_t PPBNaClPrivate::GetNumberOfProcessors() {
|
| - IPC::Sender* sender = content::RenderThread::Get();
|
| - DCHECK(sender);
|
| int32_t num_processors = 1;
|
| - return sender->Send(new NaClHostMsg_NaClGetNumProcessors(&num_processors)) ?
|
| - num_processors : 1;
|
| + return g_nacl_host_connection.Get().host()->NaClGetNumProcessors(
|
| + &num_processors)
|
| + ? num_processors
|
| + : 1;
|
| }
|
|
|
| namespace {
|
| @@ -784,7 +758,7 @@ void PPBNaClPrivate::ReportTranslationFinished(PP_Instance instance,
|
|
|
| // If the resource host isn't initialized, don't try to do that here.
|
| // Just return because something is already very wrong.
|
| - if (g_pnacl_resource_host.Get().get() == NULL)
|
| + if (g_pnacl_resource_host.Get() == NULL)
|
| return;
|
| g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success);
|
|
|
| @@ -816,26 +790,16 @@ PP_FileHandle OpenNaClExecutable(PP_Instance instance,
|
| if (!CanOpenViaFastPath(plugin_instance, gurl))
|
| return PP_kInvalidFileHandle;
|
|
|
| - IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit();
|
| - IPC::Sender* sender = content::RenderThread::Get();
|
| - DCHECK(sender);
|
| *nonce_lo = 0;
|
| *nonce_hi = 0;
|
| base::FilePath file_path;
|
| - if (!sender->Send(
|
| - new NaClHostMsg_OpenNaClExecutable(GetRoutingID(instance),
|
| - GURL(file_url),
|
| - !load_manager->nonsfi(),
|
| - &out_fd,
|
| - nonce_lo,
|
| - nonce_hi))) {
|
| + base::File file;
|
| + if (!g_nacl_host_connection.Get().host()->OpenNaClExecutable(
|
| + GetRoutingID(instance), GURL(file_url), !load_manager->nonsfi(),
|
| + &file, nonce_lo, nonce_hi)) {
|
| return PP_kInvalidFileHandle;
|
| }
|
| -
|
| - if (out_fd == IPC::InvalidPlatformFileForTransit())
|
| - return PP_kInvalidFileHandle;
|
| -
|
| - return IPC::PlatformFileForTransitToPlatformFile(out_fd);
|
| + return file.TakePlatformFile();
|
| }
|
|
|
| } // namespace
|
| @@ -904,8 +868,8 @@ PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) {
|
| DCHECK(sender);
|
| bool should_debug = false;
|
| return PP_FromBool(
|
| - sender->Send(new NaClHostMsg_NaClDebugEnabledForURL(GURL(alleged_nmf_url),
|
| - &should_debug)) &&
|
| + g_nacl_host_connection.Get().host()->NaClDebugEnabledForURL(
|
| + GURL(alleged_nmf_url), &should_debug) &&
|
| should_debug);
|
| }
|
|
|
|
|