blob: 31ac0793dcf81b0cabad117c7bb91d8a37800aa5 [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.
[email protected]17af2ab2012-02-02 04:07:5252 virtual void OnSessionRouteChange(
53 ClientSession* client,
54 const std::string& channel_name,
55 const net::IPEndPoint& remote_end_point,
56 const net::IPEndPoint& local_end_point) = 0;
[email protected]44f60762011-03-23 12:13:3557 };
58
[email protected]ec6411872011-11-11 03:28:5559 // Takes ownership of |connection|. Does not take ownership of
[email protected]995c2c6d2011-09-15 05:08:2560 // |event_handler|, |input_stub| or |capturer|.
[email protected]44f60762011-03-23 12:13:3561 ClientSession(EventHandler* event_handler,
[email protected]ec6411872011-11-11 03:28:5562 protocol::ConnectionToClient* connection,
[email protected]995c2c6d2011-09-15 05:08:2563 protocol::InputStub* input_stub,
64 Capturer* capturer);
[email protected]ec6411872011-11-11 03:28:5565 virtual ~ClientSession();
[email protected]44f60762011-03-23 12:13:3566
[email protected]4ea2c7c2011-03-31 14:20:0667 // protocol::InputStub interface.
[email protected]6a6fe8062011-11-19 00:06:0268 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE;
69 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE;
[email protected]4ea2c7c2011-03-31 14:20:0670
[email protected]ee910fd2011-11-10 18:23:3171 // protocol::ConnectionToClient::EventHandler interface.
72 virtual void OnConnectionOpened(
73 protocol::ConnectionToClient* connection) OVERRIDE;
74 virtual void OnConnectionClosed(
75 protocol::ConnectionToClient* connection) OVERRIDE;
[email protected]1f249e22011-11-29 20:19:5976 virtual void OnConnectionFailed(protocol::ConnectionToClient* connection,
[email protected]204a9e32012-03-02 05:42:5877 protocol::ErrorCode error) OVERRIDE;
[email protected]ee910fd2011-11-10 18:23:3178 virtual void OnSequenceNumberUpdated(
79 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE;
[email protected]17af2ab2012-02-02 04:07:5280 virtual void OnRouteChange(
81 protocol::ConnectionToClient* connection,
82 const std::string& channel_name,
83 const net::IPEndPoint& remote_end_point,
84 const net::IPEndPoint& local_end_point) OVERRIDE;
[email protected]44f60762011-03-23 12:13:3585
[email protected]ee910fd2011-11-10 18:23:3186 // Disconnects the session and destroys the transport. Event handler
87 // is guaranteed not to be called after this method is called. Can
88 // be called multiple times. The object should not be used after
89 // this method returns.
90 void Disconnect();
[email protected]1ce457a2011-05-19 19:59:4891
[email protected]4ea2c7c2011-03-31 14:20:0692 protocol::ConnectionToClient* connection() const {
93 return connection_.get();
94 }
[email protected]44f60762011-03-23 12:13:3595
[email protected]4ea2c7c2011-03-31 14:20:0696 bool authenticated() const {
97 return authenticated_;
98 }
[email protected]44f60762011-03-23 12:13:3599
[email protected]35c14ee2011-06-20 19:32:45100 void set_awaiting_continue_approval(bool awaiting) {
101 awaiting_continue_approval_ = awaiting;
102 }
103
[email protected]f19d9bd2011-09-13 05:21:11104 const std::string& client_jid() { return client_jid_; }
105
[email protected]c78669c92011-06-13 22:42:38106 // Indicate that local mouse activity has been detected. This causes remote
107 // inputs to be ignored for a short time so that the local user will always
108 // have the upper hand in 'pointer wars'.
[email protected]bcad2682011-09-30 20:35:26109 void LocalMouseMoved(const SkIPoint& new_pos);
[email protected]c78669c92011-06-13 22:42:38110
[email protected]b25ff3b2011-09-13 18:17:30111 bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent& event) const;
112 bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent& event) const;
[email protected]c78669c92011-06-13 22:42:38113
[email protected]44f60762011-03-23 12:13:35114 private:
[email protected]b67fb9302011-09-26 01:55:52115 friend class ClientSessionTest_RestoreEventState_Test;
[email protected]4ea2c7c2011-03-31 14:20:06116
[email protected]b67fb9302011-09-26 01:55:52117 // Keep track of input state so that we can clean up the event queue when
118 // the user disconnects.
[email protected]b25ff3b2011-09-13 18:17:30119 void RecordKeyEvent(const protocol::KeyEvent& event);
[email protected]b67fb9302011-09-26 01:55:52120 void RecordMouseButtonState(const protocol::MouseEvent& event);
[email protected]86c5a1e2011-06-29 20:50:15121
[email protected]b67fb9302011-09-26 01:55:52122 // Synthesize KeyUp and MouseUp events so that we can undo these events
123 // when the user disconnects.
124 void RestoreEventState();
[email protected]86c5a1e2011-06-29 20:50:15125
[email protected]44f60762011-03-23 12:13:35126 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06127
[email protected]4ea2c7c2011-03-31 14:20:06128 // The connection to the client.
[email protected]ec6411872011-11-11 03:28:55129 scoped_ptr<protocol::ConnectionToClient> connection_;
[email protected]44f60762011-03-23 12:13:35130
[email protected]f19d9bd2011-09-13 05:21:11131 std::string client_jid_;
132
[email protected]4ea2c7c2011-03-31 14:20:06133 // The input stub to which this object delegates.
134 protocol::InputStub* input_stub_;
135
[email protected]995c2c6d2011-09-15 05:08:25136 // Capturer, used to determine current screen size for ensuring injected
137 // mouse events fall within the screen area.
138 // TODO(lambroslambrou): Move floor-control logic, and clamping to screen
139 // area, out of this class (crbug.com/96508).
140 Capturer* capturer_;
141
[email protected]4ea2c7c2011-03-31 14:20:06142 // Whether this client is authenticated.
143 bool authenticated_;
144
[email protected]35c14ee2011-06-20 19:32:45145 // Whether or not inputs from this client are blocked pending approval from
146 // the host user to continue the connection.
147 bool awaiting_continue_approval_;
148
[email protected]c78669c92011-06-13 22:42:38149 // State to control remote input blocking while the local pointer is in use.
150 uint32 remote_mouse_button_state_;
[email protected]4fe827a2011-08-10 03:30:19151
[email protected]b67fb9302011-09-26 01:55:52152 // Current location of the mouse pointer. This is used to provide appropriate
153 // coordinates when we release the mouse buttons after a user disconnects.
[email protected]bcad2682011-09-30 20:35:26154 SkIPoint remote_mouse_pos_;
[email protected]b67fb9302011-09-26 01:55:52155
[email protected]4fe827a2011-08-10 03:30:19156 // Queue of recently-injected mouse positions. This is used to detect whether
157 // mouse events from the local input monitor are echoes of injected positions,
158 // or genuine mouse movements of a local input device.
[email protected]bcad2682011-09-30 20:35:26159 std::list<SkIPoint> injected_mouse_positions_;
[email protected]4fe827a2011-08-10 03:30:19160
[email protected]c78669c92011-06-13 22:42:38161 base::Time latest_local_input_time_;
[email protected]b67fb9302011-09-26 01:55:52162
163 // Set of keys that are currently pressed down by the user. This is used so
164 // we can release them if the user disconnects.
[email protected]35c14ee2011-06-20 19:32:45165 std::set<int> pressed_keys_;
[email protected]c78669c92011-06-13 22:42:38166
[email protected]44f60762011-03-23 12:13:35167 DISALLOW_COPY_AND_ASSIGN(ClientSession);
168};
169
170} // namespace remoting
171
172#endif // REMOTING_HOST_CLIENT_SESSION_H_