forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
32 changed files
with
1,126 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.