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 base::LazyInstance<NaClHostConnectionHolder>::Leaky g_nacl_host_connection = | |
tibell
2017/01/31 01:24:13
Comment why this global is needed?
Sam McNally
2017/02/07 00:13:18
Done.
| |
103 LAZY_INSTANCE_INITIALIZER; | |
104 | |
90 bool InitializePnaclResourceHost() { | 105 bool InitializePnaclResourceHost() { |
91 // Must run on the main thread. | 106 // Must run on the main thread. |
92 content::RenderThread* render_thread = content::RenderThread::Get(); | 107 content::RenderThread* render_thread = content::RenderThread::Get(); |
93 if (!render_thread) | 108 if (!render_thread) |
94 return false; | 109 return false; |
95 if (!g_pnacl_resource_host.Get().get()) { | 110 if (!g_pnacl_resource_host.Get()) { |
96 g_pnacl_resource_host.Get() = | 111 g_pnacl_resource_host.Get() = |
97 new PnaclTranslationResourceHost(render_thread->GetIOTaskRunner()); | 112 base::MakeUnique<PnaclTranslationResourceHost>( |
98 render_thread->AddFilter(g_pnacl_resource_host.Get().get()); | 113 g_nacl_host_connection.Get().host()); |
99 } | 114 } |
100 return true; | 115 return true; |
101 } | 116 } |
102 | 117 |
103 bool CanOpenViaFastPath(content::PepperPluginInstance* plugin_instance, | 118 bool CanOpenViaFastPath(content::PepperPluginInstance* plugin_instance, |
104 const GURL& gurl) { | 119 const GURL& gurl) { |
105 // Fast path only works for installed file URLs. | 120 // Fast path only works for installed file URLs. |
106 if (!gurl.SchemeIs("chrome-extension")) | 121 if (!gurl.SchemeIs("chrome-extension")) |
107 return PP_kInvalidFileHandle; | 122 return PP_kInvalidFileHandle; |
108 | 123 |
(...skipping 13 matching lines...) Expand all Loading... | |
122 GURL url; | 137 GURL url; |
123 ppapi::PpapiPermissions permissions; | 138 ppapi::PpapiPermissions permissions; |
124 base::ProcessId plugin_pid; | 139 base::ProcessId plugin_pid; |
125 int plugin_child_id; | 140 int plugin_child_id; |
126 IPC::ChannelHandle channel_handle; | 141 IPC::ChannelHandle channel_handle; |
127 }; | 142 }; |
128 | 143 |
129 class NaClPluginInstance { | 144 class NaClPluginInstance { |
130 public: | 145 public: |
131 explicit NaClPluginInstance(PP_Instance instance) | 146 explicit NaClPluginInstance(PP_Instance instance) |
132 : nexe_load_manager(instance), pexe_size(0) {} | 147 : nexe_load_manager(instance, g_nacl_host_connection.Get().host()), |
148 pexe_size(0) {} | |
133 ~NaClPluginInstance() { | 149 ~NaClPluginInstance() { |
134 // Make sure that we do not leak a mojo handle if the NaCl loader | 150 // Make sure that we do not leak a mojo handle if the NaCl loader |
135 // process never called ppapi_start() to initialize PPAPI. | 151 // process never called ppapi_start() to initialize PPAPI. |
136 if (instance_info) { | 152 if (instance_info) { |
137 DCHECK(instance_info->channel_handle.is_mojo_channel_handle()); | 153 DCHECK(instance_info->channel_handle.is_mojo_channel_handle()); |
138 instance_info->channel_handle.mojo_handle.Close(); | 154 instance_info->channel_handle.mojo_handle.Close(); |
139 } | 155 } |
140 } | 156 } |
141 | 157 |
142 NexeLoadManager nexe_load_manager; | 158 NexeLoadManager nexe_load_manager; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 PP_Instance instance, | 410 PP_Instance instance, |
395 PP_Bool main_service_runtime, | 411 PP_Bool main_service_runtime, |
396 const char* alleged_url, | 412 const char* alleged_url, |
397 const PP_NaClFileInfo* nexe_file_info, | 413 const PP_NaClFileInfo* nexe_file_info, |
398 PP_Bool uses_nonsfi_mode, | 414 PP_Bool uses_nonsfi_mode, |
399 PP_NaClAppProcessType pp_process_type, | 415 PP_NaClAppProcessType pp_process_type, |
400 std::unique_ptr<IPC::SyncChannel>* translator_channel, | 416 std::unique_ptr<IPC::SyncChannel>* translator_channel, |
401 PP_CompletionCallback callback) { | 417 PP_CompletionCallback callback) { |
402 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 418 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
403 BelongsToCurrentThread()); | 419 BelongsToCurrentThread()); |
420 base::File nexe_file(nexe_file_info->handle); | |
404 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); | 421 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); |
405 // Create the manifest service proxy here, so on error case, it will be | 422 // Create the manifest service proxy here, so on error case, it will be |
406 // destructed (without passing it to ManifestServiceChannel). | 423 // destructed (without passing it to ManifestServiceChannel). |
407 std::unique_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( | 424 std::unique_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( |
408 new ManifestServiceProxy(instance, process_type)); | 425 new ManifestServiceProxy(instance, process_type)); |
409 | 426 |
410 IPC::Sender* sender = content::RenderThread::Get(); | |
411 DCHECK(sender); | |
412 int routing_id = GetRoutingID(instance); | 427 int routing_id = GetRoutingID(instance); |
413 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 428 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
414 DCHECK(load_manager); | 429 DCHECK(load_manager); |
415 content::PepperPluginInstance* plugin_instance = | 430 content::PepperPluginInstance* plugin_instance = |
416 content::PepperPluginInstance::Get(instance); | 431 content::PepperPluginInstance::Get(instance); |
417 DCHECK(plugin_instance); | 432 DCHECK(plugin_instance); |
418 if (!routing_id || !load_manager || !plugin_instance) { | 433 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( | 434 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
423 FROM_HERE, base::Bind(callback.func, callback.user_data, | 435 FROM_HERE, base::Bind(callback.func, callback.user_data, |
424 static_cast<int32_t>(PP_ERROR_FAILED))); | 436 static_cast<int32_t>(PP_ERROR_FAILED))); |
425 return; | 437 return; |
426 } | 438 } |
427 | 439 |
428 InstanceInfo instance_info; | 440 InstanceInfo instance_info; |
429 instance_info.url = GURL(alleged_url); | 441 instance_info.url = GURL(alleged_url); |
430 | 442 |
431 uint32_t perm_bits = ppapi::PERMISSION_NONE; | 443 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); | 459 const GURL gurl(resource_prefetch_request_list[i].resource_url); |
448 // Important security check. Do not remove. | 460 // Important security check. Do not remove. |
449 if (!CanOpenViaFastPath(plugin_instance, gurl)) { | 461 if (!CanOpenViaFastPath(plugin_instance, gurl)) { |
450 resource_prefetch_request_list.clear(); | 462 resource_prefetch_request_list.clear(); |
451 break; | 463 break; |
452 } | 464 } |
453 } | 465 } |
454 } | 466 } |
455 } | 467 } |
456 | 468 |
457 IPC::PlatformFileForTransit nexe_for_transit = | 469 std::string error_message_string; |
458 IPC::InvalidPlatformFileForTransit(); | 470 mojom::NaClLaunchResultPtr launch_result; |
459 #if defined(OS_POSIX) | 471 auto launch_params = mojom::NaClLaunchParams::New(); |
460 if (nexe_file_info->handle != PP_kInvalidFileHandle) | 472 launch_params->manifest_url = instance_info.url; |
461 nexe_for_transit = base::FileDescriptor(nexe_file_info->handle, true); | 473 launch_params->nexe_file = std::move(nexe_file); |
462 #elif defined(OS_WIN) | 474 launch_params->nexe_token_lo = nexe_file_info->token_lo; |
463 nexe_for_transit = IPC::PlatformFileForTransit(nexe_file_info->handle, | 475 launch_params->nexe_token_hi = nexe_file_info->token_hi; |
464 base::GetCurrentProcId()); | 476 launch_params->resource_prefetch_request_list = |
465 #else | 477 resource_prefetch_request_list; |
466 # error Unsupported target platform. | 478 launch_params->render_view_id = routing_id; |
467 #endif | 479 launch_params->permission_bits = perm_bits; |
480 launch_params->uses_nonsfi_mode = PP_ToBool(uses_nonsfi_mode); | |
481 launch_params->process_type = process_type; | |
468 | 482 |
469 std::string error_message_string; | 483 if (!g_nacl_host_connection.Get().host()->LaunchNaCl( |
470 NaClLaunchResult launch_result; | 484 std::move(launch_params), &launch_result, &error_message_string)) { |
471 if (!sender->Send(new NaClHostMsg_LaunchNaCl( | |
472 NaClLaunchParams( | |
473 instance_info.url.spec(), | |
474 nexe_for_transit, | |
475 nexe_file_info->token_lo, | |
476 nexe_file_info->token_hi, | |
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( | 485 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
485 FROM_HERE, | 486 FROM_HERE, |
486 base::Bind(callback.func, callback.user_data, | 487 base::Bind(callback.func, callback.user_data, |
487 static_cast<int32_t>(PP_ERROR_FAILED))); | 488 static_cast<int32_t>(PP_ERROR_FAILED))); |
488 return; | 489 return; |
489 } | 490 } |
490 | 491 |
491 load_manager->set_nonsfi(PP_ToBool(uses_nonsfi_mode)); | 492 load_manager->set_nonsfi(PP_ToBool(uses_nonsfi_mode)); |
492 | 493 |
493 if (!error_message_string.empty()) { | 494 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)) { | 495 if (PP_ToBool(main_service_runtime)) { |
502 load_manager->ReportLoadError(PP_NACL_ERROR_SEL_LDR_LAUNCH, | 496 load_manager->ReportLoadError(PP_NACL_ERROR_SEL_LDR_LAUNCH, |
503 "ServiceRuntime: failed to start", | 497 "ServiceRuntime: failed to start", |
504 error_message_string); | 498 error_message_string); |
505 } | 499 } |
506 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 500 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
507 FROM_HERE, | 501 FROM_HERE, |
508 base::Bind(callback.func, callback.user_data, | 502 base::Bind(callback.func, callback.user_data, |
509 static_cast<int32_t>(PP_ERROR_FAILED))); | 503 static_cast<int32_t>(PP_ERROR_FAILED))); |
510 return; | 504 return; |
511 } | 505 } |
506 DCHECK(launch_result); | |
512 | 507 |
513 instance_info.channel_handle = launch_result.ppapi_ipc_channel_handle; | 508 instance_info.channel_handle = |
514 instance_info.plugin_pid = launch_result.plugin_pid; | 509 launch_result->ppapi_ipc_channel_handle.release(); |
515 instance_info.plugin_child_id = launch_result.plugin_child_id; | 510 instance_info.plugin_pid = launch_result->plugin_pid; |
511 instance_info.plugin_child_id = launch_result->plugin_child_id; | |
516 | 512 |
517 // Don't save instance_info if channel handle is invalid. | 513 // Don't save instance_info if channel handle is invalid. |
518 if (IsValidChannelHandle(instance_info.channel_handle)) { | 514 if (IsValidChannelHandle(instance_info.channel_handle)) { |
519 if (process_type == kPNaClTranslatorProcessType) { | 515 if (process_type == kPNaClTranslatorProcessType) { |
520 // Return an IPC channel which allows communicating with a PNaCl | 516 // Return an IPC channel which allows communicating with a PNaCl |
521 // translator process. | 517 // translator process. |
522 *translator_channel = IPC::SyncChannel::Create( | 518 *translator_channel = IPC::SyncChannel::Create( |
523 instance_info.channel_handle, IPC::Channel::MODE_CLIENT, | 519 instance_info.channel_handle, IPC::Channel::MODE_CLIENT, |
524 new NoOpListener, content::RenderThread::Get()->GetIOTaskRunner(), | 520 new NoOpListener, content::RenderThread::Get()->GetIOTaskRunner(), |
525 true, content::RenderThread::Get()->GetShutdownEvent()); | 521 true, content::RenderThread::Get()->GetShutdownEvent()); |
526 } else { | 522 } else { |
527 // Save the channel handle for when StartPpapiProxy() is called. | 523 // Save the channel handle for when StartPpapiProxy() is called. |
528 NaClPluginInstance* nacl_plugin_instance = | 524 NaClPluginInstance* nacl_plugin_instance = |
529 GetNaClPluginInstance(instance); | 525 GetNaClPluginInstance(instance); |
530 nacl_plugin_instance->instance_info.reset( | 526 nacl_plugin_instance->instance_info.reset( |
531 new InstanceInfo(instance_info)); | 527 new InstanceInfo(instance_info)); |
532 } | 528 } |
533 } | 529 } |
534 | 530 |
535 // Store the crash information shared memory handle. | 531 // Store the crash information shared memory handle. |
536 load_manager->set_crash_info_shmem_handle( | 532 load_manager->set_crash_info_shmem_handle( |
537 launch_result.crash_info_shmem_handle); | 533 std::move(launch_result->crash_info_shmem_handle)); |
538 | 534 |
539 // Create the trusted plugin channel. | 535 // Create the trusted plugin channel. |
540 if (IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { | 536 if (launch_result->trusted_ipc_channel_handle.is_pending()) { |
541 bool is_helper_nexe = !PP_ToBool(main_service_runtime); | 537 bool is_helper_nexe = !PP_ToBool(main_service_runtime); |
542 std::unique_ptr<TrustedPluginChannel> trusted_plugin_channel( | 538 std::unique_ptr<TrustedPluginChannel> trusted_plugin_channel( |
543 new TrustedPluginChannel( | 539 new TrustedPluginChannel( |
544 load_manager, | 540 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)); | 541 is_helper_nexe)); |
549 load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel)); | 542 load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel)); |
550 } else { | 543 } else { |
551 PostPPCompletionCallback(callback, PP_ERROR_FAILED); | 544 PostPPCompletionCallback(callback, PP_ERROR_FAILED); |
552 return; | 545 return; |
553 } | 546 } |
554 | 547 |
555 // Create the manifest service handle as well. | 548 // Create the manifest service handle as well. |
556 if (IsValidChannelHandle(launch_result.manifest_service_ipc_channel_handle)) { | 549 if (launch_result->manifest_service_ipc_channel_handle.is_valid()) { |
557 std::unique_ptr<ManifestServiceChannel> manifest_service_channel( | 550 std::unique_ptr<ManifestServiceChannel> manifest_service_channel( |
558 new ManifestServiceChannel( | 551 new ManifestServiceChannel( |
559 launch_result.manifest_service_ipc_channel_handle, | 552 launch_result->manifest_service_ipc_channel_handle.release(), |
560 base::Bind(&PostPPCompletionCallback, callback), | 553 base::Bind(&PostPPCompletionCallback, callback), |
561 std::move(manifest_service_proxy), | 554 std::move(manifest_service_proxy), |
562 content::RenderThread::Get()->GetShutdownEvent())); | 555 content::RenderThread::Get()->GetShutdownEvent())); |
563 load_manager->set_manifest_service_channel( | 556 load_manager->set_manifest_service_channel( |
564 std::move(manifest_service_channel)); | 557 std::move(manifest_service_channel)); |
565 } | 558 } |
566 } | 559 } |
567 | 560 |
568 namespace { | 561 namespace { |
569 | 562 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 replace_pos = r.find_first_not_of(kWhiteList); | 625 replace_pos = r.find_first_not_of(kWhiteList); |
633 } | 626 } |
634 return r; | 627 return r; |
635 } | 628 } |
636 | 629 |
637 PP_FileHandle GetReadonlyPnaclFd(const char* url, | 630 PP_FileHandle GetReadonlyPnaclFd(const char* url, |
638 bool is_executable, | 631 bool is_executable, |
639 uint64_t* nonce_lo, | 632 uint64_t* nonce_lo, |
640 uint64_t* nonce_hi) { | 633 uint64_t* nonce_hi) { |
641 std::string filename = PnaclComponentURLToFilename(url); | 634 std::string filename = PnaclComponentURLToFilename(url); |
642 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 635 base::File file; |
643 IPC::Sender* sender = content::RenderThread::Get(); | 636 if (!g_nacl_host_connection.Get().host()->GetReadonlyPnaclFd( |
644 DCHECK(sender); | 637 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; | 638 return PP_kInvalidFileHandle; |
649 } | 639 } |
650 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 640 return file.TakePlatformFile(); |
651 return PP_kInvalidFileHandle; | |
652 } | |
653 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | |
654 } | 641 } |
655 | 642 |
656 } // namespace | 643 } // namespace |
657 | 644 |
658 // static | 645 // static |
659 void PPBNaClPrivate::GetReadExecPnaclFd(const char* url, | 646 void PPBNaClPrivate::GetReadExecPnaclFd(const char* url, |
660 PP_NaClFileInfo* out_file_info) { | 647 PP_NaClFileInfo* out_file_info) { |
661 *out_file_info = kInvalidNaClFileInfo; | 648 *out_file_info = kInvalidNaClFileInfo; |
662 out_file_info->handle = GetReadonlyPnaclFd(url, true /* is_executable */, | 649 out_file_info->handle = GetReadonlyPnaclFd(url, true /* is_executable */, |
663 &out_file_info->token_lo, | 650 &out_file_info->token_lo, |
664 &out_file_info->token_hi); | 651 &out_file_info->token_hi); |
665 } | 652 } |
666 | 653 |
667 // static | 654 // static |
668 PP_FileHandle PPBNaClPrivate::CreateTemporaryFile(PP_Instance instance) { | 655 PP_FileHandle PPBNaClPrivate::CreateTemporaryFile(PP_Instance instance) { |
669 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); | 656 base::File file; |
670 IPC::Sender* sender = content::RenderThread::Get(); | 657 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; | 658 return PP_kInvalidFileHandle; |
675 } | 659 } |
676 | 660 return file.TakePlatformFile(); |
677 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { | |
678 return PP_kInvalidFileHandle; | |
679 } | |
680 | |
681 return IPC::PlatformFileForTransitToPlatformFile(transit_fd); | |
682 } | 661 } |
683 | 662 |
684 // static | 663 // static |
685 int32_t PPBNaClPrivate::GetNumberOfProcessors() { | 664 int32_t PPBNaClPrivate::GetNumberOfProcessors() { |
686 IPC::Sender* sender = content::RenderThread::Get(); | |
687 DCHECK(sender); | |
688 int32_t num_processors = 1; | 665 int32_t num_processors = 1; |
689 return sender->Send(new NaClHostMsg_NaClGetNumProcessors(&num_processors)) ? | 666 return g_nacl_host_connection.Get().host()->NaClGetNumProcessors( |
690 num_processors : 1; | 667 &num_processors) |
668 ? num_processors | |
669 : 1; | |
691 } | 670 } |
692 | 671 |
693 namespace { | 672 namespace { |
694 | 673 |
695 void GetNexeFd(PP_Instance instance, | 674 void GetNexeFd(PP_Instance instance, |
696 const std::string& pexe_url, | 675 const std::string& pexe_url, |
697 uint32_t opt_level, | 676 uint32_t opt_level, |
698 const base::Time& last_modified_time, | 677 const base::Time& last_modified_time, |
699 const std::string& etag, | 678 const std::string& etag, |
700 bool has_no_store_header, | 679 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"); | 756 std::string uma_suffix(use_subzero ? ".Subzero" : ".LLC"); |
778 LogTranslationFinishedUMA("", opt_level, kUnknownOptLevel, nexe_size, | 757 LogTranslationFinishedUMA("", opt_level, kUnknownOptLevel, nexe_size, |
779 pexe_size, compile_time_us, total_time); | 758 pexe_size, compile_time_us, total_time); |
780 LogTranslationFinishedUMA(uma_suffix, opt_level, kUnknownOptLevel, | 759 LogTranslationFinishedUMA(uma_suffix, opt_level, kUnknownOptLevel, |
781 nexe_size, pexe_size, compile_time_us, | 760 nexe_size, pexe_size, compile_time_us, |
782 total_time); | 761 total_time); |
783 } | 762 } |
784 | 763 |
785 // If the resource host isn't initialized, don't try to do that here. | 764 // If the resource host isn't initialized, don't try to do that here. |
786 // Just return because something is already very wrong. | 765 // Just return because something is already very wrong. |
787 if (g_pnacl_resource_host.Get().get() == NULL) | 766 if (g_pnacl_resource_host.Get() == NULL) |
788 return; | 767 return; |
789 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); | 768 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); |
790 | 769 |
791 // Record the pexe size for reporting in a later load event. | 770 // Record the pexe size for reporting in a later load event. |
792 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); | 771 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); |
793 if (nacl_plugin_instance) { | 772 if (nacl_plugin_instance) { |
794 nacl_plugin_instance->pexe_size = pexe_size; | 773 nacl_plugin_instance->pexe_size = pexe_size; |
795 } | 774 } |
796 } | 775 } |
797 | 776 |
(...skipping 11 matching lines...) Expand all Loading... | |
809 content::PepperPluginInstance* plugin_instance = | 788 content::PepperPluginInstance* plugin_instance = |
810 content::PepperPluginInstance::Get(instance); | 789 content::PepperPluginInstance::Get(instance); |
811 if (!plugin_instance) | 790 if (!plugin_instance) |
812 return PP_kInvalidFileHandle; | 791 return PP_kInvalidFileHandle; |
813 | 792 |
814 GURL gurl(file_url); | 793 GURL gurl(file_url); |
815 // Important security check. Do not remove. | 794 // Important security check. Do not remove. |
816 if (!CanOpenViaFastPath(plugin_instance, gurl)) | 795 if (!CanOpenViaFastPath(plugin_instance, gurl)) |
817 return PP_kInvalidFileHandle; | 796 return PP_kInvalidFileHandle; |
818 | 797 |
819 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | |
820 IPC::Sender* sender = content::RenderThread::Get(); | |
821 DCHECK(sender); | |
822 *nonce_lo = 0; | 798 *nonce_lo = 0; |
823 *nonce_hi = 0; | 799 *nonce_hi = 0; |
824 base::FilePath file_path; | 800 base::FilePath file_path; |
825 if (!sender->Send( | 801 base::File file; |
826 new NaClHostMsg_OpenNaClExecutable(GetRoutingID(instance), | 802 if (!g_nacl_host_connection.Get().host()->OpenNaClExecutable( |
827 GURL(file_url), | 803 GetRoutingID(instance), GURL(file_url), !load_manager->nonsfi(), |
828 !load_manager->nonsfi(), | 804 &file, nonce_lo, nonce_hi)) { |
829 &out_fd, | |
830 nonce_lo, | |
831 nonce_hi))) { | |
832 return PP_kInvalidFileHandle; | 805 return PP_kInvalidFileHandle; |
833 } | 806 } |
834 | 807 return file.TakePlatformFile(); |
835 if (out_fd == IPC::InvalidPlatformFileForTransit()) | |
836 return PP_kInvalidFileHandle; | |
837 | |
838 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | |
839 } | 808 } |
840 | 809 |
841 } // namespace | 810 } // namespace |
842 | 811 |
843 // static | 812 // static |
844 void PPBNaClPrivate::DispatchEvent(PP_Instance instance, | 813 void PPBNaClPrivate::DispatchEvent(PP_Instance instance, |
845 PP_NaClEventType event_type, | 814 PP_NaClEventType event_type, |
846 const char* resource_url, | 815 const char* resource_url, |
847 PP_Bool length_is_computable, | 816 PP_Bool length_is_computable, |
848 uint64_t loaded_bytes, | 817 uint64_t loaded_bytes, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 namespace { | 866 namespace { |
898 | 867 |
899 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { | 868 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { |
900 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 869 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
901 switches::kEnableNaClDebug)) | 870 switches::kEnableNaClDebug)) |
902 return PP_FALSE; | 871 return PP_FALSE; |
903 IPC::Sender* sender = content::RenderThread::Get(); | 872 IPC::Sender* sender = content::RenderThread::Get(); |
904 DCHECK(sender); | 873 DCHECK(sender); |
905 bool should_debug = false; | 874 bool should_debug = false; |
906 return PP_FromBool( | 875 return PP_FromBool( |
907 sender->Send(new NaClHostMsg_NaClDebugEnabledForURL(GURL(alleged_nmf_url), | 876 g_nacl_host_connection.Get().host()->NaClDebugEnabledForURL( |
908 &should_debug)) && | 877 GURL(alleged_nmf_url), &should_debug) && |
909 should_debug); | 878 should_debug); |
910 } | 879 } |
911 | 880 |
912 } // namespace | 881 } // namespace |
913 | 882 |
914 // static | 883 // static |
915 void PPBNaClPrivate::InitializePlugin(PP_Instance instance, | 884 void PPBNaClPrivate::InitializePlugin(PP_Instance instance, |
916 uint32_t argc, | 885 uint32_t argc, |
917 const char* argn[], | 886 const char* argn[], |
918 const char* argv[]) { | 887 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, | 1712 // Mark the request as requesting a PNaCl bitcode file, |
1744 // so that component updater can detect this user action. | 1713 // so that component updater can detect this user action. |
1745 url_request.addHTTPHeaderField( | 1714 url_request.addHTTPHeaderField( |
1746 blink::WebString::fromUTF8("Accept"), | 1715 blink::WebString::fromUTF8("Accept"), |
1747 blink::WebString::fromUTF8("application/x-pnacl, */*")); | 1716 blink::WebString::fromUTF8("application/x-pnacl, */*")); |
1748 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 1717 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
1749 downloader->Load(url_request); | 1718 downloader->Load(url_request); |
1750 } | 1719 } |
1751 | 1720 |
1752 } // namespace nacl | 1721 } // namespace nacl |
OLD | NEW |