Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc

Issue 8826011: Remove PP_Module from parameters for PPB_Var.VarFromUtf8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 return expected_element_size; 321 return expected_element_size;
322 } 322 }
323 323
324 324
325 // 325 //
326 // This should be invoked only if DeserializePpVarSize succeeds, i.e., 326 // This should be invoked only if DeserializePpVarSize succeeds, i.e.,
327 // there are enough bytes at p. 327 // there are enough bytes at p.
328 // 328 //
329 bool DeserializeString(char* p, 329 bool DeserializeString(char* p,
330 PP_Var* var, 330 PP_Var* var) {
331 NaClSrpcChannel* channel) {
332 SerializedString* ss = reinterpret_cast<SerializedString*>(p); 331 SerializedString* ss = reinterpret_cast<SerializedString*>(p);
333 uint32_t string_length = ss->fixed.u.string_length; 332 uint32_t string_length = ss->fixed.u.string_length;
334 // VarFromUtf8 creates a buffer of size string_length using the browser-side 333 // VarFromUtf8 creates a buffer of size string_length using the browser-side
335 // memory allocation function, and copies string_length bytes from 334 // memory allocation function, and copies string_length bytes from
336 // ss->string_bytes in to that buffer. The ref count of the returned var is 335 // ss->string_bytes in to that buffer. The ref count of the returned var is
337 // 1. 336 // 1.
338 *var = PPBVarInterface()->VarFromUtf8(LookupModuleIdForSrpcChannel(channel), 337 *var = PPBVarInterface()->VarFromUtf8(ss->string_bytes,
339 ss->string_bytes,
340 string_length); 338 string_length);
341 return true; 339 return true;
342 } 340 }
343 341
344 bool DeserializePpVar(NaClSrpcChannel* channel, 342 bool DeserializePpVar(char* bytes,
345 char* bytes,
346 uint32_t length, 343 uint32_t length,
347 PP_Var* vars, 344 PP_Var* vars,
348 uint32_t argc) { 345 uint32_t argc) {
349 char* p = bytes; 346 char* p = bytes;
350 347
351 for (uint32_t i = 0; i < argc; ++i) { 348 for (uint32_t i = 0; i < argc; ++i) {
352 PP_VarType element_type; 349 PP_VarType element_type;
353 uint32_t element_size = DeserializePpVarSize(p, length, &element_type); 350 uint32_t element_size = DeserializePpVarSize(p, length, &element_type);
354 if (std::numeric_limits<uint32_t>::max() == element_size) { 351 if (std::numeric_limits<uint32_t>::max() == element_size) {
355 return false; 352 return false;
(...skipping 10 matching lines...) Expand all
366 break; 363 break;
367 case PP_VARTYPE_INT32: 364 case PP_VARTYPE_INT32:
368 vars[i].value.as_int = s->u.int32_value; 365 vars[i].value.as_int = s->u.int32_value;
369 break; 366 break;
370 case PP_VARTYPE_DOUBLE: { 367 case PP_VARTYPE_DOUBLE: {
371 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p); 368 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p);
372 vars[i].value.as_double = sd->double_value; 369 vars[i].value.as_double = sd->double_value;
373 break; 370 break;
374 } 371 }
375 case PP_VARTYPE_STRING: 372 case PP_VARTYPE_STRING:
376 if (!DeserializeString(p, &vars[i], channel)) { 373 if (!DeserializeString(p, &vars[i])) {
377 return false; 374 return false;
378 } 375 }
379 break; 376 break;
380 case PP_VARTYPE_OBJECT: 377 case PP_VARTYPE_OBJECT:
381 case PP_VARTYPE_ARRAY: 378 case PP_VARTYPE_ARRAY:
382 case PP_VARTYPE_DICTIONARY: 379 case PP_VARTYPE_DICTIONARY:
383 case PP_VARTYPE_ARRAY_BUFFER: 380 case PP_VARTYPE_ARRAY_BUFFER:
384 NACL_NOTREACHED(); 381 NACL_NOTREACHED();
385 default: 382 default:
386 return false; 383 return false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // Serialize the vars. 435 // Serialize the vars.
439 if (!SerializePpVar(vars, argc, bytes, tmp_length)) { 436 if (!SerializePpVar(vars, argc, bytes, tmp_length)) {
440 delete[] bytes; 437 delete[] bytes;
441 return NULL; 438 return NULL;
442 } 439 }
443 // Return success. 440 // Return success.
444 *length = tmp_length; 441 *length = tmp_length;
445 return bytes; 442 return bytes;
446 } 443 }
447 444
448 bool DeserializeTo(NaClSrpcChannel* channel, 445 bool DeserializeTo(char* bytes,
449 char* bytes,
450 uint32_t length, 446 uint32_t length,
451 uint32_t argc, 447 uint32_t argc,
452 PP_Var* vars) { 448 PP_Var* vars) {
453 // Deserializing a zero-length vector is trivially done. 449 // Deserializing a zero-length vector is trivially done.
454 if (0 == argc) { 450 if (0 == argc) {
455 return true; 451 return true;
456 } 452 }
457 // Otherwise, there must be some input bytes to get from. 453 // Otherwise, there must be some input bytes to get from.
458 if (NULL == bytes || 0 == length) { 454 if (NULL == bytes || 0 == length) {
459 return false; 455 return false;
460 } 456 }
461 // And there has to be a valid address to deserialize to. 457 // And there has to be a valid address to deserialize to.
462 if (NULL == vars) { 458 if (NULL == vars) {
463 return false; 459 return false;
464 } 460 }
465 // Read the serialized PP_Vars into the allocated memory. 461 // Read the serialized PP_Vars into the allocated memory.
466 if (!DeserializePpVar(channel, bytes, length, vars, argc)) { 462 if (!DeserializePpVar(bytes, length, vars, argc)) {
467 return false; 463 return false;
468 } 464 }
469 return true; 465 return true;
470 } 466 }
471 467
472 } // namespace ppapi_proxy 468 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698