| 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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); | 1073 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
| 1074 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); | 1074 *pp_uses_nonsfi_mode = PP_FromBool(uses_nonsfi_mode); |
| 1075 return PP_TRUE; | 1075 return PP_TRUE; |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 if (load_manager) | 1078 if (load_manager) |
| 1079 load_manager->ReportLoadError(error_info.error, error_info.string); | 1079 load_manager->ReportLoadError(error_info.error, error_info.string); |
| 1080 return PP_FALSE; | 1080 return PP_FALSE; |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 // TODO(teravest): Refactor DownloadFile/DownloadNexe out to their own file; | 1083 PP_Bool ManifestResolveKey(PP_Instance instance, |
| 1084 // this one is getting way too messy. | 1084 PP_Bool is_helper_process, |
| 1085 void DownloadFile(PP_Instance instance, | 1085 const char* key, |
| 1086 const std::string& url, | 1086 PP_Var* pp_full_url, |
| 1087 struct PP_NaClFileInfo* file_info, | 1087 PP_PNaClOptions* pnacl_options) { |
| 1088 struct PP_CompletionCallback callback); | |
| 1089 | |
| 1090 void OpenManifestEntry(PP_Instance instance, | |
| 1091 PP_Bool is_helper_process, | |
| 1092 const char* key, | |
| 1093 PP_NaClFileInfo* out_file_info, | |
| 1094 PP_CompletionCallback callback) { | |
| 1095 std::string resolved_url; | |
| 1096 | |
| 1097 // For "helper" processes (llc and ld), we resolve keys manually as there is | 1088 // For "helper" processes (llc and ld), we resolve keys manually as there is |
| 1098 // no existing .nmf file to parse. | 1089 // no existing .nmf file to parse. |
| 1099 if (PP_ToBool(is_helper_process)) { | 1090 if (PP_ToBool(is_helper_process)) { |
| 1091 pnacl_options->translate = PP_FALSE; |
| 1100 // We can only resolve keys in the files/ namespace. | 1092 // We can only resolve keys in the files/ namespace. |
| 1101 const std::string kFilesPrefix = "files/"; | 1093 const std::string kFilesPrefix = "files/"; |
| 1102 std::string key_string(key); | 1094 std::string key_string(key); |
| 1103 if (key_string.find(kFilesPrefix) == std::string::npos) { | 1095 if (key_string.find(kFilesPrefix) == std::string::npos) { |
| 1104 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1096 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1105 if (load_manager) | 1097 if (load_manager) |
| 1106 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, | 1098 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, |
| 1107 "key did not start with files/"); | 1099 "key did not start with files/"); |
| 1108 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1100 return PP_FALSE; |
| 1109 FROM_HERE, | |
| 1110 base::Bind(callback.func, callback.user_data, | |
| 1111 static_cast<int32_t>(PP_ERROR_FAILED))); | |
| 1112 return; | |
| 1113 } | 1101 } |
| 1114 std::string key_basename = key_string.substr(kFilesPrefix.length()); | 1102 std::string key_basename = key_string.substr(kFilesPrefix.length()); |
| 1115 resolved_url = | 1103 std::string pnacl_url = |
| 1116 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + | 1104 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" + |
| 1117 key_basename; | 1105 key_basename; |
| 1118 } else { | 1106 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); |
| 1119 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); | 1107 return PP_TRUE; |
| 1120 if (it == g_manifest_map.Get().end()) { | |
| 1121 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
| 1122 FROM_HERE, | |
| 1123 base::Bind(callback.func, callback.user_data, | |
| 1124 static_cast<int32_t>(PP_ERROR_FAILED))); | |
| 1125 return; | |
| 1126 } | |
| 1127 | |
| 1128 PP_PNaClOptions pnacl_options; | |
| 1129 bool ok = it->second->ResolveKey(key, &resolved_url, &pnacl_options); | |
| 1130 // We don't support OpenManifestEntry for files that require PNaCl | |
| 1131 // translation. | |
| 1132 if (!ok || pnacl_options.translate) { | |
| 1133 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
| 1134 FROM_HERE, | |
| 1135 base::Bind(callback.func, callback.user_data, | |
| 1136 static_cast<int32_t>(PP_ERROR_FAILED))); | |
| 1137 return; | |
| 1138 } | |
| 1139 } | 1108 } |
| 1140 | 1109 |
| 1141 // Hand off to DownloadFile to perform fetching the actual file. | 1110 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); |
| 1142 DownloadFile(instance, resolved_url, out_file_info, callback); | 1111 if (it == g_manifest_map.Get().end()) |
| 1112 return PP_FALSE; |
| 1113 |
| 1114 std::string full_url; |
| 1115 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); |
| 1116 if (ok) |
| 1117 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); |
| 1118 return PP_FromBool(ok); |
| 1143 } | 1119 } |
| 1144 | 1120 |
| 1145 PP_Bool GetPNaClResourceInfo(PP_Instance instance, | 1121 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
| 1146 const char* filename, | 1122 const char* filename, |
| 1147 PP_Var* llc_tool_name, | 1123 PP_Var* llc_tool_name, |
| 1148 PP_Var* ld_tool_name) { | 1124 PP_Var* ld_tool_name) { |
| 1149 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1125 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1150 DCHECK(load_manager); | 1126 DCHECK(load_manager); |
| 1151 if (!load_manager) | 1127 if (!load_manager) |
| 1152 return PP_FALSE; | 1128 return PP_FALSE; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 int32_t pp_error = FileDownloaderToPepperError(status); | 1421 int32_t pp_error = FileDownloaderToPepperError(status); |
| 1446 if (pp_error == PP_OK) { | 1422 if (pp_error == PP_OK) { |
| 1447 file_info->handle = file; | 1423 file_info->handle = file; |
| 1448 file_info->token_lo = 0; | 1424 file_info->token_lo = 0; |
| 1449 file_info->token_hi = 0; | 1425 file_info->token_hi = 0; |
| 1450 } | 1426 } |
| 1451 callback.func(callback.user_data, pp_error); | 1427 callback.func(callback.user_data, pp_error); |
| 1452 } | 1428 } |
| 1453 | 1429 |
| 1454 void DownloadFile(PP_Instance instance, | 1430 void DownloadFile(PP_Instance instance, |
| 1455 const std::string& url, | 1431 const char* url, |
| 1456 struct PP_NaClFileInfo* file_info, | 1432 struct PP_NaClFileInfo* file_info, |
| 1457 struct PP_CompletionCallback callback) { | 1433 struct PP_CompletionCallback callback) { |
| 1434 CHECK(url); |
| 1458 CHECK(file_info); | 1435 CHECK(file_info); |
| 1459 | 1436 |
| 1460 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1437 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1461 DCHECK(load_manager); | 1438 DCHECK(load_manager); |
| 1462 if (!load_manager) { | 1439 if (!load_manager) { |
| 1463 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1440 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1464 FROM_HERE, | 1441 FROM_HERE, |
| 1465 base::Bind(callback.func, callback.user_data, | 1442 base::Bind(callback.func, callback.user_data, |
| 1466 static_cast<int32_t>(PP_ERROR_FAILED))); | 1443 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1467 return; | 1444 return; |
| 1468 } | 1445 } |
| 1469 | 1446 |
| 1470 // Handle special PNaCl support files which are installed on the user's | 1447 // Handle special PNaCl support files which are installed on the user's |
| 1471 // machine. | 1448 // machine. |
| 1472 if (url.find(kPNaClTranslatorBaseUrl, 0) == 0) { | 1449 std::string url_string(url); |
| 1473 PP_FileHandle handle = GetReadonlyPnaclFd(url.c_str()); | 1450 if (url_string.find(kPNaClTranslatorBaseUrl, 0) == 0) { |
| 1451 PP_FileHandle handle = GetReadonlyPnaclFd(url); |
| 1474 if (handle == PP_kInvalidFileHandle) { | 1452 if (handle == PP_kInvalidFileHandle) { |
| 1475 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1453 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1476 FROM_HERE, | 1454 FROM_HERE, |
| 1477 base::Bind(callback.func, callback.user_data, | 1455 base::Bind(callback.func, callback.user_data, |
| 1478 static_cast<int32_t>(PP_ERROR_FAILED))); | 1456 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1479 return; | 1457 return; |
| 1480 } | 1458 } |
| 1481 // TODO(ncbray): enable the fast loading and validation paths for this type | 1459 // TODO(ncbray): enable the fast loading and validation paths for this type |
| 1482 // of file. | 1460 // of file. |
| 1483 file_info->handle = handle; | 1461 file_info->handle = handle; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1498 FROM_HERE, | 1476 FROM_HERE, |
| 1499 base::Bind(callback.func, callback.user_data, | 1477 base::Bind(callback.func, callback.user_data, |
| 1500 static_cast<int32_t>(PP_ERROR_FAILED))); | 1478 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 1501 return; | 1479 return; |
| 1502 } | 1480 } |
| 1503 | 1481 |
| 1504 // Try the fast path for retrieving the file first. | 1482 // Try the fast path for retrieving the file first. |
| 1505 uint64_t file_token_lo = 0; | 1483 uint64_t file_token_lo = 0; |
| 1506 uint64_t file_token_hi = 0; | 1484 uint64_t file_token_hi = 0; |
| 1507 PP_FileHandle file_handle = OpenNaClExecutable(instance, | 1485 PP_FileHandle file_handle = OpenNaClExecutable(instance, |
| 1508 url.c_str(), | 1486 url, |
| 1509 &file_token_lo, | 1487 &file_token_lo, |
| 1510 &file_token_hi); | 1488 &file_token_hi); |
| 1511 if (file_handle != PP_kInvalidFileHandle) { | 1489 if (file_handle != PP_kInvalidFileHandle) { |
| 1512 file_info->handle = file_handle; | 1490 file_info->handle = file_handle; |
| 1513 file_info->token_lo = file_token_lo; | 1491 file_info->token_lo = file_token_lo; |
| 1514 file_info->token_hi = file_token_hi; | 1492 file_info->token_hi = file_token_hi; |
| 1515 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1493 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 1516 FROM_HERE, | 1494 FROM_HERE, |
| 1517 base::Bind(callback.func, callback.user_data, | 1495 base::Bind(callback.func, callback.user_data, |
| 1518 static_cast<int32_t>(PP_OK))); | 1496 static_cast<int32_t>(PP_OK))); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 &SetExitStatus, | 1556 &SetExitStatus, |
| 1579 &Vlog, | 1557 &Vlog, |
| 1580 &InitializePlugin, | 1558 &InitializePlugin, |
| 1581 &GetNexeSize, | 1559 &GetNexeSize, |
| 1582 &RequestNaClManifest, | 1560 &RequestNaClManifest, |
| 1583 &GetManifestBaseURL, | 1561 &GetManifestBaseURL, |
| 1584 &ProcessNaClManifest, | 1562 &ProcessNaClManifest, |
| 1585 &GetManifestURLArgument, | 1563 &GetManifestURLArgument, |
| 1586 &DevInterfacesEnabled, | 1564 &DevInterfacesEnabled, |
| 1587 &ManifestGetProgramURL, | 1565 &ManifestGetProgramURL, |
| 1588 &OpenManifestEntry, | 1566 &ManifestResolveKey, |
| 1589 &GetPNaClResourceInfo, | 1567 &GetPNaClResourceInfo, |
| 1590 &GetCpuFeatureAttrs, | 1568 &GetCpuFeatureAttrs, |
| 1591 &PostMessageToJavaScript, | 1569 &PostMessageToJavaScript, |
| 1592 &DownloadNexe, | 1570 &DownloadNexe, |
| 1571 &DownloadFile |
| 1593 }; | 1572 }; |
| 1594 | 1573 |
| 1595 } // namespace | 1574 } // namespace |
| 1596 | 1575 |
| 1597 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1576 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
| 1598 return &nacl_interface; | 1577 return &nacl_interface; |
| 1599 } | 1578 } |
| 1600 | 1579 |
| 1601 } // namespace nacl | 1580 } // namespace nacl |
| OLD | NEW |