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/proxy/host_resolver_resource.h" 6 7 #include "base/logging.h" 8 #include "ppapi/c/private/ppb_host_resolver_private.h" 9 #include "ppapi/proxy/net_address_resource.h" 10 #include "ppapi/shared_impl/tracked_callback.h" 11 12 namespace ppapi { 13 namespace proxy { 14 15 namespace { 16 17 PP_HostResolver_Private_Hint ConvertToHostResolverPrivateHint( 18 const PP_HostResolver_Hint& hint) { 19 PP_HostResolver_Private_Hint private_hint; 20 switch (hint.family) { 21 case PP_NETADDRESS_FAMILY_UNSPECIFIED: 22 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_UNSPECIFIED; 23 break; 24 case PP_NETADDRESS_FAMILY_IPV4: 25 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_IPV4; 26 break; 27 case PP_NETADDRESS_FAMILY_IPV6: 28 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_IPV6; 29 break; 30 default: 31 NOTREACHED(); 32 private_hint.family = PP_NETADDRESSFAMILY_PRIVATE_UNSPECIFIED; 33 } 34 35 private_hint.flags = 0; 36 if (hint.flags & PP_HOSTRESOLVER_FLAG_CANONNAME) 37 private_hint.flags |= PP_HOST_RESOLVER_PRIVATE_FLAGS_CANONNAME; 38 39 return private_hint; 40 } 41 42 } // namespace 43 44 HostResolverResource::HostResolverResource(Connection connection, 45 PP_Instance instance) 46 : HostResolverResourceBase(connection, instance, false) { 47 } 48 49 HostResolverResource::~HostResolverResource() { 50 } 51 52 thunk::PPB_HostResolver_API* HostResolverResource::AsPPB_HostResolver_API() { 53 return this; 54 } 55 56 int32_t HostResolverResource::Resolve(const char* host, 57 uint16_t port, 58 const PP_HostResolver_Hint* hint, 59 scoped_refptr<TrackedCallback> callback) { 60 if (!hint) 61 return PP_ERROR_BADARGUMENT; 62 63 PP_HostResolver_Private_Hint private_hint = 64 ConvertToHostResolverPrivateHint(*hint); 65 return ResolveImpl(host, port, &private_hint, callback); 66 } 67 68 PP_Var HostResolverResource::GetCanonicalName() { 69 return GetCanonicalNameImpl(); 70 } 71 72 uint32_t HostResolverResource::GetNetAddressCount() { 73 return GetSizeImpl(); 74 } 75 76 PP_Resource HostResolverResource::GetNetAddress(uint32_t index) { 77 scoped_refptr<NetAddressResource> addr_resource = GetNetAddressImpl(index); 78 if (!addr_resource.get()) 79 return 0; 80 81 return addr_resource->GetReference(); 82 } 83 84 } // namespace proxy 85 } // namespace ppapi 86