Home | History | Annotate | Download | only in cpp
      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/cpp/host_resolver.h"
      6 
      7 #include "ppapi/c/pp_errors.h"
      8 #include "ppapi/cpp/completion_callback.h"
      9 #include "ppapi/cpp/instance_handle.h"
     10 #include "ppapi/cpp/module_impl.h"
     11 
     12 namespace pp {
     13 
     14 namespace {
     15 
     16 template <> const char* interface_name<PPB_HostResolver_1_0>() {
     17   return PPB_HOSTRESOLVER_INTERFACE_1_0;
     18 }
     19 
     20 }  // namespace
     21 
     22 HostResolver::HostResolver() {
     23 }
     24 
     25 HostResolver::HostResolver(const InstanceHandle& instance) {
     26   if (has_interface<PPB_HostResolver_1_0>()) {
     27     PassRefFromConstructor(get_interface<PPB_HostResolver_1_0>()->Create(
     28         instance.pp_instance()));
     29   }
     30 }
     31 
     32 HostResolver::HostResolver(PassRef, PP_Resource resource)
     33     : Resource(PASS_REF, resource) {
     34 }
     35 
     36 HostResolver::HostResolver(const HostResolver& other) : Resource(other) {
     37 }
     38 
     39 HostResolver::~HostResolver() {
     40 }
     41 
     42 HostResolver& HostResolver::operator=(const HostResolver& other) {
     43   Resource::operator=(other);
     44   return *this;
     45 }
     46 
     47 // static
     48 bool HostResolver::IsAvailable() {
     49   return has_interface<PPB_HostResolver_1_0>();
     50 }
     51 
     52 int32_t HostResolver::Resolve(const char* host,
     53                               uint16_t port,
     54                               const PP_HostResolver_Hint& hint,
     55                               const CompletionCallback& callback) {
     56   if (has_interface<PPB_HostResolver_1_0>()) {
     57     return get_interface<PPB_HostResolver_1_0>()->Resolve(
     58         pp_resource(), host, port, &hint, callback.pp_completion_callback());
     59   }
     60 
     61   return callback.MayForce(PP_ERROR_NOINTERFACE);
     62 }
     63 
     64 Var HostResolver::GetCanonicalName() const {
     65   if (has_interface<PPB_HostResolver_1_0>()) {
     66     return Var(PASS_REF,
     67                get_interface<PPB_HostResolver_1_0>()->GetCanonicalName(
     68                    pp_resource()));
     69   }
     70 
     71   return Var();
     72 }
     73 
     74 uint32_t HostResolver::GetNetAddressCount() const {
     75   if (has_interface<PPB_HostResolver_1_0>()) {
     76     return get_interface<PPB_HostResolver_1_0>()->GetNetAddressCount(
     77         pp_resource());
     78   }
     79 
     80   return 0;
     81 }
     82 
     83 NetAddress HostResolver::GetNetAddress(uint32_t index) const {
     84   if (has_interface<PPB_HostResolver_1_0>()) {
     85     return NetAddress(PASS_REF,
     86                       get_interface<PPB_HostResolver_1_0>()->GetNetAddress(
     87                           pp_resource(), index));
     88   }
     89 
     90   return NetAddress();
     91 }
     92 
     93 }  // namespace pp
     94