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

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

Issue 8804006: Reland 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed compilation for content_shell_lib Created 9 years 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 | Annotate | Revision Log
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "media/video/capture/video_capture_proxy.h" 50 #include "media/video/capture/video_capture_proxy.h"
51 #include "ppapi/c/dev/pp_video_dev.h" 51 #include "ppapi/c/dev/pp_video_dev.h"
52 #include "ppapi/c/pp_errors.h" 52 #include "ppapi/c/pp_errors.h"
53 #include "ppapi/c/private/ppb_flash.h" 53 #include "ppapi/c/private/ppb_flash.h"
54 #include "ppapi/c/private/ppb_flash_net_connector.h" 54 #include "ppapi/c/private/ppb_flash_net_connector.h"
55 #include "ppapi/proxy/host_dispatcher.h" 55 #include "ppapi/proxy/host_dispatcher.h"
56 #include "ppapi/proxy/ppapi_messages.h" 56 #include "ppapi/proxy/ppapi_messages.h"
57 #include "ppapi/shared_impl/platform_file.h" 57 #include "ppapi/shared_impl/platform_file.h"
58 #include "ppapi/shared_impl/ppapi_preferences.h" 58 #include "ppapi/shared_impl/ppapi_preferences.h"
59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h" 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h"
61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h" 62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h"
63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
63 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
64 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 67 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
66 #include "ui/gfx/size.h" 68 #include "ui/gfx/size.h"
67 #include "ui/gfx/surface/transport_dib.h" 69 #include "ui/gfx/surface/transport_dib.h"
68 #include "webkit/fileapi/file_system_callback_dispatcher.h" 70 #include "webkit/fileapi/file_system_callback_dispatcher.h"
69 #include "webkit/glue/context_menu.h" 71 #include "webkit/glue/context_menu.h"
70 #include "webkit/plugins/npapi/webplugin.h" 72 #include "webkit/plugins/npapi/webplugin.h"
71 #include "webkit/plugins/ppapi/file_path.h" 73 #include "webkit/plugins/ppapi/file_path.h"
72 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" 74 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
73 #include "webkit/plugins/ppapi/plugin_module.h" 75 #include "webkit/plugins/ppapi/plugin_module.h"
74 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 76 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
75 #include "webkit/plugins/ppapi/ppb_broker_impl.h" 77 #include "webkit/plugins/ppapi/ppb_broker_impl.h"
76 #include "webkit/plugins/ppapi/ppb_flash_impl.h" 78 #include "webkit/plugins/ppapi/ppb_flash_impl.h"
77 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" 79 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
80 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
81 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h"
78 #include "webkit/plugins/ppapi/resource_helper.h" 82 #include "webkit/plugins/ppapi/resource_helper.h"
79 #include "webkit/plugins/webplugininfo.h" 83 #include "webkit/plugins/webplugininfo.h"
80 84
81 using WebKit::WebView; 85 using WebKit::WebView;
86 using WebKit::WebFrame;
82 87
83 namespace { 88 namespace {
84 89
85 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) { 90 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) {
86 base::SyncSocket::Handle out_handle = base::kInvalidPlatformFileValue; 91 base::SyncSocket::Handle out_handle = base::kInvalidPlatformFileValue;
87 #if defined(OS_WIN) 92 #if defined(OS_WIN)
88 DWORD options = DUPLICATE_SAME_ACCESS; 93 DWORD options = DUPLICATE_SAME_ACCESS;
89 if (!::DuplicateHandle(::GetCurrentProcess(), 94 if (!::DuplicateHandle(::GetCurrentProcess(),
90 handle, 95 handle,
91 ::GetCurrentProcess(), 96 ::GetCurrentProcess(),
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 base::PlatformFile socket, 1680 base::PlatformFile socket,
1676 const PP_NetAddress_Private& local_addr, 1681 const PP_NetAddress_Private& local_addr,
1677 const PP_NetAddress_Private& remote_addr) { 1682 const PP_NetAddress_Private& remote_addr) {
1678 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector = 1683 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector =
1679 *pending_connect_tcps_.Lookup(request_id); 1684 *pending_connect_tcps_.Lookup(request_id);
1680 pending_connect_tcps_.Remove(request_id); 1685 pending_connect_tcps_.Remove(request_id);
1681 1686
1682 connector->CompleteConnectTcp(socket, local_addr, remote_addr); 1687 connector->CompleteConnectTcp(socket, local_addr, remote_addr);
1683 } 1688 }
1684 1689
1690 uint32 PepperPluginDelegateImpl::TCPSocketCreate() {
1691 if (!CanUseSocketAPIs())
1692 return 0;
1693
1694 uint32 socket_id = 0;
1695 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Create(
1696 render_view_->routing_id(), 0, &socket_id));
1697 return socket_id;
1698 }
1699
1700 void PepperPluginDelegateImpl::TCPSocketConnect(
1701 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1702 uint32 socket_id,
1703 const std::string& host,
1704 uint16_t port) {
1705 tcp_sockets_.AddWithID(socket, socket_id);
1706 render_view_->Send(
1707 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port));
1708 }
1709
1710 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress(
1711 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1712 uint32 socket_id,
1713 const PP_NetAddress_Private& addr) {
1714 tcp_sockets_.AddWithID(socket, socket_id);
1715 render_view_->Send(
1716 new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(socket_id, addr));
1717 }
1718
1719 void PepperPluginDelegateImpl::TCPSocketSSLHandshake(
1720 uint32 socket_id,
1721 const std::string& server_name,
1722 uint16_t server_port) {
1723 DCHECK(tcp_sockets_.Lookup(socket_id));
1724 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake(
1725 socket_id, server_name, server_port));
1726 }
1727
1728 void PepperPluginDelegateImpl::TCPSocketRead(uint32 socket_id,
1729 int32_t bytes_to_read) {
1730 DCHECK(tcp_sockets_.Lookup(socket_id));
1731 render_view_->Send(
1732 new PpapiHostMsg_PPBTCPSocket_Read(socket_id, bytes_to_read));
1733 }
1734
1735 void PepperPluginDelegateImpl::TCPSocketWrite(uint32 socket_id,
1736 const std::string& buffer) {
1737 DCHECK(tcp_sockets_.Lookup(socket_id));
1738 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id, buffer));
1739 }
1740
1741 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) {
1742 // There are no DCHECK(tcp_sockets_.Lookup(socket_id)) because it
1743 // can be called before
1744 // TCPSocketConnect/TCPSocketConnectWithNetAddress is called.
1745 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id));
1746 tcp_sockets_.Remove(socket_id);
1747 }
1748
1749 uint32 PepperPluginDelegateImpl::UDPSocketCreate() {
1750 if (!CanUseSocketAPIs())
1751 return 0;
1752
1753 uint32 socket_id = 0;
1754 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create(
1755 render_view_->routing_id(), 0, &socket_id));
1756 return socket_id;
1757 }
1758
1759 void PepperPluginDelegateImpl::UDPSocketBind(
1760 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket,
1761 uint32 socket_id,
1762 const PP_NetAddress_Private& addr) {
1763 udp_sockets_.AddWithID(socket, socket_id);
1764 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Bind(socket_id, addr));
1765 }
1766
1767 void PepperPluginDelegateImpl::UDPSocketRecvFrom(uint32 socket_id,
1768 int32_t num_bytes) {
1769 DCHECK(udp_sockets_.Lookup(socket_id));
1770 render_view_->Send(
1771 new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id, num_bytes));
1772 }
1773
1774 void PepperPluginDelegateImpl::UDPSocketSendTo(
1775 uint32 socket_id,
1776 const std::string& buffer,
1777 const PP_NetAddress_Private& net_addr) {
1778 DCHECK(udp_sockets_.Lookup(socket_id));
1779 render_view_->Send(
1780 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr));
1781 }
1782
1783 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) {
1784 // There are no DCHECK(udp_sockets_.Lookup(socket_id)) because it
1785 // can be called before UDPSocketBind is called.
1786 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id));
1787 udp_sockets_.Remove(socket_id);
1788 }
1789
1685 int32_t PepperPluginDelegateImpl::ShowContextMenu( 1790 int32_t PepperPluginDelegateImpl::ShowContextMenu(
1686 webkit::ppapi::PluginInstance* instance, 1791 webkit::ppapi::PluginInstance* instance,
1687 webkit::ppapi::PPB_Flash_Menu_Impl* menu, 1792 webkit::ppapi::PPB_Flash_Menu_Impl* menu,
1688 const gfx::Point& position) { 1793 const gfx::Point& position) {
1689 int32 render_widget_id = render_view_->routing_id(); 1794 int32 render_widget_id = render_view_->routing_id();
1690 if (instance->FlashIsFullscreen(instance->pp_instance())) { 1795 if (instance->FlashIsFullscreen(instance->pp_instance())) {
1691 webkit::ppapi::FullscreenContainer* container = 1796 webkit::ppapi::FullscreenContainer* container =
1692 instance->fullscreen_container(); 1797 instance->fullscreen_container();
1693 DCHECK(container); 1798 DCHECK(container);
1694 render_widget_id = 1799 render_widget_id =
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 2020
1916 void PepperPluginDelegateImpl::DidReceiveMouseEvent( 2021 void PepperPluginDelegateImpl::DidReceiveMouseEvent(
1917 webkit::ppapi::PluginInstance* instance) { 2022 webkit::ppapi::PluginInstance* instance) {
1918 last_mouse_event_target_ = instance; 2023 last_mouse_event_target_ = instance;
1919 } 2024 }
1920 2025
1921 bool PepperPluginDelegateImpl::IsInFullscreenMode() { 2026 bool PepperPluginDelegateImpl::IsInFullscreenMode() {
1922 return render_view_->is_fullscreen(); 2027 return render_view_->is_fullscreen();
1923 } 2028 }
1924 2029
2030 bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) {
2031 bool handled = true;
2032 IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message)
2033 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK,
2034 OnTCPSocketConnectACK)
2035 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK,
2036 OnTCPSocketSSLHandshakeACK)
2037 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK)
2038 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK)
2039 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK)
2040 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK,
2041 OnUDPSocketRecvFromACK)
2042 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, OnUDPSocketSendToACK)
2043 IPC_MESSAGE_UNHANDLED(handled = false)
2044 IPC_END_MESSAGE_MAP()
2045 return handled;
2046 }
2047
2048 void PepperPluginDelegateImpl::OnTCPSocketConnectACK(
2049 uint32 plugin_dispatcher_id,
2050 uint32 socket_id,
2051 bool succeeded,
2052 const PP_NetAddress_Private& local_addr,
2053 const PP_NetAddress_Private& remote_addr) {
2054 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2055 tcp_sockets_.Lookup(socket_id);
2056 if (socket)
2057 socket->OnConnectCompleted(succeeded, local_addr, remote_addr);
2058 }
2059
2060 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(
2061 uint32 plugin_dispatcher_id,
2062 uint32 socket_id,
2063 bool succeeded) {
2064 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2065 tcp_sockets_.Lookup(socket_id);
2066 if (socket)
2067 socket->OnSSLHandshakeCompleted(succeeded);
2068 }
2069
2070 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id,
2071 uint32 socket_id,
2072 bool succeeded,
2073 const std::string& data) {
2074 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2075 tcp_sockets_.Lookup(socket_id);
2076 if (socket)
2077 socket->OnReadCompleted(succeeded, data);
2078 }
2079
2080 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id,
2081 uint32 socket_id,
2082 bool succeeded,
2083 int32_t bytes_written) {
2084 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2085 tcp_sockets_.Lookup(socket_id);
2086 if (socket)
2087 socket->OnWriteCompleted(succeeded, bytes_written);
2088 }
2089
2090 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id,
2091 uint32 socket_id,
2092 bool succeeded) {
2093 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2094 udp_sockets_.Lookup(socket_id);
2095 if (socket)
2096 socket->OnBindCompleted(succeeded);
2097 }
2098
2099 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK(
2100 uint32 plugin_dispatcher_id,
2101 uint32 socket_id,
2102 bool succeeded,
2103 const std::string& data,
2104 const PP_NetAddress_Private& remote_addr) {
2105 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2106 udp_sockets_.Lookup(socket_id);
2107 if (socket)
2108 socket->OnRecvFromCompleted(succeeded, data, remote_addr);
2109 }
2110
2111 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 plugin_dispatcher_id,
2112 uint32 socket_id,
2113 bool succeeded,
2114 int32_t bytes_written) {
2115 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2116 udp_sockets_.Lookup(socket_id);
2117 if (socket)
2118 socket->OnSendToCompleted(succeeded, bytes_written);
2119 }
2120
1925 int PepperPluginDelegateImpl::GetRoutingId() const { 2121 int PepperPluginDelegateImpl::GetRoutingId() const {
1926 return render_view_->routing_id(); 2122 return render_view_->routing_id();
1927 } 2123 }
1928 2124
1929 RendererGLContext* 2125 RendererGLContext*
1930 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { 2126 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() {
1931 WebGraphicsContext3DCommandBufferImpl* context = 2127 WebGraphicsContext3DCommandBufferImpl* context =
1932 static_cast<WebGraphicsContext3DCommandBufferImpl*>( 2128 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
1933 render_view_->webview()->graphicsContext3D()); 2129 render_view_->webview()->graphicsContext3D());
1934 if (!context) 2130 if (!context)
1935 return NULL; 2131 return NULL;
1936 if (!context->makeContextCurrent() || context->isContextLost()) 2132 if (!context->makeContextCurrent() || context->isContextLost())
1937 return NULL; 2133 return NULL;
1938 2134
1939 RendererGLContext* parent_context = context->context(); 2135 RendererGLContext* parent_context = context->context();
1940 if (!parent_context) 2136 if (!parent_context)
1941 return NULL; 2137 return NULL;
1942 return parent_context; 2138 return parent_context;
1943 } 2139 }
2140
2141 bool PepperPluginDelegateImpl::CanUseSocketAPIs() {
2142 WebView* webview = render_view_->webview();
2143 WebFrame* main_frame = webview ? webview->mainFrame() : NULL;
2144 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL());
2145 if (!url.is_valid())
2146 return false;
2147
2148 return content::GetContentClient()->renderer()->AllowSocketAPI(url);
2149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698