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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 base::PlatformFile file = GetReadonlyPnaclFD(filename); | 1107 base::PlatformFile file = GetReadonlyPnaclFD(filename); |
1108 if (file == base::kInvalidPlatformFileValue) { | 1108 if (file == base::kInvalidPlatformFileValue) { |
1109 load_manager->ReportLoadError( | 1109 load_manager->ReportLoadError( |
1110 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1110 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1111 "The Portable Native Client (pnacl) component is not " | 1111 "The Portable Native Client (pnacl) component is not " |
1112 "installed. Please consult chrome://components for more " | 1112 "installed. Please consult chrome://components for more " |
1113 "information."); | 1113 "information."); |
1114 return PP_FALSE; | 1114 return PP_FALSE; |
1115 } | 1115 } |
1116 | 1116 |
1117 const int kBufferSize = 1 << 20; | 1117 base::PlatformFileInfo file_info; |
1118 scoped_ptr<char[]> buffer(new char[kBufferSize]); | 1118 if (!GetPlatformFileInfo(file, &file_info)) { |
1119 if (base::ReadPlatformFile(file, 0, buffer.get(), kBufferSize) < 0) { | |
1120 load_manager->ReportLoadError( | 1119 load_manager->ReportLoadError( |
1121 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1120 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1122 std::string("PnaclResources::ReadResourceInfo reading failed for: ") + | 1121 std::string("GetPNaClResourceInfo, GetFileInfo failed for: ") + |
1123 filename); | 1122 filename); |
1124 return PP_FALSE; | 1123 return PP_FALSE; |
1125 } | 1124 } |
1126 | 1125 |
| 1126 if (file_info.size > 1 << 20) { |
| 1127 load_manager->ReportLoadError( |
| 1128 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 1129 std::string("GetPNaClResourceInfo, file too large: ") + filename); |
| 1130 return PP_FALSE; |
| 1131 } |
| 1132 |
| 1133 scoped_ptr<char[]> buffer(new char[file_info.size + 1]); |
| 1134 if (buffer.get() == NULL) { |
| 1135 load_manager->ReportLoadError( |
| 1136 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 1137 std::string("GetPNaClResourceInfo, couldn't allocate for: ") + |
| 1138 filename); |
| 1139 return PP_FALSE; |
| 1140 } |
| 1141 |
| 1142 int rc = base::ReadPlatformFile(file, 0, buffer.get(), file_info.size); |
| 1143 if (rc < 0) { |
| 1144 load_manager->ReportLoadError( |
| 1145 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 1146 std::string("GetPNaClResourceInfo, reading failed for: ") + filename); |
| 1147 return PP_FALSE; |
| 1148 } |
| 1149 |
| 1150 // Null-terminate the bytes we we read from the file. |
| 1151 buffer.get()[rc] = 0; |
| 1152 |
1127 // Expect the JSON file to contain a top-level object (dictionary). | 1153 // Expect the JSON file to contain a top-level object (dictionary). |
1128 Json::Reader json_reader; | 1154 Json::Reader json_reader; |
1129 Json::Value json_data; | 1155 Json::Value json_data; |
1130 if (!json_reader.parse(buffer.get(), json_data)) { | 1156 if (!json_reader.parse(buffer.get(), json_data)) { |
1131 load_manager->ReportLoadError( | 1157 load_manager->ReportLoadError( |
1132 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 1158 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
1133 std::string("Parsing resource info failed: JSON parse error: ") + | 1159 std::string("Parsing resource info failed: JSON parse error: ") + |
1134 json_reader.getFormattedErrorMessages()); | 1160 json_reader.getFormattedErrorMessages()); |
1135 return PP_FALSE; | 1161 return PP_FALSE; |
1136 } | 1162 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 &PostMessageToJavaScript | 1305 &PostMessageToJavaScript |
1280 }; | 1306 }; |
1281 | 1307 |
1282 } // namespace | 1308 } // namespace |
1283 | 1309 |
1284 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1310 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1285 return &nacl_interface; | 1311 return &nacl_interface; |
1286 } | 1312 } |
1287 | 1313 |
1288 } // namespace nacl | 1314 } // namespace nacl |
OLD | NEW |