blob: d55f57582d53f8216250090df638fc9fa399faaa [file] [log] [blame]
[email protected]339fbcff2012-02-29 16:10:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/ppapi_param_traits.h"
6
avie029c4132015-12-23 06:45:227#include <stddef.h>
8#include <stdint.h>
[email protected]c2932f5e2010-11-03 03:22:339#include <string.h> // For memcpy
10
avie029c4132015-12-23 06:45:2211#include "base/macros.h"
12#include "build/build_config.h"
[email protected]799d1ab2010-11-09 17:16:2813#include "ppapi/c/pp_resource.h"
[email protected]799d1ab2010-11-09 17:16:2814#include "ppapi/proxy/ppapi_messages.h"
[email protected]7358d572011-02-15 18:44:4015#include "ppapi/proxy/serialized_flash_menu.h"
avie029c4132015-12-23 06:45:2216#include "ppapi/proxy/serialized_var.h"
[email protected]be0a84b2011-08-13 04:18:4417#include "ppapi/shared_impl/host_resource.h"
[email protected]de2895262012-04-04 17:15:4818#include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h"
[email protected]c2932f5e2010-11-03 03:22:3319
20namespace IPC {
21
[email protected]1162a6a2011-04-21 17:28:1622namespace {
23
24// Deserializes a vector from IPC. This special version must be used instead
25// of the default IPC version when the vector contains a SerializedVar, either
26// directly or indirectly (i.e. a vector of objects that have a SerializedVar
27// inside them).
28//
29// The default vector deserializer does resize and then we deserialize into
30// those allocated slots. However, the implementation of vector (at least in
31// GCC's implementation), creates a new empty object using the default
32// constructor, and then sets the rest of the items to that empty one using the
33// copy constructor.
34//
35// Since we allocate the inner class when you call the default constructor and
36// transfer the inner class when you do operator=, the entire vector will end
37// up referring to the same inner class. Deserializing into this will just end
38// up overwriting the same item over and over, since all the SerializedVars
39// will refer to the same thing.
40//
41// The solution is to make a new object for each deserialized item, and then
42// add it to the vector one at a time.
brettwbd4d7112015-06-03 04:29:2543template <typename T>
rockot502c94f2016-02-03 20:20:1644bool ReadVectorWithoutCopy(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:2545 base::PickleIterator* iter,
[email protected]1162a6a2011-04-21 17:28:1646 std::vector<T>* output) {
47 // This part is just a copy of the the default ParamTraits vector Read().
48 int size;
49 // ReadLength() checks for < 0 itself.
avi48fc13b2014-12-28 23:31:4850 if (!iter->ReadLength(&size))
[email protected]1162a6a2011-04-21 17:28:1651 return false;
52 // Resizing beforehand is not safe, see BUG 1006367 for details.
53 if (INT_MAX / sizeof(T) <= static_cast<size_t>(size))
54 return false;
55
56 output->reserve(size);
57 for (int i = 0; i < size; i++) {
58 T cur;
59 if (!ReadParam(m, iter, &cur))
60 return false;
61 output->push_back(cur);
62 }
63 return true;
64}
65
66// This serializes the vector of items to the IPC message in exactly the same
67// way as the "regular" IPC vector serializer does. But having the code here
68// saves us from having to copy this code into all ParamTraits that use the
69// ReadVectorWithoutCopy function for deserializing.
rockot502c94f2016-02-03 20:20:1670template <typename T>
71void WriteVectorWithoutCopy(base::Pickle* m, const std::vector<T>& p) {
[email protected]1162a6a2011-04-21 17:28:1672 WriteParam(m, static_cast<int>(p.size()));
73 for (size_t i = 0; i < p.size(); i++)
74 WriteParam(m, p[i]);
75}
76
77} // namespace
78
[email protected]799d1ab2010-11-09 17:16:2879// PP_Bool ---------------------------------------------------------------------
80
81// static
jam3db6b6d2016-05-13 15:09:5882void ParamTraits<PP_Bool>::GetSize(base::PickleSizer* s, const param_type& p) {
83 GetParamSize(s, PP_ToBool(p));
84}
85
86// static
rockot502c94f2016-02-03 20:20:1687void ParamTraits<PP_Bool>::Write(base::Pickle* m, const param_type& p) {
bbudge03071f12015-11-02 23:51:2088 WriteParam(m, PP_ToBool(p));
[email protected]799d1ab2010-11-09 17:16:2889}
90
91// static
rockot502c94f2016-02-03 20:20:1692bool ParamTraits<PP_Bool>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:2593 base::PickleIterator* iter,
[email protected]ce208f872012-03-07 20:42:5694 param_type* r) {
[email protected]799d1ab2010-11-09 17:16:2895 // We specifically want to be strict here about what types of input we accept,
96 // which ParamTraits<bool> does for us. We don't want to deserialize "2" into
97 // a PP_Bool, for example.
98 bool result = false;
bbudge03071f12015-11-02 23:51:2099 if (!ReadParam(m, iter, &result))
[email protected]799d1ab2010-11-09 17:16:28100 return false;
[email protected]8a855a02011-07-08 05:22:45101 *r = PP_FromBool(result);
[email protected]799d1ab2010-11-09 17:16:28102 return true;
103}
104
105// static
106void ParamTraits<PP_Bool>::Log(const param_type& p, std::string* l) {
107}
108
jrummella68c98f2015-01-08 22:35:43109// PP_KeyInformation -------------------------------------------------------
110
111// static
rockot502c94f2016-02-03 20:20:16112void ParamTraits<PP_KeyInformation>::Write(base::Pickle* m,
113 const param_type& p) {
jrummella68c98f2015-01-08 22:35:43114 WriteParam(m, p.key_id_size);
115 m->WriteBytes(p.key_id, static_cast<int>(p.key_id_size));
116 WriteParam(m, p.key_status);
117 WriteParam(m, p.system_code);
118}
119
120// static
rockot502c94f2016-02-03 20:20:16121bool ParamTraits<PP_KeyInformation>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25122 base::PickleIterator* iter,
jrummella68c98f2015-01-08 22:35:43123 param_type* p) {
124 uint32_t size;
125 if (!ReadParam(m, iter, &size))
126 return false;
127 if (size > sizeof(p->key_id))
128 return false;
129 p->key_id_size = size;
130
131 const char* data;
132 if (!iter->ReadBytes(&data, size))
133 return false;
134 memcpy(p->key_id, data, size);
135
136 PP_CdmKeyStatus key_status;
137 if (!ReadParam(m, iter, &key_status))
138 return false;
139 p->key_status = key_status;
140
141 uint32_t system_code;
142 if (!ReadParam(m, iter, &system_code))
143 return false;
144 p->system_code = system_code;
145
146 return true;
147}
148
149// static
150void ParamTraits<PP_KeyInformation>::Log(const param_type& p, std::string* l) {
151 l->append("<PP_KeyInformation (");
152 LogParam(p.key_id_size, l);
153 l->append(" bytes)>");
154}
155
[email protected]5a2b68f2011-11-10 00:00:49156// PP_NetAddress_Private -------------------------------------------------------
[email protected]373a95a2011-07-01 16:58:14157
158// static
jam3db6b6d2016-05-13 15:09:58159void ParamTraits<PP_NetAddress_Private>::GetSize(base::PickleSizer* s,
160 const param_type& p) {
161 GetParamSize(s, p.size);
162 s->AddBytes(static_cast<int>(p.size));
163}
164
165// static
rockot502c94f2016-02-03 20:20:16166void ParamTraits<PP_NetAddress_Private>::Write(base::Pickle* m,
[email protected]5a2b68f2011-11-10 00:00:49167 const param_type& p) {
[email protected]373a95a2011-07-01 16:58:14168 WriteParam(m, p.size);
169 m->WriteBytes(p.data, static_cast<int>(p.size));
170}
171
172// static
rockot502c94f2016-02-03 20:20:16173bool ParamTraits<PP_NetAddress_Private>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25174 base::PickleIterator* iter,
[email protected]5a2b68f2011-11-10 00:00:49175 param_type* p) {
avie029c4132015-12-23 06:45:22176 uint16_t size;
[email protected]373a95a2011-07-01 16:58:14177 if (!ReadParam(m, iter, &size))
178 return false;
179 if (size > sizeof(p->data))
180 return false;
181 p->size = size;
182
183 const char* data;
avi48fc13b2014-12-28 23:31:48184 if (!iter->ReadBytes(&data, size))
[email protected]373a95a2011-07-01 16:58:14185 return false;
186 memcpy(p->data, data, size);
187 return true;
188}
189
190// static
[email protected]5a2b68f2011-11-10 00:00:49191void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p,
192 std::string* l) {
193 l->append("<PP_NetAddress_Private (");
[email protected]373a95a2011-07-01 16:58:14194 LogParam(p.size, l);
195 l->append(" bytes)>");
196}
197
[email protected]6761d632012-04-18 17:54:49198// HostResource ----------------------------------------------------------------
199
200// static
jam3db6b6d2016-05-13 15:09:58201void ParamTraits<ppapi::HostResource>::GetSize(base::PickleSizer* s,
202 const param_type& p) {
203 GetParamSize(s, p.instance());
204 GetParamSize(s, p.host_resource());
205}
206
207// static
rockot502c94f2016-02-03 20:20:16208void ParamTraits<ppapi::HostResource>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49209 const param_type& p) {
bbudge03071f12015-11-02 23:51:20210 WriteParam(m, p.instance());
211 WriteParam(m, p.host_resource());
[email protected]6761d632012-04-18 17:54:49212}
213
214// static
rockot502c94f2016-02-03 20:20:16215bool ParamTraits<ppapi::HostResource>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25216 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49217 param_type* r) {
218 PP_Instance instance;
219 PP_Resource resource;
bbudge03071f12015-11-02 23:51:20220 if (!ReadParam(m, iter, &instance) || !ReadParam(m, iter, &resource))
[email protected]6761d632012-04-18 17:54:49221 return false;
222 r->SetHostResource(instance, resource);
223 return true;
224}
225
226// static
227void ParamTraits<ppapi::HostResource>::Log(const param_type& p,
228 std::string* l) {
229}
230
231// SerializedVar ---------------------------------------------------------------
232
233// static
rockot502c94f2016-02-03 20:20:16234void ParamTraits<ppapi::proxy::SerializedVar>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49235 const param_type& p) {
236 p.WriteToMessage(m);
237}
238
239// static
rockot502c94f2016-02-03 20:20:16240bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25241 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49242 param_type* r) {
243 return r->ReadFromMessage(m, iter);
244}
245
246// static
247void ParamTraits<ppapi::proxy::SerializedVar>::Log(const param_type& p,
248 std::string* l) {
249}
250
251// std::vector<SerializedVar> --------------------------------------------------
252
rockot502c94f2016-02-03 20:20:16253void ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Write(
254 base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49255 const param_type& p) {
256 WriteVectorWithoutCopy(m, p);
257}
258
259// static
brettwbd4d7112015-06-03 04:29:25260bool ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Read(
rockot502c94f2016-02-03 20:20:16261 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25262 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49263 param_type* r) {
264 return ReadVectorWithoutCopy(m, iter, r);
265}
266
267// static
268void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log(
269 const param_type& p,
270 std::string* l) {
271}
272
[email protected]195d4cde2012-10-02 18:12:41273// ppapi::PpapiPermissions -----------------------------------------------------
274
jam3db6b6d2016-05-13 15:09:58275// static
276void ParamTraits<ppapi::PpapiPermissions>::GetSize(base::PickleSizer* s,
277 const param_type& p) {
278 GetParamSize(s, p.GetBits());
279}
280
281// static
rockot502c94f2016-02-03 20:20:16282void ParamTraits<ppapi::PpapiPermissions>::Write(base::Pickle* m,
[email protected]195d4cde2012-10-02 18:12:41283 const param_type& p) {
bbudge03071f12015-11-02 23:51:20284 WriteParam(m, p.GetBits());
[email protected]195d4cde2012-10-02 18:12:41285}
286
287// static
rockot502c94f2016-02-03 20:20:16288bool ParamTraits<ppapi::PpapiPermissions>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25289 base::PickleIterator* iter,
[email protected]195d4cde2012-10-02 18:12:41290 param_type* r) {
291 uint32_t bits;
bbudge03071f12015-11-02 23:51:20292 if (!ReadParam(m, iter, &bits))
[email protected]195d4cde2012-10-02 18:12:41293 return false;
294 *r = ppapi::PpapiPermissions(bits);
295 return true;
296}
297
298// static
299void ParamTraits<ppapi::PpapiPermissions>::Log(const param_type& p,
300 std::string* l) {
301}
302
[email protected]246fc492012-08-27 20:28:18303// SerializedHandle ------------------------------------------------------------
304
305// static
rockot502c94f2016-02-03 20:20:16306void ParamTraits<ppapi::proxy::SerializedHandle>::Write(base::Pickle* m,
[email protected]246fc492012-08-27 20:28:18307 const param_type& p) {
308 ppapi::proxy::SerializedHandle::WriteHeader(p.header(), m);
309 switch (p.type()) {
310 case ppapi::proxy::SerializedHandle::SHARED_MEMORY:
bbudge03071f12015-11-02 23:51:20311 WriteParam(m, p.shmem());
[email protected]246fc492012-08-27 20:28:18312 break;
313 case ppapi::proxy::SerializedHandle::SOCKET:
[email protected]0c92b0d2012-12-08 00:46:23314 case ppapi::proxy::SerializedHandle::FILE:
bbudge03071f12015-11-02 23:51:20315 WriteParam(m, p.descriptor());
[email protected]246fc492012-08-27 20:28:18316 break;
317 case ppapi::proxy::SerializedHandle::INVALID:
318 break;
319 // No default so the compiler will warn on new types.
320 }
321}
322
323// static
brettwbd4d7112015-06-03 04:29:25324bool ParamTraits<ppapi::proxy::SerializedHandle>::Read(
rockot502c94f2016-02-03 20:20:16325 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25326 base::PickleIterator* iter,
327 param_type* r) {
[email protected]246fc492012-08-27 20:28:18328 ppapi::proxy::SerializedHandle::Header header;
329 if (!ppapi::proxy::SerializedHandle::ReadHeader(iter, &header))
330 return false;
331 switch (header.type) {
332 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: {
333 base::SharedMemoryHandle handle;
bbudge03071f12015-11-02 23:51:20334 if (ReadParam(m, iter, &handle)) {
[email protected]246fc492012-08-27 20:28:18335 r->set_shmem(handle, header.size);
336 return true;
337 }
338 break;
339 }
340 case ppapi::proxy::SerializedHandle::SOCKET: {
341 IPC::PlatformFileForTransit socket;
bbudge03071f12015-11-02 23:51:20342 if (ReadParam(m, iter, &socket)) {
[email protected]246fc492012-08-27 20:28:18343 r->set_socket(socket);
344 return true;
345 }
346 break;
347 }
[email protected]0c92b0d2012-12-08 00:46:23348 case ppapi::proxy::SerializedHandle::FILE: {
349 IPC::PlatformFileForTransit desc;
bbudge03071f12015-11-02 23:51:20350 if (ReadParam(m, iter, &desc)) {
[email protected]80f8f842013-12-18 22:47:57351 r->set_file_handle(desc, header.open_flags, header.file_io);
[email protected]0c92b0d2012-12-08 00:46:23352 return true;
353 }
354 break;
355 }
[email protected]246fc492012-08-27 20:28:18356 case ppapi::proxy::SerializedHandle::INVALID:
357 return true;
358 // No default so the compiler will warn us if a new type is added.
359 }
360 return false;
361}
362
363// static
364void ParamTraits<ppapi::proxy::SerializedHandle>::Log(const param_type& p,
365 std::string* l) {
366}
367
[email protected]5a5d9b5322012-10-02 22:20:23368// PPBURLLoader_UpdateProgress_Params ------------------------------------------
369
370// static
371void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Write(
rockot502c94f2016-02-03 20:20:16372 base::Pickle* m,
[email protected]5a5d9b5322012-10-02 22:20:23373 const param_type& p) {
bbudge03071f12015-11-02 23:51:20374 WriteParam(m, p.instance);
375 WriteParam(m, p.resource);
376 WriteParam(m, p.bytes_sent);
377 WriteParam(m, p.total_bytes_to_be_sent);
378 WriteParam(m, p.bytes_received);
379 WriteParam(m, p.total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23380}
381
382// static
383bool ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Read(
rockot502c94f2016-02-03 20:20:16384 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25385 base::PickleIterator* iter,
[email protected]5a5d9b5322012-10-02 22:20:23386 param_type* r) {
bbudge03071f12015-11-02 23:51:20387 return ReadParam(m, iter, &r->instance) && ReadParam(m, iter, &r->resource) &&
388 ReadParam(m, iter, &r->bytes_sent) &&
389 ReadParam(m, iter, &r->total_bytes_to_be_sent) &&
390 ReadParam(m, iter, &r->bytes_received) &&
391 ReadParam(m, iter, &r->total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23392}
393
394// static
395void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Log(
396 const param_type& p,
397 std::string* l) {
398}
399
[email protected]246fc492012-08-27 20:28:18400#if !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]6761d632012-04-18 17:54:49401// PPBFlash_DrawGlyphs_Params --------------------------------------------------
[email protected]43a40202010-11-12 16:25:01402// static
[email protected]4d2efd22011-08-18 21:58:02403void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Write(
rockot502c94f2016-02-03 20:20:16404 base::Pickle* m,
[email protected]43a40202010-11-12 16:25:01405 const param_type& p) {
bbudge03071f12015-11-02 23:51:20406 WriteParam(m, p.instance);
407 WriteParam(m, p.image_data);
408 WriteParam(m, p.font_desc);
409 WriteParam(m, p.color);
410 WriteParam(m, p.position);
411 WriteParam(m, p.clip);
412 WriteParam(m, p.transformation[0][0]);
413 WriteParam(m, p.transformation[0][1]);
414 WriteParam(m, p.transformation[0][2]);
415 WriteParam(m, p.transformation[1][0]);
416 WriteParam(m, p.transformation[1][1]);
417 WriteParam(m, p.transformation[1][2]);
418 WriteParam(m, p.transformation[2][0]);
419 WriteParam(m, p.transformation[2][1]);
420 WriteParam(m, p.transformation[2][2]);
421 WriteParam(m, p.allow_subpixel_aa);
422 WriteParam(m, p.glyph_indices);
423 WriteParam(m, p.glyph_advances);
[email protected]43a40202010-11-12 16:25:01424}
425
426// static
[email protected]4d2efd22011-08-18 21:58:02427bool ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Read(
rockot502c94f2016-02-03 20:20:16428 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25429 base::PickleIterator* iter,
[email protected]43a40202010-11-12 16:25:01430 param_type* r) {
bbudge03071f12015-11-02 23:51:20431 return ReadParam(m, iter, &r->instance) &&
432 ReadParam(m, iter, &r->image_data) &&
433 ReadParam(m, iter, &r->font_desc) && ReadParam(m, iter, &r->color) &&
434 ReadParam(m, iter, &r->position) && ReadParam(m, iter, &r->clip) &&
435 ReadParam(m, iter, &r->transformation[0][0]) &&
436 ReadParam(m, iter, &r->transformation[0][1]) &&
437 ReadParam(m, iter, &r->transformation[0][2]) &&
438 ReadParam(m, iter, &r->transformation[1][0]) &&
439 ReadParam(m, iter, &r->transformation[1][1]) &&
440 ReadParam(m, iter, &r->transformation[1][2]) &&
441 ReadParam(m, iter, &r->transformation[2][0]) &&
442 ReadParam(m, iter, &r->transformation[2][1]) &&
443 ReadParam(m, iter, &r->transformation[2][2]) &&
444 ReadParam(m, iter, &r->allow_subpixel_aa) &&
445 ReadParam(m, iter, &r->glyph_indices) &&
446 ReadParam(m, iter, &r->glyph_advances) &&
447 r->glyph_indices.size() == r->glyph_advances.size();
[email protected]43a40202010-11-12 16:25:01448}
449
450// static
[email protected]4d2efd22011-08-18 21:58:02451void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Log(
[email protected]43a40202010-11-12 16:25:01452 const param_type& p,
453 std::string* l) {
454}
455
[email protected]43a40202010-11-12 16:25:01456// SerializedDirEntry ----------------------------------------------------------
457
458// static
rockot502c94f2016-02-03 20:20:16459void ParamTraits<ppapi::proxy::SerializedDirEntry>::Write(base::Pickle* m,
[email protected]4d2efd22011-08-18 21:58:02460 const param_type& p) {
bbudge03071f12015-11-02 23:51:20461 WriteParam(m, p.name);
462 WriteParam(m, p.is_dir);
[email protected]43a40202010-11-12 16:25:01463}
464
465// static
brettwbd4d7112015-06-03 04:29:25466bool ParamTraits<ppapi::proxy::SerializedDirEntry>::Read(
rockot502c94f2016-02-03 20:20:16467 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25468 base::PickleIterator* iter,
469 param_type* r) {
bbudge03071f12015-11-02 23:51:20470 return ReadParam(m, iter, &r->name) && ReadParam(m, iter, &r->is_dir);
[email protected]43a40202010-11-12 16:25:01471}
472
473// static
[email protected]4d2efd22011-08-18 21:58:02474void ParamTraits<ppapi::proxy::SerializedDirEntry>::Log(const param_type& p,
475 std::string* l) {
[email protected]43a40202010-11-12 16:25:01476}
477
[email protected]4d2efd22011-08-18 21:58:02478// ppapi::proxy::SerializedFontDescription -------------------------------------
[email protected]799d1ab2010-11-09 17:16:28479
480// static
[email protected]4d2efd22011-08-18 21:58:02481void ParamTraits<ppapi::proxy::SerializedFontDescription>::Write(
rockot502c94f2016-02-03 20:20:16482 base::Pickle* m,
[email protected]799d1ab2010-11-09 17:16:28483 const param_type& p) {
bbudge03071f12015-11-02 23:51:20484 WriteParam(m, p.face);
485 WriteParam(m, p.family);
486 WriteParam(m, p.size);
487 WriteParam(m, p.weight);
488 WriteParam(m, p.italic);
489 WriteParam(m, p.small_caps);
490 WriteParam(m, p.letter_spacing);
491 WriteParam(m, p.word_spacing);
[email protected]799d1ab2010-11-09 17:16:28492}
493
494// static
[email protected]4d2efd22011-08-18 21:58:02495bool ParamTraits<ppapi::proxy::SerializedFontDescription>::Read(
rockot502c94f2016-02-03 20:20:16496 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25497 base::PickleIterator* iter,
[email protected]799d1ab2010-11-09 17:16:28498 param_type* r) {
bbudge03071f12015-11-02 23:51:20499 return ReadParam(m, iter, &r->face) && ReadParam(m, iter, &r->family) &&
500 ReadParam(m, iter, &r->size) && ReadParam(m, iter, &r->weight) &&
501 ReadParam(m, iter, &r->italic) && ReadParam(m, iter, &r->small_caps) &&
502 ReadParam(m, iter, &r->letter_spacing) &&
503 ReadParam(m, iter, &r->word_spacing);
[email protected]799d1ab2010-11-09 17:16:28504}
505
506// static
[email protected]4d2efd22011-08-18 21:58:02507void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log(
[email protected]799d1ab2010-11-09 17:16:28508 const param_type& p,
509 std::string* l) {
510}
[email protected]725056b72013-03-16 09:57:51511#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]799d1ab2010-11-09 17:16:28512
[email protected]725056b72013-03-16 09:57:51513// ppapi::proxy::SerializedTrueTypeFontDesc ------------------------------------
514
515// static
516void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Write(
rockot502c94f2016-02-03 20:20:16517 base::Pickle* m,
[email protected]725056b72013-03-16 09:57:51518 const param_type& p) {
bbudge03071f12015-11-02 23:51:20519 WriteParam(m, p.family);
520 WriteParam(m, p.generic_family);
521 WriteParam(m, p.style);
522 WriteParam(m, p.weight);
523 WriteParam(m, p.width);
524 WriteParam(m, p.charset);
[email protected]725056b72013-03-16 09:57:51525}
526
527// static
528bool ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Read(
rockot502c94f2016-02-03 20:20:16529 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25530 base::PickleIterator* iter,
[email protected]725056b72013-03-16 09:57:51531 param_type* r) {
bbudge03071f12015-11-02 23:51:20532 return ReadParam(m, iter, &r->family) &&
533 ReadParam(m, iter, &r->generic_family) &&
534 ReadParam(m, iter, &r->style) && ReadParam(m, iter, &r->weight) &&
535 ReadParam(m, iter, &r->width) && ReadParam(m, iter, &r->charset);
[email protected]725056b72013-03-16 09:57:51536}
537
538// static
539void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Log(
540 const param_type& p,
541 std::string* l) {
542}
543
544#if !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]0c92b0d2012-12-08 00:46:23545// ppapi::PepperFilePath -------------------------------------------------------
546
547// static
rockot502c94f2016-02-03 20:20:16548void ParamTraits<ppapi::PepperFilePath>::Write(base::Pickle* m,
[email protected]0c92b0d2012-12-08 00:46:23549 const param_type& p) {
550 WriteParam(m, static_cast<unsigned>(p.domain()));
551 WriteParam(m, p.path());
552}
553
554// static
rockot502c94f2016-02-03 20:20:16555bool ParamTraits<ppapi::PepperFilePath>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25556 base::PickleIterator* iter,
[email protected]0c92b0d2012-12-08 00:46:23557 param_type* p) {
558 unsigned domain;
[email protected]d30a36f2013-02-07 04:16:26559 base::FilePath path;
[email protected]0c92b0d2012-12-08 00:46:23560 if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path))
561 return false;
562 if (domain > ppapi::PepperFilePath::DOMAIN_MAX_VALID)
563 return false;
564
565 *p = ppapi::PepperFilePath(
566 static_cast<ppapi::PepperFilePath::Domain>(domain), path);
567 return true;
568}
569
570// static
571void ParamTraits<ppapi::PepperFilePath>::Log(const param_type& p,
572 std::string* l) {
573 l->append("(");
574 LogParam(static_cast<unsigned>(p.domain()), l);
575 l->append(", ");
576 LogParam(p.path(), l);
577 l->append(")");
578}
579
[email protected]7358d572011-02-15 18:44:40580// SerializedFlashMenu ---------------------------------------------------------
581
582// static
[email protected]4d2efd22011-08-18 21:58:02583void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Write(
rockot502c94f2016-02-03 20:20:16584 base::Pickle* m,
[email protected]4d2efd22011-08-18 21:58:02585 const param_type& p) {
[email protected]7358d572011-02-15 18:44:40586 p.WriteToMessage(m);
587}
588
589// static
brettwbd4d7112015-06-03 04:29:25590bool ParamTraits<ppapi::proxy::SerializedFlashMenu>::Read(
rockot502c94f2016-02-03 20:20:16591 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25592 base::PickleIterator* iter,
593 param_type* r) {
[email protected]7358d572011-02-15 18:44:40594 return r->ReadFromMessage(m, iter);
595}
596
597// static
[email protected]4d2efd22011-08-18 21:58:02598void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Log(const param_type& p,
599 std::string* l) {
[email protected]7358d572011-02-15 18:44:40600}
[email protected]667591d2012-09-04 21:30:12601#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]7358d572011-02-15 18:44:40602
[email protected]de2895262012-04-04 17:15:48603// PPB_X509Certificate_Fields --------------------------------------------------
604
605// static
606void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Write(
rockot502c94f2016-02-03 20:20:16607 base::Pickle* m,
[email protected]de2895262012-04-04 17:15:48608 const param_type& p) {
bbudge03071f12015-11-02 23:51:20609 WriteParam(m, p.values_);
[email protected]de2895262012-04-04 17:15:48610}
611
612// static
brettwbd4d7112015-06-03 04:29:25613bool ParamTraits<ppapi::PPB_X509Certificate_Fields>::Read(
rockot502c94f2016-02-03 20:20:16614 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25615 base::PickleIterator* iter,
616 param_type* r) {
bbudge03071f12015-11-02 23:51:20617 return ReadParam(m, iter, &(r->values_));
[email protected]de2895262012-04-04 17:15:48618}
619
620// static
621void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Log(const param_type& p,
622 std::string* l) {
623}
624
[email protected]64a61fc2013-06-19 13:30:59625// ppapi::SocketOptionData -----------------------------------------------------
626
627// static
rockot502c94f2016-02-03 20:20:16628void ParamTraits<ppapi::SocketOptionData>::Write(base::Pickle* m,
[email protected]64a61fc2013-06-19 13:30:59629 const param_type& p) {
630 ppapi::SocketOptionData::Type type = p.GetType();
bbudge03071f12015-11-02 23:51:20631 WriteParam(m, static_cast<int32_t>(type));
[email protected]64a61fc2013-06-19 13:30:59632 switch (type) {
633 case ppapi::SocketOptionData::TYPE_INVALID: {
634 break;
635 }
636 case ppapi::SocketOptionData::TYPE_BOOL: {
637 bool out_value = false;
638 bool result = p.GetBool(&out_value);
639 // Suppress unused variable warnings.
640 static_cast<void>(result);
641 DCHECK(result);
642
bbudge03071f12015-11-02 23:51:20643 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59644 break;
645 }
646 case ppapi::SocketOptionData::TYPE_INT32: {
647 int32_t out_value = 0;
648 bool result = p.GetInt32(&out_value);
649 // Suppress unused variable warnings.
650 static_cast<void>(result);
651 DCHECK(result);
652
bbudge03071f12015-11-02 23:51:20653 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59654 break;
655 }
656 // No default so the compiler will warn on new types.
657 }
658}
659
660// static
rockot502c94f2016-02-03 20:20:16661bool ParamTraits<ppapi::SocketOptionData>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25662 base::PickleIterator* iter,
[email protected]64a61fc2013-06-19 13:30:59663 param_type* r) {
664 *r = ppapi::SocketOptionData();
665 int32_t type = 0;
bbudge03071f12015-11-02 23:51:20666 if (!ReadParam(m, iter, &type))
[email protected]64a61fc2013-06-19 13:30:59667 return false;
668 if (type != ppapi::SocketOptionData::TYPE_INVALID &&
669 type != ppapi::SocketOptionData::TYPE_BOOL &&
670 type != ppapi::SocketOptionData::TYPE_INT32) {
671 return false;
672 }
673 switch (static_cast<ppapi::SocketOptionData::Type>(type)) {
674 case ppapi::SocketOptionData::TYPE_INVALID: {
675 return true;
676 }
677 case ppapi::SocketOptionData::TYPE_BOOL: {
678 bool value = false;
bbudge03071f12015-11-02 23:51:20679 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59680 return false;
681 r->SetBool(value);
682 return true;
683 }
684 case ppapi::SocketOptionData::TYPE_INT32: {
685 int32_t value = 0;
bbudge03071f12015-11-02 23:51:20686 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59687 return false;
688 r->SetInt32(value);
689 return true;
690 }
691 // No default so the compiler will warn on new types.
692 }
693 return false;
694}
695
696// static
697void ParamTraits<ppapi::SocketOptionData>::Log(const param_type& p,
698 std::string* l) {
699}
700
[email protected]c44620b2014-06-16 14:20:26701// ppapi::CompositorLayerData --------------------------------------------------
702
703// static
jam3db6b6d2016-05-13 15:09:58704void ParamTraits<ppapi::CompositorLayerData::Transform>::GetSize(
705 base::PickleSizer* s, const param_type& p) {
706 for (size_t i = 0; i < arraysize(p.matrix); i++)
707 GetParamSize(s, p.matrix[i]);
708}
709
710// static
[email protected]c44620b2014-06-16 14:20:26711void ParamTraits<ppapi::CompositorLayerData::Transform>::Write(
rockot502c94f2016-02-03 20:20:16712 base::Pickle* m,
[email protected]c44620b2014-06-16 14:20:26713 const param_type& p) {
714 for (size_t i = 0; i < arraysize(p.matrix); i++)
bbudge03071f12015-11-02 23:51:20715 WriteParam(m, p.matrix[i]);
[email protected]c44620b2014-06-16 14:20:26716}
717
718// static
719bool ParamTraits<ppapi::CompositorLayerData::Transform>::Read(
rockot502c94f2016-02-03 20:20:16720 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25721 base::PickleIterator* iter,
[email protected]c44620b2014-06-16 14:20:26722 param_type* r) {
723 for (size_t i = 0; i < arraysize(r->matrix);i++) {
bbudge03071f12015-11-02 23:51:20724 if (!ReadParam(m, iter, &r->matrix[i]))
[email protected]c44620b2014-06-16 14:20:26725 return false;
726 }
727 return true;
728}
729
730void ParamTraits<ppapi::CompositorLayerData::Transform>::Log(
731 const param_type& p,
732 std::string* l) {
733}
734
[email protected]c2932f5e2010-11-03 03:22:33735} // namespace IPC