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

Unified 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: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd42bc35c3b012147da3785f8621cc3f0da4ab34
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_tcp_socket_private_impl.cc
@@ -0,0 +1,117 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
+
+#include "base/message_loop.h"
+#include "base/task.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/host_globals.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/plugin_module.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+class AbortCallbackTask : public Task {
+ public:
+ explicit AbortCallbackTask(PP_CompletionCallback callback)
+ : callback_(callback) {}
+ virtual ~AbortCallbackTask() {}
+ virtual void Run() {
+ if (callback_.func)
+ PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
+ }
+
+ private:
+ PP_CompletionCallback callback_;
+};
+
+} // namespace
+
+PPB_TCPSocket_Private_Impl::PPB_TCPSocket_Private_Impl(
+ PP_Instance instance, uint32 socket_id)
+ : ::ppapi::TCPSocketImpl(instance, socket_id) {
+}
+
+PPB_TCPSocket_Private_Impl::~PPB_TCPSocket_Private_Impl() {
+}
+
+PP_Resource PPB_TCPSocket_Private_Impl::CreateResource(PP_Instance instance) {
+ PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance);
+ if (!plugin_instance)
+ return 0;
+
+ PluginDelegate* pluign_delegate = plugin_instance->delegate();
+ uint32 socket_id = pluign_delegate->TCPSocketCreate();
+ if (!socket_id)
+ return 0;
+
+ return (new PPB_TCPSocket_Private_Impl(instance, socket_id))->GetReference();
+}
+
+void PPB_TCPSocket_Private_Impl::SendConnect(const std::string& host,
+ uint16_t port) {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketConnect(this, socket_id_, host, port);
+}
+
+void PPB_TCPSocket_Private_Impl::SendConnectWithNetAddress(
+ const PP_NetAddress_Private& addr) {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketConnectWithNetAddress(this, socket_id_, addr);
+}
+
+void PPB_TCPSocket_Private_Impl::SendSSLHandshake(
+ const std::string& server_name,
+ uint16_t server_port) {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketSSLHandshake(socket_id_, server_name, server_port);
+}
+
+void PPB_TCPSocket_Private_Impl::SendRead(int32_t bytes_to_read) {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketRead(socket_id_, bytes_to_read);
+}
+
+
+void PPB_TCPSocket_Private_Impl::SendWrite(const std::string& buffer) {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketWrite(socket_id_, buffer);
+}
+
+void PPB_TCPSocket_Private_Impl::SendDisconnect() {
+ PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!pluign_delegate)
+ return;
+
+ pluign_delegate->TCPSocketDisconnect(socket_id_);
+}
+
+void PPB_TCPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) {
+ MessageLoop::current()->PostTask(FROM_HERE, new AbortCallbackTask(callback));
+}
+
+} // namespace ppapi
+} // namespace webkit

Powered by Google App Engine
This is Rietveld 408576698