| 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/ref_counted.h" | |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/protocol/connection_to_host.h" | 13 #include "remoting/protocol/connection_to_host.h" |
| 15 #include "remoting/protocol/cursor_shape_stub.h" | 14 #include "remoting/protocol/cursor_shape_stub.h" |
| 16 | 15 |
| 17 namespace remoting { | 16 namespace remoting { |
| 18 | 17 |
| 19 class ChromotingJniRuntime; | 18 class ChromotingJniRuntime; |
| 20 class ChromotingJniInstance; | 19 class ChromotingJniInstance; |
| 20 class JniDisplayHandler; |
| 21 class JniPairingSecretFetcher; |
| 21 | 22 |
| 22 // Houses resources scoped to a session and exposes JNI interface to the | 23 // Houses resources scoped to a session and exposes JNI interface to the |
| 23 // Java client during a session. All its methods should be invoked exclusively | 24 // Java client during a session. All its methods should be invoked exclusively |
| 24 // from the UI thread unless otherwise noted. | 25 // from the UI thread unless otherwise noted. |
| 25 class JniClient { | 26 class JniClient { |
| 26 public: | 27 public: |
| 27 JniClient(jobject java_client); | 28 JniClient(ChromotingJniRuntime* runtime, |
| 29 base::android::ScopedJavaGlobalRef<jobject> java_client); |
| 30 virtual ~JniClient(); |
| 28 | 31 |
| 29 // Initiates a connection with the specified host. Only call when a host | 32 // Initiates a connection with the specified host. To skip the attempt at |
| 30 // connection is active (i.e. between a call to Connect() and the | 33 // pair-based authentication, leave |pairing_id| and |pairing_secret| as |
| 31 // corresponding call to Disconnect()). To skip the attempt at pair-based | 34 // empty strings. |
| 32 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. | 35 void ConnectToHost(base::WeakPtr<JniDisplayHandler> handler, |
| 33 void ConnectToHost(const std::string& username, | 36 const std::string& username, |
| 34 const std::string& auth_token, | 37 const std::string& auth_token, |
| 35 const std::string& host_jid, | 38 const std::string& host_jid, |
| 36 const std::string& host_id, | 39 const std::string& host_id, |
| 37 const std::string& host_pubkey, | 40 const std::string& host_pubkey, |
| 38 const std::string& pairing_id, | 41 const std::string& pairing_id, |
| 39 const std::string& pairing_secret, | 42 const std::string& pairing_secret, |
| 40 const std::string& capabilities, | 43 const std::string& capabilities, |
| 41 const std::string& flags); | 44 const std::string& flags); |
| 42 | 45 |
| 43 // Terminates any ongoing connection attempt and cleans up by nullifying | 46 // Terminates any ongoing connection attempt and cleans up by nullifying |
| (...skipping 19 matching lines...) Expand all Loading... |
| 63 const std::string& scope); | 66 const std::string& scope); |
| 64 | 67 |
| 65 // Pass on the set of negotiated capabilities to the client. | 68 // Pass on the set of negotiated capabilities to the client. |
| 66 void SetCapabilities(const std::string& capabilities); | 69 void SetCapabilities(const std::string& capabilities); |
| 67 | 70 |
| 68 // Passes on the deconstructed ExtensionMessage to the client to handle | 71 // Passes on the deconstructed ExtensionMessage to the client to handle |
| 69 // appropriately. | 72 // appropriately. |
| 70 void HandleExtensionMessage(const std::string& type, | 73 void HandleExtensionMessage(const std::string& type, |
| 71 const std::string& message); | 74 const std::string& message); |
| 72 | 75 |
| 73 // Creates a new Bitmap object to store a video frame. | |
| 74 base::android::ScopedJavaLocalRef<jobject> NewBitmap(int width, int height); | |
| 75 | |
| 76 // Updates video frame bitmap. |bitmap| must be an instance of | |
| 77 // android.graphics.Bitmap. Call on the display thread. | |
| 78 void UpdateFrameBitmap(jobject bitmap); | |
| 79 | |
| 80 // Updates cursor shape. Call on display thread. | |
| 81 void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape); | |
| 82 | |
| 83 // Draws the latest image buffer onto the canvas. Call on the display thread. | |
| 84 void RedrawCanvas(); | |
| 85 | |
| 86 // Register C++ methods exposed to Java using JNI. | 76 // Register C++ methods exposed to Java using JNI. |
| 87 static bool RegisterJni(JNIEnv* env); | 77 static bool RegisterJni(JNIEnv* env); |
| 88 | 78 |
| 89 // The following methods are exposed to Java via JNI. | 79 // The following methods are exposed to Java via JNI. |
| 90 | 80 |
| 91 void Connect(JNIEnv* env, | 81 void Connect(JNIEnv* env, |
| 92 const base::android::JavaParamRef<jobject>& caller, | 82 const base::android::JavaParamRef<jobject>& caller, |
| 83 jlong display_handler_ptr, |
| 93 const base::android::JavaParamRef<jstring>& username, | 84 const base::android::JavaParamRef<jstring>& username, |
| 94 const base::android::JavaParamRef<jstring>& authToken, | 85 const base::android::JavaParamRef<jstring>& authToken, |
| 95 const base::android::JavaParamRef<jstring>& hostJid, | 86 const base::android::JavaParamRef<jstring>& hostJid, |
| 96 const base::android::JavaParamRef<jstring>& hostId, | 87 const base::android::JavaParamRef<jstring>& hostId, |
| 97 const base::android::JavaParamRef<jstring>& hostPubkey, | 88 const base::android::JavaParamRef<jstring>& hostPubkey, |
| 98 const base::android::JavaParamRef<jstring>& pairId, | 89 const base::android::JavaParamRef<jstring>& pairId, |
| 99 const base::android::JavaParamRef<jstring>& pairSecret, | 90 const base::android::JavaParamRef<jstring>& pairSecret, |
| 100 const base::android::JavaParamRef<jstring>& capabilities, | 91 const base::android::JavaParamRef<jstring>& capabilities, |
| 101 const base::android::JavaParamRef<jstring>& flags); | 92 const base::android::JavaParamRef<jstring>& flags); |
| 102 | 93 |
| 103 void Disconnect(JNIEnv* env, | 94 void Disconnect(JNIEnv* env, |
| 104 const base::android::JavaParamRef<jobject>& caller); | 95 const base::android::JavaParamRef<jobject>& caller); |
| 105 | 96 |
| 106 void AuthenticationResponse( | 97 void AuthenticationResponse( |
| 107 JNIEnv* env, | 98 JNIEnv* env, |
| 108 const base::android::JavaParamRef<jobject>& caller, | 99 const base::android::JavaParamRef<jobject>& caller, |
| 109 const base::android::JavaParamRef<jstring>& pin, | 100 const base::android::JavaParamRef<jstring>& pin, |
| 110 jboolean createPair, | 101 jboolean createPair, |
| 111 const base::android::JavaParamRef<jstring>& deviceName); | 102 const base::android::JavaParamRef<jstring>& deviceName); |
| 112 | 103 |
| 113 void ScheduleRedraw(JNIEnv* env, | |
| 114 const base::android::JavaParamRef<jobject>& caller); | |
| 115 | |
| 116 void SendMouseEvent(JNIEnv* env, | 104 void SendMouseEvent(JNIEnv* env, |
| 117 const base::android::JavaParamRef<jobject>& caller, | 105 const base::android::JavaParamRef<jobject>& caller, |
| 118 jint x, | 106 jint x, |
| 119 jint y, | 107 jint y, |
| 120 jint whichButton, | 108 jint whichButton, |
| 121 jboolean buttonDown); | 109 jboolean buttonDown); |
| 122 | 110 |
| 123 void SendMouseWheelEvent(JNIEnv* env, | 111 void SendMouseWheelEvent(JNIEnv* env, |
| 124 const base::android::JavaParamRef<jobject>& caller, | 112 const base::android::JavaParamRef<jobject>& caller, |
| 125 jint delta_x, | 113 jint delta_x, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 149 JNIEnv* env, | 137 JNIEnv* env, |
| 150 const base::android::JavaParamRef<jobject>& caller, | 138 const base::android::JavaParamRef<jobject>& caller, |
| 151 const base::android::JavaParamRef<jstring>& token, | 139 const base::android::JavaParamRef<jstring>& token, |
| 152 const base::android::JavaParamRef<jstring>& shared_secret); | 140 const base::android::JavaParamRef<jstring>& shared_secret); |
| 153 | 141 |
| 154 void SendExtensionMessage(JNIEnv* env, | 142 void SendExtensionMessage(JNIEnv* env, |
| 155 const base::android::JavaParamRef<jobject>& caller, | 143 const base::android::JavaParamRef<jobject>& caller, |
| 156 const base::android::JavaParamRef<jstring>& type, | 144 const base::android::JavaParamRef<jstring>& type, |
| 157 const base::android::JavaParamRef<jstring>& data); | 145 const base::android::JavaParamRef<jstring>& data); |
| 158 | 146 |
| 159 // Destroys this object. Called on UI thread. This function will delete the | 147 // Deletes this object. |
| 160 // |java_client_| reference and delete |this|. | |
| 161 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); | 148 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); |
| 162 | 149 |
| 163 // Get the weak pointer of the object. Should be used on the UI thread. | 150 // Get the weak pointer of the object. Should be used on the UI thread. |
| 164 // TODO(yuweih): Instead of exposing a weak pointer in the public API, | 151 // TODO(yuweih): Instead of exposing a weak pointer in the public API, |
| 165 // consider handling task posting inside the client. | 152 // consider handling task posting inside the client. |
| 166 base::WeakPtr<JniClient> GetWeakPtr(); | 153 base::WeakPtr<JniClient> GetWeakPtr(); |
| 167 | 154 |
| 168 private: | 155 private: |
| 169 // Please use Destroy() to delete this object. | 156 ChromotingJniRuntime* runtime_; |
| 170 ~JniClient(); | |
| 171 | |
| 172 // Helper function for getting the runtime instance. | |
| 173 static ChromotingJniRuntime* runtime(); | |
| 174 | 157 |
| 175 // Reference to the Java client object. | 158 // Reference to the Java client object. |
| 176 jobject java_client_; | 159 base::android::ScopedJavaGlobalRef<jobject> java_client_; |
| 177 | 160 |
| 178 scoped_refptr<ChromotingJniInstance> session_; | 161 base::WeakPtr<JniDisplayHandler> display_handler_; |
| 162 |
| 163 // Deleted on UI thread. |
| 164 std::unique_ptr<JniPairingSecretFetcher> secret_fetcher_; |
| 165 |
| 166 // Deleted on Network thread. |
| 167 std::unique_ptr<ChromotingJniInstance> session_; |
| 179 | 168 |
| 180 // Holds pointer for the UI thread. | 169 // Holds pointer for the UI thread. |
| 181 base::WeakPtrFactory<JniClient> weak_factory_; | 170 base::WeakPtrFactory<JniClient> weak_factory_; |
| 182 | 171 |
| 183 DISALLOW_COPY_AND_ASSIGN(JniClient); | 172 DISALLOW_COPY_AND_ASSIGN(JniClient); |
| 184 }; | 173 }; |
| 185 | 174 |
| 186 } // namespace remoting | 175 } // namespace remoting |
| 187 | 176 |
| 188 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 177 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
| OLD | NEW |