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

Side by Side Diff: ppapi/shared_impl/private/net_address_private_impl.cc

Issue 10993078: Use extensions socket permission for TCP/UDP socket APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed Android build Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/private/net_address_private_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/private/net_address_private_impl.h" 5 #include "ppapi/shared_impl/private/net_address_private_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <winsock2.h> 9 #include <winsock2.h>
10 #include <ws2tcpip.h> 10 #include <ws2tcpip.h>
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 if (include_port) 275 if (include_port)
276 base::StringAppendF(&description, "]:%u", net_addr->port); 276 base::StringAppendF(&description, "]:%u", net_addr->port);
277 277
278 return description; 278 return description;
279 } 279 }
280 280
281 PP_Var Describe(PP_Module /*module*/, 281 PP_Var Describe(PP_Module /*module*/,
282 const struct PP_NetAddress_Private* addr, 282 const struct PP_NetAddress_Private* addr,
283 PP_Bool include_port) { 283 PP_Bool include_port) {
284 const NetAddress* net_addr = ToNetAddress(addr); 284 std::string str = NetAddressPrivateImpl::DescribeNetAddress(
285 if (!IsValid(net_addr)) 285 *addr, PP_ToBool(include_port));
286 if (str.empty())
286 return PP_MakeUndefined(); 287 return PP_MakeUndefined();
287 288 return StringVar::StringToPPVar(str);
288 std::string description;
289 if (net_addr->is_ipv6) {
290 description = ConvertIPv6AddressToString(net_addr,
291 PP_ToBool(include_port));
292 } else {
293 description = ConvertIPv4AddressToString(net_addr,
294 PP_ToBool(include_port));
295 }
296 return StringVar::StringToPPVar(description);
297 } 289 }
298 290
299 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, 291 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr,
300 uint16_t port, 292 uint16_t port,
301 struct PP_NetAddress_Private* dest_addr) { 293 struct PP_NetAddress_Private* dest_addr) {
302 const NetAddress* src_net_addr = ToNetAddress(src_addr); 294 const NetAddress* src_net_addr = ToNetAddress(src_addr);
303 if (!IsValid(src_net_addr) || !dest_addr) 295 if (!IsValid(src_net_addr) || !dest_addr)
304 return PP_FALSE; 296 return PP_FALSE;
305 dest_addr->size = sizeof(NetAddress); // make sure 'size' is valid. 297 dest_addr->size = sizeof(NetAddress); // make sure 'size' is valid.
306 NetAddress* dest_net_addr = ToNetAddress(dest_addr); 298 NetAddress* dest_net_addr = ToNetAddress(dest_addr);
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 return false; 483 return false;
492 484
493 *port = net_addr->port; 485 *port = net_addr->port;
494 size_t address_size = GetAddressSize(net_addr); 486 size_t address_size = GetAddressSize(net_addr);
495 address->assign(&net_addr->address[0], &net_addr->address[address_size]); 487 address->assign(&net_addr->address[0], &net_addr->address[address_size]);
496 488
497 return true; 489 return true;
498 } 490 }
499 #endif // !defined(OS_NACL) 491 #endif // !defined(OS_NACL)
500 492
493 // static
494 std::string NetAddressPrivateImpl::DescribeNetAddress(
495 const PP_NetAddress_Private& addr,
496 bool include_port) {
497 const NetAddress* net_addr = ToNetAddress(&addr);
498 if (!IsValid(net_addr))
499 return std::string();
500
501 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac,
502 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6:
503 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't
504 // display the scope).
505 if (net_addr->is_ipv6)
506 return ConvertIPv6AddressToString(net_addr, include_port);
507 return ConvertIPv4AddressToString(net_addr, include_port);
508 }
509
501 } // namespace ppapi 510 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/private/net_address_private_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698