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

Side by Side Diff: components/nacl/loader/nacl_listener.cc

Issue 728113002: obsolete: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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/loader/nacl_listener.h" 5 #include "components/nacl/loader/nacl_listener.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { 265 bool NaClListener::OnMessageReceived(const IPC::Message& msg) {
266 bool handled = true; 266 bool handled = true;
267 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) 267 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg)
268 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) 268 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart)
269 IPC_MESSAGE_UNHANDLED(handled = false) 269 IPC_MESSAGE_UNHANDLED(handled = false)
270 IPC_END_MESSAGE_MAP() 270 IPC_END_MESSAGE_MAP()
271 return handled; 271 return handled;
272 } 272 }
273 273
274 bool NaClListener::OnOpenResource(
275 const IPC::Message& msg,
276 const std::string& key,
277 NaClIPCAdapter::OpenResourceReplyCallback cb) {
278 DCHECK(!cb.is_null());
279 std::map<std::string, std::pair<
280 IPC::PlatformFileForTransit, base::FilePath> >::iterator it;
281
282 const std::string files_prefix = "files/";
283 if (key.find(files_prefix) == 0)
284 it = resource_files_.find(key.substr(files_prefix.length()));
285 else
286 it = resource_files_.find(key);
287
288 if (it != resource_files_.end()) {
289 IPC::PlatformFileForTransit file = it->second.first;
290 base::FilePath path = it->second.second;
291 resource_files_.erase(it);
292 // A pre-opened resource descriptor is available. Run the reply callback
293 // and return true.
294 cb.Run(msg, file, path);
295 return true;
296 }
297
298 // Return false to let the IPC adapter issue an IPC to the renderer.
299 return false;
300 }
301
274 void NaClListener::OnStart(const nacl::NaClStartParams& params) { 302 void NaClListener::OnStart(const nacl::NaClStartParams& params) {
275 #if defined(OS_LINUX) || defined(OS_MACOSX) 303 #if defined(OS_LINUX) || defined(OS_MACOSX)
276 int urandom_fd = dup(base::GetUrandomFD()); 304 int urandom_fd = dup(base::GetUrandomFD());
277 if (urandom_fd < 0) { 305 if (urandom_fd < 0) {
278 LOG(ERROR) << "Failed to dup() the urandom FD"; 306 LOG(ERROR) << "Failed to dup() the urandom FD";
279 return; 307 return;
280 } 308 }
281 NaClChromeMainSetUrandomFd(urandom_fd); 309 NaClChromeMainSetUrandomFd(urandom_fd);
282 #endif 310 #endif
283 struct NaClApp* nap = NULL; 311 struct NaClApp* nap = NULL;
284 NaClChromeMainInit(); 312 NaClChromeMainInit();
285 313
286 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, 314 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle,
287 false)); 315 false));
288 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 316 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
289 NaClSetFatalErrorCallback(&FatalLogHandler); 317 NaClSetFatalErrorCallback(&FatalLogHandler);
290 318
291 nap = NaClAppCreate(); 319 nap = NaClAppCreate();
292 if (nap == NULL) { 320 if (nap == NULL) {
293 LOG(ERROR) << "NaClAppCreate() failed"; 321 LOG(ERROR) << "NaClAppCreate() failed";
294 return; 322 return;
295 } 323 }
296 324
297 IPC::ChannelHandle browser_handle; 325 IPC::ChannelHandle browser_handle;
298 IPC::ChannelHandle ppapi_renderer_handle; 326 IPC::ChannelHandle ppapi_renderer_handle;
299 IPC::ChannelHandle manifest_service_handle; 327 IPC::ChannelHandle manifest_service_handle;
300 328
329 for (size_t i = 0; i < params.resource_files.size(); ++i) {
330 if (!resource_files_.insert(std::make_pair(
331 params.resource_files[i].file_key,
332 std::make_pair(params.resource_files[i].file,
333 params.resource_files[i].file_path))).second) {
334 DLOG(ERROR) << "Duplicated open_resource key: "
335 << params.resource_files[i].file_key;
336 }
337 }
338
301 if (params.enable_ipc_proxy) { 339 if (params.enable_ipc_proxy) {
302 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 340 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
303 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 341 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
304 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); 342 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
305 343
306 // Create the PPAPI IPC channels between the NaCl IRT and the host 344 // Create the PPAPI IPC channels between the NaCl IRT and the host
307 // (browser/renderer) processes. The IRT uses these channels to 345 // (browser/renderer) processes. The IRT uses these channels to
308 // communicate with the host and to initialize the IPC dispatchers. 346 // communicate with the host and to initialize the IPC dispatchers.
309 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), 347 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
310 nap, NACL_CHROME_DESC_BASE); 348 nap, NACL_CHROME_DESC_BASE);
311 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), 349 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(),
312 nap, NACL_CHROME_DESC_BASE + 1); 350 nap, NACL_CHROME_DESC_BASE + 1);
313 351
314 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter = 352 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter =
315 SetUpIPCAdapter(&manifest_service_handle, 353 SetUpIPCAdapter(&manifest_service_handle,
316 io_thread_.message_loop_proxy(), 354 io_thread_.message_loop_proxy(),
317 nap, 355 nap,
318 NACL_CHROME_DESC_BASE + 2); 356 NACL_CHROME_DESC_BASE + 2);
319 manifest_ipc_adapter->set_resolve_file_token_callback( 357 manifest_ipc_adapter->set_resolve_file_token_callback(
320 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this))); 358 base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)));
359 manifest_ipc_adapter->set_open_resource_callback(
360 base::Bind(&NaClListener::OnOpenResource, base::Unretained(this)));
321 } 361 }
322 362
323 trusted_listener_ = new NaClTrustedListener( 363 trusted_listener_ = new NaClTrustedListener(
324 IPC::Channel::GenerateVerifiedChannelID("nacl"), 364 IPC::Channel::GenerateVerifiedChannelID("nacl"),
325 io_thread_.message_loop_proxy().get(), 365 io_thread_.message_loop_proxy().get(),
326 &shutdown_event_); 366 &shutdown_event_);
327 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 367 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
328 browser_handle, 368 browser_handle,
329 ppapi_renderer_handle, 369 ppapi_renderer_handle,
330 trusted_listener_->TakeClientChannelHandle(), 370 trusted_listener_->TakeClientChannelHandle(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 #if defined(OS_LINUX) 456 #if defined(OS_LINUX)
417 args->prereserved_sandbox_size = prereserved_sandbox_size_; 457 args->prereserved_sandbox_size = prereserved_sandbox_size_;
418 #endif 458 #endif
419 459
420 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile( 460 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile(
421 params.nexe_file); 461 params.nexe_file);
422 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe(); 462 std::string file_path_str = params.nexe_file_path_metadata.AsUTF8Unsafe();
423 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file, 463 args->nexe_desc = NaClDescCreateWithFilePathMetadata(nexe_file,
424 file_path_str.c_str()); 464 file_path_str.c_str());
425 465
426 // TODO(yusukes): Support pre-opening resource files.
427 CHECK(params.resource_files.empty());
428
429 int exit_status; 466 int exit_status;
430 if (!NaClChromeMainStart(nap, args, &exit_status)) 467 if (!NaClChromeMainStart(nap, args, &exit_status))
431 NaClExit(1); 468 NaClExit(1);
432 469
433 // Report the plugin's exit status if the application started successfully. 470 // Report the plugin's exit status if the application started successfully.
434 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); 471 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status));
435 NaClExit(exit_status); 472 NaClExit(exit_status);
436 } 473 }
437 474
438 void NaClListener::ResolveFileToken( 475 void NaClListener::ResolveFileToken(
439 uint64_t token_lo, 476 uint64_t token_lo,
440 uint64_t token_hi, 477 uint64_t token_hi,
441 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) { 478 base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> cb) {
442 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) { 479 if (!Send(new NaClProcessMsg_ResolveFileToken(token_lo, token_hi))) {
443 cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); 480 cb.Run(IPC::PlatformFileForTransit(), base::FilePath());
444 return; 481 return;
445 } 482 }
446 resolved_cb_ = cb; 483 resolved_cb_ = cb;
447 } 484 }
448 485
449 void NaClListener::OnFileTokenResolved( 486 void NaClListener::OnFileTokenResolved(
450 uint64_t token_lo, 487 uint64_t token_lo,
451 uint64_t token_hi, 488 uint64_t token_hi,
452 IPC::PlatformFileForTransit ipc_fd, 489 IPC::PlatformFileForTransit ipc_fd,
453 base::FilePath file_path) { 490 base::FilePath file_path) {
454 resolved_cb_.Run(ipc_fd, file_path); 491 resolved_cb_.Run(ipc_fd, file_path);
455 resolved_cb_.Reset(); 492 resolved_cb_.Reset();
456 } 493 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_listener.h ('k') | components/nacl/renderer/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698