Skip to content

Commit

Permalink
[Chromoting] Add plumbing to carry clipboard events from the host to …
Browse files Browse the repository at this point in the history
…the client.

BUG=117473


Review URL: http://codereview.chromium.org/9921034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130023 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
simonmorris@chromium.org committed Mar 31, 2012
1 parent e67453f commit ba6d1c2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 16 deletions.
8 changes: 7 additions & 1 deletion remoting/client/chromoting_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) {

connection_->Connect(xmpp_proxy, config_.local_jid, config_.host_jid,
config_.host_public_key, authenticator.Pass(),
this, this, this);
this, this, this, this);

if (!view_->Initialize()) {
ClientDone();
Expand Down Expand Up @@ -104,6 +104,12 @@ ChromotingStats* ChromotingClient::GetStats() {
return &stats_;
}

void ChromotingClient::InjectClipboardEvent(
const protocol::ClipboardEvent& event) {
// TODO(simonmorris): Pass the clipboard event to the webapp.
return;
}

void ChromotingClient::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
const base::Closure& done) {
DCHECK(message_loop()->BelongsToCurrentThread());
Expand Down
6 changes: 6 additions & 0 deletions remoting/client/chromoting_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "remoting/client/chromoting_stats.h"
#include "remoting/client/chromoting_view.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/input_stub.h"
#include "remoting/protocol/video_stub.h"
Expand All @@ -31,6 +32,7 @@ class RectangleUpdateDecoder;
// TODO(sergeyu): Move VideoStub implementation to RectangleUpdateDecoder.
class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
public protocol::ClientStub,
public protocol::ClipboardStub,
public protocol::VideoStub {
public:
// Objects passed in are not owned by this class.
Expand All @@ -49,6 +51,10 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
// Return the stats recorded by this client.
ChromotingStats* GetStats();

// ClipboardStub implementation.
virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event)
OVERRIDE;

// ConnectionToHost::HostEventCallback implementation.
virtual void OnConnectionState(
protocol::ConnectionToHost::State state,
Expand Down
9 changes: 8 additions & 1 deletion remoting/protocol/client_control_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace protocol {
ClientControlDispatcher::ClientControlDispatcher()
: ChannelDispatcherBase(kControlChannelName),
client_stub_(NULL),
clipboard_stub_(NULL),
writer_(new BufferedSocketWriter(base::MessageLoopProxy::current())) {
}

Expand All @@ -45,8 +46,14 @@ void ClientControlDispatcher::InjectClipboardEvent(
void ClientControlDispatcher::OnMessageReceived(
scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
DCHECK(client_stub_);
DCHECK(clipboard_stub_);
base::ScopedClosureRunner done_runner(done_task);
LOG(WARNING) << "Unknown control message received.";

if (message->has_clipboard_event()) {
clipboard_stub_->InjectClipboardEvent(message->clipboard_event());
} else {
LOG(WARNING) << "Unknown control message received.";
}
}

} // namespace protocol
Expand Down
16 changes: 11 additions & 5 deletions remoting/protocol/client_control_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class BufferedSocketWriter;
class Session;

// ClientControlDispatcher dispatches incoming messages on the control
// channel to ClientStub, and also implements ClipboardStub and HostStub for
// outgoing messages.
// channel to ClientStub or ClipboardStub, and also implements ClipboardStub
// and HostStub for outgoing messages.
class ClientControlDispatcher : public ChannelDispatcherBase,
public ClipboardStub,
public HostStub {
Expand All @@ -32,11 +32,16 @@ class ClientControlDispatcher : public ChannelDispatcherBase,
// ClipboardStub implementation.
virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE;

// Sets ClientStub that will be called for each incoming control
// message. Doesn't take ownership of |client_stub|. It must outlive
// this dispatcher.
// Sets the ClientStub that will be called for each incoming control
// message. |client_stub| must outlive this object.
void set_client_stub(ClientStub* client_stub) { client_stub_ = client_stub; }

// Sets the ClipboardStub that will be called for each incoming clipboard
// message. |clipboard_stub| must outlive this object.
void set_clipboard_stub(ClipboardStub* clipboard_stub) {
clipboard_stub_ = clipboard_stub;
}

protected:
// ChannelDispatcherBase overrides.
virtual void OnInitialized() OVERRIDE;
Expand All @@ -46,6 +51,7 @@ class ClientControlDispatcher : public ChannelDispatcherBase,
const base::Closure& done_task);

ClientStub* client_stub_;
ClipboardStub* clipboard_stub_;

ProtobufMessageReader<ControlMessage> reader_;
scoped_refptr<BufferedSocketWriter> writer_;
Expand Down
5 changes: 5 additions & 0 deletions remoting/protocol/connection_to_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "remoting/protocol/client_control_dispatcher.h"
#include "remoting/protocol/client_event_dispatcher.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/jingle_session_manager.h"
#include "remoting/protocol/pepper_transport_factory.h"
Expand All @@ -35,6 +36,7 @@ ConnectionToHost::ConnectionToHost(
allow_nat_traversal_(allow_nat_traversal),
event_callback_(NULL),
client_stub_(NULL),
clipboard_stub_(NULL),
video_stub_(NULL),
state_(CONNECTING),
error_(OK) {
Expand All @@ -54,9 +56,11 @@ void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy,
scoped_ptr<Authenticator> authenticator,
HostEventCallback* event_callback,
ClientStub* client_stub,
ClipboardStub* clipboard_stub,
VideoStub* video_stub) {
event_callback_ = event_callback;
client_stub_ = client_stub;
clipboard_stub_ = clipboard_stub;
video_stub_ = video_stub;
authenticator_ = authenticator.Pass();

Expand Down Expand Up @@ -165,6 +169,7 @@ void ConnectionToHost::OnSessionStateChange(
control_dispatcher_->Init(session_.get(), base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
control_dispatcher_->set_client_stub(client_stub_);
control_dispatcher_->set_clipboard_stub(clipboard_stub_);

event_dispatcher_.reset(new ClientEventDispatcher());
event_dispatcher_->Init(session_.get(), base::Bind(
Expand Down
3 changes: 3 additions & 0 deletions remoting/protocol/connection_to_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Authenticator;
class ClientControlDispatcher;
class ClientEventDispatcher;
class ClientStub;
class ClipboardStub;
class HostStub;
class InputStub;
class SessionConfig;
Expand Down Expand Up @@ -73,6 +74,7 @@ class ConnectionToHost : public SignalStrategy::Listener,
scoped_ptr<Authenticator> authenticator,
HostEventCallback* event_callback,
ClientStub* client_stub,
ClipboardStub* clipboard_stub,
VideoStub* video_stub);

virtual void Disconnect(const base::Closure& shutdown_task);
Expand Down Expand Up @@ -128,6 +130,7 @@ class ConnectionToHost : public SignalStrategy::Listener,

// Stub for incoming messages.
ClientStub* client_stub_;
ClipboardStub* clipboard_stub_;
VideoStub* video_stub_;

scoped_ptr<SignalStrategy> signal_strategy_;
Expand Down
6 changes: 6 additions & 0 deletions remoting/protocol/host_control_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void HostControlDispatcher::OnInitialized() {
writer_->Init(channel(), BufferedSocketWriter::WriteFailedCallback());
}

void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
ControlMessage message;
message.mutable_clipboard_event()->CopyFrom(event);
writer_->Write(SerializeAndFrameMessage(message), base::Closure());
}

void HostControlDispatcher::OnMessageReceived(
scoped_ptr<ControlMessage> message, const base::Closure& done_task) {
DCHECK(clipboard_stub_);
Expand Down
20 changes: 11 additions & 9 deletions remoting/protocol/host_control_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/memory/ref_counted.h"
#include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/message_reader.h"

namespace net {
Expand All @@ -18,29 +19,30 @@ namespace remoting {
namespace protocol {

class BufferedSocketWriter;
class ClipboardStub;
class ControlMessage;
class HostStub;
class Session;

// HostControlDispatcher dispatches incoming messages on the control
// channel to HostStub or ClipboardStub, and also implements ClientStub for
// outgoing messages.
class HostControlDispatcher : public ChannelDispatcherBase, public ClientStub {
// channel to HostStub or ClipboardStub, and also implements ClientStub and
// ClipboardStub for outgoing messages.
class HostControlDispatcher : public ChannelDispatcherBase, public ClientStub,
public ClipboardStub {
public:
HostControlDispatcher();
virtual ~HostControlDispatcher();

// ClipboardStub implementation.
virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE;

// Sets the ClipboardStub that will be called for each incoming clipboard
// message. Doesn't take ownership of |clipboard_stub|, which must outlive
// the dispatcher.
// message. |clipboard_stub| must outlive this object.
void set_clipboard_stub(ClipboardStub* clipboard_stub) {
clipboard_stub_ = clipboard_stub;
}

// Sets HostStub that will be called for each incoming control
// message. Doesn't take ownership of |host_stub|. It must outlive
// this dispatcher.
// Sets the HostStub that will be called for each incoming control
// message. |host_stub| must outlive this object.
void set_host_stub(HostStub* host_stub) { host_stub_ = host_stub; }

protected:
Expand Down

0 comments on commit ba6d1c2

Please sign in to comment.