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 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 } | 1106 } |
1107 | 1107 |
1108 JsonManifest* manifest = GetJsonManifest(instance); | 1108 JsonManifest* manifest = GetJsonManifest(instance); |
1109 if (manifest == NULL) | 1109 if (manifest == NULL) |
1110 return false; | 1110 return false; |
1111 | 1111 |
1112 return manifest->ResolveKey(key, full_url, pnacl_options); | 1112 return manifest->ResolveKey(key, full_url, pnacl_options); |
1113 } | 1113 } |
1114 | 1114 |
1115 PP_Bool GetPNaClResourceInfo(PP_Instance instance, | 1115 PP_Bool GetPNaClResourceInfo(PP_Instance instance, |
1116 const char* filename, | |
1117 PP_Var* llc_tool_name, | 1116 PP_Var* llc_tool_name, |
1118 PP_Var* ld_tool_name) { | 1117 PP_Var* ld_tool_name) { |
| 1118 static const char kFilename[] = "chrome://pnacl-translator/pnacl.json"; |
1119 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1119 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1120 DCHECK(load_manager); | 1120 DCHECK(load_manager); |
1121 if (!load_manager) | 1121 if (!load_manager) |
1122 return PP_FALSE; | 1122 return PP_FALSE; |
1123 | 1123 |
1124 uint64_t nonce_lo = 0; | 1124 uint64_t nonce_lo = 0; |
1125 uint64_t nonce_hi = 0; | 1125 uint64_t nonce_hi = 0; |
1126 base::File file(GetReadonlyPnaclFd(filename, false /* is_executable */, | 1126 base::File file(GetReadonlyPnaclFd(kFilename, false /* is_executable */, |
1127 &nonce_lo, &nonce_hi)); | 1127 &nonce_lo, &nonce_hi)); |
1128 if (!file.IsValid()) { | 1128 if (!file.IsValid()) { |
1129 load_manager->ReportLoadError( | 1129 load_manager->ReportLoadError( |
1130 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1130 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1131 "The Portable Native Client (pnacl) component is not " | 1131 "The Portable Native Client (pnacl) component is not " |
1132 "installed. Please consult chrome://components for more " | 1132 "installed. Please consult chrome://components for more " |
1133 "information."); | 1133 "information."); |
1134 return PP_FALSE; | 1134 return PP_FALSE; |
1135 } | 1135 } |
1136 | 1136 |
1137 base::File::Info file_info; | 1137 base::File::Info file_info; |
1138 if (!file.GetInfo(&file_info)) { | 1138 if (!file.GetInfo(&file_info)) { |
1139 load_manager->ReportLoadError( | 1139 load_manager->ReportLoadError( |
1140 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1140 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1141 std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") + | 1141 std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") + |
1142 filename); | 1142 kFilename); |
1143 return PP_FALSE; | 1143 return PP_FALSE; |
1144 } | 1144 } |
1145 | 1145 |
1146 if (file_info.size > 1 << 20) { | 1146 if (file_info.size > 1 << 20) { |
1147 load_manager->ReportLoadError( | 1147 load_manager->ReportLoadError( |
1148 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1148 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1149 std::string("GetPNaClResourceInfo, file too large: ") + filename); | 1149 std::string("GetPNaClResourceInfo, file too large: ") + kFilename); |
1150 return PP_FALSE; | 1150 return PP_FALSE; |
1151 } | 1151 } |
1152 | 1152 |
1153 scoped_ptr<char[]> buffer(new char[file_info.size + 1]); | 1153 scoped_ptr<char[]> buffer(new char[file_info.size + 1]); |
1154 if (buffer.get() == NULL) { | 1154 if (buffer.get() == NULL) { |
1155 load_manager->ReportLoadError( | 1155 load_manager->ReportLoadError( |
1156 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1156 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1157 std::string("GetPNaClResourceInfo, couldn't allocate for: ") + | 1157 std::string("GetPNaClResourceInfo, couldn't allocate for: ") + |
1158 filename); | 1158 kFilename); |
1159 return PP_FALSE; | 1159 return PP_FALSE; |
1160 } | 1160 } |
1161 | 1161 |
1162 int rc = file.Read(0, buffer.get(), file_info.size); | 1162 int rc = file.Read(0, buffer.get(), file_info.size); |
1163 if (rc < 0) { | 1163 if (rc < 0) { |
1164 load_manager->ReportLoadError( | 1164 load_manager->ReportLoadError( |
1165 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1165 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1166 std::string("GetPNaClResourceInfo, reading failed for: ") + filename); | 1166 std::string("GetPNaClResourceInfo, reading failed for: ") + kFilename); |
1167 return PP_FALSE; | 1167 return PP_FALSE; |
1168 } | 1168 } |
1169 | 1169 |
1170 // Null-terminate the bytes we we read from the file. | 1170 // Null-terminate the bytes we we read from the file. |
1171 buffer.get()[rc] = 0; | 1171 buffer.get()[rc] = 0; |
1172 | 1172 |
1173 // Expect the JSON file to contain a top-level object (dictionary). | 1173 // Expect the JSON file to contain a top-level object (dictionary). |
1174 Json::Reader json_reader; | 1174 Json::Reader json_reader; |
1175 Json::Value json_data; | 1175 Json::Value json_data; |
1176 if (!json_reader.parse(buffer.get(), json_data)) { | 1176 if (!json_reader.parse(buffer.get(), json_data)) { |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 &SetPNaClStartTime | 1639 &SetPNaClStartTime |
1640 }; | 1640 }; |
1641 | 1641 |
1642 } // namespace | 1642 } // namespace |
1643 | 1643 |
1644 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1644 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1645 return &nacl_interface; | 1645 return &nacl_interface; |
1646 } | 1646 } |
1647 | 1647 |
1648 } // namespace nacl | 1648 } // namespace nacl |
OLD | NEW |