[email protected] | 91e4b7f6 | 2012-01-25 23:23:02 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 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] | c78669c9 | 2011-06-13 22:42:38 | [diff] [blame] | 8 | #include <list> |
| 9 | |
[email protected] | 60fc9600 | 2011-08-12 23:07:05 | [diff] [blame] | 10 | #include "base/time.h" |
[email protected] | ec641187 | 2011-11-11 03:28:55 | [diff] [blame] | 11 | #include "base/threading/non_thread_safe.h" |
[email protected] | 86cbe6b | 2012-04-03 00:56:18 | [diff] [blame] | 12 | #include "remoting/host/remote_input_filter.h" |
[email protected] | ff3761a1 | 2012-05-22 22:29:24 | [diff] [blame] | 13 | #include "remoting/protocol/clipboard_echo_filter.h" |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 14 | #include "remoting/protocol/clipboard_stub.h" |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 15 | #include "remoting/protocol/connection_to_client.h" |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 16 | #include "remoting/protocol/host_event_stub.h" |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 17 | #include "remoting/protocol/host_stub.h" |
[email protected] | 86cbe6b | 2012-04-03 00:56:18 | [diff] [blame] | 18 | #include "remoting/protocol/input_event_tracker.h" |
| 19 | #include "remoting/protocol/input_filter.h" |
| 20 | #include "remoting/protocol/input_stub.h" |
[email protected] | f5d62e36 | 2012-04-30 20:54:37 | [diff] [blame] | 21 | #include "remoting/protocol/mouse_input_filter.h" |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 22 | #include "third_party/skia/include/core/SkPoint.h" |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 23 | |
| 24 | namespace remoting { |
| 25 | |
[email protected] | 995c2c6d | 2011-09-15 05:08:25 | [diff] [blame] | 26 | class Capturer; |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 27 | |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 28 | // A ClientSession keeps a reference to a connection to a client, and maintains |
| 29 | // per-client state. |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 30 | class ClientSession : public protocol::HostEventStub, |
| 31 | public protocol::HostStub, |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 32 | public protocol::ConnectionToClient::EventHandler, |
[email protected] | ec641187 | 2011-11-11 03:28:55 | [diff] [blame] | 33 | public base::NonThreadSafe { |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 34 | public: |
| 35 | // Callback interface for passing events to the ChromotingHost. |
| 36 | class EventHandler { |
| 37 | public: |
| 38 | virtual ~EventHandler() {} |
| 39 | |
[email protected] | 1f249e2 | 2011-11-29 20:19:59 | [diff] [blame] | 40 | // Called after authentication has finished successfully. |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 41 | virtual void OnSessionAuthenticated(ClientSession* client) = 0; |
[email protected] | 1f249e2 | 2011-11-29 20:19:59 | [diff] [blame] | 42 | |
[email protected] | cba6f81 | 2012-03-27 01:01:50 | [diff] [blame] | 43 | // Called after we've finished connecting all channels. |
| 44 | virtual void OnSessionChannelsConnected(ClientSession* client) = 0; |
| 45 | |
[email protected] | 1f249e2 | 2011-11-29 20:19:59 | [diff] [blame] | 46 | // Called after authentication has failed. Must not tear down this |
| 47 | // object. OnSessionClosed() is notified after this handler |
| 48 | // returns. |
| 49 | virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0; |
| 50 | |
| 51 | // Called after connection has failed or after the client closed it. |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 52 | virtual void OnSessionClosed(ClientSession* client) = 0; |
[email protected] | 1f249e2 | 2011-11-29 20:19:59 | [diff] [blame] | 53 | |
| 54 | // Called to notify of each message's sequence number. The |
| 55 | // callback must not tear down this object. |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 56 | virtual void OnSessionSequenceNumber(ClientSession* client, |
| 57 | int64 sequence_number) = 0; |
[email protected] | 91e4b7f6 | 2012-01-25 23:23:02 | [diff] [blame] | 58 | |
| 59 | // Called on notification of a route change event, when a channel is |
| 60 | // connected. |
[email protected] | 17af2ab | 2012-02-02 04:07:52 | [diff] [blame] | 61 | virtual void OnSessionRouteChange( |
| 62 | ClientSession* client, |
| 63 | const std::string& channel_name, |
[email protected] | be451c8 | 2012-03-20 22:24:47 | [diff] [blame] | 64 | const protocol::TransportRoute& route) = 0; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | ClientSession(EventHandler* event_handler, |
[email protected] | 3361e1f | 2012-03-20 20:31:44 | [diff] [blame] | 68 | scoped_ptr<protocol::ConnectionToClient> connection, |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 69 | protocol::HostEventStub* host_event_stub, |
[email protected] | 995c2c6d | 2011-09-15 05:08:25 | [diff] [blame] | 70 | Capturer* capturer); |
[email protected] | ec641187 | 2011-11-11 03:28:55 | [diff] [blame] | 71 | virtual ~ClientSession(); |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 72 | |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 73 | // protocol::ClipboardStub interface. |
| 74 | virtual void InjectClipboardEvent( |
| 75 | const protocol::ClipboardEvent& event) OVERRIDE; |
| 76 | |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 77 | // protocol::InputStub interface. |
[email protected] | 6a6fe806 | 2011-11-19 00:06:02 | [diff] [blame] | 78 | virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE; |
| 79 | virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE; |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 80 | |
[email protected] | f2b9cf3 | 2012-04-27 00:13:43 | [diff] [blame] | 81 | // protocol::HostStub interface. |
| 82 | virtual void NotifyClientDimensions( |
| 83 | const protocol::ClientDimensions& dimensions) OVERRIDE; |
[email protected] | 50d71c7 | 2012-05-03 01:28:55 | [diff] [blame] | 84 | virtual void ControlVideo( |
| 85 | const protocol::VideoControl& video_control) OVERRIDE; |
[email protected] | f2b9cf3 | 2012-04-27 00:13:43 | [diff] [blame] | 86 | |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 87 | // protocol::ConnectionToClient::EventHandler interface. |
[email protected] | cba6f81 | 2012-03-27 01:01:50 | [diff] [blame] | 88 | virtual void OnConnectionAuthenticated( |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 89 | protocol::ConnectionToClient* connection) OVERRIDE; |
[email protected] | cba6f81 | 2012-03-27 01:01:50 | [diff] [blame] | 90 | virtual void OnConnectionChannelsConnected( |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 91 | protocol::ConnectionToClient* connection) OVERRIDE; |
[email protected] | cba6f81 | 2012-03-27 01:01:50 | [diff] [blame] | 92 | virtual void OnConnectionClosed(protocol::ConnectionToClient* connection, |
[email protected] | 204a9e3 | 2012-03-02 05:42:58 | [diff] [blame] | 93 | protocol::ErrorCode error) OVERRIDE; |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 94 | virtual void OnSequenceNumberUpdated( |
| 95 | protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE; |
[email protected] | 17af2ab | 2012-02-02 04:07:52 | [diff] [blame] | 96 | virtual void OnRouteChange( |
| 97 | protocol::ConnectionToClient* connection, |
| 98 | const std::string& channel_name, |
[email protected] | be451c8 | 2012-03-20 22:24:47 | [diff] [blame] | 99 | const protocol::TransportRoute& route) OVERRIDE; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 100 | |
[email protected] | ee910fd | 2011-11-10 18:23:31 | [diff] [blame] | 101 | // Disconnects the session and destroys the transport. Event handler |
| 102 | // is guaranteed not to be called after this method is called. Can |
| 103 | // be called multiple times. The object should not be used after |
| 104 | // this method returns. |
| 105 | void Disconnect(); |
[email protected] | 1ce457a | 2011-05-19 19:59:48 | [diff] [blame] | 106 | |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 107 | protocol::ConnectionToClient* connection() const { |
| 108 | return connection_.get(); |
| 109 | } |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 110 | |
[email protected] | f19d9bd | 2011-09-13 05:21:11 | [diff] [blame] | 111 | const std::string& client_jid() { return client_jid_; } |
| 112 | |
[email protected] | dda4da3b | 2012-05-22 00:51:26 | [diff] [blame] | 113 | bool is_authenticated() { return is_authenticated_; } |
| 114 | |
[email protected] | c78669c9 | 2011-06-13 22:42:38 | [diff] [blame] | 115 | // Indicate that local mouse activity has been detected. This causes remote |
| 116 | // inputs to be ignored for a short time so that the local user will always |
| 117 | // have the upper hand in 'pointer wars'. |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame] | 118 | void LocalMouseMoved(const SkIPoint& new_pos); |
[email protected] | c78669c9 | 2011-06-13 22:42:38 | [diff] [blame] | 119 | |
[email protected] | 86cbe6b | 2012-04-03 00:56:18 | [diff] [blame] | 120 | // Disable handling of input events from this client. If the client has any |
| 121 | // keys or mouse buttons pressed then these will be released. |
| 122 | void SetDisableInputs(bool disable_inputs); |
[email protected] | c78669c9 | 2011-06-13 22:42:38 | [diff] [blame] | 123 | |
[email protected] | 7f44ba4 | 2012-05-31 20:26:29 | [diff] [blame] | 124 | // Creates a proxy for sending clipboard events to the client. |
| 125 | scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); |
| 126 | |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 127 | private: |
| 128 | EventHandler* event_handler_; |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 129 | |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 130 | // The connection to the client. |
[email protected] | ec641187 | 2011-11-11 03:28:55 | [diff] [blame] | 131 | scoped_ptr<protocol::ConnectionToClient> connection_; |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 132 | |
[email protected] | f19d9bd | 2011-09-13 05:21:11 | [diff] [blame] | 133 | std::string client_jid_; |
[email protected] | dda4da3b | 2012-05-22 00:51:26 | [diff] [blame] | 134 | bool is_authenticated_; |
[email protected] | f19d9bd | 2011-09-13 05:21:11 | [diff] [blame] | 135 | |
[email protected] | f5d62e36 | 2012-04-30 20:54:37 | [diff] [blame] | 136 | // The host event stub to which this object delegates. This is the final |
| 137 | // element in the input pipeline, whose components appear in order below. |
[email protected] | e265ad7 | 2012-03-16 17:28:03 | [diff] [blame] | 138 | protocol::HostEventStub* host_event_stub_; |
[email protected] | 4ea2c7c | 2011-03-31 14:20:06 | [diff] [blame] | 139 | |
[email protected] | 86cbe6b | 2012-04-03 00:56:18 | [diff] [blame] | 140 | // Tracker used to release pressed keys and buttons when disconnecting. |
| 141 | protocol::InputEventTracker input_tracker_; |
| 142 | |
| 143 | // Filter used to disable remote inputs during local input activity. |
| 144 | RemoteInputFilter remote_input_filter_; |
| 145 | |
[email protected] | f5d62e36 | 2012-04-30 20:54:37 | [diff] [blame] | 146 | // Filter used to clamp mouse events to the current display dimensions. |
| 147 | protocol::MouseInputFilter mouse_input_filter_; |
| 148 | |
[email protected] | 86cbe6b | 2012-04-03 00:56:18 | [diff] [blame] | 149 | // Filter used to manage enabling & disabling of client input events. |
| 150 | protocol::InputFilter disable_input_filter_; |
| 151 | |
| 152 | // Filter used to disable inputs when we're not authenticated. |
| 153 | protocol::InputFilter auth_input_filter_; |
| 154 | |
[email protected] | ff3761a1 | 2012-05-22 22:29:24 | [diff] [blame] | 155 | // Filter to used to stop clipboard items sent from the client being echoed |
| 156 | // back to it. |
| 157 | protocol::ClipboardEchoFilter clipboard_echo_filter_; |
| 158 | |
[email protected] | 7f44ba4 | 2012-05-31 20:26:29 | [diff] [blame] | 159 | // Factory for weak pointers to the client clipboard stub. |
| 160 | // This must appear after |clipboard_echo_filter_|, so that it won't outlive |
| 161 | // it. |
| 162 | base::WeakPtrFactory<ClipboardStub> client_clipboard_factory_; |
| 163 | |
[email protected] | 995c2c6d | 2011-09-15 05:08:25 | [diff] [blame] | 164 | // Capturer, used to determine current screen size for ensuring injected |
| 165 | // mouse events fall within the screen area. |
| 166 | // TODO(lambroslambrou): Move floor-control logic, and clamping to screen |
| 167 | // area, out of this class (crbug.com/96508). |
| 168 | Capturer* capturer_; |
| 169 | |
[email protected] | 44f6076 | 2011-03-23 12:13:35 | [diff] [blame] | 170 | DISALLOW_COPY_AND_ASSIGN(ClientSession); |
| 171 | }; |
| 172 | |
| 173 | } // namespace remoting |
| 174 | |
| 175 | #endif // REMOTING_HOST_CLIENT_SESSION_H_ |