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.
5 #include "ppapi/cpp/net_address.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/cpp/instance_handle.h"
9 #include "ppapi/cpp/module_impl.h"
15 template <> const char* interface_name
<PPB_NetAddress_1_0
>() {
16 return PPB_NETADDRESS_INTERFACE_1_0
;
21 NetAddress::NetAddress() {
24 NetAddress::NetAddress(PassRef
, PP_Resource resource
)
25 : Resource(PASS_REF
, resource
) {
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
));
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
));
46 NetAddress::NetAddress(const NetAddress
& other
) : Resource(other
) {
49 NetAddress::~NetAddress() {
52 NetAddress
& NetAddress::operator=(const NetAddress
& other
) {
53 Resource::operator=(other
);
58 bool NetAddress::IsAvailable() {
59 return has_interface
<PPB_NetAddress_1_0
>();
62 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());
66 return PP_NETADDRESS_FAMILY_UNSPECIFIED
;
69 Var
NetAddress::DescribeAsString(bool include_port
) const {
70 if (has_interface
<PPB_NetAddress_1_0
>()) {
72 get_interface
<PPB_NetAddress_1_0
>()->DescribeAsString(
73 pp_resource(), PP_FromBool(include_port
)));
79 bool NetAddress::DescribeAsIPv4Address(PP_NetAddress_IPv4
* ipv4_addr
) const {
80 if (has_interface
<PPB_NetAddress_1_0
>()) {
82 get_interface
<PPB_NetAddress_1_0
>()->DescribeAsIPv4Address(
83 pp_resource(), ipv4_addr
));
89 bool NetAddress::DescribeAsIPv6Address(PP_NetAddress_IPv6
* ipv6_addr
) const {
90 if (has_interface
<PPB_NetAddress_1_0
>()) {
92 get_interface
<PPB_NetAddress_1_0
>()->DescribeAsIPv6Address(
93 pp_resource(), ipv6_addr
));