Skip to content

Commit

Permalink
TCPSockets are switched to the new Pepper proxy.
Browse files Browse the repository at this point in the history
BUG=230784
TEST=browser_tests:*TCPSocket*, *TCPServerSocket*

Review URL: https://chromiumcodereview.appspot.com/22923014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220073 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ygorshenin@chromium.org committed Aug 28, 2013
1 parent a23bccf commit 8522332
Show file tree
Hide file tree
Showing 61 changed files with 1,870 additions and 2,184 deletions.
1 change: 0 additions & 1 deletion chrome/browser/nacl_host/nacl_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ void NaClProcessHost::OnPpapiChannelCreated(
permissions_,
process_->GetData().handle,
ipc_proxy_channel_.get(),
nacl_host_message_filter_->GetHostResolver(),
nacl_host_message_filter_->render_process_id(),
render_view_id_,
profile_directory_));
Expand Down
2 changes: 0 additions & 2 deletions chrome/test/ppapi/ppapi_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,9 @@ IN_PROC_BROWSER_TEST_F(PPAPINaClPNaClTest, TCPSocket) {
}

TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate)
TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate)
TEST_PPAPI_NACL_WITH_SSL_SERVER(TCPSocketPrivate)

TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivateTrusted)
TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(TCPSocketPrivateTrusted)

// UDPSocket tests.
// UDPSocket_Broadcast is disabled for OSX because it requires root permissions
Expand Down
8 changes: 3 additions & 5 deletions content/browser/plugin_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess(
PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
int render_process_id,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
PpapiPluginProcessHost::PluginClient* client) {
const base::FilePath& profile_data_directory) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));

if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
Expand All @@ -356,8 +355,7 @@ PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(

// This plugin isn't loaded by any plugin process, so create a new process.
return PpapiPluginProcessHost::CreatePluginHost(
*info, profile_data_directory,
client->GetResourceContext()->GetHostResolver());
*info, profile_data_directory);
}

PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
Expand Down Expand Up @@ -413,7 +411,7 @@ void PluginServiceImpl::OpenChannelToPpapiPlugin(
const base::FilePath& profile_data_directory,
PpapiPluginProcessHost::PluginClient* client) {
PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
render_process_id, plugin_path, profile_data_directory, client);
render_process_id, plugin_path, profile_data_directory);
if (plugin_host) {
plugin_host->OpenChannelToPlugin(client);
} else {
Expand Down
3 changes: 1 addition & 2 deletions content/browser/plugin_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ class CONTENT_EXPORT PluginServiceImpl
PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
int render_process_id,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
PpapiPluginProcessHost::PluginClient* client);
const base::FilePath& profile_data_directory);
PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess(
int render_process_id, const base::FilePath& plugin_path);

Expand Down
17 changes: 6 additions & 11 deletions content/browser/ppapi_plugin_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ PpapiPluginProcessHost::~PpapiPluginProcessHost() {
// static
PpapiPluginProcessHost* PpapiPluginProcessHost::CreatePluginHost(
const PepperPluginInfo& info,
const base::FilePath& profile_data_directory,
net::HostResolver* host_resolver) {
const base::FilePath& profile_data_directory) {
PpapiPluginProcessHost* plugin_host = new PpapiPluginProcessHost(
info, profile_data_directory, host_resolver);
info, profile_data_directory);
if (plugin_host->Init(info))
return plugin_host;

Expand Down Expand Up @@ -206,22 +205,19 @@ void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) {

PpapiPluginProcessHost::PpapiPluginProcessHost(
const PepperPluginInfo& info,
const base::FilePath& profile_data_directory,
net::HostResolver* host_resolver)
const base::FilePath& profile_data_directory)
: permissions_(
ppapi::PpapiPermissions::GetForCommandLine(info.permissions)),
profile_data_directory_(profile_data_directory),
is_broker_(false) {
process_.reset(new BrowserChildProcessHostImpl(
PROCESS_TYPE_PPAPI_PLUGIN, this));

filter_ = new PepperMessageFilter(permissions_, host_resolver);

host_impl_.reset(new BrowserPpapiHostImpl(this, permissions_, info.name,
info.path, profile_data_directory,
false,
filter_));
false));

filter_ = PepperMessageFilter::CreateForPpapiPluginProcess(permissions_);
process_->GetHost()->AddFilter(filter_.get());
process_->GetHost()->AddFilter(host_impl_->message_filter().get());

Expand All @@ -243,8 +239,7 @@ PpapiPluginProcessHost::PpapiPluginProcessHost()
host_impl_.reset(new BrowserPpapiHostImpl(this, permissions,
std::string(), base::FilePath(),
base::FilePath(),
false,
NULL));
false));
}

bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) {
Expand Down
10 changes: 2 additions & 8 deletions content/browser/ppapi_plugin_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
#include "ipc/ipc_sender.h"
#include "ppapi/shared_impl/ppapi_permissions.h"

namespace net {
class HostResolver;
}

namespace content {
class BrowserChildProcessHostImpl;
class ResourceContext;
Expand Down Expand Up @@ -76,8 +72,7 @@ class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate,

static PpapiPluginProcessHost* CreatePluginHost(
const PepperPluginInfo& info,
const base::FilePath& profile_data_directory,
net::HostResolver* host_resolver);
const base::FilePath& profile_data_directory);
static PpapiPluginProcessHost* CreateBrokerHost(
const PepperPluginInfo& info);

Expand Down Expand Up @@ -122,8 +117,7 @@ class PpapiPluginProcessHost : public BrowserChildProcessHostDelegate,
// Constructors for plugin and broker process hosts, respectively.
// You must call Init before doing anything else.
PpapiPluginProcessHost(const PepperPluginInfo& info,
const base::FilePath& profile_data_directory,
net::HostResolver* host_resolver);
const base::FilePath& profile_data_directory);
PpapiPluginProcessHost();

// Actually launches the process with the given plugin info. Returns true
Expand Down
21 changes: 8 additions & 13 deletions content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"

#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
#include "content/browser/tracing/trace_message_filter.h"
#include "content/common/pepper_renderer_instance_data.h"
#include "content/public/browser/render_view_host.h"
Expand All @@ -18,23 +19,17 @@ BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess(
ppapi::PpapiPermissions permissions,
base::ProcessHandle plugin_child_process,
IPC::ChannelProxy* channel,
net::HostResolver* host_resolver,
int render_process_id,
int render_view_id,
const base::FilePath& profile_directory) {
scoped_refptr<PepperMessageFilter> pepper_message_filter(
new PepperMessageFilter(permissions,
host_resolver,
render_process_id,
render_view_id));

// The plugin name and path shouldn't be needed for external plugins.
BrowserPpapiHostImpl* browser_ppapi_host =
new BrowserPpapiHostImpl(sender, permissions, std::string(),
base::FilePath(), profile_directory, true,
pepper_message_filter);
base::FilePath(), profile_directory, true);
browser_ppapi_host->set_plugin_process_handle(plugin_child_process);

scoped_refptr<PepperMessageFilter> pepper_message_filter(
PepperMessageFilter::CreateForExternalPluginProcess(permissions));
channel->AddFilter(pepper_message_filter);
channel->AddFilter(browser_ppapi_host->message_filter().get());
channel->AddFilter(new TraceMessageFilter());
Expand All @@ -48,17 +43,17 @@ BrowserPpapiHostImpl::BrowserPpapiHostImpl(
const std::string& plugin_name,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
bool external_plugin,
const scoped_refptr<PepperMessageFilter>& pepper_message_filter)
bool external_plugin)
: ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)),
plugin_process_handle_(base::kNullProcessHandle),
plugin_name_(plugin_name),
plugin_path_(plugin_path),
profile_data_directory_(profile_data_directory),
external_plugin_(external_plugin) {
external_plugin_(external_plugin),
ssl_context_helper_(new SSLContextHelper()) {
message_filter_ = new HostMessageFilter(ppapi_host_.get());
ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
new ContentBrowserPepperHostFactory(this, pepper_message_filter)));
new ContentBrowserPepperHostFactory(this)));
}

BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
Expand Down
13 changes: 8 additions & 5 deletions content/browser/renderer_host/pepper/browser_ppapi_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "content/browser/renderer_host/pepper/content_browser_pepper_host_factory.h"
#include "content/browser/renderer_host/pepper/pepper_message_filter.h"
#include "content/browser/renderer_host/pepper/ssl_context_helper.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/common/process_type.h"
Expand All @@ -37,10 +37,7 @@ class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
const std::string& plugin_name,
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory,
bool external_plugin,
// TODO (ygorshenin@): remove this once TCP sockets are
// converted to the new design.
const scoped_refptr<PepperMessageFilter>& pepper_message_filter);
bool external_plugin);
virtual ~BrowserPpapiHostImpl();

// BrowserPpapiHost.
Expand Down Expand Up @@ -73,6 +70,10 @@ class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
return message_filter_;
}

const scoped_refptr<SSLContextHelper>& ssl_context_helper() const {
return ssl_context_helper_;
}

private:
friend class BrowserPpapiHostTest;

Expand Down Expand Up @@ -104,6 +105,8 @@ class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost {
// BrowserPpapiHost::CreateExternalPluginProcess.
bool external_plugin_;

scoped_refptr<SSLContextHelper> ssl_context_helper_;

// Tracks all PP_Instances in this plugin and associated renderer-related
// data.
typedef std::map<PP_Instance, PepperRendererInstanceData> InstanceMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ BrowserPpapiHostTest::BrowserPpapiHostTest()
std::string(),
base::FilePath(),
base::FilePath(),
false,
NULL));
false));
ppapi_host_->set_plugin_process_handle(base::GetCurrentProcessHandle());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h"
#include "content/browser/renderer_host/pepper/pepper_printing_host.h"
#include "content/browser/renderer_host/pepper/pepper_tcp_server_socket_message_filter.h"
#include "content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter.h"
#include "content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h"
#include "content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h"
#include "net/socket/stream_socket.h"
#include "ppapi/host/message_filter_host.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/host/resource_host.h"
Expand All @@ -36,18 +38,17 @@ const size_t kMaxSocketsAllowed = 1024;

bool CanCreateSocket() {
return
PepperUDPSocketMessageFilter::GetNumInstances() +
PepperTCPServerSocketMessageFilter::GetNumInstances() <
PepperTCPServerSocketMessageFilter::GetNumInstances() +
PepperTCPSocketMessageFilter::GetNumInstances() +
PepperUDPSocketMessageFilter::GetNumInstances() <
kMaxSocketsAllowed;
}

} // namespace

ContentBrowserPepperHostFactory::ContentBrowserPepperHostFactory(
BrowserPpapiHostImpl* host,
const scoped_refptr<PepperMessageFilter>& pepper_message_filter)
: host_(host),
pepper_message_filter_(pepper_message_filter) {
BrowserPpapiHostImpl* host)
: host_(host) {
}

ContentBrowserPepperHostFactory::~ContentBrowserPepperHostFactory() {
Expand Down Expand Up @@ -102,6 +103,18 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost(
return scoped_ptr<ResourceHost>(new PepperFileRefHost(
host_, instance, params.pp_resource(), file_system, internal_path));
}
case PpapiHostMsg_TCPSocket_Create::ID: {
if (CanCreateSocket()) {
scoped_refptr<ResourceMessageFilter> tcp_socket(
new PepperTCPSocketMessageFilter(host_,
instance,
false));
return scoped_ptr<ResourceHost>(new MessageFilterHost(
host_->GetPpapiHost(), instance, params.pp_resource(), tcp_socket));
} else {
return scoped_ptr<ResourceHost>();
}
}
case PpapiHostMsg_UDPSocket_Create::ID: {
if (CanCreateSocket()) {
scoped_refptr<ResourceMessageFilter> udp_socket(
Expand Down Expand Up @@ -155,15 +168,26 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost(
if (message.type() == PpapiHostMsg_TCPServerSocket_CreatePrivate::ID) {
if (CanCreateSocket()) {
scoped_refptr<ResourceMessageFilter> tcp_server_socket(
new PepperTCPServerSocketMessageFilter(host_, instance, true,
pepper_message_filter_));
new PepperTCPServerSocketMessageFilter(this, host_, instance, true));
return scoped_ptr<ResourceHost>(new MessageFilterHost(
host_->GetPpapiHost(), instance, params.pp_resource(),
tcp_server_socket));
} else {
return scoped_ptr<ResourceHost>();
}
}
if (message.type() == PpapiHostMsg_TCPSocket_CreatePrivate::ID) {
if (CanCreateSocket()) {
scoped_refptr<ResourceMessageFilter> tcp_socket(
new PepperTCPSocketMessageFilter(host_,
instance,
true));
return scoped_ptr<ResourceHost>(new MessageFilterHost(
host_->GetPpapiHost(), instance, params.pp_resource(), tcp_socket));
} else {
return scoped_ptr<ResourceHost>();
}
}
if (message.type() == PpapiHostMsg_UDPSocket_CreatePrivate::ID) {
if (CanCreateSocket()) {
scoped_refptr<ResourceMessageFilter> udp_socket(
Expand Down Expand Up @@ -191,6 +215,24 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost(
return scoped_ptr<ResourceHost>();
}

scoped_ptr<ppapi::host::ResourceHost>
ContentBrowserPepperHostFactory::CreateAcceptedTCPSocket(
PP_Instance instance,
bool private_api,
net::StreamSocket* socket) {
scoped_ptr<net::StreamSocket> s(socket);

if (!CanCreateSocket())
return scoped_ptr<ResourceHost>();
scoped_refptr<ResourceMessageFilter> tcp_socket(
new PepperTCPSocketMessageFilter(host_,
instance,
private_api,
s.release()));
return scoped_ptr<ResourceHost>(new MessageFilterHost(
host_->GetPpapiHost(), instance, 0, tcp_socket));
}

const ppapi::PpapiPermissions&
ContentBrowserPepperHostFactory::GetPermissions() const {
return host_->GetPpapiHost()->permissions();
Expand Down
Loading

0 comments on commit 8522332

Please sign in to comment.