OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ppapi/proxy/raw_var_data.h" | 5 #include "ppapi/proxy/raw_var_data.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 m->WriteInt(data_[i]->Type()); | 181 m->WriteInt(data_[i]->Type()); |
182 data_[i]->Write(m, handle_writer); | 182 data_[i]->Write(m, handle_writer); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 // static | 186 // static |
187 scoped_ptr<RawVarDataGraph> RawVarDataGraph::Read(const IPC::Message* m, | 187 scoped_ptr<RawVarDataGraph> RawVarDataGraph::Read(const IPC::Message* m, |
188 PickleIterator* iter) { | 188 PickleIterator* iter) { |
189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph); | 189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph); |
190 uint32_t size = 0; | 190 uint32_t size = 0; |
191 if (!m->ReadUInt32(iter, &size)) | 191 if (!iter->ReadUInt32(&size)) |
192 return scoped_ptr<RawVarDataGraph>(); | 192 return scoped_ptr<RawVarDataGraph>(); |
193 for (uint32_t i = 0; i < size; ++i) { | 193 for (uint32_t i = 0; i < size; ++i) { |
194 int32_t type; | 194 int32_t type; |
195 if (!m->ReadInt(iter, &type)) | 195 if (!iter->ReadInt(&type)) |
196 return scoped_ptr<RawVarDataGraph>(); | 196 return scoped_ptr<RawVarDataGraph>(); |
197 PP_VarType var_type = static_cast<PP_VarType>(type); | 197 PP_VarType var_type = static_cast<PP_VarType>(type); |
198 result->data_.push_back(RawVarData::Create(var_type)); | 198 result->data_.push_back(RawVarData::Create(var_type)); |
199 if (!result->data_.back()->Read(var_type, m, iter)) | 199 if (!result->data_.back()->Read(var_type, m, iter)) |
200 return scoped_ptr<RawVarDataGraph>(); | 200 return scoped_ptr<RawVarDataGraph>(); |
201 } | 201 } |
202 return result.Pass(); | 202 return result.Pass(); |
203 } | 203 } |
204 | 204 |
205 std::vector<SerializedHandle*> RawVarDataGraph::GetHandles() { | 205 std::vector<SerializedHandle*> RawVarDataGraph::GetHandles() { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 PP_Var result; | 316 PP_Var result; |
317 result.type = type; | 317 result.type = type; |
318 switch (type) { | 318 switch (type) { |
319 case PP_VARTYPE_UNDEFINED: | 319 case PP_VARTYPE_UNDEFINED: |
320 case PP_VARTYPE_NULL: | 320 case PP_VARTYPE_NULL: |
321 // These don't have any data associated with them other than the type we | 321 // These don't have any data associated with them other than the type we |
322 // just deserialized. | 322 // just deserialized. |
323 break; | 323 break; |
324 case PP_VARTYPE_BOOL: { | 324 case PP_VARTYPE_BOOL: { |
325 bool bool_value; | 325 bool bool_value; |
326 if (!m->ReadBool(iter, &bool_value)) | 326 if (!iter->ReadBool(&bool_value)) |
327 return false; | 327 return false; |
328 result.value.as_bool = PP_FromBool(bool_value); | 328 result.value.as_bool = PP_FromBool(bool_value); |
329 break; | 329 break; |
330 } | 330 } |
331 case PP_VARTYPE_INT32: | 331 case PP_VARTYPE_INT32: |
332 if (!m->ReadInt(iter, &result.value.as_int)) | 332 if (!iter->ReadInt(&result.value.as_int)) |
333 return false; | 333 return false; |
334 break; | 334 break; |
335 case PP_VARTYPE_DOUBLE: | 335 case PP_VARTYPE_DOUBLE: |
336 if (!IPC::ParamTraits<double>::Read(m, iter, &result.value.as_double)) | 336 if (!IPC::ParamTraits<double>::Read(m, iter, &result.value.as_double)) |
337 return false; | 337 return false; |
338 break; | 338 break; |
339 case PP_VARTYPE_OBJECT: | 339 case PP_VARTYPE_OBJECT: |
340 if (!m->ReadInt64(iter, &result.value.as_id)) | 340 if (!iter->ReadInt64(&result.value.as_id)) |
341 return false; | 341 return false; |
342 break; | 342 break; |
343 default: | 343 default: |
344 NOTREACHED(); | 344 NOTREACHED(); |
345 return false; | 345 return false; |
346 } | 346 } |
347 var_ = result; | 347 var_ = result; |
348 return true; | 348 return true; |
349 } | 349 } |
350 | 350 |
(...skipping 27 matching lines...) Expand all Loading... |
378 } | 378 } |
379 | 379 |
380 void StringRawVarData::Write(IPC::Message* m, | 380 void StringRawVarData::Write(IPC::Message* m, |
381 const HandleWriter& handle_writer) { | 381 const HandleWriter& handle_writer) { |
382 m->WriteString(data_); | 382 m->WriteString(data_); |
383 } | 383 } |
384 | 384 |
385 bool StringRawVarData::Read(PP_VarType type, | 385 bool StringRawVarData::Read(PP_VarType type, |
386 const IPC::Message* m, | 386 const IPC::Message* m, |
387 PickleIterator* iter) { | 387 PickleIterator* iter) { |
388 if (!m->ReadString(iter, &data_)) | 388 if (!iter->ReadString(&data_)) |
389 return false; | 389 return false; |
390 return true; | 390 return true; |
391 } | 391 } |
392 | 392 |
393 // ArrayBufferRawVarData ------------------------------------------------------- | 393 // ArrayBufferRawVarData ------------------------------------------------------- |
394 ArrayBufferRawVarData::ArrayBufferRawVarData() { | 394 ArrayBufferRawVarData::ArrayBufferRawVarData() { |
395 } | 395 } |
396 | 396 |
397 ArrayBufferRawVarData::~ArrayBufferRawVarData() { | 397 ArrayBufferRawVarData::~ArrayBufferRawVarData() { |
398 } | 398 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 case ARRAY_BUFFER_NO_SHMEM: | 496 case ARRAY_BUFFER_NO_SHMEM: |
497 m->WriteString(data_); | 497 m->WriteString(data_); |
498 break; | 498 break; |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 bool ArrayBufferRawVarData::Read(PP_VarType type, | 502 bool ArrayBufferRawVarData::Read(PP_VarType type, |
503 const IPC::Message* m, | 503 const IPC::Message* m, |
504 PickleIterator* iter) { | 504 PickleIterator* iter) { |
505 int shmem_type; | 505 int shmem_type; |
506 if (!m->ReadInt(iter, &shmem_type)) | 506 if (!iter->ReadInt(&shmem_type)) |
507 return false; | 507 return false; |
508 type_ = static_cast<ShmemType>(shmem_type); | 508 type_ = static_cast<ShmemType>(shmem_type); |
509 switch (type_) { | 509 switch (type_) { |
510 case ARRAY_BUFFER_SHMEM_HOST: | 510 case ARRAY_BUFFER_SHMEM_HOST: |
511 if (!m->ReadInt(iter, &host_shm_handle_id_)) | 511 if (!iter->ReadInt(&host_shm_handle_id_)) |
512 return false; | 512 return false; |
513 break; | 513 break; |
514 case ARRAY_BUFFER_SHMEM_PLUGIN: | 514 case ARRAY_BUFFER_SHMEM_PLUGIN: |
515 if (!IPC::ParamTraits<SerializedHandle>::Read( | 515 if (!IPC::ParamTraits<SerializedHandle>::Read( |
516 m, iter, &plugin_shm_handle_)) { | 516 m, iter, &plugin_shm_handle_)) { |
517 return false; | 517 return false; |
518 } | 518 } |
519 break; | 519 break; |
520 case ARRAY_BUFFER_NO_SHMEM: | 520 case ARRAY_BUFFER_NO_SHMEM: |
521 if (!m->ReadString(iter, &data_)) | 521 if (!iter->ReadString(&data_)) |
522 return false; | 522 return false; |
523 break; | 523 break; |
524 default: | 524 default: |
525 // We read an invalid ID. | 525 // We read an invalid ID. |
526 NOTREACHED(); | 526 NOTREACHED(); |
527 return false; | 527 return false; |
528 } | 528 } |
529 return true; | 529 return true; |
530 } | 530 } |
531 | 531 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 const HandleWriter& handle_writer) { | 577 const HandleWriter& handle_writer) { |
578 m->WriteUInt32(static_cast<uint32_t>(children_.size())); | 578 m->WriteUInt32(static_cast<uint32_t>(children_.size())); |
579 for (size_t i = 0; i < children_.size(); ++i) | 579 for (size_t i = 0; i < children_.size(); ++i) |
580 m->WriteUInt32(static_cast<uint32_t>(children_[i])); | 580 m->WriteUInt32(static_cast<uint32_t>(children_[i])); |
581 } | 581 } |
582 | 582 |
583 bool ArrayRawVarData::Read(PP_VarType type, | 583 bool ArrayRawVarData::Read(PP_VarType type, |
584 const IPC::Message* m, | 584 const IPC::Message* m, |
585 PickleIterator* iter) { | 585 PickleIterator* iter) { |
586 uint32_t size; | 586 uint32_t size; |
587 if (!m->ReadUInt32(iter, &size)) | 587 if (!iter->ReadUInt32(&size)) |
588 return false; | 588 return false; |
589 for (uint32_t i = 0; i < size; ++i) { | 589 for (uint32_t i = 0; i < size; ++i) { |
590 uint32_t index; | 590 uint32_t index; |
591 if (!m->ReadUInt32(iter, &index)) | 591 if (!iter->ReadUInt32(&index)) |
592 return false; | 592 return false; |
593 children_.push_back(index); | 593 children_.push_back(index); |
594 } | 594 } |
595 return true; | 595 return true; |
596 } | 596 } |
597 | 597 |
598 // DictionaryRawVarData -------------------------------------------------------- | 598 // DictionaryRawVarData -------------------------------------------------------- |
599 DictionaryRawVarData::DictionaryRawVarData() { | 599 DictionaryRawVarData::DictionaryRawVarData() { |
600 } | 600 } |
601 | 601 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 for (size_t i = 0; i < children_.size(); ++i) { | 643 for (size_t i = 0; i < children_.size(); ++i) { |
644 m->WriteString(children_[i].first); | 644 m->WriteString(children_[i].first); |
645 m->WriteUInt32(static_cast<uint32_t>(children_[i].second)); | 645 m->WriteUInt32(static_cast<uint32_t>(children_[i].second)); |
646 } | 646 } |
647 } | 647 } |
648 | 648 |
649 bool DictionaryRawVarData::Read(PP_VarType type, | 649 bool DictionaryRawVarData::Read(PP_VarType type, |
650 const IPC::Message* m, | 650 const IPC::Message* m, |
651 PickleIterator* iter) { | 651 PickleIterator* iter) { |
652 uint32_t size; | 652 uint32_t size; |
653 if (!m->ReadUInt32(iter, &size)) | 653 if (!iter->ReadUInt32(&size)) |
654 return false; | 654 return false; |
655 for (uint32_t i = 0; i < size; ++i) { | 655 for (uint32_t i = 0; i < size; ++i) { |
656 std::string key; | 656 std::string key; |
657 uint32_t value; | 657 uint32_t value; |
658 if (!m->ReadString(iter, &key)) | 658 if (!iter->ReadString(&key)) |
659 return false; | 659 return false; |
660 if (!m->ReadUInt32(iter, &value)) | 660 if (!iter->ReadUInt32(&value)) |
661 return false; | 661 return false; |
662 children_.push_back(make_pair(key, value)); | 662 children_.push_back(make_pair(key, value)); |
663 } | 663 } |
664 return true; | 664 return true; |
665 } | 665 } |
666 | 666 |
667 // ResourceRawVarData ---------------------------------------------------------- | 667 // ResourceRawVarData ---------------------------------------------------------- |
668 ResourceRawVarData::ResourceRawVarData() | 668 ResourceRawVarData::ResourceRawVarData() |
669 : pp_resource_(0), | 669 : pp_resource_(0), |
670 pending_renderer_host_id_(0), | 670 pending_renderer_host_id_(0), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 m->WriteInt(pending_browser_host_id_); | 720 m->WriteInt(pending_browser_host_id_); |
721 m->WriteBool(creation_message_); | 721 m->WriteBool(creation_message_); |
722 if (creation_message_) | 722 if (creation_message_) |
723 IPC::ParamTraits<IPC::Message>::Write(m, *creation_message_); | 723 IPC::ParamTraits<IPC::Message>::Write(m, *creation_message_); |
724 } | 724 } |
725 | 725 |
726 bool ResourceRawVarData::Read(PP_VarType type, | 726 bool ResourceRawVarData::Read(PP_VarType type, |
727 const IPC::Message* m, | 727 const IPC::Message* m, |
728 PickleIterator* iter) { | 728 PickleIterator* iter) { |
729 int value; | 729 int value; |
730 if (!m->ReadInt(iter, &value)) | 730 if (!iter->ReadInt(&value)) |
731 return false; | 731 return false; |
732 pp_resource_ = static_cast<PP_Resource>(value); | 732 pp_resource_ = static_cast<PP_Resource>(value); |
733 if (!m->ReadInt(iter, &pending_renderer_host_id_)) | 733 if (!iter->ReadInt(&pending_renderer_host_id_)) |
734 return false; | 734 return false; |
735 if (!m->ReadInt(iter, &pending_browser_host_id_)) | 735 if (!iter->ReadInt(&pending_browser_host_id_)) |
736 return false; | 736 return false; |
737 bool has_creation_message; | 737 bool has_creation_message; |
738 if (!m->ReadBool(iter, &has_creation_message)) | 738 if (!iter->ReadBool(&has_creation_message)) |
739 return false; | 739 return false; |
740 if (has_creation_message) { | 740 if (has_creation_message) { |
741 creation_message_.reset(new IPC::Message()); | 741 creation_message_.reset(new IPC::Message()); |
742 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) | 742 if (!IPC::ParamTraits<IPC::Message>::Read(m, iter, creation_message_.get())) |
743 return false; | 743 return false; |
744 } else { | 744 } else { |
745 creation_message_.reset(); | 745 creation_message_.reset(); |
746 } | 746 } |
747 return true; | 747 return true; |
748 } | 748 } |
749 | 749 |
750 } // namespace proxy | 750 } // namespace proxy |
751 } // namespace ppapi | 751 } // namespace ppapi |
OLD | NEW |