[email protected] | 339fbcff | 2012-02-29 16:10:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 2 | // 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 | |
| 7 | #include <string.h> // For memcpy |
| 8 | |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 9 | #include "ppapi/c/pp_resource.h" |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 10 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 11 | #include "ppapi/proxy/serialized_var.h" |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 12 | #include "ppapi/proxy/serialized_flash_menu.h" |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 13 | #include "ppapi/shared_impl/host_resource.h" |
[email protected] | de289526 | 2012-04-04 17:15:48 | [diff] [blame] | 14 | #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 15 | |
| 16 | namespace IPC { |
| 17 | |
[email protected] | 1162a6a | 2011-04-21 17:28:16 | [diff] [blame] | 18 | namespace { |
| 19 | |
| 20 | // Deserializes a vector from IPC. This special version must be used instead |
| 21 | // of the default IPC version when the vector contains a SerializedVar, either |
| 22 | // directly or indirectly (i.e. a vector of objects that have a SerializedVar |
| 23 | // inside them). |
| 24 | // |
| 25 | // The default vector deserializer does resize and then we deserialize into |
| 26 | // those allocated slots. However, the implementation of vector (at least in |
| 27 | // GCC's implementation), creates a new empty object using the default |
| 28 | // constructor, and then sets the rest of the items to that empty one using the |
| 29 | // copy constructor. |
| 30 | // |
| 31 | // Since we allocate the inner class when you call the default constructor and |
| 32 | // transfer the inner class when you do operator=, the entire vector will end |
| 33 | // up referring to the same inner class. Deserializing into this will just end |
| 34 | // up overwriting the same item over and over, since all the SerializedVars |
| 35 | // will refer to the same thing. |
| 36 | // |
| 37 | // The solution is to make a new object for each deserialized item, and then |
| 38 | // add it to the vector one at a time. |
| 39 | template<typename T> |
| 40 | bool ReadVectorWithoutCopy(const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 41 | PickleIterator* iter, |
[email protected] | 1162a6a | 2011-04-21 17:28:16 | [diff] [blame] | 42 | std::vector<T>* output) { |
| 43 | // This part is just a copy of the the default ParamTraits vector Read(). |
| 44 | int size; |
| 45 | // ReadLength() checks for < 0 itself. |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 46 | if (!iter->ReadLength(&size)) |
[email protected] | 1162a6a | 2011-04-21 17:28:16 | [diff] [blame] | 47 | return false; |
| 48 | // Resizing beforehand is not safe, see BUG 1006367 for details. |
| 49 | if (INT_MAX / sizeof(T) <= static_cast<size_t>(size)) |
| 50 | return false; |
| 51 | |
| 52 | output->reserve(size); |
| 53 | for (int i = 0; i < size; i++) { |
| 54 | T cur; |
| 55 | if (!ReadParam(m, iter, &cur)) |
| 56 | return false; |
| 57 | output->push_back(cur); |
| 58 | } |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | // This serializes the vector of items to the IPC message in exactly the same |
| 63 | // way as the "regular" IPC vector serializer does. But having the code here |
| 64 | // saves us from having to copy this code into all ParamTraits that use the |
| 65 | // ReadVectorWithoutCopy function for deserializing. |
| 66 | template<typename T> |
| 67 | void WriteVectorWithoutCopy(Message* m, const std::vector<T>& p) { |
| 68 | WriteParam(m, static_cast<int>(p.size())); |
| 69 | for (size_t i = 0; i < p.size(); i++) |
| 70 | WriteParam(m, p[i]); |
| 71 | } |
| 72 | |
| 73 | } // namespace |
| 74 | |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 75 | // PP_Bool --------------------------------------------------------------------- |
| 76 | |
| 77 | // static |
| 78 | void ParamTraits<PP_Bool>::Write(Message* m, const param_type& p) { |
[email protected] | 8a855a0 | 2011-07-08 05:22:45 | [diff] [blame] | 79 | ParamTraits<bool>::Write(m, PP_ToBool(p)); |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // static |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 83 | bool ParamTraits<PP_Bool>::Read(const Message* m, |
| 84 | PickleIterator* iter, |
| 85 | param_type* r) { |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 86 | // We specifically want to be strict here about what types of input we accept, |
| 87 | // which ParamTraits<bool> does for us. We don't want to deserialize "2" into |
| 88 | // a PP_Bool, for example. |
| 89 | bool result = false; |
| 90 | if (!ParamTraits<bool>::Read(m, iter, &result)) |
| 91 | return false; |
[email protected] | 8a855a0 | 2011-07-08 05:22:45 | [diff] [blame] | 92 | *r = PP_FromBool(result); |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 93 | return true; |
| 94 | } |
| 95 | |
| 96 | // static |
| 97 | void ParamTraits<PP_Bool>::Log(const param_type& p, std::string* l) { |
| 98 | } |
| 99 | |
jrummell | a68c98f | 2015-01-08 22:35:43 | [diff] [blame^] | 100 | // PP_KeyInformation ------------------------------------------------------- |
| 101 | |
| 102 | // static |
| 103 | void ParamTraits<PP_KeyInformation>::Write(Message* m, const param_type& p) { |
| 104 | WriteParam(m, p.key_id_size); |
| 105 | m->WriteBytes(p.key_id, static_cast<int>(p.key_id_size)); |
| 106 | WriteParam(m, p.key_status); |
| 107 | WriteParam(m, p.system_code); |
| 108 | } |
| 109 | |
| 110 | // static |
| 111 | bool ParamTraits<PP_KeyInformation>::Read(const Message* m, |
| 112 | PickleIterator* iter, |
| 113 | param_type* p) { |
| 114 | uint32_t size; |
| 115 | if (!ReadParam(m, iter, &size)) |
| 116 | return false; |
| 117 | if (size > sizeof(p->key_id)) |
| 118 | return false; |
| 119 | p->key_id_size = size; |
| 120 | |
| 121 | const char* data; |
| 122 | if (!iter->ReadBytes(&data, size)) |
| 123 | return false; |
| 124 | memcpy(p->key_id, data, size); |
| 125 | |
| 126 | PP_CdmKeyStatus key_status; |
| 127 | if (!ReadParam(m, iter, &key_status)) |
| 128 | return false; |
| 129 | p->key_status = key_status; |
| 130 | |
| 131 | uint32_t system_code; |
| 132 | if (!ReadParam(m, iter, &system_code)) |
| 133 | return false; |
| 134 | p->system_code = system_code; |
| 135 | |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | // static |
| 140 | void ParamTraits<PP_KeyInformation>::Log(const param_type& p, std::string* l) { |
| 141 | l->append("<PP_KeyInformation ("); |
| 142 | LogParam(p.key_id_size, l); |
| 143 | l->append(" bytes)>"); |
| 144 | } |
| 145 | |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 146 | // PP_NetAddress_Private ------------------------------------------------------- |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 147 | |
| 148 | // static |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 149 | void ParamTraits<PP_NetAddress_Private>::Write(Message* m, |
| 150 | const param_type& p) { |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 151 | WriteParam(m, p.size); |
| 152 | m->WriteBytes(p.data, static_cast<int>(p.size)); |
| 153 | } |
| 154 | |
| 155 | // static |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 156 | bool ParamTraits<PP_NetAddress_Private>::Read(const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 157 | PickleIterator* iter, |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 158 | param_type* p) { |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 159 | uint16 size; |
| 160 | if (!ReadParam(m, iter, &size)) |
| 161 | return false; |
| 162 | if (size > sizeof(p->data)) |
| 163 | return false; |
| 164 | p->size = size; |
| 165 | |
| 166 | const char* data; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 167 | if (!iter->ReadBytes(&data, size)) |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 168 | return false; |
| 169 | memcpy(p->data, data, size); |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | // static |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 174 | void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p, |
| 175 | std::string* l) { |
| 176 | l->append("<PP_NetAddress_Private ("); |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 177 | LogParam(p.size, l); |
| 178 | l->append(" bytes)>"); |
| 179 | } |
| 180 | |
[email protected] | 6761d63 | 2012-04-18 17:54:49 | [diff] [blame] | 181 | // HostResource ---------------------------------------------------------------- |
| 182 | |
| 183 | // static |
| 184 | void ParamTraits<ppapi::HostResource>::Write(Message* m, |
| 185 | const param_type& p) { |
| 186 | ParamTraits<PP_Instance>::Write(m, p.instance()); |
| 187 | ParamTraits<PP_Resource>::Write(m, p.host_resource()); |
| 188 | } |
| 189 | |
| 190 | // static |
| 191 | bool ParamTraits<ppapi::HostResource>::Read(const Message* m, |
| 192 | PickleIterator* iter, |
| 193 | param_type* r) { |
| 194 | PP_Instance instance; |
| 195 | PP_Resource resource; |
| 196 | if (!ParamTraits<PP_Instance>::Read(m, iter, &instance) || |
| 197 | !ParamTraits<PP_Resource>::Read(m, iter, &resource)) |
| 198 | return false; |
| 199 | r->SetHostResource(instance, resource); |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | // static |
| 204 | void ParamTraits<ppapi::HostResource>::Log(const param_type& p, |
| 205 | std::string* l) { |
| 206 | } |
| 207 | |
| 208 | // SerializedVar --------------------------------------------------------------- |
| 209 | |
| 210 | // static |
| 211 | void ParamTraits<ppapi::proxy::SerializedVar>::Write(Message* m, |
| 212 | const param_type& p) { |
| 213 | p.WriteToMessage(m); |
| 214 | } |
| 215 | |
| 216 | // static |
| 217 | bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const Message* m, |
| 218 | PickleIterator* iter, |
| 219 | param_type* r) { |
| 220 | return r->ReadFromMessage(m, iter); |
| 221 | } |
| 222 | |
| 223 | // static |
| 224 | void ParamTraits<ppapi::proxy::SerializedVar>::Log(const param_type& p, |
| 225 | std::string* l) { |
| 226 | } |
| 227 | |
| 228 | // std::vector<SerializedVar> -------------------------------------------------- |
| 229 | |
| 230 | void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Write( |
| 231 | Message* m, |
| 232 | const param_type& p) { |
| 233 | WriteVectorWithoutCopy(m, p); |
| 234 | } |
| 235 | |
| 236 | // static |
| 237 | bool ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Read( |
| 238 | const Message* m, |
| 239 | PickleIterator* iter, |
| 240 | param_type* r) { |
| 241 | return ReadVectorWithoutCopy(m, iter, r); |
| 242 | } |
| 243 | |
| 244 | // static |
| 245 | void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log( |
| 246 | const param_type& p, |
| 247 | std::string* l) { |
| 248 | } |
| 249 | |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 250 | // ppapi::PpapiPermissions ----------------------------------------------------- |
| 251 | |
| 252 | void ParamTraits<ppapi::PpapiPermissions>::Write(Message* m, |
| 253 | const param_type& p) { |
| 254 | ParamTraits<uint32_t>::Write(m, p.GetBits()); |
| 255 | } |
| 256 | |
| 257 | // static |
| 258 | bool ParamTraits<ppapi::PpapiPermissions>::Read(const Message* m, |
| 259 | PickleIterator* iter, |
| 260 | param_type* r) { |
| 261 | uint32_t bits; |
| 262 | if (!ParamTraits<uint32_t>::Read(m, iter, &bits)) |
| 263 | return false; |
| 264 | *r = ppapi::PpapiPermissions(bits); |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | // static |
| 269 | void ParamTraits<ppapi::PpapiPermissions>::Log(const param_type& p, |
| 270 | std::string* l) { |
| 271 | } |
| 272 | |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 273 | // SerializedHandle ------------------------------------------------------------ |
| 274 | |
| 275 | // static |
| 276 | void ParamTraits<ppapi::proxy::SerializedHandle>::Write(Message* m, |
| 277 | const param_type& p) { |
| 278 | ppapi::proxy::SerializedHandle::WriteHeader(p.header(), m); |
| 279 | switch (p.type()) { |
| 280 | case ppapi::proxy::SerializedHandle::SHARED_MEMORY: |
| 281 | ParamTraits<base::SharedMemoryHandle>::Write(m, p.shmem()); |
| 282 | break; |
| 283 | case ppapi::proxy::SerializedHandle::SOCKET: |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 284 | case ppapi::proxy::SerializedHandle::FILE: |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 285 | ParamTraits<IPC::PlatformFileForTransit>::Write(m, p.descriptor()); |
| 286 | break; |
| 287 | case ppapi::proxy::SerializedHandle::INVALID: |
| 288 | break; |
| 289 | // No default so the compiler will warn on new types. |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // static |
| 294 | bool ParamTraits<ppapi::proxy::SerializedHandle>::Read(const Message* m, |
| 295 | PickleIterator* iter, |
| 296 | param_type* r) { |
| 297 | ppapi::proxy::SerializedHandle::Header header; |
| 298 | if (!ppapi::proxy::SerializedHandle::ReadHeader(iter, &header)) |
| 299 | return false; |
| 300 | switch (header.type) { |
| 301 | case ppapi::proxy::SerializedHandle::SHARED_MEMORY: { |
| 302 | base::SharedMemoryHandle handle; |
| 303 | if (ParamTraits<base::SharedMemoryHandle>::Read(m, iter, &handle)) { |
| 304 | r->set_shmem(handle, header.size); |
| 305 | return true; |
| 306 | } |
| 307 | break; |
| 308 | } |
| 309 | case ppapi::proxy::SerializedHandle::SOCKET: { |
| 310 | IPC::PlatformFileForTransit socket; |
| 311 | if (ParamTraits<IPC::PlatformFileForTransit>::Read(m, iter, &socket)) { |
| 312 | r->set_socket(socket); |
| 313 | return true; |
| 314 | } |
| 315 | break; |
| 316 | } |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 317 | case ppapi::proxy::SerializedHandle::FILE: { |
| 318 | IPC::PlatformFileForTransit desc; |
| 319 | if (ParamTraits<IPC::PlatformFileForTransit>::Read(m, iter, &desc)) { |
[email protected] | 80f8f84 | 2013-12-18 22:47:57 | [diff] [blame] | 320 | r->set_file_handle(desc, header.open_flags, header.file_io); |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 321 | return true; |
| 322 | } |
| 323 | break; |
| 324 | } |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 325 | case ppapi::proxy::SerializedHandle::INVALID: |
| 326 | return true; |
| 327 | // No default so the compiler will warn us if a new type is added. |
| 328 | } |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | // static |
| 333 | void ParamTraits<ppapi::proxy::SerializedHandle>::Log(const param_type& p, |
| 334 | std::string* l) { |
| 335 | } |
| 336 | |
[email protected] | 5a5d9b532 | 2012-10-02 22:20:23 | [diff] [blame] | 337 | // PPBURLLoader_UpdateProgress_Params ------------------------------------------ |
| 338 | |
| 339 | // static |
| 340 | void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Write( |
| 341 | Message* m, |
| 342 | const param_type& p) { |
| 343 | ParamTraits<PP_Instance>::Write(m, p.instance); |
| 344 | ParamTraits<ppapi::HostResource>::Write(m, p.resource); |
| 345 | ParamTraits<int64_t>::Write(m, p.bytes_sent); |
| 346 | ParamTraits<int64_t>::Write(m, p.total_bytes_to_be_sent); |
| 347 | ParamTraits<int64_t>::Write(m, p.bytes_received); |
| 348 | ParamTraits<int64_t>::Write(m, p.total_bytes_to_be_received); |
| 349 | } |
| 350 | |
| 351 | // static |
| 352 | bool ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Read( |
| 353 | const Message* m, |
| 354 | PickleIterator* iter, |
| 355 | param_type* r) { |
| 356 | return |
| 357 | ParamTraits<PP_Instance>::Read(m, iter, &r->instance) && |
| 358 | ParamTraits<ppapi::HostResource>::Read(m, iter, &r->resource) && |
| 359 | ParamTraits<int64_t>::Read(m, iter, &r->bytes_sent) && |
| 360 | ParamTraits<int64_t>::Read(m, iter, &r->total_bytes_to_be_sent) && |
| 361 | ParamTraits<int64_t>::Read(m, iter, &r->bytes_received) && |
| 362 | ParamTraits<int64_t>::Read(m, iter, &r->total_bytes_to_be_received); |
| 363 | } |
| 364 | |
| 365 | // static |
| 366 | void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Log( |
| 367 | const param_type& p, |
| 368 | std::string* l) { |
| 369 | } |
| 370 | |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 371 | #if !defined(OS_NACL) && !defined(NACL_WIN64) |
[email protected] | 6761d63 | 2012-04-18 17:54:49 | [diff] [blame] | 372 | // PPBFlash_DrawGlyphs_Params -------------------------------------------------- |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 373 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 374 | void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Write( |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 375 | Message* m, |
| 376 | const param_type& p) { |
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 377 | ParamTraits<PP_Instance>::Write(m, p.instance); |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 378 | ParamTraits<ppapi::HostResource>::Write(m, p.image_data); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 379 | ParamTraits<ppapi::proxy::SerializedFontDescription>::Write(m, p.font_desc); |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 380 | ParamTraits<uint32_t>::Write(m, p.color); |
| 381 | ParamTraits<PP_Point>::Write(m, p.position); |
| 382 | ParamTraits<PP_Rect>::Write(m, p.clip); |
| 383 | ParamTraits<float>::Write(m, p.transformation[0][0]); |
| 384 | ParamTraits<float>::Write(m, p.transformation[0][1]); |
| 385 | ParamTraits<float>::Write(m, p.transformation[0][2]); |
| 386 | ParamTraits<float>::Write(m, p.transformation[1][0]); |
| 387 | ParamTraits<float>::Write(m, p.transformation[1][1]); |
| 388 | ParamTraits<float>::Write(m, p.transformation[1][2]); |
| 389 | ParamTraits<float>::Write(m, p.transformation[2][0]); |
| 390 | ParamTraits<float>::Write(m, p.transformation[2][1]); |
| 391 | ParamTraits<float>::Write(m, p.transformation[2][2]); |
[email protected] | 2e4361ae | 2011-12-15 00:03:35 | [diff] [blame] | 392 | ParamTraits<PP_Bool>::Write(m, p.allow_subpixel_aa); |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 393 | ParamTraits<std::vector<uint16_t> >::Write(m, p.glyph_indices); |
| 394 | ParamTraits<std::vector<PP_Point> >::Write(m, p.glyph_advances); |
| 395 | } |
| 396 | |
| 397 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 398 | bool ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Read( |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 399 | const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 400 | PickleIterator* iter, |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 401 | param_type* r) { |
| 402 | return |
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 403 | ParamTraits<PP_Instance>::Read(m, iter, &r->instance) && |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 404 | ParamTraits<ppapi::HostResource>::Read(m, iter, &r->image_data) && |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 405 | ParamTraits<ppapi::proxy::SerializedFontDescription>::Read(m, iter, |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 406 | &r->font_desc) && |
| 407 | ParamTraits<uint32_t>::Read(m, iter, &r->color) && |
| 408 | ParamTraits<PP_Point>::Read(m, iter, &r->position) && |
| 409 | ParamTraits<PP_Rect>::Read(m, iter, &r->clip) && |
| 410 | ParamTraits<float>::Read(m, iter, &r->transformation[0][0]) && |
| 411 | ParamTraits<float>::Read(m, iter, &r->transformation[0][1]) && |
| 412 | ParamTraits<float>::Read(m, iter, &r->transformation[0][2]) && |
| 413 | ParamTraits<float>::Read(m, iter, &r->transformation[1][0]) && |
| 414 | ParamTraits<float>::Read(m, iter, &r->transformation[1][1]) && |
| 415 | ParamTraits<float>::Read(m, iter, &r->transformation[1][2]) && |
| 416 | ParamTraits<float>::Read(m, iter, &r->transformation[2][0]) && |
| 417 | ParamTraits<float>::Read(m, iter, &r->transformation[2][1]) && |
| 418 | ParamTraits<float>::Read(m, iter, &r->transformation[2][2]) && |
[email protected] | 2e4361ae | 2011-12-15 00:03:35 | [diff] [blame] | 419 | ParamTraits<PP_Bool>::Read(m, iter, &r->allow_subpixel_aa) && |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 420 | ParamTraits<std::vector<uint16_t> >::Read(m, iter, &r->glyph_indices) && |
| 421 | ParamTraits<std::vector<PP_Point> >::Read(m, iter, &r->glyph_advances) && |
| 422 | r->glyph_indices.size() == r->glyph_advances.size(); |
| 423 | } |
| 424 | |
| 425 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 426 | void ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Log( |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 427 | const param_type& p, |
| 428 | std::string* l) { |
| 429 | } |
| 430 | |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 431 | // SerializedDirEntry ---------------------------------------------------------- |
| 432 | |
| 433 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 434 | void ParamTraits<ppapi::proxy::SerializedDirEntry>::Write(Message* m, |
| 435 | const param_type& p) { |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 436 | ParamTraits<std::string>::Write(m, p.name); |
| 437 | ParamTraits<bool>::Write(m, p.is_dir); |
| 438 | } |
| 439 | |
| 440 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 441 | bool ParamTraits<ppapi::proxy::SerializedDirEntry>::Read(const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 442 | PickleIterator* iter, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 443 | param_type* r) { |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 444 | return ParamTraits<std::string>::Read(m, iter, &r->name) && |
| 445 | ParamTraits<bool>::Read(m, iter, &r->is_dir); |
| 446 | } |
| 447 | |
| 448 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 449 | void ParamTraits<ppapi::proxy::SerializedDirEntry>::Log(const param_type& p, |
| 450 | std::string* l) { |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 453 | // ppapi::proxy::SerializedFontDescription ------------------------------------- |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 454 | |
| 455 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 456 | void ParamTraits<ppapi::proxy::SerializedFontDescription>::Write( |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 457 | Message* m, |
| 458 | const param_type& p) { |
[email protected] | cb65f13 | 2012-10-09 17:06:09 | [diff] [blame] | 459 | ParamTraits<std::string>::Write(m, p.face); |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 460 | ParamTraits<int32_t>::Write(m, p.family); |
| 461 | ParamTraits<uint32_t>::Write(m, p.size); |
| 462 | ParamTraits<int32_t>::Write(m, p.weight); |
| 463 | ParamTraits<PP_Bool>::Write(m, p.italic); |
| 464 | ParamTraits<PP_Bool>::Write(m, p.small_caps); |
| 465 | ParamTraits<int32_t>::Write(m, p.letter_spacing); |
| 466 | ParamTraits<int32_t>::Write(m, p.word_spacing); |
| 467 | } |
| 468 | |
| 469 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 470 | bool ParamTraits<ppapi::proxy::SerializedFontDescription>::Read( |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 471 | const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 472 | PickleIterator* iter, |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 473 | param_type* r) { |
| 474 | return |
[email protected] | cb65f13 | 2012-10-09 17:06:09 | [diff] [blame] | 475 | ParamTraits<std::string>::Read(m, iter, &r->face) && |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 476 | ParamTraits<int32_t>::Read(m, iter, &r->family) && |
| 477 | ParamTraits<uint32_t>::Read(m, iter, &r->size) && |
| 478 | ParamTraits<int32_t>::Read(m, iter, &r->weight) && |
| 479 | ParamTraits<PP_Bool>::Read(m, iter, &r->italic) && |
| 480 | ParamTraits<PP_Bool>::Read(m, iter, &r->small_caps) && |
| 481 | ParamTraits<int32_t>::Read(m, iter, &r->letter_spacing) && |
| 482 | ParamTraits<int32_t>::Read(m, iter, &r->word_spacing); |
| 483 | } |
| 484 | |
| 485 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 486 | void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log( |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 487 | const param_type& p, |
| 488 | std::string* l) { |
| 489 | } |
[email protected] | 725056b7 | 2013-03-16 09:57:51 | [diff] [blame] | 490 | #endif // !defined(OS_NACL) && !defined(NACL_WIN64) |
[email protected] | 799d1ab | 2010-11-09 17:16:28 | [diff] [blame] | 491 | |
[email protected] | 725056b7 | 2013-03-16 09:57:51 | [diff] [blame] | 492 | // ppapi::proxy::SerializedTrueTypeFontDesc ------------------------------------ |
| 493 | |
| 494 | // static |
| 495 | void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Write( |
| 496 | Message* m, |
| 497 | const param_type& p) { |
| 498 | ParamTraits<std::string>::Write(m, p.family); |
| 499 | ParamTraits<PP_TrueTypeFontFamily_Dev>::Write(m, p.generic_family); |
| 500 | ParamTraits<PP_TrueTypeFontStyle_Dev>::Write(m, p.style); |
| 501 | ParamTraits<PP_TrueTypeFontWeight_Dev>::Write(m, p.weight); |
| 502 | ParamTraits<PP_TrueTypeFontWidth_Dev>::Write(m, p.width); |
| 503 | ParamTraits<PP_TrueTypeFontCharset_Dev>::Write(m, p.charset); |
| 504 | } |
| 505 | |
| 506 | // static |
| 507 | bool ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Read( |
| 508 | const Message* m, |
| 509 | PickleIterator* iter, |
| 510 | param_type* r) { |
| 511 | return |
| 512 | ParamTraits<std::string>::Read(m, iter, &r->family) && |
| 513 | ParamTraits<PP_TrueTypeFontFamily_Dev>::Read(m, iter, |
| 514 | &r->generic_family) && |
| 515 | ParamTraits<PP_TrueTypeFontStyle_Dev>::Read(m, iter, &r->style) && |
| 516 | ParamTraits<PP_TrueTypeFontWeight_Dev>::Read(m, iter, &r->weight) && |
| 517 | ParamTraits<PP_TrueTypeFontWidth_Dev>::Read(m, iter, &r->width) && |
| 518 | ParamTraits<PP_TrueTypeFontCharset_Dev>::Read(m, iter, &r->charset); |
| 519 | } |
| 520 | |
| 521 | // static |
| 522 | void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Log( |
| 523 | const param_type& p, |
| 524 | std::string* l) { |
| 525 | } |
| 526 | |
| 527 | #if !defined(OS_NACL) && !defined(NACL_WIN64) |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 528 | // ppapi::PepperFilePath ------------------------------------------------------- |
| 529 | |
| 530 | // static |
| 531 | void ParamTraits<ppapi::PepperFilePath>::Write(Message* m, |
| 532 | const param_type& p) { |
| 533 | WriteParam(m, static_cast<unsigned>(p.domain())); |
| 534 | WriteParam(m, p.path()); |
| 535 | } |
| 536 | |
| 537 | // static |
| 538 | bool ParamTraits<ppapi::PepperFilePath>::Read(const Message* m, |
| 539 | PickleIterator* iter, |
| 540 | param_type* p) { |
| 541 | unsigned domain; |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 542 | base::FilePath path; |
[email protected] | 0c92b0d | 2012-12-08 00:46:23 | [diff] [blame] | 543 | if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path)) |
| 544 | return false; |
| 545 | if (domain > ppapi::PepperFilePath::DOMAIN_MAX_VALID) |
| 546 | return false; |
| 547 | |
| 548 | *p = ppapi::PepperFilePath( |
| 549 | static_cast<ppapi::PepperFilePath::Domain>(domain), path); |
| 550 | return true; |
| 551 | } |
| 552 | |
| 553 | // static |
| 554 | void ParamTraits<ppapi::PepperFilePath>::Log(const param_type& p, |
| 555 | std::string* l) { |
| 556 | l->append("("); |
| 557 | LogParam(static_cast<unsigned>(p.domain()), l); |
| 558 | l->append(", "); |
| 559 | LogParam(p.path(), l); |
| 560 | l->append(")"); |
| 561 | } |
| 562 | |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 563 | // SerializedFlashMenu --------------------------------------------------------- |
| 564 | |
| 565 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 566 | void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Write( |
| 567 | Message* m, |
| 568 | const param_type& p) { |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 569 | p.WriteToMessage(m); |
| 570 | } |
| 571 | |
| 572 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 573 | bool ParamTraits<ppapi::proxy::SerializedFlashMenu>::Read(const Message* m, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 574 | PickleIterator* iter, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 575 | param_type* r) { |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 576 | return r->ReadFromMessage(m, iter); |
| 577 | } |
| 578 | |
| 579 | // static |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 580 | void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Log(const param_type& p, |
| 581 | std::string* l) { |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 582 | } |
[email protected] | 667591d | 2012-09-04 21:30:12 | [diff] [blame] | 583 | #endif // !defined(OS_NACL) && !defined(NACL_WIN64) |
[email protected] | 7358d57 | 2011-02-15 18:44:40 | [diff] [blame] | 584 | |
[email protected] | de289526 | 2012-04-04 17:15:48 | [diff] [blame] | 585 | // PPB_X509Certificate_Fields -------------------------------------------------- |
| 586 | |
| 587 | // static |
| 588 | void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Write( |
| 589 | Message* m, |
| 590 | const param_type& p) { |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 591 | ParamTraits<base::ListValue>::Write(m, p.values_); |
[email protected] | de289526 | 2012-04-04 17:15:48 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | // static |
| 595 | bool ParamTraits<ppapi::PPB_X509Certificate_Fields>::Read(const Message* m, |
| 596 | PickleIterator* iter, |
| 597 | param_type* r) { |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 598 | return ParamTraits<base::ListValue>::Read(m, iter, &(r->values_)); |
[email protected] | de289526 | 2012-04-04 17:15:48 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | // static |
| 602 | void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Log(const param_type& p, |
| 603 | std::string* l) { |
| 604 | } |
| 605 | |
[email protected] | 64a61fc | 2013-06-19 13:30:59 | [diff] [blame] | 606 | // ppapi::SocketOptionData ----------------------------------------------------- |
| 607 | |
| 608 | // static |
| 609 | void ParamTraits<ppapi::SocketOptionData>::Write(Message* m, |
| 610 | const param_type& p) { |
| 611 | ppapi::SocketOptionData::Type type = p.GetType(); |
| 612 | ParamTraits<int32_t>::Write(m, static_cast<int32_t>(type)); |
| 613 | switch (type) { |
| 614 | case ppapi::SocketOptionData::TYPE_INVALID: { |
| 615 | break; |
| 616 | } |
| 617 | case ppapi::SocketOptionData::TYPE_BOOL: { |
| 618 | bool out_value = false; |
| 619 | bool result = p.GetBool(&out_value); |
| 620 | // Suppress unused variable warnings. |
| 621 | static_cast<void>(result); |
| 622 | DCHECK(result); |
| 623 | |
| 624 | ParamTraits<bool>::Write(m, out_value); |
| 625 | break; |
| 626 | } |
| 627 | case ppapi::SocketOptionData::TYPE_INT32: { |
| 628 | int32_t out_value = 0; |
| 629 | bool result = p.GetInt32(&out_value); |
| 630 | // Suppress unused variable warnings. |
| 631 | static_cast<void>(result); |
| 632 | DCHECK(result); |
| 633 | |
| 634 | ParamTraits<int32_t>::Write(m, out_value); |
| 635 | break; |
| 636 | } |
| 637 | // No default so the compiler will warn on new types. |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // static |
| 642 | bool ParamTraits<ppapi::SocketOptionData>::Read(const Message* m, |
| 643 | PickleIterator* iter, |
| 644 | param_type* r) { |
| 645 | *r = ppapi::SocketOptionData(); |
| 646 | int32_t type = 0; |
| 647 | if (!ParamTraits<int32_t>::Read(m, iter, &type)) |
| 648 | return false; |
| 649 | if (type != ppapi::SocketOptionData::TYPE_INVALID && |
| 650 | type != ppapi::SocketOptionData::TYPE_BOOL && |
| 651 | type != ppapi::SocketOptionData::TYPE_INT32) { |
| 652 | return false; |
| 653 | } |
| 654 | switch (static_cast<ppapi::SocketOptionData::Type>(type)) { |
| 655 | case ppapi::SocketOptionData::TYPE_INVALID: { |
| 656 | return true; |
| 657 | } |
| 658 | case ppapi::SocketOptionData::TYPE_BOOL: { |
| 659 | bool value = false; |
| 660 | if (!ParamTraits<bool>::Read(m, iter, &value)) |
| 661 | return false; |
| 662 | r->SetBool(value); |
| 663 | return true; |
| 664 | } |
| 665 | case ppapi::SocketOptionData::TYPE_INT32: { |
| 666 | int32_t value = 0; |
| 667 | if (!ParamTraits<int32_t>::Read(m, iter, &value)) |
| 668 | return false; |
| 669 | r->SetInt32(value); |
| 670 | return true; |
| 671 | } |
| 672 | // No default so the compiler will warn on new types. |
| 673 | } |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | // static |
| 678 | void ParamTraits<ppapi::SocketOptionData>::Log(const param_type& p, |
| 679 | std::string* l) { |
| 680 | } |
| 681 | |
[email protected] | c44620b | 2014-06-16 14:20:26 | [diff] [blame] | 682 | // ppapi::CompositorLayerData -------------------------------------------------- |
| 683 | |
| 684 | // static |
| 685 | void ParamTraits<ppapi::CompositorLayerData::Transform>::Write( |
| 686 | Message* m, |
| 687 | const param_type& p) { |
| 688 | for (size_t i = 0; i < arraysize(p.matrix); i++) |
| 689 | ParamTraits<float>::Write(m, p.matrix[i]); |
| 690 | } |
| 691 | |
| 692 | // static |
| 693 | bool ParamTraits<ppapi::CompositorLayerData::Transform>::Read( |
| 694 | const Message* m, |
| 695 | PickleIterator* iter, |
| 696 | param_type* r) { |
| 697 | for (size_t i = 0; i < arraysize(r->matrix);i++) { |
| 698 | if (!ParamTraits<float>::Read(m, iter, &r->matrix[i])) |
| 699 | return false; |
| 700 | } |
| 701 | return true; |
| 702 | } |
| 703 | |
| 704 | void ParamTraits<ppapi::CompositorLayerData::Transform>::Log( |
| 705 | const param_type& p, |
| 706 | std::string* l) { |
| 707 | } |
| 708 | |
[email protected] | c2932f5e | 2010-11-03 03:22:33 | [diff] [blame] | 709 | } // namespace IPC |