blob: 41068fa6bcb2e740585b77631de7b34ec812b19b [file] [log] [blame]
[email protected]91e4b7f62012-01-25 23:23:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]44f60762011-03-23 12:13:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef REMOTING_HOST_CLIENT_SESSION_H_
6#define REMOTING_HOST_CLIENT_SESSION_H_
7
[email protected]c78669c92011-06-13 22:42:388#include <list>
[email protected]c78669c92011-06-13 22:42:389
[email protected]60fc96002011-08-12 23:07:0510#include "base/time.h"
[email protected]ec6411872011-11-11 03:28:5511#include "base/threading/non_thread_safe.h"
[email protected]86cbe6b2012-04-03 00:56:1812#include "remoting/host/remote_input_filter.h"
[email protected]e265ad72012-03-16 17:28:0313#include "remoting/protocol/clipboard_stub.h"
[email protected]44f60762011-03-23 12:13:3514#include "remoting/protocol/connection_to_client.h"
[email protected]e265ad72012-03-16 17:28:0315#include "remoting/protocol/host_event_stub.h"
[email protected]44f60762011-03-23 12:13:3516#include "remoting/protocol/host_stub.h"
[email protected]86cbe6b2012-04-03 00:56:1817#include "remoting/protocol/input_event_tracker.h"
18#include "remoting/protocol/input_filter.h"
19#include "remoting/protocol/input_stub.h"
[email protected]bcad2682011-09-30 20:35:2620#include "third_party/skia/include/core/SkPoint.h"
[email protected]44f60762011-03-23 12:13:3521
22namespace remoting {
23
[email protected]995c2c6d2011-09-15 05:08:2524class Capturer;
[email protected]4ea2c7c2011-03-31 14:20:0625
[email protected]44f60762011-03-23 12:13:3526// A ClientSession keeps a reference to a connection to a client, and maintains
27// per-client state.
[email protected]e265ad72012-03-16 17:28:0328class ClientSession : public protocol::HostEventStub,
29 public protocol::HostStub,
[email protected]ee910fd2011-11-10 18:23:3130 public protocol::ConnectionToClient::EventHandler,
[email protected]ec6411872011-11-11 03:28:5531 public base::NonThreadSafe {
[email protected]44f60762011-03-23 12:13:3532 public:
33 // Callback interface for passing events to the ChromotingHost.
34 class EventHandler {
35 public:
36 virtual ~EventHandler() {}
37
[email protected]1f249e22011-11-29 20:19:5938 // Called after authentication has finished successfully.
[email protected]ee910fd2011-11-10 18:23:3139 virtual void OnSessionAuthenticated(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5940
[email protected]cba6f812012-03-27 01:01:5041 // Called after we've finished connecting all channels.
42 virtual void OnSessionChannelsConnected(ClientSession* client) = 0;
43
[email protected]1f249e22011-11-29 20:19:5944 // Called after authentication has failed. Must not tear down this
45 // object. OnSessionClosed() is notified after this handler
46 // returns.
47 virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
48
49 // Called after connection has failed or after the client closed it.
[email protected]ee910fd2011-11-10 18:23:3150 virtual void OnSessionClosed(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5951
52 // Called to notify of each message's sequence number. The
53 // callback must not tear down this object.
[email protected]ee910fd2011-11-10 18:23:3154 virtual void OnSessionSequenceNumber(ClientSession* client,
55 int64 sequence_number) = 0;
[email protected]91e4b7f62012-01-25 23:23:0256
57 // Called on notification of a route change event, when a channel is
58 // connected.
[email protected]17af2ab2012-02-02 04:07:5259 virtual void OnSessionRouteChange(
60 ClientSession* client,
61 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:4762 const protocol::TransportRoute& route) = 0;
[email protected]44f60762011-03-23 12:13:3563 };
64
65 ClientSession(EventHandler* event_handler,
[email protected]3361e1f2012-03-20 20:31:4466 scoped_ptr<protocol::ConnectionToClient> connection,
[email protected]e265ad72012-03-16 17:28:0367 protocol::HostEventStub* host_event_stub,
[email protected]995c2c6d2011-09-15 05:08:2568 Capturer* capturer);
[email protected]ec6411872011-11-11 03:28:5569 virtual ~ClientSession();
[email protected]44f60762011-03-23 12:13:3570
[email protected]e265ad72012-03-16 17:28:0371 // protocol::ClipboardStub interface.
72 virtual void InjectClipboardEvent(
73 const protocol::ClipboardEvent& event) OVERRIDE;
74
[email protected]4ea2c7c2011-03-31 14:20:0675 // protocol::InputStub interface.
[email protected]6a6fe8062011-11-19 00:06:0276 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE;
77 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE;
[email protected]4ea2c7c2011-03-31 14:20:0678
[email protected]ee910fd2011-11-10 18:23:3179 // protocol::ConnectionToClient::EventHandler interface.
[email protected]cba6f812012-03-27 01:01:5080 virtual void OnConnectionAuthenticated(
[email protected]ee910fd2011-11-10 18:23:3181 protocol::ConnectionToClient* connection) OVERRIDE;
[email protected]cba6f812012-03-27 01:01:5082 virtual void OnConnectionChannelsConnected(
[email protected]ee910fd2011-11-10 18:23:3183 protocol::ConnectionToClient* connection) OVERRIDE;
[email protected]cba6f812012-03-27 01:01:5084 virtual void OnConnectionClosed(protocol::ConnectionToClient* connection,
[email protected]204a9e32012-03-02 05:42:5885 protocol::ErrorCode error) OVERRIDE;
[email protected]ee910fd2011-11-10 18:23:3186 virtual void OnSequenceNumberUpdated(
87 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE;
[email protected]17af2ab2012-02-02 04:07:5288 virtual void OnRouteChange(
89 protocol::ConnectionToClient* connection,
90 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:4791 const protocol::TransportRoute& route) OVERRIDE;
[email protected]44f60762011-03-23 12:13:3592
[email protected]ee910fd2011-11-10 18:23:3193 // Disconnects the session and destroys the transport. Event handler
94 // is guaranteed not to be called after this method is called. Can
95 // be called multiple times. The object should not be used after
96 // this method returns.
97 void Disconnect();
[email protected]1ce457a2011-05-19 19:59:4898
[email protected]4ea2c7c2011-03-31 14:20:0699 protocol::ConnectionToClient* connection() const {
100 return connection_.get();
101 }
[email protected]44f60762011-03-23 12:13:35102
[email protected]f19d9bd2011-09-13 05:21:11103 const std::string& client_jid() { return client_jid_; }
104
[email protected]c78669c92011-06-13 22:42:38105 // Indicate that local mouse activity has been detected. This causes remote
106 // inputs to be ignored for a short time so that the local user will always
107 // have the upper hand in 'pointer wars'.
[email protected]bcad2682011-09-30 20:35:26108 void LocalMouseMoved(const SkIPoint& new_pos);
[email protected]c78669c92011-06-13 22:42:38109
[email protected]86cbe6b2012-04-03 00:56:18110 // Disable handling of input events from this client. If the client has any
111 // keys or mouse buttons pressed then these will be released.
112 void SetDisableInputs(bool disable_inputs);
[email protected]c78669c92011-06-13 22:42:38113
[email protected]44f60762011-03-23 12:13:35114 private:
[email protected]44f60762011-03-23 12:13:35115 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06116
[email protected]4ea2c7c2011-03-31 14:20:06117 // The connection to the client.
[email protected]ec6411872011-11-11 03:28:55118 scoped_ptr<protocol::ConnectionToClient> connection_;
[email protected]44f60762011-03-23 12:13:35119
[email protected]f19d9bd2011-09-13 05:21:11120 std::string client_jid_;
121
[email protected]e265ad72012-03-16 17:28:03122 // The host event stub to which this object delegates.
123 protocol::HostEventStub* host_event_stub_;
[email protected]4ea2c7c2011-03-31 14:20:06124
[email protected]86cbe6b2012-04-03 00:56:18125 // Tracker used to release pressed keys and buttons when disconnecting.
126 protocol::InputEventTracker input_tracker_;
127
128 // Filter used to disable remote inputs during local input activity.
129 RemoteInputFilter remote_input_filter_;
130
131 // Filter used to manage enabling & disabling of client input events.
132 protocol::InputFilter disable_input_filter_;
133
134 // Filter used to disable inputs when we're not authenticated.
135 protocol::InputFilter auth_input_filter_;
136
[email protected]995c2c6d2011-09-15 05:08:25137 // Capturer, used to determine current screen size for ensuring injected
138 // mouse events fall within the screen area.
139 // TODO(lambroslambrou): Move floor-control logic, and clamping to screen
140 // area, out of this class (crbug.com/96508).
141 Capturer* capturer_;
142
[email protected]44f60762011-03-23 12:13:35143 DISALLOW_COPY_AND_ASSIGN(ClientSession);
144};
145
146} // namespace remoting
147
148#endif // REMOTING_HOST_CLIENT_SESSION_H_