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(socket, socket_id); |
| 1700 render_view_->Send( |
| 1701 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port)); |
| 1702 } |
| 1703 |
| 1704 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress( |
| 1705 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket, |
| 1706 uint32 socket_id, |
| 1707 const PP_NetAddress_Private& addr) { |
| 1708 tcp_sockets_.AddWithID(socket, socket_id); |
| 1709 render_view_->Send( |
| 1710 new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(socket_id, addr)); |
| 1711 } |
| 1712 |
| 1713 void PepperPluginDelegateImpl::OnTCPSocketConnectACK( |
| 1714 uint32 socket_id, |
| 1715 bool succeeded, |
| 1716 const PP_NetAddress_Private& local_addr, |
| 1717 const PP_NetAddress_Private& remote_addr) { |
| 1718 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = |
| 1719 tcp_sockets_.Lookup(socket_id); |
| 1720 if (socket) |
| 1721 socket->OnConnectCompleted(succeeded, local_addr, remote_addr); |
| 1722 } |
| 1723 |
| 1724 void PepperPluginDelegateImpl::TCPSocketSSLHandshake( |
| 1725 uint32 socket_id, |
| 1726 const std::string& server_name, |
| 1727 uint16_t server_port) { |
| 1728 DCHECK(tcp_sockets_.Lookup(socket_id)); |
| 1729 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake( |
| 1730 socket_id, server_name, server_port)); |
| 1731 } |
| 1732 |
| 1733 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(uint32 socket_id, |
| 1734 bool succeeded) { |
| 1735 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = |
| 1736 tcp_sockets_.Lookup(socket_id); |
| 1737 if (socket) |
| 1738 socket->OnSSLHandshakeCompleted(succeeded); |
| 1739 } |
| 1740 |
| 1741 void PepperPluginDelegateImpl::TCPSocketRead(uint32 socket_id, |
| 1742 int32_t bytes_to_read) { |
| 1743 DCHECK(tcp_sockets_.Lookup(socket_id)); |
| 1744 render_view_->Send( |
| 1745 new PpapiHostMsg_PPBTCPSocket_Read(socket_id, bytes_to_read)); |
| 1746 } |
| 1747 |
| 1748 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 socket_id, |
| 1749 bool succeeded, |
| 1750 const std::string& data) { |
| 1751 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = |
| 1752 tcp_sockets_.Lookup(socket_id); |
| 1753 if (socket) |
| 1754 socket->OnReadCompleted(succeeded, data); |
| 1755 } |
| 1756 |
| 1757 void PepperPluginDelegateImpl::TCPSocketWrite(uint32 socket_id, |
| 1758 const std::string& buffer) { |
| 1759 DCHECK(tcp_sockets_.Lookup(socket_id)); |
| 1760 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id, buffer)); |
| 1761 } |
| 1762 |
| 1763 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 socket_id, |
| 1764 bool succeeded, |
| 1765 int32_t bytes_written) { |
| 1766 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket = |
| 1767 tcp_sockets_.Lookup(socket_id); |
| 1768 if (socket) |
| 1769 socket->OnWriteCompleted(succeeded, bytes_written); |
| 1770 } |
| 1771 |
| 1772 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) { |
| 1773 // There are no DCHECK(tcp_sockets_.Lookup(socket_id)) because it |
| 1774 // can be called before |
| 1775 // TCPSocketConnect/TCPSocketConnectWithNetAddress is called. |
| 1776 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id)); |
| 1777 tcp_sockets_.Remove(socket_id); |
| 1778 } |
| 1779 |
| 1780 uint32 PepperPluginDelegateImpl::UDPSocketCreate() { |
| 1781 if (!render_view_->CanUseSocketAPIs()) |
| 1782 return 0; |
| 1783 |
| 1784 uint32 socket_id = 0; |
| 1785 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create( |
| 1786 render_view_->routing_id(), 0, &socket_id)); |
| 1787 return socket_id; |
| 1788 } |
| 1789 |
| 1790 void PepperPluginDelegateImpl::UDPSocketBind( |
| 1791 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket, |
| 1792 uint32 socket_id, |
| 1793 const PP_NetAddress_Private& addr) { |
| 1794 udp_sockets_.AddWithID(socket, socket_id); |
| 1795 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Bind(socket_id, addr)); |
| 1796 } |
| 1797 |
| 1798 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 socket_id, |
| 1799 bool succeeded) { |
| 1800 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = |
| 1801 udp_sockets_.Lookup(socket_id); |
| 1802 if (socket) |
| 1803 socket->OnBindCompleted(succeeded); |
| 1804 } |
| 1805 |
| 1806 void PepperPluginDelegateImpl::UDPSocketRecvFrom(uint32 socket_id, |
| 1807 int32_t num_bytes) { |
| 1808 DCHECK(udp_sockets_.Lookup(socket_id)); |
| 1809 render_view_->Send( |
| 1810 new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id, num_bytes)); |
| 1811 } |
| 1812 |
| 1813 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK( |
| 1814 uint32 socket_id, |
| 1815 bool succeeded, |
| 1816 const std::string& data, |
| 1817 const PP_NetAddress_Private& remote_addr) { |
| 1818 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = |
| 1819 udp_sockets_.Lookup(socket_id); |
| 1820 if (socket) |
| 1821 socket->OnRecvFromCompleted(succeeded, data, remote_addr); |
| 1822 } |
| 1823 |
| 1824 void PepperPluginDelegateImpl::UDPSocketSendTo( |
| 1825 uint32 socket_id, |
| 1826 const std::string& buffer, |
| 1827 const PP_NetAddress_Private& net_addr) { |
| 1828 DCHECK(udp_sockets_.Lookup(socket_id)); |
| 1829 render_view_->Send( |
| 1830 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr)); |
| 1831 } |
| 1832 |
| 1833 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 socket_id, |
| 1834 bool succeeded, |
| 1835 int32_t bytes_written) { |
| 1836 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket = |
| 1837 udp_sockets_.Lookup(socket_id); |
| 1838 if (socket) |
| 1839 socket->OnSendToCompleted(succeeded, bytes_written); |
| 1840 } |
| 1841 |
| 1842 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) { |
| 1843 // There are no DCHECK(udp_sockets_.Lookup(socket_id)) because it |
| 1844 // can be called before UDPSocketBind is called. |
| 1845 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id)); |
| 1846 udp_sockets_.Remove(socket_id); |
| 1847 } |
| 1848 |
1682 int32_t PepperPluginDelegateImpl::ShowContextMenu( | 1849 int32_t PepperPluginDelegateImpl::ShowContextMenu( |
1683 webkit::ppapi::PluginInstance* instance, | 1850 webkit::ppapi::PluginInstance* instance, |
1684 webkit::ppapi::PPB_Flash_Menu_Impl* menu, | 1851 webkit::ppapi::PPB_Flash_Menu_Impl* menu, |
1685 const gfx::Point& position) { | 1852 const gfx::Point& position) { |
1686 int32 render_widget_id = render_view_->routing_id(); | 1853 int32 render_widget_id = render_view_->routing_id(); |
1687 if (instance->FlashIsFullscreen(instance->pp_instance())) { | 1854 if (instance->FlashIsFullscreen(instance->pp_instance())) { |
1688 webkit::ppapi::FullscreenContainer* container = | 1855 webkit::ppapi::FullscreenContainer* container = |
1689 instance->fullscreen_container(); | 1856 instance->fullscreen_container(); |
1690 DCHECK(container); | 1857 DCHECK(container); |
1691 render_widget_id = | 1858 render_widget_id = |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 if (!context) | 2098 if (!context) |
1932 return NULL; | 2099 return NULL; |
1933 if (!context->makeContextCurrent() || context->isContextLost()) | 2100 if (!context->makeContextCurrent() || context->isContextLost()) |
1934 return NULL; | 2101 return NULL; |
1935 | 2102 |
1936 RendererGLContext* parent_context = context->context(); | 2103 RendererGLContext* parent_context = context->context(); |
1937 if (!parent_context) | 2104 if (!parent_context) |
1938 return NULL; | 2105 return NULL; |
1939 return parent_context; | 2106 return parent_context; |
1940 } | 2107 } |
OLD | NEW |