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.
5 #include "ppapi/cpp/host_resolver.h"
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"
16 template <> const char* interface_name
<PPB_HostResolver_1_0
>() {
17 return PPB_HOSTRESOLVER_INTERFACE_1_0
;
22 HostResolver::HostResolver() {
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()));
32 HostResolver::HostResolver(PassRef
, PP_Resource resource
)
33 : Resource(PASS_REF
, resource
) {
36 HostResolver::HostResolver(const HostResolver
& other
) : Resource(other
) {
39 HostResolver::~HostResolver() {
42 HostResolver
& HostResolver::operator=(const HostResolver
& other
) {
43 Resource::operator=(other
);
48 bool HostResolver::IsAvailable() {
49 return has_interface
<PPB_HostResolver_1_0
>();
52 int32_t HostResolver::Resolve(const char* host
,
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());
61 return callback
.MayForce(PP_ERROR_NOINTERFACE
);
64 Var
HostResolver::GetCanonicalName() const {
65 if (has_interface
<PPB_HostResolver_1_0
>()) {
67 get_interface
<PPB_HostResolver_1_0
>()->GetCanonicalName(
74 uint32_t HostResolver::GetNetAddressCount() const {
75 if (has_interface
<PPB_HostResolver_1_0
>()) {
76 return get_interface
<PPB_HostResolver_1_0
>()->GetNetAddressCount(
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
));