OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This file defines functions that implement the static methods declared in a | 5 // This file defines functions that implement the static methods declared in a |
6 // closely-related Java class in the platform-specific user interface | 6 // closely-related Java class in the platform-specific user interface |
7 // implementation. In effect, it is the entry point for all JNI calls *into* | 7 // implementation. In effect, it is the entry point for all JNI calls *into* |
8 // the C++ codebase from Java. The separate ChromotingJni class serves as the | 8 // the C++ codebase from Java. The separate ChromotingJniRuntime class serves |
9 // corresponding exit point, and is responsible for making all JNI calls | 9 // as the corresponding exit point, and is responsible for making all JNI calls |
10 // *out of* the C++ codebase into Java. | 10 // *out of* the C++ codebase into Java. |
11 | 11 |
12 #include <jni.h> | 12 #include <jni.h> |
13 | 13 |
14 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
18 #include "remoting/client/jni/chromoting_jni.h" | |
19 #include "remoting/client/jni/chromoting_jni_instance.h" | 18 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 19 #include "remoting/client/jni/chromoting_jni_runtime.h" |
20 | 20 |
21 // Class and package name of the Java class that declares this file's functions. | 21 // Class and package name of the Java class that declares this file's functions. |
22 #define JNI_IMPLEMENTATION(method) \ | 22 #define JNI_IMPLEMENTATION(method) \ |
23 Java_org_chromium_chromoting_jni_JniInterface_##method | 23 Java_org_chromium_chromoting_jni_JniInterface_##method |
24 | 24 |
25 extern "C" { | 25 extern "C" { |
26 | 26 |
27 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 27 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
28 base::android::InitVM(vm); | 28 base::android::InitVM(vm); |
29 return JNI_VERSION_1_2; | 29 return JNI_VERSION_1_2; |
30 } | 30 } |
31 | 31 |
32 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(loadNative)(JNIEnv* env, | 32 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(loadNative)(JNIEnv* env, |
33 jobject that, | 33 jobject that, |
34 jobject context) { | 34 jobject context) { |
35 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); | 35 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); |
36 base::android::InitApplicationContext(context_activity); | 36 base::android::InitApplicationContext(context_activity); |
37 | 37 |
38 // The google_apis functions check the command-line arguments to make sure no | 38 // The google_apis functions check the command-line arguments to make sure no |
39 // runtime API keys have been specified by the environment. Unfortunately, we | 39 // runtime API keys have been specified by the environment. Unfortunately, we |
40 // neither launch Chromium nor have a command line, so we need to prevent | 40 // neither launch Chromium nor have a command line, so we need to prevent |
41 // them from DCHECKing out when they go looking. | 41 // them from DCHECKing out when they go looking. |
42 CommandLine::Init(0, NULL); | 42 CommandLine::Init(0, NULL); |
43 | 43 |
44 // Create the singleton now so that the Chromoting threads will be set up. | 44 // Create the singleton now so that the Chromoting threads will be set up. |
45 remoting::ChromotingJni::GetInstance(); | 45 remoting::ChromotingJniRuntime::GetInstance(); |
46 } | 46 } |
47 | 47 |
48 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, | 48 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, |
49 jobject that) { | 49 jobject that) { |
50 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); | 50 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); |
51 } | 51 } |
52 | 52 |
53 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, | 53 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, |
54 jobject that) { | 54 jobject that) { |
55 return env->NewStringUTF( | 55 return env->NewStringUTF( |
(...skipping 13 matching lines...) Expand all Loading... |
69 jstring auth_token_jstr, | 69 jstring auth_token_jstr, |
70 jstring host_jid_jstr, | 70 jstring host_jid_jstr, |
71 jstring host_id_jstr, | 71 jstring host_id_jstr, |
72 jstring host_pubkey_jstr) { | 72 jstring host_pubkey_jstr) { |
73 const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); | 73 const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); |
74 const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); | 74 const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); |
75 const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); | 75 const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); |
76 const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); | 76 const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); |
77 const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); | 77 const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); |
78 | 78 |
79 remoting::ChromotingJni::GetInstance()->ConnectToHost( | 79 remoting::ChromotingJniRuntime::GetInstance()->ConnectToHost( |
80 username_cstr, | 80 username_cstr, |
81 auth_token_cstr, | 81 auth_token_cstr, |
82 host_jid_cstr, | 82 host_jid_cstr, |
83 host_id_cstr, | 83 host_id_cstr, |
84 host_pubkey_cstr); | 84 host_pubkey_cstr); |
85 | 85 |
86 env->ReleaseStringUTFChars(username_jstr, username_cstr); | 86 env->ReleaseStringUTFChars(username_jstr, username_cstr); |
87 env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); | 87 env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); |
88 env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); | 88 env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); |
89 env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); | 89 env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); |
90 env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); | 90 env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); |
91 } | 91 } |
92 | 92 |
93 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, | 93 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, |
94 jobject that) { | 94 jobject that) { |
95 remoting::ChromotingJni::GetInstance()->DisconnectFromHost(); | 95 remoting::ChromotingJniRuntime::GetInstance()->DisconnectFromHost(); |
96 } | 96 } |
97 | 97 |
98 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( | 98 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( |
99 JNIEnv* env, | 99 JNIEnv* env, |
100 jobject that, | 100 jobject that, |
101 jstring pin_jstr) { | 101 jstring pin_jstr) { |
102 const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); | 102 const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); |
103 | 103 |
104 remoting::ChromotingJni::GetInstance()-> | 104 remoting::ChromotingJniRuntime::GetInstance()-> |
105 session()->ProvideSecret(pin_cstr); | 105 session()->ProvideSecret(pin_cstr); |
106 | 106 |
107 env->ReleaseStringUTFChars(pin_jstr, pin_cstr); | 107 env->ReleaseStringUTFChars(pin_jstr, pin_cstr); |
108 } | 108 } |
109 | 109 |
110 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(scheduleRedrawNative)( | 110 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(scheduleRedrawNative)( |
111 JNIEnv* env, | 111 JNIEnv* env, |
112 jobject that) { | 112 jobject that) { |
113 remoting::ChromotingJni::GetInstance()->session()->RedrawDesktop(); | 113 remoting::ChromotingJniRuntime::GetInstance()->session()->RedrawDesktop(); |
114 } | 114 } |
115 | 115 |
116 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(mouseActionNative)( | 116 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(mouseActionNative)( |
117 JNIEnv* env, | 117 JNIEnv* env, |
118 jobject that, | 118 jobject that, |
119 jint x, | 119 jint x, |
120 jint y, | 120 jint y, |
121 jint which_button, | 121 jint which_button, |
122 jboolean button_down) { | 122 jboolean button_down) { |
123 remoting::ChromotingJni::GetInstance()->session()->PerformMouseAction( | 123 remoting::ChromotingJniRuntime::GetInstance()->session()->PerformMouseAction( |
124 x, | 124 x, |
125 y, | 125 y, |
126 static_cast<remoting::protocol::MouseEvent_MouseButton>(which_button), | 126 static_cast<remoting::protocol::MouseEvent_MouseButton>(which_button), |
127 button_down); | 127 button_down); |
128 } | 128 } |
129 | 129 |
130 } // extern "C" | 130 } // extern "C" |
OLD | NEW |