| Index: content/browser/renderer_host/pepper/pepper_message_filter.cc
|
| diff --git a/content/browser/renderer_host/pepper/pepper_message_filter.cc b/content/browser/renderer_host/pepper/pepper_message_filter.cc
|
| index 717de350dc75d6085c3eafdd65054e4fd43d2414..698decfc58ed20fe428743e2803be8a81389b693 100644
|
| --- a/content/browser/renderer_host/pepper/pepper_message_filter.cc
|
| +++ b/content/browser/renderer_host/pepper/pepper_message_filter.cc
|
| @@ -6,110 +6,44 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| -#include "base/callback.h"
|
| -#include "base/compiler_specific.h"
|
| -#include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| -#include "base/memory/ref_counted.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| -#include "base/threading/sequenced_worker_pool.h"
|
| -#include "base/threading/worker_pool.h"
|
| -#include "build/build_config.h"
|
| #include "content/browser/renderer_host/pepper/pepper_socket_utils.h"
|
| -#include "content/browser/renderer_host/pepper/pepper_tcp_socket.h"
|
| #include "content/browser/renderer_host/render_process_host_impl.h"
|
| -#include "content/browser/renderer_host/render_view_host_impl.h"
|
| -#include "content/common/pepper_messages.h"
|
| -#include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/content_browser_client.h"
|
| -#include "content/public/browser/resource_context.h"
|
| #include "content/public/common/content_client.h"
|
| -#include "net/base/address_family.h"
|
| -#include "net/base/address_list.h"
|
| -#include "net/base/host_port_pair.h"
|
| -#include "net/base/sys_addrinfo.h"
|
| -#include "net/cert/cert_verifier.h"
|
| -#include "ppapi/c/pp_errors.h"
|
| -#include "ppapi/c/private/ppb_net_address_private.h"
|
| +#include "ppapi/c/private/ppb_network_list_private.h"
|
| #include "ppapi/proxy/ppapi_messages.h"
|
| #include "ppapi/shared_impl/api_id.h"
|
| #include "ppapi/shared_impl/private/net_address_private_impl.h"
|
| -#include "ppapi/shared_impl/socket_option_data.h"
|
|
|
| using ppapi::NetAddressPrivateImpl;
|
|
|
| namespace content {
|
| -namespace {
|
|
|
| -const size_t kMaxSocketsAllowed = 1024;
|
| -const uint32 kInvalidSocketID = 0;
|
| -
|
| -} // namespace
|
| -
|
| -PepperMessageFilter::PepperMessageFilter(int process_id,
|
| - BrowserContext* browser_context)
|
| - : plugin_type_(PLUGIN_TYPE_IN_PROCESS),
|
| - permissions_(),
|
| - process_id_(process_id),
|
| - external_plugin_render_view_id_(0),
|
| - resource_context_(browser_context->GetResourceContext()),
|
| - host_resolver_(NULL),
|
| - next_socket_id_(1) {
|
| - DCHECK(browser_context);
|
| - // Keep BrowserContext data in FILE-thread friendly storage.
|
| - browser_path_ = browser_context->GetPath();
|
| - incognito_ = browser_context->IsOffTheRecord();
|
| - DCHECK(resource_context_);
|
| +// static
|
| +PepperMessageFilter* PepperMessageFilter::CreateForRendererProcess() {
|
| + return new PepperMessageFilter(ppapi::PpapiPermissions(),
|
| + PLUGIN_TYPE_IN_PROCESS);
|
| }
|
|
|
| -PepperMessageFilter::PepperMessageFilter(
|
| - const ppapi::PpapiPermissions& permissions,
|
| - net::HostResolver* host_resolver)
|
| - : plugin_type_(PLUGIN_TYPE_OUT_OF_PROCESS),
|
| - permissions_(permissions),
|
| - process_id_(0),
|
| - external_plugin_render_view_id_(0),
|
| - resource_context_(NULL),
|
| - host_resolver_(host_resolver),
|
| - next_socket_id_(1),
|
| - incognito_(false) {
|
| - DCHECK(host_resolver);
|
| +// static
|
| +PepperMessageFilter* PepperMessageFilter::CreateForPpapiPluginProcess(
|
| + const ppapi::PpapiPermissions& permissions) {
|
| + return new PepperMessageFilter(permissions,
|
| + PLUGIN_TYPE_OUT_OF_PROCESS);
|
| }
|
|
|
| -PepperMessageFilter::PepperMessageFilter(
|
| - const ppapi::PpapiPermissions& permissions,
|
| - net::HostResolver* host_resolver,
|
| - int process_id,
|
| - int render_view_id)
|
| - : plugin_type_(PLUGIN_TYPE_EXTERNAL_PLUGIN),
|
| - permissions_(permissions),
|
| - process_id_(process_id),
|
| - external_plugin_render_view_id_(render_view_id),
|
| - resource_context_(NULL),
|
| - host_resolver_(host_resolver),
|
| - next_socket_id_(1) {
|
| - DCHECK(host_resolver);
|
| +// static
|
| +PepperMessageFilter* PepperMessageFilter::CreateForExternalPluginProcess(
|
| + const ppapi::PpapiPermissions& permissions) {
|
| + return new PepperMessageFilter(permissions,
|
| + PLUGIN_TYPE_EXTERNAL_PLUGIN);
|
| }
|
|
|
| bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg,
|
| bool* message_was_ok) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP_EX(PepperMessageFilter, msg, *message_was_ok)
|
| - // TCP messages.
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Create, OnTCPCreate)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_CreatePrivate,
|
| - OnTCPCreatePrivate)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Connect, OnTCPConnect)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_ConnectWithNetAddress,
|
| - OnTCPConnectWithNetAddress)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_SSLHandshake,
|
| - OnTCPSSLHandshake)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Read, OnTCPRead)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Write, OnTCPWrite)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_Disconnect, OnTCPDisconnect)
|
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPSocket_SetOption, OnTCPSetOption)
|
| -
|
| // NetworkMonitor messages.
|
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBNetworkMonitor_Start,
|
| OnNetworkMonitorStart)
|
| @@ -129,44 +63,11 @@ void PepperMessageFilter::OnIPAddressChanged() {
|
| GetAndSendNetworkList();
|
| }
|
|
|
| -net::HostResolver* PepperMessageFilter::GetHostResolver() {
|
| - return resource_context_ ?
|
| - resource_context_->GetHostResolver() : host_resolver_;
|
| -}
|
| -
|
| -net::CertVerifier* PepperMessageFilter::GetCertVerifier() {
|
| - if (!cert_verifier_)
|
| - cert_verifier_.reset(net::CertVerifier::CreateDefault());
|
| -
|
| - return cert_verifier_.get();
|
| -}
|
| -
|
| -net::TransportSecurityState* PepperMessageFilter::GetTransportSecurityState() {
|
| - if (!transport_security_state_)
|
| - transport_security_state_.reset(new net::TransportSecurityState);
|
| -
|
| - return transport_security_state_.get();
|
| -}
|
| -
|
| -uint32 PepperMessageFilter::AddAcceptedTCPSocket(
|
| - int32 routing_id,
|
| - uint32 plugin_dispatcher_id,
|
| - net::StreamSocket* socket) {
|
| - scoped_ptr<net::StreamSocket> s(socket);
|
| -
|
| - uint32 tcp_socket_id = GenerateSocketID();
|
| - if (tcp_socket_id != kInvalidSocketID) {
|
| - // Currently all TCP sockets created this way correspond to
|
| - // PPB_TCPSocket_Private.
|
| - tcp_sockets_[tcp_socket_id] = linked_ptr<PepperTCPSocket>(
|
| - new PepperTCPSocket(this,
|
| - routing_id,
|
| - plugin_dispatcher_id,
|
| - tcp_socket_id,
|
| - s.release(),
|
| - true /* private_api */));
|
| - }
|
| - return tcp_socket_id;
|
| +PepperMessageFilter::PepperMessageFilter(
|
| + const ppapi::PpapiPermissions& permissions,
|
| + PluginType plugin_type)
|
| + : plugin_type_(plugin_type),
|
| + permissions_(permissions) {
|
| }
|
|
|
| PepperMessageFilter::~PepperMessageFilter() {
|
| @@ -174,176 +75,6 @@ PepperMessageFilter::~PepperMessageFilter() {
|
| net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
|
| }
|
|
|
| -void PepperMessageFilter::OnTCPCreate(int32 routing_id,
|
| - uint32 plugin_dispatcher_id,
|
| - uint32* socket_id) {
|
| - CreateTCPSocket(routing_id, plugin_dispatcher_id, false, socket_id);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPCreatePrivate(int32 routing_id,
|
| - uint32 plugin_dispatcher_id,
|
| - uint32* socket_id) {
|
| - CreateTCPSocket(routing_id, plugin_dispatcher_id, true, socket_id);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPConnect(int32 routing_id,
|
| - uint32 socket_id,
|
| - const std::string& host,
|
| - uint16_t port) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - // This is only supported by PPB_TCPSocket_Private.
|
| - if (!iter->second->private_api()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - content::SocketPermissionRequest params(
|
| - content::SocketPermissionRequest::TCP_CONNECT, host, port);
|
| - BrowserThread::PostTaskAndReplyWithResult(
|
| - BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&PepperMessageFilter::CanUseSocketAPIs, this,
|
| - routing_id, params, true /* private_api */),
|
| - base::Bind(&PepperMessageFilter::DoTCPConnect, this,
|
| - routing_id, socket_id, host, port));
|
| -}
|
| -
|
| -void PepperMessageFilter::DoTCPConnect(int32 routing_id,
|
| - uint32 socket_id,
|
| - const std::string& host,
|
| - uint16_t port,
|
| - bool allowed) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - // Due to current permission check process (IO -> UI -> IO) some
|
| - // calls to the TCP socket interface can be intermixed (like
|
| - // Connect and Close). So, NOTREACHED() is not appropriate here.
|
| - return;
|
| - }
|
| -
|
| - if (routing_id == iter->second->routing_id() && allowed)
|
| - iter->second->Connect(host, port);
|
| - else
|
| - iter->second->SendConnectACKError(PP_ERROR_NOACCESS);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPConnectWithNetAddress(
|
| - int32 routing_id,
|
| - uint32 socket_id,
|
| - const PP_NetAddress_Private& net_addr) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - content::SocketPermissionRequest params =
|
| - pepper_socket_utils::CreateSocketPermissionRequest(
|
| - content::SocketPermissionRequest::TCP_CONNECT, net_addr);
|
| - BrowserThread::PostTaskAndReplyWithResult(
|
| - BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&PepperMessageFilter::CanUseSocketAPIs, this,
|
| - routing_id, params, iter->second->private_api()),
|
| - base::Bind(&PepperMessageFilter::DoTCPConnectWithNetAddress, this,
|
| - routing_id, socket_id, net_addr));
|
| -}
|
| -
|
| -void PepperMessageFilter::DoTCPConnectWithNetAddress(
|
| - int32 routing_id,
|
| - uint32 socket_id,
|
| - const PP_NetAddress_Private& net_addr,
|
| - bool allowed) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - // Due to current permission check process (IO -> UI -> IO) some
|
| - // calls to the TCP socket interface can be intermixed (like
|
| - // ConnectWithNetAddress and Close). So, NOTREACHED() is not
|
| - // appropriate here.
|
| - return;
|
| - }
|
| -
|
| - if (routing_id == iter->second->routing_id() && allowed)
|
| - iter->second->ConnectWithNetAddress(net_addr);
|
| - else
|
| - iter->second->SendConnectACKError(PP_ERROR_NOACCESS);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPSSLHandshake(
|
| - uint32 socket_id,
|
| - const std::string& server_name,
|
| - uint16_t server_port,
|
| - const std::vector<std::vector<char> >& trusted_certs,
|
| - const std::vector<std::vector<char> >& untrusted_certs) {
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - // This is only supported by PPB_TCPSocket_Private.
|
| - if (!iter->second->private_api()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - iter->second->SSLHandshake(server_name, server_port, trusted_certs,
|
| - untrusted_certs);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPRead(uint32 socket_id, int32_t bytes_to_read) {
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - iter->second->Read(bytes_to_read);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPWrite(uint32 socket_id,
|
| - const std::string& data) {
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - iter->second->Write(data);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPDisconnect(uint32 socket_id) {
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - // Destroying the TCPSocket instance will cancel any pending completion
|
| - // callback. From this point on, there won't be any messages associated with
|
| - // this socket sent to the plugin side.
|
| - tcp_sockets_.erase(iter);
|
| -}
|
| -
|
| -void PepperMessageFilter::OnTCPSetOption(uint32 socket_id,
|
| - PP_TCPSocket_Option name,
|
| - const ppapi::SocketOptionData& value) {
|
| - TCPSocketMap::iterator iter = tcp_sockets_.find(socket_id);
|
| - if (iter == tcp_sockets_.end()) {
|
| - NOTREACHED();
|
| - return;
|
| - }
|
| -
|
| - iter->second->SetOption(name, value);
|
| -}
|
| -
|
| void PepperMessageFilter::OnNetworkMonitorStart(uint32 plugin_dispatcher_id) {
|
| // Support all in-process plugins, and ones with "private" permissions.
|
| if (plugin_type_ != PLUGIN_TYPE_IN_PROCESS &&
|
| @@ -376,56 +107,8 @@ void PepperMessageFilter::OnX509CertificateParseDER(
|
| ppapi::PPB_X509Certificate_Fields* result) {
|
| if (der.size() == 0)
|
| *succeeded = false;
|
| - *succeeded = PepperTCPSocket::GetCertificateFields(&der[0], der.size(),
|
| - result);
|
| -}
|
| -
|
| -uint32 PepperMessageFilter::GenerateSocketID() {
|
| - // TODO(yzshen): Change to use Pepper resource ID as socket ID.
|
| - //
|
| - // Generate a socket ID. For each process which sends us socket requests, IDs
|
| - // of living sockets must be unique, to each socket type.
|
| - //
|
| - // However, it is safe to generate IDs based on the internal state of a single
|
| - // PepperSocketMessageHandler object, because for each plugin or renderer
|
| - // process, there is at most one PepperMessageFilter (in other words, at most
|
| - // one PepperSocketMessageHandler) talking to it.
|
| - if (tcp_sockets_.size() >= kMaxSocketsAllowed)
|
| - return kInvalidSocketID;
|
| -
|
| - uint32 socket_id = kInvalidSocketID;
|
| - do {
|
| - // Although it is unlikely, make sure that we won't cause any trouble when
|
| - // the counter overflows.
|
| - socket_id = next_socket_id_++;
|
| - } while (socket_id == kInvalidSocketID ||
|
| - tcp_sockets_.find(socket_id) != tcp_sockets_.end());
|
| -
|
| - return socket_id;
|
| -}
|
| -
|
| -bool PepperMessageFilter::CanUseSocketAPIs(
|
| - int32 render_id,
|
| - const content::SocketPermissionRequest& params,
|
| - bool private_api) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| -
|
| - // External plugins always get their own PepperMessageFilter, initialized with
|
| - // a render view id. Use this instead of the one that came with the message,
|
| - // which is actually an API ID.
|
| - bool external_plugin = false;
|
| - if (plugin_type_ == PLUGIN_TYPE_EXTERNAL_PLUGIN) {
|
| - external_plugin = true;
|
| - render_id = external_plugin_render_view_id_;
|
| - }
|
| -
|
| - RenderViewHostImpl* render_view_host =
|
| - RenderViewHostImpl::FromID(process_id_, render_id);
|
| -
|
| - return pepper_socket_utils::CanUseSocketAPIs(external_plugin,
|
| - private_api,
|
| - params,
|
| - render_view_host);
|
| + *succeeded =
|
| + pepper_socket_utils::GetCertificateFields(&der[0], der.size(), result);
|
| }
|
|
|
| void PepperMessageFilter::GetAndSendNetworkList() {
|
| @@ -475,17 +158,4 @@ void PepperMessageFilter::SendNetworkList(
|
| }
|
| }
|
|
|
| -void PepperMessageFilter::CreateTCPSocket(int32 routing_id,
|
| - uint32 plugin_dispatcher_id,
|
| - bool private_api,
|
| - uint32* socket_id) {
|
| - *socket_id = GenerateSocketID();
|
| - if (*socket_id == kInvalidSocketID)
|
| - return;
|
| -
|
| - tcp_sockets_[*socket_id] = linked_ptr<PepperTCPSocket>(
|
| - new PepperTCPSocket(this, routing_id, plugin_dispatcher_id, *socket_id,
|
| - private_api));
|
| -}
|
| -
|
| } // namespace content
|
|
|