Skip to content

Commit

Permalink
Build remoting for PNaCl
Browse files Browse the repository at this point in the history
BUG=276739
R=jamiewalch@chromium.org, rsleevi@chromium.org

Review URL: https://codereview.chromium.org/234023003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271343 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sergeyu@chromium.org committed May 19, 2014
1 parent efa6bb8 commit adc6cfd
Show file tree
Hide file tree
Showing 17 changed files with 419 additions and 19 deletions.
5 changes: 5 additions & 0 deletions jingle/jingle_nacl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
'sources': [
'<@(jingle_glue_sources)',
],
'sources!': [
'glue/chrome_async_socket.cc',
'glue/proxy_resolving_client_socket.cc',
'glue/xmpp_client_socket_factory.cc',
],
'dependencies': [
'../base/base_nacl.gyp:base_nacl',
'../native_client/tools.gyp:prep_toolchain',
Expand Down
1 change: 1 addition & 0 deletions net/net_nacl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'../native_client_sdk/native_client_sdk_untrusted.gyp:nacl_io_untrusted',
'../third_party/openssl/openssl_nacl.gyp:openssl_nacl',
'../url/url_nacl.gyp:url_nacl',
'net.gyp:net_derived_sources',
'net.gyp:net_resources',
],
'defines': [
Expand Down
43 changes: 32 additions & 11 deletions remoting/client/plugin/chromoting_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <string>
#include <vector>

#if defined(OS_NACL)
#include <sys/mount.h>
#include <nacl_io/nacl_io.h>
#endif

#include "base/bind.h"
#include "base/callback.h"
#include "base/json/json_reader.h"
Expand All @@ -21,7 +26,7 @@
#include "base/values.h"
#include "crypto/random.h"
#include "jingle/glue/thread_wrapper.h"
#include "media/base/media.h"
#include "media/base/yuv_convert.h"
#include "net/socket/ssl_server_socket.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/url_util_dev.h"
Expand Down Expand Up @@ -210,6 +215,24 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
use_async_pin_dialog_(false),
use_media_source_rendering_(false),
weak_factory_(this) {
#if defined(OS_NACL)
// In NaCl global resources need to be initialized differently because they
// are not shared with Chrome.
thread_task_runner_handle_.reset(
new base::ThreadTaskRunnerHandle(plugin_task_runner_));
thread_wrapper_.reset(
new jingle_glue::JingleThreadWrapper(plugin_task_runner_));
media::InitializeCPUSpecificYUVConversions();
#else
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
#endif

#if defined(OS_NACL)
nacl_io_init_ppapi(pp_instance, pp::Module::Get()->get_browser_interface());
mount("", "/etc", "memfs", 0, "");
mount("", "/usr", "memfs", 0, "");
#endif

RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);

Expand Down Expand Up @@ -264,18 +287,15 @@ bool ChromotingInstance::Init(uint32_t argc,

VLOG(1) << "Started ChromotingInstance::Init";

// Check to make sure the media library is initialized.
// http://crbug.com/91521.
if (!media::IsMediaLibraryInitialized()) {
LOG(ERROR) << "Media library not initialized.";
return false;
}

// Check that the calling content is part of an app or extension.
// Check that the calling content is part of an app or extension. This is only
// necessary for non-PNaCl version of the plugin. Also PPB_URLUtil_Dev doesn't
// work in NaCl at the moment so the check fails in NaCl builds.
#if !defined(OS_NACL)
if (!IsCallerAppOrExtension()) {
LOG(ERROR) << "Not an app or extension";
return false;
}
#endif

// Start all the threads.
context_.Start();
Expand Down Expand Up @@ -345,6 +365,9 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) {
void ChromotingInstance::DidChangeFocus(bool has_focus) {
DCHECK(plugin_task_runner_->BelongsToCurrentThread());

if (!IsConnected())
return;

input_handler_.DidChangeFocus(has_focus);
}

Expand Down Expand Up @@ -627,8 +650,6 @@ void ChromotingInstance::ConnectWithConfig(const ClientConfig& config,
const std::string& local_jid) {
DCHECK(plugin_task_runner_->BelongsToCurrentThread());

jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();

if (use_media_source_rendering_) {
video_renderer_.reset(new MediaSourceVideoRenderer(this));
} else {
Expand Down
7 changes: 7 additions & 0 deletions remoting/client/plugin/chromoting_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/thread_task_runner_handle.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_resource.h"
Expand Down Expand Up @@ -45,6 +46,10 @@ class Module;
class VarDictionary;
} // namespace pp

namespace jingle_glue {
class JingleThreadWrapper;
} // namespace jingle_glue

namespace webrtc {
class DesktopRegion;
class DesktopSize;
Expand Down Expand Up @@ -259,6 +264,8 @@ class ChromotingInstance :

PepperPluginThreadDelegate plugin_thread_delegate_;
scoped_refptr<PluginThreadTaskRunner> plugin_task_runner_;
scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
scoped_ptr<jingle_glue::JingleThreadWrapper> thread_wrapper_;
ClientContext context_;
scoped_ptr<VideoRenderer> video_renderer_;
scoped_ptr<PepperView> view_;
Expand Down
32 changes: 32 additions & 0 deletions remoting/client/plugin/pepper_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2014 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 "base/at_exit.h"
#include "base/compiler_specific.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "remoting/client/plugin/chromoting_instance.h"

namespace remoting {

class ChromotingModule : public pp::Module {
protected:
virtual pp::Instance* CreateInstance(PP_Instance instance) OVERRIDE {
pp::Instance* result = new ChromotingInstance(instance);
return result;
}
private:
base::AtExitManager at_exit_manager_;
};

} // namespace remoting

namespace pp {

// Factory function for your specialization of the Module object.
Module* CreateModule() {
return new remoting::ChromotingModule();
}

} // namespace pp
2 changes: 2 additions & 0 deletions remoting/protocol/jingle_session_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/run_loop.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "jingle/glue/thread_wrapper.h"
#include "net/socket/socket.h"
#include "net/socket/stream_socket.h"
#include "net/url_request/url_request_context_getter.h"
Expand Down Expand Up @@ -94,6 +95,7 @@ class JingleSessionTest : public testing::Test {
public:
JingleSessionTest() {
message_loop_.reset(new base::MessageLoopForIO());
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
}

// Helper method that handles OnIncomingSession().
Expand Down
2 changes: 0 additions & 2 deletions remoting/protocol/libjingle_transport_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/timer/timer.h"
#include "jingle/glue/channel_socket_adapter.h"
#include "jingle/glue/pseudotcp_adapter.h"
#include "jingle/glue/thread_wrapper.h"
#include "jingle/glue/utils.h"
#include "net/base/net_errors.h"
#include "remoting/base/constants.h"
Expand Down Expand Up @@ -424,7 +423,6 @@ LibjingleTransportFactory::LibjingleTransportFactory(
: signal_strategy_(signal_strategy),
port_allocator_(port_allocator.Pass()),
network_settings_(network_settings) {
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
}

LibjingleTransportFactory::~LibjingleTransportFactory() {
Expand Down
22 changes: 19 additions & 3 deletions remoting/protocol/ssl_hmac_channel_authenticator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_client_socket_openssl.h"
#include "net/socket/ssl_server_socket.h"
#include "net/ssl/ssl_config_service.h"
#include "remoting/base/rsa_key_pair.h"
Expand Down Expand Up @@ -63,6 +64,12 @@ void SslHmacChannelAuthenticator::SecureAndAuthenticate(

int result;
if (is_ssl_server()) {
#if defined(OS_NACL)
// Client plugin doesn't use server SSL sockets, and so SSLServerSocket
// implementation is not compiled for NaCl as part of net_nacl.
NOTREACHED();
result = net::ERR_FAILED;
#else
scoped_refptr<net::X509Certificate> cert =
net::X509Certificate::CreateFromBytes(
local_cert_.data(), local_cert_.length());
Expand All @@ -85,6 +92,7 @@ void SslHmacChannelAuthenticator::SecureAndAuthenticate(
result = raw_server_socket->Handshake(
base::Bind(&SslHmacChannelAuthenticator::OnConnected,
base::Unretained(this)));
#endif
} else {
transport_security_state_.reset(new net::TransportSecurityState);

Expand All @@ -104,11 +112,19 @@ void SslHmacChannelAuthenticator::SecureAndAuthenticate(
net::HostPortPair host_and_port(kSslFakeHostName, 0);
net::SSLClientSocketContext context;
context.transport_security_state = transport_security_state_.get();
scoped_ptr<net::ClientSocketHandle> connection(new net::ClientSocketHandle);
connection->SetSocket(socket.Pass());
scoped_ptr<net::ClientSocketHandle> socket_handle(
new net::ClientSocketHandle);
socket_handle->SetSocket(socket.Pass());

#if defined(OS_NACL)
// net_nacl doesn't include ClientSocketFactory.
socket_.reset(new net::SSLClientSocketOpenSSL(
socket_handle.Pass(), host_and_port, ssl_config, context));
#else
socket_ =
net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket(
connection.Pass(), host_and_port, ssl_config, context);
socket_handle.Pass(), host_and_port, ssl_config, context);
#endif

result = socket_->Connect(
base::Bind(&SslHmacChannelAuthenticator::OnConnected,
Expand Down
26 changes: 26 additions & 0 deletions remoting/remoting_client.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
'remoting_webapp_v1',
'remoting_webapp_v2',
],
'conditions': [
['disable_nacl==0 and disable_nacl_untrusted==0', {
'dependencies': [
'remoting_webapp_pnacl',
],
}],
],
}, # end of target 'remoting_webapp'

{
Expand All @@ -127,4 +134,23 @@
'includes': [ 'remoting_webapp.gypi', ],
}, # end of target 'remoting_webapp_v2'
], # end of targets

'conditions': [
['disable_nacl==0 and disable_nacl_untrusted==0', {
'targets': [
{
'target_name': 'remoting_webapp_pnacl',
'type': 'none',
'variables': {
'output_dir': '<(PRODUCT_DIR)/remoting/remoting.webapp.pnacl',
'zip_path': '<(PRODUCT_DIR)/remoting-webapp-pnacl.zip',
'extra_files': [ 'webapp/background.js' ],
'webapp_type': 'v2_pnacl',
},
'includes': [ 'remoting_webapp.gypi', ],
}, # end of target 'remoting_webapp_pnacl'
],
}],
],

}
Loading

0 comments on commit adc6cfd

Please sign in to comment.