Skip to content

Commit

Permalink
Introduce PPB_HostResolver_Dev.
Browse files Browse the repository at this point in the history
This change exposes the PPB_HostResolver_Dev interface and makes it to share the same backend as PPB_HostResolver_Private.

It doesn't include apps permission check, which will be implemented in separate CLs.

BUG=247225
TEST=newly added test_host_resolver.{h,cc}.

Review URL: https://chromiumcodereview.appspot.com/16727002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206321 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yzshen@chromium.org committed Jun 14, 2013
1 parent cce836e commit 0edbfc8
Show file tree
Hide file tree
Showing 32 changed files with 1,126 additions and 82 deletions.
30 changes: 30 additions & 0 deletions chrome/test/ppapi/ppapi_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,36 @@ TEST_PPAPI_IN_PROCESS_VIA_HTTP(TCPServerSocketPrivate)
TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(TCPServerSocketPrivate)
TEST_PPAPI_NACL(TCPServerSocketPrivate)

// HostResolver tests.
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, HostResolver) {
RunTestViaHTTP(
LIST_TEST(HostResolver_Empty)
LIST_TEST(HostResolver_Resolve)
LIST_TEST(HostResolver_ResolveIPv4)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClNewlibTest, HostResolver) {
RunTestViaHTTP(
LIST_TEST(HostResolver_Empty)
LIST_TEST(HostResolver_Resolve)
LIST_TEST(HostResolver_ResolveIPv4)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClGLibcTest, MAYBE_GLIBC(HostResolver)) {
RunTestViaHTTP(
LIST_TEST(HostResolver_Empty)
LIST_TEST(HostResolver_Resolve)
LIST_TEST(HostResolver_ResolveIPv4)
);
}
IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, HostResolver) {
RunTestViaHTTP(
LIST_TEST(HostResolver_Empty)
LIST_TEST(HostResolver_Resolve)
LIST_TEST(HostResolver_ResolveIPv4)
);
}

TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_Resolve)
TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_ResolveIPv4)
TEST_PPAPI_NACL(HostResolverPrivate_Resolve)
Expand Down
2 changes: 2 additions & 0 deletions native_client_sdk/src/build_tools/sdk_files.list
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ include/ppapi/c/dev/ppb_find_dev.h
include/ppapi/c/dev/ppb_font_dev.h
include/ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h
include/ppapi/c/dev/ppb_graphics_2d_dev.h
include/ppapi/c/dev/ppb_host_resolver_dev.h
include/ppapi/c/dev/ppb_ime_input_event_dev.h
include/ppapi/c/dev/ppb_keyboard_input_event_dev.h
include/ppapi/c/dev/ppb_memory_dev.h
Expand Down Expand Up @@ -379,6 +380,7 @@ include/ppapi/cpp/dev/file_chooser_dev.h
include/ppapi/cpp/dev/find_dev.h
include/ppapi/cpp/dev/font_dev.h
include/ppapi/cpp/dev/graphics_2d_dev.h
include/ppapi/cpp/dev/host_resolver_dev.h
include/ppapi/cpp/dev/ime_input_event_dev.h
include/ppapi/cpp/dev/memory_dev.h
include/ppapi/cpp/dev/net_address_dev.h
Expand Down
82 changes: 82 additions & 0 deletions ppapi/api/dev/ppb_host_resolver_dev.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

/**
* This file defines the <code>PPB_HostResolver_Dev</code> interface.
* TODO(yzshen): Tidy up the document.
*/

[generate_thunk]

label Chrome {
M29 = 0.1
};

/**
* The <code>PP_HostResolver_Flags_Dev</code> is an enumeration of the
* different types of flags, that can be OR-ed and passed to host
* resolver.
*/
[assert_size(4)]
enum PP_HostResolver_Flags_Dev {
/**
* AI_CANONNAME
*/
PP_HOSTRESOLVER_FLAGS_CANONNAME = 1 << 0,
/**
* Hint to the resolver that only loopback addresses are configured.
*/
PP_HOSTRESOLVER_FLAGS_LOOPBACK_ONLY = 1 << 1
};

[assert_size(8)]
struct PP_HostResolver_Hint_Dev {
PP_NetAddress_Family_Dev family;
int32_t flags;
};

interface PPB_HostResolver_Dev {
/**
* Allocates a Host Resolver resource.
*/
PP_Resource Create([in] PP_Instance instance);

/**
* Determines if a given resource is a Host Resolver.
*/
PP_Bool IsHostResolver([in] PP_Resource resource);

/**
* Creates a new request to Host Resolver. |callback| is invoked when request
* is processed and a list of network addresses is obtained. These addresses
* can be used in Connect, Bind or Listen calls to connect to a given |host|
* and |port|.
*/
int32_t Resolve([in] PP_Resource host_resolver,
[in] str_t host,
[in] uint16_t port,
[in] PP_HostResolver_Hint_Dev hint,
[in] PP_CompletionCallback callback);

/**
* Gets canonical name of host. Returns an undefined var if there is a pending
* Resolve call or the previous Resolve call failed.
*/
PP_Var GetCanonicalName([in] PP_Resource host_resolver);

/**
* Gets number of network addresses obtained after Resolve call. Returns 0 if
* there is a pending Resolve call or the previous Resolve call failed.
*/
uint32_t GetNetAddressCount([in] PP_Resource host_resolver);

/**
* Gets the |index|-th network address.
* Returns 0 if there is a pending Resolve call or the previous Resolve call
* failed, or |index| is not less than the number of available addresses.
*/
PP_Resource GetNetAddress([in] PP_Resource host_resolver,
[in] uint32_t index);
};
115 changes: 115 additions & 0 deletions ppapi/c/dev/ppb_host_resolver_dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* Copyright 2013 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

/* From dev/ppb_host_resolver_dev.idl modified Mon Jun 10 13:42:25 2013. */

#ifndef PPAPI_C_DEV_PPB_HOST_RESOLVER_DEV_H_
#define PPAPI_C_DEV_PPB_HOST_RESOLVER_DEV_H_

#include "ppapi/c/dev/ppb_net_address_dev.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"

#define PPB_HOSTRESOLVER_DEV_INTERFACE_0_1 "PPB_HostResolver(Dev);0.1"
#define PPB_HOSTRESOLVER_DEV_INTERFACE PPB_HOSTRESOLVER_DEV_INTERFACE_0_1

/**
* @file
* This file defines the <code>PPB_HostResolver_Dev</code> interface.
* TODO(yzshen): Tidy up the document.
*/


/**
* @addtogroup Enums
* @{
*/
/**
* The <code>PP_HostResolver_Flags_Dev</code> is an enumeration of the
* different types of flags, that can be OR-ed and passed to host
* resolver.
*/
typedef enum {
/**
* AI_CANONNAME
*/
PP_HOSTRESOLVER_FLAGS_CANONNAME = 1 << 0,
/**
* Hint to the resolver that only loopback addresses are configured.
*/
PP_HOSTRESOLVER_FLAGS_LOOPBACK_ONLY = 1 << 1
} PP_HostResolver_Flags_Dev;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_HostResolver_Flags_Dev, 4);
/**
* @}
*/

/**
* @addtogroup Structs
* @{
*/
struct PP_HostResolver_Hint_Dev {
PP_NetAddress_Family_Dev family;
int32_t flags;
};
PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_HostResolver_Hint_Dev, 8);
/**
* @}
*/

/**
* @addtogroup Interfaces
* @{
*/
struct PPB_HostResolver_Dev_0_1 {
/**
* Allocates a Host Resolver resource.
*/
PP_Resource (*Create)(PP_Instance instance);
/**
* Determines if a given resource is a Host Resolver.
*/
PP_Bool (*IsHostResolver)(PP_Resource resource);
/**
* Creates a new request to Host Resolver. |callback| is invoked when request
* is processed and a list of network addresses is obtained. These addresses
* can be used in Connect, Bind or Listen calls to connect to a given |host|
* and |port|.
*/
int32_t (*Resolve)(PP_Resource host_resolver,
const char* host,
uint16_t port,
const struct PP_HostResolver_Hint_Dev* hint,
struct PP_CompletionCallback callback);
/**
* Gets canonical name of host. Returns an undefined var if there is a pending
* Resolve call or the previous Resolve call failed.
*/
struct PP_Var (*GetCanonicalName)(PP_Resource host_resolver);
/**
* Gets number of network addresses obtained after Resolve call. Returns 0 if
* there is a pending Resolve call or the previous Resolve call failed.
*/
uint32_t (*GetNetAddressCount)(PP_Resource host_resolver);
/**
* Gets the |index|-th network address.
* Returns 0 if there is a pending Resolve call or the previous Resolve call
* failed, or |index| is not less than the number of available addresses.
*/
PP_Resource (*GetNetAddress)(PP_Resource host_resolver, uint32_t index);
};

typedef struct PPB_HostResolver_Dev_0_1 PPB_HostResolver_Dev;
/**
* @}
*/

#endif /* PPAPI_C_DEV_PPB_HOST_RESOLVER_DEV_H_ */

95 changes: 95 additions & 0 deletions ppapi/cpp/dev/host_resolver_dev.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/cpp/dev/host_resolver_dev.h"

#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/module_impl.h"

namespace pp {

namespace {

template <> const char* interface_name<PPB_HostResolver_Dev_0_1>() {
return PPB_HOSTRESOLVER_DEV_INTERFACE_0_1;
}

} // namespace

HostResolver_Dev::HostResolver_Dev() {
}

HostResolver_Dev::HostResolver_Dev(const InstanceHandle& instance) {
if (has_interface<PPB_HostResolver_Dev_0_1>()) {
PassRefFromConstructor(get_interface<PPB_HostResolver_Dev_0_1>()->Create(
instance.pp_instance()));
}
}

HostResolver_Dev::HostResolver_Dev(PassRef, PP_Resource resource)
: Resource(PASS_REF, resource) {
}

HostResolver_Dev::HostResolver_Dev(const HostResolver_Dev& other)
: Resource(other) {
}

HostResolver_Dev::~HostResolver_Dev() {
}

HostResolver_Dev& HostResolver_Dev::operator=(const HostResolver_Dev& other) {
Resource::operator=(other);
return *this;
}

// static
bool HostResolver_Dev::IsAvailable() {
return has_interface<PPB_HostResolver_Dev_0_1>();
}

int32_t HostResolver_Dev::Resolve(const char* host,
uint16_t port,
const PP_HostResolver_Hint_Dev& hint,
const CompletionCallback& callback) {
if (has_interface<PPB_HostResolver_Dev_0_1>()) {
return get_interface<PPB_HostResolver_Dev_0_1>()->Resolve(
pp_resource(), host, port, &hint, callback.pp_completion_callback());
}

return callback.MayForce(PP_ERROR_NOINTERFACE);
}

Var HostResolver_Dev::GetCanonicalName() const {
if (has_interface<PPB_HostResolver_Dev_0_1>()) {
return Var(PASS_REF,
get_interface<PPB_HostResolver_Dev_0_1>()->GetCanonicalName(
pp_resource()));
}

return Var();
}

uint32_t HostResolver_Dev::GetNetAddressCount() const {
if (has_interface<PPB_HostResolver_Dev_0_1>()) {
return get_interface<PPB_HostResolver_Dev_0_1>()->GetNetAddressCount(
pp_resource());
}

return 0;
}

NetAddress_Dev HostResolver_Dev::GetNetAddress(uint32_t index) const {
if (has_interface<PPB_HostResolver_Dev_0_1>()) {
return NetAddress_Dev(
PASS_REF,
get_interface<PPB_HostResolver_Dev_0_1>()->GetNetAddress(
pp_resource(), index));
}

return NetAddress_Dev();
}

} // namespace pp
48 changes: 48 additions & 0 deletions ppapi/cpp/dev/host_resolver_dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_CPP_DEV_HOST_RESOLVER_DEV_H_
#define PPAPI_CPP_DEV_HOST_RESOLVER_DEV_H_

#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/dev/ppb_host_resolver_dev.h"
#include "ppapi/cpp/dev/net_address_dev.h"
#include "ppapi/cpp/pass_ref.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/var.h"

namespace pp {

class CompletionCallback;
class InstanceHandle;

class HostResolver_Dev : public Resource {
public:
HostResolver_Dev();

explicit HostResolver_Dev(const InstanceHandle& instance);

HostResolver_Dev(PassRef, PP_Resource resource);

HostResolver_Dev(const HostResolver_Dev& other);

virtual ~HostResolver_Dev();

HostResolver_Dev& operator=(const HostResolver_Dev& other);

// Returns true if the required interface is available.
static bool IsAvailable();

int32_t Resolve(const char* host,
uint16_t port,
const PP_HostResolver_Hint_Dev& hint,
const CompletionCallback& callback);
Var GetCanonicalName() const;
uint32_t GetNetAddressCount() const;
NetAddress_Dev GetNetAddress(uint32_t index) const;
};

} // namespace pp

#endif // PPAPI_CPP_DEV_HOST_RESOLVER_DEV_H_
Loading

0 comments on commit 0edbfc8

Please sign in to comment.