This source file includes following definitions.
- weak_ptr_factory_
- OnChannelClosing
- OnMessageReceived
- GetHostResolver
- OnLaunchNaCl
- OnGetReadonlyPnaclFd
- SyncReturnTemporaryFile
- OnNaClCreateTemporaryFile
- AsyncReturnTemporaryFile
- OnNaClGetNumProcessors
- OnGetNexeFd
- OnTranslationFinished
- OnMissingArchError
- OnOpenNaClExecutable
- OnNaClDebugEnabledForURL
#include "components/nacl/browser/nacl_host_message_filter.h"
#include "base/sys_info.h"
#include "components/nacl/browser/nacl_browser.h"
#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 "ipc/ipc_platform_file.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
namespace nacl {
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),
off_the_record_(is_off_the_record),
profile_directory_(profile_directory),
request_context_(request_context),
weak_ptr_factory_(this) {
}
NaClHostMessageFilter::~NaClHostMessageFilter() {
}
void NaClHostMessageFilter::OnChannelClosing() {
pnacl::PnaclHost::GetInstance()->RendererClosing(render_process_id_);
}
bool NaClHostMessageFilter::OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(NaClHostMessageFilter, message, *message_was_ok)
#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 NaClHostMessageFilter::OnLaunchNaCl(
const nacl::NaClLaunchParams& launch_params,
IPC::Message* reply_msg) {
NaClProcessHost* host = new NaClProcessHost(
GURL(launch_params.manifest_url),
launch_params.render_view_id,
launch_params.permission_bits,
launch_params.uses_irt,
launch_params.uses_nonsfi_mode,
launch_params.enable_dyncode_syscalls,
launch_params.enable_exception_handling,
launch_params.enable_crash_throttling,
off_the_record_,
profile_directory_);
GURL manifest_url(launch_params.manifest_url);
base::FilePath manifest_path;
nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath(
manifest_url, false , &manifest_path);
host->Launch(this, reply_msg, manifest_path);
}
void NaClHostMessageFilter::OnGetReadonlyPnaclFd(
const std::string& filename, IPC::Message* reply_msg) {
nacl_file_host::GetReadonlyPnaclFd(this, filename, reply_msg);
pnacl::PnaclHost::GetInstance()->Init();
}
void NaClHostMessageFilter::SyncReturnTemporaryFile(
IPC::Message* reply_msg,
base::File file) {
if (file.IsValid()) {
NaClHostMsg_NaClCreateTemporaryFile::WriteReplyParams(
reply_msg,
IPC::TakeFileHandleForProcess(file.Pass(), PeerHandle()));
} 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,
base::PlatformFile fd,
bool is_hit) {
Send(new NaClViewMsg_NexeTempFileReply(
pp_instance,
is_hit,
IPC::GetFileHandleForProcess(fd, PeerHandle(), false)));
}
void NaClHostMessageFilter::OnNaClGetNumProcessors(int* num_processors) {
*num_processors = base::SysInfo::NumberOfProcessors();
}
void NaClHostMessageFilter::OnGetNexeFd(
int render_view_id,
int pp_instance,
const nacl::PnaclCacheInfo& cache_info) {
if (!cache_info.pexe_url.is_valid()) {
LOG(ERROR) << "Bad URL received from GetNexeFd: " <<
cache_info.pexe_url.possibly_invalid_spec();
BadMessageReceived();
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));
}
void NaClHostMessageFilter::OnTranslationFinished(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 NaClHostMessageFilter::OnOpenNaClExecutable(int render_view_id,
const GURL& file_url,
IPC::Message* reply_msg) {
nacl_file_host::OpenNaClExecutable(this, render_view_id, file_url,
reply_msg);
}
void NaClHostMessageFilter::OnNaClDebugEnabledForURL(const GURL& nmf_url,
bool* should_debug) {
*should_debug =
nacl::NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(nmf_url);
}
}