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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 59 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" |
60 #include "third_party/jsoncpp/source/include/json/reader.h" | 60 #include "third_party/jsoncpp/source/include/json/reader.h" |
61 #include "third_party/jsoncpp/source/include/json/value.h" | 61 #include "third_party/jsoncpp/source/include/json/value.h" |
62 | 62 |
63 namespace nacl { | 63 namespace nacl { |
64 namespace { | 64 namespace { |
65 | 65 |
66 // The pseudo-architecture used to indicate portable native client. | 66 // The pseudo-architecture used to indicate portable native client. |
67 const char* const kPortableArch = "portable"; | 67 const char* const kPortableArch = "portable"; |
68 | 68 |
| 69 // The base URL for resources used by the PNaCl translator processes. |
| 70 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/"; |
| 71 |
69 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > | 72 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > |
70 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; | 73 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; |
71 | 74 |
72 bool InitializePnaclResourceHost() { | 75 bool InitializePnaclResourceHost() { |
73 // Must run on the main thread. | 76 // Must run on the main thread. |
74 content::RenderThread* render_thread = content::RenderThread::Get(); | 77 content::RenderThread* render_thread = content::RenderThread::Get(); |
75 if (!render_thread) | 78 if (!render_thread) |
76 return false; | 79 return false; |
77 if (!g_pnacl_resource_host.Get()) { | 80 if (!g_pnacl_resource_host.Get()) { |
78 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( | 81 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 uint32_t options) { | 516 uint32_t options) { |
514 #if defined(OS_WIN) | 517 #if defined(OS_WIN) |
515 return content::BrokerDuplicateHandle(source_handle, process_id, | 518 return content::BrokerDuplicateHandle(source_handle, process_id, |
516 target_handle, desired_access, | 519 target_handle, desired_access, |
517 options); | 520 options); |
518 #else | 521 #else |
519 return 0; | 522 return 0; |
520 #endif | 523 #endif |
521 } | 524 } |
522 | 525 |
523 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { | 526 // Convert a URL to a filename for GetReadonlyPnaclFd. |
| 527 // Must be kept in sync with PnaclCanOpenFile() in |
| 528 // components/nacl/browser/nacl_file_host.cc. |
| 529 std::string PnaclComponentURLToFilename(const std::string& url) { |
| 530 // PNaCl component URLs aren't arbitrary URLs; they are always either |
| 531 // generated from ManifestResolveKey or PnaclResources::ReadResourceInfo. |
| 532 // So, it's safe to just use string parsing operations here instead of |
| 533 // URL-parsing ones. |
| 534 DCHECK(StartsWithASCII(url, kPNaClTranslatorBaseUrl, true)); |
| 535 std::string r = url.substr(std::string(kPNaClTranslatorBaseUrl).length()); |
| 536 |
| 537 // Use white-listed-chars. |
| 538 size_t replace_pos; |
| 539 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; |
| 540 replace_pos = r.find_first_not_of(white_list); |
| 541 while(replace_pos != std::string::npos) { |
| 542 r = r.replace(replace_pos, 1, "_"); |
| 543 replace_pos = r.find_first_not_of(white_list); |
| 544 } |
| 545 return r; |
| 546 } |
| 547 |
| 548 PP_FileHandle GetReadonlyPnaclFd(const char* url) { |
| 549 std::string filename = PnaclComponentURLToFilename(url); |
524 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); | 550 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); |
525 IPC::Sender* sender = content::RenderThread::Get(); | 551 IPC::Sender* sender = content::RenderThread::Get(); |
526 DCHECK(sender); | 552 DCHECK(sender); |
527 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( | 553 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( |
528 std::string(filename), | 554 std::string(filename), |
529 &out_fd))) { | 555 &out_fd))) { |
530 return base::kInvalidPlatformFileValue; | 556 return base::kInvalidPlatformFileValue; |
531 } | 557 } |
532 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 558 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
533 return base::kInvalidPlatformFileValue; | 559 return base::kInvalidPlatformFileValue; |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 std::string key_string(key); | 1094 std::string key_string(key); |
1069 if (key_string.find(kFilesPrefix) == std::string::npos) { | 1095 if (key_string.find(kFilesPrefix) == std::string::npos) { |
1070 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1096 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1071 if (load_manager) | 1097 if (load_manager) |
1072 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, | 1098 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, |
1073 "key did not start with files/"); | 1099 "key did not start with files/"); |
1074 return PP_FALSE; | 1100 return PP_FALSE; |
1075 } | 1101 } |
1076 std::string key_basename = key_string.substr(kFilesPrefix.length()); | 1102 std::string key_basename = key_string.substr(kFilesPrefix.length()); |
1077 std::string pnacl_url = | 1103 std::string pnacl_url = |
1078 std::string("chrome://pnacl-translator/") + GetSandboxArch() + "/" + | 1104 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + |
1079 key_basename; | 1105 key_basename; |
1080 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); | 1106 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); |
1081 return PP_TRUE; | 1107 return PP_TRUE; |
1082 } | 1108 } |
1083 | 1109 |
1084 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1110 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); |
1085 if (it == g_manifest_map.Get().end()) | 1111 if (it == g_manifest_map.Get().end()) |
1086 return PP_FALSE; | 1112 return PP_FALSE; |
1087 | 1113 |
1088 std::string full_url; | 1114 std::string full_url; |
1089 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); | 1115 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); |
1090 if (ok) | 1116 if (ok) |
1091 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); | 1117 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
1092 return PP_FromBool(ok); | 1118 return PP_FromBool(ok); |
1093 } | 1119 } |
1094 | 1120 |
1095 PP_Bool GetPNaClResourceInfo(PP_Instance instance, | 1121 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
1096 const char* filename, | 1122 const char* filename, |
1097 PP_Var* llc_tool_name, | 1123 PP_Var* llc_tool_name, |
1098 PP_Var* ld_tool_name) { | 1124 PP_Var* ld_tool_name) { |
1099 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1125 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1100 DCHECK(load_manager); | 1126 DCHECK(load_manager); |
1101 if (!load_manager) | 1127 if (!load_manager) |
1102 return PP_FALSE; | 1128 return PP_FALSE; |
1103 | 1129 |
1104 base::PlatformFile file = GetReadonlyPnaclFD(filename); | 1130 base::PlatformFile file = GetReadonlyPnaclFd(filename); |
1105 if (file == base::kInvalidPlatformFileValue) { | 1131 if (file == base::kInvalidPlatformFileValue) { |
1106 load_manager->ReportLoadError( | 1132 load_manager->ReportLoadError( |
1107 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1133 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1108 "The Portable Native Client (pnacl) component is not " | 1134 "The Portable Native Client (pnacl) component is not " |
1109 "installed. Please consult chrome://components for more " | 1135 "installed. Please consult chrome://components for more " |
1110 "information."); | 1136 "information."); |
1111 return PP_FALSE; | 1137 return PP_FALSE; |
1112 } | 1138 } |
1113 | 1139 |
1114 base::PlatformFileInfo file_info; | 1140 base::PlatformFileInfo file_info; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1437 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1412 DCHECK(load_manager); | 1438 DCHECK(load_manager); |
1413 if (!load_manager) { | 1439 if (!load_manager) { |
1414 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1440 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1415 FROM_HERE, | 1441 FROM_HERE, |
1416 base::Bind(callback.func, callback.user_data, | 1442 base::Bind(callback.func, callback.user_data, |
1417 static_cast<int32_t>(PP_ERROR_FAILED))); | 1443 static_cast<int32_t>(PP_ERROR_FAILED))); |
1418 return; | 1444 return; |
1419 } | 1445 } |
1420 | 1446 |
| 1447 // Handle special PNaCl support files which are installed on the user's |
| 1448 // machine. |
| 1449 std::string url_string(url); |
| 1450 if (url_string.find(kPNaClTranslatorBaseUrl, 0) == 0) { |
| 1451 PP_FileHandle handle = GetReadonlyPnaclFd(url); |
| 1452 if (handle == PP_kInvalidFileHandle) { |
| 1453 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1454 FROM_HERE, |
| 1455 base::Bind(callback.func, callback.user_data, |
| 1456 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1457 return; |
| 1458 } |
| 1459 // TODO(ncbray): enable the fast loading and validation paths for this type |
| 1460 // of file. |
| 1461 file_info->handle = handle; |
| 1462 file_info->token_lo = 0; |
| 1463 file_info->token_hi = 0; |
| 1464 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1465 FROM_HERE, |
| 1466 base::Bind(callback.func, callback.user_data, |
| 1467 static_cast<int32_t>(PP_OK))); |
| 1468 return; |
| 1469 } |
| 1470 |
1421 // We have to ensure that this url resolves relative to the plugin base url | 1471 // We have to ensure that this url resolves relative to the plugin base url |
1422 // before downloading it. | 1472 // before downloading it. |
1423 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); | 1473 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); |
1424 if (!test_gurl.is_valid()) { | 1474 if (!test_gurl.is_valid()) { |
1425 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1475 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1426 FROM_HERE, | 1476 FROM_HERE, |
1427 base::Bind(callback.func, callback.user_data, | 1477 base::Bind(callback.func, callback.user_data, |
1428 static_cast<int32_t>(PP_ERROR_FAILED))); | 1478 static_cast<int32_t>(PP_ERROR_FAILED))); |
1429 return; | 1479 return; |
1430 } | 1480 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 base::Owned(tracker), url)); | 1527 base::Owned(tracker), url)); |
1478 file_downloader->Load(url_request); | 1528 file_downloader->Load(url_request); |
1479 } | 1529 } |
1480 | 1530 |
1481 const PPB_NaCl_Private nacl_interface = { | 1531 const PPB_NaCl_Private nacl_interface = { |
1482 &LaunchSelLdr, | 1532 &LaunchSelLdr, |
1483 &StartPpapiProxy, | 1533 &StartPpapiProxy, |
1484 &UrandomFD, | 1534 &UrandomFD, |
1485 &Are3DInterfacesDisabled, | 1535 &Are3DInterfacesDisabled, |
1486 &BrokerDuplicateHandle, | 1536 &BrokerDuplicateHandle, |
1487 &GetReadonlyPnaclFD, | 1537 &GetReadonlyPnaclFd, |
1488 &CreateTemporaryFile, | 1538 &CreateTemporaryFile, |
1489 &GetNumberOfProcessors, | 1539 &GetNumberOfProcessors, |
1490 &PPIsNonSFIModeEnabled, | 1540 &PPIsNonSFIModeEnabled, |
1491 &GetNexeFd, | 1541 &GetNexeFd, |
1492 &ReportTranslationFinished, | 1542 &ReportTranslationFinished, |
1493 &DispatchEvent, | 1543 &DispatchEvent, |
1494 &ReportLoadSuccess, | 1544 &ReportLoadSuccess, |
1495 &ReportLoadError, | 1545 &ReportLoadError, |
1496 &ReportLoadAbort, | 1546 &ReportLoadAbort, |
1497 &NexeDidCrash, | 1547 &NexeDidCrash, |
(...skipping 23 matching lines...) Expand all Loading... |
1521 &DownloadFile | 1571 &DownloadFile |
1522 }; | 1572 }; |
1523 | 1573 |
1524 } // namespace | 1574 } // namespace |
1525 | 1575 |
1526 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1576 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1527 return &nacl_interface; | 1577 return &nacl_interface; |
1528 } | 1578 } |
1529 | 1579 |
1530 } // namespace nacl | 1580 } // namespace nacl |
OLD | NEW |