diff options
24 files changed, 949 insertions, 17 deletions
diff --git a/build/common.gypi b/build/common.gypi index 5d3ef05..b26818f 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -128,6 +128,13 @@ }, { 'linux_fpic%': 1, }], + + # Enable some hacks to support Flapper only on Chrome OS. + ['chromeos==1', { + 'enable_flapper_hacks%': 1, + }, { + 'enable_flapper_hacks%': 0, + }], ], }, @@ -139,6 +146,7 @@ 'toolkit_views%': '<(toolkit_views)', 'use_gnome_keyring%': '<(use_gnome_keyring)', 'linux_fpic%': '<(linux_fpic)', + 'enable_flapper_hacks%': '<(enable_flapper_hacks)', 'chromeos%': '<(chromeos)', 'touchui%': '<(touchui)', 'inside_chromium_build%': '<(inside_chromium_build)', @@ -488,6 +496,9 @@ ['proprietary_codecs==1', { 'defines': ['USE_PROPRIETARY_CODECS'], }], + ['enable_flapper_hacks==1', { + 'defines': ['ENABLE_FLAPPER_HACKS=1'], + }], ['fastbuild!=0', { 'conditions': [ # For Windows, we don't genererate debug information. diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index a052a2d..1d4653b 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -8,6 +8,7 @@ include_rules = [ "+chrome/tools/profiles", # For history unit tests. "+chrome/views", "+grit", # For generated headers + "+ppapi/c", # For various types. "+ppapi/proxy", "+rlz", "+sandbox/linux", diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index d901a77..3b97c4b 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -54,6 +54,7 @@ #include "chrome/browser/renderer_host/database_message_filter.h" #include "chrome/browser/renderer_host/file_utilities_message_filter.h" #include "chrome/browser/renderer_host/pepper_file_message_filter.h" +#include "chrome/browser/renderer_host/pepper_message_filter.h" #include "chrome/browser/renderer_host/render_message_filter.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" @@ -452,6 +453,7 @@ void BrowserRenderProcessHost::CreateMessageFilters() { GeolocationDispatcherHost::New( id(), profile()->GetGeolocationPermissionContext())); channel_->AddFilter(new PepperFileMessageFilter(id(), profile())); + channel_->AddFilter(new PepperMessageFilter(profile())); channel_->AddFilter(new speech_input::SpeechInputDispatcherHost(id())); channel_->AddFilter( new SearchProviderInstallStateMessageFilter(id(), profile())); diff --git a/chrome/browser/renderer_host/pepper_message_filter.cc b/chrome/browser/renderer_host/pepper_message_filter.cc new file mode 100644 index 0000000..62464af --- /dev/null +++ b/chrome/browser/renderer_host/pepper_message_filter.cc @@ -0,0 +1,285 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/pepper_message_filter.h" + +#include "base/basictypes.h" +#include "base/process_util.h" +#include "base/threading/worker_pool.h" +#include "chrome/browser/browser_thread.h" +#include "chrome/browser/net/chrome_url_request_context.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_host/browser_render_process_host.h" +#include "chrome/common/render_messages.h" +#include "net/base/address_list.h" +#include "net/base/host_port_pair.h" +#include "net/base/host_resolver.h" +#include "net/url_request/url_request_context.h" +#include "webkit/plugins/ppapi/ppb_flash_impl.h" + +#if defined(ENABLE_FLAPPER_HACKS) +#include <netdb.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> + +// Make sure the storage in |PP_Flash_NetAddress| is big enough. (Do it here +// since the data is opaque elsewhere.) +COMPILE_ASSERT(sizeof(reinterpret_cast<PP_Flash_NetAddress*>(0)->data) >= + sizeof(sockaddr_storage), PP_Flash_NetAddress_data_too_small); +#endif // ENABLE_FLAPPER_HACKS + +const PP_Flash_NetAddress kInvalidNetAddress = { 0 }; + +PepperMessageFilter::PepperMessageFilter(Profile* profile) + : profile_(profile) { +} + +bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, + bool* message_was_ok) { +#if defined(ENABLE_FLAPPER_HACKS) + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_PepperConnectTcp, OnPepperConnectTcp) + IPC_MESSAGE_HANDLER(ViewHostMsg_PepperConnectTcpAddress, + OnPepperConnectTcpAddress) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP_EX() + return handled; +#else + return false; +#endif // ENABLE_FLAPPER_HACKS +} + +#if defined(ENABLE_FLAPPER_HACKS) + +namespace { + +bool ValidateNetAddress(const PP_Flash_NetAddress& addr) { + if (addr.size < sizeof(sa_family_t)) + return false; + + // TODO(viettrungluu): more careful validation? + // Just do a size check for AF_INET. + if (reinterpret_cast<const sockaddr*>(addr.data)->sa_family == AF_INET && + addr.size >= sizeof(sockaddr_in)) + return true; + + // Ditto for AF_INET6. + if (reinterpret_cast<const sockaddr*>(addr.data)->sa_family == AF_INET6 && + addr.size >= sizeof(sockaddr_in6)) + return true; + + // Reject everything else. + return false; +} + +PP_Flash_NetAddress SockaddrToNetAddress(const struct sockaddr* sa, + socklen_t sa_length) { + PP_Flash_NetAddress addr; + CHECK_LE(sa_length, sizeof(addr.data)); + addr.size = sa_length; + memcpy(addr.data, sa, addr.size); + return addr; +} + +int ConnectTcpSocket(const PP_Flash_NetAddress& addr, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out) { + *local_addr_out = kInvalidNetAddress; + *remote_addr_out = kInvalidNetAddress; + + const struct sockaddr* sa = + reinterpret_cast<const struct sockaddr*>(addr.data); + socklen_t sa_len = addr.size; + int fd = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP); + if (fd == -1) + return -1; + if (connect(fd, sa, sa_len) != 0) { + close(fd); + return -1; + } + + // Get the local address. + socklen_t local_length = sizeof(local_addr_out->data); + if (getsockname(fd, reinterpret_cast<struct sockaddr*>(local_addr_out->data), + &local_length) == -1 || + local_length > sizeof(local_addr_out->data)) { + close(fd); + return -1; + } + + // The remote address is just the address we connected to. + *remote_addr_out = addr; + + return fd; +} + +} // namespace + +class PepperMessageFilter::LookupRequest { + public: + LookupRequest(PepperMessageFilter* pepper_message_filter, + net::HostResolver* resolver, + int routing_id, + int request_id, + const net::HostResolver::RequestInfo& request_info) + : ALLOW_THIS_IN_INITIALIZER_LIST( + net_callback_(this, &LookupRequest::OnLookupFinished)), + pepper_message_filter_(pepper_message_filter), + resolver_(resolver), + routing_id_(routing_id), + request_id_(request_id), + request_info_(request_info) { + } + + void Start() { + int result = resolver_.Resolve(request_info_, &addresses_, &net_callback_, + net::BoundNetLog()); + if (result != net::ERR_IO_PENDING) + OnLookupFinished(result); + } + + private: + void OnLookupFinished(int /*result*/) { + pepper_message_filter_->PepperConnectTcpLookupFinished( + routing_id_, request_id_, addresses_); + delete this; + } + + // HostResolver will call us using this callback when resolution is complete. + net::CompletionCallbackImpl<LookupRequest> net_callback_; + + PepperMessageFilter* pepper_message_filter_; + net::SingleRequestHostResolver resolver_; + + int routing_id_; + int request_id_; + net::HostResolver::RequestInfo request_info_; + + net::AddressList addresses_; + + DISALLOW_COPY_AND_ASSIGN(LookupRequest); +}; + +void PepperMessageFilter::OnPepperConnectTcp( + int routing_id, + int request_id, + const std::string& host, + uint16 port) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + URLRequestContext* req_context = + profile_->GetRequestContext()->GetURLRequestContext(); + net::HostResolver::RequestInfo request_info(net::HostPortPair(host, port)); + + // The lookup request will delete itself on completion. + LookupRequest* lookup_request = + new LookupRequest(this, req_context->host_resolver(), + routing_id, request_id, request_info); + lookup_request->Start(); +} + +void PepperMessageFilter::OnPepperConnectTcpAddress( + int routing_id, + int request_id, + const PP_Flash_NetAddress& addr) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + // Validate the address and then continue (doing |connect()|) on a worker + // thread. + if (!ValidateNetAddress(addr) || + !base::WorkerPool::PostTask(FROM_HERE, + NewRunnableMethod( + this, + &PepperMessageFilter::PepperConnectTcpAddressOnWorkerThread, + routing_id, request_id, addr), + true)) { + SendPepperConnectTcpACKError(routing_id, request_id); + } +} + +bool PepperMessageFilter::SendPepperConnectTcpACKError(int routing_id, + int request_id) { + return Send(new ViewMsg_PepperConnectTcpACK( + routing_id, request_id, + IPC::InvalidPlatformFileForTransit(), + kInvalidNetAddress, kInvalidNetAddress)); +} + +void PepperMessageFilter::PepperConnectTcpLookupFinished( + int routing_id, + int request_id, + const net::AddressList& addresses) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + // If the lookup returned addresses, continue (doing |connect()|) on a worker + // thread. + if (!addresses.head() || + !base::WorkerPool::PostTask(FROM_HERE, + NewRunnableMethod( + this, + &PepperMessageFilter::PepperConnectTcpOnWorkerThread, + routing_id, request_id, addresses), + true)) { + SendPepperConnectTcpACKError(routing_id, request_id); + } +} + +void PepperMessageFilter::PepperConnectTcpOnWorkerThread( + int routing_id, + int request_id, + net::AddressList addresses) { + DCHECK(!MessageLoop::current()); // Check we are on a worker thread. + + IPC::PlatformFileForTransit socket_for_transit = + IPC::InvalidPlatformFileForTransit(); + PP_Flash_NetAddress local_addr = kInvalidNetAddress; + PP_Flash_NetAddress remote_addr = kInvalidNetAddress; + + for (const struct addrinfo* ai = addresses.head(); ai; ai = ai->ai_next) { + PP_Flash_NetAddress addr = SockaddrToNetAddress(ai->ai_addr, + ai->ai_addrlen); + int fd = ConnectTcpSocket(addr, &local_addr, &remote_addr); + if (fd != -1) { + socket_for_transit = base::FileDescriptor(fd, true); + break; + } + } + + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + NewRunnableMethod( + this, &PepperMessageFilter::Send, + new ViewMsg_PepperConnectTcpACK( + routing_id, request_id, + socket_for_transit, local_addr, remote_addr))); +} + +// TODO(vluu): Eliminate duplication between this and +// |PepperConnectTcpOnWorkerThread()|. +void PepperMessageFilter::PepperConnectTcpAddressOnWorkerThread( + int routing_id, + int request_id, + PP_Flash_NetAddress addr) { + DCHECK(!MessageLoop::current()); // Check we are on a worker thread. + + IPC::PlatformFileForTransit socket_for_transit = + IPC::InvalidPlatformFileForTransit(); + PP_Flash_NetAddress local_addr = kInvalidNetAddress; + PP_Flash_NetAddress remote_addr = kInvalidNetAddress; + + int fd = ConnectTcpSocket(addr, &local_addr, &remote_addr); + if (fd != -1) + socket_for_transit = base::FileDescriptor(fd, true); + + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + NewRunnableMethod( + this, &PepperMessageFilter::Send, + new ViewMsg_PepperConnectTcpACK( + routing_id, request_id, + socket_for_transit, local_addr, remote_addr))); +} + +#endif // ENABLE_FLAPPER_HACKS diff --git a/chrome/browser/renderer_host/pepper_message_filter.h b/chrome/browser/renderer_host/pepper_message_filter.h new file mode 100644 index 0000000..ec36c08 --- /dev/null +++ b/chrome/browser/renderer_host/pepper_message_filter.h @@ -0,0 +1,67 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_MESSAGE_FILTER_H_ +#define CHROME_BROWSER_RENDERER_HOST_PEPPER_MESSAGE_FILTER_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/process.h" +#include "chrome/browser/browser_message_filter.h" +#include "ipc/ipc_channel_proxy.h" +#include "ppapi/c/private/ppb_flash.h" + +class Profile; + +namespace net { +class AddressList; +} + +class PepperMessageFilter : public BrowserMessageFilter { + public: + explicit PepperMessageFilter(Profile* profile); + + private: + // BrowserMessageFilter methods. + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok); + +#if defined(ENABLE_FLAPPER_HACKS) + // Message handlers. + void OnPepperConnectTcp(int routing_id, + int request_id, + const std::string& host, + uint16 port); + void OnPepperConnectTcpAddress(int routing_id, + int request_id, + const PP_Flash_NetAddress& address); + + // |Send()| a |ViewMsg_PepperConnectTcpACK|, which reports an error. + bool SendPepperConnectTcpACKError(int routing_id, + int request_id); + + // Used by |OnPepperConnectTcp()| (below). + class LookupRequest; + friend class LookupRequest; + + // Continuation of |OnPepperConnectTcp()|. + void PepperConnectTcpLookupFinished(int routing_id, + int request_id, + const net::AddressList& addresses); + void PepperConnectTcpOnWorkerThread(int routing_id, + int request_id, + net::AddressList addresses); + + // Continuation of |OnPepperConnectTcpAddress()|. + void PepperConnectTcpAddressOnWorkerThread(int routing_id, + int request_id, + PP_Flash_NetAddress addr); +#endif // ENABLE_FLAPPER_HACKS + + Profile* profile_; +}; + +#endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_MESSAGE_FILTER_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1c62111..e01b64e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2166,6 +2166,8 @@ 'browser/renderer_host/offline_resource_handler.h', 'browser/renderer_host/pepper_file_message_filter.cc', 'browser/renderer_host/pepper_file_message_filter.h', + 'browser/renderer_host/pepper_message_filter.cc', + 'browser/renderer_host/pepper_message_filter.h', 'browser/renderer_host/redirect_to_file_resource_handler.cc', 'browser/renderer_host/redirect_to_file_resource_handler.h', 'browser/renderer_host/render_message_filter.cc', diff --git a/chrome/common/DEPS b/chrome/common/DEPS index a4256b3..cd9bd3f 100644 --- a/chrome/common/DEPS +++ b/chrome/common/DEPS @@ -5,6 +5,7 @@ include_rules = [ "+libxml", "+media/audio", "+media/base", + "+ppapi/c", # For various types. "+remoting/client/plugin", "+sandbox/src", "+skia", diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index c865a68..2519c7f 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,6 +17,7 @@ #include "media/audio/audio_buffers_state.h" #include "net/base/upload_data.h" #include "net/http/http_response_headers.h" +#include "ppapi/c/private/ppb_flash.h" #include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h" #include "third_party/skia/include/core/SkBitmap.h" #include "webkit/appcache/appcache_interfaces.h" @@ -39,7 +40,6 @@ namespace IPC { - template<> struct ParamTraits<WebMenuItem::Type> { typedef WebMenuItem::Type param_type; @@ -1236,4 +1236,33 @@ void ParamTraits<speech_input::SpeechInputResultItem>::Log(const param_type& p, l->append(")"); } +void ParamTraits<PP_Flash_NetAddress>::Write(Message* m, const param_type& p) { + WriteParam(m, p.size); + m->WriteBytes(p.data, p.size); +} + +bool ParamTraits<PP_Flash_NetAddress>::Read(const Message* m, + void** iter, + param_type* p) { + uint16 size; + if (!ReadParam(m, iter, &size)) + return false; + if (size > sizeof(p->data)) + return false; + p->size = size; + + const char* data; + if (!m->ReadBytes(iter, &data, size)) + return false; + memcpy(p->data, data, size); + return true; +} + +void ParamTraits<PP_Flash_NetAddress>::Log(const param_type& p, + std::string* l) { + l->append("<PP_Flash_NetAddress ("); + LogParam(p.size, l); + l->append(" bytes)>"); +} + } // namespace IPC diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index e06a667..258734a 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -61,7 +61,6 @@ struct ResourceLoadTimingInfo; struct ResourceResponseInfo; struct WebAccessibility; struct WebCookie; -struct WebAccessibility; } namespace webkit { @@ -79,6 +78,7 @@ class SkBitmap; class URLPattern; struct ContextMenuParams; struct EditCommand; +struct PP_Flash_NetAddress; struct ResourceResponseHead; struct SyncLoadResult; struct RendererPreferences; @@ -552,6 +552,14 @@ struct ParamTraits<speech_input::SpeechInputResultItem> { static void Log(const param_type& p, std::string* l); }; +template <> +struct ParamTraits<PP_Flash_NetAddress> { + typedef PP_Flash_NetAddress param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + } // namespace IPC #include "chrome/common/render_messages_internal.h" diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 999a72f..ce0851d 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -51,6 +51,7 @@ typedef std::map<std::string, std::string> SubstitutionMap; class Value; class GPUInfo; +struct PP_Flash_NetAddress; class SkBitmap; struct ThumbnailScore; class WebCursor; @@ -1075,6 +1076,13 @@ IPC_MESSAGE_ROUTED1(ViewMsg_SelectPopupMenuItem, IPC_MESSAGE_CONTROL1(ViewMsg_SpeechInput_SetFeatureEnabled, bool /* enabled */) +// The response to ViewHostMsg_PepperConnectTcp(Address). +IPC_MESSAGE_ROUTED4(ViewMsg_PepperConnectTcpACK, + int /* request_id */, + IPC::PlatformFileForTransit /* socket */, + PP_Flash_NetAddress /* local_addr */, + PP_Flash_NetAddress /* remote_addr */) + //----------------------------------------------------------------------------- // TabContents messages // These are messages sent from the renderer to the browser process. @@ -2630,3 +2638,16 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_ScriptEvalResponse, // Updates the content restrictions, i.e. to disable print/copy. IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateContentRestrictions, int /* restrictions */) + +// Pepper-related messages ----------------------------------------------------- + +IPC_MESSAGE_CONTROL4(ViewHostMsg_PepperConnectTcp, + int /* routing_id */, + int /* request_id */, + std::string /* host */, + uint16 /* port */) + +IPC_MESSAGE_CONTROL3(ViewHostMsg_PepperConnectTcpAddress, + int /* routing_id */, + int /* request_id */, + PP_Flash_NetAddress /* addr */) diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 31c5183..eba798a 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,6 +35,7 @@ #include "grit/locale_settings.h" #include "ipc/ipc_channel_handle.h" #include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/host_dispatcher.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" @@ -45,6 +46,7 @@ #include "webkit/plugins/ppapi/ppb_file_io_impl.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_flash_impl.h" #if defined(OS_MACOSX) #include "chrome/common/render_messages.h" @@ -767,6 +769,7 @@ base::PlatformFileError PepperPluginDelegateImpl::QueryModuleLocalFile( } return error; } + base::PlatformFileError PepperPluginDelegateImpl::GetModuleLocalDirContents( const std::string& module_name, const FilePath& path, @@ -789,6 +792,50 @@ PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { return RenderThread::current()->GetFileThreadMessageLoopProxy(); } +int32_t PepperPluginDelegateImpl::ConnectTcp( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const char* host, + uint16_t port) { + int request_id = pending_connect_tcps_.Add( + new scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl>(connector)); + IPC::Message* msg = + new ViewHostMsg_PepperConnectTcp(render_view_->routing_id(), + request_id, + std::string(host), + port); + if (!render_view_->Send(msg)) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; +} + +int32_t PepperPluginDelegateImpl::ConnectTcpAddress( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const struct PP_Flash_NetAddress* addr) { + int request_id = pending_connect_tcps_.Add( + new scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl>(connector)); + IPC::Message* msg = + new ViewHostMsg_PepperConnectTcpAddress(render_view_->routing_id(), + request_id, + *addr); + if (!render_view_->Send(msg)) + return PP_ERROR_FAILED; + + return PP_ERROR_WOULDBLOCK; +} + +void PepperPluginDelegateImpl::OnConnectTcpACK( + int request_id, + base::PlatformFile socket, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr) { + scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl> connector = + *pending_connect_tcps_.Lookup(request_id); + pending_connect_tcps_.Remove(request_id); + + connector->CompleteConnectTcp(socket, local_addr, remote_addr); +} + webkit::ppapi::FullscreenContainer* PepperPluginDelegateImpl::CreateFullscreenContainer( webkit::ppapi::PluginInstance* instance) { diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index cd732fe..b4d7424 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -141,6 +141,19 @@ class PepperPluginDelegateImpl const FilePath& path, webkit::ppapi::DirContents* contents); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); + virtual int32_t ConnectTcp( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const char* host, + uint16_t port); + virtual int32_t ConnectTcpAddress( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const struct PP_Flash_NetAddress* addr); + // This is the completion for both |ConnectTcp()| and |ConnectTcpAddress()|. + void OnConnectTcpACK( + int request_id, + base::PlatformFile socket, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr); virtual webkit::ppapi::FullscreenContainer* CreateFullscreenContainer( webkit::ppapi::PluginInstance* instance); @@ -157,9 +170,14 @@ class PepperPluginDelegateImpl std::set<webkit::ppapi::PluginInstance*> active_instances_; + // TODO(viettrungluu): Get rid of |id_generator_| -- just use |IDMap::Add()|. + // Rename |messages_waiting_replies_| (to specify async open file). int id_generator_; IDMap<AsyncOpenFileCallback> messages_waiting_replies_; + IDMap<scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl>, + IDMapOwnPointer> pending_connect_tcps_; + DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl); }; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 791476d..e9b6e18 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -109,6 +109,7 @@ #include "net/base/escape.h" #include "net/base/net_errors.h" #include "net/http/http_util.h" +#include "ppapi/c/private/ppb_flash.h" #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" @@ -1093,6 +1094,9 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, OnAccessibilityNotificationsAck) IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) +#if defined(ENABLE_FLAPPER_HACKS) + IPC_MESSAGE_HANDLER(ViewMsg_PepperConnectTcpACK, OnConnectTcpACK) +#endif #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) #endif @@ -5752,3 +5756,17 @@ void RenderView::AddErrorToRootConsole(const string16& message) { WebConsoleMessage(WebConsoleMessage::LevelError, message)); } } + +#if defined(ENABLE_FLAPPER_HACKS) +void RenderView::OnConnectTcpACK( + int request_id, + IPC::PlatformFileForTransit socket_for_transit, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr) { + pepper_delegate_.OnConnectTcpACK( + request_id, + IPC::PlatformFileForTransitToPlatformFile(socket_for_transit), + local_addr, + remote_addr); +} +#endif diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 897a964..10d45cd 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -81,6 +81,7 @@ class SpeechInputDispatcher; class WebPluginDelegatePepper; class WebPluginDelegateProxy; struct ContextMenuMediaParams; +struct PP_Flash_NetAddress; struct ThumbnailScore; struct ViewMsg_ClosePage_Params; struct ViewMsg_Navigate_Params; @@ -834,6 +835,9 @@ class RenderView : public RenderWidget, const WebKit::WebConsoleMessage::Level&); void OnAdvanceToNextMisspelling(); void OnAllowScriptToClose(bool script_can_close); + void OnAsyncFileOpened(base::PlatformFileError error_code, + IPC::PlatformFileForTransit file_for_transit, + int message_id); void OnAutocompleteSuggestionsReturned( int query_id, const std::vector<string16>& suggestions, @@ -849,6 +853,12 @@ class RenderView : public RenderWidget, void OnCancelDownload(int32 download_id); void OnClearFocusedNode(); void OnClosePage(const ViewMsg_ClosePage_Params& params); +#if defined(ENABLE_FLAPPER_HACKS) + void OnConnectTcpACK(int request_id, + IPC::PlatformFileForTransit socket_for_transit, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr); +#endif void OnCopy(); void OnCopyImageAt(int x, int y); #if defined(OS_MACOSX) @@ -978,10 +988,6 @@ class RenderView : public RenderWidget, #endif void OnZoom(PageZoom::Function function); - void OnAsyncFileOpened(base::PlatformFileError error_code, - IPC::PlatformFileForTransit file_for_transit, - int message_id); - // Adding a new message handler? Please add it in alphabetical order above // and put it in the same position in the .cc file. diff --git a/ppapi/c/private/ppb_flash.h b/ppapi/c/private/ppb_flash.h index ccc2f0a..49535e4 100644 --- a/ppapi/c/private/ppb_flash.h +++ b/ppapi/c/private/ppb_flash.h @@ -17,7 +17,9 @@ #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_var.h" -#define PPB_FLASH_INTERFACE "PPB_Flash;1" +// PPB_Flash ------------------------------------------------------------------- + +#define PPB_FLASH_INTERFACE "PPB_Flash;2" #ifdef _WIN32 typedef HANDLE PP_FileHandle; @@ -27,6 +29,7 @@ typedef int PP_FileHandle; static const PP_FileHandle PP_kInvalidFileHandle = -1; #endif +struct PP_CompletionCallback; struct PP_FontDescription_Dev; struct PP_FileInfo_Dev; @@ -114,4 +117,39 @@ struct PPB_Flash { const char* target); }; +// PPB_Flash_NetConnector ------------------------------------------------------ + +#define PPB_FLASH_NETCONNECTOR_INTERFACE "PPB_Flash_NetConnector;1" + +// This is an opaque type holding a network address. +struct PP_Flash_NetAddress { + size_t size; + char data[128]; +}; + +struct PPB_Flash_NetConnector { + PP_Resource (*Create)(PP_Instance instance_id); + PP_Bool (*IsFlashNetConnector)(PP_Resource resource_id); + + // Connect to a TCP port given as a host-port pair. The local and remote + // addresses of the connection (if successful) are returned in + // |local_addr_out| and |remote_addr_out|, respectively, if non-null. + int32_t (*ConnectTcp)(PP_Resource connector_id, + const char* host, + uint16_t port, + PP_FileHandle* socket_out, + struct PP_Flash_NetAddress* local_addr_out, + struct PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback); + + // Same as |ConnectTcp()|, but connecting to the address given by |addr|. A + // typical use-case would be for reconnections. + int32_t (*ConnectTcpAddress)(PP_Resource connector_id, + const struct PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + struct PP_Flash_NetAddress* local_addr_out, + struct PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback); +}; + #endif // PPAPI_C_PRIVATE_PPB_FLASH_H_ diff --git a/ppapi/cpp/private/flash.cc b/ppapi/cpp/private/flash.cc new file mode 100644 index 0000000..5af96bc --- /dev/null +++ b/ppapi/cpp/private/flash.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(viettrungluu): See the comment in corresponding .h file. + +#include "ppapi/cpp/private/flash.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_NetConnector>() { + return PPB_FLASH_NETCONNECTOR_INTERFACE; +} + +} // namespace + +namespace flash { + +NetConnector::NetConnector(const Instance& instance) { + if (has_interface<PPB_Flash_NetConnector>()) { + PassRefFromConstructor(get_interface<PPB_Flash_NetConnector>()->Create( + instance.pp_instance())); + } +} + +int32_t NetConnector::ConnectTcp(const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + const CompletionCallback& cc) { + if (!has_interface<PPB_Flash_NetConnector>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_Flash_NetConnector>()->ConnectTcp( + pp_resource(), + host, port, + socket_out, local_addr_out, remote_addr_out, + cc.pp_completion_callback()); +} + +int32_t NetConnector::ConnectTcpAddress(const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + const CompletionCallback& cc) { + if (!has_interface<PPB_Flash_NetConnector>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_Flash_NetConnector>()->ConnectTcpAddress( + pp_resource(), + addr, + socket_out, local_addr_out, remote_addr_out, + cc.pp_completion_callback()); +} + +} // namespace flash +} // namespace pp diff --git a/ppapi/cpp/private/flash.h b/ppapi/cpp/private/flash.h new file mode 100644 index 0000000..ffd1353 --- /dev/null +++ b/ppapi/cpp/private/flash.h @@ -0,0 +1,42 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(viettrungluu): This (and the .cc file) contain C++ wrappers for some +// things in ppapi/c/private/ppb_flash.h. This is currently not used in (or even +// compiled with) Chromium. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_H_ +#define PPAPI_CPP_PRIVATE_FLASH_H_ + +#include "ppapi/c/private/ppb_flash.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class Instance; + +namespace flash { + +class NetConnector : public Resource { + public: + explicit NetConnector(const Instance& instance); + + int32_t ConnectTcp(const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + const CompletionCallback& cc); + int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + const CompletionCallback& cc); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_H_ diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 93ace2c..2a96571 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -5,6 +5,7 @@ #include "webkit/plugins/ppapi/mock_plugin_delegate.h" #include "base/message_loop_proxy.h" +#include "ppapi/c/pp_errors.h" namespace webkit { namespace ppapi { @@ -159,6 +160,19 @@ MockPluginDelegate::GetFileThreadMessageLoopProxy() { return scoped_refptr<base::MessageLoopProxy>(); } +int32_t MockPluginDelegate::ConnectTcp( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const char* host, + uint16_t port) { + return PP_ERROR_FAILED; +} + +int32_t MockPluginDelegate::ConnectTcpAddress( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const struct PP_Flash_NetAddress* addr) { + return PP_ERROR_FAILED; +} + FullscreenContainer* MockPluginDelegate::CreateFullscreenContainer( PluginInstance* instance) { return NULL; diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 4f83a80..7037a96 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -83,6 +83,13 @@ class MockPluginDelegate : public PluginDelegate { DirContents* contents); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); + virtual int32_t ConnectTcp( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const char* host, + uint16_t port); + virtual int32_t ConnectTcpAddress( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const struct PP_Flash_NetAddress* addr); virtual FullscreenContainer* CreateFullscreenContainer( PluginInstance* instance); virtual std::string GetDefaultEncoding(); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 9feff6d..fd73c3a 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -52,6 +52,7 @@ class WebFileChooserCompletion; struct WebFileChooserParams; } +struct PP_Flash_NetAddress; struct PP_VideoCompressedDataBuffer_Dev; struct PP_VideoDecoderConfig_Dev; struct PP_VideoUncompressedDataBuffer_Dev; @@ -62,9 +63,10 @@ namespace webkit { namespace ppapi { class FileIO; +class FullscreenContainer; class PluginInstance; class PluginModule; -class FullscreenContainer; +class PPB_Flash_NetConnector_Impl; // Virtual interface that the browser implements to implement features for // PPAPI plugins. @@ -303,6 +305,14 @@ class PluginDelegate { virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy() = 0; + virtual int32_t ConnectTcp( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const char* host, + uint16_t port) = 0; + virtual int32_t ConnectTcpAddress( + webkit::ppapi::PPB_Flash_NetConnector_Impl* connector, + const struct PP_Flash_NetAddress* addr) = 0; + // Create a fullscreen container for a plugin instance. This effectively // switches the plugin to fullscreen. virtual FullscreenContainer* CreateFullscreenContainer( diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 11d0593..620fff6 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -296,6 +296,11 @@ const void* GetInterface(const char* name) { } #endif // ENABLE_GPU +#ifdef ENABLE_FLAPPER_HACKS + if (strcmp(name, PPB_FLASH_NETCONNECTOR_INTERFACE) == 0) + return PPB_Flash_NetConnector_Impl::GetInterface(); +#endif // ENABLE_FLAPPER_HACKS + // Only support the testing interface when the command line switch is // specified. This allows us to prevent people from (ab)using this interface // in production code. diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index f48a71b..8b1ff6c 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -12,7 +12,9 @@ #include "googleurl/src/gurl.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/dev/ppb_file_io_dev.h" +#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/private/ppb_flash.h" +#include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/error_util.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -22,6 +24,8 @@ namespace webkit { namespace ppapi { +// PPB_Flash_Impl -------------------------------------------------------------- + namespace { PluginInstance* GetSomeInstance(PP_Module pp_module) { @@ -241,6 +245,191 @@ const PPB_Flash* PPB_Flash_Impl::GetInterface() { return &ppb_flash; } +// PPB_Flash_NetConnector_Impl ------------------------------------------------- + +namespace { + +PP_Resource Create(PP_Instance instance_id) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); + if (!instance) + return 0; + + scoped_refptr<PPB_Flash_NetConnector_Impl> connector( + new PPB_Flash_NetConnector_Impl(instance)); + return connector->GetReference(); +} + +PP_Bool IsFlashNetConnector(PP_Resource resource) { + return BoolToPPBool(!!Resource::GetAs<PPB_Flash_NetConnector_Impl>(resource)); +} + +int32_t ConnectTcp(PP_Resource connector_id, + const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + scoped_refptr<PPB_Flash_NetConnector_Impl> connector( + Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id)); + if (!connector.get()) + return PP_ERROR_BADRESOURCE; + + return connector->ConnectTcp( + host, port, socket_out, local_addr_out, remote_addr_out, callback); +} + +int32_t ConnectTcpAddress(PP_Resource connector_id, + const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + scoped_refptr<PPB_Flash_NetConnector_Impl> connector( + Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id)); + if (!connector.get()) + return PP_ERROR_BADRESOURCE; + + return connector->ConnectTcpAddress( + addr, socket_out, local_addr_out, remote_addr_out, callback); +} + +const PPB_Flash_NetConnector ppb_flash_netconnector = { + &Create, + &IsFlashNetConnector, + &ConnectTcp, + &ConnectTcpAddress, +}; + +} // namespace + +PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl( + PluginInstance* instance) + : Resource(instance->module()), + instance_(instance) { +} + +PPB_Flash_NetConnector_Impl::~PPB_Flash_NetConnector_Impl() { +} + +// static +const PPB_Flash_NetConnector* PPB_Flash_NetConnector_Impl::GetInterface() { + return &ppb_flash_netconnector; +} + +PPB_Flash_NetConnector_Impl* + PPB_Flash_NetConnector_Impl::AsPPB_Flash_NetConnector_Impl() { + return this; +} + +int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( + const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + // |socket_out| is not optional. + if (!socket_out) + return PP_ERROR_BADARGUMENT; + + if (!callback.func) { + NOTIMPLEMENTED(); + return PP_ERROR_BADARGUMENT; + } + + if (callback_.get() && !callback_->completed()) + return PP_ERROR_INPROGRESS; + + PP_Resource resource_id = GetReferenceNoAddRef(); + if (!resource_id) { + NOTREACHED(); + return PP_ERROR_FAILED; + } + + int32_t rv = instance()->delegate()->ConnectTcp(this, host, port); + if (rv == PP_ERROR_WOULDBLOCK) { + // Record callback and output buffers. + callback_ = new TrackedCompletionCallback( + instance()->module()->GetCallbackTracker(), resource_id, callback); + socket_out_ = socket_out; + local_addr_out_ = local_addr_out; + remote_addr_out_ = remote_addr_out; + } else { + // This should never be completed synchronously successfully. + DCHECK_NE(rv, PP_OK); + } + return rv; +} + +int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( + const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + // |socket_out| is not optional. + if (!socket_out) + return PP_ERROR_BADARGUMENT; + + if (!callback.func) { + NOTIMPLEMENTED(); + return PP_ERROR_BADARGUMENT; + } + + if (callback_.get() && !callback_->completed()) + return PP_ERROR_INPROGRESS; + + PP_Resource resource_id = GetReferenceNoAddRef(); + if (!resource_id) { + NOTREACHED(); + return PP_ERROR_FAILED; + } + + int32_t rv = instance()->delegate()->ConnectTcpAddress(this, addr); + if (rv == PP_ERROR_WOULDBLOCK) { + // Record callback and output buffers. + callback_ = new TrackedCompletionCallback( + instance()->module()->GetCallbackTracker(), resource_id, callback); + socket_out_ = socket_out; + local_addr_out_ = local_addr_out; + remote_addr_out_ = remote_addr_out; + } else { + // This should never be completed synchronously successfully. + DCHECK_NE(rv, PP_OK); + } + return rv; +} + +void PPB_Flash_NetConnector_Impl::CompleteConnectTcp( + PP_FileHandle socket, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr) { + int32_t rv = PP_ERROR_ABORTED; + if (!callback_->aborted()) { + CHECK(!callback_->completed()); + + // Write output data. + *socket_out_ = socket; + if (socket != PP_kInvalidFileHandle) { + if (local_addr_out_) + *local_addr_out_ = local_addr; + if (remote_addr_out_) + *remote_addr_out_ = remote_addr; + rv = PP_OK; + } else { + rv = PP_ERROR_FAILED; + } + } + + callback_->Run(rv); // Will complete abortively if necessary. + + // Wipe everything out for safety. + callback_ = NULL; + socket_out_ = NULL; + local_addr_out_ = NULL; + remote_addr_out_ = NULL; +} + } // namespace ppapi } // namespace webkit - diff --git a/webkit/plugins/ppapi/ppb_flash_impl.h b/webkit/plugins/ppapi/ppb_flash_impl.h index 44ed224..25b20d0 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,14 +6,14 @@ #define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_IMPL_H_ #include "base/basictypes.h" +#include "base/ref_counted.h" #include "build/build_config.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/pp_rect.h" +#include "ppapi/c/private/ppb_flash.h" +#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/resource.h" -struct PP_FontDescription_Dev; -struct PPB_Flash; - namespace webkit { namespace ppapi { @@ -42,6 +42,52 @@ class PPB_Flash_Impl { DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Impl); }; +class PPB_Flash_NetConnector_Impl : public Resource { + public: + explicit PPB_Flash_NetConnector_Impl(PluginInstance* instance); + virtual ~PPB_Flash_NetConnector_Impl(); + + static const PPB_Flash_NetConnector* GetInterface(); + + // Resource override. + virtual PPB_Flash_NetConnector_Impl* AsPPB_Flash_NetConnector_Impl(); + + PluginInstance* instance() { return instance_; } + + // PPB_Flash_NetConnector implementation. + int32_t ConnectTcp(const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback); + int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback); + + // Called to complete |ConnectTcp()| and |ConnectTcpAddress()|. + void CompleteConnectTcp(PP_FileHandle socket, + const PP_Flash_NetAddress& local_addr, + const PP_Flash_NetAddress& remote_addr); + + private: + // Plugin instance this connector with which is associated. + PluginInstance* instance_; + + // Any pending callback (for |ConnectTcp()| or |ConnectTcpAddress()|). + scoped_refptr<TrackedCompletionCallback> callback_; + + // Output buffers to be filled in when the callback is completed successfully + // (|{local,remote}_addr_out| are optional and may be null). + PP_FileHandle* socket_out_; + PP_Flash_NetAddress* local_addr_out_; + PP_Flash_NetAddress* remote_addr_out_; + + DISALLOW_COPY_AND_ASSIGN(PPB_Flash_NetConnector_Impl); +}; + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/resource.h b/webkit/plugins/ppapi/resource.h index 28f19e3..d8114d0 100644 --- a/webkit/plugins/ppapi/resource.h +++ b/webkit/plugins/ppapi/resource.h @@ -26,6 +26,7 @@ namespace ppapi { F(PPB_FileIO_Impl) \ F(PPB_FileRef_Impl) \ F(PPB_FileSystem_Impl) \ + F(PPB_Flash_NetConnector_Impl) \ F(PPB_Font_Impl) \ F(PPB_Graphics2D_Impl) \ F(PPB_Graphics3D_Impl) \ |