blob: 98f6cf8a593ea40ab8714fe79382d21a5113d4b7 [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]35c14ee2011-06-20 19:32:459#include <set>
[email protected]c78669c92011-06-13 22:42:3810
[email protected]60fc96002011-08-12 23:07:0511#include "base/time.h"
[email protected]ec6411872011-11-11 03:28:5512#include "base/threading/non_thread_safe.h"
[email protected]44f60762011-03-23 12:13:3513#include "remoting/protocol/connection_to_client.h"
14#include "remoting/protocol/host_stub.h"
[email protected]4ea2c7c2011-03-31 14:20:0615#include "remoting/protocol/input_stub.h"
[email protected]bcad2682011-09-30 20:35:2616#include "third_party/skia/include/core/SkPoint.h"
[email protected]44f60762011-03-23 12:13:3517
18namespace remoting {
19
[email protected]995c2c6d2011-09-15 05:08:2520class Capturer;
[email protected]4ea2c7c2011-03-31 14:20:0621
[email protected]44f60762011-03-23 12:13:3522// A ClientSession keeps a reference to a connection to a client, and maintains
23// per-client state.
24class ClientSession : public protocol::HostStub,
[email protected]4ea2c7c2011-03-31 14:20:0625 public protocol::InputStub,
[email protected]ee910fd2011-11-10 18:23:3126 public protocol::ConnectionToClient::EventHandler,
[email protected]ec6411872011-11-11 03:28:5527 public base::NonThreadSafe {
[email protected]44f60762011-03-23 12:13:3528 public:
29 // Callback interface for passing events to the ChromotingHost.
30 class EventHandler {
31 public:
32 virtual ~EventHandler() {}
33
[email protected]1f249e22011-11-29 20:19:5934 // Called after authentication has finished successfully.
[email protected]ee910fd2011-11-10 18:23:3135 virtual void OnSessionAuthenticated(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5936
37 // Called after authentication has failed. Must not tear down this
38 // object. OnSessionClosed() is notified after this handler
39 // returns.
40 virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
41
42 // Called after connection has failed or after the client closed it.
[email protected]ee910fd2011-11-10 18:23:3143 virtual void OnSessionClosed(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5944
45 // Called to notify of each message's sequence number. The
46 // callback must not tear down this object.
[email protected]ee910fd2011-11-10 18:23:3147 virtual void OnSessionSequenceNumber(ClientSession* client,
48 int64 sequence_number) = 0;
[email protected]91e4b7f62012-01-25 23:23:0249
50 // Called on notification of a route change event, when a channel is
51 // connected.
52 virtual void OnSessionIpAddress(ClientSession* client,
53 const std::string& channel_name,
54 const net::IPEndPoint& end_point) = 0;
[email protected]44f60762011-03-23 12:13:3555 };
56
[email protected]ec6411872011-11-11 03:28:5557 // Takes ownership of |connection|. Does not take ownership of
[email protected]995c2c6d2011-09-15 05:08:2558 // |event_handler|, |input_stub| or |capturer|.
[email protected]44f60762011-03-23 12:13:3559 ClientSession(EventHandler* event_handler,
[email protected]ec6411872011-11-11 03:28:5560 protocol::ConnectionToClient* connection,
[email protected]995c2c6d2011-09-15 05:08:2561 protocol::InputStub* input_stub,
62 Capturer* capturer);
[email protected]ec6411872011-11-11 03:28:5563 virtual ~ClientSession();
[email protected]44f60762011-03-23 12:13:3564
[email protected]4ea2c7c2011-03-31 14:20:0665 // protocol::InputStub interface.
[email protected]6a6fe8062011-11-19 00:06:0266 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE;
67 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE;
[email protected]4ea2c7c2011-03-31 14:20:0668
[email protected]ee910fd2011-11-10 18:23:3169 // protocol::ConnectionToClient::EventHandler interface.
70 virtual void OnConnectionOpened(
71 protocol::ConnectionToClient* connection) OVERRIDE;
72 virtual void OnConnectionClosed(
73 protocol::ConnectionToClient* connection) OVERRIDE;
[email protected]1f249e22011-11-29 20:19:5974 virtual void OnConnectionFailed(protocol::ConnectionToClient* connection,
75 protocol::Session::Error error) OVERRIDE;
[email protected]ee910fd2011-11-10 18:23:3176 virtual void OnSequenceNumberUpdated(
77 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE;
[email protected]91e4b7f62012-01-25 23:23:0278 virtual void OnClientIpAddress(protocol::ConnectionToClient* connection,
79 const std::string& channel_name,
80 const net::IPEndPoint& end_point) OVERRIDE;
[email protected]44f60762011-03-23 12:13:3581
[email protected]ee910fd2011-11-10 18:23:3182 // Disconnects the session and destroys the transport. Event handler
83 // is guaranteed not to be called after this method is called. Can
84 // be called multiple times. The object should not be used after
85 // this method returns.
86 void Disconnect();
[email protected]1ce457a2011-05-19 19:59:4887
[email protected]4ea2c7c2011-03-31 14:20:0688 protocol::ConnectionToClient* connection() const {
89 return connection_.get();
90 }
[email protected]44f60762011-03-23 12:13:3591
[email protected]4ea2c7c2011-03-31 14:20:0692 bool authenticated() const {
93 return authenticated_;
94 }
[email protected]44f60762011-03-23 12:13:3595
[email protected]35c14ee2011-06-20 19:32:4596 void set_awaiting_continue_approval(bool awaiting) {
97 awaiting_continue_approval_ = awaiting;
98 }
99
[email protected]f19d9bd2011-09-13 05:21:11100 const std::string& client_jid() { return client_jid_; }
101
[email protected]c78669c92011-06-13 22:42:38102 // Indicate that local mouse activity has been detected. This causes remote
103 // inputs to be ignored for a short time so that the local user will always
104 // have the upper hand in 'pointer wars'.
[email protected]bcad2682011-09-30 20:35:26105 void LocalMouseMoved(const SkIPoint& new_pos);
[email protected]c78669c92011-06-13 22:42:38106
[email protected]b25ff3b2011-09-13 18:17:30107 bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent& event) const;
108 bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent& event) const;
[email protected]c78669c92011-06-13 22:42:38109
[email protected]44f60762011-03-23 12:13:35110 private:
[email protected]b67fb9302011-09-26 01:55:52111 friend class ClientSessionTest_RestoreEventState_Test;
[email protected]4ea2c7c2011-03-31 14:20:06112
[email protected]b67fb9302011-09-26 01:55:52113 // Keep track of input state so that we can clean up the event queue when
114 // the user disconnects.
[email protected]b25ff3b2011-09-13 18:17:30115 void RecordKeyEvent(const protocol::KeyEvent& event);
[email protected]b67fb9302011-09-26 01:55:52116 void RecordMouseButtonState(const protocol::MouseEvent& event);
[email protected]86c5a1e2011-06-29 20:50:15117
[email protected]b67fb9302011-09-26 01:55:52118 // Synthesize KeyUp and MouseUp events so that we can undo these events
119 // when the user disconnects.
120 void RestoreEventState();
[email protected]86c5a1e2011-06-29 20:50:15121
[email protected]44f60762011-03-23 12:13:35122 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06123
[email protected]4ea2c7c2011-03-31 14:20:06124 // The connection to the client.
[email protected]ec6411872011-11-11 03:28:55125 scoped_ptr<protocol::ConnectionToClient> connection_;
[email protected]44f60762011-03-23 12:13:35126
[email protected]f19d9bd2011-09-13 05:21:11127 std::string client_jid_;
128
[email protected]4ea2c7c2011-03-31 14:20:06129 // The input stub to which this object delegates.
130 protocol::InputStub* input_stub_;
131
[email protected]995c2c6d2011-09-15 05:08:25132 // Capturer, used to determine current screen size for ensuring injected
133 // mouse events fall within the screen area.
134 // TODO(lambroslambrou): Move floor-control logic, and clamping to screen
135 // area, out of this class (crbug.com/96508).
136 Capturer* capturer_;
137
[email protected]4ea2c7c2011-03-31 14:20:06138 // Whether this client is authenticated.
139 bool authenticated_;
140
[email protected]35c14ee2011-06-20 19:32:45141 // Whether or not inputs from this client are blocked pending approval from
142 // the host user to continue the connection.
143 bool awaiting_continue_approval_;
144
[email protected]c78669c92011-06-13 22:42:38145 // State to control remote input blocking while the local pointer is in use.
146 uint32 remote_mouse_button_state_;
[email protected]4fe827a2011-08-10 03:30:19147
[email protected]b67fb9302011-09-26 01:55:52148 // Current location of the mouse pointer. This is used to provide appropriate
149 // coordinates when we release the mouse buttons after a user disconnects.
[email protected]bcad2682011-09-30 20:35:26150 SkIPoint remote_mouse_pos_;
[email protected]b67fb9302011-09-26 01:55:52151
[email protected]4fe827a2011-08-10 03:30:19152 // Queue of recently-injected mouse positions. This is used to detect whether
153 // mouse events from the local input monitor are echoes of injected positions,
154 // or genuine mouse movements of a local input device.
[email protected]bcad2682011-09-30 20:35:26155 std::list<SkIPoint> injected_mouse_positions_;
[email protected]4fe827a2011-08-10 03:30:19156
[email protected]c78669c92011-06-13 22:42:38157 base::Time latest_local_input_time_;
[email protected]b67fb9302011-09-26 01:55:52158
159 // Set of keys that are currently pressed down by the user. This is used so
160 // we can release them if the user disconnects.
[email protected]35c14ee2011-06-20 19:32:45161 std::set<int> pressed_keys_;
[email protected]c78669c92011-06-13 22:42:38162
[email protected]44f60762011-03-23 12:13:35163 DISALLOW_COPY_AND_ASSIGN(ClientSession);
164};
165
166} // namespace remoting
167
168#endif // REMOTING_HOST_CLIENT_SESSION_H_