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

Side by Side Diff: webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc

Issue 9283022: Exposed Listen and Accept methods to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Sync. Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" 5 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
6 6
7 #include "webkit/plugins/ppapi/host_globals.h" 7 #include "webkit/plugins/ppapi/host_globals.h"
8 #include "webkit/plugins/ppapi/plugin_delegate.h" 8 #include "webkit/plugins/ppapi/plugin_delegate.h"
9 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 9 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
10 #include "webkit/plugins/ppapi/resource_helper.h" 10 #include "webkit/plugins/ppapi/resource_helper.h"
11 11
12 namespace webkit { 12 namespace webkit {
13 namespace ppapi { 13 namespace ppapi {
14 14
15 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( 15 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl(
16 PP_Instance instance, uint32 socket_id) 16 PP_Instance instance, uint32 socket_id)
17 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) { 17 : ::ppapi::TCPSocketPrivateImpl(instance, socket_id) {
18 } 18 }
19 19
20 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { 20 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() {
21 Disconnect(); 21 Disconnect();
22 } 22 }
23 23
24 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { 24 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) {
25 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); 25 PluginDelegate* plugin_delegate = GetPluginDelegate(instance);
26 if (!plugin_instance) 26 if (!plugin_delegate)
27 return 0; 27 return 0;
28 28
29 PluginDelegate* plugin_delegate = plugin_instance->delegate();
30 uint32 socket_id = plugin_delegate->TCPSocketCreate(); 29 uint32 socket_id = plugin_delegate->TCPSocketCreate();
31 if (!socket_id) 30 if (!socket_id)
32 return 0; 31 return 0;
33 32
34 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); 33 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference();
35 } 34 }
36 35
36 PP_Resource PPB_TCPSocket_Private_Impl::CreateConnectedSocket(
37 PP_Instance instance,
38 uint32 socket_id,
39 const PP_NetAddress_Private& local_addr,
40 const PP_NetAddress_Private& remote_addr) {
41 PluginDelegate* plugin_delegate = GetPluginDelegate(instance);
42 if (!plugin_delegate)
43 return 0;
44
45 PPB_TCPSocket_Private_Impl* socket =
46 new PPB_TCPSocket_Private_Impl(instance, socket_id);
47
48 socket->connection_state_ = PPB_TCPSocket_Private_Impl::CONNECTED;
49 socket->local_addr_ = local_addr;
50 socket->remote_addr_ = remote_addr;
51
52 plugin_delegate->RegisterTCPSocket(socket, socket_id);
53
54 return socket->GetReference();
55 }
56
37 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, 57 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host,
38 uint16_t port) { 58 uint16_t port) {
39 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); 59 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
40 if (!plugin_delegate) 60 if (!plugin_delegate)
41 return; 61 return;
42 62
43 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port); 63 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port);
44 } 64 }
45 65
46 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( 66 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 100 }
81 101
82 void PPB_TCPSocket_Private_Impl::SendDisconnect() { 102 void PPB_TCPSocket_Private_Impl::SendDisconnect() {
83 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); 103 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
84 if (!plugin_delegate) 104 if (!plugin_delegate)
85 return; 105 return;
86 106
87 plugin_delegate->TCPSocketDisconnect(socket_id_); 107 plugin_delegate->TCPSocketDisconnect(socket_id_);
88 } 108 }
89 109
110 PluginDelegate* PPB_TCPSocket_Private_Impl::GetPluginDelegate(
111 PP_Instance instance) {
112 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance);
113 if (!plugin_instance)
114 return NULL;
115 return plugin_instance->delegate();
116 }
117
90 } // namespace ppapi 118 } // namespace ppapi
91 } // namespace webkit 119 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h ('k') | webkit/plugins/ppapi/resource_creation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698