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