| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 5 #ifndef REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
| 6 #define REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 6 #define REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "remoting/client/chromoting_session.h" |
| 13 #include "remoting/protocol/connection_to_host.h" | 14 #include "remoting/protocol/connection_to_host.h" |
| 14 #include "remoting/protocol/cursor_shape_stub.h" | 15 #include "remoting/protocol/cursor_shape_stub.h" |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 | 18 |
| 19 class AudioPlayerAndroid; |
| 18 class ChromotingClientRuntime; | 20 class ChromotingClientRuntime; |
| 19 class ChromotingJniInstance; | |
| 20 class JniGlDisplayHandler; | 21 class JniGlDisplayHandler; |
| 21 class JniPairingSecretFetcher; | 22 class JniPairingSecretFetcher; |
| 22 | 23 |
| 23 struct ConnectToHostInfo; | 24 struct ConnectToHostInfo; |
| 24 | 25 |
| 25 // Houses resources scoped to a session and exposes JNI interface to the | 26 // Houses resources scoped to a session and exposes JNI interface to the |
| 26 // Java client during a session. All its methods should be invoked exclusively | 27 // Java client during a session. All its methods should be invoked exclusively |
| 27 // from the UI thread unless otherwise noted. | 28 // from the UI thread unless otherwise noted. |
| 28 class JniClient { | 29 class JniClient : public ChromotingSession::Delegate { |
| 29 public: | 30 public: |
| 30 JniClient(base::android::ScopedJavaGlobalRef<jobject> java_client); | 31 JniClient(base::android::ScopedJavaGlobalRef<jobject> java_client); |
| 31 virtual ~JniClient(); | 32 ~JniClient() override; |
| 32 | 33 |
| 33 // Initiates a connection with the specified host. To skip the attempt at | 34 // Initiates a connection with the specified host. To skip the attempt at |
| 34 // pair-based authentication, leave |pairing_id| and |pairing_secret| as | 35 // pair-based authentication, leave |pairing_id| and |pairing_secret| as |
| 35 // empty strings. | 36 // empty strings. |
| 36 void ConnectToHost(const ConnectToHostInfo& info); | 37 void ConnectToHost(const ConnectToHostInfo& info); |
| 37 | 38 |
| 38 // Terminates any ongoing connection attempt and cleans up by nullifying | 39 // Terminates any ongoing connection attempt and cleans up by nullifying |
| 39 // |session_|. This is a no-op unless |session| is currently non-null. | 40 // |session_|. This is a no-op unless |session| is currently non-null. |
| 40 void DisconnectFromHost(); | 41 void DisconnectFromHost(); |
| 41 | 42 |
| 42 // Notifies Java code of the current connection status. Call on UI thread. | |
| 43 void OnConnectionState(protocol::ConnectionToHost::State state, | |
| 44 protocol::ErrorCode error); | |
| 45 | |
| 46 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. | 43 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. |
| 47 void DisplayAuthenticationPrompt(bool pairing_supported); | 44 void DisplayAuthenticationPrompt(bool pairing_supported); |
| 48 | 45 |
| 46 // Register C++ methods exposed to Java using JNI. |
| 47 static bool RegisterJni(JNIEnv* env); |
| 48 |
| 49 // ChromotingSession::Delegate implementation |
| 50 |
| 51 // Notifies Java code of the current connection status. Call on UI thread. |
| 52 void OnConnectionState(protocol::ConnectionToHost::State state, |
| 53 protocol::ErrorCode error) override; |
| 54 |
| 49 // Saves new pairing credentials to permanent storage. Call on UI thread. | 55 // Saves new pairing credentials to permanent storage. Call on UI thread. |
| 50 void CommitPairingCredentials(const std::string& host, | 56 void CommitPairingCredentials(const std::string& host, |
| 51 const std::string& id, | 57 const std::string& id, |
| 52 const std::string& secret); | 58 const std::string& secret) override; |
| 53 | 59 |
| 54 // Pops up a third party login page to fetch token required for | 60 // Pops up a third party login page to fetch token required for |
| 55 // authentication. Call on UI thread. | 61 // authentication. Call on UI thread. |
| 56 void FetchThirdPartyToken(const std::string& token_url, | 62 void FetchThirdPartyToken(const std::string& token_url, |
| 57 const std::string& client_id, | 63 const std::string& client_id, |
| 58 const std::string& scope); | 64 const std::string& scope) override; |
| 59 | 65 |
| 60 // Pass on the set of negotiated capabilities to the client. | 66 // Pass on the set of negotiated capabilities to the client. |
| 61 void SetCapabilities(const std::string& capabilities); | 67 void SetCapabilities(const std::string& capabilities) override; |
| 62 | 68 |
| 63 // Passes on the deconstructed ExtensionMessage to the client to handle | 69 // Passes on the deconstructed ExtensionMessage to the client to handle |
| 64 // appropriately. | 70 // appropriately. |
| 65 void HandleExtensionMessage(const std::string& type, | 71 void HandleExtensionMessage(const std::string& type, |
| 66 const std::string& message); | 72 const std::string& message) override; |
| 67 | |
| 68 // Register C++ methods exposed to Java using JNI. | |
| 69 static bool RegisterJni(JNIEnv* env); | |
| 70 | 73 |
| 71 // The following methods are exposed to Java via JNI. | 74 // The following methods are exposed to Java via JNI. |
| 72 | 75 |
| 73 // TODO(yuweih): Pass a class/struct from Java holding all these arguments. | 76 // TODO(yuweih): Pass a class/struct from Java holding all these arguments. |
| 74 void Connect(JNIEnv* env, | 77 void Connect(JNIEnv* env, |
| 75 const base::android::JavaParamRef<jobject>& caller, | 78 const base::android::JavaParamRef<jobject>& caller, |
| 76 const base::android::JavaParamRef<jstring>& username, | 79 const base::android::JavaParamRef<jstring>& username, |
| 77 const base::android::JavaParamRef<jstring>& auth_token, | 80 const base::android::JavaParamRef<jstring>& auth_token, |
| 78 const base::android::JavaParamRef<jstring>& host_jid, | 81 const base::android::JavaParamRef<jstring>& host_jid, |
| 79 const base::android::JavaParamRef<jstring>& host_id, | 82 const base::android::JavaParamRef<jstring>& host_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // consider handling task posting inside the client. | 150 // consider handling task posting inside the client. |
| 148 base::WeakPtr<JniClient> GetWeakPtr(); | 151 base::WeakPtr<JniClient> GetWeakPtr(); |
| 149 | 152 |
| 150 private: | 153 private: |
| 151 ChromotingClientRuntime* runtime_; | 154 ChromotingClientRuntime* runtime_; |
| 152 | 155 |
| 153 // Reference to the Java client object. | 156 // Reference to the Java client object. |
| 154 base::android::ScopedJavaGlobalRef<jobject> java_client_; | 157 base::android::ScopedJavaGlobalRef<jobject> java_client_; |
| 155 | 158 |
| 156 std::unique_ptr<JniGlDisplayHandler> display_handler_; | 159 std::unique_ptr<JniGlDisplayHandler> display_handler_; |
| 160 std::unique_ptr<AudioPlayerAndroid> audio_player_; |
| 157 | 161 |
| 158 // Deleted on UI thread. | 162 // Deleted on UI thread. |
| 159 std::unique_ptr<JniPairingSecretFetcher> secret_fetcher_; | 163 std::unique_ptr<JniPairingSecretFetcher> secret_fetcher_; |
| 160 | 164 |
| 161 // Deleted on Network thread. | 165 // Deleted on Network thread. |
| 162 std::unique_ptr<ChromotingJniInstance> session_; | 166 std::unique_ptr<ChromotingSession> session_; |
| 163 | 167 |
| 164 // Holds pointer for the UI thread. | 168 // Holds pointer for the UI thread. |
| 165 base::WeakPtr<JniClient> weak_ptr_; | 169 base::WeakPtr<JniClient> weak_ptr_; |
| 166 base::WeakPtrFactory<JniClient> weak_factory_; | 170 base::WeakPtrFactory<JniClient> weak_factory_; |
| 167 | 171 |
| 168 DISALLOW_COPY_AND_ASSIGN(JniClient); | 172 DISALLOW_COPY_AND_ASSIGN(JniClient); |
| 169 }; | 173 }; |
| 170 | 174 |
| 171 } // namespace remoting | 175 } // namespace remoting |
| 172 | 176 |
| 173 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 177 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
| OLD | NEW |