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