• 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/c/pp_errors.h"
6 #include "ppapi/c/ppb_net_address.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_instance_api.h"
10 #include "ppapi/thunk/ppb_net_address_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
13 
14 namespace ppapi {
15 namespace thunk {
16 
17 namespace {
18 
CreateFromIPv4Address(PP_Instance instance,const struct PP_NetAddress_IPv4 * ipv4_addr)19 PP_Resource CreateFromIPv4Address(
20     PP_Instance instance,
21     const struct PP_NetAddress_IPv4* ipv4_addr) {
22   VLOG(4) << "PPB_NetAddress::CreateFromIPv4Address()";
23   EnterResourceCreation enter(instance);
24   if (enter.failed())
25     return 0;
26   return enter.functions()->CreateNetAddressFromIPv4Address(instance,
27                                                             ipv4_addr);
28 }
29 
CreateFromIPv6Address(PP_Instance instance,const struct PP_NetAddress_IPv6 * ipv6_addr)30 PP_Resource CreateFromIPv6Address(
31     PP_Instance instance,
32     const struct PP_NetAddress_IPv6* ipv6_addr) {
33   VLOG(4) << "PPB_NetAddress::CreateFromIPv6Address()";
34   EnterResourceCreation enter(instance);
35   if (enter.failed())
36     return 0;
37   return enter.functions()->CreateNetAddressFromIPv6Address(instance,
38                                                             ipv6_addr);
39 }
40 
IsNetAddress(PP_Resource resource)41 PP_Bool IsNetAddress(PP_Resource resource) {
42   VLOG(4) << "PPB_NetAddress::IsNetAddress()";
43   EnterResource<PPB_NetAddress_API> enter(resource, false);
44   return PP_FromBool(enter.succeeded());
45 }
46 
GetFamily(PP_Resource addr)47 PP_NetAddress_Family GetFamily(PP_Resource addr) {
48   VLOG(4) << "PPB_NetAddress::GetFamily()";
49   EnterResource<PPB_NetAddress_API> enter(addr, true);
50   if (enter.failed())
51     return PP_NETADDRESS_FAMILY_UNSPECIFIED;
52   return enter.object()->GetFamily();
53 }
54 
DescribeAsString(PP_Resource addr,PP_Bool include_port)55 struct PP_Var DescribeAsString(PP_Resource addr, PP_Bool include_port) {
56   VLOG(4) << "PPB_NetAddress::DescribeAsString()";
57   EnterResource<PPB_NetAddress_API> enter(addr, true);
58   if (enter.failed())
59     return PP_MakeUndefined();
60   return enter.object()->DescribeAsString(include_port);
61 }
62 
DescribeAsIPv4Address(PP_Resource addr,struct PP_NetAddress_IPv4 * ipv4_addr)63 PP_Bool DescribeAsIPv4Address(PP_Resource addr,
64                               struct PP_NetAddress_IPv4* ipv4_addr) {
65   VLOG(4) << "PPB_NetAddress::DescribeAsIPv4Address()";
66   EnterResource<PPB_NetAddress_API> enter(addr, true);
67   if (enter.failed())
68     return PP_FALSE;
69   return enter.object()->DescribeAsIPv4Address(ipv4_addr);
70 }
71 
DescribeAsIPv6Address(PP_Resource addr,struct PP_NetAddress_IPv6 * ipv6_addr)72 PP_Bool DescribeAsIPv6Address(PP_Resource addr,
73                               struct PP_NetAddress_IPv6* ipv6_addr) {
74   VLOG(4) << "PPB_NetAddress::DescribeAsIPv6Address()";
75   EnterResource<PPB_NetAddress_API> enter(addr, true);
76   if (enter.failed())
77     return PP_FALSE;
78   return enter.object()->DescribeAsIPv6Address(ipv6_addr);
79 }
80 
81 const PPB_NetAddress_1_0 g_ppb_netaddress_thunk_1_0 = {
82   &CreateFromIPv4Address,
83   &CreateFromIPv6Address,
84   &IsNetAddress,
85   &GetFamily,
86   &DescribeAsString,
87   &DescribeAsIPv4Address,
88   &DescribeAsIPv6Address
89 };
90 
91 }  // namespace
92 
GetPPB_NetAddress_1_0_Thunk()93 const PPB_NetAddress_1_0* GetPPB_NetAddress_1_0_Thunk() {
94   return &g_ppb_netaddress_thunk_1_0;
95 }
96 
97 }  // namespace thunk
98 }  // namespace ppapi
99