1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_MESSAGE_FILTER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_MESSAGE_FILTER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "base/compiler_specific.h" 13 #include "base/memory/ref_counted.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "content/common/content_export.h" 16 #include "content/public/common/process_type.h" 17 #include "net/base/completion_callback.h" 18 #include "net/base/ip_endpoint.h" 19 #include "ppapi/c/pp_instance.h" 20 #include "ppapi/c/pp_stdint.h" 21 #include "ppapi/c/ppb_udp_socket.h" 22 #include "ppapi/host/resource_message_filter.h" 23 24 struct PP_NetAddress_Private; 25 26 namespace net { 27 class IOBuffer; 28 class IOBufferWithSize; 29 class UDPServerSocket; 30 } 31 32 namespace ppapi { 33 34 class SocketOptionData; 35 36 namespace host { 37 struct ReplyMessageContext; 38 } 39 } 40 41 namespace content { 42 43 class BrowserPpapiHostImpl; 44 struct SocketPermissionRequest; 45 46 class CONTENT_EXPORT PepperUDPSocketMessageFilter 47 : public ppapi::host::ResourceMessageFilter { 48 public: 49 PepperUDPSocketMessageFilter(BrowserPpapiHostImpl* host, 50 PP_Instance instance, 51 bool private_api); 52 53 static size_t GetNumInstances(); 54 55 protected: 56 virtual ~PepperUDPSocketMessageFilter(); 57 58 private: 59 // ppapi::host::ResourceMessageFilter overrides. 60 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( 61 const IPC::Message& message) OVERRIDE; 62 virtual int32_t OnResourceMessageReceived( 63 const IPC::Message& msg, 64 ppapi::host::HostMessageContext* context) OVERRIDE; 65 66 int32_t OnMsgSetOption( 67 const ppapi::host::HostMessageContext* context, 68 PP_UDPSocket_Option name, 69 const ppapi::SocketOptionData& value); 70 int32_t OnMsgBind(const ppapi::host::HostMessageContext* context, 71 const PP_NetAddress_Private& addr); 72 int32_t OnMsgRecvFrom(const ppapi::host::HostMessageContext* context, 73 int32_t num_bytes); 74 int32_t OnMsgSendTo(const ppapi::host::HostMessageContext* context, 75 const std::string& data, 76 const PP_NetAddress_Private& addr); 77 int32_t OnMsgClose(const ppapi::host::HostMessageContext* context); 78 79 void DoBind(const ppapi::host::ReplyMessageContext& context, 80 const PP_NetAddress_Private& addr); 81 void DoSendTo(const ppapi::host::ReplyMessageContext& context, 82 const std::string& data, 83 const PP_NetAddress_Private& addr); 84 void Close(); 85 86 void OnRecvFromCompleted(const ppapi::host::ReplyMessageContext& context, 87 int net_result); 88 void OnSendToCompleted(const ppapi::host::ReplyMessageContext& context, 89 int net_result); 90 91 void SendBindReply(const ppapi::host::ReplyMessageContext& context, 92 int32_t result, 93 const PP_NetAddress_Private& addr); 94 void SendRecvFromReply(const ppapi::host::ReplyMessageContext& context, 95 int32_t result, 96 const std::string& data, 97 const PP_NetAddress_Private& addr); 98 void SendSendToReply(const ppapi::host::ReplyMessageContext& context, 99 int32_t result, 100 int32_t bytes_written); 101 102 void SendBindError(const ppapi::host::ReplyMessageContext& context, 103 int32_t result); 104 void SendRecvFromError(const ppapi::host::ReplyMessageContext& context, 105 int32_t result); 106 void SendSendToError(const ppapi::host::ReplyMessageContext& context, 107 int32_t result); 108 109 bool allow_address_reuse_; 110 bool allow_broadcast_; 111 112 scoped_ptr<net::UDPServerSocket> socket_; 113 bool closed_; 114 115 scoped_refptr<net::IOBuffer> recvfrom_buffer_; 116 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; 117 118 net::IPEndPoint recvfrom_address_; 119 120 bool external_plugin_; 121 bool private_api_; 122 123 int render_process_id_; 124 int render_view_id_; 125 126 DISALLOW_COPY_AND_ASSIGN(PepperUDPSocketMessageFilter); 127 }; 128 129 } // namespace content 130 131 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_UDP_SOCKET_MESSAGE_FILTER_H_ 132