Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: components/nacl/browser/nacl_host_impl.cc

Issue 2514323004: Convert NaCl renderer-browser messages to mojo. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/nacl/browser/nacl_host_impl.h ('k') | components/nacl/browser/nacl_host_message_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/nacl/browser/nacl_host_impl.cc
diff --git a/components/nacl/browser/nacl_host_message_filter.cc b/components/nacl/browser/nacl_host_impl.cc
similarity index 41%
rename from components/nacl/browser/nacl_host_message_filter.cc
rename to components/nacl/browser/nacl_host_impl.cc
index c8d0ebfe06d350059b22169bdf4dbcfc9dc19cb3..7ee8e51eea87d694d4363a3cbc99f8982ec24fea 100644
--- a/components/nacl/browser/nacl_host_message_filter.cc
+++ b/components/nacl/browser/nacl_host_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/nacl/browser/nacl_host_message_filter.h"
+#include "components/nacl/browser/nacl_host_impl.h"
#include <stddef.h>
#include <stdint.h>
@@ -15,14 +15,12 @@
#include "components/nacl/browser/nacl_file_host.h"
#include "components/nacl/browser/nacl_process_host.h"
#include "components/nacl/browser/pnacl_host.h"
-#include "components/nacl/common/nacl_host_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_platform_file.h"
-#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_context_getter.h"
+#include "mojo/public/cpp/system/platform_handle.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "url/gurl.h"
@@ -65,162 +63,130 @@ ppapi::PpapiPermissions GetPpapiPermissions(uint32_t permission_bits,
content::WebContents::FromRenderViewHost(view_host);
if (contents)
document_url = contents->GetLastCommittedURL();
- return GetNaClPermissions(permission_bits,
- host->GetBrowserContext(),
+ return GetNaClPermissions(permission_bits, host->GetBrowserContext(),
document_url);
}
} // namespace
-NaClHostMessageFilter::NaClHostMessageFilter(
- int render_process_id,
- bool is_off_the_record,
- const base::FilePath& profile_directory,
- net::URLRequestContextGetter* request_context)
- : BrowserMessageFilter(NaClHostMsgStart),
- render_process_id_(render_process_id),
+NaClHostImpl::NaClHostImpl(int render_process_id,
+ bool is_off_the_record,
+ const base::FilePath& profile_directory,
+ mojom::NaClHostRequest request)
+ : render_process_id_(render_process_id),
off_the_record_(is_off_the_record),
profile_directory_(profile_directory),
- request_context_(request_context),
+ self_(this),
+ binding_(this, std::move(request)),
weak_ptr_factory_(this) {
+ binding_.set_connection_error_handler(base::Bind(
+ &NaClHostImpl::OnConnectionError, weak_ptr_factory_.GetWeakPtr()));
}
-NaClHostMessageFilter::~NaClHostMessageFilter() {
-}
+NaClHostImpl::~NaClHostImpl() = default;
-void NaClHostMessageFilter::OnChannelClosing() {
- pnacl::PnaclHost::GetInstance()->RendererClosing(render_process_id_);
+// static
+void NaClHostImpl::Create(int render_process_id,
+ bool is_off_the_record,
+ const base::FilePath& profile_directory,
+ mojom::NaClHostRequest request) {
+ new NaClHostImpl(render_process_id, is_off_the_record, profile_directory,
+ std::move(request));
}
-bool NaClHostMessageFilter::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(NaClHostMessageFilter, message)
-#if !defined(DISABLE_NACL)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_LaunchNaCl, OnLaunchNaCl)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_GetReadonlyPnaclFD,
- OnGetReadonlyPnaclFd)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_NaClCreateTemporaryFile,
- OnNaClCreateTemporaryFile)
- IPC_MESSAGE_HANDLER(NaClHostMsg_NexeTempFileRequest,
- OnGetNexeFd)
- IPC_MESSAGE_HANDLER(NaClHostMsg_ReportTranslationFinished,
- OnTranslationFinished)
- IPC_MESSAGE_HANDLER(NaClHostMsg_MissingArchError,
- OnMissingArchError)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_OpenNaClExecutable,
- OnOpenNaClExecutable)
- IPC_MESSAGE_HANDLER(NaClHostMsg_NaClGetNumProcessors,
- OnNaClGetNumProcessors)
- IPC_MESSAGE_HANDLER(NaClHostMsg_NaClDebugEnabledForURL,
- OnNaClDebugEnabledForURL)
-#endif
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
-
- return handled;
-}
-
-net::HostResolver* NaClHostMessageFilter::GetHostResolver() {
- return request_context_->GetURLRequestContext()->host_resolver();
+void NaClHostImpl::OnConnectionError() {
+ pnacl::PnaclHost::GetInstance()->RendererClosing(render_process_id_);
+ self_ = nullptr;
}
-void NaClHostMessageFilter::OnLaunchNaCl(
- const nacl::NaClLaunchParams& launch_params,
- IPC::Message* reply_msg) {
+void NaClHostImpl::LaunchNaCl(mojom::NaClLaunchParamsPtr launch_params,
+ const LaunchNaClCallback& callback) {
// If we're running llc or ld for the PNaCl translator, we don't need to look
// up permissions, and we don't have the right browser state to look up some
// of the whitelisting parameters anyway.
- if (launch_params.process_type == kPNaClTranslatorProcessType) {
- uint32_t perms = launch_params.permission_bits & ppapi::PERMISSION_DEV;
- LaunchNaClContinuationOnIOThread(
- launch_params,
- reply_msg,
- std::vector<NaClResourcePrefetchResult>(),
- ppapi::PpapiPermissions(perms));
+ if (launch_params->process_type == kPNaClTranslatorProcessType) {
+ uint32_t perms = launch_params->permission_bits & ppapi::PERMISSION_DEV;
+ LaunchNaClContinuationOnIOThread(std::move(launch_params), callback,
+ std::vector<NaClResourcePrefetchResult>(),
+ ppapi::PpapiPermissions(perms));
return;
}
content::BrowserThread::PostTask(
- content::BrowserThread::UI,
- FROM_HERE,
- base::Bind(&NaClHostMessageFilter::LaunchNaClContinuation,
- this,
- launch_params,
- reply_msg));
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&NaClHostImpl::LaunchNaClContinuation, this,
+ base::Passed(&launch_params), callback));
}
-void NaClHostMessageFilter::LaunchNaClContinuation(
- const nacl::NaClLaunchParams& launch_params,
- IPC::Message* reply_msg) {
+void NaClHostImpl::LaunchNaClContinuation(
+ mojom::NaClLaunchParamsPtr launch_params,
+ const LaunchNaClCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ppapi::PpapiPermissions permissions =
- GetPpapiPermissions(launch_params.permission_bits,
- render_process_id_,
- launch_params.render_view_id);
+ GetPpapiPermissions(launch_params->permission_bits, render_process_id_,
+ launch_params->render_view_id);
content::RenderViewHost* rvh = content::RenderViewHost::FromID(
- render_process_id(), launch_params.render_view_id);
+ render_process_id_, launch_params->render_view_id);
if (!rvh) {
+ // Mojo requires that the callback be called in all cases.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, base::Passed(nacl::mojom::NaClLaunchResultPtr()),
+ ""));
bad_message::ReceivedBadMessage(
- this, bad_message::NHMF_LAUNCH_CONTINUATION_BAD_ROUTING_ID);
- delete reply_msg;
+ render_process_id_,
+ bad_message::NHMF_LAUNCH_CONTINUATION_BAD_ROUTING_ID);
return;
}
- nacl::NaClLaunchParams safe_launch_params(launch_params);
- safe_launch_params.resource_prefetch_request_list.clear();
-
- // TODO(yusukes): Fix NaClProcessHost::~NaClProcessHost() and remove the
- // ifdef.
+// TODO(yusukes): Fix NaClProcessHost::~NaClProcessHost() and remove the
+// ifdef.
#if !defined(OS_WIN)
- const std::vector<NaClResourcePrefetchRequest>& original_request_list =
- launch_params.resource_prefetch_request_list;
+ std::vector<NaClResourcePrefetchRequest> original_request_list =
+ std::move(launch_params->resource_prefetch_request_list);
+ launch_params->resource_prefetch_request_list.clear();
content::SiteInstance* site_instance = rvh->GetSiteInstance();
for (size_t i = 0; i < original_request_list.size(); ++i) {
GURL gurl(original_request_list[i].resource_url);
// Important security check: Do the same check as OpenNaClExecutable()
// in nacl_file_host.cc.
if (!content::SiteInstance::IsSameWebSite(
- site_instance->GetBrowserContext(),
- site_instance->GetSiteURL(),
+ site_instance->GetBrowserContext(), site_instance->GetSiteURL(),
gurl)) {
continue;
}
- safe_launch_params.resource_prefetch_request_list.push_back(
+ launch_params->resource_prefetch_request_list.push_back(
original_request_list[i]);
}
#endif
// Process a list of resource file URLs in
- // |launch_params.resource_files_to_prefetch|.
+ // |launch_params->resource_files_to_prefetch|.
content::BrowserThread::PostBlockingPoolTask(
FROM_HERE,
- base::Bind(&NaClHostMessageFilter::BatchOpenResourceFiles,
- this,
- safe_launch_params,
- reply_msg,
- permissions));
+ base::Bind(&NaClHostImpl::BatchOpenResourceFiles, this,
+ base::Passed(&launch_params), callback, permissions));
}
-void NaClHostMessageFilter::BatchOpenResourceFiles(
- const nacl::NaClLaunchParams& launch_params,
- IPC::Message* reply_msg,
+void NaClHostImpl::BatchOpenResourceFiles(
+ mojom::NaClLaunchParamsPtr launch_params,
+ const LaunchNaClCallback& callback,
ppapi::PpapiPermissions permissions) {
std::vector<NaClResourcePrefetchResult> prefetched_resource_files;
const std::vector<NaClResourcePrefetchRequest>& request_list =
- launch_params.resource_prefetch_request_list;
+ launch_params->resource_prefetch_request_list;
for (size_t i = 0; i < request_list.size(); ++i) {
GURL gurl(request_list[i].resource_url);
base::FilePath file_path_metadata;
if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath(
gurl,
true, // use_blocking_api
- profile_directory_,
- &file_path_metadata)) {
+ profile_directory_, &file_path_metadata)) {
continue;
}
- base::File file = nacl::OpenNaClReadExecImpl(
- file_path_metadata, true /* is_executable */);
+ base::File file = nacl::OpenNaClReadExecImpl(file_path_metadata,
+ true /* is_executable */);
if (!file.IsValid())
continue;
@@ -233,155 +199,108 @@ void NaClHostMessageFilter::BatchOpenResourceFiles(
}
content::BrowserThread::PostTask(
- content::BrowserThread::IO,
- FROM_HERE,
- base::Bind(&NaClHostMessageFilter::LaunchNaClContinuationOnIOThread,
- this,
- launch_params,
- reply_msg,
- prefetched_resource_files,
- permissions));
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&NaClHostImpl::LaunchNaClContinuationOnIOThread, this,
+ base::Passed(&launch_params), callback,
+ prefetched_resource_files, permissions));
}
-void NaClHostMessageFilter::LaunchNaClContinuationOnIOThread(
- const nacl::NaClLaunchParams& launch_params,
- IPC::Message* reply_msg,
+void NaClHostImpl::LaunchNaClContinuationOnIOThread(
+ mojom::NaClLaunchParamsPtr launch_params,
+ const LaunchNaClCallback& callback,
const std::vector<NaClResourcePrefetchResult>& prefetched_resource_files,
ppapi::PpapiPermissions permissions) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
NaClFileToken nexe_token = {
- launch_params.nexe_token_lo, // lo
- launch_params.nexe_token_hi // hi
+ launch_params->nexe_token_lo, // lo
+ launch_params->nexe_token_hi // hi
};
- base::PlatformFile nexe_file =
- IPC::PlatformFileForTransitToPlatformFile(launch_params.nexe_file);
-
NaClProcessHost* host = new NaClProcessHost(
- GURL(launch_params.manifest_url),
- base::File(nexe_file),
- nexe_token,
- prefetched_resource_files,
- permissions,
- launch_params.render_view_id,
- launch_params.permission_bits,
- launch_params.uses_nonsfi_mode,
- off_the_record_,
- launch_params.process_type,
- profile_directory_);
- GURL manifest_url(launch_params.manifest_url);
+ launch_params->manifest_url, std::move(launch_params->nexe_file),
+ nexe_token, prefetched_resource_files, permissions, render_process_id_,
+ launch_params->render_view_id, launch_params->permission_bits,
+ launch_params->uses_nonsfi_mode, off_the_record_,
+ launch_params->process_type, profile_directory_);
base::FilePath manifest_path;
// We're calling MapUrlToLocalFilePath with the non-blocking API
// because we're running in the I/O thread. Ideally we'd use the other path,
// which would cover more cases.
nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath(
- manifest_url,
- false /* use_blocking_api */,
- profile_directory_,
- &manifest_path);
- host->Launch(this, reply_msg, manifest_path);
+ launch_params->manifest_url, false /* use_blocking_api */,
+ profile_directory_, &manifest_path);
+ host->Launch(manifest_path, callback);
}
-void NaClHostMessageFilter::OnGetReadonlyPnaclFd(
- const std::string& filename, bool is_executable, IPC::Message* reply_msg) {
+void NaClHostImpl::GetReadonlyPnaclFd(
+ const std::string& filename,
+ bool is_executable,
+ const GetReadonlyPnaclFdCallback& callback) {
// This posts a task to another thread, but the renderer will
// block until the reply is sent.
- nacl_file_host::GetReadonlyPnaclFd(this, filename, is_executable, reply_msg);
+ nacl_file_host::GetReadonlyPnaclFd(filename, is_executable, callback);
// This is the first message we receive from the renderer once it knows we
// want to use PNaCl, so start the translation cache initialization here.
pnacl::PnaclHost::GetInstance()->Init();
}
-// Return the temporary file via a reply to the
-// NaClHostMsg_NaClCreateTemporaryFile sync message.
-void NaClHostMessageFilter::SyncReturnTemporaryFile(
- IPC::Message* reply_msg,
- base::File file) {
- if (file.IsValid()) {
- NaClHostMsg_NaClCreateTemporaryFile::WriteReplyParams(
- reply_msg, IPC::TakePlatformFileForTransit(std::move(file)));
- } else {
- reply_msg->set_reply_error();
- }
- Send(reply_msg);
-}
-
-void NaClHostMessageFilter::OnNaClCreateTemporaryFile(
- IPC::Message* reply_msg) {
- pnacl::PnaclHost::GetInstance()->CreateTemporaryFile(
- base::Bind(&NaClHostMessageFilter::SyncReturnTemporaryFile,
- this,
- reply_msg));
-}
-
-void NaClHostMessageFilter::AsyncReturnTemporaryFile(
- int pp_instance,
- const base::File& file,
- bool is_hit) {
- IPC::PlatformFileForTransit fd = IPC::InvalidPlatformFileForTransit();
- if (file.IsValid()) {
- // Don't close our copy of the handle, because PnaclHost will use it
- // when the translation finishes.
- fd = IPC::GetPlatformFileForTransit(file.GetPlatformFile(), false);
- }
- Send(new NaClViewMsg_NexeTempFileReply(pp_instance, is_hit, fd));
+void NaClHostImpl::NaClCreateTemporaryFile(
+ const NaClCreateTemporaryFileCallback& callback) {
+ pnacl::PnaclHost::GetInstance()->CreateTemporaryFile(callback);
}
-void NaClHostMessageFilter::OnNaClGetNumProcessors(int* num_processors) {
- *num_processors = base::SysInfo::NumberOfProcessors();
+void NaClHostImpl::NaClGetNumProcessors(
+ const NaClGetNumProcessorsCallback& callback) {
+ callback.Run(base::SysInfo::NumberOfProcessors());
}
-void NaClHostMessageFilter::OnGetNexeFd(
+void NaClHostImpl::NexeTempFileRequest(
int render_view_id,
int pp_instance,
- const nacl::PnaclCacheInfo& cache_info) {
+ const PnaclCacheInfo& cache_info,
+ const NexeTempFileRequestCallback& callback) {
if (!cache_info.pexe_url.is_valid()) {
- LOG(ERROR) << "Bad URL received from GetNexeFd: " <<
- cache_info.pexe_url.possibly_invalid_spec();
- bad_message::ReceivedBadMessage(this,
+ LOG(ERROR) << "Bad URL received from GetNexeFd: "
+ << cache_info.pexe_url.possibly_invalid_spec();
+ // Mojo requires that the callback be called in all cases.
+ callback.Run(pp_instance, base::File(), false);
+ bad_message::ReceivedBadMessage(render_process_id_,
bad_message::NHMF_GET_NEXE_FD_BAD_URL);
return;
}
pnacl::PnaclHost::GetInstance()->GetNexeFd(
- render_process_id_,
- render_view_id,
- pp_instance,
- off_the_record_,
- cache_info,
- base::Bind(&NaClHostMessageFilter::AsyncReturnTemporaryFile,
- this,
- pp_instance));
+ render_process_id_, render_view_id, pp_instance, off_the_record_,
+ cache_info, base::Bind(callback, pp_instance));
}
-void NaClHostMessageFilter::OnTranslationFinished(int instance, bool success) {
- pnacl::PnaclHost::GetInstance()->TranslationFinished(
- render_process_id_, instance, success);
+void NaClHostImpl::ReportTranslationFinished(int instance, bool success) {
+ pnacl::PnaclHost::GetInstance()->TranslationFinished(render_process_id_,
+ instance, success);
}
-void NaClHostMessageFilter::OnMissingArchError(int render_view_id) {
- nacl::NaClBrowser::GetDelegate()->
- ShowMissingArchInfobar(render_process_id_, render_view_id);
+void NaClHostImpl::MissingArchError(int render_view_id) {
+ nacl::NaClBrowser::GetDelegate()->ShowMissingArchInfobar(render_process_id_,
+ render_view_id);
}
-void NaClHostMessageFilter::OnOpenNaClExecutable(
+void NaClHostImpl::OpenNaClExecutable(
int render_view_id,
const GURL& file_url,
bool enable_validation_caching,
- IPC::Message* reply_msg) {
- nacl_file_host::OpenNaClExecutable(this,
- render_view_id,
- file_url,
- enable_validation_caching,
- reply_msg);
+ const OpenNaClExecutableCallback& callback) {
+ nacl_file_host::OpenNaClExecutable(
+ render_view_id, file_url, enable_validation_caching, render_process_id_,
+ profile_directory_, base::ThreadTaskRunnerHandle::Get(), callback);
}
-void NaClHostMessageFilter::OnNaClDebugEnabledForURL(const GURL& nmf_url,
- bool* should_debug) {
- *should_debug =
- nacl::NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(nmf_url);
+void NaClHostImpl::NaClDebugEnabledForURL(
+ const GURL& nmf_url,
+ const NaClDebugEnabledForURLCallback& callback) {
+ callback.Run(
+ nacl::NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(nmf_url));
}
} // namespace nacl
« no previous file with comments | « components/nacl/browser/nacl_host_impl.h ('k') | components/nacl/browser/nacl_host_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698