Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 Dart_GetField(builtin_lib, | 280 Dart_GetField(builtin_lib, |
| 281 DartUtils::NewString("_httpRequestStatusString")); | 281 DartUtils::NewString("_httpRequestStatusString")); |
| 282 if (Dart_IsError(responseStatus)) { | 282 if (Dart_IsError(responseStatus)) { |
| 283 return responseStatus; | 283 return responseStatus; |
| 284 } | 284 } |
| 285 if (Dart_IsNull(responseStatus)) { | 285 if (Dart_IsNull(responseStatus)) { |
| 286 return Dart_Error("HTTP error."); | 286 return Dart_Error("HTTP error."); |
| 287 } | 287 } |
| 288 return Dart_Error(DartUtils::GetStringValue(responseStatus)); | 288 return Dart_Error(DartUtils::GetStringValue(responseStatus)); |
| 289 } | 289 } |
| 290 Dart_Handle responseList = | 290 Dart_Handle response = |
| 291 Dart_GetField(builtin_lib, DartUtils::NewString("_httpRequestResponse")); | 291 Dart_GetField(builtin_lib, DartUtils::NewString("_httpRequestResponse")); |
| 292 if (Dart_IsError(responseList)) { | 292 if (Dart_IsError(response)) { |
| 293 return responseList; | 293 return response; |
| 294 } | 294 } |
| 295 // Query list length. | 295 if (Dart_IsString(response)) { |
| 296 result = Dart_ListLength(responseList, buffer_len); | 296 // Received response as string. |
| 297 if (Dart_IsError(result)) { | 297 const char* responseString = NULL; |
| 298 *buffer_len = 0; | 298 Dart_Handle r = Dart_StringToCString(response, &responseString); |
|
Søren Gjesse
2013/06/03 19:06:06
Shouldn't this be Dart_StringToUTF8? E.g. what hap
Cutch
2013/06/03 20:03:20
Done.
| |
| 299 *buffer = NULL; | 299 if (Dart_IsError(r)) { |
| 300 return result; | 300 *buffer = NULL; |
| 301 } | 301 *buffer_len = 0; |
| 302 // Get payload as bytes. | 302 return r; |
| 303 *buffer = reinterpret_cast<uint8_t*>(malloc(*buffer_len)); | 303 } |
| 304 result = Dart_ListGetAsBytes(responseList, 0, *buffer, *buffer_len); | 304 // Get payload as bytes. |
| 305 if (Dart_IsError(result)) { | 305 *buffer_len = strlen(responseString)+1; |
| 306 free(*buffer); | 306 *buffer = reinterpret_cast<uint8_t*>(malloc(*buffer_len)); |
| 307 *buffer_len = 0; | 307 memmove(*buffer, responseString, *buffer_len); |
| 308 *buffer = NULL; | 308 } else { |
| 309 return result; | 309 // Received response as list of bytes. |
| 310 ASSERT(Dart_IsList(response)); | |
| 311 // Query list length. | |
| 312 result = Dart_ListLength(response, buffer_len); | |
| 313 if (Dart_IsError(result)) { | |
| 314 *buffer_len = 0; | |
| 315 *buffer = NULL; | |
| 316 return result; | |
| 317 } | |
| 318 // Get payload as bytes. | |
| 319 *buffer = reinterpret_cast<uint8_t*>(malloc(*buffer_len)); | |
| 320 result = Dart_ListGetAsBytes(response, 0, *buffer, *buffer_len); | |
|
Søren Gjesse
2013/06/03 19:06:06
Does it make sense to handle the HTTP response wit
Cutch
2013/06/03 20:03:20
Yes for a couple of reasons:
1) Loading snapshots
| |
| 321 if (Dart_IsError(result)) { | |
| 322 free(*buffer); | |
| 323 *buffer_len = 0; | |
| 324 *buffer = NULL; | |
| 325 return result; | |
| 326 } | |
| 310 } | 327 } |
| 311 return result; | 328 return result; |
| 312 } | 329 } |
| 313 | 330 |
| 314 | 331 |
| 315 Dart_Handle DartUtils::ReadStringFromHttp(const char* script_uri) { | 332 Dart_Handle DartUtils::ReadStringFromHttp(const char* script_uri) { |
| 316 Dart_Handle uri = NewString(script_uri); | 333 Dart_Handle uri = NewString(script_uri); |
| 317 if (Dart_IsError(uri)) { | 334 if (Dart_IsError(uri)) { |
| 318 return uri; | 335 return uri; |
| 319 } | 336 } |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 new CObjectString(CObject::NewString(os_error->message())); | 950 new CObjectString(CObject::NewString(os_error->message())); |
| 934 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 951 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 935 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 952 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 936 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 953 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 937 result->SetAt(2, error_message); | 954 result->SetAt(2, error_message); |
| 938 return result; | 955 return result; |
| 939 } | 956 } |
| 940 | 957 |
| 941 } // namespace bin | 958 } // namespace bin |
| 942 } // namespace dart | 959 } // namespace dart |
| OLD | NEW |