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 ChromotingJNIInstance class serves | 8 // the C++ codebase from Java. The separate ChromotingJni class serves as the |
9 // as the corresponding exit point, and is responsible for making all JNI calls | 9 // 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" |
18 #include "remoting/client/jni/chromoting_jni_instance.h" | 19 #include "remoting/client/jni/chromoting_jni_instance.h" |
19 | 20 |
20 // 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. |
21 #define JNI_IMPLEMENTATION(method) \ | 22 #define JNI_IMPLEMENTATION(method) \ |
22 Java_org_chromium_chromoting_jni_JNIInterface_##method | 23 Java_org_chromium_chromoting_jni_JNIInterface_##method |
23 | 24 |
24 extern "C" { | 25 extern "C" { |
25 | 26 |
26 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 27 JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
27 base::android::InitVM(vm); | 28 base::android::InitVM(vm); |
28 return JNI_VERSION_1_2; | 29 return JNI_VERSION_1_2; |
29 } | 30 } |
30 | 31 |
31 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(loadNative)(JNIEnv* env, | 32 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(loadNative)(JNIEnv* env, |
32 jobject that, | 33 jobject that, |
33 jobject context) { | 34 jobject context) { |
34 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); | 35 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); |
35 base::android::InitApplicationContext(context_activity); | 36 base::android::InitApplicationContext(context_activity); |
36 | 37 |
37 // 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 |
38 // runtime API keys have been specified by the environment. Unfortunately, we | 39 // runtime API keys have been specified by the environment. Unfortunately, we |
39 // 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 |
40 // them from DCHECKing out when they go looking. | 41 // them from DCHECKing out when they go looking. |
41 CommandLine::Init(0, NULL); | 42 CommandLine::Init(0, NULL); |
42 | 43 |
43 // 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. |
44 remoting::ChromotingJNIInstance::GetInstance(); | 45 remoting::ChromotingJni::GetInstance(); |
45 } | 46 } |
46 | 47 |
47 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, | 48 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, |
48 jobject that) { | 49 jobject that) { |
49 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); | 50 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); |
50 } | 51 } |
51 | 52 |
52 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, | 53 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, |
53 jobject that) { | 54 jobject that) { |
54 return env->NewStringUTF( | 55 return env->NewStringUTF( |
(...skipping 13 matching lines...) Expand all Loading... |
68 jstring auth_token_jstr, | 69 jstring auth_token_jstr, |
69 jstring host_jid_jstr, | 70 jstring host_jid_jstr, |
70 jstring host_id_jstr, | 71 jstring host_id_jstr, |
71 jstring host_pubkey_jstr) { | 72 jstring host_pubkey_jstr) { |
72 const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); | 73 const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); |
73 const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); | 74 const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); |
74 const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); | 75 const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); |
75 const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); | 76 const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); |
76 const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); | 77 const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); |
77 | 78 |
78 remoting::ChromotingJNIInstance::GetInstance()->ConnectToHost( | 79 remoting::ChromotingJni::GetInstance()->ConnectToHost( |
79 username_cstr, | 80 username_cstr, |
80 auth_token_cstr, | 81 auth_token_cstr, |
81 host_jid_cstr, | 82 host_jid_cstr, |
82 host_id_cstr, | 83 host_id_cstr, |
83 host_pubkey_cstr); | 84 host_pubkey_cstr); |
84 | 85 |
85 env->ReleaseStringUTFChars(username_jstr, username_cstr); | 86 env->ReleaseStringUTFChars(username_jstr, username_cstr); |
86 env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); | 87 env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); |
87 env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); | 88 env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); |
88 env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); | 89 env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); |
89 env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); | 90 env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); |
90 } | 91 } |
91 | 92 |
92 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, | 93 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, |
93 jobject that) { | 94 jobject that) { |
94 remoting::ChromotingJNIInstance::GetInstance()->DisconnectFromHost(); | 95 remoting::ChromotingJni::GetInstance()->DisconnectFromHost(); |
95 } | 96 } |
96 | 97 |
97 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( | 98 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( |
98 JNIEnv* env, | 99 JNIEnv* env, |
99 jobject that, | 100 jobject that, |
100 jstring pin_jstr) { | 101 jstring pin_jstr) { |
101 const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); | 102 const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); |
102 | 103 |
103 remoting::ChromotingJNIInstance::GetInstance()->ProvideSecret(pin_cstr); | 104 remoting::ChromotingJni::GetInstance()-> |
| 105 session()->ProvideSecret(pin_cstr); |
104 | 106 |
105 env->ReleaseStringUTFChars(pin_jstr, pin_cstr); | 107 env->ReleaseStringUTFChars(pin_jstr, pin_cstr); |
106 } | 108 } |
107 | 109 |
108 } // extern "C" | 110 } // extern "C" |
OLD | NEW |