 Chromium Code Reviews
 Chromium Code Reviews Issue 649603004:
  Non-SFI NaCl: Batch-open resource files  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 649603004:
  Non-SFI NaCl: Batch-open resource files  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" | 
| 6 | 6 | 
| 7 #include <numeric> | 7 #include <numeric> | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| 11 #include "base/bind.h" | 11 #include "base/bind.h" | 
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" | 
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" | 
| 14 #include "base/cpu.h" | 14 #include "base/cpu.h" | 
| 15 #include "base/files/file.h" | 15 #include "base/files/file.h" | 
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" | 
| 17 #include "base/logging.h" | 17 #include "base/logging.h" | 
| 18 #include "base/macros.h" | |
| 18 #include "base/rand_util.h" | 19 #include "base/rand_util.h" | 
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" | 
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" | 
| 21 #include "components/nacl/common/nacl_host_messages.h" | 22 #include "components/nacl/common/nacl_host_messages.h" | 
| 22 #include "components/nacl/common/nacl_messages.h" | 23 #include "components/nacl/common/nacl_messages.h" | 
| 23 #include "components/nacl/common/nacl_nonsfi_util.h" | 24 #include "components/nacl/common/nacl_nonsfi_util.h" | 
| 24 #include "components/nacl/common/nacl_switches.h" | 25 #include "components/nacl/common/nacl_switches.h" | 
| 25 #include "components/nacl/common/nacl_types.h" | 26 #include "components/nacl/common/nacl_types.h" | 
| 26 #include "components/nacl/renderer/file_downloader.h" | 27 #include "components/nacl/renderer/file_downloader.h" | 
| 27 #include "components/nacl/renderer/histogram.h" | 28 #include "components/nacl/renderer/histogram.h" | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 56 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 57 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 
| 57 #include "third_party/WebKit/public/web/WebDocument.h" | 58 #include "third_party/WebKit/public/web/WebDocument.h" | 
| 58 #include "third_party/WebKit/public/web/WebElement.h" | 59 #include "third_party/WebKit/public/web/WebElement.h" | 
| 59 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 60 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 
| 60 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 61 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 
| 61 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 62 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 
| 62 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 63 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 
| 63 #include "third_party/jsoncpp/source/include/json/reader.h" | 64 #include "third_party/jsoncpp/source/include/json/reader.h" | 
| 64 #include "third_party/jsoncpp/source/include/json/value.h" | 65 #include "third_party/jsoncpp/source/include/json/value.h" | 
| 65 | 66 | 
| 67 #if defined(OS_POSIX) | |
| 68 #include "ipc/file_descriptor_set_posix.h" | |
| 69 #endif | |
| 70 | |
| 66 namespace nacl { | 71 namespace nacl { | 
| 67 namespace { | 72 namespace { | 
| 68 | 73 | 
| 69 // The pseudo-architecture used to indicate portable native client. | 74 // The pseudo-architecture used to indicate portable native client. | 
| 70 const char* const kPortableArch = "portable"; | 75 const char* const kPortableArch = "portable"; | 
| 71 | 76 | 
| 72 // The base URL for resources used by the PNaCl translator processes. | 77 // The base URL for resources used by the PNaCl translator processes. | 
| 73 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/"; | 78 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/"; | 
| 74 | 79 | 
| 80 // The maximum number of resource files DownloadNexe() can open. | |
| 81 const size_t kMaxPreOpenResourceFiles = 121; | |
| 82 | |
| 83 #if defined(OS_POSIX) | |
| 84 // On POSIX platforms, the maximum number of files a process can pass to | |
| 85 // another is limited to kMaxDescriptorsPerMessage which is 128. Since | |
| 86 // the browser process may use up to 7 descriptors for passing non-resource | |
| 87 // files when creating the NaCl plugin process, kMaxPreOpenResourceFiles | |
| 88 // must be smaller than or equal to 121. | |
| 89 COMPILE_ASSERT(kMaxPreOpenResourceFiles <= | |
| 90 FileDescriptorSet::kMaxDescriptorsPerMessage - 7, | |
| 91 k_max_pre_open_resource_files_too_large); | |
| 92 #endif | |
| 93 | |
| 75 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > | 94 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > | 
| 76 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; | 95 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; | 
| 77 | 96 | 
| 78 bool InitializePnaclResourceHost() { | 97 bool InitializePnaclResourceHost() { | 
| 79 // Must run on the main thread. | 98 // Must run on the main thread. | 
| 80 content::RenderThread* render_thread = content::RenderThread::Get(); | 99 content::RenderThread* render_thread = content::RenderThread::Get(); | 
| 81 if (!render_thread) | 100 if (!render_thread) | 
| 82 return false; | 101 return false; | 
| 83 if (!g_pnacl_resource_host.Get().get()) { | 102 if (!g_pnacl_resource_host.Get().get()) { | 
| 84 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( | 103 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( | 
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 DCHECK(pp_process_type > PP_UNKNOWN_NACL_PROCESS_TYPE && | 313 DCHECK(pp_process_type > PP_UNKNOWN_NACL_PROCESS_TYPE && | 
| 295 pp_process_type < PP_NUM_NACL_PROCESS_TYPES); | 314 pp_process_type < PP_NUM_NACL_PROCESS_TYPES); | 
| 296 return static_cast<NaClAppProcessType>(pp_process_type); | 315 return static_cast<NaClAppProcessType>(pp_process_type); | 
| 297 } | 316 } | 
| 298 | 317 | 
| 299 // Launch NaCl's sel_ldr process. | 318 // Launch NaCl's sel_ldr process. | 
| 300 void LaunchSelLdr(PP_Instance instance, | 319 void LaunchSelLdr(PP_Instance instance, | 
| 301 PP_Bool main_service_runtime, | 320 PP_Bool main_service_runtime, | 
| 302 const char* alleged_url, | 321 const char* alleged_url, | 
| 303 const PP_NaClFileInfo* nexe_file_info, | 322 const PP_NaClFileInfo* nexe_file_info, | 
| 323 const PP_NaClResourceFileHandle* resource_file_handles, | |
| 324 uint32_t resource_file_handles_len, | |
| 304 PP_Bool uses_nonsfi_mode, | 325 PP_Bool uses_nonsfi_mode, | 
| 305 PP_Bool enable_ppapi_dev, | 326 PP_Bool enable_ppapi_dev, | 
| 306 PP_NaClAppProcessType pp_process_type, | 327 PP_NaClAppProcessType pp_process_type, | 
| 307 void* imc_handle, | 328 void* imc_handle, | 
| 308 PP_CompletionCallback callback) { | 329 PP_CompletionCallback callback) { | 
| 309 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 330 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 
| 310 BelongsToCurrentThread()); | 331 BelongsToCurrentThread()); | 
| 311 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); | 332 NaClAppProcessType process_type = PP_ToNaClAppProcessType(pp_process_type); | 
| 312 // Create the manifest service proxy here, so on error case, it will be | 333 // Create the manifest service proxy here, so on error case, it will be | 
| 313 // destructed (without passing it to ManifestServiceChannel). | 334 // destructed (without passing it to ManifestServiceChannel). | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 // must also check on the trusted side of the proxy. | 368 // must also check on the trusted side of the proxy. | 
| 348 if (enable_ppapi_dev) | 369 if (enable_ppapi_dev) | 
| 349 perm_bits |= ppapi::PERMISSION_DEV; | 370 perm_bits |= ppapi::PERMISSION_DEV; | 
| 350 instance_info.permissions = | 371 instance_info.permissions = | 
| 351 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); | 372 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); | 
| 352 std::string error_message_string; | 373 std::string error_message_string; | 
| 353 NaClLaunchResult launch_result; | 374 NaClLaunchResult launch_result; | 
| 354 | 375 | 
| 355 IPC::PlatformFileForTransit nexe_for_transit = | 376 IPC::PlatformFileForTransit nexe_for_transit = | 
| 356 IPC::InvalidPlatformFileForTransit(); | 377 IPC::InvalidPlatformFileForTransit(); | 
| 378 std::vector<NaClLaunchParams::ResourceFileInfo> resource_files_info; | |
| 379 | |
| 357 #if defined(OS_POSIX) | 380 #if defined(OS_POSIX) | 
| 358 if (nexe_file_info->handle != PP_kInvalidFileHandle) | 381 if (nexe_file_info->handle != PP_kInvalidFileHandle) | 
| 359 nexe_for_transit = base::FileDescriptor(nexe_file_info->handle, true); | 382 nexe_for_transit = base::FileDescriptor(nexe_file_info->handle, true); | 
| 383 for (size_t i = 0; i < resource_file_handles_len; ++i) { | |
| 384 NaClLaunchParams::ResourceFileInfo resource_file_info( | |
| 385 base::FileDescriptor(resource_file_handles[i].handle, true), | |
| 386 resource_file_handles[i].token_lo, | |
| 387 resource_file_handles[i].token_hi, | |
| 388 resource_file_handles[i].key); | |
| 389 resource_files_info.push_back(resource_file_info); | |
| 390 } | |
| 360 #elif defined(OS_WIN) | 391 #elif defined(OS_WIN) | 
| 361 // Duplicate the handle on the browser side instead of the renderer. | 392 // Duplicate the handle on the browser side instead of the renderer. | 
| 362 // This is because BrokerGetFileForProcess isn't part of content/public, and | 393 // This is because BrokerGetFileForProcess isn't part of content/public, and | 
| 363 // it's simpler to do the duplication in the browser anyway. | 394 // it's simpler to do the duplication in the browser anyway. | 
| 364 nexe_for_transit = nexe_file_info->handle; | 395 nexe_for_transit = nexe_file_info->handle; | 
| 396 // TODO(yusukes): Support pre-opening resource files. | |
| 397 CHECK(resource_file_handles_len == 0); | |
| 365 #else | 398 #else | 
| 366 #error Unsupported target platform. | 399 #error Unsupported target platform. | 
| 367 #endif | 400 #endif | 
| 368 if (!sender->Send(new NaClHostMsg_LaunchNaCl( | 401 if (!sender->Send(new NaClHostMsg_LaunchNaCl( | 
| 369 NaClLaunchParams( | 402 NaClLaunchParams( | 
| 370 instance_info.url.spec(), | 403 instance_info.url.spec(), | 
| 371 nexe_for_transit, | 404 nexe_for_transit, | 
| 372 nexe_file_info->token_lo, | 405 nexe_file_info->token_lo, | 
| 373 nexe_file_info->token_hi, | 406 nexe_file_info->token_hi, | 
| 407 resource_files_info, | |
| 374 routing_id, | 408 routing_id, | 
| 375 perm_bits, | 409 perm_bits, | 
| 376 PP_ToBool(uses_nonsfi_mode), | 410 PP_ToBool(uses_nonsfi_mode), | 
| 377 process_type), | 411 process_type), | 
| 378 &launch_result, | 412 &launch_result, | 
| 379 &error_message_string))) { | 413 &error_message_string))) { | 
| 380 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 414 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 
| 381 FROM_HERE, | 415 FROM_HERE, | 
| 382 base::Bind(callback.func, callback.user_data, | 416 base::Bind(callback.func, callback.user_data, | 
| 383 static_cast<int32_t>(PP_ERROR_FAILED))); | 417 static_cast<int32_t>(PP_ERROR_FAILED))); | 
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 } | 708 } | 
| 675 } | 709 } | 
| 676 | 710 | 
| 677 // If the resource host isn't initialized, don't try to do that here. | 711 // If the resource host isn't initialized, don't try to do that here. | 
| 678 // Just return because something is already very wrong. | 712 // Just return because something is already very wrong. | 
| 679 if (g_pnacl_resource_host.Get().get() == NULL) | 713 if (g_pnacl_resource_host.Get().get() == NULL) | 
| 680 return; | 714 return; | 
| 681 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); | 715 g_pnacl_resource_host.Get()->ReportTranslationFinished(instance, success); | 
| 682 } | 716 } | 
| 683 | 717 | 
| 684 PP_FileHandle OpenNaClExecutable(PP_Instance instance, | 718 PP_FileHandle OpenNaClResources( | 
| 685 const char* file_url, | 719 PP_Instance instance, | 
| 686 uint64_t* nonce_lo, | 720 const char* file_url, | 
| 687 uint64_t* nonce_hi) { | 721 uint64_t* nonce_lo, | 
| 722 uint64_t* nonce_hi, | |
| 723 const std::vector<std::string>& resource_file_urls, | |
| 724 PP_NaClResourceFileHandle** out_resource_file_handles, | |
| 725 uint32_t* out_resource_file_handles_len) { | |
| 688 // Fast path only works for installed file URLs. | 726 // Fast path only works for installed file URLs. | 
| 689 GURL gurl(file_url); | 727 GURL gurl(file_url); | 
| 690 if (!gurl.SchemeIs("chrome-extension")) | 728 if (!gurl.SchemeIs("chrome-extension")) | 
| 691 return PP_kInvalidFileHandle; | 729 return PP_kInvalidFileHandle; | 
| 692 | 730 | 
| 693 content::PepperPluginInstance* plugin_instance = | 731 content::PepperPluginInstance* plugin_instance = | 
| 694 content::PepperPluginInstance::Get(instance); | 732 content::PepperPluginInstance::Get(instance); | 
| 695 if (!plugin_instance) | 733 if (!plugin_instance) | 
| 696 return PP_kInvalidFileHandle; | 734 return PP_kInvalidFileHandle; | 
| 697 // IMPORTANT: Make sure the document can request the given URL. If we don't | 735 // IMPORTANT: Make sure the document can request the given URL. If we don't | 
| 698 // check, a malicious app could probe the extension system. This enforces a | 736 // check, a malicious app could probe the extension system. This enforces a | 
| 699 // same-origin policy which prevents the app from requesting resources from | 737 // same-origin policy which prevents the app from requesting resources from | 
| 700 // another app. | 738 // another app. | 
| 701 blink::WebSecurityOrigin security_origin = | 739 blink::WebSecurityOrigin security_origin = | 
| 702 plugin_instance->GetContainer()->element().document().securityOrigin(); | 740 plugin_instance->GetContainer()->element().document().securityOrigin(); | 
| 703 if (!security_origin.canRequest(gurl)) | 741 if (!security_origin.canRequest(gurl)) | 
| 704 return PP_kInvalidFileHandle; | 742 return PP_kInvalidFileHandle; | 
| 705 | 743 | 
| 706 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 744 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 
| 707 IPC::Sender* sender = content::RenderThread::Get(); | 745 IPC::Sender* sender = content::RenderThread::Get(); | 
| 708 DCHECK(sender); | 746 DCHECK(sender); | 
| 709 *nonce_lo = 0; | 747 *nonce_lo = 0; | 
| 710 *nonce_hi = 0; | 748 *nonce_hi = 0; | 
| 711 base::FilePath file_path; | 749 base::FilePath file_path; | 
| 712 if (!sender->Send( | 750 | 
| 713 new NaClHostMsg_OpenNaClExecutable(GetRoutingID(instance), | 751 std::vector<GURL> resource_urls; | 
| 714 GURL(file_url), | 752 for (size_t i = 0; i < resource_file_urls.size(); ++i) { | 
| 715 &out_fd, | 753 GURL gurl(resource_file_urls[i]); | 
| 716 nonce_lo, | 754 if (!gurl.SchemeIs("chrome-extension")) | 
| 717 nonce_hi))) { | 755 return PP_kInvalidFileHandle; | 
| 756 if (!security_origin.canRequest(gurl)) | |
| 757 return PP_kInvalidFileHandle; | |
| 758 resource_urls.push_back(gurl); | |
| 759 } | |
| 760 | |
| 761 nacl::NaClOpenExecutableResult open_result; | |
| 762 if (!sender->Send(new NaClHostMsg_OpenNaClResources(GetRoutingID(instance), | |
| 763 GURL(file_url), | |
| 764 resource_urls, | |
| 765 &open_result))) { | |
| 718 return PP_kInvalidFileHandle; | 766 return PP_kInvalidFileHandle; | 
| 719 } | 767 } | 
| 720 | 768 | 
| 721 if (out_fd == IPC::InvalidPlatformFileForTransit()) | 769 if (open_result.file_info.file == IPC::InvalidPlatformFileForTransit()) | 
| 722 return PP_kInvalidFileHandle; | 770 return PP_kInvalidFileHandle; | 
| 723 | 771 | 
| 772 for (size_t i = 0; i < open_result.resource_files_info.size(); ++i) { | |
| 773 if (open_result.resource_files_info[i].file == | |
| 774 IPC::InvalidPlatformFileForTransit()) { | |
| 775 DLOG(ERROR) << "Could not open a resource file: " | |
| 776 << resource_file_urls[i]; | |
| 777 return PP_kInvalidFileHandle; | |
| 778 } | |
| 779 } | |
| 780 | |
| 781 out_fd = open_result.file_info.file; | |
| 782 *nonce_lo = open_result.file_info.file_token_lo; | |
| 783 *nonce_hi = open_result.file_info.file_token_hi; | |
| 784 | |
| 785 if (out_resource_file_handles && !open_result.resource_files_info.empty()) { | |
| 786 DCHECK(out_resource_file_handles_len); | |
| 787 *out_resource_file_handles_len = | |
| 788 static_cast<uint32_t>(open_result.resource_files_info.size()); | |
| 789 *out_resource_file_handles = | |
| 790 new PP_NaClResourceFileHandle[*out_resource_file_handles_len]; | |
| 791 for (size_t i = 0; i < *out_resource_file_handles_len; ++i) { | |
| 792 PP_NaClResourceFileHandle& entry = (*out_resource_file_handles)[i]; | |
| 793 entry.handle = IPC::PlatformFileForTransitToPlatformFile( | |
| 794 open_result.resource_files_info[i].file); | |
| 795 entry.token_lo = open_result.resource_files_info[i].file_token_lo; | |
| 796 entry.token_hi = open_result.resource_files_info[i].file_token_hi; | |
| 797 entry.key = NULL; // DownloadNexe fills this later. | |
| 798 } | |
| 799 } | |
| 800 | |
| 724 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | 801 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | 
| 725 } | 802 } | 
| 726 | 803 | 
| 727 void DispatchEvent(PP_Instance instance, | 804 void DispatchEvent(PP_Instance instance, | 
| 728 PP_NaClEventType event_type, | 805 PP_NaClEventType event_type, | 
| 729 const char *resource_url, | 806 const char *resource_url, | 
| 730 PP_Bool length_is_computable, | 807 PP_Bool length_is_computable, | 
| 731 uint64_t loaded_bytes, | 808 uint64_t loaded_bytes, | 
| 732 uint64_t total_bytes) { | 809 uint64_t total_bytes) { | 
| 733 ProgressEvent event(event_type, | 810 ProgressEvent event(event_type, | 
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 }; | 1284 }; | 
| 1208 | 1285 | 
| 1209 void DownloadNexeCompletion(const DownloadNexeRequest& request, | 1286 void DownloadNexeCompletion(const DownloadNexeRequest& request, | 
| 1210 PP_NaClFileInfo* out_file_info, | 1287 PP_NaClFileInfo* out_file_info, | 
| 1211 FileDownloader::Status status, | 1288 FileDownloader::Status status, | 
| 1212 base::File target_file, | 1289 base::File target_file, | 
| 1213 int http_status); | 1290 int http_status); | 
| 1214 | 1291 | 
| 1215 void DownloadNexe(PP_Instance instance, | 1292 void DownloadNexe(PP_Instance instance, | 
| 1216 const char* url, | 1293 const char* url, | 
| 1294 PP_Bool download_resource_files, | |
| 1217 PP_NaClFileInfo* out_file_info, | 1295 PP_NaClFileInfo* out_file_info, | 
| 1296 PP_NaClResourceFileHandle** out_resource_file_handles, | |
| 1297 uint32_t* out_resource_file_handles_len, | |
| 1218 PP_CompletionCallback callback) { | 1298 PP_CompletionCallback callback) { | 
| 1219 CHECK(url); | 1299 CHECK(url); | 
| 1220 CHECK(out_file_info); | 1300 CHECK(out_file_info); | 
| 1301 CHECK(!download_resource_files || out_resource_file_handles); | |
| 1302 | |
| 1221 DownloadNexeRequest request; | 1303 DownloadNexeRequest request; | 
| 1222 request.instance = instance; | 1304 request.instance = instance; | 
| 1223 request.url = url; | 1305 request.url = url; | 
| 1224 request.callback = callback; | 1306 request.callback = callback; | 
| 1225 request.start_time = base::Time::Now(); | 1307 request.start_time = base::Time::Now(); | 
| 1226 | 1308 | 
| 1309 std::vector< | |
| 1310 std::pair<std::string /*url*/, std::string /*key*/> > resource_files; | |
| 1311 std::vector<std::string> resource_file_urls; | |
| 1312 | |
| 1313 if (download_resource_files) { | |
| 1314 JsonManifest* manifest = GetJsonManifest(instance); | |
| 1315 if (manifest) | |
| 1316 manifest->GetFiles(&resource_files); | |
| 1317 if (resource_files.size() > kMaxPreOpenResourceFiles) | |
| 1318 resource_files.resize(kMaxPreOpenResourceFiles); | |
| 1319 for (size_t i = 0; i < resource_files.size(); ++i) { | |
| 1320 resource_file_urls.push_back(resource_files[i].first); | |
| 1321 } | |
| 1322 } | |
| 1323 | |
| 1227 // Try the fast path for retrieving the file first. | 1324 // Try the fast path for retrieving the file first. | 
| 1228 PP_FileHandle handle = OpenNaClExecutable(instance, | 1325 PP_FileHandle handle = OpenNaClResources(instance, | 
| 1229 url, | 1326 url, | 
| 1230 &out_file_info->token_lo, | 1327 &out_file_info->token_lo, | 
| 1231 &out_file_info->token_hi); | 1328 &out_file_info->token_hi, | 
| 1329 resource_file_urls, | |
| 1330 out_resource_file_handles, | |
| 1331 out_resource_file_handles_len); | |
| 1232 if (handle != PP_kInvalidFileHandle) { | 1332 if (handle != PP_kInvalidFileHandle) { | 
| 1333 if (!resource_files.empty()) { | |
| 1334 for (size_t i = 0; i < resource_files.size(); ++i) { | |
| 1335 PP_NaClResourceFileHandle& entry = (*out_resource_file_handles)[i]; | |
| 
teravest
2014/11/10 20:36:12
Please use a pointer instead of a reference here.
 
Yusuke Sato
2014/11/11 00:58:35
Done.
 | |
| 1336 CHECK(entry.handle != PP_kInvalidFileHandle) << i; | |
| 1337 entry.key = strdup(resource_files[i].second.c_str()); | |
| 1338 } | |
| 1339 } | |
| 1233 DownloadNexeCompletion(request, | 1340 DownloadNexeCompletion(request, | 
| 1234 out_file_info, | 1341 out_file_info, | 
| 1235 FileDownloader::SUCCESS, | 1342 FileDownloader::SUCCESS, | 
| 1236 base::File(handle), | 1343 base::File(handle), | 
| 1237 200); | 1344 200); | 
| 1238 return; | 1345 return; | 
| 1239 } | 1346 } | 
| 1240 | 1347 | 
| 1241 // The fast path didn't work, we'll fetch the file using URLLoader and write | 1348 // The fast path didn't work, we'll fetch the file using URLLoader and write | 
| 1242 // it to local storage. | 1349 // it to local storage. | 
| 1243 base::File target_file(CreateTemporaryFile(instance)); | 1350 base::File target_file(CreateTemporaryFile(instance)); | 
| 1244 GURL gurl(url); | 1351 GURL gurl(url); | 
| 1245 | 1352 | 
| 1353 // On the slow path, do not retry to pre-open the resource files. | |
| 1354 if (out_resource_file_handles) | |
| 1355 *out_resource_file_handles = NULL; | |
| 1356 | |
| 1246 content::PepperPluginInstance* plugin_instance = | 1357 content::PepperPluginInstance* plugin_instance = | 
| 1247 content::PepperPluginInstance::Get(instance); | 1358 content::PepperPluginInstance::Get(instance); | 
| 1248 if (!plugin_instance) { | 1359 if (!plugin_instance) { | 
| 1249 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1360 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 
| 1250 FROM_HERE, | 1361 FROM_HERE, | 
| 1251 base::Bind(callback.func, callback.user_data, | 1362 base::Bind(callback.func, callback.user_data, | 
| 1252 static_cast<int32_t>(PP_ERROR_FAILED))); | 1363 static_cast<int32_t>(PP_ERROR_FAILED))); | 
| 1253 } | 1364 } | 
| 1254 const blink::WebDocument& document = | 1365 const blink::WebDocument& document = | 
| 1255 plugin_instance->GetContainer()->element().document(); | 1366 plugin_instance->GetContainer()->element().document(); | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1373 FROM_HERE, | 1484 FROM_HERE, | 
| 1374 base::Bind(callback, | 1485 base::Bind(callback, | 
| 1375 static_cast<int32_t>(PP_ERROR_FAILED), | 1486 static_cast<int32_t>(PP_ERROR_FAILED), | 
| 1376 kInvalidNaClFileInfo)); | 1487 kInvalidNaClFileInfo)); | 
| 1377 return; | 1488 return; | 
| 1378 } | 1489 } | 
| 1379 | 1490 | 
| 1380 // Try the fast path for retrieving the file first. | 1491 // Try the fast path for retrieving the file first. | 
| 1381 uint64_t file_token_lo = 0; | 1492 uint64_t file_token_lo = 0; | 
| 1382 uint64_t file_token_hi = 0; | 1493 uint64_t file_token_hi = 0; | 
| 1383 PP_FileHandle file_handle = OpenNaClExecutable(instance, | 1494 PP_FileHandle file_handle = OpenNaClResources(instance, | 
| 1384 url.c_str(), | 1495 url.c_str(), | 
| 1385 &file_token_lo, | 1496 &file_token_lo, | 
| 1386 &file_token_hi); | 1497 &file_token_hi, | 
| 1498 std::vector<std::string>(), | |
| 1499 NULL, | |
| 1500 NULL); | |
| 1387 if (file_handle != PP_kInvalidFileHandle) { | 1501 if (file_handle != PP_kInvalidFileHandle) { | 
| 1388 PP_NaClFileInfo file_info; | 1502 PP_NaClFileInfo file_info; | 
| 1389 file_info.handle = file_handle; | 1503 file_info.handle = file_handle; | 
| 1390 file_info.token_lo = file_token_lo; | 1504 file_info.token_lo = file_token_lo; | 
| 1391 file_info.token_hi = file_token_hi; | 1505 file_info.token_hi = file_token_hi; | 
| 1392 base::MessageLoop::current()->PostTask( | 1506 base::MessageLoop::current()->PostTask( | 
| 1393 FROM_HERE, | 1507 FROM_HERE, | 
| 1394 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); | 1508 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); | 
| 1395 return; | 1509 return; | 
| 1396 } | 1510 } | 
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1698 &StreamPexe | 1812 &StreamPexe | 
| 1699 }; | 1813 }; | 
| 1700 | 1814 | 
| 1701 } // namespace | 1815 } // namespace | 
| 1702 | 1816 | 
| 1703 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1817 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 
| 1704 return &nacl_interface; | 1818 return &nacl_interface; | 
| 1705 } | 1819 } | 
| 1706 | 1820 | 
| 1707 } // namespace nacl | 1821 } // namespace nacl | 
| OLD | NEW |