blob: a301ff937baba8f63299c581f478513b7e26a812 [file] [log] [blame]
[email protected]44f60762011-03-23 12:13:351// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// 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]ee910fd2011-11-10 18:23:3134 virtual void OnSessionAuthenticated(ClientSession* client) = 0;
35 virtual void OnSessionClosed(ClientSession* client) = 0;
36 virtual void OnSessionSequenceNumber(ClientSession* client,
37 int64 sequence_number) = 0;
[email protected]44f60762011-03-23 12:13:3538 };
39
[email protected]ec6411872011-11-11 03:28:5540 // Takes ownership of |connection|. Does not take ownership of
[email protected]995c2c6d2011-09-15 05:08:2541 // |event_handler|, |input_stub| or |capturer|.
[email protected]44f60762011-03-23 12:13:3542 ClientSession(EventHandler* event_handler,
[email protected]ec6411872011-11-11 03:28:5543 protocol::ConnectionToClient* connection,
[email protected]995c2c6d2011-09-15 05:08:2544 protocol::InputStub* input_stub,
45 Capturer* capturer);
[email protected]ec6411872011-11-11 03:28:5546 virtual ~ClientSession();
[email protected]44f60762011-03-23 12:13:3547
[email protected]4ea2c7c2011-03-31 14:20:0648 // protocol::InputStub interface.
[email protected]6a6fe8062011-11-19 00:06:0249 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE;
50 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE;
[email protected]4ea2c7c2011-03-31 14:20:0651
[email protected]ee910fd2011-11-10 18:23:3152 // protocol::ConnectionToClient::EventHandler interface.
53 virtual void OnConnectionOpened(
54 protocol::ConnectionToClient* connection) OVERRIDE;
55 virtual void OnConnectionClosed(
56 protocol::ConnectionToClient* connection) OVERRIDE;
57 virtual void OnConnectionFailed(
58 protocol::ConnectionToClient* connection) OVERRIDE;
59 virtual void OnSequenceNumberUpdated(
60 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE;
[email protected]44f60762011-03-23 12:13:3561
[email protected]ee910fd2011-11-10 18:23:3162 // Disconnects the session and destroys the transport. Event handler
63 // is guaranteed not to be called after this method is called. Can
64 // be called multiple times. The object should not be used after
65 // this method returns.
66 void Disconnect();
[email protected]1ce457a2011-05-19 19:59:4867
[email protected]4ea2c7c2011-03-31 14:20:0668 protocol::ConnectionToClient* connection() const {
69 return connection_.get();
70 }
[email protected]44f60762011-03-23 12:13:3571
[email protected]4ea2c7c2011-03-31 14:20:0672 bool authenticated() const {
73 return authenticated_;
74 }
[email protected]44f60762011-03-23 12:13:3575
[email protected]35c14ee2011-06-20 19:32:4576 void set_awaiting_continue_approval(bool awaiting) {
77 awaiting_continue_approval_ = awaiting;
78 }
79
[email protected]f19d9bd2011-09-13 05:21:1180 const std::string& client_jid() { return client_jid_; }
81
[email protected]c78669c92011-06-13 22:42:3882 // Indicate that local mouse activity has been detected. This causes remote
83 // inputs to be ignored for a short time so that the local user will always
84 // have the upper hand in 'pointer wars'.
[email protected]bcad2682011-09-30 20:35:2685 void LocalMouseMoved(const SkIPoint& new_pos);
[email protected]c78669c92011-06-13 22:42:3886
[email protected]b25ff3b2011-09-13 18:17:3087 bool ShouldIgnoreRemoteMouseInput(const protocol::MouseEvent& event) const;
88 bool ShouldIgnoreRemoteKeyboardInput(const protocol::KeyEvent& event) const;
[email protected]c78669c92011-06-13 22:42:3889
[email protected]44f60762011-03-23 12:13:3590 private:
[email protected]b67fb9302011-09-26 01:55:5291 friend class ClientSessionTest_RestoreEventState_Test;
[email protected]4ea2c7c2011-03-31 14:20:0692
[email protected]b67fb9302011-09-26 01:55:5293 // Keep track of input state so that we can clean up the event queue when
94 // the user disconnects.
[email protected]b25ff3b2011-09-13 18:17:3095 void RecordKeyEvent(const protocol::KeyEvent& event);
[email protected]b67fb9302011-09-26 01:55:5296 void RecordMouseButtonState(const protocol::MouseEvent& event);
[email protected]86c5a1e2011-06-29 20:50:1597
[email protected]b67fb9302011-09-26 01:55:5298 // Synthesize KeyUp and MouseUp events so that we can undo these events
99 // when the user disconnects.
100 void RestoreEventState();
[email protected]86c5a1e2011-06-29 20:50:15101
[email protected]44f60762011-03-23 12:13:35102 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06103
[email protected]4ea2c7c2011-03-31 14:20:06104 // The connection to the client.
[email protected]ec6411872011-11-11 03:28:55105 scoped_ptr<protocol::ConnectionToClient> connection_;
[email protected]44f60762011-03-23 12:13:35106
[email protected]f19d9bd2011-09-13 05:21:11107 std::string client_jid_;
108
[email protected]4ea2c7c2011-03-31 14:20:06109 // The input stub to which this object delegates.
110 protocol::InputStub* input_stub_;
111
[email protected]995c2c6d2011-09-15 05:08:25112 // Capturer, used to determine current screen size for ensuring injected
113 // mouse events fall within the screen area.
114 // TODO(lambroslambrou): Move floor-control logic, and clamping to screen
115 // area, out of this class (crbug.com/96508).
116 Capturer* capturer_;
117
[email protected]4ea2c7c2011-03-31 14:20:06118 // Whether this client is authenticated.
119 bool authenticated_;
120
[email protected]35c14ee2011-06-20 19:32:45121 // Whether or not inputs from this client are blocked pending approval from
122 // the host user to continue the connection.
123 bool awaiting_continue_approval_;
124
[email protected]c78669c92011-06-13 22:42:38125 // State to control remote input blocking while the local pointer is in use.
126 uint32 remote_mouse_button_state_;
[email protected]4fe827a2011-08-10 03:30:19127
[email protected]b67fb9302011-09-26 01:55:52128 // Current location of the mouse pointer. This is used to provide appropriate
129 // coordinates when we release the mouse buttons after a user disconnects.
[email protected]bcad2682011-09-30 20:35:26130 SkIPoint remote_mouse_pos_;
[email protected]b67fb9302011-09-26 01:55:52131
[email protected]4fe827a2011-08-10 03:30:19132 // Queue of recently-injected mouse positions. This is used to detect whether
133 // mouse events from the local input monitor are echoes of injected positions,
134 // or genuine mouse movements of a local input device.
[email protected]bcad2682011-09-30 20:35:26135 std::list<SkIPoint> injected_mouse_positions_;
[email protected]4fe827a2011-08-10 03:30:19136
[email protected]c78669c92011-06-13 22:42:38137 base::Time latest_local_input_time_;
[email protected]b67fb9302011-09-26 01:55:52138
139 // Set of keys that are currently pressed down by the user. This is used so
140 // we can release them if the user disconnects.
[email protected]35c14ee2011-06-20 19:32:45141 std::set<int> pressed_keys_;
[email protected]c78669c92011-06-13 22:42:38142
[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_