OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | 7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 317 } |
318 return expected_element_size; | 318 return expected_element_size; |
319 } | 319 } |
320 | 320 |
321 | 321 |
322 // | 322 // |
323 // This should be invoked only if DeserializePpVarSize succeeds, i.e., | 323 // This should be invoked only if DeserializePpVarSize succeeds, i.e., |
324 // there are enough bytes at p. | 324 // there are enough bytes at p. |
325 // | 325 // |
326 bool DeserializeString(char* p, | 326 bool DeserializeString(char* p, |
327 PP_Var* var, | 327 PP_Var* var) { |
328 NaClSrpcChannel* channel) { | |
329 SerializedString* ss = reinterpret_cast<SerializedString*>(p); | 328 SerializedString* ss = reinterpret_cast<SerializedString*>(p); |
330 uint32_t string_length = ss->fixed.u.string_length; | 329 uint32_t string_length = ss->fixed.u.string_length; |
331 // VarFromUtf8 creates a buffer of size string_length using the browser-side | 330 // VarFromUtf8 creates a buffer of size string_length using the browser-side |
332 // memory allocation function, and copies string_length bytes from | 331 // memory allocation function, and copies string_length bytes from |
333 // ss->string_bytes in to that buffer. The ref count of the returned var is | 332 // ss->string_bytes in to that buffer. The ref count of the returned var is |
334 // 1. | 333 // 1. |
335 *var = PPBVarInterface()->VarFromUtf8(LookupModuleIdForSrpcChannel(channel), | 334 *var = PPBVarInterface()->VarFromUtf8(ss->string_bytes, |
336 ss->string_bytes, | |
337 string_length); | 335 string_length); |
338 return true; | 336 return true; |
339 } | 337 } |
340 | 338 |
341 bool DeserializePpVar(NaClSrpcChannel* channel, | 339 bool DeserializePpVar(char* bytes, |
342 char* bytes, | |
343 uint32_t length, | 340 uint32_t length, |
344 PP_Var* vars, | 341 PP_Var* vars, |
345 uint32_t argc) { | 342 uint32_t argc) { |
346 char* p = bytes; | 343 char* p = bytes; |
347 | 344 |
348 for (uint32_t i = 0; i < argc; ++i) { | 345 for (uint32_t i = 0; i < argc; ++i) { |
349 PP_VarType element_type; | 346 PP_VarType element_type; |
350 uint32_t element_size = DeserializePpVarSize(p, length, &element_type); | 347 uint32_t element_size = DeserializePpVarSize(p, length, &element_type); |
351 if (std::numeric_limits<uint32_t>::max() == element_size) { | 348 if (std::numeric_limits<uint32_t>::max() == element_size) { |
352 return false; | 349 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
363 break; | 360 break; |
364 case PP_VARTYPE_INT32: | 361 case PP_VARTYPE_INT32: |
365 vars[i].value.as_int = s->u.int32_value; | 362 vars[i].value.as_int = s->u.int32_value; |
366 break; | 363 break; |
367 case PP_VARTYPE_DOUBLE: { | 364 case PP_VARTYPE_DOUBLE: { |
368 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p); | 365 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p); |
369 vars[i].value.as_double = sd->double_value; | 366 vars[i].value.as_double = sd->double_value; |
370 break; | 367 break; |
371 } | 368 } |
372 case PP_VARTYPE_STRING: | 369 case PP_VARTYPE_STRING: |
373 if (!DeserializeString(p, &vars[i], channel)) { | 370 if (!DeserializeString(p, &vars[i])) { |
374 return false; | 371 return false; |
375 } | 372 } |
376 break; | 373 break; |
377 case PP_VARTYPE_OBJECT: | 374 case PP_VARTYPE_OBJECT: |
378 case PP_VARTYPE_ARRAY: | 375 case PP_VARTYPE_ARRAY: |
379 case PP_VARTYPE_DICTIONARY: | 376 case PP_VARTYPE_DICTIONARY: |
380 NACL_NOTREACHED(); | 377 NACL_NOTREACHED(); |
381 default: | 378 default: |
382 return false; | 379 return false; |
383 } | 380 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // Serialize the vars. | 431 // Serialize the vars. |
435 if (!SerializePpVar(vars, argc, bytes, tmp_length)) { | 432 if (!SerializePpVar(vars, argc, bytes, tmp_length)) { |
436 delete[] bytes; | 433 delete[] bytes; |
437 return NULL; | 434 return NULL; |
438 } | 435 } |
439 // Return success. | 436 // Return success. |
440 *length = tmp_length; | 437 *length = tmp_length; |
441 return bytes; | 438 return bytes; |
442 } | 439 } |
443 | 440 |
444 bool DeserializeTo(NaClSrpcChannel* channel, | 441 bool DeserializeTo(char* bytes, |
445 char* bytes, | |
446 uint32_t length, | 442 uint32_t length, |
447 uint32_t argc, | 443 uint32_t argc, |
448 PP_Var* vars) { | 444 PP_Var* vars) { |
449 // Deserializing a zero-length vector is trivially done. | 445 // Deserializing a zero-length vector is trivially done. |
450 if (0 == argc) { | 446 if (0 == argc) { |
451 return true; | 447 return true; |
452 } | 448 } |
453 // Otherwise, there must be some input bytes to get from. | 449 // Otherwise, there must be some input bytes to get from. |
454 if (NULL == bytes || 0 == length) { | 450 if (NULL == bytes || 0 == length) { |
455 return false; | 451 return false; |
456 } | 452 } |
457 // And there has to be a valid address to deserialize to. | 453 // And there has to be a valid address to deserialize to. |
458 if (NULL == vars) { | 454 if (NULL == vars) { |
459 return false; | 455 return false; |
460 } | 456 } |
461 // Read the serialized PP_Vars into the allocated memory. | 457 // Read the serialized PP_Vars into the allocated memory. |
462 if (!DeserializePpVar(channel, bytes, length, vars, argc)) { | 458 if (!DeserializePpVar(bytes, length, vars, argc)) { |
463 return false; | 459 return false; |
464 } | 460 } |
465 return true; | 461 return true; |
466 } | 462 } |
467 | 463 |
468 } // namespace ppapi_proxy | 464 } // namespace ppapi_proxy |
OLD | NEW |