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 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 size_t replace_pos; | 537 size_t replace_pos; |
538 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; | 538 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; |
539 replace_pos = r.find_first_not_of(white_list); | 539 replace_pos = r.find_first_not_of(white_list); |
540 while(replace_pos != std::string::npos) { | 540 while(replace_pos != std::string::npos) { |
541 r = r.replace(replace_pos, 1, "_"); | 541 r = r.replace(replace_pos, 1, "_"); |
542 replace_pos = r.find_first_not_of(white_list); | 542 replace_pos = r.find_first_not_of(white_list); |
543 } | 543 } |
544 return r; | 544 return r; |
545 } | 545 } |
546 | 546 |
547 PP_FileHandle GetReadonlyPnaclFd(const char* url) { | 547 PP_FileHandle GetReadonlyPnaclFd(const char* url, |
548 bool is_executable, | |
549 uint64_t* nonce_lo, | |
550 uint64_t* nonce_hi) { | |
548 std::string filename = PnaclComponentURLToFilename(url); | 551 std::string filename = PnaclComponentURLToFilename(url); |
549 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 552 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
550 IPC::Sender* sender = content::RenderThread::Get(); | 553 IPC::Sender* sender = content::RenderThread::Get(); |
551 DCHECK(sender); | 554 DCHECK(sender); |
552 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( | 555 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( |
553 std::string(filename), | 556 std::string(filename), is_executable, |
554 &out_fd))) { | 557 &out_fd, nonce_lo, nonce_hi))) { |
555 return PP_kInvalidFileHandle; | 558 return PP_kInvalidFileHandle; |
556 } | 559 } |
557 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 560 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
558 return PP_kInvalidFileHandle; | 561 return PP_kInvalidFileHandle; |
559 } | 562 } |
560 return IPC::PlatformFileForTransitToPlatformFile(out_fd); | 563 return IPC::PlatformFileForTransitToPlatformFile(out_fd); |
561 } | 564 } |
562 | 565 |
566 void GetReadExecPnaclFd(const char* url, | |
567 PP_NaClFileInfo* out_file_info) { | |
568 *out_file_info = kInvalidNaClFileInfo; | |
569 out_file_info->handle = GetReadonlyPnaclFd(url, true /* is_executable */, | |
570 &out_file_info->token_lo, | |
571 &out_file_info->token_hi); | |
572 } | |
573 | |
563 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { | 574 PP_FileHandle CreateTemporaryFile(PP_Instance instance) { |
564 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); | 575 IPC::PlatformFileForTransit transit_fd = IPC::InvalidPlatformFileForTransit(); |
565 IPC::Sender* sender = content::RenderThread::Get(); | 576 IPC::Sender* sender = content::RenderThread::Get(); |
566 DCHECK(sender); | 577 DCHECK(sender); |
567 if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile( | 578 if (!sender->Send(new NaClHostMsg_NaClCreateTemporaryFile( |
568 &transit_fd))) { | 579 &transit_fd))) { |
569 return PP_kInvalidFileHandle; | 580 return PP_kInvalidFileHandle; |
570 } | 581 } |
571 | 582 |
572 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { | 583 if (transit_fd == IPC::InvalidPlatformFileForTransit()) { |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 | 1122 |
1112 PP_Bool GetPNaClResourceInfo(PP_Instance instance, | 1123 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
1113 const char* filename, | 1124 const char* filename, |
1114 PP_Var* llc_tool_name, | 1125 PP_Var* llc_tool_name, |
1115 PP_Var* ld_tool_name) { | 1126 PP_Var* ld_tool_name) { |
1116 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1127 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1117 DCHECK(load_manager); | 1128 DCHECK(load_manager); |
1118 if (!load_manager) | 1129 if (!load_manager) |
1119 return PP_FALSE; | 1130 return PP_FALSE; |
1120 | 1131 |
1121 base::File file(GetReadonlyPnaclFd(filename)); | 1132 uint64_t nonce_lo = 0; |
1133 uint64_t nonce_hi = 0; | |
1134 base::File file(GetReadonlyPnaclFd(filename, false /* is_executable */, | |
1135 &nonce_lo, &nonce_hi)); | |
1122 if (!file.IsValid()) { | 1136 if (!file.IsValid()) { |
1123 load_manager->ReportLoadError( | 1137 load_manager->ReportLoadError( |
1124 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1138 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1125 "The Portable Native Client (pnacl) component is not " | 1139 "The Portable Native Client (pnacl) component is not " |
1126 "installed. Please consult chrome://components for more " | 1140 "installed. Please consult chrome://components for more " |
1127 "information."); | 1141 "information."); |
1128 return PP_FALSE; | 1142 return PP_FALSE; |
1129 } | 1143 } |
1130 | 1144 |
1131 base::File::Info file_info; | 1145 base::File::Info file_info; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1437 FROM_HERE, | 1451 FROM_HERE, |
1438 base::Bind(callback, | 1452 base::Bind(callback, |
1439 static_cast<int32_t>(PP_ERROR_FAILED), | 1453 static_cast<int32_t>(PP_ERROR_FAILED), |
1440 kInvalidNaClFileInfo)); | 1454 kInvalidNaClFileInfo)); |
1441 return; | 1455 return; |
1442 } | 1456 } |
1443 | 1457 |
1444 // Handle special PNaCl support files which are installed on the user's | 1458 // Handle special PNaCl support files which are installed on the user's |
1445 // machine. | 1459 // machine. |
1446 if (url.find(kPNaClTranslatorBaseUrl, 0) == 0) { | 1460 if (url.find(kPNaClTranslatorBaseUrl, 0) == 0) { |
1447 PP_FileHandle handle = GetReadonlyPnaclFd(url.c_str()); | 1461 PP_NaClFileInfo file_info = kInvalidNaClFileInfo; |
1462 PP_FileHandle handle = GetReadonlyPnaclFd(url.c_str(), | |
1463 false /* executable*/, | |
Nick Bray (chromium)
2014/06/27 21:03:16
nit: space before */
jvoung (off chromium)
2014/06/27 22:30:08
Done.
| |
1464 &file_info.token_lo, | |
1465 &file_info.token_hi); | |
1448 if (handle == PP_kInvalidFileHandle) { | 1466 if (handle == PP_kInvalidFileHandle) { |
1449 base::MessageLoop::current()->PostTask( | 1467 base::MessageLoop::current()->PostTask( |
1450 FROM_HERE, | 1468 FROM_HERE, |
1451 base::Bind(callback, | 1469 base::Bind(callback, |
1452 static_cast<int32_t>(PP_ERROR_FAILED), | 1470 static_cast<int32_t>(PP_ERROR_FAILED), |
1453 kInvalidNaClFileInfo)); | 1471 kInvalidNaClFileInfo)); |
1454 return; | 1472 return; |
1455 } | 1473 } |
1456 // TODO(ncbray): enable the fast loading and validation paths for this type | |
1457 // of file. | |
1458 PP_NaClFileInfo file_info; | |
1459 file_info.handle = handle; | 1474 file_info.handle = handle; |
1460 file_info.token_lo = 0; | |
1461 file_info.token_hi = 0; | |
1462 base::MessageLoop::current()->PostTask( | 1475 base::MessageLoop::current()->PostTask( |
1463 FROM_HERE, | 1476 FROM_HERE, |
1464 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); | 1477 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); |
1465 return; | 1478 return; |
1466 } | 1479 } |
1467 | 1480 |
1468 // We have to ensure that this url resolves relative to the plugin base url | 1481 // We have to ensure that this url resolves relative to the plugin base url |
1469 // before downloading it. | 1482 // before downloading it. |
1470 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); | 1483 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); |
1471 if (!test_gurl.is_valid()) { | 1484 if (!test_gurl.is_valid()) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 DownloadFile(instance, url, | 1597 DownloadFile(instance, url, |
1585 base::Bind(&DidOpenManifestEntry, out_file_info, callback)); | 1598 base::Bind(&DidOpenManifestEntry, out_file_info, callback)); |
1586 } | 1599 } |
1587 | 1600 |
1588 const PPB_NaCl_Private nacl_interface = { | 1601 const PPB_NaCl_Private nacl_interface = { |
1589 &LaunchSelLdr, | 1602 &LaunchSelLdr, |
1590 &StartPpapiProxy, | 1603 &StartPpapiProxy, |
1591 &UrandomFD, | 1604 &UrandomFD, |
1592 &Are3DInterfacesDisabled, | 1605 &Are3DInterfacesDisabled, |
1593 &BrokerDuplicateHandle, | 1606 &BrokerDuplicateHandle, |
1594 &GetReadonlyPnaclFd, | 1607 &GetReadExecPnaclFd, |
1595 &CreateTemporaryFile, | 1608 &CreateTemporaryFile, |
1596 &GetNumberOfProcessors, | 1609 &GetNumberOfProcessors, |
1597 &PPIsNonSFIModeEnabled, | 1610 &PPIsNonSFIModeEnabled, |
1598 &GetNexeFd, | 1611 &GetNexeFd, |
1599 &ReportTranslationFinished, | 1612 &ReportTranslationFinished, |
1600 &DispatchEvent, | 1613 &DispatchEvent, |
1601 &ReportLoadSuccess, | 1614 &ReportLoadSuccess, |
1602 &ReportLoadError, | 1615 &ReportLoadError, |
1603 &ReportLoadAbort, | 1616 &ReportLoadAbort, |
1604 &NexeDidCrash, | 1617 &NexeDidCrash, |
(...skipping 22 matching lines...) Expand all Loading... | |
1627 &OpenManifestEntry | 1640 &OpenManifestEntry |
1628 }; | 1641 }; |
1629 | 1642 |
1630 } // namespace | 1643 } // namespace |
1631 | 1644 |
1632 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1645 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1633 return &nacl_interface; | 1646 return &nacl_interface; |
1634 } | 1647 } |
1635 | 1648 |
1636 } // namespace nacl | 1649 } // namespace nacl |
OLD | NEW |