blob: 9d21eac13400d49d90aa67ff86bce55001b071ea [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
rockot502c94f2016-02-03 20:20:1682void ParamTraits<PP_Bool>::Write(base::Pickle* m, const param_type& p) {
bbudge03071f12015-11-02 23:51:2083 WriteParam(m, PP_ToBool(p));
[email protected]799d1ab2010-11-09 17:16:2884}
85
86// static
rockot502c94f2016-02-03 20:20:1687bool ParamTraits<PP_Bool>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:2588 base::PickleIterator* iter,
[email protected]ce208f872012-03-07 20:42:5689 param_type* r) {
[email protected]799d1ab2010-11-09 17:16:2890 // We specifically want to be strict here about what types of input we accept,
91 // which ParamTraits<bool> does for us. We don't want to deserialize "2" into
92 // a PP_Bool, for example.
93 bool result = false;
bbudge03071f12015-11-02 23:51:2094 if (!ReadParam(m, iter, &result))
[email protected]799d1ab2010-11-09 17:16:2895 return false;
[email protected]8a855a02011-07-08 05:22:4596 *r = PP_FromBool(result);
[email protected]799d1ab2010-11-09 17:16:2897 return true;
98}
99
100// static
101void ParamTraits<PP_Bool>::Log(const param_type& p, std::string* l) {
102}
103
jrummella68c98f2015-01-08 22:35:43104// PP_KeyInformation -------------------------------------------------------
105
106// static
rockot502c94f2016-02-03 20:20:16107void ParamTraits<PP_KeyInformation>::Write(base::Pickle* m,
108 const param_type& p) {
jrummella68c98f2015-01-08 22:35:43109 WriteParam(m, p.key_id_size);
110 m->WriteBytes(p.key_id, static_cast<int>(p.key_id_size));
111 WriteParam(m, p.key_status);
112 WriteParam(m, p.system_code);
113}
114
115// static
rockot502c94f2016-02-03 20:20:16116bool ParamTraits<PP_KeyInformation>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25117 base::PickleIterator* iter,
jrummella68c98f2015-01-08 22:35:43118 param_type* p) {
119 uint32_t size;
120 if (!ReadParam(m, iter, &size))
121 return false;
122 if (size > sizeof(p->key_id))
123 return false;
124 p->key_id_size = size;
125
126 const char* data;
127 if (!iter->ReadBytes(&data, size))
128 return false;
129 memcpy(p->key_id, data, size);
130
131 PP_CdmKeyStatus key_status;
132 if (!ReadParam(m, iter, &key_status))
133 return false;
134 p->key_status = key_status;
135
136 uint32_t system_code;
137 if (!ReadParam(m, iter, &system_code))
138 return false;
139 p->system_code = system_code;
140
141 return true;
142}
143
144// static
145void ParamTraits<PP_KeyInformation>::Log(const param_type& p, std::string* l) {
146 l->append("<PP_KeyInformation (");
147 LogParam(p.key_id_size, l);
148 l->append(" bytes)>");
149}
150
[email protected]5a2b68f2011-11-10 00:00:49151// PP_NetAddress_Private -------------------------------------------------------
[email protected]373a95a2011-07-01 16:58:14152
153// static
rockot502c94f2016-02-03 20:20:16154void ParamTraits<PP_NetAddress_Private>::Write(base::Pickle* m,
[email protected]5a2b68f2011-11-10 00:00:49155 const param_type& p) {
[email protected]373a95a2011-07-01 16:58:14156 WriteParam(m, p.size);
157 m->WriteBytes(p.data, static_cast<int>(p.size));
158}
159
160// static
rockot502c94f2016-02-03 20:20:16161bool ParamTraits<PP_NetAddress_Private>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25162 base::PickleIterator* iter,
[email protected]5a2b68f2011-11-10 00:00:49163 param_type* p) {
avie029c4132015-12-23 06:45:22164 uint16_t size;
[email protected]373a95a2011-07-01 16:58:14165 if (!ReadParam(m, iter, &size))
166 return false;
167 if (size > sizeof(p->data))
168 return false;
169 p->size = size;
170
171 const char* data;
avi48fc13b2014-12-28 23:31:48172 if (!iter->ReadBytes(&data, size))
[email protected]373a95a2011-07-01 16:58:14173 return false;
174 memcpy(p->data, data, size);
175 return true;
176}
177
178// static
[email protected]5a2b68f2011-11-10 00:00:49179void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p,
180 std::string* l) {
181 l->append("<PP_NetAddress_Private (");
[email protected]373a95a2011-07-01 16:58:14182 LogParam(p.size, l);
183 l->append(" bytes)>");
184}
185
[email protected]6761d632012-04-18 17:54:49186// HostResource ----------------------------------------------------------------
187
188// static
rockot502c94f2016-02-03 20:20:16189void ParamTraits<ppapi::HostResource>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49190 const param_type& p) {
bbudge03071f12015-11-02 23:51:20191 WriteParam(m, p.instance());
192 WriteParam(m, p.host_resource());
[email protected]6761d632012-04-18 17:54:49193}
194
195// static
rockot502c94f2016-02-03 20:20:16196bool ParamTraits<ppapi::HostResource>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25197 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49198 param_type* r) {
199 PP_Instance instance;
200 PP_Resource resource;
bbudge03071f12015-11-02 23:51:20201 if (!ReadParam(m, iter, &instance) || !ReadParam(m, iter, &resource))
[email protected]6761d632012-04-18 17:54:49202 return false;
203 r->SetHostResource(instance, resource);
204 return true;
205}
206
207// static
208void ParamTraits<ppapi::HostResource>::Log(const param_type& p,
209 std::string* l) {
210}
211
212// SerializedVar ---------------------------------------------------------------
213
214// static
rockot502c94f2016-02-03 20:20:16215void ParamTraits<ppapi::proxy::SerializedVar>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49216 const param_type& p) {
217 p.WriteToMessage(m);
218}
219
220// static
rockot502c94f2016-02-03 20:20:16221bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25222 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49223 param_type* r) {
224 return r->ReadFromMessage(m, iter);
225}
226
227// static
228void ParamTraits<ppapi::proxy::SerializedVar>::Log(const param_type& p,
229 std::string* l) {
230}
231
232// std::vector<SerializedVar> --------------------------------------------------
233
rockot502c94f2016-02-03 20:20:16234void ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Write(
235 base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49236 const param_type& p) {
237 WriteVectorWithoutCopy(m, p);
238}
239
240// static
brettwbd4d7112015-06-03 04:29:25241bool ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Read(
rockot502c94f2016-02-03 20:20:16242 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25243 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49244 param_type* r) {
245 return ReadVectorWithoutCopy(m, iter, r);
246}
247
248// static
249void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log(
250 const param_type& p,
251 std::string* l) {
252}
253
[email protected]195d4cde2012-10-02 18:12:41254// ppapi::PpapiPermissions -----------------------------------------------------
255
rockot502c94f2016-02-03 20:20:16256void ParamTraits<ppapi::PpapiPermissions>::Write(base::Pickle* m,
[email protected]195d4cde2012-10-02 18:12:41257 const param_type& p) {
bbudge03071f12015-11-02 23:51:20258 WriteParam(m, p.GetBits());
[email protected]195d4cde2012-10-02 18:12:41259}
260
261// static
rockot502c94f2016-02-03 20:20:16262bool ParamTraits<ppapi::PpapiPermissions>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25263 base::PickleIterator* iter,
[email protected]195d4cde2012-10-02 18:12:41264 param_type* r) {
265 uint32_t bits;
bbudge03071f12015-11-02 23:51:20266 if (!ReadParam(m, iter, &bits))
[email protected]195d4cde2012-10-02 18:12:41267 return false;
268 *r = ppapi::PpapiPermissions(bits);
269 return true;
270}
271
272// static
273void ParamTraits<ppapi::PpapiPermissions>::Log(const param_type& p,
274 std::string* l) {
275}
276
[email protected]246fc492012-08-27 20:28:18277// SerializedHandle ------------------------------------------------------------
278
279// static
rockot502c94f2016-02-03 20:20:16280void ParamTraits<ppapi::proxy::SerializedHandle>::Write(base::Pickle* m,
[email protected]246fc492012-08-27 20:28:18281 const param_type& p) {
282 ppapi::proxy::SerializedHandle::WriteHeader(p.header(), m);
283 switch (p.type()) {
284 case ppapi::proxy::SerializedHandle::SHARED_MEMORY:
bbudge03071f12015-11-02 23:51:20285 WriteParam(m, p.shmem());
[email protected]246fc492012-08-27 20:28:18286 break;
287 case ppapi::proxy::SerializedHandle::SOCKET:
[email protected]0c92b0d2012-12-08 00:46:23288 case ppapi::proxy::SerializedHandle::FILE:
bbudge03071f12015-11-02 23:51:20289 WriteParam(m, p.descriptor());
[email protected]246fc492012-08-27 20:28:18290 break;
291 case ppapi::proxy::SerializedHandle::INVALID:
292 break;
293 // No default so the compiler will warn on new types.
294 }
295}
296
297// static
brettwbd4d7112015-06-03 04:29:25298bool ParamTraits<ppapi::proxy::SerializedHandle>::Read(
rockot502c94f2016-02-03 20:20:16299 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25300 base::PickleIterator* iter,
301 param_type* r) {
[email protected]246fc492012-08-27 20:28:18302 ppapi::proxy::SerializedHandle::Header header;
303 if (!ppapi::proxy::SerializedHandle::ReadHeader(iter, &header))
304 return false;
305 switch (header.type) {
306 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: {
307 base::SharedMemoryHandle handle;
bbudge03071f12015-11-02 23:51:20308 if (ReadParam(m, iter, &handle)) {
[email protected]246fc492012-08-27 20:28:18309 r->set_shmem(handle, header.size);
310 return true;
311 }
312 break;
313 }
314 case ppapi::proxy::SerializedHandle::SOCKET: {
315 IPC::PlatformFileForTransit socket;
bbudge03071f12015-11-02 23:51:20316 if (ReadParam(m, iter, &socket)) {
[email protected]246fc492012-08-27 20:28:18317 r->set_socket(socket);
318 return true;
319 }
320 break;
321 }
[email protected]0c92b0d2012-12-08 00:46:23322 case ppapi::proxy::SerializedHandle::FILE: {
323 IPC::PlatformFileForTransit desc;
bbudge03071f12015-11-02 23:51:20324 if (ReadParam(m, iter, &desc)) {
[email protected]80f8f842013-12-18 22:47:57325 r->set_file_handle(desc, header.open_flags, header.file_io);
[email protected]0c92b0d2012-12-08 00:46:23326 return true;
327 }
328 break;
329 }
[email protected]246fc492012-08-27 20:28:18330 case ppapi::proxy::SerializedHandle::INVALID:
331 return true;
332 // No default so the compiler will warn us if a new type is added.
333 }
334 return false;
335}
336
337// static
338void ParamTraits<ppapi::proxy::SerializedHandle>::Log(const param_type& p,
339 std::string* l) {
340}
341
[email protected]5a5d9b5322012-10-02 22:20:23342// PPBURLLoader_UpdateProgress_Params ------------------------------------------
343
344// static
345void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Write(
rockot502c94f2016-02-03 20:20:16346 base::Pickle* m,
[email protected]5a5d9b5322012-10-02 22:20:23347 const param_type& p) {
bbudge03071f12015-11-02 23:51:20348 WriteParam(m, p.instance);
349 WriteParam(m, p.resource);
350 WriteParam(m, p.bytes_sent);
351 WriteParam(m, p.total_bytes_to_be_sent);
352 WriteParam(m, p.bytes_received);
353 WriteParam(m, p.total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23354}
355
356// static
357bool ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Read(
rockot502c94f2016-02-03 20:20:16358 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25359 base::PickleIterator* iter,
[email protected]5a5d9b5322012-10-02 22:20:23360 param_type* r) {
bbudge03071f12015-11-02 23:51:20361 return ReadParam(m, iter, &r->instance) && ReadParam(m, iter, &r->resource) &&
362 ReadParam(m, iter, &r->bytes_sent) &&
363 ReadParam(m, iter, &r->total_bytes_to_be_sent) &&
364 ReadParam(m, iter, &r->bytes_received) &&
365 ReadParam(m, iter, &r->total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23366}
367
368// static
369void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Log(
370 const param_type& p,
371 std::string* l) {
372}
373
[email protected]246fc492012-08-27 20:28:18374#if !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]6761d632012-04-18 17:54:49375// PPBFlash_DrawGlyphs_Params --------------------------------------------------
[email protected]43a40202010-11-12 16:25:01376// static
[email protected]4d2efd22011-08-18 21:58:02377void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Write(
rockot502c94f2016-02-03 20:20:16378 base::Pickle* m,
[email protected]43a40202010-11-12 16:25:01379 const param_type& p) {
bbudge03071f12015-11-02 23:51:20380 WriteParam(m, p.instance);
381 WriteParam(m, p.image_data);
382 WriteParam(m, p.font_desc);
383 WriteParam(m, p.color);
384 WriteParam(m, p.position);
385 WriteParam(m, p.clip);
386 WriteParam(m, p.transformation[0][0]);
387 WriteParam(m, p.transformation[0][1]);
388 WriteParam(m, p.transformation[0][2]);
389 WriteParam(m, p.transformation[1][0]);
390 WriteParam(m, p.transformation[1][1]);
391 WriteParam(m, p.transformation[1][2]);
392 WriteParam(m, p.transformation[2][0]);
393 WriteParam(m, p.transformation[2][1]);
394 WriteParam(m, p.transformation[2][2]);
395 WriteParam(m, p.allow_subpixel_aa);
396 WriteParam(m, p.glyph_indices);
397 WriteParam(m, p.glyph_advances);
[email protected]43a40202010-11-12 16:25:01398}
399
400// static
[email protected]4d2efd22011-08-18 21:58:02401bool ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Read(
rockot502c94f2016-02-03 20:20:16402 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25403 base::PickleIterator* iter,
[email protected]43a40202010-11-12 16:25:01404 param_type* r) {
bbudge03071f12015-11-02 23:51:20405 return ReadParam(m, iter, &r->instance) &&
406 ReadParam(m, iter, &r->image_data) &&
407 ReadParam(m, iter, &r->font_desc) && ReadParam(m, iter, &r->color) &&
408 ReadParam(m, iter, &r->position) && ReadParam(m, iter, &r->clip) &&
409 ReadParam(m, iter, &r->transformation[0][0]) &&
410 ReadParam(m, iter, &r->transformation[0][1]) &&
411 ReadParam(m, iter, &r->transformation[0][2]) &&
412 ReadParam(m, iter, &r->transformation[1][0]) &&
413 ReadParam(m, iter, &r->transformation[1][1]) &&
414 ReadParam(m, iter, &r->transformation[1][2]) &&
415 ReadParam(m, iter, &r->transformation[2][0]) &&
416 ReadParam(m, iter, &r->transformation[2][1]) &&
417 ReadParam(m, iter, &r->transformation[2][2]) &&
418 ReadParam(m, iter, &r->allow_subpixel_aa) &&
419 ReadParam(m, iter, &r->glyph_indices) &&
420 ReadParam(m, iter, &r->glyph_advances) &&
421 r->glyph_indices.size() == r->glyph_advances.size();
[email protected]43a40202010-11-12 16:25:01422}
423
424// static
[email protected]4d2efd22011-08-18 21:58:02425void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Log(
[email protected]43a40202010-11-12 16:25:01426 const param_type& p,
427 std::string* l) {
428}
429
[email protected]43a40202010-11-12 16:25:01430// SerializedDirEntry ----------------------------------------------------------
431
432// static
rockot502c94f2016-02-03 20:20:16433void ParamTraits<ppapi::proxy::SerializedDirEntry>::Write(base::Pickle* m,
[email protected]4d2efd22011-08-18 21:58:02434 const param_type& p) {
bbudge03071f12015-11-02 23:51:20435 WriteParam(m, p.name);
436 WriteParam(m, p.is_dir);
[email protected]43a40202010-11-12 16:25:01437}
438
439// static
brettwbd4d7112015-06-03 04:29:25440bool ParamTraits<ppapi::proxy::SerializedDirEntry>::Read(
rockot502c94f2016-02-03 20:20:16441 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25442 base::PickleIterator* iter,
443 param_type* r) {
bbudge03071f12015-11-02 23:51:20444 return ReadParam(m, iter, &r->name) && ReadParam(m, iter, &r->is_dir);
[email protected]43a40202010-11-12 16:25:01445}
446
447// static
[email protected]4d2efd22011-08-18 21:58:02448void ParamTraits<ppapi::proxy::SerializedDirEntry>::Log(const param_type& p,
449 std::string* l) {
[email protected]43a40202010-11-12 16:25:01450}
451
[email protected]4d2efd22011-08-18 21:58:02452// ppapi::proxy::SerializedFontDescription -------------------------------------
[email protected]799d1ab2010-11-09 17:16:28453
454// static
[email protected]4d2efd22011-08-18 21:58:02455void ParamTraits<ppapi::proxy::SerializedFontDescription>::Write(
rockot502c94f2016-02-03 20:20:16456 base::Pickle* m,
[email protected]799d1ab2010-11-09 17:16:28457 const param_type& p) {
bbudge03071f12015-11-02 23:51:20458 WriteParam(m, p.face);
459 WriteParam(m, p.family);
460 WriteParam(m, p.size);
461 WriteParam(m, p.weight);
462 WriteParam(m, p.italic);
463 WriteParam(m, p.small_caps);
464 WriteParam(m, p.letter_spacing);
465 WriteParam(m, p.word_spacing);
[email protected]799d1ab2010-11-09 17:16:28466}
467
468// static
[email protected]4d2efd22011-08-18 21:58:02469bool ParamTraits<ppapi::proxy::SerializedFontDescription>::Read(
rockot502c94f2016-02-03 20:20:16470 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25471 base::PickleIterator* iter,
[email protected]799d1ab2010-11-09 17:16:28472 param_type* r) {
bbudge03071f12015-11-02 23:51:20473 return ReadParam(m, iter, &r->face) && ReadParam(m, iter, &r->family) &&
474 ReadParam(m, iter, &r->size) && ReadParam(m, iter, &r->weight) &&
475 ReadParam(m, iter, &r->italic) && ReadParam(m, iter, &r->small_caps) &&
476 ReadParam(m, iter, &r->letter_spacing) &&
477 ReadParam(m, iter, &r->word_spacing);
[email protected]799d1ab2010-11-09 17:16:28478}
479
480// static
[email protected]4d2efd22011-08-18 21:58:02481void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log(
[email protected]799d1ab2010-11-09 17:16:28482 const param_type& p,
483 std::string* l) {
484}
[email protected]725056b72013-03-16 09:57:51485#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]799d1ab2010-11-09 17:16:28486
[email protected]725056b72013-03-16 09:57:51487// ppapi::proxy::SerializedTrueTypeFontDesc ------------------------------------
488
489// static
490void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Write(
rockot502c94f2016-02-03 20:20:16491 base::Pickle* m,
[email protected]725056b72013-03-16 09:57:51492 const param_type& p) {
bbudge03071f12015-11-02 23:51:20493 WriteParam(m, p.family);
494 WriteParam(m, p.generic_family);
495 WriteParam(m, p.style);
496 WriteParam(m, p.weight);
497 WriteParam(m, p.width);
498 WriteParam(m, p.charset);
[email protected]725056b72013-03-16 09:57:51499}
500
501// static
502bool ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Read(
rockot502c94f2016-02-03 20:20:16503 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25504 base::PickleIterator* iter,
[email protected]725056b72013-03-16 09:57:51505 param_type* r) {
bbudge03071f12015-11-02 23:51:20506 return ReadParam(m, iter, &r->family) &&
507 ReadParam(m, iter, &r->generic_family) &&
508 ReadParam(m, iter, &r->style) && ReadParam(m, iter, &r->weight) &&
509 ReadParam(m, iter, &r->width) && ReadParam(m, iter, &r->charset);
[email protected]725056b72013-03-16 09:57:51510}
511
512// static
513void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Log(
514 const param_type& p,
515 std::string* l) {
516}
517
518#if !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]0c92b0d2012-12-08 00:46:23519// ppapi::PepperFilePath -------------------------------------------------------
520
521// static
rockot502c94f2016-02-03 20:20:16522void ParamTraits<ppapi::PepperFilePath>::Write(base::Pickle* m,
[email protected]0c92b0d2012-12-08 00:46:23523 const param_type& p) {
524 WriteParam(m, static_cast<unsigned>(p.domain()));
525 WriteParam(m, p.path());
526}
527
528// static
rockot502c94f2016-02-03 20:20:16529bool ParamTraits<ppapi::PepperFilePath>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25530 base::PickleIterator* iter,
[email protected]0c92b0d2012-12-08 00:46:23531 param_type* p) {
532 unsigned domain;
[email protected]d30a36f2013-02-07 04:16:26533 base::FilePath path;
[email protected]0c92b0d2012-12-08 00:46:23534 if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path))
535 return false;
536 if (domain > ppapi::PepperFilePath::DOMAIN_MAX_VALID)
537 return false;
538
539 *p = ppapi::PepperFilePath(
540 static_cast<ppapi::PepperFilePath::Domain>(domain), path);
541 return true;
542}
543
544// static
545void ParamTraits<ppapi::PepperFilePath>::Log(const param_type& p,
546 std::string* l) {
547 l->append("(");
548 LogParam(static_cast<unsigned>(p.domain()), l);
549 l->append(", ");
550 LogParam(p.path(), l);
551 l->append(")");
552}
553
[email protected]7358d572011-02-15 18:44:40554// SerializedFlashMenu ---------------------------------------------------------
555
556// static
[email protected]4d2efd22011-08-18 21:58:02557void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Write(
rockot502c94f2016-02-03 20:20:16558 base::Pickle* m,
[email protected]4d2efd22011-08-18 21:58:02559 const param_type& p) {
[email protected]7358d572011-02-15 18:44:40560 p.WriteToMessage(m);
561}
562
563// static
brettwbd4d7112015-06-03 04:29:25564bool ParamTraits<ppapi::proxy::SerializedFlashMenu>::Read(
rockot502c94f2016-02-03 20:20:16565 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25566 base::PickleIterator* iter,
567 param_type* r) {
[email protected]7358d572011-02-15 18:44:40568 return r->ReadFromMessage(m, iter);
569}
570
571// static
[email protected]4d2efd22011-08-18 21:58:02572void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Log(const param_type& p,
573 std::string* l) {
[email protected]7358d572011-02-15 18:44:40574}
[email protected]667591d2012-09-04 21:30:12575#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
[email protected]7358d572011-02-15 18:44:40576
[email protected]de2895262012-04-04 17:15:48577// PPB_X509Certificate_Fields --------------------------------------------------
578
579// static
580void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Write(
rockot502c94f2016-02-03 20:20:16581 base::Pickle* m,
[email protected]de2895262012-04-04 17:15:48582 const param_type& p) {
bbudge03071f12015-11-02 23:51:20583 WriteParam(m, p.values_);
[email protected]de2895262012-04-04 17:15:48584}
585
586// static
brettwbd4d7112015-06-03 04:29:25587bool ParamTraits<ppapi::PPB_X509Certificate_Fields>::Read(
rockot502c94f2016-02-03 20:20:16588 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25589 base::PickleIterator* iter,
590 param_type* r) {
bbudge03071f12015-11-02 23:51:20591 return ReadParam(m, iter, &(r->values_));
[email protected]de2895262012-04-04 17:15:48592}
593
594// static
595void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Log(const param_type& p,
596 std::string* l) {
597}
598
[email protected]64a61fc2013-06-19 13:30:59599// ppapi::SocketOptionData -----------------------------------------------------
600
601// static
rockot502c94f2016-02-03 20:20:16602void ParamTraits<ppapi::SocketOptionData>::Write(base::Pickle* m,
[email protected]64a61fc2013-06-19 13:30:59603 const param_type& p) {
604 ppapi::SocketOptionData::Type type = p.GetType();
bbudge03071f12015-11-02 23:51:20605 WriteParam(m, static_cast<int32_t>(type));
[email protected]64a61fc2013-06-19 13:30:59606 switch (type) {
607 case ppapi::SocketOptionData::TYPE_INVALID: {
608 break;
609 }
610 case ppapi::SocketOptionData::TYPE_BOOL: {
611 bool out_value = false;
612 bool result = p.GetBool(&out_value);
613 // Suppress unused variable warnings.
614 static_cast<void>(result);
615 DCHECK(result);
616
bbudge03071f12015-11-02 23:51:20617 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59618 break;
619 }
620 case ppapi::SocketOptionData::TYPE_INT32: {
621 int32_t out_value = 0;
622 bool result = p.GetInt32(&out_value);
623 // Suppress unused variable warnings.
624 static_cast<void>(result);
625 DCHECK(result);
626
bbudge03071f12015-11-02 23:51:20627 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59628 break;
629 }
630 // No default so the compiler will warn on new types.
631 }
632}
633
634// static
rockot502c94f2016-02-03 20:20:16635bool ParamTraits<ppapi::SocketOptionData>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25636 base::PickleIterator* iter,
[email protected]64a61fc2013-06-19 13:30:59637 param_type* r) {
638 *r = ppapi::SocketOptionData();
639 int32_t type = 0;
bbudge03071f12015-11-02 23:51:20640 if (!ReadParam(m, iter, &type))
[email protected]64a61fc2013-06-19 13:30:59641 return false;
642 if (type != ppapi::SocketOptionData::TYPE_INVALID &&
643 type != ppapi::SocketOptionData::TYPE_BOOL &&
644 type != ppapi::SocketOptionData::TYPE_INT32) {
645 return false;
646 }
647 switch (static_cast<ppapi::SocketOptionData::Type>(type)) {
648 case ppapi::SocketOptionData::TYPE_INVALID: {
649 return true;
650 }
651 case ppapi::SocketOptionData::TYPE_BOOL: {
652 bool value = false;
bbudge03071f12015-11-02 23:51:20653 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59654 return false;
655 r->SetBool(value);
656 return true;
657 }
658 case ppapi::SocketOptionData::TYPE_INT32: {
659 int32_t value = 0;
bbudge03071f12015-11-02 23:51:20660 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59661 return false;
662 r->SetInt32(value);
663 return true;
664 }
665 // No default so the compiler will warn on new types.
666 }
667 return false;
668}
669
670// static
671void ParamTraits<ppapi::SocketOptionData>::Log(const param_type& p,
672 std::string* l) {
673}
674
[email protected]c44620b2014-06-16 14:20:26675// ppapi::CompositorLayerData --------------------------------------------------
676
677// static
678void ParamTraits<ppapi::CompositorLayerData::Transform>::Write(
rockot502c94f2016-02-03 20:20:16679 base::Pickle* m,
[email protected]c44620b2014-06-16 14:20:26680 const param_type& p) {
681 for (size_t i = 0; i < arraysize(p.matrix); i++)
bbudge03071f12015-11-02 23:51:20682 WriteParam(m, p.matrix[i]);
[email protected]c44620b2014-06-16 14:20:26683}
684
685// static
686bool ParamTraits<ppapi::CompositorLayerData::Transform>::Read(
rockot502c94f2016-02-03 20:20:16687 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25688 base::PickleIterator* iter,
[email protected]c44620b2014-06-16 14:20:26689 param_type* r) {
690 for (size_t i = 0; i < arraysize(r->matrix);i++) {
bbudge03071f12015-11-02 23:51:20691 if (!ReadParam(m, iter, &r->matrix[i]))
[email protected]c44620b2014-06-16 14:20:26692 return false;
693 }
694 return true;
695}
696
697void ParamTraits<ppapi::CompositorLayerData::Transform>::Log(
698 const param_type& p,
699 std::string* l) {
700}
701
[email protected]c2932f5e2010-11-03 03:22:33702} // namespace IPC