OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/browser/nacl_host_message_filter.h" | 5 #include "components/nacl/browser/nacl_host_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "components/nacl/browser/bad_message.h" | 13 #include "components/nacl/browser/bad_message.h" |
14 #include "components/nacl/browser/nacl_browser.h" | 14 #include "components/nacl/browser/nacl_browser.h" |
15 #include "components/nacl/browser/nacl_file_host.h" | 15 #include "components/nacl/browser/nacl_file_host.h" |
16 #include "components/nacl/browser/nacl_process_host.h" | 16 #include "components/nacl/browser/nacl_process_host.h" |
17 #include "components/nacl/browser/pnacl_host.h" | 17 #include "components/nacl/browser/pnacl_host.h" |
18 #include "components/nacl/common/nacl_host_messages.h" | |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/plugin_service.h" | 19 #include "content/public/browser/plugin_service.h" |
21 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
23 #include "ipc/ipc_platform_file.h" | 22 #include "ipc/ipc_platform_file.h" |
24 #include "net/url_request/url_request_context.h" | 23 #include "mojo/public/cpp/system/platform_handle.h" |
25 #include "net/url_request/url_request_context_getter.h" | |
26 #include "ppapi/shared_impl/ppapi_permissions.h" | 24 #include "ppapi/shared_impl/ppapi_permissions.h" |
27 #include "url/gurl.h" | 25 #include "url/gurl.h" |
28 | 26 |
29 namespace nacl { | 27 namespace nacl { |
30 | 28 |
31 namespace { | 29 namespace { |
32 | 30 |
33 // The maximum number of resource file handles the browser process accepts. Use | 31 // The maximum number of resource file handles the browser process accepts. Use |
34 // 200 because ARC's nmf has ~128 resource files as of May 2015. This prevents | 32 // 200 because ARC's nmf has ~128 resource files as of May 2015. This prevents |
35 // untrusted code filling the FD/handle table. | 33 // untrusted code filling the FD/handle table. |
(...skipping 22 matching lines...) Expand all Loading... |
58 content::RenderProcessHost::FromID(render_process_id); | 56 content::RenderProcessHost::FromID(render_process_id); |
59 content::RenderViewHost* view_host = | 57 content::RenderViewHost* view_host = |
60 content::RenderViewHost::FromID(render_process_id, render_view_id); | 58 content::RenderViewHost::FromID(render_process_id, render_view_id); |
61 if (!view_host) | 59 if (!view_host) |
62 return ppapi::PpapiPermissions(); | 60 return ppapi::PpapiPermissions(); |
63 GURL document_url; | 61 GURL document_url; |
64 content::WebContents* contents = | 62 content::WebContents* contents = |
65 content::WebContents::FromRenderViewHost(view_host); | 63 content::WebContents::FromRenderViewHost(view_host); |
66 if (contents) | 64 if (contents) |
67 document_url = contents->GetLastCommittedURL(); | 65 document_url = contents->GetLastCommittedURL(); |
68 return GetNaClPermissions(permission_bits, | 66 return GetNaClPermissions(permission_bits, host->GetBrowserContext(), |
69 host->GetBrowserContext(), | |
70 document_url); | 67 document_url); |
71 } | 68 } |
72 | 69 |
73 } // namespace | 70 } // namespace |
74 | 71 |
75 NaClHostMessageFilter::NaClHostMessageFilter( | 72 NaClHostImpl::NaClHostImpl(int render_process_id, |
76 int render_process_id, | 73 bool is_off_the_record, |
77 bool is_off_the_record, | 74 const base::FilePath& profile_directory, |
78 const base::FilePath& profile_directory, | 75 mojom::NaClHostRequest request) |
79 net::URLRequestContextGetter* request_context) | 76 : render_process_id_(render_process_id), |
80 : BrowserMessageFilter(NaClHostMsgStart), | |
81 render_process_id_(render_process_id), | |
82 off_the_record_(is_off_the_record), | 77 off_the_record_(is_off_the_record), |
83 profile_directory_(profile_directory), | 78 profile_directory_(profile_directory), |
84 request_context_(request_context), | 79 self_(this), |
| 80 binding_(this, std::move(request)), |
85 weak_ptr_factory_(this) { | 81 weak_ptr_factory_(this) { |
| 82 binding_.set_connection_error_handler(base::Bind( |
| 83 &NaClHostImpl::OnConnectionError, weak_ptr_factory_.GetWeakPtr())); |
86 } | 84 } |
87 | 85 |
88 NaClHostMessageFilter::~NaClHostMessageFilter() { | 86 NaClHostImpl::~NaClHostImpl() {} |
| 87 |
| 88 // static |
| 89 void NaClHostImpl::Create(int render_process_id, |
| 90 bool is_off_the_record, |
| 91 const base::FilePath& profile_directory, |
| 92 mojom::NaClHostRequest request) { |
| 93 new NaClHostImpl(render_process_id, is_off_the_record, profile_directory, |
| 94 std::move(request)); |
89 } | 95 } |
90 | 96 |
91 void NaClHostMessageFilter::OnChannelClosing() { | 97 void NaClHostImpl::OnConnectionError() { |
92 pnacl::PnaclHost::GetInstance()->RendererClosing(render_process_id_); | 98 pnacl::PnaclHost::GetInstance()->RendererClosing(render_process_id_); |
| 99 self_ = nullptr; |
93 } | 100 } |
94 | 101 |
95 bool NaClHostMessageFilter::OnMessageReceived(const IPC::Message& message) { | 102 void NaClHostImpl::LaunchNaCl(mojom::NaClLaunchParamsPtr launch_params, |
96 bool handled = true; | 103 const LaunchNaClCallback& callback) { |
97 IPC_BEGIN_MESSAGE_MAP(NaClHostMessageFilter, message) | |
98 #if !defined(DISABLE_NACL) | |
99 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_LaunchNaCl, OnLaunchNaCl) | |
100 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_GetReadonlyPnaclFD, | |
101 OnGetReadonlyPnaclFd) | |
102 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_NaClCreateTemporaryFile, | |
103 OnNaClCreateTemporaryFile) | |
104 IPC_MESSAGE_HANDLER(NaClHostMsg_NexeTempFileRequest, | |
105 OnGetNexeFd) | |
106 IPC_MESSAGE_HANDLER(NaClHostMsg_ReportTranslationFinished, | |
107 OnTranslationFinished) | |
108 IPC_MESSAGE_HANDLER(NaClHostMsg_MissingArchError, | |
109 OnMissingArchError) | |
110 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClHostMsg_OpenNaClExecutable, | |
111 OnOpenNaClExecutable) | |
112 IPC_MESSAGE_HANDLER(NaClHostMsg_NaClGetNumProcessors, | |
113 OnNaClGetNumProcessors) | |
114 IPC_MESSAGE_HANDLER(NaClHostMsg_NaClDebugEnabledForURL, | |
115 OnNaClDebugEnabledForURL) | |
116 #endif | |
117 IPC_MESSAGE_UNHANDLED(handled = false) | |
118 IPC_END_MESSAGE_MAP() | |
119 | |
120 return handled; | |
121 } | |
122 | |
123 net::HostResolver* NaClHostMessageFilter::GetHostResolver() { | |
124 return request_context_->GetURLRequestContext()->host_resolver(); | |
125 } | |
126 | |
127 void NaClHostMessageFilter::OnLaunchNaCl( | |
128 const nacl::NaClLaunchParams& launch_params, | |
129 IPC::Message* reply_msg) { | |
130 // If we're running llc or ld for the PNaCl translator, we don't need to look | 104 // If we're running llc or ld for the PNaCl translator, we don't need to look |
131 // up permissions, and we don't have the right browser state to look up some | 105 // up permissions, and we don't have the right browser state to look up some |
132 // of the whitelisting parameters anyway. | 106 // of the whitelisting parameters anyway. |
133 if (launch_params.process_type == kPNaClTranslatorProcessType) { | 107 if (launch_params->process_type == kPNaClTranslatorProcessType) { |
134 uint32_t perms = launch_params.permission_bits & ppapi::PERMISSION_DEV; | 108 uint32_t perms = launch_params->permission_bits & ppapi::PERMISSION_DEV; |
135 LaunchNaClContinuationOnIOThread( | 109 LaunchNaClContinuationOnIOThread(std::move(launch_params), callback, |
136 launch_params, | 110 std::vector<NaClResourcePrefetchResult>(), |
137 reply_msg, | 111 ppapi::PpapiPermissions(perms)); |
138 std::vector<NaClResourcePrefetchResult>(), | |
139 ppapi::PpapiPermissions(perms)); | |
140 return; | 112 return; |
141 } | 113 } |
142 content::BrowserThread::PostTask( | 114 content::BrowserThread::PostTask( |
143 content::BrowserThread::UI, | 115 content::BrowserThread::UI, FROM_HERE, |
144 FROM_HERE, | 116 base::Bind(&NaClHostImpl::LaunchNaClContinuation, this, |
145 base::Bind(&NaClHostMessageFilter::LaunchNaClContinuation, | 117 base::Passed(&launch_params), callback)); |
146 this, | |
147 launch_params, | |
148 reply_msg)); | |
149 } | 118 } |
150 | 119 |
151 void NaClHostMessageFilter::LaunchNaClContinuation( | 120 void NaClHostImpl::LaunchNaClContinuation( |
152 const nacl::NaClLaunchParams& launch_params, | 121 mojom::NaClLaunchParamsPtr launch_params, |
153 IPC::Message* reply_msg) { | 122 const LaunchNaClCallback& callback) { |
154 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
155 | 124 |
156 ppapi::PpapiPermissions permissions = | 125 ppapi::PpapiPermissions permissions = |
157 GetPpapiPermissions(launch_params.permission_bits, | 126 GetPpapiPermissions(launch_params->permission_bits, render_process_id_, |
158 render_process_id_, | 127 launch_params->render_view_id); |
159 launch_params.render_view_id); | |
160 | 128 |
161 content::RenderViewHost* rvh = content::RenderViewHost::FromID( | 129 content::RenderViewHost* rvh = content::RenderViewHost::FromID( |
162 render_process_id(), launch_params.render_view_id); | 130 render_process_id_, launch_params->render_view_id); |
163 if (!rvh) { | 131 if (!rvh) { |
| 132 // Mojo requires that the callback be called in all cases. |
| 133 content::BrowserThread::PostTask( |
| 134 content::BrowserThread::IO, FROM_HERE, |
| 135 base::Bind(callback, base::Passed(nacl::mojom::NaClLaunchResultPtr()), |
| 136 "")); |
164 bad_message::ReceivedBadMessage( | 137 bad_message::ReceivedBadMessage( |
165 this, bad_message::NHMF_LAUNCH_CONTINUATION_BAD_ROUTING_ID); | 138 render_process_id_, |
166 delete reply_msg; | 139 bad_message::NHMF_LAUNCH_CONTINUATION_BAD_ROUTING_ID); |
167 return; | 140 return; |
168 } | 141 } |
169 | 142 |
170 nacl::NaClLaunchParams safe_launch_params(launch_params); | 143 // TODO(yusukes): Fix NaClProcessHost::~NaClProcessHost() and remove the |
171 safe_launch_params.resource_prefetch_request_list.clear(); | 144 // ifdef. |
172 | |
173 // TODO(yusukes): Fix NaClProcessHost::~NaClProcessHost() and remove the | |
174 // ifdef. | |
175 #if !defined(OS_WIN) | 145 #if !defined(OS_WIN) |
176 const std::vector<NaClResourcePrefetchRequest>& original_request_list = | 146 std::vector<NaClResourcePrefetchRequest> original_request_list = |
177 launch_params.resource_prefetch_request_list; | 147 std::move(launch_params->resource_prefetch_request_list); |
| 148 launch_params->resource_prefetch_request_list.clear(); |
178 content::SiteInstance* site_instance = rvh->GetSiteInstance(); | 149 content::SiteInstance* site_instance = rvh->GetSiteInstance(); |
179 for (size_t i = 0; i < original_request_list.size(); ++i) { | 150 for (size_t i = 0; i < original_request_list.size(); ++i) { |
180 GURL gurl(original_request_list[i].resource_url); | 151 GURL gurl(original_request_list[i].resource_url); |
181 // Important security check: Do the same check as OpenNaClExecutable() | 152 // Important security check: Do the same check as OpenNaClExecutable() |
182 // in nacl_file_host.cc. | 153 // in nacl_file_host.cc. |
183 if (!content::SiteInstance::IsSameWebSite( | 154 if (!content::SiteInstance::IsSameWebSite( |
184 site_instance->GetBrowserContext(), | 155 site_instance->GetBrowserContext(), site_instance->GetSiteURL(), |
185 site_instance->GetSiteURL(), | |
186 gurl)) { | 156 gurl)) { |
187 continue; | 157 continue; |
188 } | 158 } |
189 safe_launch_params.resource_prefetch_request_list.push_back( | 159 launch_params->resource_prefetch_request_list.push_back( |
190 original_request_list[i]); | 160 original_request_list[i]); |
191 } | 161 } |
192 #endif | 162 #endif |
193 | 163 |
194 // Process a list of resource file URLs in | 164 // Process a list of resource file URLs in |
195 // |launch_params.resource_files_to_prefetch|. | 165 // |launch_params->resource_files_to_prefetch|. |
196 content::BrowserThread::PostBlockingPoolTask( | 166 content::BrowserThread::PostBlockingPoolTask( |
197 FROM_HERE, | 167 FROM_HERE, |
198 base::Bind(&NaClHostMessageFilter::BatchOpenResourceFiles, | 168 base::Bind(&NaClHostImpl::BatchOpenResourceFiles, this, |
199 this, | 169 base::Passed(&launch_params), callback, permissions)); |
200 safe_launch_params, | |
201 reply_msg, | |
202 permissions)); | |
203 } | 170 } |
204 | 171 |
205 void NaClHostMessageFilter::BatchOpenResourceFiles( | 172 void NaClHostImpl::BatchOpenResourceFiles( |
206 const nacl::NaClLaunchParams& launch_params, | 173 mojom::NaClLaunchParamsPtr launch_params, |
207 IPC::Message* reply_msg, | 174 const LaunchNaClCallback& callback, |
208 ppapi::PpapiPermissions permissions) { | 175 ppapi::PpapiPermissions permissions) { |
209 std::vector<NaClResourcePrefetchResult> prefetched_resource_files; | 176 std::vector<NaClResourcePrefetchResult> prefetched_resource_files; |
210 const std::vector<NaClResourcePrefetchRequest>& request_list = | 177 const std::vector<NaClResourcePrefetchRequest>& request_list = |
211 launch_params.resource_prefetch_request_list; | 178 launch_params->resource_prefetch_request_list; |
212 for (size_t i = 0; i < request_list.size(); ++i) { | 179 for (size_t i = 0; i < request_list.size(); ++i) { |
213 GURL gurl(request_list[i].resource_url); | 180 GURL gurl(request_list[i].resource_url); |
214 base::FilePath file_path_metadata; | 181 base::FilePath file_path_metadata; |
215 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( | 182 if (!nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
216 gurl, | 183 gurl, |
217 true, // use_blocking_api | 184 true, // use_blocking_api |
218 profile_directory_, | 185 profile_directory_, &file_path_metadata)) { |
219 &file_path_metadata)) { | |
220 continue; | 186 continue; |
221 } | 187 } |
222 base::File file = nacl::OpenNaClReadExecImpl( | 188 base::File file = nacl::OpenNaClReadExecImpl(file_path_metadata, |
223 file_path_metadata, true /* is_executable */); | 189 true /* is_executable */); |
224 if (!file.IsValid()) | 190 if (!file.IsValid()) |
225 continue; | 191 continue; |
226 | 192 |
227 prefetched_resource_files.push_back(NaClResourcePrefetchResult( | 193 prefetched_resource_files.push_back(NaClResourcePrefetchResult( |
228 IPC::TakePlatformFileForTransit(std::move(file)), file_path_metadata, | 194 IPC::TakePlatformFileForTransit(std::move(file)), file_path_metadata, |
229 request_list[i].file_key)); | 195 request_list[i].file_key)); |
230 | 196 |
231 if (prefetched_resource_files.size() >= kMaxPreOpenResourceFiles) | 197 if (prefetched_resource_files.size() >= kMaxPreOpenResourceFiles) |
232 break; | 198 break; |
233 } | 199 } |
234 | 200 |
235 content::BrowserThread::PostTask( | 201 content::BrowserThread::PostTask( |
236 content::BrowserThread::IO, | 202 content::BrowserThread::IO, FROM_HERE, |
237 FROM_HERE, | 203 base::Bind(&NaClHostImpl::LaunchNaClContinuationOnIOThread, this, |
238 base::Bind(&NaClHostMessageFilter::LaunchNaClContinuationOnIOThread, | 204 base::Passed(&launch_params), callback, |
239 this, | 205 prefetched_resource_files, permissions)); |
240 launch_params, | |
241 reply_msg, | |
242 prefetched_resource_files, | |
243 permissions)); | |
244 } | 206 } |
245 | 207 |
246 void NaClHostMessageFilter::LaunchNaClContinuationOnIOThread( | 208 void NaClHostImpl::LaunchNaClContinuationOnIOThread( |
247 const nacl::NaClLaunchParams& launch_params, | 209 mojom::NaClLaunchParamsPtr launch_params, |
248 IPC::Message* reply_msg, | 210 const LaunchNaClCallback& callback, |
249 const std::vector<NaClResourcePrefetchResult>& prefetched_resource_files, | 211 const std::vector<NaClResourcePrefetchResult>& prefetched_resource_files, |
250 ppapi::PpapiPermissions permissions) { | 212 ppapi::PpapiPermissions permissions) { |
251 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 213 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
252 | 214 |
253 NaClFileToken nexe_token = { | 215 NaClFileToken nexe_token = { |
254 launch_params.nexe_token_lo, // lo | 216 launch_params->nexe_token_lo, // lo |
255 launch_params.nexe_token_hi // hi | 217 launch_params->nexe_token_hi // hi |
256 }; | 218 }; |
257 | 219 |
258 base::PlatformFile nexe_file = | |
259 IPC::PlatformFileForTransitToPlatformFile(launch_params.nexe_file); | |
260 | |
261 NaClProcessHost* host = new NaClProcessHost( | 220 NaClProcessHost* host = new NaClProcessHost( |
262 GURL(launch_params.manifest_url), | 221 launch_params->manifest_url, std::move(launch_params->nexe_file), |
263 base::File(nexe_file), | 222 nexe_token, prefetched_resource_files, permissions, render_process_id_, |
264 nexe_token, | 223 launch_params->render_view_id, launch_params->permission_bits, |
265 prefetched_resource_files, | 224 launch_params->uses_nonsfi_mode, off_the_record_, |
266 permissions, | 225 launch_params->process_type, profile_directory_); |
267 launch_params.render_view_id, | |
268 launch_params.permission_bits, | |
269 launch_params.uses_nonsfi_mode, | |
270 off_the_record_, | |
271 launch_params.process_type, | |
272 profile_directory_); | |
273 GURL manifest_url(launch_params.manifest_url); | |
274 base::FilePath manifest_path; | 226 base::FilePath manifest_path; |
275 // We're calling MapUrlToLocalFilePath with the non-blocking API | 227 // We're calling MapUrlToLocalFilePath with the non-blocking API |
276 // because we're running in the I/O thread. Ideally we'd use the other path, | 228 // because we're running in the I/O thread. Ideally we'd use the other path, |
277 // which would cover more cases. | 229 // which would cover more cases. |
278 nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( | 230 nacl::NaClBrowser::GetDelegate()->MapUrlToLocalFilePath( |
279 manifest_url, | 231 launch_params->manifest_url, false /* use_blocking_api */, |
280 false /* use_blocking_api */, | 232 profile_directory_, &manifest_path); |
281 profile_directory_, | 233 host->Launch(manifest_path, callback); |
282 &manifest_path); | |
283 host->Launch(this, reply_msg, manifest_path); | |
284 } | 234 } |
285 | 235 |
286 void NaClHostMessageFilter::OnGetReadonlyPnaclFd( | 236 void NaClHostImpl::GetReadonlyPnaclFd( |
287 const std::string& filename, bool is_executable, IPC::Message* reply_msg) { | 237 const std::string& filename, |
| 238 bool is_executable, |
| 239 const GetReadonlyPnaclFdCallback& callback) { |
288 // This posts a task to another thread, but the renderer will | 240 // This posts a task to another thread, but the renderer will |
289 // block until the reply is sent. | 241 // block until the reply is sent. |
290 nacl_file_host::GetReadonlyPnaclFd(this, filename, is_executable, reply_msg); | 242 nacl_file_host::GetReadonlyPnaclFd(filename, is_executable, callback); |
291 | 243 |
292 // This is the first message we receive from the renderer once it knows we | 244 // This is the first message we receive from the renderer once it knows we |
293 // want to use PNaCl, so start the translation cache initialization here. | 245 // want to use PNaCl, so start the translation cache initialization here. |
294 pnacl::PnaclHost::GetInstance()->Init(); | 246 pnacl::PnaclHost::GetInstance()->Init(); |
295 } | 247 } |
296 | 248 |
297 // Return the temporary file via a reply to the | 249 void NaClHostImpl::NaClCreateTemporaryFile( |
298 // NaClHostMsg_NaClCreateTemporaryFile sync message. | 250 const NaClCreateTemporaryFileCallback& callback) { |
299 void NaClHostMessageFilter::SyncReturnTemporaryFile( | 251 pnacl::PnaclHost::GetInstance()->CreateTemporaryFile(callback); |
300 IPC::Message* reply_msg, | |
301 base::File file) { | |
302 if (file.IsValid()) { | |
303 NaClHostMsg_NaClCreateTemporaryFile::WriteReplyParams( | |
304 reply_msg, IPC::TakePlatformFileForTransit(std::move(file))); | |
305 } else { | |
306 reply_msg->set_reply_error(); | |
307 } | |
308 Send(reply_msg); | |
309 } | 252 } |
310 | 253 |
311 void NaClHostMessageFilter::OnNaClCreateTemporaryFile( | 254 void NaClHostImpl::NaClGetNumProcessors( |
312 IPC::Message* reply_msg) { | 255 const NaClGetNumProcessorsCallback& callback) { |
313 pnacl::PnaclHost::GetInstance()->CreateTemporaryFile( | 256 callback.Run(base::SysInfo::NumberOfProcessors()); |
314 base::Bind(&NaClHostMessageFilter::SyncReturnTemporaryFile, | |
315 this, | |
316 reply_msg)); | |
317 } | 257 } |
318 | 258 |
319 void NaClHostMessageFilter::AsyncReturnTemporaryFile( | 259 void NaClHostImpl::NexeTempFileRequest( |
320 int pp_instance, | |
321 const base::File& file, | |
322 bool is_hit) { | |
323 IPC::PlatformFileForTransit fd = IPC::InvalidPlatformFileForTransit(); | |
324 if (file.IsValid()) { | |
325 // Don't close our copy of the handle, because PnaclHost will use it | |
326 // when the translation finishes. | |
327 fd = IPC::GetPlatformFileForTransit(file.GetPlatformFile(), false); | |
328 } | |
329 Send(new NaClViewMsg_NexeTempFileReply(pp_instance, is_hit, fd)); | |
330 } | |
331 | |
332 void NaClHostMessageFilter::OnNaClGetNumProcessors(int* num_processors) { | |
333 *num_processors = base::SysInfo::NumberOfProcessors(); | |
334 } | |
335 | |
336 void NaClHostMessageFilter::OnGetNexeFd( | |
337 int render_view_id, | 260 int render_view_id, |
338 int pp_instance, | 261 int pp_instance, |
339 const nacl::PnaclCacheInfo& cache_info) { | 262 const PnaclCacheInfo& cache_info, |
| 263 const NexeTempFileRequestCallback& callback) { |
340 if (!cache_info.pexe_url.is_valid()) { | 264 if (!cache_info.pexe_url.is_valid()) { |
341 LOG(ERROR) << "Bad URL received from GetNexeFd: " << | 265 LOG(ERROR) << "Bad URL received from GetNexeFd: " |
342 cache_info.pexe_url.possibly_invalid_spec(); | 266 << cache_info.pexe_url.possibly_invalid_spec(); |
343 bad_message::ReceivedBadMessage(this, | 267 // Mojo requires that the callback be called in all cases. |
| 268 callback.Run(pp_instance, base::File(), false); |
| 269 bad_message::ReceivedBadMessage(render_process_id_, |
344 bad_message::NHMF_GET_NEXE_FD_BAD_URL); | 270 bad_message::NHMF_GET_NEXE_FD_BAD_URL); |
345 return; | 271 return; |
346 } | 272 } |
347 | 273 |
348 pnacl::PnaclHost::GetInstance()->GetNexeFd( | 274 pnacl::PnaclHost::GetInstance()->GetNexeFd( |
349 render_process_id_, | 275 render_process_id_, render_view_id, pp_instance, off_the_record_, |
350 render_view_id, | 276 cache_info, base::Bind(callback, pp_instance)); |
351 pp_instance, | |
352 off_the_record_, | |
353 cache_info, | |
354 base::Bind(&NaClHostMessageFilter::AsyncReturnTemporaryFile, | |
355 this, | |
356 pp_instance)); | |
357 } | 277 } |
358 | 278 |
359 void NaClHostMessageFilter::OnTranslationFinished(int instance, bool success) { | 279 void NaClHostImpl::ReportTranslationFinished(int instance, bool success) { |
360 pnacl::PnaclHost::GetInstance()->TranslationFinished( | 280 pnacl::PnaclHost::GetInstance()->TranslationFinished(render_process_id_, |
361 render_process_id_, instance, success); | 281 instance, success); |
362 } | 282 } |
363 | 283 |
364 void NaClHostMessageFilter::OnMissingArchError(int render_view_id) { | 284 void NaClHostImpl::MissingArchError(int render_view_id) { |
365 nacl::NaClBrowser::GetDelegate()-> | 285 nacl::NaClBrowser::GetDelegate()->ShowMissingArchInfobar(render_process_id_, |
366 ShowMissingArchInfobar(render_process_id_, render_view_id); | 286 render_view_id); |
367 } | 287 } |
368 | 288 |
369 void NaClHostMessageFilter::OnOpenNaClExecutable( | 289 void NaClHostImpl::OpenNaClExecutable( |
370 int render_view_id, | 290 int render_view_id, |
371 const GURL& file_url, | 291 const GURL& file_url, |
372 bool enable_validation_caching, | 292 bool enable_validation_caching, |
373 IPC::Message* reply_msg) { | 293 const OpenNaClExecutableCallback& callback) { |
374 nacl_file_host::OpenNaClExecutable(this, | 294 nacl_file_host::OpenNaClExecutable( |
375 render_view_id, | 295 render_view_id, file_url, enable_validation_caching, render_process_id_, |
376 file_url, | 296 profile_directory_, base::ThreadTaskRunnerHandle::Get(), callback); |
377 enable_validation_caching, | |
378 reply_msg); | |
379 } | 297 } |
380 | 298 |
381 void NaClHostMessageFilter::OnNaClDebugEnabledForURL(const GURL& nmf_url, | 299 void NaClHostImpl::NaClDebugEnabledForURL( |
382 bool* should_debug) { | 300 const GURL& nmf_url, |
383 *should_debug = | 301 const NaClDebugEnabledForURLCallback& callback) { |
384 nacl::NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(nmf_url); | 302 callback.Run( |
| 303 nacl::NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(nmf_url)); |
385 } | 304 } |
386 | 305 |
387 } // namespace nacl | 306 } // namespace nacl |
OLD | NEW |