• 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/cpp/net_address.h"
6 
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/cpp/instance_handle.h"
9 #include "ppapi/cpp/module_impl.h"
10 
11 namespace pp {
12 
13 namespace {
14 
interface_name()15 template <> const char* interface_name<PPB_NetAddress_1_0>() {
16   return PPB_NETADDRESS_INTERFACE_1_0;
17 }
18 
19 }  // namespace
20 
NetAddress()21 NetAddress::NetAddress() {
22 }
23 
NetAddress(PassRef,PP_Resource resource)24 NetAddress::NetAddress(PassRef, PP_Resource resource)
25     : Resource(PASS_REF, resource) {
26 }
27 
NetAddress(const InstanceHandle & instance,const PP_NetAddress_IPv4 & ipv4_addr)28 NetAddress::NetAddress(const InstanceHandle& instance,
29                        const PP_NetAddress_IPv4& ipv4_addr) {
30   if (has_interface<PPB_NetAddress_1_0>()) {
31     PassRefFromConstructor(
32         get_interface<PPB_NetAddress_1_0>()->CreateFromIPv4Address(
33             instance.pp_instance(), &ipv4_addr));
34   }
35 }
36 
NetAddress(const InstanceHandle & instance,const PP_NetAddress_IPv6 & ipv6_addr)37 NetAddress::NetAddress(const InstanceHandle& instance,
38                        const PP_NetAddress_IPv6& ipv6_addr) {
39   if (has_interface<PPB_NetAddress_1_0>()) {
40     PassRefFromConstructor(
41         get_interface<PPB_NetAddress_1_0>()->CreateFromIPv6Address(
42             instance.pp_instance(), &ipv6_addr));
43   }
44 }
45 
NetAddress(const NetAddress & other)46 NetAddress::NetAddress(const NetAddress& other) : Resource(other) {
47 }
48 
~NetAddress()49 NetAddress::~NetAddress() {
50 }
51 
operator =(const NetAddress & other)52 NetAddress& NetAddress::operator=(const NetAddress& other) {
53   Resource::operator=(other);
54   return *this;
55 }
56 
57 // static
IsAvailable()58 bool NetAddress::IsAvailable() {
59   return has_interface<PPB_NetAddress_1_0>();
60 }
61 
GetFamily() const62 PP_NetAddress_Family NetAddress::GetFamily() const {
63   if (has_interface<PPB_NetAddress_1_0>())
64     return get_interface<PPB_NetAddress_1_0>()->GetFamily(pp_resource());
65 
66   return PP_NETADDRESS_FAMILY_UNSPECIFIED;
67 }
68 
DescribeAsString(bool include_port) const69 Var NetAddress::DescribeAsString(bool include_port) const {
70   if (has_interface<PPB_NetAddress_1_0>()) {
71     return Var(PASS_REF,
72                get_interface<PPB_NetAddress_1_0>()->DescribeAsString(
73                    pp_resource(), PP_FromBool(include_port)));
74   }
75 
76   return Var();
77 }
78 
DescribeAsIPv4Address(PP_NetAddress_IPv4 * ipv4_addr) const79 bool NetAddress::DescribeAsIPv4Address(PP_NetAddress_IPv4* ipv4_addr) const {
80   if (has_interface<PPB_NetAddress_1_0>()) {
81     return PP_ToBool(
82         get_interface<PPB_NetAddress_1_0>()->DescribeAsIPv4Address(
83             pp_resource(), ipv4_addr));
84   }
85 
86   return false;
87 }
88 
DescribeAsIPv6Address(PP_NetAddress_IPv6 * ipv6_addr) const89 bool NetAddress::DescribeAsIPv6Address(PP_NetAddress_IPv6* ipv6_addr) const {
90   if (has_interface<PPB_NetAddress_1_0>()) {
91     return PP_ToBool(
92         get_interface<PPB_NetAddress_1_0>()->DescribeAsIPv6Address(
93             pp_resource(), ipv6_addr));
94   }
95 
96   return false;
97 }
98 
99 }  // namespace pp
100