summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/test/ui/ppapi_uitest.cc7
-rw-r--r--content/browser/renderer_host/pepper_lookup_request.h60
-rw-r--r--content/browser/renderer_host/pepper_message_filter.cc198
-rw-r--r--content/browser/renderer_host/pepper_message_filter.h46
-rw-r--r--content/content_browser.gypi1
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc2
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.cc58
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.h17
-rw-r--r--ppapi/api/private/ppb_host_resolver_private.idl79
-rw-r--r--ppapi/c/private/ppb_host_resolver_private.h118
-rw-r--r--ppapi/ppapi_proxy.gypi2
-rw-r--r--ppapi/ppapi_shared.gypi5
-rw-r--r--ppapi/ppapi_sources.gypi2
-rw-r--r--ppapi/proxy/interface_list.cc1
-rw-r--r--ppapi/proxy/ppapi_messages.h37
-rw-r--r--ppapi/proxy/ppb_host_resolver_private_proxy.cc123
-rw-r--r--ppapi/proxy/ppb_host_resolver_private_proxy.h43
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc6
-rw-r--r--ppapi/proxy/resource_creation_proxy.h1
-rw-r--r--ppapi/shared_impl/api_id.h1
-rw-r--r--ppapi/shared_impl/private/ppb_host_resolver_shared.cc118
-rw-r--r--ppapi/shared_impl/private/ppb_host_resolver_shared.h83
-rw-r--r--ppapi/shared_impl/resource.h1
-rw-r--r--ppapi/tests/test_host_resolver_private.cc238
-rw-r--r--ppapi/tests/test_host_resolver_private.h62
-rw-r--r--ppapi/thunk/interfaces_ppb_private.h3
-rw-r--r--ppapi/thunk/ppb_host_resolver_private_api.h31
-rw-r--r--ppapi/thunk/ppb_host_resolver_private_thunk.cc81
-rw-r--r--ppapi/thunk/resource_creation_api.h1
-rw-r--r--ppapi/thunk/thunk.h3
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc14
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h10
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h13
-rw-r--r--webkit/plugins/ppapi/ppb_host_resolver_private_impl.cc38
-rw-r--r--webkit/plugins/ppapi/ppb_host_resolver_private_impl.h29
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc6
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.h1
38 files changed, 1473 insertions, 68 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc
index 055b615..ddecbc1 100644
--- a/chrome/test/ui/ppapi_uitest.cc
+++ b/chrome/test/ui/ppapi_uitest.cc
@@ -480,6 +480,13 @@ TEST_PPAPI_IN_PROCESS_VIA_HTTP(TCPServerSocketPrivate)
// TODO(ygorshenin): http://crbug.com/116480.
TEST_PPAPI_NACL_VIA_HTTP(DISABLED_TCPServerSocketPrivate)
+TEST_PPAPI_IN_PROCESS_VIA_HTTP(HostResolverPrivate_Create)
+TEST_PPAPI_IN_PROCESS_VIA_HTTP(HostResolverPrivate_Resolve)
+TEST_PPAPI_IN_PROCESS_VIA_HTTP(HostResolverPrivate_ResolveIPV4)
+TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_Create)
+TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_Resolve)
+TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(HostResolverPrivate_ResolveIPV4)
+
// URLLoader tests.
TEST_PPAPI_IN_PROCESS_VIA_HTTP(URLLoader_BasicGET)
TEST_PPAPI_IN_PROCESS_VIA_HTTP(URLLoader_BasicPOST)
diff --git a/content/browser/renderer_host/pepper_lookup_request.h b/content/browser/renderer_host/pepper_lookup_request.h
new file mode 100644
index 0000000..89d738e
--- /dev/null
+++ b/content/browser/renderer_host/pepper_lookup_request.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_
+#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_
+#pragma once
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/address_list.h"
+#include "net/base/host_resolver.h"
+#include "net/base/net_errors.h"
+#include "net/base/single_request_host_resolver.h"
+
+template<class T>
+class PepperLookupRequest {
+ public:
+ typedef base::Callback<void(int, const net::AddressList&, const T&)>
+ LookupRequestCallback;
+
+ // Takes ownership over |bound_info|. |bound_info| will be passed to
+ // callback, when lookup will finish.
+ PepperLookupRequest(net::HostResolver* resolver,
+ const net::HostResolver::RequestInfo& request_info,
+ T* bound_info,
+ const LookupRequestCallback& callback)
+ : resolver_(resolver),
+ request_info_(request_info),
+ bound_info_(bound_info),
+ callback_(callback) {
+ }
+
+ void Start() {
+ int result = resolver_.Resolve(
+ request_info_, &addresses_,
+ base::Bind(&PepperLookupRequest<T>::OnLookupFinished,
+ base::Unretained(this)),
+ net::BoundNetLog());
+ if (result != net::ERR_IO_PENDING)
+ OnLookupFinished(result);
+ }
+
+ private:
+ void OnLookupFinished(int result) {
+ callback_.Run(result, addresses_, *bound_info_);
+ delete this;
+ }
+
+ net::SingleRequestHostResolver resolver_;
+ net::HostResolver::RequestInfo request_info_;
+ scoped_ptr<T> bound_info_;
+ LookupRequestCallback callback_;
+
+ net::AddressList addresses_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperLookupRequest);
+};
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_LOOKUP_REQUEST_H_
diff --git a/content/browser/renderer_host/pepper_message_filter.cc b/content/browser/renderer_host/pepper_message_filter.cc
index f17f73c..92a30ae 100644
--- a/content/browser/renderer_host/pepper_message_filter.cc
+++ b/content/browser/renderer_host/pepper_message_filter.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
@@ -13,6 +14,7 @@
#include "base/process_util.h"
#include "base/threading/worker_pool.h"
#include "base/values.h"
+#include "content/browser/renderer_host/pepper_lookup_request.h"
#include "content/browser/renderer_host/pepper_tcp_server_socket.h"
#include "content/browser/renderer_host/pepper_tcp_socket.h"
#include "content/browser/renderer_host/pepper_udp_socket.h"
@@ -25,16 +27,18 @@
#include "content/public/browser/resource_context.h"
#include "content/public/browser/site_instance.h"
#include "content/public/common/content_client.h"
+#include "net/base/address_family.h"
#include "net/base/address_list.h"
#include "net/base/cert_verifier.h"
#include "net/base/host_port_pair.h"
-#include "net/base/host_resolver.h"
-#include "net/base/net_errors.h"
-#include "net/base/single_request_host_resolver.h"
+#include "net/base/sys_addrinfo.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
+#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/c/private/ppb_net_address_private.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/private/net_address_private_impl.h"
+#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
#include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
#if defined(ENABLE_FLAPPER_HACKS)
@@ -88,7 +92,8 @@ void PepperMessageFilter::OverrideThreadForMessage(
if (message.type() == PpapiHostMsg_PPBTCPSocket_Connect::ID ||
message.type() == PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress::ID ||
message.type() == PpapiHostMsg_PPBUDPSocket_Bind::ID ||
- message.type() == PpapiHostMsg_PPBTCPServerSocket_Listen::ID) {
+ message.type() == PpapiHostMsg_PPBTCPServerSocket_Listen::ID ||
+ message.type() == PpapiHostMsg_PPBHostResolver_Resolve::ID) {
*thread = BrowserThread::UI;
}
}
@@ -131,6 +136,10 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg,
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPServerSocket_Destroy,
RemoveTCPServerSocket)
+ // HostResolver messages.
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBHostResolver_Resolve,
+ OnHostResolverResolve)
+
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
@@ -217,48 +226,6 @@ int ConnectTcpSocket(const PP_NetAddress_Private& addr,
} // namespace
-class PepperMessageFilter::LookupRequest {
- public:
- LookupRequest(PepperMessageFilter* pepper_message_filter,
- net::HostResolver* resolver,
- int routing_id,
- int request_id,
- const net::HostResolver::RequestInfo& request_info)
- : pepper_message_filter_(pepper_message_filter),
- resolver_(resolver),
- routing_id_(routing_id),
- request_id_(request_id),
- request_info_(request_info) {
- }
-
- void Start() {
- int result = resolver_.Resolve(
- request_info_, &addresses_,
- base::Bind(&LookupRequest::OnLookupFinished, base::Unretained(this)),
- net::BoundNetLog());
- if (result != net::ERR_IO_PENDING)
- OnLookupFinished(result);
- }
-
- private:
- void OnLookupFinished(int /*result*/) {
- pepper_message_filter_->ConnectTcpLookupFinished(
- routing_id_, request_id_, addresses_);
- delete this;
- }
-
- PepperMessageFilter* pepper_message_filter_;
- net::SingleRequestHostResolver resolver_;
-
- int routing_id_;
- int request_id_;
- net::HostResolver::RequestInfo request_info_;
-
- net::AddressList addresses_;
-
- DISALLOW_COPY_AND_ASSIGN(LookupRequest);
-};
-
void PepperMessageFilter::OnConnectTcp(int routing_id,
int request_id,
const std::string& host,
@@ -267,10 +234,18 @@ void PepperMessageFilter::OnConnectTcp(int routing_id,
net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port));
+ scoped_ptr<OnConnectTcpBoundInfo> bound_info(new OnConnectTcpBoundInfo);
+ bound_info->routing_id = routing_id;
+ bound_info->request_id = request_id;
+
// The lookup request will delete itself on completion.
- LookupRequest* lookup_request =
- new LookupRequest(this, GetHostResolver(),
- routing_id, request_id, request_info);
+ PepperLookupRequest<OnConnectTcpBoundInfo>* lookup_request =
+ new PepperLookupRequest<OnConnectTcpBoundInfo>(
+ GetHostResolver(),
+ request_info,
+ bound_info.release(),
+ base::Bind(&PepperMessageFilter::ConnectTcpLookupFinished,
+ this));
lookup_request->Start();
}
@@ -302,9 +277,9 @@ bool PepperMessageFilter::SendConnectTcpACKError(int routing_id,
}
void PepperMessageFilter::ConnectTcpLookupFinished(
- int routing_id,
- int request_id,
- const net::AddressList& addresses) {
+ int result,
+ const net::AddressList& addresses,
+ const OnConnectTcpBoundInfo& bound_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// If the lookup returned addresses, continue (doing |connect()|) on a worker
@@ -314,9 +289,9 @@ void PepperMessageFilter::ConnectTcpLookupFinished(
FROM_HERE,
base::Bind(
&PepperMessageFilter::ConnectTcpOnWorkerThread, this,
- routing_id, request_id, addresses),
+ bound_info.routing_id, bound_info.request_id, addresses),
true)) {
- SendConnectTcpACKError(routing_id, request_id);
+ SendConnectTcpACKError(bound_info.routing_id, bound_info.request_id);
}
}
@@ -647,6 +622,121 @@ void PepperMessageFilter::OnTCPServerAccept(uint32 real_socket_id) {
iter->second->Accept();
}
+void PepperMessageFilter::OnHostResolverResolve(
+ int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ const ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint& hint) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&PepperMessageFilter::DoHostResolverResolve, this,
+ CanUseSocketAPIs(routing_id),
+ routing_id,
+ plugin_dispatcher_id,
+ host_resolver_id,
+ host_port,
+ hint));
+}
+
+void PepperMessageFilter::DoHostResolverResolve(
+ bool allowed,
+ int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ const ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint& hint) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (!allowed) {
+ SendHostResolverResolveACKError(routing_id,
+ plugin_dispatcher_id,
+ host_resolver_id);
+ return;
+ }
+
+ net::HostResolver::RequestInfo request_info(
+ net::HostPortPair(host_port.host, host_port.port));
+
+ net::AddressFamily address_family;
+ switch (hint.family) {
+ case PP_NETADDRESSFAMILY_IPV4:
+ address_family = net::ADDRESS_FAMILY_IPV4;
+ break;
+ case PP_NETADDRESSFAMILY_IPV6:
+ address_family = net::ADDRESS_FAMILY_IPV6;
+ break;
+ default:
+ address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
+ }
+ request_info.set_address_family(address_family);
+
+ net::HostResolverFlags host_resolver_flags = 0;
+ if (hint.flags & PP_HOST_RESOLVER_FLAGS_CANONNAME)
+ host_resolver_flags |= net::HOST_RESOLVER_CANONNAME;
+ if (hint.flags & PP_HOST_RESOLVER_FLAGS_LOOPBACK_ONLY)
+ host_resolver_flags |= net::HOST_RESOLVER_LOOPBACK_ONLY;
+ request_info.set_host_resolver_flags(host_resolver_flags);
+
+ scoped_ptr<OnHostResolverResolveBoundInfo> bound_info(
+ new OnHostResolverResolveBoundInfo);
+ bound_info->routing_id = routing_id;
+ bound_info->plugin_dispatcher_id = plugin_dispatcher_id;
+ bound_info->host_resolver_id = host_resolver_id;
+
+ // The lookup request will delete itself on completion.
+ PepperLookupRequest<OnHostResolverResolveBoundInfo>* lookup_request =
+ new PepperLookupRequest<OnHostResolverResolveBoundInfo>(
+ GetHostResolver(),
+ request_info,
+ bound_info.release(),
+ base::Bind(&PepperMessageFilter::OnHostResolverResolveLookupFinished,
+ this));
+ lookup_request->Start();
+}
+
+void PepperMessageFilter::OnHostResolverResolveLookupFinished(
+ int result,
+ const net::AddressList& addresses,
+ const OnHostResolverResolveBoundInfo& bound_info) {
+ if (result != net::OK) {
+ SendHostResolverResolveACKError(bound_info.routing_id,
+ bound_info.plugin_dispatcher_id,
+ bound_info.host_resolver_id);
+ } else {
+ std::string canonical_name;
+ addresses.GetCanonicalName(&canonical_name);
+ scoped_ptr<ppapi::NetAddressList> net_address_list(
+ ppapi::CreateNetAddressListFromAddrInfo(addresses.head()));
+ if (!net_address_list.get()) {
+ SendHostResolverResolveACKError(bound_info.routing_id,
+ bound_info.plugin_dispatcher_id,
+ bound_info.host_resolver_id);
+ } else {
+ Send(new PpapiMsg_PPBHostResolver_ResolveACK(
+ bound_info.routing_id,
+ bound_info.plugin_dispatcher_id,
+ bound_info.host_resolver_id,
+ true,
+ canonical_name,
+ *net_address_list.get()));
+ }
+ }
+}
+
+bool PepperMessageFilter::SendHostResolverResolveACKError(
+ int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id) {
+ return Send(new PpapiMsg_PPBHostResolver_ResolveACK(
+ routing_id,
+ plugin_dispatcher_id,
+ host_resolver_id,
+ false,
+ "",
+ ppapi::NetAddressList()));
+}
+
void PepperMessageFilter::GetFontFamiliesComplete(
IPC::Message* reply_msg,
scoped_ptr<base::ListValue> result) {
diff --git a/content/browser/renderer_host/pepper_message_filter.h b/content/browser/renderer_host/pepper_message_filter.h
index cccff7c..a1a5610 100644
--- a/content/browser/renderer_host/pepper_message_filter.h
+++ b/content/browser/renderer_host/pepper_message_filter.h
@@ -23,6 +23,7 @@ class ListValue;
class PepperTCPServerSocket;
class PepperTCPSocket;
class PepperUDPSocket;
+struct PP_HostResolver_Private_Hint;
struct PP_NetAddress_Private;
namespace content {
@@ -35,6 +36,10 @@ class CertVerifier;
class HostResolver;
}
+namespace ppapi {
+struct HostPortPair;
+}
+
// This class is used in two contexts, both supporting PPAPI plugins. The first
// is on the renderer->browser channel, to handle requests from in-process
// PPAPI plugins and any requests that the PPAPI implementation code in the
@@ -82,6 +87,17 @@ class PepperMessageFilter : public content::BrowserMessageFilter {
const net::SSLConfig& ssl_config() { return ssl_config_; }
private:
+ struct OnConnectTcpBoundInfo {
+ int routing_id;
+ int request_id;
+ };
+
+ struct OnHostResolverResolveBoundInfo {
+ int32 routing_id;
+ uint32 plugin_dispatcher_id;
+ uint32 host_resolver_id;
+ };
+
#if defined(ENABLE_FLAPPER_HACKS)
// Message handlers.
void OnConnectTcp(int routing_id,
@@ -96,14 +112,10 @@ class PepperMessageFilter : public content::BrowserMessageFilter {
bool SendConnectTcpACKError(int routing_id,
int request_id);
- // Used by |OnConnectTcp()| (below).
- class LookupRequest;
- friend class LookupRequest;
-
// Continuation of |OnConnectTcp()|.
- void ConnectTcpLookupFinished(int routing_id,
- int request_id,
- const net::AddressList& addresses);
+ void ConnectTcpLookupFinished(int result,
+ const net::AddressList& addresses,
+ const OnConnectTcpBoundInfo& bound_info);
void ConnectTcpOnWorkerThread(int routing_id,
int request_id,
net::AddressList addresses);
@@ -153,6 +165,20 @@ class PepperMessageFilter : public content::BrowserMessageFilter {
int32_t backlog);
void OnTCPServerAccept(uint32 real_socket_id);
+ void OnHostResolverResolve(int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ const ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint& hint);
+ // Continuation of |OnHostResolverResolve()|.
+ void OnHostResolverResolveLookupFinished(
+ int result,
+ const net::AddressList& addresses,
+ const OnHostResolverResolveBoundInfo& bound_info);
+ bool SendHostResolverResolveACKError(int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id);
+
void DoTCPConnect(bool allowed,
int32 routing_id,
uint32 socket_id,
@@ -172,6 +198,12 @@ class PepperMessageFilter : public content::BrowserMessageFilter {
uint32 temp_socket_id,
const PP_NetAddress_Private& addr,
int32_t backlog);
+ void DoHostResolverResolve(bool allowed,
+ int32 routing_id,
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ const ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint& hint);
// Callback when the font list has been retrieved on a background thread.
void GetFontFamiliesComplete(IPC::Message* reply_msg,
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index f3495a0..8ee5461 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -513,6 +513,7 @@
'browser/renderer_host/native_web_keyboard_event_win.cc',
'browser/renderer_host/pepper_file_message_filter.cc',
'browser/renderer_host/pepper_file_message_filter.h',
+ 'browser/renderer_host/pepper_lookup_request.h',
'browser/renderer_host/pepper_message_filter.cc',
'browser/renderer_host/pepper_message_filter.h',
'browser/renderer_host/pepper_tcp_server_socket.cc',
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index 6450cf8..08cada4 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -97,6 +97,8 @@ bool PpapiThread::OnMessageReceived(const IPC::Message& msg) {
OnPluginDispatcherMessageReceived(msg))
IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBUDPSocket_BindACK,
OnPluginDispatcherMessageReceived(msg))
+ IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBHostResolver_ResolveACK,
+ OnPluginDispatcherMessageReceived(msg))
IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState)
IPC_END_MESSAGE_MAP()
return true;
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
index c2041e7..a68ab1c 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
@@ -5,6 +5,7 @@
#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
#include <cmath>
+#include <cstddef>
#include <map>
#include <queue>
@@ -60,9 +61,9 @@
#include "ppapi/c/private/ppb_flash_net_connector.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/shared_impl/ppb_device_ref_shared.h"
#include "ppapi/shared_impl/platform_file.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
+#include "ppapi/shared_impl/ppb_device_ref_shared.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserCompletion.h"
@@ -1090,6 +1091,44 @@ void PepperPluginDelegateImpl::TCPServerSocketStopListening(
}
}
+void PepperPluginDelegateImpl::RegisterHostResolver(
+ ppapi::PPB_HostResolver_Shared* host_resolver,
+ uint32 host_resolver_id) {
+ host_resolvers_.AddWithID(host_resolver, host_resolver_id);
+}
+
+void PepperPluginDelegateImpl::HostResolverResolve(
+ uint32 host_resolver_id,
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) {
+ DCHECK(host_resolvers_.Lookup(host_resolver_id));
+ if (!hint) {
+ PP_HostResolver_Private_Hint empty_hint;
+ empty_hint.family = PP_NETADDRESSFAMILY_UNSPECIFIED;
+ empty_hint.flags = static_cast<PP_HostResolver_Private_Flags>(0);
+ render_view_->Send(
+ new PpapiHostMsg_PPBHostResolver_Resolve(
+ GetRoutingID(),
+ 0,
+ host_resolver_id,
+ host_port,
+ empty_hint));
+ } else {
+ render_view_->Send(
+ new PpapiHostMsg_PPBHostResolver_Resolve(
+ GetRoutingID(),
+ 0,
+ host_resolver_id,
+ host_port,
+ *hint));
+ }
+}
+
+void PepperPluginDelegateImpl::UnregisterHostResolver(
+ uint32 host_resolver_id) {
+ host_resolvers_.Remove(host_resolver_id);
+}
+
bool PepperPluginDelegateImpl::AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) {
#if defined(ENABLE_P2P_APIS)
@@ -1371,6 +1410,8 @@ bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) {
OnTCPServerSocketListenACK)
IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_AcceptACK,
OnTCPServerSocketAcceptACK)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBHostResolver_ResolveACK,
+ OnHostResolverResolveACK)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -1498,6 +1539,21 @@ void PepperPluginDelegateImpl::OnTCPServerSocketAcceptACK(
}
}
+void PepperPluginDelegateImpl::OnHostResolverResolveACK(
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ bool succeeded,
+ const std::string& canonical_name,
+ const ppapi::NetAddressList& net_address_list) {
+ ppapi::PPB_HostResolver_Shared* host_resolver =
+ host_resolvers_.Lookup(host_resolver_id);
+ if (host_resolver) {
+ host_resolver->OnResolveCompleted(succeeded,
+ canonical_name,
+ net_address_list);
+ }
+}
+
int PepperPluginDelegateImpl::GetRoutingID() const {
return render_view_->routing_id();
}
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h
index f5519b4..932dbe4 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h
@@ -20,6 +20,7 @@
#include "content/public/renderer/render_view_observer.h"
#include "content/renderer/mouse_lock_dispatcher.h"
#include "content/renderer/pepper/pepper_parent_context_provider.h"
+#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
#include "ppapi/shared_impl/private/tcp_socket_private_impl.h"
#include "ppapi/shared_impl/private/udp_socket_private_impl.h"
#include "ui/base/ime/text_input_type.h"
@@ -301,6 +302,15 @@ class PepperPluginDelegateImpl
virtual void TCPServerSocketStopListening(uint32 real_socket_id,
uint32 temp_socket_id) OVERRIDE;
+ virtual void RegisterHostResolver(
+ ppapi::PPB_HostResolver_Shared* host_resolver,
+ uint32 host_resolver_id) OVERRIDE;
+ virtual void HostResolverResolve(
+ uint32 host_resolver_id,
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) OVERRIDE;
+ virtual void UnregisterHostResolver(uint32 host_resolver_id) OVERRIDE;
+
virtual bool AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) OVERRIDE;
virtual void RemoveNetworkListObserver(
@@ -393,6 +403,11 @@ class PepperPluginDelegateImpl
uint32 accepted_socket_id,
const PP_NetAddress_Private& local_addr,
const PP_NetAddress_Private& remote_addr);
+ void OnHostResolverResolveACK(uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ bool succeeded,
+ const std::string& canonical_name,
+ const ppapi::NetAddressList& net_address_list);
CONTENT_EXPORT int GetRoutingID() const;
@@ -450,6 +465,8 @@ class PepperPluginDelegateImpl
IDMap<webkit::ppapi::PPB_TCPServerSocket_Private_Impl>
uninitialized_tcp_server_sockets_;
+ IDMap<ppapi::PPB_HostResolver_Shared> host_resolvers_;
+
IDMap<scoped_refptr<webkit::ppapi::PPB_Flash_Menu_Impl>,
IDMapOwnPointer> pending_context_menus_;
diff --git a/ppapi/api/private/ppb_host_resolver_private.idl b/ppapi/api/private/ppb_host_resolver_private.idl
new file mode 100644
index 0000000..4db93bf
--- /dev/null
+++ b/ppapi/api/private/ppb_host_resolver_private.idl
@@ -0,0 +1,79 @@
+/* Copyright (c) 2012 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_Private</code> interface.
+ */
+
+label Chrome {
+ M19 = 0.1
+};
+
+/**
+ * The <code>PP_HostResolver_Flags</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_Private_Flags {
+ /**
+ * AI_CANONNAME
+ */
+ PP_HOST_RESOLVER_FLAGS_CANONNAME = 1 << 0,
+ /**
+ * Hint to the resolver that only loopback addresses are configured.
+ */
+ PP_HOST_RESOLVER_FLAGS_LOOPBACK_ONLY = 1 << 1
+};
+
+[assert_size(8)]
+struct PP_HostResolver_Private_Hint {
+ PP_NetAddressFamily_Private family;
+ int32_t flags;
+};
+
+interface PPB_HostResolver_Private {
+ /**
+ * 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 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_Private_Hint hint,
+ [in] PP_CompletionCallback callback);
+
+ /**
+ * Returns canonical name of host.
+ */
+ PP_Var GetCanonicalName([in] PP_Resource host_resolver);
+
+ /**
+ * Returns number of network addresses obtained after Resolve call.
+ */
+ uint32_t GetSize([in] PP_Resource host_resolver);
+
+ /**
+ * Stores in the |addr| |index|-th network address. |addr| can't be
+ * NULL. Returns PP_TRUE if success or PP_FALSE if the given
+ * resource is not a Host Resolver or |index| exceeds number of
+ * available addresses.
+ */
+ PP_Bool GetNetAddress([in] PP_Resource host_resolver,
+ [in] uint32_t index,
+ [out] PP_NetAddress_Private addr);
+};
diff --git a/ppapi/c/private/ppb_host_resolver_private.h b/ppapi/c/private/ppb_host_resolver_private.h
new file mode 100644
index 0000000..34346eb
--- /dev/null
+++ b/ppapi/c/private/ppb_host_resolver_private.h
@@ -0,0 +1,118 @@
+/* Copyright (c) 2012 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 private/ppb_host_resolver_private.idl,
+ * modified Mon Mar 5 17:39:57 2012.
+ */
+
+#ifndef PPAPI_C_PRIVATE_PPB_HOST_RESOLVER_PRIVATE_H_
+#define PPAPI_C_PRIVATE_PPB_HOST_RESOLVER_PRIVATE_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"
+#include "ppapi/c/private/ppb_net_address_private.h"
+
+#define PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1 "PPB_HostResolver_Private;0.1"
+#define PPB_HOSTRESOLVER_PRIVATE_INTERFACE \
+ PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1
+
+/**
+ * @file
+ * This file defines the <code>PPB_HostResolver_Private</code> interface.
+ */
+
+
+/**
+ * @addtogroup Enums
+ * @{
+ */
+/**
+ * The <code>PP_HostResolver_Flags</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_HOST_RESOLVER_FLAGS_CANONNAME = 1 << 0,
+ /**
+ * Hint to the resolver that only loopback addresses are configured.
+ */
+ PP_HOST_RESOLVER_FLAGS_LOOPBACK_ONLY = 1 << 1
+} PP_HostResolver_Private_Flags;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_HostResolver_Private_Flags, 4);
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup Structs
+ * @{
+ */
+struct PP_HostResolver_Private_Hint {
+ PP_NetAddressFamily_Private family;
+ int32_t flags;
+};
+PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_HostResolver_Private_Hint, 8);
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup Interfaces
+ * @{
+ */
+struct PPB_HostResolver_Private_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 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_Private_Hint* hint,
+ struct PP_CompletionCallback callback);
+ /**
+ * Returns canonical name of host.
+ */
+ struct PP_Var (*GetCanonicalName)(PP_Resource host_resolver);
+ /**
+ * Returns number of network addresses obtained after Resolve call.
+ */
+ uint32_t (*GetSize)(PP_Resource host_resolver);
+ /**
+ * Stores in the |addr| |index|-th network address. |addr| can't be
+ * NULL. Returns PP_TRUE if success or PP_FALSE if the given
+ * resource is not a Host Resolver or |index| exceeds number of
+ * available addresses.
+ */
+ PP_Bool (*GetNetAddress)(PP_Resource host_resolver,
+ uint32_t index,
+ struct PP_NetAddress_Private* addr);
+};
+
+typedef struct PPB_HostResolver_Private_0_1 PPB_HostResolver_Private;
+/**
+ * @}
+ */
+
+#endif /* PPAPI_C_PRIVATE_PPB_HOST_RESOLVER_PRIVATE_H_ */
+
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 44d245c..855c7e2 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -97,6 +97,8 @@
'proxy/ppb_graphics_2d_proxy.h',
'proxy/ppb_graphics_3d_proxy.cc',
'proxy/ppb_graphics_3d_proxy.h',
+ 'proxy/ppb_host_resolver_private_proxy.cc',
+ 'proxy/ppb_host_resolver_private_proxy.h',
'proxy/ppb_image_data_proxy.cc',
'proxy/ppb_image_data_proxy.h',
'proxy/ppb_instance_proxy.cc',
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index cc018a5..01b9aef 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -133,6 +133,9 @@
'shared_impl/private/ppb_browser_font_trusted_shared.h',
'shared_impl/private/ppb_char_set_shared.cc',
'shared_impl/private/ppb_char_set_shared.h',
+
+ 'shared_impl/private/ppb_host_resolver_shared.cc',
+ 'shared_impl/private/ppb_host_resolver_shared.h',
'shared_impl/private/ppb_tcp_server_socket_shared.cc',
'shared_impl/private/ppb_tcp_server_socket_shared.h',
'shared_impl/private/tcp_socket_private_impl.cc',
@@ -195,6 +198,8 @@
'thunk/ppb_graphics_3d_api.h',
'thunk/ppb_graphics_3d_thunk.cc',
'thunk/ppb_graphics_3d_trusted_thunk.cc',
+ 'thunk/ppb_host_resolver_private_api.h',
+ 'thunk/ppb_host_resolver_private_thunk.cc',
'thunk/ppb_image_data_api.h',
'thunk/ppb_image_data_thunk.cc',
'thunk/ppb_image_data_trusted_thunk.cc',
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index 98cabad..80677d9 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -396,6 +396,8 @@
'tests/test_graphics_2d.h',
'tests/test_graphics_3d.cc',
'tests/test_graphics_3d.h',
+ 'tests/test_host_resolver_private.cc',
+ 'tests/test_host_resolver_private.h',
'tests/test_image_data.cc',
'tests/test_image_data.h',
'tests/test_input_event.cc',
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc
index 036492e..374bbf2 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -87,6 +87,7 @@
#include "ppapi/proxy/ppb_flash_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
+#include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_instance_proxy.h"
#include "ppapi/proxy/ppb_message_loop_proxy.h"
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 2872bd7..f1cd174 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -31,6 +31,8 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_size.h"
#include "ppapi/c/pp_time.h"
+#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/c/private/ppb_net_address_private.h"
#include "ppapi/c/private/ppb_tcp_socket_private.h"
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/ppapi_proxy_export.h"
@@ -41,6 +43,7 @@
#include "ppapi/shared_impl/ppb_input_event_shared.h"
#include "ppapi/shared_impl/ppb_url_request_info_shared.h"
#include "ppapi/shared_impl/ppb_view_shared.h"
+#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT PPAPI_PROXY_EXPORT
@@ -48,11 +51,12 @@
#define IPC_MESSAGE_START PpapiMsgStart
IPC_ENUM_TRAITS(PP_DeviceType_Dev)
-IPC_ENUM_TRAITS(PP_InputEvent_Type)
IPC_ENUM_TRAITS(PP_InputEvent_MouseButton)
+IPC_ENUM_TRAITS(PP_InputEvent_Type)
+IPC_ENUM_TRAITS(PP_NetAddressFamily_Private)
IPC_ENUM_TRAITS(PP_TextInput_Type)
-IPC_ENUM_TRAITS(PP_VideoDecoder_Profile)
IPC_ENUM_TRAITS(PP_VideoDecodeError_Dev)
+IPC_ENUM_TRAITS(PP_VideoDecoder_Profile)
IPC_STRUCT_TRAITS_BEGIN(PP_Point)
IPC_STRUCT_TRAITS_MEMBER(x)
@@ -96,6 +100,11 @@ IPC_STRUCT_TRAITS_BEGIN(PP_VideoCaptureDeviceInfo_Dev)
IPC_STRUCT_TRAITS_MEMBER(frames_per_second)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(PP_HostResolver_Private_Hint)
+ IPC_STRUCT_TRAITS_MEMBER(family)
+ IPC_STRUCT_TRAITS_MEMBER(flags)
+IPC_STRUCT_TRAITS_END()
+
IPC_STRUCT_TRAITS_BEGIN(ppapi::DeviceRefData)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(name)
@@ -145,6 +154,11 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::InputEventData)
IPC_STRUCT_TRAITS_MEMBER(composition_selection_end)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(ppapi::HostPortPair)
+ IPC_STRUCT_TRAITS_MEMBER(host)
+ IPC_STRUCT_TRAITS_MEMBER(port)
+IPC_STRUCT_TRAITS_END()
+
IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data)
IPC_STRUCT_TRAITS_MEMBER(url)
IPC_STRUCT_TRAITS_MEMBER(method)
@@ -317,7 +331,7 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPBTCPSocket_WriteACK,
bool /* succeeded */,
int32_t /* bytes_written */)
-// PPB_UDPSocket_Private
+// PPB_UDPSocket_Private.
IPC_MESSAGE_ROUTED4(PpapiMsg_PPBUDPSocket_BindACK,
uint32 /* plugin_dispatcher_id */,
uint32 /* socket_id */,
@@ -355,6 +369,14 @@ IPC_MESSAGE_ROUTED5(PpapiMsg_PPBTCPServerSocket_AcceptACK,
PP_NetAddress_Private /* local_addr */,
PP_NetAddress_Private /* remote_addr */)
+// PPB_HostResolver_Private.
+IPC_MESSAGE_ROUTED5(PpapiMsg_PPBHostResolver_ResolveACK,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* host_resolver_id */,
+ bool /* succeeded */,
+ std::string /* canonical_name */,
+ ppapi::NetAddressList /* net_address_list */)
+
// PPB_Graphics2D.
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK,
ppapi::HostResource /* graphics_2d */,
@@ -786,6 +808,14 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
ppapi::HostResource /* graphics_3d */)
+// PPB_HostResolver_Private.
+IPC_MESSAGE_CONTROL5(PpapiHostMsg_PPBHostResolver_Resolve,
+ int32 /* routing_id */,
+ uint32 /* plugin_dispatcher_id */,
+ uint32 /* host_resolver_id */,
+ ppapi::HostPortPair /* host_port */,
+ PP_HostResolver_Private_Hint /* hint */)
+
// PPB_ImageData.
IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_Create,
PP_Instance /* instance */,
@@ -1259,4 +1289,3 @@ IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBTCPServerSocket_Destroy,
IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
std::string /* result */)
#endif // !defined(OS_NACL)
-
diff --git a/ppapi/proxy/ppb_host_resolver_private_proxy.cc b/ppapi/proxy/ppb_host_resolver_private_proxy.cc
new file mode 100644
index 0000000..984ef9e
--- /dev/null
+++ b/ppapi/proxy/ppb_host_resolver_private_proxy.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 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/proxy/ppb_host_resolver_private_proxy.h"
+
+#include <cstddef>
+#include <map>
+
+#include "base/logging.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_globals.h"
+#include "ppapi/proxy/plugin_proxy_delegate.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/host_resource.h"
+
+namespace ppapi {
+namespace proxy {
+
+namespace {
+
+typedef std::map<uint32, PPB_HostResolver_Shared*> IDToHostResolverMap;
+IDToHostResolverMap* g_id_to_host_resolver = NULL;
+
+class HostResolver : public PPB_HostResolver_Shared {
+ public:
+ HostResolver(const HostResource& resource,
+ uint32 plugin_dispatcher_id);
+ virtual ~HostResolver();
+
+ virtual void SendResolve(const HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) OVERRIDE;
+
+ private:
+ void SendToBrowser(IPC::Message* msg);
+
+ const uint32 plugin_dispatcher_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostResolver);
+};
+
+HostResolver::HostResolver(const HostResource& resource,
+ uint32 plugin_dispatcher_id)
+ : PPB_HostResolver_Shared(resource),
+ plugin_dispatcher_id_(plugin_dispatcher_id) {
+ if (!g_id_to_host_resolver)
+ g_id_to_host_resolver = new IDToHostResolverMap();
+ DCHECK(g_id_to_host_resolver->find(host_resolver_id_) ==
+ g_id_to_host_resolver->end());
+ (*g_id_to_host_resolver)[host_resolver_id_] = this;
+}
+
+HostResolver::~HostResolver() {
+ g_id_to_host_resolver->erase(host_resolver_id_);
+}
+
+void HostResolver::SendResolve(const HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) {
+ SendToBrowser(new PpapiHostMsg_PPBHostResolver_Resolve(
+ API_ID_PPB_HOSTRESOLVER_PRIVATE,
+ plugin_dispatcher_id_,
+ host_resolver_id_,
+ host_port,
+ *hint));
+}
+
+void HostResolver::SendToBrowser(IPC::Message* msg) {
+ PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(msg);
+}
+
+} // namespace
+
+//------------------------------------------------------------------------------
+
+PPB_HostResolver_Private_Proxy::PPB_HostResolver_Private_Proxy(
+ Dispatcher* dispatcher) : InterfaceProxy(dispatcher) {
+}
+
+PPB_HostResolver_Private_Proxy::~PPB_HostResolver_Private_Proxy() {
+}
+
+// static
+PP_Resource PPB_HostResolver_Private_Proxy::CreateProxyResource(
+ PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+
+ HostResolver* host_resolver =
+ new HostResolver(HostResource::MakeInstanceOnly(instance),
+ dispatcher->plugin_dispatcher_id());
+ return host_resolver->GetReference();
+}
+
+bool PPB_HostResolver_Private_Proxy::OnMessageReceived(
+ const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_HostResolver_Private_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBHostResolver_ResolveACK, OnMsgResolveACK)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_HostResolver_Private_Proxy::OnMsgResolveACK(
+ uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ bool succeeded,
+ const std::string& canonical_name,
+ const ppapi::NetAddressList& net_address_list) {
+ if (!g_id_to_host_resolver) {
+ NOTREACHED();
+ return;
+ }
+ IDToHostResolverMap::iterator it =
+ g_id_to_host_resolver->find(host_resolver_id);
+ if (it == g_id_to_host_resolver->end())
+ return;
+ it->second->OnResolveCompleted(succeeded, canonical_name, net_address_list);
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/ppb_host_resolver_private_proxy.h b/ppapi/proxy/ppb_host_resolver_private_proxy.h
new file mode 100644
index 0000000..4282d3d
--- /dev/null
+++ b/ppapi/proxy/ppb_host_resolver_private_proxy.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 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_PROXY_PPB_HOST_RESOLVER_PRIVATE_PROXY_H_
+#define PPAPI_PROXY_PPB_HOST_RESOLVER_PRIVATE_PROXY_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
+
+namespace ppapi {
+namespace proxy {
+
+class PPB_HostResolver_Private_Proxy : public InterfaceProxy {
+ public:
+ PPB_HostResolver_Private_Proxy(Dispatcher* dispatcher);
+ virtual~PPB_HostResolver_Private_Proxy();
+
+ static PP_Resource CreateProxyResource(PP_Instance instance);
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ static const ApiID kApiID = API_ID_PPB_HOSTRESOLVER_PRIVATE;
+
+ private:
+ // Browser->plugin message handlers.
+ void OnMsgResolveACK(uint32 plugin_dispatcher_id,
+ uint32 host_resolver_id,
+ bool succeeded,
+ const std::string& canonical_name,
+ const ppapi::NetAddressList& net_address_list);
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_HostResolver_Private_Proxy);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_PPB_HOST_RESOLVER_PRIVATE_PROXY_H_
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index 75c41bd..1f3b323 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -23,6 +23,7 @@
#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
+#include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
#include "ppapi/proxy/ppb_udp_socket_private_proxy.h"
@@ -172,6 +173,11 @@ PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
is_always_opaque);
}
+PP_Resource ResourceCreationProxy::CreateHostResolverPrivate(
+ PP_Instance instance) {
+ return PPB_HostResolver_Private_Proxy::CreateProxyResource(instance);
+}
+
PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h
index 8e50896..9e4f6c9 100644
--- a/ppapi/proxy/resource_creation_proxy.h
+++ b/ppapi/proxy/resource_creation_proxy.h
@@ -81,6 +81,7 @@ class ResourceCreationProxy : public InterfaceProxy,
virtual PP_Resource CreateGraphics3DRaw(PP_Instance instance,
PP_Resource share_context,
const int32_t* attrib_list) OVERRIDE;
+ virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
diff --git a/ppapi/shared_impl/api_id.h b/ppapi/shared_impl/api_id.h
index f886aab..60aa90b 100644
--- a/ppapi/shared_impl/api_id.h
+++ b/ppapi/shared_impl/api_id.h
@@ -34,6 +34,7 @@ enum ApiID {
API_ID_PPB_FONT,
API_ID_PPB_GRAPHICS_2D,
API_ID_PPB_GRAPHICS_3D,
+ API_ID_PPB_HOSTRESOLVER_PRIVATE,
API_ID_PPB_IMAGE_DATA,
API_ID_PPB_INSTANCE,
API_ID_PPB_INSTANCE_PRIVATE,
diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc
new file mode 100644
index 0000000..af3db62
--- /dev/null
+++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc
@@ -0,0 +1,118 @@
+// Copyright (c) 2012 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/shared_impl/private/ppb_host_resolver_shared.h"
+
+#include <cstddef>
+#include <cstring>
+
+#include "net/base/sys_addrinfo.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/private/net_address_private_impl.h"
+#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/thunk.h"
+
+namespace ppapi {
+
+NetAddressList* CreateNetAddressListFromAddrInfo(const addrinfo* ai) {
+ scoped_ptr<NetAddressList> net_address_list(new NetAddressList());
+ PP_NetAddress_Private address;
+
+ while (ai != NULL) {
+ if (!NetAddressPrivateImpl::SockaddrToNetAddress(
+ ai->ai_addr, ai->ai_addrlen, &address)) {
+ return NULL;
+ }
+ net_address_list->push_back(address);
+ ai = ai->ai_next;
+ }
+
+ return net_address_list.release();
+}
+
+PPB_HostResolver_Shared::PPB_HostResolver_Shared(PP_Instance instance)
+ : Resource(OBJECT_IS_IMPL, instance),
+ host_resolver_id_(GenerateHostResolverID()) {
+}
+
+PPB_HostResolver_Shared::PPB_HostResolver_Shared(
+ const HostResource& resource)
+ : Resource(OBJECT_IS_PROXY, resource),
+ host_resolver_id_(GenerateHostResolverID()) {
+}
+
+PPB_HostResolver_Shared::~PPB_HostResolver_Shared() {
+}
+
+thunk::PPB_HostResolver_Private_API*
+PPB_HostResolver_Shared::AsPPB_HostResolver_Private_API() {
+ return this;
+}
+
+int32_t PPB_HostResolver_Shared::Resolve(
+ const char* host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint* hint,
+ PP_CompletionCallback callback) {
+ if (!host)
+ return PP_ERROR_BADARGUMENT;
+ if (!callback.func)
+ return PP_ERROR_BLOCKS_MAIN_THREAD;
+ if (ResolveInProgress())
+ return PP_ERROR_INPROGRESS;
+
+ resolve_callback_ = new TrackedCallback(this, callback);
+
+ HostPortPair host_port;
+ host_port.host = host;
+ host_port.port = port;
+
+ SendResolve(host_port, hint);
+ return PP_OK_COMPLETIONPENDING;
+}
+
+PP_Var PPB_HostResolver_Shared::GetCanonicalName() {
+ return StringVar::StringToPPVar(canonical_name_);
+}
+
+uint32_t PPB_HostResolver_Shared::GetSize() {
+ if (ResolveInProgress())
+ return 0;
+ return static_cast<uint32_t>(net_address_list_.size());
+}
+
+bool PPB_HostResolver_Shared::GetNetAddress(uint32 index,
+ PP_NetAddress_Private* address) {
+ if (ResolveInProgress() || index >= GetSize())
+ return false;
+ *address = net_address_list_[index];
+ return true;
+}
+
+void PPB_HostResolver_Shared::OnResolveCompleted(
+ bool succeeded,
+ const std::string& canonical_name,
+ const NetAddressList& net_address_list) {
+ if (succeeded) {
+ canonical_name_ = canonical_name;
+ net_address_list_ = net_address_list;
+ } else {
+ canonical_name_.clear();
+ net_address_list_.clear();
+ }
+
+ TrackedCallback::ClearAndRun(&resolve_callback_,
+ succeeded ? PP_OK : PP_ERROR_FAILED);
+}
+
+uint32 PPB_HostResolver_Shared::GenerateHostResolverID() {
+ static uint32 host_resolver_id = 0;
+ return host_resolver_id++;
+}
+
+bool PPB_HostResolver_Shared::ResolveInProgress() const {
+ return TrackedCallback::IsPending(resolve_callback_);
+}
+
+} // namespace ppapi
diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.h b/ppapi/shared_impl/private/ppb_host_resolver_shared.h
new file mode 100644
index 0000000..a0b080f
--- /dev/null
+++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 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_SHARED_IMPL_PRIVATE_PPB_HOST_RESOLVER_SHARED_H_
+#define PPAPI_SHARED_IMPL_PRIVATE_PPB_HOST_RESOLVER_SHARED_H_
+
+#include <string>
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/tracked_callback.h"
+#include "ppapi/thunk/ppb_host_resolver_private_api.h"
+
+struct addrinfo;
+
+namespace ppapi {
+
+struct HostPortPair {
+ std::string host;
+ uint16_t port;
+};
+
+typedef std::vector<PP_NetAddress_Private> NetAddressList;
+
+PPAPI_SHARED_EXPORT NetAddressList*
+ CreateNetAddressListFromAddrInfo(const addrinfo* ai);
+
+class PPAPI_SHARED_EXPORT PPB_HostResolver_Shared
+ : public thunk::PPB_HostResolver_Private_API,
+ public Resource {
+ public:
+ // C-tor used in Impl case.
+ explicit PPB_HostResolver_Shared(PP_Instance instance);
+
+ // C-tor used in Proxy case.
+ explicit PPB_HostResolver_Shared(const HostResource& resource);
+
+ virtual ~PPB_HostResolver_Shared();
+
+ // Resource overrides.
+ virtual PPB_HostResolver_Private_API*
+ AsPPB_HostResolver_Private_API() OVERRIDE;
+
+ // PPB_HostResolver_Private_API implementation.
+ virtual int32_t Resolve(const char* host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint* hint,
+ PP_CompletionCallback callback) OVERRIDE;
+ virtual PP_Var GetCanonicalName() OVERRIDE;
+ virtual uint32_t GetSize() OVERRIDE;
+ virtual bool GetNetAddress(uint32_t index,
+ PP_NetAddress_Private* address) OVERRIDE;
+
+ void OnResolveCompleted(bool succeeded,
+ const std::string& canonical_name,
+ const NetAddressList& net_address_list);
+
+ // Send functions that need to be implemented differently for the
+ // proxied and non-proxied derived classes.
+ virtual void SendResolve(const HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) = 0;
+
+ protected:
+ static uint32 GenerateHostResolverID();
+ bool ResolveInProgress() const;
+
+ const uint32 host_resolver_id_;
+
+ scoped_refptr<TrackedCallback> resolve_callback_;
+
+ std::string canonical_name_;
+ NetAddressList net_address_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_HostResolver_Shared);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_PRIVATE_PPB_HOST_RESOLVER_SHARED_H_
diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h
index 6a1cda9..45b6fbf 100644
--- a/ppapi/shared_impl/resource.h
+++ b/ppapi/shared_impl/resource.h
@@ -40,6 +40,7 @@
F(PPB_Flash_NetConnector_API) \
F(PPB_Graphics2D_API) \
F(PPB_Graphics3D_API) \
+ F(PPB_HostResolver_Private_API) \
F(PPB_ImageData_API) \
F(PPB_InputEvent_API) \
F(PPB_LayerCompositor_API) \
diff --git a/ppapi/tests/test_host_resolver_private.cc b/ppapi/tests/test_host_resolver_private.cc
new file mode 100644
index 0000000..efba09e
--- /dev/null
+++ b/ppapi/tests/test_host_resolver_private.cc
@@ -0,0 +1,238 @@
+// Copyright (c) 2012 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/tests/test_host_resolver_private.h"
+
+#include "ppapi/c/private/ppb_net_address_private.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/pass_ref.h"
+#include "ppapi/cpp/private/tcp_socket_private.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(HostResolverPrivate);
+
+TestHostResolverPrivate::TestHostResolverPrivate(TestingInstance* instance)
+ : TestCase(instance) {
+}
+
+bool TestHostResolverPrivate::Init() {
+ core_interface_ = static_cast<const PPB_Core*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE));
+ if (!core_interface_)
+ instance_->AppendError("PPB_Core interface not available");
+ host_resolver_private_interface_ =
+ static_cast<const PPB_HostResolver_Private*>(
+ pp::Module::Get()->GetBrowserInterface(
+ PPB_HOSTRESOLVER_PRIVATE_INTERFACE));
+ bool tcp_socket_private_is_available = pp::TCPSocketPrivate::IsAvailable();
+ if (!tcp_socket_private_is_available)
+ instance_->AppendError("PPB_TCPSocket_Private interface not available");
+ if (!host_resolver_private_interface_)
+ instance_->AppendError("PPB_HostResolver_Private interface not available");
+
+ bool init_host_port = GetLocalHostPort(
+ instance_->pp_instance(), &host_, &port_);
+ if (!init_host_port)
+ instance_->AppendError("Can't init host and port");
+
+ return core_interface_ &&
+ host_resolver_private_interface_ &&
+ tcp_socket_private_is_available &&
+ init_host_port &&
+ CheckTestingInterface() &&
+ EnsureRunningOverHTTP();
+}
+
+void TestHostResolverPrivate::RunTests(const std::string& filter) {
+ RUN_TEST(Create, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(Resolve, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(ResolveIPv4, filter);
+}
+
+std::string TestHostResolverPrivate::SyncConnect(pp::TCPSocketPrivate* socket,
+ const std::string& host,
+ uint16_t port) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = socket->Connect(host.c_str(), port, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("PPB_TCPSocket_Private::Connect force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, rv);
+ PASS();
+}
+
+std::string TestHostResolverPrivate::SyncConnect(
+ pp::TCPSocketPrivate* socket,
+ const PP_NetAddress_Private& address) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = socket->ConnectWithNetAddress(&address, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("PPB_TCPSocket_Private::Connect force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ ASSERT_EQ(PP_OK, rv);
+ PASS();
+}
+
+std::string TestHostResolverPrivate::SyncRead(pp::TCPSocketPrivate* socket,
+ char* buffer,
+ int32_t num_bytes,
+ int32_t* bytes_read) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = socket->Read(buffer, num_bytes, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("PPB_TCPSocket_Private::Read force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (num_bytes != rv)
+ return ReportError("PPB_TCPSocket_Private::Read", rv);
+ *bytes_read = rv;
+ PASS();
+}
+
+std::string TestHostResolverPrivate::SyncWrite(pp::TCPSocketPrivate* socket,
+ const char* buffer,
+ int32_t num_bytes,
+ int32_t* bytes_written) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = socket->Write(buffer, num_bytes, callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("PPB_TCPSocket_Private::Write force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (num_bytes != rv)
+ return ReportError("PPB_TCPSocket_Private::Write", rv);
+ *bytes_written = rv;
+ PASS();
+}
+
+std::string TestHostResolverPrivate::CheckHTTPResponse(
+ pp::TCPSocketPrivate* socket,
+ const std::string& request,
+ const std::string& response) {
+ int32_t rv = 0;
+ std::string error_message;
+
+ error_message = SyncWrite(socket, request.c_str(), request.size(), &rv);
+ if (!error_message.empty())
+ return error_message;
+
+ std::vector<char> response_buffer(response.size());
+ error_message = SyncRead(socket, &response_buffer[0], response.size(), &rv);
+ if (!error_message.empty())
+ return error_message;
+ std::string actual_response(&response_buffer[0], rv);
+ if (response != actual_response) {
+ return "CheckHTTPResponse failed, expected: " + response +
+ ", actual: " + actual_response;
+ }
+ PASS();
+}
+
+std::string TestHostResolverPrivate::SyncResolve(
+ PP_Resource host_resolver,
+ const std::string& host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint& hint) {
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ int32_t rv = host_resolver_private_interface_->Resolve(
+ host_resolver,
+ host.c_str(),
+ port,
+ &hint,
+ static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("PPB_HostResolver_Private::Resolve force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("PPB_HostResolver_Private::Resolve", rv);
+ PASS();
+}
+
+std::string TestHostResolverPrivate::TestCreate() {
+ PP_Resource host_resolver = host_resolver_private_interface_->Create(0);
+ ASSERT_EQ(0, host_resolver);
+
+ host_resolver =
+ host_resolver_private_interface_->Create(instance_->pp_instance());
+ ASSERT_NE(0, host_resolver);
+ ASSERT_TRUE(host_resolver_private_interface_->IsHostResolver(host_resolver));
+ ASSERT_EQ(0, host_resolver_private_interface_->GetSize(host_resolver));
+
+ PP_NetAddress_Private address;
+ ASSERT_FALSE(host_resolver_private_interface_->GetNetAddress(host_resolver,
+ 0,
+ &address));
+ core_interface_->ReleaseResource(host_resolver);
+ PASS();
+}
+
+std::string TestHostResolverPrivate::ParametrizedTestResolve(
+ const PP_HostResolver_Private_Hint &hint) {
+ PP_Resource host_resolver =
+ host_resolver_private_interface_->Create(instance_->pp_instance());
+ ASSERT_NE(0, host_resolver);
+ ASSERT_TRUE(host_resolver_private_interface_->IsHostResolver(host_resolver));
+
+ std::string error_message = SyncResolve(host_resolver, host_, port_, hint);
+ if (!error_message.empty())
+ return error_message;
+
+ const size_t size = host_resolver_private_interface_->GetSize(host_resolver);
+ ASSERT_TRUE(size >= 1);
+
+ PP_NetAddress_Private address;
+ for (size_t i = 0; i < size; ++i) {
+ ASSERT_TRUE(host_resolver_private_interface_->GetNetAddress(host_resolver,
+ i,
+ &address));
+ pp::TCPSocketPrivate socket(instance_);
+ error_message = SyncConnect(&socket, address);
+ error_message =
+ CheckHTTPResponse(&socket, "GET / HTTP/1.0\r\n\r\n", "HTTP/1.0");
+ if (!error_message.empty())
+ return error_message;
+ socket.Disconnect();
+ }
+
+ ASSERT_FALSE(host_resolver_private_interface_->GetNetAddress(host_resolver,
+ size,
+ &address));
+ PP_Var pp_var =
+ host_resolver_private_interface_->GetCanonicalName(host_resolver);
+ pp::Var canonical_name(pp::PassRef(), pp_var);
+ ASSERT_TRUE(canonical_name.is_string());
+ pp::TCPSocketPrivate socket(instance_);
+ error_message = SyncConnect(&socket,
+ canonical_name.AsString().c_str(),
+ port_);
+ if (!error_message.empty())
+ return error_message;
+ error_message = CheckHTTPResponse(&socket,
+ "GET / HTTP/1.0\r\n\r\n", "HTTP");
+ if (!error_message.empty())
+ return error_message;
+ socket.Disconnect();
+
+ core_interface_->ReleaseResource(host_resolver);
+ PASS();
+}
+
+std::string TestHostResolverPrivate::TestResolve() {
+ PP_HostResolver_Private_Hint hint;
+ hint.family = PP_NETADDRESSFAMILY_UNSPECIFIED;
+ hint.flags = PP_HOST_RESOLVER_FLAGS_CANONNAME;
+ return ParametrizedTestResolve(hint);
+}
+
+std::string TestHostResolverPrivate::TestResolveIPv4() {
+ PP_HostResolver_Private_Hint hint;
+ hint.family = PP_NETADDRESSFAMILY_IPV4;
+ hint.flags = PP_HOST_RESOLVER_FLAGS_CANONNAME;
+ return ParametrizedTestResolve(hint);
+}
diff --git a/ppapi/tests/test_host_resolver_private.h b/ppapi/tests/test_host_resolver_private.h
new file mode 100644
index 0000000..23f3acf
--- /dev/null
+++ b/ppapi/tests/test_host_resolver_private.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2012 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_TESTS_TEST_HOST_RESOLVER_PRIVATE_H_
+#define PPAPI_TESTS_TEST_HOST_RESOLVER_PRIVATE_H_
+
+#include <string>
+
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/tests/test_case.h"
+
+namespace pp {
+
+class TCPSocketPrivate;
+
+} // namespace pp
+
+class TestHostResolverPrivate : public TestCase {
+ public:
+ explicit TestHostResolverPrivate(TestingInstance* instance);
+
+ // TestCase implementation.
+ virtual bool Init();
+ virtual void RunTests(const std::string& filter);
+
+ private:
+ std::string SyncConnect(pp::TCPSocketPrivate* socket,
+ const std::string& host,
+ uint16_t port);
+ std::string SyncConnect(pp::TCPSocketPrivate* socket,
+ const PP_NetAddress_Private& address);
+ std::string SyncRead(pp::TCPSocketPrivate* socket,
+ char* buffer,
+ int32_t num_bytes,
+ int32_t* bytes_read);
+ std::string SyncWrite(pp::TCPSocketPrivate* socket,
+ const char* buffer,
+ int32_t num_bytes,
+ int32_t* bytes_written);
+ std::string CheckHTTPResponse(pp::TCPSocketPrivate* socket,
+ const std::string& request,
+ const std::string& response);
+ std::string SyncResolve(PP_Resource host_resolver,
+ const std::string& host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint& hint);
+ std::string ParametrizedTestResolve(const PP_HostResolver_Private_Hint& hint);
+
+ std::string TestCreate();
+ std::string TestResolve();
+ std::string TestResolveIPv4();
+
+ const PPB_Core* core_interface_;
+ const PPB_HostResolver_Private* host_resolver_private_interface_;
+
+ std::string host_;
+ uint16_t port_;
+};
+
+#endif // PPAPI_TESTS_TEST_HOST_RESOLVER_PRIVATE_H_
diff --git a/ppapi/thunk/interfaces_ppb_private.h b/ppapi/thunk/interfaces_ppb_private.h
index 9adaa45..df93202 100644
--- a/ppapi/thunk/interfaces_ppb_private.h
+++ b/ppapi/thunk/interfaces_ppb_private.h
@@ -8,6 +8,7 @@
#include "ppapi/thunk/interfaces_preamble.h"
PROXIED_API(PPB_Broker)
+PROXIED_API(PPB_HostResolver_Private)
PROXIED_API(PPB_TCPSocket_Private)
PROXIED_API(PPB_UDPSocket_Private)
@@ -22,6 +23,8 @@ PROXIED_IFACE(PPB_FileRef, PPB_FILEREFPRIVATE_INTERFACE_0_1,
// This uses the FileIO API which is declared in the public stable file.
PROXIED_IFACE(PPB_FileIO, PPB_FILEIOTRUSTED_INTERFACE_0_4,
PPB_FileIOTrusted_0_4)
+PROXIED_IFACE(PPB_HostResolver_Private, PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1,
+ PPB_HostResolver_Private_0_1)
PROXIED_IFACE(PPB_Instance, PPB_FLASHFULLSCREEN_INTERFACE_0_1,
PPB_FlashFullscreen_0_1)
PROXIED_IFACE(NoAPIName, PPB_NETADDRESS_PRIVATE_INTERFACE_0_1,
diff --git a/ppapi/thunk/ppb_host_resolver_private_api.h b/ppapi/thunk/ppb_host_resolver_private_api.h
new file mode 100644
index 0000000..367e0c3
--- /dev/null
+++ b/ppapi/thunk/ppb_host_resolver_private_api.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2012 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_THUNK_PPB_HOST_RESOLVER_PRIVATE_API_H_
+#define PPAPI_THUNK_PPB_HOST_RESOLVER_PRIVATE_API_H_
+
+#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/thunk/ppapi_thunk_export.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPAPI_THUNK_EXPORT PPB_HostResolver_Private_API {
+ public:
+ virtual ~PPB_HostResolver_Private_API() {}
+
+ virtual int32_t Resolve(const char* host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint* hint,
+ PP_CompletionCallback callback) = 0;
+ virtual PP_Var GetCanonicalName() = 0;
+ virtual uint32_t GetSize() = 0;
+ virtual bool GetNetAddress(uint32_t index,
+ PP_NetAddress_Private* addr) = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_PPB_TCP_SOCKET_PRIVATE_API_H_
diff --git a/ppapi/thunk/ppb_host_resolver_private_thunk.cc b/ppapi/thunk/ppb_host_resolver_private_thunk.cc
new file mode 100644
index 0000000..424cee92
--- /dev/null
+++ b/ppapi/thunk/ppb_host_resolver_private_thunk.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 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/c/pp_var.h"
+#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_host_resolver_private_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+#include "ppapi/thunk/thunk.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+typedef EnterResource<PPB_HostResolver_Private_API> EnterHostResolver;
+
+PP_Resource Create(PP_Instance instance) {
+ EnterFunction<ResourceCreationAPI> enter(instance, true);
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateHostResolverPrivate(instance);
+}
+
+PP_Bool IsHostResolver(PP_Resource resource) {
+ EnterHostResolver enter(resource, false);
+ return PP_FromBool(enter.succeeded());
+}
+
+int32_t Resolve(PP_Resource host_resolver,
+ const char* host,
+ uint16_t port,
+ const PP_HostResolver_Private_Hint* hint,
+ PP_CompletionCallback callback) {
+ EnterHostResolver enter(host_resolver, callback, true);
+ if (enter.failed())
+ return enter.retval();
+ return enter.SetResult(enter.object()->Resolve(host, port, hint, callback));
+}
+
+PP_Var GetCanonicalName(PP_Resource host_resolver) {
+ EnterHostResolver enter(host_resolver, true);
+ if (enter.failed())
+ return PP_MakeUndefined();
+ return enter.object()->GetCanonicalName();
+}
+
+uint32_t GetSize(PP_Resource host_resolver) {
+ EnterHostResolver enter(host_resolver, true);
+ if (enter.failed())
+ return 0;
+ return enter.object()->GetSize();
+}
+
+PP_Bool GetNetAddress(PP_Resource host_resolver,
+ uint32_t index,
+ PP_NetAddress_Private* addr) {
+ EnterHostResolver enter(host_resolver, true);
+ if (enter.failed())
+ return PP_FALSE;
+ return PP_FromBool(enter.object()->GetNetAddress(index, addr));
+}
+
+const PPB_HostResolver_Private g_ppb_host_resolver_thunk = {
+ &Create,
+ &IsHostResolver,
+ &Resolve,
+ &GetCanonicalName,
+ &GetSize,
+ &GetNetAddress
+};
+
+} // namespace
+
+const PPB_HostResolver_Private_0_1* GetPPB_HostResolver_Private_0_1_Thunk() {
+ return &g_ppb_host_resolver_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
index d78f226..a9032bf 100644
--- a/ppapi/thunk/resource_creation_api.h
+++ b/ppapi/thunk/resource_creation_api.h
@@ -84,6 +84,7 @@ class ResourceCreationAPI {
virtual PP_Resource CreateGraphics3DRaw(PP_Instance instance,
PP_Resource share_context,
const int32_t* attrib_list) = 0;
+ virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) = 0;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index 49d48ca..37698b6 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -11,6 +11,7 @@
#include "ppapi/c/private/ppb_flash_message_loop.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
#include "ppapi/c/private/ppb_flash_fullscreen.h"
+#include "ppapi/c/private/ppb_host_resolver_private.h"
#include "ppapi/c/private/ppb_instance_private.h"
#include "ppapi/c/private/ppb_tcp_server_socket_private.h"
#include "ppapi/c/private/ppb_tcp_socket_private.h"
@@ -70,6 +71,8 @@ PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector_0_2*
GetPPB_Flash_NetConnector_0_2_Thunk();
PPAPI_THUNK_EXPORT const PPB_Graphics3DTrusted_1_0*
GetPPB_Graphics3DTrusted_1_0_Thunk();
+PPAPI_THUNK_EXPORT const PPB_HostResolver_Private_0_1*
+ GetPPB_HostResolver_Private_0_1_Thunk();
PPAPI_THUNK_EXPORT const PPB_ImageDataTrusted_0_4*
GetPPB_ImageDataTrusted_0_4_Thunk();
PPAPI_THUNK_EXPORT const PPB_Instance_Private_0_1*
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 9c875b6..b840527 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -291,6 +291,8 @@
'../plugins/ppapi/ppb_graphics_2d_impl.h',
'../plugins/ppapi/ppb_graphics_3d_impl.cc',
'../plugins/ppapi/ppb_graphics_3d_impl.h',
+ '../plugins/ppapi/ppb_host_resolver_private_impl.cc',
+ '../plugins/ppapi/ppb_host_resolver_private_impl.h',
'../plugins/ppapi/ppb_image_data_impl.cc',
'../plugins/ppapi/ppb_image_data_impl.h',
'../plugins/ppapi/ppb_layer_compositor_impl.cc',
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 81a0690..51713ef 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -314,6 +314,20 @@ void MockPluginDelegate::TCPServerSocketStopListening(uint32 real_socket_id,
uint32 temp_socket_id) {
}
+void MockPluginDelegate::RegisterHostResolver(
+ ::ppapi::PPB_HostResolver_Shared* host_resolver,
+ uint32 host_resolver_id) {
+}
+
+void MockPluginDelegate::HostResolverResolve(
+ uint32 host_resolver_id,
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) {
+}
+
+void MockPluginDelegate::UnregisterHostResolver(uint32 host_resolver_id) {
+}
+
bool MockPluginDelegate::AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) {
return false;
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index 95fbafe..38bfa58 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -142,13 +142,19 @@ class MockPluginDelegate : public PluginDelegate {
virtual void TCPServerSocketAccept(uint32 real_socket_id);
virtual void TCPServerSocketStopListening(uint32 real_socket_id,
uint32 temp_socket_id);
-
+ virtual void RegisterHostResolver(
+ ::ppapi::PPB_HostResolver_Shared* host_resolver,
+ uint32 host_resolver_id);
+ virtual void HostResolverResolve(
+ uint32 host_resolver_id,
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint);
+ virtual void UnregisterHostResolver(uint32 host_resolver_id);
// Add/remove a network list observer.
virtual bool AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) OVERRIDE;
virtual void RemoveNetworkListObserver(
webkit_glue::NetworkListObserver* observer) OVERRIDE;
-
virtual int32_t ShowContextMenu(
PluginInstance* instance,
webkit::ppapi::PPB_Flash_Menu_Impl* menu,
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 9de72bc..be8cd16 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -31,6 +31,7 @@
#include "webkit/quota/quota_types.h"
class GURL;
+struct PP_HostResolver_Private_Hint;
struct PP_NetAddress_Private;
class SkBitmap;
class TransportDIB;
@@ -53,7 +54,9 @@ class CommandBuffer;
}
namespace ppapi {
+class PPB_HostResolver_Shared;
struct DeviceRefData;
+struct HostPortPair;
struct Preferences;
}
@@ -483,6 +486,16 @@ class PluginDelegate {
virtual void TCPServerSocketStopListening(uint32 real_socket_id,
uint32 temp_socket_id) = 0;
+ // For PPB_HostResolver_Private.
+ virtual void RegisterHostResolver(
+ ::ppapi::PPB_HostResolver_Shared* host_resolver,
+ uint32 host_resolver_id) = 0;
+ virtual void HostResolverResolve(
+ uint32 host_resolver_id,
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) = 0;
+ virtual void UnregisterHostResolver(uint32 host_resolver_id) = 0;
+
// Add/remove a network list observer.
virtual bool AddNetworkListObserver(
webkit_glue::NetworkListObserver* observer) = 0;
diff --git a/webkit/plugins/ppapi/ppb_host_resolver_private_impl.cc b/webkit/plugins/ppapi/ppb_host_resolver_private_impl.cc
new file mode 100644
index 0000000..9e63d3e
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_host_resolver_private_impl.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2012 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 "webkit/plugins/ppapi/ppb_host_resolver_private_impl.h"
+
+#include "webkit/plugins/ppapi/host_globals.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+
+namespace webkit {
+namespace ppapi {
+
+PPB_HostResolver_Private_Impl::PPB_HostResolver_Private_Impl(
+ PP_Instance instance)
+ : ::ppapi::PPB_HostResolver_Shared(instance) {
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (plugin_delegate)
+ plugin_delegate->RegisterHostResolver(this, host_resolver_id_);
+}
+
+PPB_HostResolver_Private_Impl::~PPB_HostResolver_Private_Impl() {
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (plugin_delegate)
+ plugin_delegate->UnregisterHostResolver(host_resolver_id_);
+}
+
+void PPB_HostResolver_Private_Impl::SendResolve(
+ const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) {
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return;
+ plugin_delegate->HostResolverResolve(host_resolver_id_, host_port, hint);
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_host_resolver_private_impl.h b/webkit/plugins/ppapi/ppb_host_resolver_private_impl.h
new file mode 100644
index 0000000..9d42ca0
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_host_resolver_private_impl.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 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 WEBKIT_PLUGINS_PPAPI_PPB_HOST_RESOLVER_PRIVATE_IMPL_H_
+#define WEBKIT_PLUGINS_PPAPI_PPB_HOST_RESOLVER_PRIVATE_IMPL_H_
+
+#include "base/compiler_specific.h"
+#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
+
+namespace webkit {
+namespace ppapi {
+
+class PPB_HostResolver_Private_Impl : public ::ppapi::PPB_HostResolver_Shared {
+ public:
+ explicit PPB_HostResolver_Private_Impl(PP_Instance instance);
+ virtual ~PPB_HostResolver_Private_Impl();
+
+ virtual void SendResolve(const ::ppapi::HostPortPair& host_port,
+ const PP_HostResolver_Private_Hint* hint) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PPB_HostResolver_Private_Impl);
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_PPB_HOST_RESOLVER_PRIVATE_IMPL_H_
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index 1afc5bf..2002de0 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -25,6 +25,7 @@
#include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
+#include "webkit/plugins/ppapi/ppb_host_resolver_private_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
#include "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h"
#include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
@@ -179,6 +180,11 @@ PP_Resource ResourceCreationImpl::CreateGraphics3DRaw(
return PPB_Graphics3D_Impl::CreateRaw(instance, share_context, attrib_list);
}
+PP_Resource ResourceCreationImpl::CreateHostResolverPrivate(
+ PP_Instance instance) {
+ return (new PPB_HostResolver_Private_Impl(instance))->GetReference();
+}
+
PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h
index 90a860a..81be5b0 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.h
+++ b/webkit/plugins/ppapi/resource_creation_impl.h
@@ -68,6 +68,7 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase,
virtual PP_Resource CreateGraphics3DRaw(PP_Instance instance,
PP_Resource share_context,
const int32_t* attrib_list) OVERRIDE;
+ virtual PP_Resource CreateHostResolverPrivate(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,