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

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 9283022: Exposed Listen and Accept methods to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added documentation for PPB_TCPServerSocket_Private methods, Create method became async. 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) 2012 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 "content/renderer/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "webkit/fileapi/file_system_callback_dispatcher.h" 69 #include "webkit/fileapi/file_system_callback_dispatcher.h"
70 #include "webkit/glue/context_menu.h" 70 #include "webkit/glue/context_menu.h"
71 #include "webkit/plugins/npapi/webplugin.h" 71 #include "webkit/plugins/npapi/webplugin.h"
72 #include "webkit/plugins/ppapi/file_path.h" 72 #include "webkit/plugins/ppapi/file_path.h"
73 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" 73 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
74 #include "webkit/plugins/ppapi/plugin_module.h" 74 #include "webkit/plugins/ppapi/plugin_module.h"
75 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 75 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
76 #include "webkit/plugins/ppapi/ppb_broker_impl.h" 76 #include "webkit/plugins/ppapi/ppb_broker_impl.h"
77 #include "webkit/plugins/ppapi/ppb_flash_impl.h" 77 #include "webkit/plugins/ppapi/ppb_flash_impl.h"
78 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" 78 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
79 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h"
79 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" 80 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
80 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" 81 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h"
81 #include "webkit/plugins/ppapi/resource_helper.h" 82 #include "webkit/plugins/ppapi/resource_helper.h"
82 #include "webkit/plugins/webplugininfo.h" 83 #include "webkit/plugins/webplugininfo.h"
83 84
84 using WebKit::WebView; 85 using WebKit::WebView;
85 using WebKit::WebFrame; 86 using WebKit::WebFrame;
86 87
87 namespace { 88 namespace {
88 89
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Create( 1658 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Create(
1658 render_view_->routing_id(), 0, &socket_id)); 1659 render_view_->routing_id(), 0, &socket_id));
1659 return socket_id; 1660 return socket_id;
1660 } 1661 }
1661 1662
1662 void PepperPluginDelegateImpl::TCPSocketConnect( 1663 void PepperPluginDelegateImpl::TCPSocketConnect(
1663 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket, 1664 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1664 uint32 socket_id, 1665 uint32 socket_id,
1665 const std::string& host, 1666 const std::string& host,
1666 uint16_t port) { 1667 uint16_t port) {
1667 tcp_sockets_.AddWithID(socket, socket_id); 1668 TCPSocketRegister(socket, socket_id);
1668 render_view_->Send( 1669 render_view_->Send(
1669 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port)); 1670 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port));
1670 } 1671 }
1671 1672
1672 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress( 1673 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress(
1673 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket, 1674 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1674 uint32 socket_id, 1675 uint32 socket_id,
1675 const PP_NetAddress_Private& addr) { 1676 const PP_NetAddress_Private& addr) {
1676 tcp_sockets_.AddWithID(socket, socket_id); 1677 tcp_sockets_.AddWithID(socket, socket_id);
1677 render_view_->Send( 1678 render_view_->Send(
(...skipping 23 matching lines...) Expand all
1701 } 1702 }
1702 1703
1703 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) { 1704 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) {
1704 // There are no DCHECK(tcp_sockets_.Lookup(socket_id)) because it 1705 // There are no DCHECK(tcp_sockets_.Lookup(socket_id)) because it
1705 // can be called before 1706 // can be called before
1706 // TCPSocketConnect/TCPSocketConnectWithNetAddress is called. 1707 // TCPSocketConnect/TCPSocketConnectWithNetAddress is called.
1707 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id)); 1708 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id));
1708 tcp_sockets_.Remove(socket_id); 1709 tcp_sockets_.Remove(socket_id);
1709 } 1710 }
1710 1711
1712 void PepperPluginDelegateImpl::TCPSocketRegister(
1713 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1714 uint32 socket_id) {
1715 tcp_sockets_.AddWithID(socket, socket_id);
1716 }
1717
1711 uint32 PepperPluginDelegateImpl::UDPSocketCreate() { 1718 uint32 PepperPluginDelegateImpl::UDPSocketCreate() {
1712 if (!CanUseSocketAPIs()) 1719 if (!CanUseSocketAPIs())
1713 return 0; 1720 return 0;
1714 1721
1715 uint32 socket_id = 0; 1722 uint32 socket_id = 0;
1716 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create( 1723 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create(
1717 render_view_->routing_id(), 0, &socket_id)); 1724 render_view_->routing_id(), 0, &socket_id));
1718 return socket_id; 1725 return socket_id;
1719 } 1726 }
1720 1727
(...skipping 21 matching lines...) Expand all
1742 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr)); 1749 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr));
1743 } 1750 }
1744 1751
1745 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) { 1752 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) {
1746 // There are no DCHECK(udp_sockets_.Lookup(socket_id)) because it 1753 // There are no DCHECK(udp_sockets_.Lookup(socket_id)) because it
1747 // can be called before UDPSocketBind is called. 1754 // can be called before UDPSocketBind is called.
1748 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id)); 1755 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id));
1749 udp_sockets_.Remove(socket_id); 1756 udp_sockets_.Remove(socket_id);
1750 } 1757 }
1751 1758
1759 bool PepperPluginDelegateImpl::TCPServerSocketInitialize(
1760 webkit::ppapi::PPB_TCPServerSocket_Private_Impl* socket) {
1761 DCHECK(socket != NULL);
1762 if (!CanUseSocketAPIs())
1763 return false;
1764
1765 uninitialized_tcp_server_sockets_.push(socket);
1766 render_view_->Send(new PpapiHostMsg_PPBTCPServerSocket_Initialize(
1767 render_view_->routing_id(), 0));
1768 return true;
1769 }
1770
1771 void PepperPluginDelegateImpl::TCPServerSocketListen(
1772 webkit::ppapi::PPB_TCPServerSocket_Private_Impl* socket,
1773 uint32 socket_id,
1774 const PP_NetAddress_Private& addr,
1775 int32_t backlog) {
1776 tcp_server_sockets_.AddWithID(socket, socket_id);
1777 render_view_->Send(
1778 new PpapiHostMsg_PPBTCPServerSocket_Listen(socket_id, addr, backlog));
1779 }
1780
1781 void PepperPluginDelegateImpl::TCPServerSocketAccept(uint32 socket_id) {
1782 DCHECK(tcp_server_sockets_.Lookup(socket_id));
1783 render_view_->Send(new PpapiHostMsg_PPBTCPServerSocket_Accept(socket_id));
1784 }
1785
1786 void PepperPluginDelegateImpl::TCPServerSocketStopListening(uint32 socket_id) {
1787 // There are no DCHECK(tcp_server_sockets_.Lookup(socket_id))
1788 // because it can be called before TCPServerSocketListen is called.
1789 render_view_->Send(
1790 new PpapiHostMsg_PPBTCPServerSocket_StopListening(socket_id));
1791 tcp_server_sockets_.Remove(socket_id);
1792 }
1793
1752 int32_t PepperPluginDelegateImpl::ShowContextMenu( 1794 int32_t PepperPluginDelegateImpl::ShowContextMenu(
1753 webkit::ppapi::PluginInstance* instance, 1795 webkit::ppapi::PluginInstance* instance,
1754 webkit::ppapi::PPB_Flash_Menu_Impl* menu, 1796 webkit::ppapi::PPB_Flash_Menu_Impl* menu,
1755 const gfx::Point& position) { 1797 const gfx::Point& position) {
1756 int32 render_widget_id = render_view_->routing_id(); 1798 int32 render_widget_id = render_view_->routing_id();
1757 if (instance->FlashIsFullscreen(instance->pp_instance())) { 1799 if (instance->FlashIsFullscreen(instance->pp_instance())) {
1758 webkit::ppapi::FullscreenContainer* container = 1800 webkit::ppapi::FullscreenContainer* container =
1759 instance->fullscreen_container(); 1801 instance->fullscreen_container();
1760 DCHECK(container); 1802 DCHECK(container);
1761 render_widget_id = 1803 render_widget_id =
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK, 2014 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK,
1973 OnTCPSocketConnectACK) 2015 OnTCPSocketConnectACK)
1974 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, 2016 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK,
1975 OnTCPSocketSSLHandshakeACK) 2017 OnTCPSocketSSLHandshakeACK)
1976 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK) 2018 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK)
1977 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK) 2019 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK)
1978 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK) 2020 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK)
1979 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK, 2021 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK,
1980 OnUDPSocketRecvFromACK) 2022 OnUDPSocketRecvFromACK)
1981 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, OnUDPSocketSendToACK) 2023 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, OnUDPSocketSendToACK)
2024 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_InitializeACK,
2025 OnTCPServerSocketInitializeACK)
2026 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_ListenACK,
2027 OnTCPServerSocketListenACK)
2028 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPServerSocket_AcceptACK,
2029 OnTCPServerSocketAcceptACK)
1982 IPC_MESSAGE_UNHANDLED(handled = false) 2030 IPC_MESSAGE_UNHANDLED(handled = false)
1983 IPC_END_MESSAGE_MAP() 2031 IPC_END_MESSAGE_MAP()
1984 return handled; 2032 return handled;
1985 } 2033 }
1986 2034
1987 void PepperPluginDelegateImpl::OnDestruct() { 2035 void PepperPluginDelegateImpl::OnDestruct() {
1988 // Nothing to do here. Default implementation in RenderViewObserver does 2036 // Nothing to do here. Default implementation in RenderViewObserver does
1989 // 'delete this' but it's not suitable for PepperPluginDelegateImpl because 2037 // 'delete this' but it's not suitable for PepperPluginDelegateImpl because
1990 // it's non-pointer member in RenderViewImpl. 2038 // it's non-pointer member in RenderViewImpl.
1991 } 2039 }
1992 2040
1993 void PepperPluginDelegateImpl::OnTCPSocketConnectACK( 2041 void PepperPluginDelegateImpl::OnTCPSocketConnectACK(
1994 uint32 plugin_dispatcher_id, 2042 uint32 plugin_dispatcher_id,
1995 uint32 socket_id, 2043 uint32 socket_id,
1996 bool succeeded, 2044 bool succeeded,
1997 const PP_NetAddress_Private& local_addr, 2045 const PP_NetAddress_Private& local_addr,
1998 const PP_NetAddress_Private& remote_addr) { 2046 const PP_NetAddress_Private& remote_addr) {
1999 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = 2047 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2000 tcp_sockets_.Lookup(socket_id); 2048 tcp_sockets_.Lookup(socket_id);
2001 if (socket) 2049 if (socket)
2002 socket->OnConnectCompleted(succeeded, local_addr, remote_addr); 2050 socket->OnConnectCompleted(succeeded, local_addr, remote_addr);
2051 if (!succeeded)
2052 tcp_sockets_.Remove(socket_id);
2003 } 2053 }
2004 2054
2005 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK( 2055 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(
2006 uint32 plugin_dispatcher_id, 2056 uint32 plugin_dispatcher_id,
2007 uint32 socket_id, 2057 uint32 socket_id,
2008 bool succeeded) { 2058 bool succeeded) {
2009 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = 2059 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2010 tcp_sockets_.Lookup(socket_id); 2060 tcp_sockets_.Lookup(socket_id);
2011 if (socket) 2061 if (socket)
2012 socket->OnSSLHandshakeCompleted(succeeded); 2062 socket->OnSSLHandshakeCompleted(succeeded);
(...skipping 19 matching lines...) Expand all
2032 socket->OnWriteCompleted(succeeded, bytes_written); 2082 socket->OnWriteCompleted(succeeded, bytes_written);
2033 } 2083 }
2034 2084
2035 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id, 2085 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id,
2036 uint32 socket_id, 2086 uint32 socket_id,
2037 bool succeeded) { 2087 bool succeeded) {
2038 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = 2088 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2039 udp_sockets_.Lookup(socket_id); 2089 udp_sockets_.Lookup(socket_id);
2040 if (socket) 2090 if (socket)
2041 socket->OnBindCompleted(succeeded); 2091 socket->OnBindCompleted(succeeded);
2092 if (!succeeded)
2093 udp_sockets_.Remove(socket_id);
2042 } 2094 }
2043 2095
2044 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK( 2096 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK(
2045 uint32 plugin_dispatcher_id, 2097 uint32 plugin_dispatcher_id,
2046 uint32 socket_id, 2098 uint32 socket_id,
2047 bool succeeded, 2099 bool succeeded,
2048 const std::string& data, 2100 const std::string& data,
2049 const PP_NetAddress_Private& remote_addr) { 2101 const PP_NetAddress_Private& remote_addr) {
2050 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = 2102 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2051 udp_sockets_.Lookup(socket_id); 2103 udp_sockets_.Lookup(socket_id);
2052 if (socket) 2104 if (socket)
2053 socket->OnRecvFromCompleted(succeeded, data, remote_addr); 2105 socket->OnRecvFromCompleted(succeeded, data, remote_addr);
2054 } 2106 }
2055 2107
2056 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 plugin_dispatcher_id, 2108 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 plugin_dispatcher_id,
2057 uint32 socket_id, 2109 uint32 socket_id,
2058 bool succeeded, 2110 bool succeeded,
2059 int32_t bytes_written) { 2111 int32_t bytes_written) {
2060 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = 2112 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2061 udp_sockets_.Lookup(socket_id); 2113 udp_sockets_.Lookup(socket_id);
2062 if (socket) 2114 if (socket)
2063 socket->OnSendToCompleted(succeeded, bytes_written); 2115 socket->OnSendToCompleted(succeeded, bytes_written);
2064 } 2116 }
2065 2117
2118 void PepperPluginDelegateImpl::OnTCPServerSocketListenACK(
2119 uint32 plugin_dispatcher_id,
2120 uint32 socket_id,
2121 bool succeeded) {
2122 webkit::ppapi::PPB_TCPServerSocket_Private_Impl* socket =
2123 tcp_server_sockets_.Lookup(socket_id);
2124 if (socket)
2125 socket->OnListenCompleted(succeeded);
2126 if (!succeeded)
2127 tcp_server_sockets_.Remove(socket_id);
2128 }
2129
2130 void PepperPluginDelegateImpl::OnTCPServerSocketInitializeACK(
2131 uint32 plugin_dispatcher_id,
2132 uint32 tcp_server_socket_id) {
2133 DCHECK(!uninitialized_tcp_server_sockets_.empty());
2134 webkit::ppapi::PPB_TCPServerSocket_Private_Impl* socket =
2135 uninitialized_tcp_server_sockets_.front();
2136 uninitialized_tcp_server_sockets_.pop();
2137 DCHECK(socket != NULL);
2138 socket->OnInitializeCompleted(tcp_server_socket_id);
2139 }
2140
2141 void PepperPluginDelegateImpl::OnTCPServerSocketAcceptACK(
2142 uint32 plugin_dispatcher_id,
2143 uint32 tcp_server_socket_id,
2144 uint32 tcp_socket_id,
2145 const PP_NetAddress_Private& local_addr,
2146 const PP_NetAddress_Private& remote_addr) {
2147 webkit::ppapi::PPB_TCPServerSocket_Private_Impl* socket =
2148 tcp_server_sockets_.Lookup(tcp_server_socket_id);
2149 if (socket) {
2150 bool succeeded = tcp_socket_id != 0;
2151 socket->OnAcceptCompleted(succeeded,
2152 tcp_socket_id,
2153 local_addr,
2154 remote_addr);
2155 }
2156 }
2157
2066 int PepperPluginDelegateImpl::GetRoutingId() const { 2158 int PepperPluginDelegateImpl::GetRoutingId() const {
2067 return render_view_->routing_id(); 2159 return render_view_->routing_id();
2068 } 2160 }
2069 2161
2070 ContentGLContext* 2162 ContentGLContext*
2071 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { 2163 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() {
2072 WebGraphicsContext3DCommandBufferImpl* context = 2164 WebGraphicsContext3DCommandBufferImpl* context =
2073 static_cast<WebGraphicsContext3DCommandBufferImpl*>( 2165 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2074 render_view_->webview()->graphicsContext3D()); 2166 render_view_->webview()->graphicsContext3D());
2075 if (!context) 2167 if (!context)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter( 2199 void PepperPluginDelegateImpl::UnSetAndDeleteLockTargetAdapter(
2108 webkit::ppapi::PluginInstance* instance) { 2200 webkit::ppapi::PluginInstance* instance) {
2109 LockTargetMap::iterator it = mouse_lock_instances_.find(instance); 2201 LockTargetMap::iterator it = mouse_lock_instances_.find(instance);
2110 if (it != mouse_lock_instances_.end()) { 2202 if (it != mouse_lock_instances_.end()) {
2111 MouseLockDispatcher::LockTarget* target = it->second; 2203 MouseLockDispatcher::LockTarget* target = it->second;
2112 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(target); 2204 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(target);
2113 delete target; 2205 delete target;
2114 mouse_lock_instances_.erase(it); 2206 mouse_lock_instances_.erase(it);
2115 } 2207 }
2116 } 2208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698