• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_var.h"
6 #include "ppapi/c/private/ppb_host_resolver_private.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_host_resolver_private_api.h"
10 #include "ppapi/thunk/resource_creation_api.h"
11 #include "ppapi/thunk/thunk.h"
12 
13 namespace ppapi {
14 namespace thunk {
15 
16 namespace {
17 
18 typedef EnterResource<PPB_HostResolver_Private_API> EnterHostResolver;
19 
Create(PP_Instance instance)20 PP_Resource Create(PP_Instance instance) {
21   EnterResourceCreation enter(instance);
22   if (enter.failed())
23     return 0;
24   return enter.functions()->CreateHostResolverPrivate(instance);
25 }
26 
IsHostResolver(PP_Resource resource)27 PP_Bool IsHostResolver(PP_Resource resource) {
28   EnterHostResolver enter(resource, false);
29   return PP_FromBool(enter.succeeded());
30 }
31 
Resolve(PP_Resource host_resolver,const char * host,uint16_t port,const PP_HostResolver_Private_Hint * hint,PP_CompletionCallback callback)32 int32_t Resolve(PP_Resource host_resolver,
33                 const char* host,
34                 uint16_t port,
35                 const PP_HostResolver_Private_Hint* hint,
36                 PP_CompletionCallback callback) {
37   EnterHostResolver enter(host_resolver, callback, true);
38   if (enter.failed())
39     return enter.retval();
40   return enter.SetResult(enter.object()->Resolve(host, port, hint,
41                                                  enter.callback()));
42 }
43 
GetCanonicalName(PP_Resource host_resolver)44 PP_Var GetCanonicalName(PP_Resource host_resolver) {
45   EnterHostResolver enter(host_resolver, true);
46   if (enter.failed())
47     return PP_MakeUndefined();
48   return enter.object()->GetCanonicalName();
49 }
50 
GetSize(PP_Resource host_resolver)51 uint32_t GetSize(PP_Resource host_resolver) {
52   EnterHostResolver enter(host_resolver, true);
53   if (enter.failed())
54     return 0;
55   return enter.object()->GetSize();
56 }
57 
GetNetAddress(PP_Resource host_resolver,uint32_t index,PP_NetAddress_Private * addr)58 PP_Bool GetNetAddress(PP_Resource host_resolver,
59                       uint32_t index,
60                       PP_NetAddress_Private* addr) {
61   EnterHostResolver enter(host_resolver, true);
62   if (enter.failed())
63     return PP_FALSE;
64   return PP_FromBool(enter.object()->GetNetAddress(index, addr));
65 }
66 
67 const PPB_HostResolver_Private g_ppb_host_resolver_thunk = {
68   &Create,
69   &IsHostResolver,
70   &Resolve,
71   &GetCanonicalName,
72   &GetSize,
73   &GetNetAddress
74 };
75 
76 }  // namespace
77 
GetPPB_HostResolver_Private_0_1_Thunk()78 const PPB_HostResolver_Private_0_1* GetPPB_HostResolver_Private_0_1_Thunk() {
79   return &g_ppb_host_resolver_thunk;
80 }
81 
82 }  // namespace thunk
83 }  // namespace ppapi
84