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

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

Issue 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added PPAPI_IN_PROCESS TCP and UDP tests. Created 9 years 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
(Empty)
1 // Copyright (c) 2011 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 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
6
7 #include "base/message_loop.h"
8 #include "base/bind.h"
9 #include "base/task.h"
10 #include "ppapi/c/pp_completion_callback.h"
11 #include "webkit/plugins/ppapi/host_globals.h"
12 #include "webkit/plugins/ppapi/plugin_delegate.h"
13 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
14 #include "webkit/plugins/ppapi/resource_helper.h"
15
16 namespace webkit {
17 namespace ppapi {
18
19 namespace {
20
21 void AbortCallback(PP_CompletionCallback callback) {
22 PP_RunCompletionCallback(&callback, PP_ERROR_ABORTED);
23 }
24
25 } // namespace
26
27 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl(
28 PP_Instance instance, uint32 socket_id)
29 : ::ppapi::TCPSocketImpl(instance, socket_id) {
30 }
31
32 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() {
33 Disconnect();
34 }
35
36 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) {
37 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance);
38 if (!plugin_instance)
39 return 0;
40
41 PluginDelegate* plugin_delegate = plugin_instance->delegate();
42 uint32 socket_id = plugin_delegate->TCPSocketCreate();
43 if (!socket_id)
44 return 0;
45
46 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference();
47 }
48
49 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host,
50 uint16_t port) {
51 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
52 if (!plugin_delegate)
53 return;
54
55 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port);
56 }
57
58 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress(
59 const PP_NetAddress_Private& addr) {
60 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
61 if (!plugin_delegate)
62 return;
63
64 plugin_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr);
65 }
66
67 void PPB_TCPSocket_Private_Impl::SendSSLHandshake(
68 const std::string& server_name,
69 uint16_t server_port) {
70 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
71 if (!plugin_delegate)
72 return;
73
74 plugin_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port);
75 }
76
77 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) {
78 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
79 if (!plugin_delegate)
80 return;
81
82 plugin_delegate->TCPSocketRead(socket_id_, bytes_to_read);
83 }
84
85
86 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) {
87 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
88 if (!plugin_delegate)
89 return;
90
91 plugin_delegate->TCPSocketWrite(socket_id_, buffer);
92 }
93
94 void PPB_TCPSocket_Private_Impl::SendDisconnect() {
95 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
96 if (!plugin_delegate)
97 return;
98
99 plugin_delegate->TCPSocketDisconnect(socket_id_);
100 }
101
102 void PPB_TCPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) {
103 MessageLoop::current()->PostTask(FROM_HERE,
104 base::Bind(&AbortCallback, callback));
105 }
106
107 } // namespace ppapi
108 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698