Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: ppapi/proxy/ppapi_param_traits.cc

Issue 9455092: HostResolver is exposed to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/class HostPortPair/struct HostPortPair. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppapi_param_traits.h" 5 #include "ppapi/proxy/ppapi_param_traits.h"
6 6
7 #include <string.h> // For memcpy 7 #include <string.h> // For memcpy
8 8
9 #include <limits>
10
9 #include "ppapi/c/pp_file_info.h" 11 #include "ppapi/c/pp_file_info.h"
10 #include "ppapi/c/pp_resource.h" 12 #include "ppapi/c/pp_resource.h"
11 #include "ppapi/c/private/ppb_flash_tcp_socket.h" 13 #include "ppapi/c/private/ppb_flash_tcp_socket.h"
12 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/serialized_flash_menu.h"
13 #include "ppapi/proxy/serialized_var.h" 16 #include "ppapi/proxy/serialized_var.h"
14 #include "ppapi/proxy/serialized_flash_menu.h"
15 #include "ppapi/shared_impl/host_resource.h" 17 #include "ppapi/shared_impl/host_resource.h"
16 18
17 namespace IPC { 19 namespace IPC {
18 20
19 namespace { 21 namespace {
20 22
21 // Deserializes a vector from IPC. This special version must be used instead 23 // Deserializes a vector from IPC. This special version must be used instead
22 // of the default IPC version when the vector contains a SerializedVar, either 24 // of the default IPC version when the vector contains a SerializedVar, either
23 // directly or indirectly (i.e. a vector of objects that have a SerializedVar 25 // directly or indirectly (i.e. a vector of objects that have a SerializedVar
24 // inside them). 26 // inside them).
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) 132 system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY)
131 return false; 133 return false;
132 r->system_type = static_cast<PP_FileSystemType>(system_type); 134 r->system_type = static_cast<PP_FileSystemType>(system_type);
133 return true; 135 return true;
134 } 136 }
135 137
136 // static 138 // static
137 void ParamTraits<PP_FileInfo>::Log(const param_type& p, std::string* l) { 139 void ParamTraits<PP_FileInfo>::Log(const param_type& p, std::string* l) {
138 } 140 }
139 141
142 // PP_HostResolver_Private_Hint ------------------------------------------------
143 // static
144 void ParamTraits<PP_HostResolver_Private_Hint>::Write(Message* m,
145 const param_type& p) {
146 ParamTraits<int>::Write(m, static_cast<int>(p.family));
147 ParamTraits<int>::Write(m, static_cast<int>(p.flags));
148 }
149
150 // static
151 bool ParamTraits<PP_HostResolver_Private_Hint>::Read(const Message* m,
152 void** iter,
153 param_type* r) {
154 int family, flags;
155 if (!ParamTraits<int>::Read(m, iter, &family) ||
156 !ParamTraits<int>::Read(m, iter, &flags)) {
157 return false;
158 }
159
160 if (family != PP_NETADDRESSFAMILY_UNSPECIFIED &&
161 family != PP_NETADDRESSFAMILY_IPV4 &&
162 family != PP_NETADDRESSFAMILY_IPV6) {
163 return false;
164 }
165 r->family = static_cast<PP_NetAddressFamily_Private>(family);
166 r->flags = static_cast<PP_HostResolver_Private_Flags>(flags);
167 return true;
168 }
169
170 // static
171 void ParamTraits<PP_HostResolver_Private_Hint>::Log(const param_type& p,
172 std::string* l) {
173 }
174
140 // PP_NetAddress_Private ------------------------------------------------------- 175 // PP_NetAddress_Private -------------------------------------------------------
141 176
142 // static 177 // static
143 void ParamTraits<PP_NetAddress_Private>::Write(Message* m, 178 void ParamTraits<PP_NetAddress_Private>::Write(Message* m,
144 const param_type& p) { 179 const param_type& p) {
145 WriteParam(m, p.size); 180 WriteParam(m, p.size);
146 m->WriteBytes(p.data, static_cast<int>(p.size)); 181 m->WriteBytes(p.data, static_cast<int>(p.size));
147 } 182 }
148 183
149 // static 184 // static
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ParamTraits<int32_t>::Read(m, iter, &r->letter_spacing) && 400 ParamTraits<int32_t>::Read(m, iter, &r->letter_spacing) &&
366 ParamTraits<int32_t>::Read(m, iter, &r->word_spacing); 401 ParamTraits<int32_t>::Read(m, iter, &r->word_spacing);
367 } 402 }
368 403
369 // static 404 // static
370 void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log( 405 void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log(
371 const param_type& p, 406 const param_type& p,
372 std::string* l) { 407 std::string* l) {
373 } 408 }
374 409
410 // HostPortPair ----------------------------------------------------------------
411
412 // static
413 void ParamTraits<ppapi::HostPortPair>::Write(Message* m,
414 const param_type& p) {
415 ParamTraits<std::string>::Write(m, p.host);
416 ParamTraits<uint32_t>::Write(m, p.port);
417 }
418
419 // static
420 bool ParamTraits<ppapi::HostPortPair>::Read(const Message* m,
421 void** iter,
422 param_type* r) {
423 if (!ParamTraits<std::string>::Read(m, iter, &r->host))
424 return false;
425 uint32_t port;
426 if (!ParamTraits<uint32_t>::Read(m, iter, &port) ||
427 port > std::numeric_limits<uint16_t>::max()) {
428 return false;
429 }
430 r->port = port;
431 return true;
432 }
433
434 // static
435 void ParamTraits<ppapi::HostPortPair>::Log(const param_type& p,
436 std::string* l) {
437 }
438
375 // HostResource ---------------------------------------------------------------- 439 // HostResource ----------------------------------------------------------------
376 440
377 // static 441 // static
378 void ParamTraits<ppapi::HostResource>::Write(Message* m, 442 void ParamTraits<ppapi::HostResource>::Write(Message* m,
379 const param_type& p) { 443 const param_type& p) {
380 ParamTraits<PP_Instance>::Write(m, p.instance()); 444 ParamTraits<PP_Instance>::Write(m, p.instance());
381 ParamTraits<PP_Resource>::Write(m, p.host_resource()); 445 ParamTraits<PP_Resource>::Write(m, p.host_resource());
382 } 446 }
383 447
384 // static 448 // static
385 bool ParamTraits<ppapi::HostResource>::Read(const Message* m, 449 bool ParamTraits<ppapi::HostResource>::Read(const Message* m,
386 void** iter, 450 void** iter,
387 param_type* r) { 451 param_type* r) {
388 PP_Instance instance; 452 PP_Instance instance;
389 PP_Resource resource; 453 PP_Resource resource;
390 if (!ParamTraits<PP_Instance>::Read(m, iter, &instance) || 454 if (!ParamTraits<PP_Instance>::Read(m, iter, &instance) ||
391 !ParamTraits<PP_Resource>::Read(m, iter, &resource)) 455 !ParamTraits<PP_Resource>::Read(m, iter, &resource))
392 return false; 456 return false;
393 r->SetHostResource(instance, resource); 457 r->SetHostResource(instance, resource);
394 return true; 458 return true;
395 } 459 }
396 460
397 // static 461 // static
398 void ParamTraits<ppapi::HostResource>::Log(const param_type& p, 462 void ParamTraits<ppapi::HostResource>::Log(const param_type& p,
399 std::string* l) { 463 std::string* l) {
400 } 464 }
401 465
466 // NameAndAddressPair ----------------------------------------------------------
yzshen1 2012/02/29 19:11:49 Is it possible to use IPC_STRUCT_TRAITS_*? And I t
ygorshenin1 2012/03/01 09:37:34 Thanks! This is greatly simplified the code. On 2
467
468 // static
469 void ParamTraits<ppapi::NameAndAddressPair>::Write(Message* m,
470 const param_type& p) {
471 ParamTraits<std::string>::Write(m, p.canonical_name);
472 ParamTraits<PP_NetAddress_Private>::Write(m, p.address);
473 }
474
475 // static
476 bool ParamTraits<ppapi::NameAndAddressPair>::Read(const Message* m,
477 void** iter,
478 param_type* r) {
479 if (!ParamTraits<std::string>::Read(m, iter, &r->canonical_name) ||
480 !ParamTraits<PP_NetAddress_Private>::Read(m, iter, &r->address)) {
481 return false;
482 }
483 return true;
484 }
485
486 // static
487 void ParamTraits<ppapi::NameAndAddressPair>::Log(const param_type& p,
488 std::string* l) {
489 }
490
491 // NetworkList -----------------------------------------------------------------
492
493 // static
494 void ParamTraits<ppapi::NetworkList>::Write(Message* m, const param_type& p) {
495 ParamTraits<int>::Write(m, static_cast<int>(p.size()));
496 for (ppapi::NetworkList::const_iterator it = p.begin(); it != p.end(); ++it)
497 ParamTraits<ppapi::NameAndAddressPair>::Write(m, *it);
498 }
499
500 // static
501 bool ParamTraits<ppapi::NetworkList>::Read(const Message* m,
502 void** iter,
503 param_type* r) {
504 int size;
505 if (!ParamTraits<int>::Read(m, iter, &size))
506 return false;
507
508 r->resize(size);
509 for (int i = 0; i < size; ++i) {
510 if (!ParamTraits<ppapi::NameAndAddressPair>::Read(m, iter, &(*r)[i]))
511 return false;
512 }
513
514 return true;
515 }
516
517 // static
518 void ParamTraits<ppapi::NetworkList>::Log(const param_type& p, std::string* l) {
519 }
520
402 // SerializedVar --------------------------------------------------------------- 521 // SerializedVar ---------------------------------------------------------------
403 522
404 // static 523 // static
405 void ParamTraits<ppapi::proxy::SerializedVar>::Write(Message* m, 524 void ParamTraits<ppapi::proxy::SerializedVar>::Write(Message* m,
406 const param_type& p) { 525 const param_type& p) {
407 p.WriteToMessage(m); 526 p.WriteToMessage(m);
408 } 527 }
409 528
410 // static 529 // static
411 bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const Message* m, 530 bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const Message* m,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 param_type* r) { 597 param_type* r) {
479 return r->ReadFromMessage(m, iter); 598 return r->ReadFromMessage(m, iter);
480 } 599 }
481 600
482 // static 601 // static
483 void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Log(const param_type& p, 602 void ParamTraits<ppapi::proxy::SerializedFlashMenu>::Log(const param_type& p,
484 std::string* l) { 603 std::string* l) {
485 } 604 }
486 605
487 } // namespace IPC 606 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698