OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 68 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
69 #include "webkit/glue/context_menu.h" | 69 #include "webkit/glue/context_menu.h" |
70 #include "webkit/plugins/npapi/webplugin.h" | 70 #include "webkit/plugins/npapi/webplugin.h" |
71 #include "webkit/plugins/ppapi/file_path.h" | 71 #include "webkit/plugins/ppapi/file_path.h" |
72 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" | 72 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" |
73 #include "webkit/plugins/ppapi/plugin_module.h" | 73 #include "webkit/plugins/ppapi/plugin_module.h" |
74 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 74 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
75 #include "webkit/plugins/ppapi/ppb_broker_impl.h" | 75 #include "webkit/plugins/ppapi/ppb_broker_impl.h" |
76 #include "webkit/plugins/ppapi/ppb_flash_impl.h" | 76 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
77 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" | 77 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" |
78 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" | |
79 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" | |
78 #include "webkit/plugins/ppapi/resource_helper.h" | 80 #include "webkit/plugins/ppapi/resource_helper.h" |
79 #include "webkit/plugins/webplugininfo.h" | 81 #include "webkit/plugins/webplugininfo.h" |
80 | 82 |
81 using WebKit::WebView; | 83 using WebKit::WebView; |
82 | 84 |
83 namespace { | 85 namespace { |
84 | 86 |
85 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) { | 87 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) { |
86 base::SyncSocket::Handle out_handle = base::kInvalidPlatformFileValue; | 88 base::SyncSocket::Handle out_handle = base::kInvalidPlatformFileValue; |
87 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 base::PlatformFile socket, | 1674 base::PlatformFile socket, |
1673 const PP_NetAddress_Private& local_addr, | 1675 const PP_NetAddress_Private& local_addr, |
1674 const PP_NetAddress_Private& remote_addr) { | 1676 const PP_NetAddress_Private& remote_addr) { |
1675 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector = | 1677 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector = |
1676 *pending_connect_tcps_.Lookup(request_id); | 1678 *pending_connect_tcps_.Lookup(request_id); |
1677 pending_connect_tcps_.Remove(request_id); | 1679 pending_connect_tcps_.Remove(request_id); |
1678 | 1680 |
1679 connector->CompleteConnectTcp(socket, local_addr, remote_addr); | 1681 connector->CompleteConnectTcp(socket, local_addr, remote_addr); |
1680 } | 1682 } |
1681 | 1683 |
1684 uint32 PepperPluginDelegateImpl::TCPSocketCreate() { | |
1685 if (!render_view_->CanUseSocketAPIs()) | |
1686 return 0; | |
1687 | |
1688 uint32 socket_id = 0; | |
1689 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Create( | |
1690 render_view_->routing_id(), 0, &socket_id)); | |
1691 return socket_id; | |
1692 } | |
1693 | |
1694 void PepperPluginDelegateImpl::TCPSocketConnect( | |
1695 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket, | |
1696 uint32 socket_id, | |
1697 const std::string& host, | |
1698 uint16_t port) { | |
1699 tcp_sockets_.AddWithID( | |
yzshen1
2011/11/28 20:59:16
Two issues here:
1) the following scenario is brok
yzshen1
2011/11/28 21:38:59
I think one way to do it:
- don't hold a reference
ygorshenin
2011/11/29 18:30:09
Done.
ygorshenin
2011/11/29 18:30:09
Done.
| |
1700 new scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl>(socket), | |
1701 socket_id); | |
1702 render_view_->Send( | |
1703 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port)); | |
1704 } | |
1705 | |
1706 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress( | |
1707 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket, | |
1708 uint32 socket_id, | |
1709 const PP_NetAddress_Private& addr) { | |
1710 tcp_sockets_.AddWithID( | |
1711 new scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl>(socket), | |
1712 socket_id); | |
1713 render_view_->Send( | |
1714 new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(socket_id, addr)); | |
1715 } | |
1716 | |
1717 void PepperPluginDelegateImpl::OnTCPSocketConnectACK( | |
1718 uint32 socket_id, | |
1719 bool succeeded, | |
1720 const PP_NetAddress_Private& local_addr, | |
1721 const PP_NetAddress_Private& remote_addr) { | |
1722 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
yzshen1
2011/11/28 20:59:16
For ALL ACK methods:
Please don't assume that soc
ygorshenin
2011/11/29 18:30:09
Done.
| |
1723 scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl> socket = | |
1724 *tcp_sockets_.Lookup(socket_id); | |
yzshen1
2011/11/28 20:59:16
For ALL ACK methods:
Don't de-reference it direct
ygorshenin
2011/11/29 18:30:09
Done.
| |
1725 if (socket.get()) | |
1726 socket->OnConnectCompleted(succeeded, local_addr, remote_addr); | |
1727 } | |
1728 | |
1729 void PepperPluginDelegateImpl::TCPSocketSSLHandshake(uint32 socket_id, | |
1730 const std::string& server_name, | |
yzshen1
2011/11/28 20:59:16
wrong indent.
ygorshenin
2011/11/29 18:30:09
Done.
| |
1731 uint16_t server_port) { | |
1732 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1733 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( | |
1734 socket_id, server_name, server_port)); | |
1735 } | |
1736 | |
1737 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(uint32 socket_id, | |
1738 bool succeeded) { | |
1739 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1740 scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl> socket = | |
1741 *tcp_sockets_.Lookup(socket_id); | |
1742 if (socket.get()) | |
1743 socket->OnSSLHandshakeCompleted(succeeded); | |
1744 } | |
1745 | |
1746 void PepperPluginDelegateImpl::TCPSocketRead(uint32 socket_id, | |
1747 int32_t bytes_to_read) { | |
1748 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1749 render_view_->Send( | |
1750 new PpapiHostMsg_PPBTCPSocket_Read(socket_id, bytes_to_read)); | |
1751 } | |
1752 | |
1753 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 socket_id, | |
1754 bool succeeded, | |
1755 const std::string& data) { | |
1756 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1757 scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl> socket = | |
1758 *tcp_sockets_.Lookup(socket_id); | |
1759 if (socket.get()) | |
1760 socket->OnReadCompleted(succeeded, data); | |
1761 } | |
1762 | |
1763 void PepperPluginDelegateImpl::TCPSocketWrite(uint32 socket_id, | |
1764 const std::string& buffer) { | |
1765 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1766 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id, buffer)); | |
1767 } | |
1768 | |
1769 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 socket_id, | |
1770 bool succeeded, | |
1771 int32_t bytes_written) { | |
1772 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
1773 scoped_refptr<webkit::ppapi::PPB_TCPSocket_Private_Impl> socket = | |
1774 *tcp_sockets_.Lookup(socket_id); | |
1775 if (socket.get()) | |
1776 socket->OnWriteCompleted(succeeded, bytes_written); | |
1777 } | |
1778 | |
1779 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) { | |
1780 DCHECK(tcp_sockets_.Lookup(socket_id)); | |
yzshen1
2011/11/29 20:19:32
Add comment about why we don't do DCHECK(tcp_socke
ygorshenin
2011/11/30 11:50:54
Done.
| |
1781 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id)); | |
1782 tcp_sockets_.Remove(socket_id); | |
1783 } | |
1784 | |
1785 uint32 PepperPluginDelegateImpl::UDPSocketCreate() { | |
1786 if (!render_view_->CanUseSocketAPIs()) | |
1787 return 0; | |
1788 | |
1789 uint32 socket_id = 0; | |
1790 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create( | |
1791 render_view_->routing_id(), 0, &socket_id)); | |
1792 return socket_id; | |
1793 } | |
1794 | |
1795 void PepperPluginDelegateImpl::UDPSocketBind( | |
1796 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket, | |
1797 uint32 socket_id, | |
1798 const PP_NetAddress_Private& addr) { | |
1799 udp_sockets_.AddWithID( | |
1800 new scoped_refptr<webkit::ppapi::PPB_UDPSocket_Private_Impl>(socket), | |
1801 socket_id); | |
1802 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Bind(socket_id, addr)); | |
1803 } | |
1804 | |
1805 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 socket_id, | |
1806 bool succeeded) { | |
1807 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1808 scoped_refptr<webkit::ppapi::PPB_UDPSocket_Private_Impl> socket = | |
1809 *udp_sockets_.Lookup(socket_id); | |
1810 if (socket.get()) | |
1811 socket->OnBindCompleted(succeeded); | |
1812 } | |
1813 | |
1814 void PepperPluginDelegateImpl::UDPSocketRecvFrom(uint32 socket_id, | |
1815 int32_t num_bytes) { | |
1816 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1817 render_view_->Send( | |
1818 new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id, num_bytes)); | |
1819 } | |
1820 | |
1821 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK( | |
1822 uint32 socket_id, | |
1823 bool succeeded, | |
1824 const std::string& data, | |
1825 const PP_NetAddress_Private& remote_addr) { | |
1826 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1827 scoped_refptr<webkit::ppapi::PPB_UDPSocket_Private_Impl> socket = | |
1828 *udp_sockets_.Lookup(socket_id); | |
1829 if (socket.get()) | |
1830 socket->OnRecvFromCompleted(succeeded, data, remote_addr); | |
1831 } | |
1832 | |
1833 void PepperPluginDelegateImpl::UDPSocketSendTo( | |
1834 uint32 socket_id, | |
1835 const std::string& buffer, | |
1836 const PP_NetAddress_Private& net_addr) { | |
1837 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1838 render_view_->Send( | |
1839 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr)); | |
1840 } | |
1841 | |
1842 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 socket_id, | |
1843 bool succeeded, | |
1844 int32_t bytes_written) { | |
1845 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1846 scoped_refptr<webkit::ppapi::PPB_UDPSocket_Private_Impl> socket = | |
1847 *udp_sockets_.Lookup(socket_id); | |
1848 if (socket.get()) | |
1849 socket->OnSendToCompleted(succeeded, bytes_written); | |
1850 } | |
1851 | |
1852 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) { | |
1853 DCHECK(udp_sockets_.Lookup(socket_id)); | |
1854 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id)); | |
1855 udp_sockets_.Remove(socket_id); | |
1856 } | |
1857 | |
1682 int32_t PepperPluginDelegateImpl::ShowContextMenu( | 1858 int32_t PepperPluginDelegateImpl::ShowContextMenu( |
1683 webkit::ppapi::PluginInstance* instance, | 1859 webkit::ppapi::PluginInstance* instance, |
1684 webkit::ppapi::PPB_Flash_Menu_Impl* menu, | 1860 webkit::ppapi::PPB_Flash_Menu_Impl* menu, |
1685 const gfx::Point& position) { | 1861 const gfx::Point& position) { |
1686 int32 render_widget_id = render_view_->routing_id(); | 1862 int32 render_widget_id = render_view_->routing_id(); |
1687 if (instance->FlashIsFullscreen(instance->pp_instance())) { | 1863 if (instance->FlashIsFullscreen(instance->pp_instance())) { |
1688 webkit::ppapi::FullscreenContainer* container = | 1864 webkit::ppapi::FullscreenContainer* container = |
1689 instance->fullscreen_container(); | 1865 instance->fullscreen_container(); |
1690 DCHECK(container); | 1866 DCHECK(container); |
1691 render_widget_id = | 1867 render_widget_id = |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1931 if (!context) | 2107 if (!context) |
1932 return NULL; | 2108 return NULL; |
1933 if (!context->makeContextCurrent() || context->isContextLost()) | 2109 if (!context->makeContextCurrent() || context->isContextLost()) |
1934 return NULL; | 2110 return NULL; |
1935 | 2111 |
1936 RendererGLContext* parent_context = context->context(); | 2112 RendererGLContext* parent_context = context->context(); |
1937 if (!parent_context) | 2113 if (!parent_context) |
1938 return NULL; | 2114 return NULL; |
1939 return parent_context; | 2115 return parent_context; |
1940 } | 2116 } |
OLD | NEW |