OLD | NEW |
(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/task.h" |
| 9 #include "ppapi/c/pp_completion_callback.h" |
| 10 #include "webkit/plugins/ppapi/host_globals.h" |
| 11 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 13 #include "webkit/plugins/ppapi/resource_helper.h" |
| 14 |
| 15 namespace webkit { |
| 16 namespace ppapi { |
| 17 |
| 18 namespace { |
| 19 |
| 20 class AbortCallbackTask : public Task { |
| 21 public: |
| 22 explicit AbortCallbackTask(PP_CompletionCallback callback) |
| 23 : callback_(callback) {} |
| 24 virtual ~AbortCallbackTask() {} |
| 25 virtual void Run() { |
| 26 if (callback_.func) |
| 27 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); |
| 28 } |
| 29 |
| 30 private: |
| 31 PP_CompletionCallback callback_; |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl( |
| 37 PP_Instance instance, uint32 socket_id) |
| 38 : ::ppapi::TCPSocketImpl(instance, socket_id) { |
| 39 } |
| 40 |
| 41 PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() { |
| 42 Disconnect(); |
| 43 } |
| 44 |
| 45 PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) { |
| 46 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); |
| 47 if (!plugin_instance) |
| 48 return 0; |
| 49 |
| 50 PluginDelegate* plugin_delegate = plugin_instance->delegate(); |
| 51 uint32 socket_id = plugin_delegate->TCPSocketCreate(); |
| 52 if (!socket_id) |
| 53 return 0; |
| 54 |
| 55 return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference(); |
| 56 } |
| 57 |
| 58 void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host, |
| 59 uint16_t port) { |
| 60 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 61 if (!plugin_delegate) |
| 62 return; |
| 63 |
| 64 plugin_delegate->TCPSocketConnect(this, socket_id_, host, port); |
| 65 } |
| 66 |
| 67 void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress( |
| 68 const PP_NetAddress_Private& addr) { |
| 69 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 70 if (!plugin_delegate) |
| 71 return; |
| 72 |
| 73 plugin_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr); |
| 74 } |
| 75 |
| 76 void PPB_TCPSocket_Private_Impl::SendSSLHandshake( |
| 77 const std::string& server_name, |
| 78 uint16_t server_port) { |
| 79 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 80 if (!plugin_delegate) |
| 81 return; |
| 82 |
| 83 plugin_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port); |
| 84 } |
| 85 |
| 86 void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) { |
| 87 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 88 if (!plugin_delegate) |
| 89 return; |
| 90 |
| 91 plugin_delegate->TCPSocketRead(socket_id_, bytes_to_read); |
| 92 } |
| 93 |
| 94 |
| 95 void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) { |
| 96 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 97 if (!plugin_delegate) |
| 98 return; |
| 99 |
| 100 plugin_delegate->TCPSocketWrite(socket_id_, buffer); |
| 101 } |
| 102 |
| 103 void PPB_TCPSocket_Private_Impl::SendDisconnect() { |
| 104 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 105 if (!plugin_delegate) |
| 106 return; |
| 107 |
| 108 plugin_delegate->TCPSocketDisconnect(socket_id_); |
| 109 } |
| 110 |
| 111 void PPB_TCPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) { |
| 112 MessageLoop::current()->PostTask(FROM_HERE, new AbortCallbackTask(callback)); |
| 113 } |
| 114 |
| 115 } // namespace ppapi |
| 116 } // namespace webkit |
OLD | NEW |