Do not assume that the orientation is PORTRAIT by default.
[chromium-blink-merge.git] / ppapi / cpp / net_address.cc
blobe96b03da1266011c5074087d4214874145c18228
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"
11 namespace pp {
13 namespace {
15 template <> const char* interface_name<PPB_NetAddress_1_0>() {
16 return PPB_NETADDRESS_INTERFACE_1_0;
19 } // namespace
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);
54 return *this;
57 // static
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>()) {
71 return Var(PASS_REF,
72 get_interface<PPB_NetAddress_1_0>()->DescribeAsString(
73 pp_resource(), PP_FromBool(include_port)));
76 return Var();
79 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));
86 return false;
89 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));
96 return false;
99 } // namespace pp