OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" |
| 10 #include "base/metrics/histogram.h" |
| 11 #include "chrome/browser/extensions/extension_info_map.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/nacl_host/nacl_file_host.h" |
| 14 #include "chrome/browser/nacl_host/nacl_infobar.h" |
| 15 #include "chrome/browser/nacl_host/nacl_process_host.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/nacl_host_messages.h" |
| 19 #include "googleurl/src/gurl.h" |
| 20 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_context_getter.h" |
| 22 |
| 23 NaClHostMessageFilter::NaClHostMessageFilter( |
| 24 int render_process_id, |
| 25 Profile* profile, |
| 26 net::URLRequestContextGetter* request_context) |
| 27 : render_process_id_(render_process_id), |
| 28 profile_(profile), |
| 29 off_the_record_(profile_->IsOffTheRecord()), |
| 30 request_context_(request_context), |
| 31 extension_info_map_( |
| 32 extensions::ExtensionSystem::Get(profile)->info_map()), |
| 33 weak_ptr_factory_(this) { |
| 34 } |
| 35 |
| 36 NaClHostMessageFilter::~NaClHostMessageFilter() { |
| 37 } |
| 38 |
| 39 bool NaClHostMessageFilter::OnMessageReceived(const IPC::Message& message, |
| 40 bool* message_was_ok) { |
| 41 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP_EX(NaClHostMessageFilter, message, *message_was_ok) |
| 43 #if !defined(DISABLE_NACL) |
| 44 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_LaunchNaCl, OnLaunchNaCl) |
| 45 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_GetReadonlyPnaclFD, |
| 46 OnGetReadonlyPnaclFd) |
| 47 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_NaClCreateTemporaryFile, |
| 48 OnNaClCreateTemporaryFile) |
| 49 IPC_MESSAGE_HANDLER(NaClHostMsg_NaClErrorStatus, OnNaClErrorStatus) |
| 50 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_OpenNaClExecutable, |
| 51 OnOpenNaClExecutable) |
| 52 #endif |
| 53 IPC_MESSAGE_UNHANDLED(handled = false) |
| 54 IPC_END_MESSAGE_MAP() |
| 55 |
| 56 return handled; |
| 57 } |
| 58 |
| 59 net::HostResolver* NaClHostMessageFilter::GetHostResolver() { |
| 60 return request_context_->GetURLRequestContext()->host_resolver(); |
| 61 } |
| 62 |
| 63 #if !defined(DISABLE_NACL) |
| 64 void NaClHostMessageFilter::OnLaunchNaCl( |
| 65 const nacl::NaClLaunchParams& launch_params, |
| 66 IPC::Message* reply_msg) { |
| 67 NaClProcessHost* host = new NaClProcessHost( |
| 68 GURL(launch_params.manifest_url), |
| 69 launch_params.render_view_id, |
| 70 launch_params.permission_bits, |
| 71 launch_params.uses_irt, |
| 72 launch_params.enable_dyncode_syscalls, |
| 73 launch_params.enable_exception_handling, |
| 74 off_the_record_, |
| 75 profile_->GetPath()); |
| 76 host->Launch(this, reply_msg, extension_info_map_); |
| 77 } |
| 78 |
| 79 void NaClHostMessageFilter::OnGetReadonlyPnaclFd( |
| 80 const std::string& filename, IPC::Message* reply_msg) { |
| 81 // This posts a task to another thread, but the renderer will |
| 82 // block until the reply is sent. |
| 83 nacl_file_host::GetReadonlyPnaclFd(this, filename, reply_msg); |
| 84 } |
| 85 |
| 86 void NaClHostMessageFilter::OnNaClCreateTemporaryFile( |
| 87 IPC::Message* reply_msg) { |
| 88 nacl_file_host::CreateTemporaryFile(this, reply_msg); |
| 89 } |
| 90 |
| 91 void NaClHostMessageFilter::OnNaClErrorStatus(int render_view_id, |
| 92 int error_id) { |
| 93 // Currently there is only one kind of error status, for which |
| 94 // we want to show the user an infobar. |
| 95 ShowNaClInfobar(render_process_id_, render_view_id, error_id); |
| 96 } |
| 97 |
| 98 void NaClHostMessageFilter::OnOpenNaClExecutable(int render_view_id, |
| 99 const GURL& file_url, |
| 100 IPC::Message* reply_msg) { |
| 101 nacl_file_host::OpenNaClExecutable(this, extension_info_map_, |
| 102 render_view_id, file_url, reply_msg); |
| 103 } |
| 104 #endif |
OLD | NEW |