Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: content/renderer/pepper/ppb_tcp_socket_private_impl.cc

Issue 20777009: A few more cleanups to the pepper code. Dispatch IPCs in the sockets implementations directly by ha… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h" 5 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h"
6 6
7 #include "content/common/pepper_messages.h" 7 #include "content/common/pepper_messages.h"
8 #include "content/renderer/pepper/host_globals.h" 8 #include "content/renderer/pepper/host_globals.h"
9 #include "content/renderer/pepper/pepper_helper_impl.h" 9 #include "content/renderer/pepper/pepper_helper_impl.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
11 #include "content/renderer/pepper/resource_helper.h"
12 #include "content/renderer/render_thread_impl.h" 11 #include "content/renderer/render_thread_impl.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "ppapi/proxy/ppapi_messages.h" 13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/shared_impl/socket_option_data.h" 14 #include "ppapi/shared_impl/socket_option_data.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( 18 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl(
19 PP_Instance instance, uint32 socket_id) 19 PP_Instance instance, uint32 socket_id, RenderView* render_view)
20 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { 20 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id),
21 RenderViewObserver(render_view),
22 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
21 } 23 }
22 24
23 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { 25 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() {
24 Disconnect(); 26 Disconnect();
25 } 27 }
26 28
27 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { 29 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) {
28 PepperHelperImpl* helper = GetHelper(instance); 30 RenderView* render_view =
29 if (!helper) 31 PepperPluginInstance::Get(instance)->GetRenderView();
30 return 0;
31 32
32 uint32 socket_id = 0; 33 uint32 socket_id = 0;
33 helper->Send(new PpapiHostMsg_PPBTCPSocket_CreatePrivate( 34 render_view->Send(new PpapiHostMsg_PPBTCPSocket_CreatePrivate(
34 helper->routing_id(), 0, &socket_id)); 35 render_view->GetRoutingID(), 0, &socket_id));
35 if (!socket_id) 36 if (!socket_id)
36 return 0; 37 return 0;
37 38
38 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); 39 return (new PPB_TCPSocket_Private_Impl(instance, socket_id, render_view))->
40 GetReference();
39 } 41 }
40 42
41 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket( 43 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket(
42 PP_Instance instance, 44 PP_Instance instance,
43 uint32 socket_id, 45 uint32 socket_id,
44 const PP_NetAddress_Private& local_addr, 46 const PP_NetAddress_Private& local_addr,
45 const PP_NetAddress_Private& remote_addr) { 47 const PP_NetAddress_Private& remote_addr) {
46 PepperHelperImpl* helper = GetHelper(instance); 48 RenderView* render_view =
47 if (!helper) 49 PepperPluginInstance::Get(instance)->GetRenderView();
48 return 0; 50 PPB_TCPSocket_Private_Impl* socket = new PPB_TCPSocket_Private_Impl(
49 51 instance, socket_id, render_view);
50 PPB_TCPSocket_Private_Impl* socket =
51 new PPB_TCPSocket_Private_Impl(instance, socket_id);
52 52
53 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED; 53 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED;
54 socket->local_addr_ = local_addr; 54 socket->local_addr_ = local_addr;
55 socket->remote_addr_ = remote_addr; 55 socket->remote_addr_ = remote_addr;
56 56
57 helper->RegisterTCPSocket(socket, socket_id);
58
59 return socket->GetReference(); 57 return socket->GetReference();
60 } 58 }
61 59
62 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, 60 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host,
63 uint16_t port) { 61 uint16_t port) {
64 PepperHelperImpl* helper = GetHelper(pp_instance()); 62 Send(new PpapiHostMsg_PPBTCPSocket_Connect(
65 if (!helper) 63 routing_id_, socket_id_, host, port));
66 return;
67
68 helper->RegisterTCPSocket(this, socket_id_);
69 helper->Send(new PpapiHostMsg_PPBTCPSocket_Connect(
70 helper->routing_id(), socket_id_, host, port));
71 } 64 }
72 65
73 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( 66 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress(
74 const PP_NetAddress_Private& addr) { 67 const PP_NetAddress_Private& addr) {
75 PepperHelperImpl* helper = GetHelper(pp_instance()); 68 Send(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(
76 if (!helper) 69 routing_id_, socket_id_, addr));
77 return;
78
79 helper->RegisterTCPSocket(this, socket_id_);
80 helper->Send(new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(
81 helper->routing_id(), socket_id_, addr));
82 } 70 }
83 71
84 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( 72 void PPB_TCPSocket_Private_Impl::SendSSLHandshake(
85 const std::string& server_name, 73 const std::string& server_name,
86 uint16_t server_port, 74 uint16_t server_port,
87 const std::vector<std::vector<char> >& trusted_certs, 75 const std::vector<std::vector<char> >& trusted_certs,
88 const std::vector<std::vector<char> >& untrusted_certs) { 76 const std::vector<std::vector<char> >& untrusted_certs) {
89 PepperHelperImpl* helper = GetHelper(pp_instance()); 77 Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake(
90 if (!helper)
91 return;
92
93 helper->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake(
94 socket_id_, server_name, server_port, trusted_certs, untrusted_certs)); 78 socket_id_, server_name, server_port, trusted_certs, untrusted_certs));
95 } 79 }
96 80
97 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { 81 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) {
98 PepperHelperImpl* helper = GetHelper(pp_instance()); 82 Send(new PpapiHostMsg_PPBTCPSocket_Read(socket_id_, bytes_to_read));
99 if (!helper)
100 return;
101
102 helper->Send(new PpapiHostMsg_PPBTCPSocket_Read(
103 socket_id_, bytes_to_read));
104 } 83 }
105 84
106 85
107 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { 86 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) {
108 PepperHelperImpl* helper = GetHelper(pp_instance()); 87 Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id_, buffer));
109 if (!helper)
110 return;
111
112 helper->Send(new PpapiHostMsg_PPBTCPSocket_Write(
113 socket_id_, buffer));
114 } 88 }
115 89
116 void PPB_TCPSocket_Private_Impl::SendDisconnect() { 90 void PPB_TCPSocket_Private_Impl::SendDisconnect() {
117 PepperHelperImpl* helper = GetHelper(pp_instance()); 91 Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_));
118 if (!helper)
119 return;
120
121 helper->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id_));
122 } 92 }
123 93
124 void PPB_TCPSocket_Private_Impl::SendSetOption( 94 void PPB_TCPSocket_Private_Impl::SendSetOption(
125 PP_TCPSocket_Option name, 95 PP_TCPSocket_Option name,
126 const ::ppapi::SocketOptionData& value) { 96 const ::ppapi::SocketOptionData& value) {
127 PepperHelperImpl* helper = GetHelper(pp_instance()); 97 Send(new PpapiHostMsg_PPBTCPSocket_SetOption(socket_id_, name, value));
128 if (!helper)
129 return;
130
131 helper->Send(new PpapiHostMsg_PPBTCPSocket_SetOption(
132 socket_id_, name, value));
133 } 98 }
134 99
135 PepperHelperImpl* PPB_TCPSocket_Private_Impl::GetHelper(PP_Instance instance) { 100 bool PPB_TCPSocket_Private_Impl::OnMessageReceived(
136 PepperPluginInstanceImpl* plugin_instance = 101 const IPC::Message& message) {
137 HostGlobals::Get()->GetInstance(instance); 102 bool handled = true;
138 if (!plugin_instance) 103 IPC_BEGIN_MESSAGE_MAP(PPB_TCPSocket_Private_Impl, message)
139 return NULL; 104 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, OnTCPSocketConnectACK)
140 return plugin_instance->helper(); 105 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK,
106 OnTCPSocketSSLHandshakeACK)
107 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK)
108 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK)
109 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SetOptionACK,
110 OnTCPSocketSetOptionACK)
111 IPC_MESSAGE_UNHANDLED(handled = false)
112 IPC_END_MESSAGE_MAP()
113 return handled;
114 }
115
116 void PPB_TCPSocket_Private_Impl::OnTCPSocketConnectACK(
117 uint32 plugin_dispatcher_id,
118 uint32 socket_id,
119 int32_t result,
120 const PP_NetAddress_Private& local_addr,
121 const PP_NetAddress_Private& remote_addr) {
122 OnConnectCompleted(result, local_addr, remote_addr);
123 }
124
125 void PPB_TCPSocket_Private_Impl::OnTCPSocketSSLHandshakeACK(
126 uint32 plugin_dispatcher_id,
127 uint32 socket_id,
128 bool succeeded,
129 const ppapi::PPB_X509Certificate_Fields& certificate_fields) {
130 OnSSLHandshakeCompleted(succeeded, certificate_fields);
131 }
132
133 void PPB_TCPSocket_Private_Impl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id,
134 uint32 socket_id,
135 int32_t result,
136 const std::string& data) {
137 OnReadCompleted(result, data);
138 }
139
140 void PPB_TCPSocket_Private_Impl::OnTCPSocketWriteACK(
141 uint32 plugin_dispatcher_id,
142 uint32 socket_id,
143 int32_t result) {
144 OnWriteCompleted(result);
145 }
146
147 void PPB_TCPSocket_Private_Impl::OnTCPSocketSetOptionACK(
148 uint32 plugin_dispatcher_id,
149 uint32 socket_id,
150 int32_t result) {
151 OnSetOptionCompleted(result);
141 } 152 }
142 153
143 } // namespace content 154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698