chromoting_jni_instance.h revision c2db58bd994c04d98e4ee2cd7565b71548655fe3
17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// found in the LICENSE file. 47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ 77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include <string> 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/ref_counted.h" 117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/scoped_ptr.h" 129ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/memory/weak_ptr.h" 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/message_loop/message_loop.h" 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/client/chromoting_client.h" 157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/client/client_config.h" 167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/client/client_context.h" 177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/client/client_user_interface.h" 187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/client/frame_consumer_proxy.h" 199ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "remoting/client/jni/jni_frame_consumer.h" 207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/jingle_glue/network_settings.h" 217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/jingle_glue/xmpp_signal_strategy.h" 22a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "remoting/protocol/clipboard_stub.h" 237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "remoting/protocol/connection_to_host.h" 24a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "remoting/protocol/cursor_shape_stub.h" 257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace remoting { 27a3f7b4e666c476898878fa745f637129375cd889Ben Murdochnamespace protocol { 28a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch class ClipboardEvent; 29a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch class CursorShapeInfo; 30a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch} // namespace protocol 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// ClientUserInterface that indirectly makes and receives JNI calls. 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass ChromotingJniInstance 347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch : public ClientUserInterface, 35a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch public protocol::ClipboardStub, 36a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch public protocol::CursorShapeStub, 377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public base::RefCountedThreadSafe<ChromotingJniInstance> { 387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public: 397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Initiates a connection with the specified host. Call from the UI thread. 40bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // The instance does not take ownership of |jni_runtime|. To connect with an 41bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings. 42bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, 43bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const char* username, 44bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const char* auth_token, 45bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const char* host_jid, 46bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const char* host_id, 47bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const char* host_pubkey, 48bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const char* pairing_id, 49bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const char* pairing_secret); 507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Terminates the current connection (if it hasn't already failed) and cleans 527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // up. Must be called before destruction. 537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void Cleanup(); 547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Provides the user's PIN and resumes the host authentication attempt. Call 567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // on the UI thread once the user has finished entering this PIN into the UI, 577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // but only after the UI has been asked to provide a PIN (via FetchSecret()). 58bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch void ProvideSecret(const std::string& pin, bool create_pair); 597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 609ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // Schedules a redraw on the display thread. May be called from any thread. 619ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch void RedrawDesktop(); 629ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch 63a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Moves the host's cursor to the specified coordinates, optionally with some 64a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. 65a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch void PerformMouseAction(int x, 66a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch int y, 67a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch protocol::MouseEvent_MouseButton button, 68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) bool button_down); 69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Sends the provided keyboard scan code to the host. 71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void PerformKeyboardAction(int key_code, bool key_down); 72a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ClientUserInterface implementation. 747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void OnConnectionState( 757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protocol::ConnectionToHost::State state, 767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protocol::ErrorCode error) OVERRIDE; 777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void OnConnectionReady(bool ready) OVERRIDE; 787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void SetPairingResponse( 807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const protocol::PairingResponse& response) OVERRIDE; 81c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch virtual void DeliverHostMessage( 82c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch const protocol::ExtensionMessage& message) OVERRIDE; 837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 88a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // CursorShapeStub implementation. 89a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual void InjectClipboardEvent( 90a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch const protocol::ClipboardEvent& event) OVERRIDE; 91a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 92a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // ClipboardStub implementation. 93a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual void SetCursorShape(const protocol::CursorShapeInfo& shape) OVERRIDE; 94a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private: 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // This object is ref-counted, so it cleans itself up. 977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual ~ChromotingJniInstance(); 987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void ConnectToHostOnDisplayThread(); 1007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void ConnectToHostOnNetworkThread(); 1019ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch void DisconnectFromHostOnNetworkThread(); 1027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Notifies the user interface that the user needs to enter a PIN. The 1047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // current authentication attempt is put on hold until |callback| is invoked. 1059ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // May be called on any thread. 1067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void FetchSecret(bool pairable, 1077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const protocol::SecretFetchedCallback& callback); 1087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 109bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // Used to obtain task runner references and make calls to Java methods. 110bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ChromotingJniRuntime* jni_runtime_; 111bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 1129ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // This group of variables is to be used on the display thread. 1137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_refptr<FrameConsumerProxy> frame_consumer_; 1149ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch scoped_ptr<JniFrameConsumer> view_; 1159ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch scoped_ptr<base::WeakPtrFactory<JniFrameConsumer> > view_weak_factory_; 1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // This group of variables is to be used on the network thread. 1187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<ClientConfig> client_config_; 1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<ClientContext> client_context_; 1207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<protocol::ConnectionToHost> connection_; 1217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<ChromotingClient> client_; 1227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<XmppSignalStrategy::XmppServerConfig> signaling_config_; 1237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_ 1247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<NetworkSettings> network_settings_; 1257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Pass this the user's PIN once we have it. To be assigned and accessed on 1277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // the UI thread, but must be posted to the network thread to call it. 1287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protocol::SecretFetchedCallback pin_callback_; 1297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // These strings describe the current connection, and are not reused. They 1317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // are initialized in ConnectionToHost(), but thereafter are only to be used 1327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // on the network thread. (This is safe because ConnectionToHost()'s finishes 1337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // using them on the UI thread before they are ever touched from network.) 1347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string username_; 1357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string auth_token_; 1367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string host_jid_; 1377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string host_id_; 1387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string host_pubkey_; 139bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch std::string pairing_id_; 140bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch std::string pairing_secret_; 141bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 142bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // Indicates whether to establish a new pairing with this host. This is 143bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // modified in ProvideSecret(), but thereafter to be used only from the 144bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // network thread. (This is safe because ProvideSecret() is invoked at most 145bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // once per run, and always before any reference to this flag.) 146bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool create_pairing_; 1477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch friend class base::RefCountedThreadSafe<ChromotingJniInstance>; 1497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance); 1517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}; 1527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} // namespace remoting 1547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#endif 156