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/cpp/private/host_resolver_private.h" 6 7 #include "ppapi/c/pp_bool.h" 8 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/cpp/completion_callback.h" 10 #include "ppapi/cpp/instance_handle.h" 11 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module_impl.h" 13 #include "ppapi/cpp/pass_ref.h" 14 15 namespace pp { 16 17 namespace { 18 19 template <> const char* interface_name<PPB_HostResolver_Private_0_1>() { 20 return PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1; 21 } 22 23 } // namespace 24 25 HostResolverPrivate::HostResolverPrivate(const InstanceHandle& instance) { 26 if (has_interface<PPB_HostResolver_Private_0_1>()) { 27 PassRefFromConstructor( 28 get_interface<PPB_HostResolver_Private_0_1>()->Create( 29 instance.pp_instance())); 30 } 31 } 32 33 // static 34 bool HostResolverPrivate::IsAvailable() { 35 return has_interface<PPB_HostResolver_Private_0_1>(); 36 } 37 38 int32_t HostResolverPrivate::Resolve(const std::string& host, 39 uint16_t port, 40 const PP_HostResolver_Private_Hint& hint, 41 const CompletionCallback& callback) { 42 if (!has_interface<PPB_HostResolver_Private_0_1>()) 43 return callback.MayForce(PP_ERROR_NOINTERFACE); 44 return get_interface<PPB_HostResolver_Private_0_1>()->Resolve( 45 pp_resource(), 46 host.c_str(), 47 port, 48 &hint, 49 callback.pp_completion_callback()); 50 } 51 52 Var HostResolverPrivate::GetCanonicalName() { 53 if (!has_interface<PPB_HostResolver_Private_0_1>()) 54 return Var(Var::Null()); 55 56 PP_Var pp_canonical_name = 57 get_interface<PPB_HostResolver_Private_0_1>()->GetCanonicalName( 58 pp_resource()); 59 return Var(PASS_REF, pp_canonical_name); 60 } 61 62 uint32_t HostResolverPrivate::GetSize() { 63 if (!has_interface<PPB_HostResolver_Private_0_1>()) 64 return 0; 65 return get_interface<PPB_HostResolver_Private_0_1>()->GetSize(pp_resource()); 66 } 67 68 bool HostResolverPrivate::GetNetAddress(uint32_t index, 69 PP_NetAddress_Private* address) { 70 if (!has_interface<PPB_HostResolver_Private_0_1>()) 71 return false; 72 PP_Bool result = get_interface<PPB_HostResolver_Private_0_1>()->GetNetAddress( 73 pp_resource(), index, address); 74 return PP_ToBool(result); 75 } 76 77 } // namespace pp 78