| 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 ChromotingJNIInstance class serves |
| 9 // as the 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. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 jobject context) { | 33 jobject context) { |
| 34 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); | 34 base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); |
| 35 base::android::InitApplicationContext(context_activity); | 35 base::android::InitApplicationContext(context_activity); |
| 36 | 36 |
| 37 // The google_apis functions check the command-line arguments to make sure no | 37 // 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 | 38 // 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 | 39 // neither launch Chromium nor have a command line, so we need to prevent |
| 40 // them from DCHECKing out when they go looking. | 40 // them from DCHECKing out when they go looking. |
| 41 CommandLine::Init(0, NULL); | 41 CommandLine::Init(0, NULL); |
| 42 | 42 |
| 43 remoting::ChromotingJNIInstance::GetInstance(); // Initialize threads now. | 43 // Create the singleton now so that the Chromoting threads will be set up. |
| 44 remoting::ChromotingJNIInstance::GetInstance(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, | 47 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getApiKey)(JNIEnv* env, |
| 47 jobject that) { | 48 jobject that) { |
| 48 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); | 49 return env->NewStringUTF(google_apis::GetAPIKey().c_str()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, | 52 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientId)(JNIEnv* env, |
| 52 jobject that) { | 53 jobject that) { |
| 53 return env->NewStringUTF( | 54 return env->NewStringUTF( |
| 54 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING).c_str()); | 55 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING).c_str()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientSecret)(JNIEnv* env, | 58 JNIEXPORT jstring JNICALL JNI_IMPLEMENTATION(getClientSecret)(JNIEnv* env, |
| 58 jobject that) { | 59 jobject that) { |
| 59 return env->NewStringUTF( | 60 return env->NewStringUTF( |
| 60 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING).c_str()); | 61 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING).c_str()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(connectNative)(JNIEnv* env, | 64 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(connectNative)( |
| 64 jobject that, | 65 JNIEnv* env, |
| 65 jstring username, | 66 jobject that, |
| 66 jstring auth_token, | 67 jstring username_jstr, |
| 67 jstring host_jid, | 68 jstring auth_token_jstr, |
| 68 jstring host_id, | 69 jstring host_jid_jstr, |
| 69 jstring host_pubkey) { | 70 jstring host_id_jstr, |
| 70 remoting::ChromotingJNIInstance::GetInstance()->ConnectToHost(username, | 71 jstring host_pubkey_jstr) { |
| 71 auth_token, | 72 const char* username_cstr = env->GetStringUTFChars(username_jstr, NULL); |
| 72 host_jid, | 73 const char* auth_token_cstr = env->GetStringUTFChars(auth_token_jstr, NULL); |
| 73 host_id, | 74 const char* host_jid_cstr = env->GetStringUTFChars(host_jid_jstr, NULL); |
| 74 host_pubkey); | 75 const char* host_id_cstr = env->GetStringUTFChars(host_id_jstr, NULL); |
| 76 const char* host_pubkey_cstr = env->GetStringUTFChars(host_pubkey_jstr, NULL); |
| 77 |
| 78 remoting::ChromotingJNIInstance::GetInstance()->ConnectToHost( |
| 79 username_cstr, |
| 80 auth_token_cstr, |
| 81 host_jid_cstr, |
| 82 host_id_cstr, |
| 83 host_pubkey_cstr); |
| 84 |
| 85 env->ReleaseStringUTFChars(username_jstr, username_cstr); |
| 86 env->ReleaseStringUTFChars(auth_token_jstr, auth_token_cstr); |
| 87 env->ReleaseStringUTFChars(host_jid_jstr, host_jid_cstr); |
| 88 env->ReleaseStringUTFChars(host_id_jstr, host_id_cstr); |
| 89 env->ReleaseStringUTFChars(host_pubkey_jstr, host_pubkey_cstr); |
| 75 } | 90 } |
| 76 | 91 |
| 77 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, | 92 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(disconnectNative)(JNIEnv* env, |
| 78 jobject that) { | 93 jobject that) { |
| 79 remoting::ChromotingJNIInstance::GetInstance()->DisconnectFromHost(); | 94 remoting::ChromotingJNIInstance::GetInstance()->DisconnectFromHost(); |
| 80 } | 95 } |
| 81 | 96 |
| 82 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)(JNIEnv* env, | 97 JNIEXPORT void JNICALL JNI_IMPLEMENTATION(authenticationResponse)( |
| 83 jobject that, | 98 JNIEnv* env, |
| 84 jstring pin) { | 99 jobject that, |
| 85 remoting::ChromotingJNIInstance::GetInstance()->AuthenticateWithPin(pin); | 100 jstring pin_jstr) { |
| 101 const char* pin_cstr = env->GetStringUTFChars(pin_jstr, NULL); |
| 102 |
| 103 remoting::ChromotingJNIInstance::GetInstance()->ProvideSecret(pin_cstr); |
| 104 |
| 105 env->ReleaseStringUTFChars(pin_jstr, pin_cstr); |
| 86 } | 106 } |
| 87 | 107 |
| 88 } // extern "C" | 108 } // extern "C" |
| OLD | NEW |