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

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: fix destruction issue 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
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(render_view),
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::OnDestruct() {
2050 // Nothing to do here. Default implementation in RenderViewObserver does
2051 // 'delete this' but it's not suitable for PepperPluginDelegateImpl because
2052 // it's non-pointer member in RenderViewImpl.
2053 }
2054
2055 void PepperPluginDelegateImpl::OnTCPSocketConnectACK(
2056 uint32 plugin_dispatcher_id,
2057 uint32 socket_id,
2058 bool succeeded,
2059 const PP_NetAddress_Private& local_addr,
2060 const PP_NetAddress_Private& remote_addr) {
2061 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2062 tcp_sockets_.Lookup(socket_id);
2063 if (socket)
2064 socket->OnConnectCompleted(succeeded, local_addr, remote_addr);
2065 }
2066
2067 void PepperPluginDelegateImpl::OnTCPSocketSSLHandshakeACK(
2068 uint32 plugin_dispatcher_id,
2069 uint32 socket_id,
2070 bool succeeded) {
2071 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2072 tcp_sockets_.Lookup(socket_id);
2073 if (socket)
2074 socket->OnSSLHandshakeCompleted(succeeded);
2075 }
2076
2077 void PepperPluginDelegateImpl::OnTCPSocketReadACK(uint32 plugin_dispatcher_id,
2078 uint32 socket_id,
2079 bool succeeded,
2080 const std::string& data) {
2081 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2082 tcp_sockets_.Lookup(socket_id);
2083 if (socket)
2084 socket->OnReadCompleted(succeeded, data);
2085 }
2086
2087 void PepperPluginDelegateImpl::OnTCPSocketWriteACK(uint32 plugin_dispatcher_id,
2088 uint32 socket_id,
2089 bool succeeded,
2090 int32_t bytes_written) {
2091 webkit::ppapi::PPB_TCPSocket_Private_Impl* socket =
2092 tcp_sockets_.Lookup(socket_id);
2093 if (socket)
2094 socket->OnWriteCompleted(succeeded, bytes_written);
2095 }
2096
2097 void PepperPluginDelegateImpl::OnUDPSocketBindACK(uint32 plugin_dispatcher_id,
2098 uint32 socket_id,
2099 bool succeeded) {
2100 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2101 udp_sockets_.Lookup(socket_id);
2102 if (socket)
2103 socket->OnBindCompleted(succeeded);
2104 }
2105
2106 void PepperPluginDelegateImpl::OnUDPSocketRecvFromACK(
2107 uint32 plugin_dispatcher_id,
2108 uint32 socket_id,
2109 bool succeeded,
2110 const std::string& data,
2111 const PP_NetAddress_Private& remote_addr) {
2112 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2113 udp_sockets_.Lookup(socket_id);
2114 if (socket)
2115 socket->OnRecvFromCompleted(succeeded, data, remote_addr);
2116 }
2117
2118 void PepperPluginDelegateImpl::OnUDPSocketSendToACK(uint32 plugin_dispatcher_id,
2119 uint32 socket_id,
2120 bool succeeded,
2121 int32_t bytes_written) {
2122 webkit::ppapi::PPB_UDPSocket_Private_Impl* socket =
2123 udp_sockets_.Lookup(socket_id);
2124 if (socket)
2125 socket->OnSendToCompleted(succeeded, bytes_written);
2126 }
2127
1925 int PepperPluginDelegateImpl::GetRoutingId() const { 2128 int PepperPluginDelegateImpl::GetRoutingId() const {
1926 return render_view_->routing_id(); 2129 return render_view_->routing_id();
1927 } 2130 }
1928 2131
1929 RendererGLContext* 2132 RendererGLContext*
1930 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() { 2133 PepperPluginDelegateImpl::GetParentContextForPlatformContext3D() {
1931 WebGraphicsContext3DCommandBufferImpl* context = 2134 WebGraphicsContext3DCommandBufferImpl* context =
1932 static_cast<WebGraphicsContext3DCommandBufferImpl*>( 2135 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
1933 render_view_->webview()->graphicsContext3D()); 2136 render_view_->webview()->graphicsContext3D());
1934 if (!context) 2137 if (!context)
1935 return NULL; 2138 return NULL;
1936 if (!context->makeContextCurrent() || context->isContextLost()) 2139 if (!context->makeContextCurrent() || context->isContextLost())
1937 return NULL; 2140 return NULL;
1938 2141
1939 RendererGLContext* parent_context = context->context(); 2142 RendererGLContext* parent_context = context->context();
1940 if (!parent_context) 2143 if (!parent_context)
1941 return NULL; 2144 return NULL;
1942 return parent_context; 2145 return parent_context;
1943 } 2146 }
2147
2148 bool PepperPluginDelegateImpl::CanUseSocketAPIs() {
2149 WebView* webview = render_view_->webview();
2150 WebFrame* main_frame = webview ? webview->mainFrame() : NULL;
2151 GURL url(main_frame ? GURL(main_frame->document().url()) : GURL());
2152 if (!url.is_valid())
2153 return false;
2154
2155 return content::GetContentClient()->renderer()->AllowSocketAPI(url);
2156 }
OLDNEW
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698