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

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: extend RenderViewObserver 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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 842
838 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing 843 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing
839 // client and plugin_socket.release(), then return. 844 // client and plugin_socket.release(), then return.
840 // That message handler will then call client->BrokerConnected() with the 845 // That message handler will then call client->BrokerConnected() with the
841 // saved pipe handle. 846 // saved pipe handle.
842 // Temporarily, just call back. 847 // Temporarily, just call back.
843 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); 848 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result);
844 } 849 }
845 850
846 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view) 851 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view)
847 : render_view_(render_view), 852 : content::RenderViewObserver(NULL),
853 render_view_(render_view),
848 has_saved_context_menu_action_(false), 854 has_saved_context_menu_action_(false),
849 saved_context_menu_action_(0), 855 saved_context_menu_action_(0),
850 focused_plugin_(NULL), 856 focused_plugin_(NULL),
851 mouse_lock_owner_(NULL), 857 mouse_lock_owner_(NULL),
852 mouse_locked_(false), 858 mouse_locked_(false),
853 pending_lock_request_(false), 859 pending_lock_request_(false),
854 pending_unlock_request_(false), 860 pending_unlock_request_(false),
855 last_mouse_event_target_(NULL) { 861 last_mouse_event_target_(NULL) {
856 } 862 }
857 863
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 base::PlatformFile socket, 1681 base::PlatformFile socket,
1676 const PP_NetAddress_Private& local_addr, 1682 const PP_NetAddress_Private& local_addr,
1677 const PP_NetAddress_Private& remote_addr) { 1683 const PP_NetAddress_Private& remote_addr) {
1678 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector = 1684 scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector =
1679 *pending_connect_tcps_.Lookup(request_id); 1685 *pending_connect_tcps_.Lookup(request_id);
1680 pending_connect_tcps_.Remove(request_id); 1686 pending_connect_tcps_.Remove(request_id);
1681 1687
1682 connector->CompleteConnectTcp(socket, local_addr, remote_addr); 1688 connector->CompleteConnectTcp(socket, local_addr, remote_addr);
1683 } 1689 }
1684 1690
1691 uint32 PepperPluginDelegateImpl::TCPSocketCreate() {
1692 if (!CanUseSocketAPIs())
1693 return 0;
1694
1695 uint32 socket_id = 0;
1696 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Create(
1697 render_view_->routing_id(), 0, &socket_id));
1698 return socket_id;
1699 }
1700
1701 void PepperPluginDelegateImpl::TCPSocketConnect(
1702 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1703 uint32 socket_id,
1704 const std::string& host,
1705 uint16_t port) {
1706 tcp_sockets_.AddWithID(socket, socket_id);
1707 render_view_->Send(
1708 new PpapiHostMsg_PPBTCPSocket_Connect(socket_id, host, port));
1709 }
1710
1711 void PepperPluginDelegateImpl::TCPSocketConnectWithNetAddress(
1712 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket,
1713 uint32 socket_id,
1714 const PP_NetAddress_Private& addr) {
1715 tcp_sockets_.AddWithID(socket, socket_id);
1716 render_view_->Send(
1717 new PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress(socket_id, addr));
1718 }
1719
1720 void PepperPluginDelegateImpl::TCPSocketSSLHandshake(
1721 uint32 socket_id,
1722 const std::string& server_name,
1723 uint16_t server_port) {
1724 DCHECK(tcp_sockets_.Lookup(socket_id));
1725 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_SSLHandshake(
1726 socket_id, server_name, server_port));
1727 }
1728
1729 void PepperPluginDelegateImpl::TCPSocketRead(uint32 socket_id,
1730 int32_t bytes_to_read) {
1731 DCHECK(tcp_sockets_.Lookup(socket_id));
1732 render_view_->Send(
1733 new PpapiHostMsg_PPBTCPSocket_Read(socket_id, bytes_to_read));
1734 }
1735
1736 void PepperPluginDelegateImpl::TCPSocketWrite(uint32 socket_id,
1737 const std::string& buffer) {
1738 DCHECK(tcp_sockets_.Lookup(socket_id));
1739 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Write(socket_id, buffer));
1740 }
1741
1742 void PepperPluginDelegateImpl::TCPSocketDisconnect(uint32 socket_id) {
1743 // There are no DCHECK(tcp_sockets_.Lookup(socket_id)) because it
1744 // can be called before
1745 // TCPSocketConnect/TCPSocketConnectWithNetAddress is called.
1746 render_view_->Send(new PpapiHostMsg_PPBTCPSocket_Disconnect(socket_id));
1747 tcp_sockets_.Remove(socket_id);
1748 }
1749
1750 uint32 PepperPluginDelegateImpl::UDPSocketCreate() {
1751 if (!CanUseSocketAPIs())
1752 return 0;
1753
1754 uint32 socket_id = 0;
1755 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Create(
1756 render_view_->routing_id(), 0, &socket_id));
1757 return socket_id;
1758 }
1759
1760 void PepperPluginDelegateImpl::UDPSocketBind(
1761 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket,
1762 uint32 socket_id,
1763 const PP_NetAddress_Private& addr) {
1764 udp_sockets_.AddWithID(socket, socket_id);
1765 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Bind(socket_id, addr));
1766 }
1767
1768 void PepperPluginDelegateImpl::UDPSocketRecvFrom(uint32 socket_id,
1769 int32_t num_bytes) {
1770 DCHECK(udp_sockets_.Lookup(socket_id));
1771 render_view_->Send(
1772 new PpapiHostMsg_PPBUDPSocket_RecvFrom(socket_id, num_bytes));
1773 }
1774
1775 void PepperPluginDelegateImpl::UDPSocketSendTo(
1776 uint32 socket_id,
1777 const std::string& buffer,
1778 const PP_NetAddress_Private& net_addr) {
1779 DCHECK(udp_sockets_.Lookup(socket_id));
1780 render_view_->Send(
1781 new PpapiHostMsg_PPBUDPSocket_SendTo(socket_id, buffer, net_addr));
1782 }
1783
1784 void PepperPluginDelegateImpl::UDPSocketClose(uint32 socket_id) {
1785 // There are no DCHECK(udp_sockets_.Lookup(socket_id)) because it
1786 // can be called before UDPSocketBind is called.
1787 render_view_->Send(new PpapiHostMsg_PPBUDPSocket_Close(socket_id));
1788 udp_sockets_.Remove(socket_id);
1789 }
1790
1685 int32_t PepperPluginDelegateImpl::ShowContextMenu( 1791 int32_t PepperPluginDelegateImpl::ShowContextMenu(
1686 webkit::ppapi::PluginInstance* instance, 1792 webkit::ppapi::PluginInstance* instance,
1687 webkit::ppapi::PPB_Flash_Menu_Impl* menu, 1793 webkit::ppapi::PPB_Flash_Menu_Impl* menu,
1688 const gfx::Point& position) { 1794 const gfx::Point& position) {
1689 int32 render_widget_id = render_view_->routing_id(); 1795 int32 render_widget_id = render_view_->routing_id();
1690 if (instance->FlashIsFullscreen(instance->pp_instance())) { 1796 if (instance->FlashIsFullscreen(instance->pp_instance())) {
1691 webkit::ppapi::FullscreenContainer* container = 1797 webkit::ppapi::FullscreenContainer* container =
1692 instance->fullscreen_container(); 1798 instance->fullscreen_container();
1693 DCHECK(container); 1799 DCHECK(container);
1694 render_widget_id = 1800 render_widget_id =
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 2021
1916 void PepperPluginDelegateImpl::DidReceiveMouseEvent( 2022 void PepperPluginDelegateImpl::DidReceiveMouseEvent(
1917 webkit::ppapi::PluginInstance* instance) { 2023 webkit::ppapi::PluginInstance* instance) {
1918 last_mouse_event_target_ = instance; 2024 last_mouse_event_target_ = instance;
1919 } 2025 }
1920 2026
1921 bool PepperPluginDelegateImpl::IsInFullscreenMode() { 2027 bool PepperPluginDelegateImpl::IsInFullscreenMode() {
1922 return render_view_->is_fullscreen(); 2028 return render_view_->is_fullscreen();
1923 } 2029 }
1924 2030
2031 bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) {
2032 bool handled = true;
2033 IPC_BEGIN_MESSAGE_MAP(PepperPluginDelegateImpl, message)
2034 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ConnectACK,
2035 OnTCPSocketConnectACK)
2036 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_SSLHandshakeACK,
2037 OnTCPSocketSSLHandshakeACK)
2038 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_ReadACK, OnTCPSocketReadACK)
2039 IPC_MESSAGE_HANDLER(PpapiMsg_PPBTCPSocket_WriteACK, OnTCPSocketWriteACK)
2040 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_BindACK, OnUDPSocketBindACK)
2041 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_RecvFromACK,
2042 OnUDPSocketRecvFromACK)
2043 IPC_MESSAGE_HANDLER(PpapiMsg_PPBUDPSocket_SendToACK, OnUDPSocketSendToACK)
2044 IPC_MESSAGE_UNHANDLED(handled = false)
2045 IPC_END_MESSAGE_MAP()
2046 return handled;
2047 }
2048
2049 void PepperPluginDelegateImpl::OnTCPSocketConnectACK(
2050 uint32 plugin_dispatcher_id,
2051 uint32 socket_id,
2052 bool succeeded,
2053 const PP_NetAddress_Private& local_addr,
2054 const PP_NetAddress_Private& remote_addr) {
2055 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2056 tcp_sockets_.Lookup(socket_id);
2057 if (socket)
2058 socket->OnConnectCompleted(succeeded, local_addr, remote_addr);
2059 }
2060
2061 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(
2062 uint32 plugin_dispatcher_id,
2063 uint32 socket_id,
2064 bool succeeded) {
2065 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2066 tcp_sockets_.Lookup(socket_id);
2067 if (socket)
2068 socket->OnSSLHandshakeCompleted(succeeded);
2069 }
2070
2071 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id,
2072 uint32 socket_id,
2073 bool succeeded,
2074 const std::string& data) {
2075 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2076 tcp_sockets_.Lookup(socket_id);
2077 if (socket)
2078 socket->OnReadCompleted(succeeded, data);
2079 }
2080
2081 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id,
2082 uint32 socket_id,
2083 bool succeeded,
2084 int32_t bytes_written) {
2085 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2086 tcp_sockets_.Lookup(socket_id);
2087 if (socket)
2088 socket->OnWriteCompleted(succeeded, bytes_written);
2089 }
2090
2091 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id,
2092 uint32 socket_id,
2093 bool succeeded) {
2094 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2095 udp_sockets_.Lookup(socket_id);
2096 if (socket)
2097 socket->OnBindCompleted(succeeded);
2098 }
2099
2100 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK(
2101 uint32 plugin_dispatcher_id,
2102 uint32 socket_id,
2103 bool succeeded,
2104 const std::string& data,
2105 const PP_NetAddress_Private& remote_addr) {
2106 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2107 udp_sockets_.Lookup(socket_id);
2108 if (socket)
2109 socket->OnRecvFromCompleted(succeeded, data, remote_addr);
2110 }
2111
2112 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 plugin_dispatcher_id,
2113 uint32 socket_id,
2114 bool succeeded,
2115 int32_t bytes_written) {
2116 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2117 udp_sockets_.Lookup(socket_id);
2118 if (socket)
2119 socket->OnSendToCompleted(succeeded, bytes_written);
2120 }
2121
1925 int PepperPluginDelegateImpl::GetRoutingId() const { 2122 int PepperPluginDelegateImpl::GetRoutingId() const {
1926 return render_view_->routing_id(); 2123 return render_view_->routing_id();
1927 } 2124 }
1928 2125
1929 RendererGLContext* 2126 RendererGLContext*
1930 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { 2127 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() {
1931 WebGraphicsContext3DCommandBufferImpl* context = 2128 WebGraphicsContext3DCommandBufferImpl* context =
1932 static_cast<WebGraphicsContext3DCommandBufferImpl*>( 2129 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
1933 render_view_->webview()->graphicsContext3D()); 2130 render_view_->webview()->graphicsContext3D());
1934 if (!context) 2131 if (!context)
1935 return NULL; 2132 return NULL;
1936 if (!context->makeContextCurrent() || context->isContextLost()) 2133 if (!context->makeContextCurrent() || context->isContextLost())
1937 return NULL; 2134 return NULL;
1938 2135
1939 RendererGLContext* parent_context = context->context(); 2136 RendererGLContext* parent_context = context->context();
1940 if (!parent_context) 2137 if (!parent_context)
1941 return NULL; 2138 return NULL;
1942 return parent_context; 2139 return parent_context;
1943 } 2140 }
2141
2142 bool PepperPluginDelegateImpl::CanUseSocketAPIs() {
2143 WebView* webview = render_view_->webview();
2144 WebFrame* main_frame = webview ? webview->mainFrame() : NULL;
2145 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL());
2146 if (!url.is_valid())
2147 return false;
2148
2149 return content::GetContentClient()->renderer()->AllowSocketAPI(url);
2150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698