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" | |
14 #include "remoting/protocol/connection_to_host.h" | |
15 #include "remoting/protocol/cursor_shape_stub.h" | |
12 | 16 |
13 namespace remoting { | 17 namespace remoting { |
14 | 18 |
19 class ChromotingJniRuntime; | |
20 class ChromotingJniInstance; | |
21 | |
22 // 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 // from the UI thread unless otherwise noted. | |
15 class JniClient { | 25 class JniClient { |
16 public: | 26 public: |
17 JniClient(); | 27 JniClient(jobject java_client); |
18 ~JniClient(); | 28 |
29 // Initiates a connection with the specified host. Only call when a host | |
30 // connection is active (i.e. between a call to Connect() and the | |
31 // corresponding call to Disconnect()). To skip the attempt at pair-based | |
32 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. | |
33 void ConnectToHost(const std::string& username, | |
34 const std::string& auth_token, | |
35 const std::string& host_jid, | |
36 const std::string& host_id, | |
37 const std::string& host_pubkey, | |
38 const std::string& pairing_id, | |
39 const std::string& pairing_secret, | |
40 const std::string& capabilities, | |
41 const std::string& flags); | |
42 | |
43 // Terminates any ongoing connection attempt and cleans up by nullifying | |
44 // |session_|. This is a no-op unless |session| is currently non-null. | |
45 void DisconnectFromHost(); | |
46 | |
47 // Notifies Java code of the current connection status. Call on UI thread. | |
48 void OnConnectionState(protocol::ConnectionToHost::State state, | |
49 protocol::ErrorCode error); | |
50 | |
51 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. | |
52 void DisplayAuthenticationPrompt(bool pairing_supported); | |
53 | |
54 // Saves new pairing credentials to permanent storage. Call on UI thread. | |
55 void CommitPairingCredentials(const std::string& host, | |
56 const std::string& id, | |
57 const std::string& secret); | |
58 | |
59 // Pops up a third party login page to fetch token required for | |
60 // authentication. Call on UI thread. | |
61 void FetchThirdPartyToken(const std::string& token_url, | |
62 const std::string& client_id, | |
63 const std::string& scope); | |
64 | |
65 // Pass on the set of negotiated capabilities to the client. | |
66 void SetCapabilities(const std::string& capabilities); | |
67 | |
68 // Passes on the deconstructed ExtensionMessage to the client to handle | |
69 // appropriately. | |
70 void HandleExtensionMessage(const std::string& type, | |
71 const std::string& message); | |
72 | |
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(); | |
19 | 85 |
20 // Register C++ methods exposed to Java using JNI. | 86 // Register C++ methods exposed to Java using JNI. |
21 static bool RegisterJni(JNIEnv* env); | 87 static bool RegisterJni(JNIEnv* env); |
22 | 88 |
89 // JNI Interface. | |
Lambros
2016/05/25 20:51:50
Maybe remove this comment, or say instead "The fol
Yuwei
2016/05/25 21:19:53
Done.
| |
90 | |
91 void Connect(JNIEnv* env, | |
92 const base::android::JavaParamRef<jobject>& caller, | |
93 const base::android::JavaParamRef<jstring>& username, | |
94 const base::android::JavaParamRef<jstring>& authToken, | |
95 const base::android::JavaParamRef<jstring>& hostJid, | |
96 const base::android::JavaParamRef<jstring>& hostId, | |
97 const base::android::JavaParamRef<jstring>& hostPubkey, | |
98 const base::android::JavaParamRef<jstring>& pairId, | |
99 const base::android::JavaParamRef<jstring>& pairSecret, | |
100 const base::android::JavaParamRef<jstring>& capabilities, | |
101 const base::android::JavaParamRef<jstring>& flags); | |
102 | |
103 void Disconnect(JNIEnv* env, | |
104 const base::android::JavaParamRef<jobject>& caller); | |
105 | |
106 void AuthenticationResponse( | |
107 JNIEnv* env, | |
108 const base::android::JavaParamRef<jobject>& caller, | |
109 const base::android::JavaParamRef<jstring>& pin, | |
110 jboolean createPair, | |
111 const base::android::JavaParamRef<jstring>& deviceName); | |
112 | |
113 void ScheduleRedraw(JNIEnv* env, | |
114 const base::android::JavaParamRef<jobject>& caller); | |
115 | |
116 void SendMouseEvent(JNIEnv* env, | |
117 const base::android::JavaParamRef<jobject>& caller, | |
118 jint x, | |
119 jint y, | |
120 jint whichButton, | |
121 jboolean buttonDown); | |
122 | |
123 void SendMouseWheelEvent(JNIEnv* env, | |
124 const base::android::JavaParamRef<jobject>& caller, | |
125 jint delta_x, | |
126 jint delta_y); | |
127 | |
128 jboolean SendKeyEvent(JNIEnv* env, | |
129 const base::android::JavaParamRef<jobject>& caller, | |
130 jint scanCode, | |
131 jint keyCode, | |
132 jboolean keyDown); | |
133 | |
134 void SendTextEvent(JNIEnv* env, | |
135 const base::android::JavaParamRef<jobject>& caller, | |
136 const base::android::JavaParamRef<jstring>& text); | |
137 | |
138 void SendTouchEvent( | |
139 JNIEnv* env, | |
140 const base::android::JavaParamRef<jobject>& caller, | |
141 jint eventType, | |
142 const base::android::JavaParamRef<jobjectArray>& touchEventObjectArray); | |
143 | |
144 void EnableVideoChannel(JNIEnv* env, | |
145 const base::android::JavaParamRef<jobject>& caller, | |
146 jboolean enable); | |
147 | |
148 void OnThirdPartyTokenFetched( | |
149 JNIEnv* env, | |
150 const base::android::JavaParamRef<jobject>& caller, | |
151 const base::android::JavaParamRef<jstring>& token, | |
152 const base::android::JavaParamRef<jstring>& shared_secret); | |
153 | |
154 void SendExtensionMessage(JNIEnv* env, | |
155 const base::android::JavaParamRef<jobject>& caller, | |
156 const base::android::JavaParamRef<jstring>& type, | |
157 const base::android::JavaParamRef<jstring>& data); | |
158 | |
159 // Destroys this object. Called on UI thread. This function will delete the | |
160 // |java_client_| reference and delete |this|. | |
23 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); | 161 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); |
24 | 162 |
163 // Get the weak pointer of the object. Should be used on the UI thread. | |
164 base::WeakPtr<JniClient> GetWeakPtr(); | |
Lambros
2016/05/25 20:51:50
Optional, I don't mind either way:
Instead of expo
Yuwei
2016/05/25 21:19:53
Left a TODO comment
| |
165 | |
25 private: | 166 private: |
167 // Please use Destroy() to delete this object. | |
168 ~JniClient(); | |
169 | |
170 // Helper function for getting the runtime instance. | |
171 static ChromotingJniRuntime* runtime(); | |
172 | |
173 // Pointer to the Java client object. | |
Lambros
2016/05/25 20:51:50
s/Pointer/Reference/
Yuwei
2016/05/25 21:19:53
Done.
| |
174 jobject java_client_; | |
175 | |
176 scoped_refptr<ChromotingJniInstance> session_; | |
177 | |
178 // Holds pointer for the UI thread. | |
179 base::WeakPtrFactory<JniClient> weak_factory_; | |
180 | |
26 DISALLOW_COPY_AND_ASSIGN(JniClient); | 181 DISALLOW_COPY_AND_ASSIGN(JniClient); |
27 }; | 182 }; |
28 | 183 |
29 } // namespace remoting | 184 } // namespace remoting |
30 | 185 |
31 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 186 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
OLD | NEW |