| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/nullable_string16.h" | 10 #include "base/nullable_string16.h" |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 ReadParam(m, iter, &r->receive) && | 723 ReadParam(m, iter, &r->receive) && |
| 724 ReadParam(m, iter, &r->dispatch) && | 724 ReadParam(m, iter, &r->dispatch) && |
| 725 ReadParam(m, iter, &r->params); | 725 ReadParam(m, iter, &r->params); |
| 726 } | 726 } |
| 727 | 727 |
| 728 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { | 728 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { |
| 729 // Doesn't make sense to implement this! | 729 // Doesn't make sense to implement this! |
| 730 } | 730 } |
| 731 | 731 |
| 732 void ParamTraits<Message>::Write(Message* m, const Message& p) { | 732 void ParamTraits<Message>::Write(Message* m, const Message& p) { |
| 733 DCHECK(p.size() <= INT_MAX); | 733 #if defined(OS_POSIX) |
| 734 int message_size = static_cast<int>(p.size()); | 734 // We don't serialize the file descriptors in the nested message, so there |
| 735 m->WriteInt(message_size); | 735 // better not be any. |
| 736 m->WriteData(reinterpret_cast<const char*>(p.data()), message_size); | 736 DCHECK(!p.HasFileDescriptors()); |
| 737 #endif |
| 738 |
| 739 // Don't just write out the message. This is used to send messages between |
| 740 // NaCl (Posix environment) and the browser (could be on Windows). The message |
| 741 // header formats differ between these systems (so does handle sharing, but |
| 742 // we already asserted we don't have any handles). So just write out the |
| 743 // parts of the header we use. |
| 744 // |
| 745 // Be careful also to use only explicitly-sized types. The NaCl environment |
| 746 // could be 64-bit and the host browser could be 32-bits. The nested message |
| 747 // may or may not be safe to send between 32-bit and 64-bit systems, but we |
| 748 // leave that up to the code sending the message to ensure. |
| 749 m->WriteUInt32(static_cast<uint32>(p.routing_id())); |
| 750 m->WriteUInt32(p.type()); |
| 751 m->WriteUInt32(p.flags()); |
| 752 m->WriteData(p.payload(), static_cast<uint32>(p.payload_size())); |
| 737 } | 753 } |
| 738 | 754 |
| 739 bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter, | 755 bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter, |
| 740 Message* r) { | 756 Message* r) { |
| 741 int size; | 757 uint32 routing_id, type, flags; |
| 742 if (!m->ReadInt(iter, &size)) | 758 if (!m->ReadUInt32(iter, &routing_id) || |
| 759 !m->ReadUInt32(iter, &type) || |
| 760 !m->ReadUInt32(iter, &flags)) |
| 743 return false; | 761 return false; |
| 744 const char* data; | 762 |
| 745 if (!m->ReadData(iter, &data, &size)) | 763 int payload_size; |
| 764 const char* payload; |
| 765 if (!m->ReadData(iter, &payload, &payload_size)) |
| 746 return false; | 766 return false; |
| 747 *r = Message(data, size); | 767 |
| 748 return true; | 768 r->SetHeaderValues(static_cast<int32>(routing_id), type, flags); |
| 769 return r->WriteBytes(payload, payload_size); |
| 749 } | 770 } |
| 750 | 771 |
| 751 void ParamTraits<Message>::Log(const Message& p, std::string* l) { | 772 void ParamTraits<Message>::Log(const Message& p, std::string* l) { |
| 752 l->append("<IPC::Message>"); | 773 l->append("<IPC::Message>"); |
| 753 } | 774 } |
| 754 | 775 |
| 755 #if defined(OS_WIN) | 776 #if defined(OS_WIN) |
| 756 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 | 777 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 |
| 757 // bit systems. | 778 // bit systems. |
| 758 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { | 779 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 return result; | 835 return result; |
| 815 } | 836 } |
| 816 | 837 |
| 817 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 838 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 818 l->append("<MSG>"); | 839 l->append("<MSG>"); |
| 819 } | 840 } |
| 820 | 841 |
| 821 #endif // OS_WIN | 842 #endif // OS_WIN |
| 822 | 843 |
| 823 } // namespace IPC | 844 } // namespace IPC |
| OLD | NEW |