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/renderer/ppb_nacl_private.h" | 5 #include "components/nacl/renderer/ppb_nacl_private.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/lazy_instance.h" | 23 #include "base/lazy_instance.h" |
24 #include "base/location.h" | 24 #include "base/location.h" |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/macros.h" | 26 #include "base/macros.h" |
27 #include "base/process/process_handle.h" | 27 #include "base/process/process_handle.h" |
28 #include "base/single_thread_task_runner.h" | 28 #include "base/single_thread_task_runner.h" |
29 #include "base/strings/string_split.h" | 29 #include "base/strings/string_split.h" |
30 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
31 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
32 #include "build/build_config.h" | 32 #include "build/build_config.h" |
33 #include "components/nacl/common/nacl_host_messages.h" | 33 #include "components/nacl/common/nacl.mojom.h" |
34 #include "components/nacl/common/nacl_messages.h" | |
35 #include "components/nacl/common/nacl_nonsfi_util.h" | 34 #include "components/nacl/common/nacl_nonsfi_util.h" |
36 #include "components/nacl/common/nacl_switches.h" | 35 #include "components/nacl/common/nacl_switches.h" |
37 #include "components/nacl/common/nacl_types.h" | 36 #include "components/nacl/common/nacl_types.h" |
38 #include "components/nacl/renderer/file_downloader.h" | 37 #include "components/nacl/renderer/file_downloader.h" |
39 #include "components/nacl/renderer/histogram.h" | 38 #include "components/nacl/renderer/histogram.h" |
40 #include "components/nacl/renderer/json_manifest.h" | 39 #include "components/nacl/renderer/json_manifest.h" |
41 #include "components/nacl/renderer/manifest_downloader.h" | 40 #include "components/nacl/renderer/manifest_downloader.h" |
42 #include "components/nacl/renderer/manifest_service_channel.h" | 41 #include "components/nacl/renderer/manifest_service_channel.h" |
43 #include "components/nacl/renderer/nexe_load_manager.h" | 42 #include "components/nacl/renderer/nexe_load_manager.h" |
44 #include "components/nacl/renderer/platform_info.h" | 43 #include "components/nacl/renderer/platform_info.h" |
(...skipping 10 matching lines...) Expand all Loading... |
55 #include "net/base/net_errors.h" | 54 #include "net/base/net_errors.h" |
56 #include "net/http/http_util.h" | 55 #include "net/http/http_util.h" |
57 #include "ppapi/c/pp_bool.h" | 56 #include "ppapi/c/pp_bool.h" |
58 #include "ppapi/c/private/pp_file_handle.h" | 57 #include "ppapi/c/private/pp_file_handle.h" |
59 #include "ppapi/shared_impl/ppapi_globals.h" | 58 #include "ppapi/shared_impl/ppapi_globals.h" |
60 #include "ppapi/shared_impl/ppapi_permissions.h" | 59 #include "ppapi/shared_impl/ppapi_permissions.h" |
61 #include "ppapi/shared_impl/ppapi_preferences.h" | 60 #include "ppapi/shared_impl/ppapi_preferences.h" |
62 #include "ppapi/shared_impl/var.h" | 61 #include "ppapi/shared_impl/var.h" |
63 #include "ppapi/shared_impl/var_tracker.h" | 62 #include "ppapi/shared_impl/var_tracker.h" |
64 #include "ppapi/thunk/enter.h" | 63 #include "ppapi/thunk/enter.h" |
| 64 #include "services/service_manager/public/cpp/interface_provider.h" |
65 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 65 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
66 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 66 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
67 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 67 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
68 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h" | 68 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h" |
69 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" | 69 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" |
70 #include "third_party/WebKit/public/web/WebDocument.h" | 70 #include "third_party/WebKit/public/web/WebDocument.h" |
71 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 71 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
72 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 72 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
73 | 73 |
74 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
75 #include "base/win/scoped_handle.h" | 75 #include "base/win/scoped_handle.h" |
76 #endif | 76 #endif |
77 | 77 |
78 namespace nacl { | 78 namespace nacl { |
79 namespace { | 79 namespace { |
80 | 80 |
81 // The pseudo-architecture used to indicate portable native client. | 81 // The pseudo-architecture used to indicate portable native client. |
82 const char* const kPortableArch = "portable"; | 82 const char* const kPortableArch = "portable"; |
83 | 83 |
84 // The base URL for resources used by the PNaCl translator processes. | 84 // The base URL for resources used by the PNaCl translator processes. |
85 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/"; | 85 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/"; |
86 | 86 |
87 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > | 87 base::LazyInstance<std::unique_ptr<PnaclTranslationResourceHost>> |
88 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; | 88 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; |
89 | 89 |
| 90 class NaClHostConnectionHolder { |
| 91 public: |
| 92 NaClHostConnectionHolder() { |
| 93 content::RenderThread::Get()->GetRemoteInterfaces()->GetInterface(&host_); |
| 94 } |
| 95 |
| 96 mojom::NaClHost* host() { return host_.get(); } |
| 97 |
| 98 private: |
| 99 mojom::NaClHostPtr host_; |
| 100 }; |
| 101 |
| 102 // A renderer-process-wide connection to the browser side. PPBNaClPrivate is a |
| 103 // collection of static methods so a global is required to store a persistent |
| 104 // connection. |
| 105 base::LazyInstance<NaClHostConnectionHolder>::Leaky g_nacl_host_connection = |
| 106 LAZY_INSTANCE_INITIALIZER; |
| 107 |
90 bool InitializePnaclResourceHost() { | 108 bool InitializePnaclResourceHost() { |
91 // Must run on the main thread. | 109 // Must run on the main thread. |
92 content::RenderThread* render_thread = content::RenderThread::Get(); | 110 content::RenderThread* render_thread = content::RenderThread::Get(); |
93 if (!render_thread) | 111 if (!render_thread) |
94 return false; | 112 return false; |
95 if (!g_pnacl_resource_host.Get().get()) { | 113 if (!g_pnacl_resource_host.Get()) { |
96 g_pnacl_resource_host.Get() = | 114 g_pnacl_resource_host.Get() = |
97 new PnaclTranslationResourceHost(render_thread->GetIOTaskRunner()); | 115 base::MakeUnique<PnaclTranslationResourceHost>( |
98 render_thread->AddFilter(g_pnacl_resource_host.Get().get()); | 116 g_nacl_host_connection.Get().host()); |
99 } | 117 } |
100 return true; | 118 return true; |
101 } | 119 } |
102 | 120 |
103 bool CanOpenViaFastPath(content::PepperPluginInstance* plugin_instance, | 121 bool CanOpenViaFastPath(content::PepperPluginInstance* plugin_instance, |
104 const GURL& gurl) { | 122 const GURL& gurl) { |
105 // Fast path only works for installed file URLs. | 123 // Fast path only works for installed file URLs. |
106 if (!gurl.SchemeIs("chrome-extension")) | 124 if (!gurl.SchemeIs("chrome-extension")) |
107 return PP_kInvalidFileHandle; | 125 return PP_kInvalidFileHandle; |
108 | 126 |
(...skipping 13 matching lines...) Expand all Loading... |
122 GURL url; | 140 GURL url; |
123 ppapi::PpapiPermissions permissions; | 141 ppapi::PpapiPermissions permissions; |
124 base::ProcessId plugin_pid; | 142 base::ProcessId plugin_pid; |
125 int plugin_child_id; | 143 int plugin_child_id; |
126 IPC::ChannelHandle channel_handle; | 144 IPC::ChannelHandle channel_handle; |
127 }; | 145 }; |
128 | 146 |
129 class NaClPluginInstance { | 147 class NaClPluginInstance { |
130 public: | 148 public: |
131 explicit NaClPluginInstance(PP_Instance instance) | 149 explicit NaClPluginInstance(PP_Instance instance) |
132 : nexe_load_manager(instance), pexe_size(0) {} | 150 : nexe_load_manager(instance, g_nacl_host_connection.Get().host()), |
| 151 pexe_size(0) {} |
133 ~NaClPluginInstance() { | 152 ~NaClPluginInstance() { |
134 // Make sure that we do not leak a mojo handle if the NaCl loader | 153 // Make sure that we do not leak a mojo handle if the NaCl loader |
135 // process never called ppapi_start() to initialize PPAPI. | 154 // process never called ppapi_start() to initialize PPAPI. |
136 if (instance_info) { | 155 if (instance_info) { |
137 DCHECK(instance_info->channel_handle.is_mojo_channel_handle()); | 156 DCHECK(instance_info->channel_handle.is_mojo_channel_handle()); |
138 instance_info->channel_handle.mojo_handle.Close(); | 157 instance_info->channel_handle.mojo_handle.Close(); |
139 } | 158 } |
140 } | 159 } |
141 | 160 |
142 NexeLoadManager nexe_load_manager; | 161 NexeLoadManager nexe_load_manager; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 PP_Instance instance, | 413 PP_Instance instance, |
395 PP_Bool main_service_runtime, | 414 PP_Bool main_service_runtime, |
396 const char* alleged_url, | 415 const char* alleged_url, |
397 const PP_NaClFileInfo* nexe_file_info, | 416 const PP_NaClFileInfo* nexe_file_info, |
398 PP_Bool uses_nonsfi_mode, | 417 PP_Bool uses_nonsfi_mode, |
399 PP_NaClAppProcessType pp_process_type, | 418 PP_NaClAppProcessType pp_process_type, |
400 std::unique_ptr<IPC::SyncChannel>* translator_channel, | 419 std::unique_ptr<IPC::SyncChannel>* translator_channel, |
401 PP_CompletionCallback callback) { | 420 PP_CompletionCallback callback) { |
402 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 421 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
403 BelongsToCurrentThread()); | 422 BelongsToCurrentThread()); |
| 423 base::File nexe_file(nexe_file_info->handle); |
404 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); | 424 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); |
405 // Create the manifest service proxy here, so on error case, it will be | 425 // Create the manifest service proxy here, so on error case, it will be |
406 // destructed (without passing it to ManifestServiceChannel). | 426 // destructed (without passing it to ManifestServiceChannel). |
407 std::unique_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( | 427 std::unique_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( |
408 new ManifestServiceProxy(instance, process_type)); | 428 new ManifestServiceProxy(instance, process_type)); |
409 | 429 |
410 IPC::Sender* sender = content::RenderThread::Get(); | |
411 DCHECK(sender); | |
412 int routing_id = GetRoutingID(instance); | 430 int routing_id = GetRoutingID(instance); |
413 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 431 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
414 DCHECK(load_manager); | 432 DCHECK(load_manager); |
415 content::PepperPluginInstance* plugin_instance = | 433 content::PepperPluginInstance* plugin_instance = |
416 content::PepperPluginInstance::Get(instance); | 434 content::PepperPluginInstance::Get(instance); |
417 DCHECK(plugin_instance); | 435 DCHECK(plugin_instance); |
418 if (!routing_id || !load_manager || !plugin_instance) { | 436 if (!routing_id || !load_manager || !plugin_instance) { |
419 if (nexe_file_info->handle != PP_kInvalidFileHandle) { | |
420 base::File closer(nexe_file_info->handle); | |
421 } | |
422 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 437 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
423 FROM_HERE, base::Bind(callback.func, callback.user_data, | 438 FROM_HERE, base::Bind(callback.func, callback.user_data, |
424 static_cast<int32_t>(PP_ERROR_FAILED))); | 439 static_cast<int32_t>(PP_ERROR_FAILED))); |
425 return; | 440 return; |
426 } | 441 } |
427 | 442 |
428 InstanceInfo instance_info; | 443 InstanceInfo instance_info; |
429 instance_info.url = GURL(alleged_url); | 444 instance_info.url = GURL(alleged_url); |
430 | 445 |
431 uint32_t perm_bits = ppapi::PERMISSION_NONE; | 446 uint32_t perm_bits = ppapi::PERMISSION_NONE; |
(...skipping 15 matching lines...) Expand all Loading... |
447 const GURL gurl(resource_prefetch_request_list[i].resource_url); | 462 const GURL gurl(resource_prefetch_request_list[i].resource_url); |
448 // Important security check. Do not remove. | 463 // Important security check. Do not remove. |
449 if (!CanOpenViaFastPath(plugin_instance, gurl)) { | 464 if (!CanOpenViaFastPath(plugin_instance, gurl)) { |
450 resource_prefetch_request_list.clear(); | 465 resource_prefetch_request_list.clear(); |
451 break; | 466 break; |
452 } | 467 } |
453 } | 468 } |
454 } | 469 } |
455 } | 470 } |
456 | 471 |
457 IPC::PlatformFileForTransit nexe_for_transit = | |
458 IPC::InvalidPlatformFileForTransit(); | |
459 #if defined(OS_POSIX) | |
460 if (nexe_file_info->handle != PP_kInvalidFileHandle) | |
461 nexe_for_transit = base::FileDescriptor(nexe_file_info->handle, true); | |
462 #elif defined(OS_WIN) | |
463 nexe_for_transit = IPC::PlatformFileForTransit(nexe_file_info->handle, | |
464 base::GetCurrentProcId()); | |
465 #else | |
466 # error Unsupported target platform. | |
467 #endif | |
468 | |
469 std::string error_message_string; | 472 std::string error_message_string; |
470 NaClLaunchResult launch_result; | 473 mojom::NaClLaunchResultPtr launch_result; |
471 if (!sender->Send(new NaClHostMsg_LaunchNaCl( | 474 if (!g_nacl_host_connection.Get().host()->LaunchNaCl( |
472 NaClLaunchParams( | 475 mojom::NaClLaunchParams::New( |
473 instance_info.url.spec(), | 476 instance_info.url, std::move(nexe_file), nexe_file_info->token_lo, |
474 nexe_for_transit, | 477 nexe_file_info->token_hi, resource_prefetch_request_list, |
475 nexe_file_info->token_lo, | 478 routing_id, perm_bits, PP_ToBool(uses_nonsfi_mode), process_type), |
476 nexe_file_info->token_hi, | 479 &launch_result, &error_message_string)) { |
477 resource_prefetch_request_list, | |
478 routing_id, | |
479 perm_bits, | |
480 PP_ToBool(uses_nonsfi_mode), | |
481 process_type), | |
482 &launch_result, | |
483 &error_message_string))) { | |
484 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 480 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
485 FROM_HERE, | 481 FROM_HERE, |
486 base::Bind(callback.func, callback.user_data, | 482 base::Bind(callback.func, callback.user_data, |
487 static_cast<int32_t>(PP_ERROR_FAILED))); | 483 static_cast<int32_t>(PP_ERROR_FAILED))); |
488 return; | 484 return; |
489 } | 485 } |
490 | 486 |
491 load_manager->set_nonsfi(PP_ToBool(uses_nonsfi_mode)); | 487 load_manager->set_nonsfi(PP_ToBool(uses_nonsfi_mode)); |
492 | 488 |
493 if (!error_message_string.empty()) { | 489 if (!error_message_string.empty()) { |
494 // Even on error, some FDs/handles may be passed to here. | |
495 // We must release those resources. | |
496 // See also nacl_process_host.cc. | |
497 if (base::SharedMemory::IsHandleValid( | |
498 launch_result.crash_info_shmem_handle)) | |
499 base::SharedMemory::CloseHandle(launch_result.crash_info_shmem_handle); | |
500 | |
501 if (PP_ToBool(main_service_runtime)) { | 490 if (PP_ToBool(main_service_runtime)) { |
502 load_manager->ReportLoadError(PP_NACL_ERROR_SEL_LDR_LAUNCH, | 491 load_manager->ReportLoadError(PP_NACL_ERROR_SEL_LDR_LAUNCH, |
503 "ServiceRuntime: failed to start", | 492 "ServiceRuntime: failed to start", |
504 error_message_string); | 493 error_message_string); |
505 } | 494 } |
506 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 495 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
507 FROM_HERE, | 496 FROM_HERE, |
508 base::Bind(callback.func, callback.user_data, | 497 base::Bind(callback.func, callback.user_data, |
509 static_cast<int32_t>(PP_ERROR_FAILED))); | 498 static_cast<int32_t>(PP_ERROR_FAILED))); |
510 return; | 499 return; |
511 } | 500 } |
| 501 DCHECK(launch_result); |
512 | 502 |
513 instance_info.channel_handle = launch_result.ppapi_ipc_channel_handle; | 503 instance_info.channel_handle = |
514 instance_info.plugin_pid = launch_result.plugin_pid; | 504 launch_result->ppapi_ipc_channel_handle.release(); |
515 instance_info.plugin_child_id = launch_result.plugin_child_id; | 505 instance_info.plugin_pid = launch_result->plugin_pid; |
| 506 instance_info.plugin_child_id = launch_result->plugin_child_id; |
516 | 507 |
517 // Don't save instance_info if channel handle is invalid. | 508 // Don't save instance_info if channel handle is invalid. |
518 if (IsValidChannelHandle(instance_info.channel_handle)) { | 509 if (IsValidChannelHandle(instance_info.channel_handle)) { |
519 if (process_type == kPNaClTranslatorProcessType) { | 510 if (process_type == kPNaClTranslatorProcessType) { |
520 // Return an IPC channel which allows communicating with a PNaCl | 511 // Return an IPC channel which allows communicating with a PNaCl |
521 // translator process. | 512 // translator process. |
522 *translator_channel = IPC::SyncChannel::Create( | 513 *translator_channel = IPC::SyncChannel::Create( |
523 instance_info.channel_handle, IPC::Channel::MODE_CLIENT, | 514 instance_info.channel_handle, IPC::Channel::MODE_CLIENT, |
524 new NoOpListener, content::RenderThread::Get()->GetIOTaskRunner(), | 515 new NoOpListener, content::RenderThread::Get()->GetIOTaskRunner(), |
525 true, content::RenderThread::Get()->GetShutdownEvent()); | 516 true, content::RenderThread::Get()->GetShutdownEvent()); |
526 } else { | 517 } else { |
527 // Save the channel handle for when StartPpapiProxy() is called. | 518 // Save the channel handle for when StartPpapiProxy() is called. |
528 NaClPluginInstance* nacl_plugin_instance = | 519 NaClPluginInstance* nacl_plugin_instance = |
529 GetNaClPluginInstance(instance); | 520 GetNaClPluginInstance(instance); |
530 nacl_plugin_instance->instance_info.reset( | 521 nacl_plugin_instance->instance_info.reset( |
531 new InstanceInfo(instance_info)); | 522 new InstanceInfo(instance_info)); |
532 } | 523 } |
533 } | 524 } |
534 | 525 |
535 // Store the crash information shared memory handle. | 526 // Store the crash information shared memory handle. |
536 load_manager->set_crash_info_shmem_handle( | 527 load_manager->set_crash_info_shmem_handle( |
537 launch_result.crash_info_shmem_handle); | 528 std::move(launch_result->crash_info_shmem_handle)); |
538 | 529 |
539 // Create the trusted plugin channel. | 530 // Create the trusted plugin channel. |
540 if (IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { | 531 if (launch_result->trusted_ipc_channel_handle.is_pending()) { |
541 bool is_helper_nexe = !PP_ToBool(main_service_runtime); | 532 bool is_helper_nexe = !PP_ToBool(main_service_runtime); |
542 std::unique_ptr<TrustedPluginChannel> trusted_plugin_channel( | 533 std::unique_ptr<TrustedPluginChannel> trusted_plugin_channel( |
543 new TrustedPluginChannel( | 534 new TrustedPluginChannel( |
544 load_manager, | 535 load_manager, std::move(launch_result->trusted_ipc_channel_handle), |
545 mojo::MakeRequest<mojom::NaClRendererHost>( | |
546 mojo::ScopedMessagePipeHandle( | |
547 launch_result.trusted_ipc_channel_handle.mojo_handle)), | |
548 is_helper_nexe)); | 536 is_helper_nexe)); |
549 load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel)); | 537 load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel)); |
550 } else { | 538 } else { |
551 PostPPCompletionCallback(callback, PP_ERROR_FAILED); | 539 PostPPCompletionCallback(callback, PP_ERROR_FAILED); |
552 return; | 540 return; |
553 } | 541 } |
554 | 542 |
555 // Create the manifest service handle as well. | 543 // Create the manifest service handle as well. |
556 if (IsValidChannelHandle(launch_result.manifest_service_ipc_channel_handle)) { | 544 if (launch_result->manifest_service_ipc_channel_handle.is_valid()) { |
557 std::unique_ptr<ManifestServiceChannel> manifest_service_channel( | 545 std::unique_ptr<ManifestServiceChannel> manifest_service_channel( |
558 new ManifestServiceChannel( | 546 new ManifestServiceChannel( |
559 launch_result.manifest_service_ipc_channel_handle, | 547 launch_result->manifest_service_ipc_channel_handle.release(), |
560 base::Bind(&PostPPCompletionCallback, callback), | 548 base::Bind(&PostPPCompletionCallback, callback), |
561 std::move(manifest_service_proxy), | 549 std::move(manifest_service_proxy), |
562 content::RenderThread::Get()->GetShutdownEvent())); | 550 content::RenderThread::Get()->GetShutdownEvent())); |
563 load_manager->set_manifest_service_channel( | 551 load_manager->set_manifest_service_channel( |
564 std::move(manifest_service_channel)); | 552 std::move(manifest_service_channel)); |
565 } | 553 } |
566 } | 554 } |
567 | 555 |
568 namespace { | 556 namespace { |
569 | 557 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 replace_pos = r.find_first_not_of(kWhiteList); | 620 replace_pos = r.find_first_not_of(kWhiteList); |
633 } | 621 } |
634 return r; | 622 return r; |
635 } | 623 } |
636 | 624 |
637 PP_FileHandle GetReadonlyPnaclFd(const char* url, | 625 PP_FileHandle GetReadonlyPnaclFd(const char* url, |
638 bool is_executable, | 626 bool is_executable, |
639 uint64_t* nonce_lo, | 627 uint64_t* nonce_lo, |
640 uint64_t* nonce_hi) { | 628 uint64_t* nonce_hi) { |
641 std::string filename = PnaclComponentURLToFilename(url); | 629 std::string filename = PnaclComponentURLToFilename(url); |
642 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 630 base::File file; |
643 IPC::Sender* sender = content::RenderThread::Get(); | 631 if (!g_nacl_host_connection.Get().host()->GetReadonlyPnaclFd( |
644 DCHECK(sender); | 632 filename, is_executable, &file, nonce_lo, nonce_hi)) { |
645 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( | |
646 std::string(filename), is_executable, | |
647 &out_fd, nonce_lo, nonce_hi))) { | |
648 return PP_kInvalidFileHandle; | 633 return PP_kInvalidFileHandle; |
649 } | 634 } |
650 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 635 return file.TakePlatformFile(); |
651 return PP_kInvalidFileHandle; | |
652 } | |
653 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | |
654 } | 636 } |
655 | 637 |
656 } // namespace | 638 } // namespace |
657 | 639 |
658 // static | 640 // static |
659 void PPBNaClPrivate::GetReadExecPnaclFd(const char* url, | 641 void PPBNaClPrivate::GetReadExecPnaclFd(const char* url, |
660 PP_NaClFileInfo* out_file_info) { | 642 PP_NaClFileInfo* out_file_info) { |
661 *out_file_info = kInvalidNaClFileInfo; | 643 *out_file_info = kInvalidNaClFileInfo; |
662 out_file_info->handle = GetReadonlyPnaclFd(url, true /* is_executable */, | 644 out_file_info->handle = GetReadonlyPnaclFd(url, true /* is_executable */, |
663 &out_file_info->token_lo, | 645 &out_file_info->token_lo, |
664 &out_file_info->token_hi); | 646 &out_file_info->token_hi); |
665 } | 647 } |
666 | 648 |
667 // static | 649 // static |
668 PP_FileHandle PPBNaClPrivate::CreateTemporaryFile(PP_Instance instance) { | 650 PP_FileHandle PPBNaClPrivate::CreateTemporaryFile(PP_Instance instance) { |
669 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); | 651 base::File file; |
670 IPC::Sender* sender = content::RenderThread::Get(); | 652 if (!g_nacl_host_connection.Get().host()->NaClCreateTemporaryFile(&file)) { |
671 DCHECK(sender); | |
672 if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile( | |
673 &transit_fd))) { | |
674 return PP_kInvalidFileHandle; | 653 return PP_kInvalidFileHandle; |
675 } | 654 } |
676 | 655 return file.TakePlatformFile(); |
677 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { | |
678 return PP_kInvalidFileHandle; | |
679 } | |
680 | |
681 return IPC::PlatformFileForTransitToPlatformFile(transit_fd); | |
682 } | 656 } |
683 | 657 |
684 // static | 658 // static |
685 int32_t PPBNaClPrivate::GetNumberOfProcessors() { | 659 int32_t PPBNaClPrivate::GetNumberOfProcessors() { |
686 IPC::Sender* sender = content::RenderThread::Get(); | |
687 DCHECK(sender); | |
688 int32_t num_processors = 1; | 660 int32_t num_processors = 1; |
689 return sender->Send(new NaClHostMsg_NaClGetNumProcessors(&num_processors)) ? | 661 return g_nacl_host_connection.Get().host()->NaClGetNumProcessors( |
690 num_processors : 1; | 662 &num_processors) |
| 663 ? num_processors |
| 664 : 1; |
691 } | 665 } |
692 | 666 |
693 namespace { | 667 namespace { |
694 | 668 |
695 void GetNexeFd(PP_Instance instance, | 669 void GetNexeFd(PP_Instance instance, |
696 const std::string& pexe_url, | 670 const std::string& pexe_url, |
697 uint32_t opt_level, | 671 uint32_t opt_level, |
698 const base::Time& last_modified_time, | 672 const base::Time& last_modified_time, |
699 const std::string& etag, | 673 const std::string& etag, |
700 bool has_no_store_header, | 674 bool has_no_store_header, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 std::string uma_suffix(use_subzero ? ".Subzero" : ".LLC"); | 751 std::string uma_suffix(use_subzero ? ".Subzero" : ".LLC"); |
778 LogTranslationFinishedUMA("", opt_level, kUnknownOptLevel, nexe_size, | 752 LogTranslationFinishedUMA("", opt_level, kUnknownOptLevel, nexe_size, |
779 pexe_size, compile_time_us, total_time); | 753 pexe_size, compile_time_us, total_time); |
780 LogTranslationFinishedUMA(uma_suffix, opt_level, kUnknownOptLevel, | 754 LogTranslationFinishedUMA(uma_suffix, opt_level, kUnknownOptLevel, |
781 nexe_size, pexe_size, compile_time_us, | 755 nexe_size, pexe_size, compile_time_us, |
782 total_time); | 756 total_time); |
783 } | 757 } |
784 | 758 |
785 // If the resource host isn't initialized, don't try to do that here. | 759 // If the resource host isn't initialized, don't try to do that here. |
786 // Just return because something is already very wrong. | 760 // Just return because something is already very wrong. |
787 if (g_pnacl_resource_host.Get().get() == NULL) | 761 if (g_pnacl_resource_host.Get() == NULL) |
788 return; | 762 return; |
789 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); | 763 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); |
790 | 764 |
791 // Record the pexe size for reporting in a later load event. | 765 // Record the pexe size for reporting in a later load event. |
792 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); | 766 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); |
793 if (nacl_plugin_instance) { | 767 if (nacl_plugin_instance) { |
794 nacl_plugin_instance->pexe_size = pexe_size; | 768 nacl_plugin_instance->pexe_size = pexe_size; |
795 } | 769 } |
796 } | 770 } |
797 | 771 |
(...skipping 11 matching lines...) Expand all Loading... |
809 content::PepperPluginInstance* plugin_instance = | 783 content::PepperPluginInstance* plugin_instance = |
810 content::PepperPluginInstance::Get(instance); | 784 content::PepperPluginInstance::Get(instance); |
811 if (!plugin_instance) | 785 if (!plugin_instance) |
812 return PP_kInvalidFileHandle; | 786 return PP_kInvalidFileHandle; |
813 | 787 |
814 GURL gurl(file_url); | 788 GURL gurl(file_url); |
815 // Important security check. Do not remove. | 789 // Important security check. Do not remove. |
816 if (!CanOpenViaFastPath(plugin_instance, gurl)) | 790 if (!CanOpenViaFastPath(plugin_instance, gurl)) |
817 return PP_kInvalidFileHandle; | 791 return PP_kInvalidFileHandle; |
818 | 792 |
819 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | |
820 IPC::Sender* sender = content::RenderThread::Get(); | |
821 DCHECK(sender); | |
822 *nonce_lo = 0; | 793 *nonce_lo = 0; |
823 *nonce_hi = 0; | 794 *nonce_hi = 0; |
824 base::FilePath file_path; | 795 base::FilePath file_path; |
825 if (!sender->Send( | 796 base::File file; |
826 new NaClHostMsg_OpenNaClExecutable(GetRoutingID(instance), | 797 if (!g_nacl_host_connection.Get().host()->OpenNaClExecutable( |
827 GURL(file_url), | 798 GetRoutingID(instance), GURL(file_url), !load_manager->nonsfi(), |
828 !load_manager->nonsfi(), | 799 &file, nonce_lo, nonce_hi)) { |
829 &out_fd, | |
830 nonce_lo, | |
831 nonce_hi))) { | |
832 return PP_kInvalidFileHandle; | 800 return PP_kInvalidFileHandle; |
833 } | 801 } |
834 | 802 return file.TakePlatformFile(); |
835 if (out_fd == IPC::InvalidPlatformFileForTransit()) | |
836 return PP_kInvalidFileHandle; | |
837 | |
838 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | |
839 } | 803 } |
840 | 804 |
841 } // namespace | 805 } // namespace |
842 | 806 |
843 // static | 807 // static |
844 void PPBNaClPrivate::DispatchEvent(PP_Instance instance, | 808 void PPBNaClPrivate::DispatchEvent(PP_Instance instance, |
845 PP_NaClEventType event_type, | 809 PP_NaClEventType event_type, |
846 const char* resource_url, | 810 const char* resource_url, |
847 PP_Bool length_is_computable, | 811 PP_Bool length_is_computable, |
848 uint64_t loaded_bytes, | 812 uint64_t loaded_bytes, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 namespace { | 861 namespace { |
898 | 862 |
899 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { | 863 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { |
900 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 864 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
901 switches::kEnableNaClDebug)) | 865 switches::kEnableNaClDebug)) |
902 return PP_FALSE; | 866 return PP_FALSE; |
903 IPC::Sender* sender = content::RenderThread::Get(); | 867 IPC::Sender* sender = content::RenderThread::Get(); |
904 DCHECK(sender); | 868 DCHECK(sender); |
905 bool should_debug = false; | 869 bool should_debug = false; |
906 return PP_FromBool( | 870 return PP_FromBool( |
907 sender->Send(new NaClHostMsg_NaClDebugEnabledForURL(GURL(alleged_nmf_url), | 871 g_nacl_host_connection.Get().host()->NaClDebugEnabledForURL( |
908 &should_debug)) && | 872 GURL(alleged_nmf_url), &should_debug) && |
909 should_debug); | 873 should_debug); |
910 } | 874 } |
911 | 875 |
912 } // namespace | 876 } // namespace |
913 | 877 |
914 // static | 878 // static |
915 void PPBNaClPrivate::InitializePlugin(PP_Instance instance, | 879 void PPBNaClPrivate::InitializePlugin(PP_Instance instance, |
916 uint32_t argc, | 880 uint32_t argc, |
917 const char* argn[], | 881 const char* argn[], |
918 const char* argv[]) { | 882 const char* argv[]) { |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 // Mark the request as requesting a PNaCl bitcode file, | 1707 // Mark the request as requesting a PNaCl bitcode file, |
1744 // so that component updater can detect this user action. | 1708 // so that component updater can detect this user action. |
1745 url_request.addHTTPHeaderField( | 1709 url_request.addHTTPHeaderField( |
1746 blink::WebString::fromUTF8("Accept"), | 1710 blink::WebString::fromUTF8("Accept"), |
1747 blink::WebString::fromUTF8("application/x-pnacl, */*")); | 1711 blink::WebString::fromUTF8("application/x-pnacl, */*")); |
1748 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 1712 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
1749 downloader->Load(url_request); | 1713 downloader->Load(url_request); |
1750 } | 1714 } |
1751 | 1715 |
1752 } // namespace nacl | 1716 } // namespace nacl |
OLD | NEW |