• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
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/net_address_resource.h"
6 
7 #include <string>
8 
9 #include "ppapi/c/pp_bool.h"
10 #include "ppapi/shared_impl/private/net_address_private_impl.h"
11 #include "ppapi/shared_impl/var.h"
12 
13 namespace ppapi {
14 namespace proxy {
15 
NetAddressResource(Connection connection,PP_Instance instance,const PP_NetAddress_IPv4 & ipv4_addr)16 NetAddressResource::NetAddressResource(
17     Connection connection,
18     PP_Instance instance,
19     const PP_NetAddress_IPv4& ipv4_addr)
20     : PluginResource(connection, instance) {
21   NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv4Address(ipv4_addr,
22                                                                 &address_);
23 }
24 
NetAddressResource(Connection connection,PP_Instance instance,const PP_NetAddress_IPv6 & ipv6_addr)25 NetAddressResource::NetAddressResource(
26     Connection connection,
27     PP_Instance instance,
28     const PP_NetAddress_IPv6& ipv6_addr)
29     : PluginResource(connection, instance) {
30   NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv6Address(ipv6_addr,
31                                                                 &address_);
32 }
33 
NetAddressResource(Connection connection,PP_Instance instance,const PP_NetAddress_Private & private_addr)34 NetAddressResource::NetAddressResource(
35     Connection connection,
36     PP_Instance instance,
37     const PP_NetAddress_Private& private_addr)
38     : PluginResource(connection, instance) {
39   address_ = private_addr;
40 }
41 
~NetAddressResource()42 NetAddressResource::~NetAddressResource() {
43 }
44 
AsPPB_NetAddress_API()45 thunk::PPB_NetAddress_API* NetAddressResource::AsPPB_NetAddress_API() {
46   return this;
47 }
48 
GetFamily()49 PP_NetAddress_Family NetAddressResource::GetFamily() {
50   return NetAddressPrivateImpl::GetFamilyFromNetAddressPrivate(address_);
51 }
52 
DescribeAsString(PP_Bool include_port)53 PP_Var NetAddressResource::DescribeAsString(PP_Bool include_port) {
54   std::string description = NetAddressPrivateImpl::DescribeNetAddress(
55       address_, PP_ToBool(include_port));
56 
57   if (description.empty())
58     return PP_MakeUndefined();
59   return StringVar::StringToPPVar(description);
60 }
61 
DescribeAsIPv4Address(PP_NetAddress_IPv4 * ipv4_addr)62 PP_Bool NetAddressResource::DescribeAsIPv4Address(
63     PP_NetAddress_IPv4* ipv4_addr) {
64   return PP_FromBool(
65       NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv4Address(
66           address_, ipv4_addr));
67 }
68 
DescribeAsIPv6Address(PP_NetAddress_IPv6 * ipv6_addr)69 PP_Bool NetAddressResource::DescribeAsIPv6Address(
70     PP_NetAddress_IPv6* ipv6_addr) {
71   return PP_FromBool(
72       NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv6Address(
73           address_, ipv6_addr));
74 }
75 
GetNetAddressPrivate()76 const PP_NetAddress_Private& NetAddressResource::GetNetAddressPrivate() {
77   return address_;
78 }
79 
80 }  // namespace proxy
81 }  // namespace ppapi
82