Add Pepper API to use UDP
author: mtilburg@adobe.com BUG=none TEST=tested with pepper flash Review URL: http://codereview.chromium.org/8036036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102817 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
AUTHORS
content
ppapi
api
private
c
private
cpp
ppapi_cpp.gypippapi_proxy.gypippapi_shared.gypiproxy
interface_id.hinterface_list.ccppapi_messages.hppb_flash_udp_socket_proxy.ccppb_flash_udp_socket_proxy.hresource_creation_proxy.ccresource_creation_proxy.h
shared_impl
thunk
webkit/plugins/ppapi
4
AUTHORS
4
AUTHORS
@ -125,3 +125,7 @@ Gajendra Singh <wxjg68@motorola.com>
|
||||
Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
Christopher Dale <chrelad@gmail.com>
|
||||
Sanjoy Pal <ncj674@motorola.com>
|
||||
Mike Tilburg <mtilburg@adobe.com>
|
||||
Peter Brophy <pbrophy@adobe.com>
|
||||
Robert Goldberg <goldberg@adobe.com>
|
||||
Don Woodward <woodward@adobe.com>
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "net/socket/client_socket_handle.h"
|
||||
#include "net/socket/ssl_client_socket.h"
|
||||
#include "net/socket/tcp_client_socket.h"
|
||||
#include "net/udp/udp_server_socket.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "ppapi/c/private/ppb_flash_net_connector.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
@ -100,16 +101,28 @@ bool AddressListToNetAddress(const net::AddressList& address_list,
|
||||
SockaddrToNetAddress(head->ai_addr, head->ai_addrlen, net_addr);
|
||||
}
|
||||
|
||||
bool NetAddressToAddressList(const PP_Flash_NetAddress& net_addr,
|
||||
net::AddressList* address_list) {
|
||||
if (!address_list || !ValidateNetAddress(net_addr))
|
||||
bool NetAddressToIPEndPoint(const PP_Flash_NetAddress& net_addr,
|
||||
net::IPEndPoint* ip_end_point) {
|
||||
if (!ip_end_point || !ValidateNetAddress(net_addr))
|
||||
return false;
|
||||
|
||||
net::IPEndPoint ip_end_point;
|
||||
if (!ip_end_point.FromSockAddr(
|
||||
if (!ip_end_point->FromSockAddr(
|
||||
reinterpret_cast<const sockaddr*>(net_addr.data), net_addr.size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NetAddressToAddressList(const PP_Flash_NetAddress& net_addr,
|
||||
net::AddressList* address_list) {
|
||||
if (!address_list)
|
||||
return false;
|
||||
|
||||
net::IPEndPoint ip_end_point;
|
||||
if (!NetAddressToIPEndPoint(net_addr, &ip_end_point))
|
||||
return false;
|
||||
|
||||
*address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(),
|
||||
ip_end_point.port());
|
||||
return true;
|
||||
@ -195,9 +208,62 @@ class PepperMessageFilter::FlashTCPSocket {
|
||||
DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket);
|
||||
};
|
||||
|
||||
// Base class for TCP and UDP socket managers.
|
||||
template<class SocketType>
|
||||
class PepperMessageFilter::FlashSocketManager {
|
||||
public:
|
||||
explicit FlashSocketManager(PepperMessageFilter* pepper_message_filter);
|
||||
|
||||
protected:
|
||||
// |socket_id| will be set to 0 on failure, non-zero otherwise.
|
||||
bool GenerateSocketID(uint32* socket_id);
|
||||
|
||||
uint32 next_socket_id_;
|
||||
PepperMessageFilter* pepper_message_filter_;
|
||||
|
||||
// SocketMap can hold either FlashTCPSocket or FlashUDPSocket.
|
||||
typedef std::map<uint32, linked_ptr<SocketType> > SocketMap;
|
||||
SocketMap sockets_;
|
||||
};
|
||||
|
||||
template<class SocketType>
|
||||
PepperMessageFilter::FlashSocketManager<SocketType>::FlashSocketManager(
|
||||
PepperMessageFilter* pepper_message_filter)
|
||||
: next_socket_id_(1),
|
||||
pepper_message_filter_(pepper_message_filter) {
|
||||
DCHECK(pepper_message_filter);
|
||||
}
|
||||
|
||||
template<class SocketType>
|
||||
bool PepperMessageFilter::FlashSocketManager<SocketType>::GenerateSocketID(
|
||||
uint32* socket_id) {
|
||||
// Generate a socket ID. For each process which sends us socket requests, IDs
|
||||
// of living sockets must be unique, to each socket type. TCP and UDP have
|
||||
// unique managers, so the socket ID can be the same in this case.
|
||||
//
|
||||
// However, it is safe to generate IDs based on the internal state of a single
|
||||
// FlashSocketManager object, because for each plugin or renderer process,
|
||||
// there is at most one PepperMessageFilter talking to it
|
||||
|
||||
if (sockets_.size() >= std::numeric_limits<uint32>::max()) {
|
||||
// All valid IDs are being used.
|
||||
*socket_id = 0;
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
// Although it is unlikely, make sure that we won't cause any trouble when
|
||||
// the counter overflows.
|
||||
*socket_id = next_socket_id_++;
|
||||
} while (*socket_id == 0 ||
|
||||
sockets_.find(*socket_id) != sockets_.end());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// FlashTCPSocketManager manages the mapping from socket IDs to FlashTCPSocket
|
||||
// instances.
|
||||
class PepperMessageFilter::FlashTCPSocketManager {
|
||||
class PepperMessageFilter::FlashTCPSocketManager
|
||||
: public FlashSocketManager<FlashTCPSocket> {
|
||||
public:
|
||||
explicit FlashTCPSocketManager(PepperMessageFilter* pepper_message_filter);
|
||||
|
||||
@ -228,13 +294,6 @@ class PepperMessageFilter::FlashTCPSocketManager {
|
||||
net::CertVerifier* GetCertVerifier();
|
||||
|
||||
private:
|
||||
typedef std::map<uint32, linked_ptr<FlashTCPSocket> > SocketMap;
|
||||
SocketMap sockets_;
|
||||
|
||||
uint32 next_socket_id_;
|
||||
|
||||
PepperMessageFilter* pepper_message_filter_;
|
||||
|
||||
// The default SSL configuration settings are used, as opposed to Chrome's SSL
|
||||
// settings.
|
||||
net::SSLConfig ssl_config_;
|
||||
@ -498,37 +557,184 @@ bool PepperMessageFilter::FlashTCPSocket::IsConnected() const {
|
||||
connection_state_ == SSL_CONNECTED;
|
||||
}
|
||||
|
||||
class PepperMessageFilter::FlashUDPSocket {
|
||||
public:
|
||||
FlashUDPSocket(PepperMessageFilter* pepper_message_filter,
|
||||
int32 routing_id,
|
||||
uint32 plugin_dispatcher_id,
|
||||
uint32 socket_id);
|
||||
~FlashUDPSocket();
|
||||
|
||||
void Bind(const PP_Flash_NetAddress& addr);
|
||||
void RecvFrom(int32_t num_bytes);
|
||||
void SendTo(const std::string& data, const PP_Flash_NetAddress& addr);
|
||||
|
||||
private:
|
||||
void SendBindACK(bool result);
|
||||
void SendRecvFromACKError();
|
||||
void SendSendToACKError();
|
||||
|
||||
void OnRecvFromCompleted(int result);
|
||||
void OnSendToCompleted(int result);
|
||||
|
||||
PepperMessageFilter* pepper_message_filter_;
|
||||
int32 routing_id_;
|
||||
uint32 plugin_dispatcher_id_;
|
||||
uint32 socket_id_;
|
||||
|
||||
net::CompletionCallbackImpl<FlashUDPSocket> recvfrom_callback_;
|
||||
net::CompletionCallbackImpl<FlashUDPSocket> sendto_callback_;
|
||||
|
||||
scoped_ptr<net::UDPServerSocket> socket_;
|
||||
|
||||
scoped_refptr<net::IOBuffer> recvfrom_buffer_;
|
||||
scoped_refptr<net::IOBuffer> sendto_buffer_;
|
||||
|
||||
net::IPEndPoint recvfrom_address_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FlashUDPSocket);
|
||||
};
|
||||
|
||||
PepperMessageFilter::FlashUDPSocket::FlashUDPSocket(
|
||||
PepperMessageFilter* pepper_message_filter,
|
||||
int32 routing_id,
|
||||
uint32 plugin_dispatcher_id,
|
||||
uint32 socket_id)
|
||||
: pepper_message_filter_(pepper_message_filter),
|
||||
routing_id_(routing_id),
|
||||
plugin_dispatcher_id_(plugin_dispatcher_id),
|
||||
socket_id_(socket_id),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
recvfrom_callback_(this, &FlashUDPSocket::OnRecvFromCompleted)),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
sendto_callback_(this, &FlashUDPSocket::OnSendToCompleted)) {
|
||||
DCHECK(pepper_message_filter);
|
||||
}
|
||||
|
||||
PepperMessageFilter::FlashUDPSocket::~FlashUDPSocket() {
|
||||
// Make sure there are no further callbacks from socket_.
|
||||
if (socket_.get())
|
||||
socket_->Close();
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::Bind(
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source()));
|
||||
|
||||
net::IPEndPoint address;
|
||||
if (!socket_.get() || !NetAddressToIPEndPoint(addr, &address)) {
|
||||
SendBindACK(false);
|
||||
return;
|
||||
}
|
||||
|
||||
int result = socket_->Listen(address);
|
||||
|
||||
SendBindACK(result == net::OK);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::RecvFrom(int32_t num_bytes) {
|
||||
if (recvfrom_buffer_.get()) {
|
||||
SendRecvFromACKError();
|
||||
return;
|
||||
}
|
||||
|
||||
recvfrom_buffer_ = new net::IOBuffer(num_bytes);
|
||||
int result = socket_->RecvFrom(recvfrom_buffer_,
|
||||
num_bytes,
|
||||
&recvfrom_address_,
|
||||
&recvfrom_callback_);
|
||||
|
||||
if (result != net::ERR_IO_PENDING)
|
||||
OnRecvFromCompleted(result);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::SendTo(
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
if (sendto_buffer_.get() || data.empty()) {
|
||||
SendSendToACKError();
|
||||
return;
|
||||
}
|
||||
|
||||
net::IPEndPoint address;
|
||||
if (!NetAddressToIPEndPoint(addr, &address)) {
|
||||
SendSendToACKError();
|
||||
return;
|
||||
}
|
||||
|
||||
int data_size = data.size();
|
||||
|
||||
sendto_buffer_ = new net::IOBuffer(data_size);
|
||||
memcpy(sendto_buffer_->data(), data.data(), data_size);
|
||||
int result = socket_->SendTo(sendto_buffer_,
|
||||
data_size,
|
||||
address,
|
||||
&sendto_callback_);
|
||||
|
||||
if (result != net::ERR_IO_PENDING)
|
||||
OnSendToCompleted(result);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::SendRecvFromACKError() {
|
||||
PP_Flash_NetAddress addr = kInvalidNetAddress;
|
||||
pepper_message_filter_->Send(
|
||||
new PpapiMsg_PPBFlashUDPSocket_RecvFromACK(
|
||||
routing_id_, plugin_dispatcher_id_, socket_id_, false,
|
||||
std::string(), addr));
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::SendSendToACKError() {
|
||||
pepper_message_filter_->Send(
|
||||
new PpapiMsg_PPBFlashUDPSocket_SendToACK(
|
||||
routing_id_, plugin_dispatcher_id_, socket_id_, false, 0));
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::SendBindACK(bool result) {
|
||||
pepper_message_filter_->Send(
|
||||
new PpapiMsg_PPBFlashUDPSocket_BindACK(
|
||||
routing_id_, plugin_dispatcher_id_, socket_id_, result));
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::OnRecvFromCompleted(int result) {
|
||||
DCHECK(recvfrom_buffer_.get());
|
||||
|
||||
// Convert IPEndPoint we get back from RecvFrom to a PP_Flash_NetAddress,
|
||||
// to send back to Flash.
|
||||
PP_Flash_NetAddress addr = kInvalidNetAddress;
|
||||
if (!IPEndPointToNetAddress(recvfrom_address_, &addr) || result < 0) {
|
||||
SendRecvFromACKError();
|
||||
} else {
|
||||
pepper_message_filter_->Send(
|
||||
new PpapiMsg_PPBFlashUDPSocket_RecvFromACK(
|
||||
routing_id_, plugin_dispatcher_id_, socket_id_, true,
|
||||
std::string(recvfrom_buffer_->data(), result), addr));
|
||||
}
|
||||
|
||||
recvfrom_buffer_ = NULL;
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocket::OnSendToCompleted(int result) {
|
||||
DCHECK(sendto_buffer_.get());
|
||||
|
||||
pepper_message_filter_->Send(
|
||||
new PpapiMsg_PPBFlashUDPSocket_SendToACK(
|
||||
routing_id_, plugin_dispatcher_id_, socket_id_, true, result));
|
||||
|
||||
sendto_buffer_ = NULL;
|
||||
}
|
||||
|
||||
PepperMessageFilter::FlashTCPSocketManager::FlashTCPSocketManager(
|
||||
PepperMessageFilter* pepper_message_filter)
|
||||
: next_socket_id_(1),
|
||||
pepper_message_filter_(pepper_message_filter) {
|
||||
DCHECK(pepper_message_filter);
|
||||
: FlashSocketManager<FlashTCPSocket>(pepper_message_filter) {
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashTCPSocketManager::OnMsgCreate(
|
||||
int32 routing_id,
|
||||
uint32 plugin_dispatcher_id,
|
||||
uint32* socket_id) {
|
||||
// Generate a socket ID. For each process which sends us socket requests, IDs
|
||||
// of living sockets must be unique.
|
||||
//
|
||||
// However, it is safe to generate IDs based on the internal state of a single
|
||||
// FlashTCPSocketManager object, because for each plugin or renderer process,
|
||||
// there is at most one PepperMessageFilter (in other words, at most one
|
||||
// FlashTCPSocketManager) talking to it.
|
||||
|
||||
DCHECK(socket_id);
|
||||
if (sockets_.size() >= std::numeric_limits<uint32>::max()) {
|
||||
// All valid IDs are being used.
|
||||
*socket_id = 0;
|
||||
if (!GenerateSocketID(socket_id))
|
||||
return;
|
||||
}
|
||||
do {
|
||||
// Although it is unlikely, make sure that we won't cause any trouble when
|
||||
// the counter overflows.
|
||||
*socket_id = next_socket_id_++;
|
||||
} while (*socket_id == 0 ||
|
||||
sockets_.find(*socket_id) != sockets_.end());
|
||||
|
||||
sockets_[*socket_id] = linked_ptr<FlashTCPSocket>(
|
||||
new FlashTCPSocket(this, routing_id, plugin_dispatcher_id, *socket_id));
|
||||
}
|
||||
@ -617,12 +823,105 @@ PepperMessageFilter::FlashTCPSocketManager::GetCertVerifier() {
|
||||
return cert_verifier_.get();
|
||||
}
|
||||
|
||||
// FlashUDPSocketManager manages the mapping from socket IDs to FlashUDPSocket
|
||||
// instances.
|
||||
class PepperMessageFilter::FlashUDPSocketManager
|
||||
: public FlashSocketManager<FlashUDPSocket> {
|
||||
public:
|
||||
explicit FlashUDPSocketManager(PepperMessageFilter* pepper_message_filter);
|
||||
|
||||
void OnMsgCreate(int32 routing_id,
|
||||
uint32 plugin_dispatcher_id,
|
||||
uint32* socket_id);
|
||||
void OnMsgBind(uint32 socket_id,
|
||||
const PP_Flash_NetAddress& addr);
|
||||
void OnMsgRecvFrom(uint32 socket_id,
|
||||
int32_t num_bytes);
|
||||
void OnMsgSendTo(uint32 socket_id,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr);
|
||||
void OnMsgClose(uint32 socket_id);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(FlashUDPSocketManager);
|
||||
};
|
||||
|
||||
PepperMessageFilter::FlashUDPSocketManager::FlashUDPSocketManager(
|
||||
PepperMessageFilter* pepper_message_filter)
|
||||
: FlashSocketManager<FlashUDPSocket>(pepper_message_filter) {
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocketManager::OnMsgCreate(
|
||||
int32 routing_id,
|
||||
uint32 plugin_dispatcher_id,
|
||||
uint32* socket_id) {
|
||||
if (!GenerateSocketID(socket_id))
|
||||
return;
|
||||
|
||||
sockets_[*socket_id] = linked_ptr<FlashUDPSocket>(
|
||||
new FlashUDPSocket(pepper_message_filter_, routing_id,
|
||||
plugin_dispatcher_id, *socket_id));
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocketManager::OnMsgBind(
|
||||
uint32 socket_id,
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
SocketMap::iterator iter = sockets_.find(socket_id);
|
||||
if (iter == sockets_.end()) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
iter->second->Bind(addr);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocketManager::OnMsgRecvFrom(
|
||||
uint32 socket_id,
|
||||
int32_t num_bytes) {
|
||||
SocketMap::iterator iter = sockets_.find(socket_id);
|
||||
if (iter == sockets_.end()) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
iter->second->RecvFrom(num_bytes);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocketManager::OnMsgSendTo(
|
||||
uint32 socket_id,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
SocketMap::iterator iter = sockets_.find(socket_id);
|
||||
if (iter == sockets_.end()) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
iter->second->SendTo(data, addr);
|
||||
}
|
||||
|
||||
void PepperMessageFilter::FlashUDPSocketManager::OnMsgClose(
|
||||
uint32 socket_id) {
|
||||
SocketMap::iterator iter = sockets_.find(socket_id);
|
||||
if (iter == sockets_.end()) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy the FlashUDPSocket instance will cancel any pending completion
|
||||
// callback. From this point on, there won't be any messages associated with
|
||||
// this socket sent to the plugin side.
|
||||
sockets_.erase(iter);
|
||||
}
|
||||
|
||||
PepperMessageFilter::PepperMessageFilter(
|
||||
const content::ResourceContext* resource_context)
|
||||
: resource_context_(resource_context),
|
||||
host_resolver_(NULL),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
socket_manager_(new FlashTCPSocketManager(this))) {
|
||||
socket_manager_tcp_(new FlashTCPSocketManager(this))),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
socket_manager_udp_(new FlashUDPSocketManager(this))) {
|
||||
DCHECK(resource_context_);
|
||||
}
|
||||
|
||||
@ -630,7 +929,9 @@ PepperMessageFilter::PepperMessageFilter(net::HostResolver* host_resolver)
|
||||
: resource_context_(NULL),
|
||||
host_resolver_(host_resolver),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
socket_manager_(new FlashTCPSocketManager(this))) {
|
||||
socket_manager_tcp_(new FlashTCPSocketManager(this))),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(
|
||||
socket_manager_udp_(new FlashUDPSocketManager(this))) {
|
||||
DCHECK(host_resolver);
|
||||
}
|
||||
|
||||
@ -650,27 +951,45 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg,
|
||||
OnGetFontFamilies)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_Create,
|
||||
socket_manager_.get(), FlashTCPSocketManager::OnMsgCreate)
|
||||
socket_manager_tcp_.get(), FlashTCPSocketManager::OnMsgCreate)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_Connect,
|
||||
socket_manager_.get(), FlashTCPSocketManager::OnMsgConnect)
|
||||
socket_manager_tcp_.get(), FlashTCPSocketManager::OnMsgConnect)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_ConnectWithNetAddress,
|
||||
socket_manager_.get(),
|
||||
socket_manager_tcp_.get(),
|
||||
FlashTCPSocketManager::OnMsgConnectWithNetAddress)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_SSLHandshake,
|
||||
socket_manager_.get(),
|
||||
socket_manager_tcp_.get(),
|
||||
FlashTCPSocketManager::OnMsgSSLHandshake)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_Read,
|
||||
socket_manager_.get(), FlashTCPSocketManager::OnMsgRead)
|
||||
socket_manager_tcp_.get(), FlashTCPSocketManager::OnMsgRead)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_Write,
|
||||
socket_manager_.get(), FlashTCPSocketManager::OnMsgWrite)
|
||||
socket_manager_tcp_.get(), FlashTCPSocketManager::OnMsgWrite)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashTCPSocket_Disconnect,
|
||||
socket_manager_.get(), FlashTCPSocketManager::OnMsgDisconnect)
|
||||
socket_manager_tcp_.get(), FlashTCPSocketManager::OnMsgDisconnect)
|
||||
|
||||
// UDP
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashUDPSocket_Create,
|
||||
socket_manager_udp_.get(), FlashUDPSocketManager::OnMsgCreate)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashUDPSocket_Bind,
|
||||
socket_manager_udp_.get(), FlashUDPSocketManager::OnMsgBind)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashUDPSocket_RecvFrom,
|
||||
socket_manager_udp_.get(), FlashUDPSocketManager::OnMsgRecvFrom)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashUDPSocket_SendTo,
|
||||
socket_manager_udp_.get(), FlashUDPSocketManager::OnMsgSendTo)
|
||||
IPC_MESSAGE_FORWARD(
|
||||
PpapiHostMsg_PPBFlashUDPSocket_Close,
|
||||
socket_manager_udp_.get(), FlashUDPSocketManager::OnMsgClose)
|
||||
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP_EX()
|
||||
return handled;
|
||||
|
@ -41,8 +41,11 @@ class PepperMessageFilter : public BrowserMessageFilter {
|
||||
bool* message_was_ok);
|
||||
|
||||
private:
|
||||
template<class SocketType> class FlashSocketManager;
|
||||
class FlashTCPSocket;
|
||||
class FlashTCPSocketManager;
|
||||
class FlashUDPSocket;
|
||||
class FlashUDPSocketManager;
|
||||
|
||||
#if defined(ENABLE_FLAPPER_HACKS)
|
||||
// Message handlers.
|
||||
@ -94,7 +97,8 @@ class PepperMessageFilter : public BrowserMessageFilter {
|
||||
// GetHostResolver instead of accessing directly.
|
||||
net::HostResolver* host_resolver_;
|
||||
|
||||
scoped_ptr<FlashTCPSocketManager> socket_manager_;
|
||||
scoped_ptr<FlashTCPSocketManager> socket_manager_tcp_;
|
||||
scoped_ptr<FlashUDPSocketManager> socket_manager_udp_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperMessageFilter);
|
||||
};
|
||||
|
@ -81,6 +81,12 @@ bool PpapiThread::OnMessageReceived(const IPC::Message& msg) {
|
||||
OnPluginDispatcherMessageReceived(msg))
|
||||
IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBFlashTCPSocket_WriteACK,
|
||||
OnPluginDispatcherMessageReceived(msg))
|
||||
IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBFlashUDPSocket_RecvFromACK,
|
||||
OnPluginDispatcherMessageReceived(msg))
|
||||
IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBFlashUDPSocket_SendToACK,
|
||||
OnPluginDispatcherMessageReceived(msg))
|
||||
IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBFlashUDPSocket_BindACK,
|
||||
OnPluginDispatcherMessageReceived(msg))
|
||||
IPC_MESSAGE_HANDLER(PpapiMsg_SetNetworkState, OnMsgSetNetworkState)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return true;
|
||||
|
59
ppapi/api/private/ppb_flash_udp_socket.idl
Normal file
59
ppapi/api/private/ppb_flash_udp_socket.idl
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright (c) 2011 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_Flash_UDPSocket</code> interface.
|
||||
*/
|
||||
|
||||
label Chrome {
|
||||
M16 = 0.1
|
||||
};
|
||||
|
||||
interface PPB_Flash_UDPSocket {
|
||||
/**
|
||||
* Creates a UDP socket resource.
|
||||
*/
|
||||
PP_Resource Create([in] PP_Instance instance_id);
|
||||
|
||||
/**
|
||||
* Determines if a given resource is a UDP socket.
|
||||
*/
|
||||
PP_Bool IsFlashUDPSocket([in] PP_Resource resource_id);
|
||||
|
||||
/* Creates a socket and binds to the address given by |addr|. */
|
||||
int32_t Bind([in] PP_Resource udp_socket,
|
||||
[in] PP_Flash_NetAddress addr,
|
||||
[in] PP_CompletionCallback callback);
|
||||
|
||||
/* Performs a non-blocking recvfrom call on socket.
|
||||
* Bind must be called first. |callback| is invoked when recvfrom
|
||||
* reads data. You must call GetRecvFromAddress to recover the
|
||||
* address the data was retrieved from.
|
||||
*/
|
||||
int32_t RecvFrom([in] PP_Resource udp_socket,
|
||||
[out] str_t buffer,
|
||||
[in] int32_t num_bytes,
|
||||
[in] PP_CompletionCallback callback);
|
||||
|
||||
/* Upon successful completion of RecvFrom, the address that the data
|
||||
* was received from is stored in |addr|.
|
||||
*/
|
||||
PP_Bool GetRecvFromAddress([in] PP_Resource udp_socket,
|
||||
[out] PP_Flash_NetAddress addr);
|
||||
|
||||
/* Performs a non-blocking sendto call on the socket created and
|
||||
* bound(has already called Bind). The callback |callback| is
|
||||
* invoked when sendto completes.
|
||||
*/
|
||||
int32_t SendTo([in] PP_Resource udp_socket,
|
||||
[in] str_t buffer,
|
||||
[in] int32_t num_bytes,
|
||||
[in] PP_Flash_NetAddress addr,
|
||||
[in] PP_CompletionCallback callback);
|
||||
|
||||
/* Cancels all pending reads and writes, and closes the socket. */
|
||||
void Close([in] PP_Resource udp_socket);
|
||||
};
|
||||
|
76
ppapi/c/private/ppb_flash_udp_socket.h
Normal file
76
ppapi/c/private/ppb_flash_udp_socket.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* Copyright (c) 2011 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 ppb_flash_udp_socket.idl modified Mon Sep 26 09:04:41 2011. */
|
||||
|
||||
#ifndef PPAPI_C_PRIVATE_PPB_FLASH_UDP_SOCKET_H_
|
||||
#define PPAPI_C_PRIVATE_PPB_FLASH_UDP_SOCKET_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/private/ppb_flash_tcp_socket.h"
|
||||
|
||||
#define PPB_FLASH_UDPSOCKET_INTERFACE_0_1 "PPB_Flash_UDPSocket;0.1"
|
||||
#define PPB_FLASH_UDPSOCKET_INTERFACE PPB_FLASH_UDPSOCKET_INTERFACE_0_1
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file defines the <code>PPB_Flash_UDPSocket</code> interface.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup Interfaces
|
||||
* @{
|
||||
*/
|
||||
struct PPB_Flash_UDPSocket {
|
||||
/**
|
||||
* Creates a UDP socket resource.
|
||||
*/
|
||||
PP_Resource (*Create)(PP_Instance instance_id);
|
||||
/**
|
||||
* Determines if a given resource is a UDP socket.
|
||||
*/
|
||||
PP_Bool (*IsFlashUDPSocket)(PP_Resource resource_id);
|
||||
/* Creates a socket and binds to the address given by |addr|. */
|
||||
int32_t (*Bind)(PP_Resource udp_socket,
|
||||
const struct PP_Flash_NetAddress* addr,
|
||||
struct PP_CompletionCallback callback);
|
||||
/* Performs a non-blocking recvfrom call on socket.
|
||||
* Bind must be called first. |callback| is invoked when recvfrom
|
||||
* reads data. You must call GetRecvFromAddress to recover the
|
||||
* address the data was retrieved from.
|
||||
*/
|
||||
int32_t (*RecvFrom)(PP_Resource udp_socket,
|
||||
char* buffer,
|
||||
int32_t num_bytes,
|
||||
struct PP_CompletionCallback callback);
|
||||
/* Upon successful completion of RecvFrom, the address that the data
|
||||
* was received from is stored in |addr|.
|
||||
*/
|
||||
PP_Bool (*GetRecvFromAddress)(PP_Resource udp_socket,
|
||||
struct PP_Flash_NetAddress* addr);
|
||||
/* Performs a non-blocking sendto call on the socket created and
|
||||
* bound(has already called Bind). The callback |callback| is
|
||||
* invoked when sendto completes.
|
||||
*/
|
||||
int32_t (*SendTo)(PP_Resource udp_socket,
|
||||
const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const struct PP_Flash_NetAddress* addr,
|
||||
struct PP_CompletionCallback callback);
|
||||
/* Cancels all pending reads and writes, and closes the socket. */
|
||||
void (*Close)(PP_Resource udp_socket);
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* PPAPI_C_PRIVATE_PPB_FLASH_UDP_SOCKET_H_ */
|
||||
|
72
ppapi/cpp/private/flash_udp_socket.cc
Normal file
72
ppapi/cpp/private/flash_udp_socket.cc
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2011 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/private/flash_udp_socket.h"
|
||||
|
||||
#include "ppapi/c/pp_bool.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/cpp/completion_callback.h"
|
||||
#include "ppapi/cpp/instance.h"
|
||||
#include "ppapi/cpp/module.h"
|
||||
#include "ppapi/cpp/module_impl.h"
|
||||
|
||||
namespace pp {
|
||||
|
||||
namespace {
|
||||
|
||||
template <> const char* interface_name<PPB_Flash_UDPSocket>() {
|
||||
return PPB_FLASH_UDPSOCKET_INTERFACE;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace flash {
|
||||
|
||||
UDPSocket::UDPSocket(Instance* instance) {
|
||||
if (has_interface<PPB_Flash_UDPSocket>() && instance) {
|
||||
PassRefFromConstructor(get_interface<PPB_Flash_UDPSocket>()->Create(
|
||||
instance->pp_instance()));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UDPSocket::Bind(const PP_Flash_NetAddress* addr,
|
||||
const CompletionCallback& callback) {
|
||||
if (!has_interface<PPB_Flash_UDPSocket>())
|
||||
return PP_ERROR_NOINTERFACE;
|
||||
return get_interface<PPB_Flash_UDPSocket>()->Bind(
|
||||
pp_resource(), addr, callback.pp_completion_callback());
|
||||
}
|
||||
|
||||
int32_t UDPSocket::RecvFrom(char* buffer,
|
||||
int32_t num_bytes,
|
||||
const CompletionCallback& callback) {
|
||||
if (!has_interface<PPB_Flash_UDPSocket>())
|
||||
return PP_ERROR_NOINTERFACE;
|
||||
return get_interface<PPB_Flash_UDPSocket>()->RecvFrom(
|
||||
pp_resource(), buffer, num_bytes, callback.pp_completion_callback());
|
||||
}
|
||||
|
||||
bool UDPSocket::GetRecvFromAddress(PP_Flash_NetAddress* addr) {
|
||||
if (!has_interface<PPB_Flash_UDPSocket>())
|
||||
return false;
|
||||
|
||||
PP_Bool result = get_interface<PPB_Flash_UDPSocket>()->GetRecvFromAddress(
|
||||
pp_resource(), addr);
|
||||
return PP_ToBool(result);
|
||||
}
|
||||
|
||||
int32_t UDPSocket::SendTo(const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const struct PP_Flash_NetAddress* addr,
|
||||
const CompletionCallback& callback) {
|
||||
if (!has_interface<PPB_Flash_UDPSocket>())
|
||||
return PP_ERROR_NOINTERFACE;
|
||||
return get_interface<PPB_Flash_UDPSocket>()->SendTo(
|
||||
pp_resource(), buffer, num_bytes, addr,
|
||||
callback.pp_completion_callback());
|
||||
}
|
||||
|
||||
} // namespace flash
|
||||
} // namespace pp
|
||||
|
40
ppapi/cpp/private/flash_udp_socket.h
Normal file
40
ppapi/cpp/private/flash_udp_socket.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2011 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_PRIVATE_FLASH_UDP_SOCKET_H_
|
||||
#define PPAPI_CPP_PRIVATE_FLASH_UDP_SOCKET_H_
|
||||
|
||||
#include "ppapi/c/pp_stdint.h"
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
#include "ppapi/cpp/resource.h"
|
||||
|
||||
namespace pp {
|
||||
|
||||
class CompletionCallback;
|
||||
class Instance;
|
||||
|
||||
namespace flash {
|
||||
|
||||
class UDPSocket : public Resource {
|
||||
public:
|
||||
explicit UDPSocket(Instance* instance);
|
||||
|
||||
int32_t Bind(const PP_Flash_NetAddress* addr,
|
||||
const CompletionCallback& callback);
|
||||
int32_t RecvFrom(char* buffer,
|
||||
int32_t num_bytes,
|
||||
const CompletionCallback& callback);
|
||||
bool GetRecvFromAddress(PP_Flash_NetAddress* addr);
|
||||
int32_t SendTo(const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const PP_Flash_NetAddress* addr,
|
||||
const CompletionCallback& callback);
|
||||
void Close();
|
||||
};
|
||||
|
||||
} // namespace flash
|
||||
} // namespace pp
|
||||
|
||||
#endif // PPAPI_CPP_PRIVATE_FLASH_UDP_SOCKET_H_
|
||||
|
@ -99,6 +99,7 @@
|
||||
'c/private/ppb_flash_menu.h',
|
||||
'c/private/ppb_flash_net_connector.h',
|
||||
'c/private/ppb_flash_tcp_socket.h',
|
||||
'c/private/ppb_flash_udp_socket.h',
|
||||
'c/private/ppb_gpu_blacklist_private.h',
|
||||
'c/private/ppb_instance_private.h',
|
||||
'c/private/ppb_nacl_private.h',
|
||||
|
@ -90,6 +90,8 @@
|
||||
'proxy/ppb_flash_net_connector_proxy.h',
|
||||
'proxy/ppb_flash_tcp_socket_proxy.cc',
|
||||
'proxy/ppb_flash_tcp_socket_proxy.h',
|
||||
'proxy/ppb_flash_udp_socket_proxy.cc',
|
||||
'proxy/ppb_flash_udp_socket_proxy.h',
|
||||
'proxy/ppb_font_proxy.cc',
|
||||
'proxy/ppb_font_proxy.h',
|
||||
'proxy/ppb_graphics_2d_proxy.cc',
|
||||
|
@ -127,6 +127,8 @@
|
||||
'thunk/ppb_flash_net_connector_thunk.cc',
|
||||
'thunk/ppb_flash_tcp_socket_api.h',
|
||||
'thunk/ppb_flash_tcp_socket_thunk.cc',
|
||||
'thunk/ppb_flash_udp_socket_api.h',
|
||||
'thunk/ppb_flash_udp_socket_thunk.cc',
|
||||
'thunk/ppb_font_api.h',
|
||||
'thunk/ppb_font_thunk.cc',
|
||||
'thunk/ppb_fullscreen_thunk.cc',
|
||||
|
@ -32,6 +32,7 @@ enum InterfaceID {
|
||||
INTERFACE_ID_PPB_FLASH_MENU,
|
||||
INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
|
||||
INTERFACE_ID_PPB_FLASH_TCPSOCKET,
|
||||
INTERFACE_ID_PPB_FLASH_UDPSOCKET,
|
||||
INTERFACE_ID_PPB_FONT,
|
||||
INTERFACE_ID_PPB_GRAPHICS_2D,
|
||||
INTERFACE_ID_PPB_GRAPHICS_3D,
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "ppapi/c/private/ppb_flash_menu.h"
|
||||
#include "ppapi/c/private/ppb_flash_net_connector.h"
|
||||
#include "ppapi/c/private/ppb_flash_tcp_socket.h"
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
#include "ppapi/c/private/ppb_pdf.h"
|
||||
#include "ppapi/c/trusted/ppb_broker_trusted.h"
|
||||
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
|
||||
@ -66,6 +67,7 @@
|
||||
#include "ppapi/proxy/ppb_flash_menu_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_udp_socket_proxy.h"
|
||||
#include "ppapi/proxy/ppb_font_proxy.h"
|
||||
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
|
||||
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
|
||||
@ -183,6 +185,7 @@ InterfaceList::InterfaceList() {
|
||||
AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
|
||||
AddPPB(PPB_Flash_Proxy::GetInfo());
|
||||
AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo());
|
||||
AddPPB(PPB_Flash_UDPSocket_Proxy::GetInfo());
|
||||
AddPPB(PPB_Instance_Proxy::GetInfoPrivate());
|
||||
AddPPB(PPB_PDF_Proxy::GetInfo());
|
||||
AddPPB(PPB_Testing_Proxy::GetInfo());
|
||||
|
@ -263,6 +263,23 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPBFlashTCPSocket_WriteACK,
|
||||
bool /* succeeded */,
|
||||
int32_t /* bytes_written */)
|
||||
|
||||
// PPB_Flash_UDPSocket
|
||||
IPC_MESSAGE_ROUTED3(PpapiMsg_PPBFlashUDPSocket_BindACK,
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 /* socket_id */,
|
||||
bool /* succeeded */)
|
||||
IPC_MESSAGE_ROUTED5(PpapiMsg_PPBFlashUDPSocket_RecvFromACK,
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 /* socket_id */,
|
||||
bool /* succeeded */,
|
||||
std::string /* data */,
|
||||
PP_Flash_NetAddress /* remote_addr */)
|
||||
IPC_MESSAGE_ROUTED4(PpapiMsg_PPBFlashUDPSocket_SendToACK,
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 /* socket_id */,
|
||||
bool /* succeeded */,
|
||||
int32_t /* bytes_written */)
|
||||
|
||||
// PPB_Graphics2D.
|
||||
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK,
|
||||
ppapi::HostResource /* graphics_2d */,
|
||||
@ -729,6 +746,24 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashTCPSocket_Write,
|
||||
IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBFlashTCPSocket_Disconnect,
|
||||
uint32 /* socket_id */)
|
||||
|
||||
// PPB_Flash_UDPSocket
|
||||
IPC_SYNC_MESSAGE_CONTROL2_1(PpapiHostMsg_PPBFlashUDPSocket_Create,
|
||||
int32 /* routing_id */,
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 /* socket_id */)
|
||||
IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashUDPSocket_Bind,
|
||||
uint32 /* socket_id */,
|
||||
PP_Flash_NetAddress /* net_addr */)
|
||||
IPC_MESSAGE_CONTROL2(PpapiHostMsg_PPBFlashUDPSocket_RecvFrom,
|
||||
uint32 /* socket_id */,
|
||||
int32_t /* num_bytes */)
|
||||
IPC_MESSAGE_CONTROL3(PpapiHostMsg_PPBFlashUDPSocket_SendTo,
|
||||
uint32 /* socket_id */,
|
||||
std::string /* data */,
|
||||
PP_Flash_NetAddress /* net_addr */)
|
||||
IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBFlashUDPSocket_Close,
|
||||
uint32 /* socket_id */)
|
||||
|
||||
// PPB_Font.
|
||||
IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
|
||||
std::string /* result */)
|
||||
|
390
ppapi/proxy/ppb_flash_udp_socket_proxy.cc
Normal file
390
ppapi/proxy/ppb_flash_udp_socket_proxy.cc
Normal file
@ -0,0 +1,390 @@
|
||||
// Copyright (c) 2011 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_flash_udp_socket_proxy.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "base/task.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/proxy/plugin_dispatcher.h"
|
||||
#include "ppapi/proxy/plugin_resource_tracker.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/shared_impl/resource.h"
|
||||
#include "ppapi/thunk/ppb_flash_udp_socket_api.h"
|
||||
#include "ppapi/thunk/thunk.h"
|
||||
|
||||
using ppapi::thunk::PPB_Flash_UDPSocket_API;
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
|
||||
const int32_t kFlashUDPSocketMaxReadSize = 1024 * 1024;
|
||||
const int32_t kFlashUDPSocketMaxWriteSize = 1024 * 1024;
|
||||
|
||||
namespace {
|
||||
|
||||
class FlashUDPSocket;
|
||||
|
||||
typedef std::map<uint32, FlashUDPSocket*> IDToSocketMap;
|
||||
IDToSocketMap* g_id_to_socket = NULL;
|
||||
|
||||
class AbortCallbackTask : public Task {
|
||||
public:
|
||||
explicit AbortCallbackTask(PP_CompletionCallback callback)
|
||||
: callback_(callback) {}
|
||||
virtual ~AbortCallbackTask() {}
|
||||
virtual void Run() {
|
||||
if (callback_.func)
|
||||
PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
|
||||
}
|
||||
|
||||
private:
|
||||
PP_CompletionCallback callback_;
|
||||
};
|
||||
|
||||
InterfaceProxy* CreateFlashUDPSocketProxy(Dispatcher* dispatcher) {
|
||||
return new PPB_Flash_UDPSocket_Proxy(dispatcher);
|
||||
}
|
||||
|
||||
class FlashUDPSocket : public PPB_Flash_UDPSocket_API,
|
||||
public Resource {
|
||||
public:
|
||||
FlashUDPSocket(const HostResource& resource, uint32 socket_id);
|
||||
virtual ~FlashUDPSocket();
|
||||
|
||||
// ResourceObjectBase overrides.
|
||||
virtual PPB_Flash_UDPSocket_API* AsPPB_Flash_UDPSocket_API() OVERRIDE;
|
||||
|
||||
// PPB_Flash_UDPSocket_API implementation.
|
||||
virtual int32_t Bind(const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) OVERRIDE;
|
||||
virtual int32_t RecvFrom(char* buffer,
|
||||
int32_t num_bytes,
|
||||
PP_CompletionCallback callback) OVERRIDE;
|
||||
virtual PP_Bool GetRecvFromAddress(PP_Flash_NetAddress* addr) OVERRIDE;
|
||||
|
||||
virtual int32_t SendTo(const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) OVERRIDE;
|
||||
virtual void Close() OVERRIDE;
|
||||
|
||||
// Notifications from the proxy.
|
||||
void OnBindCompleted(bool succeeded);
|
||||
void OnRecvFromCompleted(bool succeeded,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr);
|
||||
void OnSendToCompleted(bool succeeded,
|
||||
int32_t bytes_written);
|
||||
|
||||
private:
|
||||
void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback);
|
||||
|
||||
PluginDispatcher* GetDispatcher() const {
|
||||
return PluginDispatcher::GetForResource(this);
|
||||
}
|
||||
|
||||
uint32 socket_id_;
|
||||
|
||||
bool binded_;
|
||||
bool closed_;
|
||||
|
||||
PP_CompletionCallback bind_callback_;
|
||||
PP_CompletionCallback recvfrom_callback_;
|
||||
PP_CompletionCallback sendto_callback_;
|
||||
|
||||
char* read_buffer_;
|
||||
int32_t bytes_to_read_;
|
||||
|
||||
PP_Flash_NetAddress recvfrom_addr_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FlashUDPSocket);
|
||||
};
|
||||
|
||||
FlashUDPSocket::FlashUDPSocket(const HostResource& resource,
|
||||
uint32 socket_id)
|
||||
: Resource(resource),
|
||||
socket_id_(socket_id),
|
||||
binded_(false),
|
||||
closed_(false),
|
||||
bind_callback_(PP_BlockUntilComplete()),
|
||||
recvfrom_callback_(PP_BlockUntilComplete()),
|
||||
sendto_callback_(PP_BlockUntilComplete()),
|
||||
read_buffer_(NULL),
|
||||
bytes_to_read_(-1) {
|
||||
DCHECK(socket_id != 0);
|
||||
|
||||
recvfrom_addr_.size = 0;
|
||||
memset(recvfrom_addr_.data, 0, sizeof(recvfrom_addr_.data));
|
||||
|
||||
if (!g_id_to_socket)
|
||||
g_id_to_socket = new IDToSocketMap();
|
||||
DCHECK(g_id_to_socket->find(socket_id) == g_id_to_socket->end());
|
||||
(*g_id_to_socket)[socket_id] = this;
|
||||
}
|
||||
|
||||
FlashUDPSocket::~FlashUDPSocket() {
|
||||
Close();
|
||||
}
|
||||
|
||||
PPB_Flash_UDPSocket_API* FlashUDPSocket::AsPPB_Flash_UDPSocket_API() {
|
||||
return this;
|
||||
}
|
||||
|
||||
int32_t FlashUDPSocket::Bind(const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) {
|
||||
if (!addr || !callback.func)
|
||||
return PP_ERROR_BADARGUMENT;
|
||||
if (binded_ || closed_)
|
||||
return PP_ERROR_FAILED;
|
||||
if (bind_callback_.func)
|
||||
return PP_ERROR_INPROGRESS;
|
||||
|
||||
bind_callback_ = callback;
|
||||
|
||||
GetDispatcher()->SendToBrowser(
|
||||
new PpapiHostMsg_PPBFlashUDPSocket_Bind(socket_id_, *addr));
|
||||
|
||||
return PP_OK_COMPLETIONPENDING;
|
||||
}
|
||||
|
||||
int32_t FlashUDPSocket::RecvFrom(char* buffer,
|
||||
int32_t num_bytes,
|
||||
PP_CompletionCallback callback) {
|
||||
if (!buffer || num_bytes <= 0 || !callback.func)
|
||||
return PP_ERROR_BADARGUMENT;
|
||||
if (!binded_)
|
||||
return PP_ERROR_FAILED;
|
||||
if (recvfrom_callback_.func)
|
||||
return PP_ERROR_INPROGRESS;
|
||||
|
||||
read_buffer_ = buffer;
|
||||
bytes_to_read_ = std::min(num_bytes, kFlashUDPSocketMaxReadSize);
|
||||
recvfrom_callback_ = callback;
|
||||
|
||||
// Send the request, the browser will call us back via RecvFromACK.
|
||||
GetDispatcher()->SendToBrowser(
|
||||
new PpapiHostMsg_PPBFlashUDPSocket_RecvFrom(
|
||||
socket_id_, num_bytes));
|
||||
return PP_OK_COMPLETIONPENDING;
|
||||
}
|
||||
|
||||
PP_Bool FlashUDPSocket::GetRecvFromAddress(PP_Flash_NetAddress* addr) {
|
||||
if (!addr)
|
||||
return PP_FALSE;
|
||||
|
||||
*addr = recvfrom_addr_;
|
||||
return PP_TRUE;
|
||||
}
|
||||
|
||||
int32_t FlashUDPSocket::SendTo(const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) {
|
||||
if (!buffer || num_bytes <= 0 || !addr || !callback.func)
|
||||
return PP_ERROR_BADARGUMENT;
|
||||
if (!binded_)
|
||||
return PP_ERROR_FAILED;
|
||||
if (sendto_callback_.func)
|
||||
return PP_ERROR_INPROGRESS;
|
||||
|
||||
if (num_bytes > kFlashUDPSocketMaxWriteSize)
|
||||
num_bytes = kFlashUDPSocketMaxWriteSize;
|
||||
|
||||
sendto_callback_ = callback;
|
||||
|
||||
// Send the request, the browser will call us back via SendToACK.
|
||||
GetDispatcher()->SendToBrowser(
|
||||
new PpapiHostMsg_PPBFlashUDPSocket_SendTo(
|
||||
socket_id_, std::string(buffer, num_bytes), *addr));
|
||||
|
||||
return PP_OK_COMPLETIONPENDING;
|
||||
}
|
||||
|
||||
void FlashUDPSocket::Close() {
|
||||
if(closed_)
|
||||
return;
|
||||
|
||||
binded_ = false;
|
||||
closed_ = true;
|
||||
|
||||
// After removed from the mapping, this object won't receive any notfications
|
||||
// from the proxy.
|
||||
DCHECK(g_id_to_socket->find(socket_id_) != g_id_to_socket->end());
|
||||
g_id_to_socket->erase(socket_id_);
|
||||
|
||||
GetDispatcher()->SendToBrowser(
|
||||
new PpapiHostMsg_PPBFlashUDPSocket_Close(socket_id_));
|
||||
socket_id_ = 0;
|
||||
|
||||
PostAbortAndClearIfNecessary(&bind_callback_);
|
||||
PostAbortAndClearIfNecessary(&recvfrom_callback_);
|
||||
PostAbortAndClearIfNecessary(&sendto_callback_);
|
||||
}
|
||||
|
||||
void FlashUDPSocket::OnBindCompleted(bool succeeded) {
|
||||
if (!bind_callback_.func) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
if (succeeded)
|
||||
binded_ = true;
|
||||
|
||||
PP_RunAndClearCompletionCallback(&bind_callback_,
|
||||
succeeded ? PP_OK : PP_ERROR_FAILED);
|
||||
}
|
||||
|
||||
void FlashUDPSocket::OnRecvFromCompleted(bool succeeded,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
if (!recvfrom_callback_.func || !read_buffer_) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
if (succeeded) {
|
||||
CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_);
|
||||
if (!data.empty())
|
||||
memcpy(read_buffer_, data.c_str(), data.size());
|
||||
}
|
||||
read_buffer_ = NULL;
|
||||
bytes_to_read_ = -1;
|
||||
recvfrom_addr_ = addr;
|
||||
|
||||
PP_RunAndClearCompletionCallback(
|
||||
&recvfrom_callback_,
|
||||
succeeded ? static_cast<int32_t>(data.size()) :
|
||||
static_cast<int32_t>(PP_ERROR_FAILED));
|
||||
}
|
||||
|
||||
void FlashUDPSocket::OnSendToCompleted(bool succeeded,
|
||||
int32_t bytes_written) {
|
||||
if (!sendto_callback_.func) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
|
||||
PP_RunAndClearCompletionCallback(
|
||||
&sendto_callback_,
|
||||
succeeded ? bytes_written : static_cast<int32_t>(PP_ERROR_FAILED));
|
||||
}
|
||||
|
||||
void FlashUDPSocket::PostAbortAndClearIfNecessary(
|
||||
PP_CompletionCallback* callback) {
|
||||
DCHECK(callback);
|
||||
|
||||
if (callback->func) {
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
new AbortCallbackTask(*callback));
|
||||
*callback = PP_BlockUntilComplete();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
PPB_Flash_UDPSocket_Proxy::PPB_Flash_UDPSocket_Proxy(Dispatcher* dispatcher)
|
||||
: InterfaceProxy(dispatcher) {
|
||||
}
|
||||
|
||||
PPB_Flash_UDPSocket_Proxy::~PPB_Flash_UDPSocket_Proxy() {
|
||||
}
|
||||
|
||||
// static
|
||||
const InterfaceProxy::Info* PPB_Flash_UDPSocket_Proxy::GetInfo() {
|
||||
static const Info info = {
|
||||
::ppapi::thunk::GetPPB_Flash_UDPSocket_Thunk(),
|
||||
PPB_FLASH_UDPSOCKET_INTERFACE,
|
||||
INTERFACE_ID_PPB_FLASH_UDPSOCKET,
|
||||
false,
|
||||
&CreateFlashUDPSocketProxy,
|
||||
};
|
||||
return &info;
|
||||
}
|
||||
|
||||
// static
|
||||
PP_Resource PPB_Flash_UDPSocket_Proxy::CreateProxyResource(
|
||||
PP_Instance instance) {
|
||||
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
|
||||
if (!dispatcher)
|
||||
return 0;
|
||||
|
||||
uint32 socket_id = 0;
|
||||
dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashUDPSocket_Create(
|
||||
INTERFACE_ID_PPB_FLASH_UDPSOCKET, dispatcher->plugin_dispatcher_id(),
|
||||
&socket_id));
|
||||
if (socket_id == 0)
|
||||
return 0;
|
||||
|
||||
return (new FlashUDPSocket(HostResource::MakeInstanceOnly(instance),
|
||||
socket_id))->GetReference();
|
||||
}
|
||||
|
||||
bool PPB_Flash_UDPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(PPB_Flash_UDPSocket_Proxy, msg)
|
||||
IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashUDPSocket_BindACK,
|
||||
OnMsgBindACK)
|
||||
IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashUDPSocket_RecvFromACK,
|
||||
OnMsgRecvFromACK)
|
||||
IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashUDPSocket_SendToACK,
|
||||
OnMsgSendToACK)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
}
|
||||
|
||||
void PPB_Flash_UDPSocket_Proxy::OnMsgBindACK(
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 socket_id,
|
||||
bool succeeded) {
|
||||
if (!g_id_to_socket) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
|
||||
if (iter == g_id_to_socket->end())
|
||||
return;
|
||||
iter->second->OnBindCompleted(succeeded);
|
||||
}
|
||||
|
||||
void PPB_Flash_UDPSocket_Proxy::OnMsgRecvFromACK(
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 socket_id,
|
||||
bool succeeded,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr) {
|
||||
if (!g_id_to_socket) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
|
||||
if (iter == g_id_to_socket->end())
|
||||
return;
|
||||
iter->second->OnRecvFromCompleted(succeeded, data, addr);
|
||||
}
|
||||
|
||||
void PPB_Flash_UDPSocket_Proxy::OnMsgSendToACK(
|
||||
uint32 /* plugin_dispatcher_id */,
|
||||
uint32 socket_id,
|
||||
bool succeeded,
|
||||
int32_t bytes_written) {
|
||||
if (!g_id_to_socket) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id);
|
||||
if (iter == g_id_to_socket->end())
|
||||
return;
|
||||
iter->second->OnSendToCompleted(succeeded, bytes_written);
|
||||
}
|
||||
|
||||
} // namespace proxy
|
||||
} // namespace ppapi
|
||||
|
60
ppapi/proxy/ppb_flash_udp_socket_proxy.h
Normal file
60
ppapi/proxy/ppb_flash_udp_socket_proxy.h
Normal file
@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2011 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_FLASH_UDP_SOCKET_PROXY_H_
|
||||
#define PPAPI_PROXY_PPB_FLASH_UDP_SOCKET_PROXY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "ppapi/c/pp_instance.h"
|
||||
#include "ppapi/c/pp_resource.h"
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
#include "ppapi/proxy/interface_proxy.h"
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
|
||||
// The maximum number of bytes that each PpapiHostMsg_PPBFlashUDPSocket_RecvFrom
|
||||
// message is allowed to request.
|
||||
extern const int32_t kFlashUDPSocketMaxReadSize;
|
||||
// The maximum number of bytes that each PpapiHostMsg_PPBFlashUDPSocket_SendTo
|
||||
// message is allowed to carry.
|
||||
extern const int32_t kFlashUDPSocketMaxWriteSize;
|
||||
|
||||
class PPB_Flash_UDPSocket_Proxy : public InterfaceProxy {
|
||||
public:
|
||||
PPB_Flash_UDPSocket_Proxy(Dispatcher* dispatcher);
|
||||
virtual ~PPB_Flash_UDPSocket_Proxy();
|
||||
|
||||
static const Info* GetInfo();
|
||||
|
||||
static PP_Resource CreateProxyResource(PP_Instance instance);
|
||||
|
||||
// InterfaceProxy implementation.
|
||||
virtual bool OnMessageReceived(const IPC::Message& msg);
|
||||
|
||||
private:
|
||||
// Browser->plugin message handlers.
|
||||
void OnMsgBindACK(uint32 plugin_dispatcher_id,
|
||||
uint32 socket_id,
|
||||
bool succeeded);
|
||||
void OnMsgRecvFromACK(uint32 plugin_dispatcher_id,
|
||||
uint32 socket_id,
|
||||
bool succeeded,
|
||||
const std::string& data,
|
||||
const PP_Flash_NetAddress& addr);
|
||||
void OnMsgSendToACK(uint32 plugin_dispatcher_id,
|
||||
uint32 socket_id,
|
||||
bool succeeded,
|
||||
int32_t bytes_written);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PPB_Flash_UDPSocket_Proxy);
|
||||
};
|
||||
|
||||
} // namespace proxy
|
||||
} // namespace ppapi
|
||||
|
||||
#endif // PPAPI_PROXY_PPB_FLASH_UDP_SOCKET_PROXY_H_
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ppapi/proxy/ppb_flash_menu_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
|
||||
#include "ppapi/proxy/ppb_flash_udp_socket_proxy.h"
|
||||
#include "ppapi/proxy/ppb_font_proxy.h"
|
||||
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
|
||||
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
|
||||
@ -156,6 +157,11 @@ PP_Resource ResourceCreationProxy::CreateFlashTCPSocket(
|
||||
return PPB_Flash_TCPSocket_Proxy::CreateProxyResource(instance);
|
||||
}
|
||||
|
||||
PP_Resource ResourceCreationProxy::CreateFlashUDPSocket(
|
||||
PP_Instance instance) {
|
||||
return PPB_Flash_UDPSocket_Proxy::CreateProxyResource(instance);
|
||||
}
|
||||
|
||||
PP_Resource ResourceCreationProxy::CreateFontObject(
|
||||
PP_Instance instance,
|
||||
const PP_FontDescription_Dev* description) {
|
||||
|
@ -71,6 +71,7 @@ class ResourceCreationProxy : public InterfaceProxy,
|
||||
const PP_Flash_Menu* menu_data) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashTCPSocket(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashUDPSocket(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFontObject(
|
||||
PP_Instance instance,
|
||||
const PP_FontDescription_Dev* description) OVERRIDE;
|
||||
|
@ -32,6 +32,7 @@
|
||||
F(PPB_Flash_Menu_API) \
|
||||
F(PPB_Flash_NetConnector_API) \
|
||||
F(PPB_Flash_TCPSocket_API) \
|
||||
F(PPB_Flash_UDPSocket_API) \
|
||||
F(PPB_Font_API) \
|
||||
F(PPB_Graphics2D_API) \
|
||||
F(PPB_Graphics3D_API) \
|
||||
|
34
ppapi/thunk/ppb_flash_udp_socket_api.h
Normal file
34
ppapi/thunk/ppb_flash_udp_socket_api.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2011 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_FLASH_UDP_SOCKET_API_H_
|
||||
#define PPAPI_THUNK_PPB_FLASH_UDP_SOCKET_API_H_
|
||||
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
|
||||
namespace ppapi {
|
||||
namespace thunk {
|
||||
|
||||
class PPB_Flash_UDPSocket_API {
|
||||
public:
|
||||
virtual ~PPB_Flash_UDPSocket_API() {}
|
||||
|
||||
virtual int32_t Bind(const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) = 0;
|
||||
virtual int32_t RecvFrom(char* buffer,
|
||||
int32_t num_bytes,
|
||||
PP_CompletionCallback callback) = 0;
|
||||
virtual PP_Bool GetRecvFromAddress(PP_Flash_NetAddress* addr) = 0;
|
||||
virtual int32_t SendTo(const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
||||
} // namespace thunk
|
||||
} // namespace ppapi
|
||||
|
||||
#endif // PPAPI_THUNK_PPB_FLASH_UDP_SOCKET_API_H_
|
||||
|
98
ppapi/thunk/ppb_flash_udp_socket_thunk.cc
Normal file
98
ppapi/thunk/ppb_flash_udp_socket_thunk.cc
Normal file
@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2011 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_completion_callback.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
#include "ppapi/thunk/common.h"
|
||||
#include "ppapi/thunk/enter.h"
|
||||
#include "ppapi/thunk/ppb_flash_udp_socket_api.h"
|
||||
#include "ppapi/thunk/resource_creation_api.h"
|
||||
#include "ppapi/thunk/thunk.h"
|
||||
|
||||
namespace ppapi {
|
||||
namespace thunk {
|
||||
|
||||
namespace {
|
||||
|
||||
PP_Resource Create(PP_Instance instance) {
|
||||
EnterFunction<ResourceCreationAPI> enter(instance, true);
|
||||
if (enter.failed())
|
||||
return 0;
|
||||
return enter.functions()->CreateFlashUDPSocket(instance);
|
||||
}
|
||||
|
||||
PP_Bool IsFlashUDPSocket(PP_Resource resource) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(resource, false);
|
||||
return PP_FromBool(enter.succeeded());
|
||||
}
|
||||
|
||||
int32_t Bind(PP_Resource udp_socket,
|
||||
const PP_Flash_NetAddress *addr,
|
||||
PP_CompletionCallback callback) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
|
||||
if (enter.failed())
|
||||
return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
|
||||
int32_t result = enter.object()->Bind(addr, callback);
|
||||
return MayForceCallback(callback, result);
|
||||
}
|
||||
|
||||
int32_t RecvFrom(PP_Resource udp_socket,
|
||||
char* buffer,
|
||||
int32_t num_bytes,
|
||||
PP_CompletionCallback callback) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
|
||||
if (enter.failed())
|
||||
return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
|
||||
int32_t result = enter.object()->RecvFrom(buffer,
|
||||
num_bytes,
|
||||
callback);
|
||||
return MayForceCallback(callback, result);
|
||||
}
|
||||
|
||||
PP_Bool GetRecvFromAddress(PP_Resource udp_socket,
|
||||
PP_Flash_NetAddress* addr) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
|
||||
if (enter.failed())
|
||||
return PP_FALSE;
|
||||
return enter.object()->GetRecvFromAddress(addr);
|
||||
}
|
||||
|
||||
int32_t SendTo(PP_Resource udp_socket,
|
||||
const char* buffer,
|
||||
int32_t num_bytes,
|
||||
const PP_Flash_NetAddress* addr,
|
||||
PP_CompletionCallback callback) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
|
||||
if (enter.failed())
|
||||
return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
|
||||
int32_t result = enter.object()->SendTo(buffer, num_bytes, addr, callback);
|
||||
return MayForceCallback(callback, result);
|
||||
}
|
||||
|
||||
void Close(PP_Resource udp_socket) {
|
||||
EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
|
||||
if (enter.succeeded())
|
||||
enter.object()->Close();
|
||||
}
|
||||
|
||||
const PPB_Flash_UDPSocket g_ppb_flash_udp_socket_thunk = {
|
||||
&Create,
|
||||
&IsFlashUDPSocket,
|
||||
&Bind,
|
||||
&RecvFrom,
|
||||
&GetRecvFromAddress,
|
||||
&SendTo,
|
||||
&Close
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
const PPB_Flash_UDPSocket* GetPPB_Flash_UDPSocket_Thunk() {
|
||||
return &g_ppb_flash_udp_socket_thunk;
|
||||
}
|
||||
|
||||
} // namespace thunk
|
||||
} // namespace ppapi
|
||||
|
@ -71,6 +71,7 @@ class ResourceCreationAPI {
|
||||
const PP_Flash_Menu* menu_data) = 0;
|
||||
virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0;
|
||||
virtual PP_Resource CreateFlashTCPSocket(PP_Instance instace) = 0;
|
||||
virtual PP_Resource CreateFlashUDPSocket(PP_Instance instace) = 0;
|
||||
// Note: can't be called CreateFont due to Windows #defines.
|
||||
virtual PP_Resource CreateFontObject(
|
||||
PP_Instance instance,
|
||||
|
@ -35,6 +35,7 @@ struct PPB_FileIOTrusted;
|
||||
struct PPB_Flash_Menu;
|
||||
struct PPB_Flash_NetConnector;
|
||||
struct PPB_Flash_TCPSocket;
|
||||
struct PPB_Flash_UDPSocket;
|
||||
struct PPB_Graphics3D;
|
||||
struct PPB_Graphics3DTrusted;
|
||||
struct PPB_ImageDataTrusted;
|
||||
@ -60,6 +61,7 @@ PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk();
|
||||
PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector*
|
||||
GetPPB_Flash_NetConnector_Thunk();
|
||||
PPAPI_THUNK_EXPORT const PPB_Flash_TCPSocket* GetPPB_Flash_TCPSocket_Thunk();
|
||||
PPAPI_THUNK_EXPORT const PPB_Flash_UDPSocket* GetPPB_Flash_UDPSocket_Thunk();
|
||||
PPAPI_THUNK_EXPORT const PPB_Graphics3DTrusted*
|
||||
GetPPB_Graphics3DTrusted_Thunk();
|
||||
PPAPI_THUNK_EXPORT const PPB_ImageDataTrusted* GetPPB_ImageDataTrusted_Thunk();
|
||||
|
@ -66,6 +66,7 @@
|
||||
#include "ppapi/c/private/ppb_flash_file.h"
|
||||
#include "ppapi/c/private/ppb_flash_fullscreen.h"
|
||||
#include "ppapi/c/private/ppb_flash_tcp_socket.h"
|
||||
#include "ppapi/c/private/ppb_flash_udp_socket.h"
|
||||
#include "ppapi/c/private/ppb_gpu_blacklist_private.h"
|
||||
#include "ppapi/c/private/ppb_instance_private.h"
|
||||
#include "ppapi/c/private/ppb_pdf.h"
|
||||
@ -270,6 +271,8 @@ const void* GetInterface(const char* name) {
|
||||
return ::ppapi::thunk::GetPPB_Flash_Menu_Thunk();
|
||||
if (strcmp(name, PPB_FLASH_TCPSOCKET_INTERFACE) == 0)
|
||||
return ::ppapi::thunk::GetPPB_Flash_TCPSocket_Thunk();
|
||||
if (strcmp(name, PPB_FLASH_UDPSOCKET_INTERFACE) == 0)
|
||||
return ::ppapi::thunk::GetPPB_Flash_UDPSocket_Thunk();
|
||||
if (strcmp(name, PPB_GPU_BLACKLIST_INTERFACE) == 0)
|
||||
return PPB_GpuBlacklist_Private_Impl::GetInterface();
|
||||
if (strcmp(name, PPB_GRAPHICS_3D_TRUSTED_INTERFACE) == 0)
|
||||
|
@ -145,6 +145,12 @@ PP_Resource ResourceCreationImpl::CreateFlashTCPSocket(
|
||||
return 0;
|
||||
}
|
||||
|
||||
PP_Resource ResourceCreationImpl::CreateFlashUDPSocket(
|
||||
PP_Instance instance) {
|
||||
// Creating UDP socket resource at the renderer side is not supported.
|
||||
return 0;
|
||||
}
|
||||
|
||||
PP_Resource ResourceCreationImpl::CreateFontObject(
|
||||
PP_Instance instance,
|
||||
const PP_FontDescription_Dev* description) {
|
||||
|
@ -58,6 +58,7 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase,
|
||||
const PP_Flash_Menu* menu_data) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashTCPSocket(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFlashUDPSocket(PP_Instance instance) OVERRIDE;
|
||||
virtual PP_Resource CreateFontObject(
|
||||
PP_Instance instance,
|
||||
const PP_FontDescription_Dev* description) OVERRIDE;
|
||||
|
Reference in New Issue
Block a user