OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/devtools_bridge/test/android/client/web_client_android.h" | 5 #include "components/devtools_bridge/test/android/client/web_client_android.h" |
6 | 6 |
| 7 #include "base/android/jni_string.h" |
| 8 #include "base/android/scoped_java_ref.h" |
7 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/profiles/profile_android.h" | 10 #include "chrome/browser/profiles/profile_android.h" |
9 #include "jni/WebClient_jni.h" | 11 #include "jni/WebClient_jni.h" |
10 | 12 |
| 13 using base::android::AttachCurrentThread; |
| 14 using base::android::ConvertJavaStringToUTF8; |
| 15 using base::android::ConvertUTF8ToJavaString; |
| 16 |
11 namespace devtools_bridge { | 17 namespace devtools_bridge { |
12 namespace android { | 18 namespace android { |
13 | 19 |
14 bool WebClientAndroid::RegisterNatives(JNIEnv* env) { | 20 bool WebClientAndroid::RegisterNatives(JNIEnv* env) { |
15 return RegisterNativesImpl(env); | 21 return RegisterNativesImpl(env); |
16 } | 22 } |
17 | 23 |
18 WebClientAndroid::WebClientAndroid(Profile* profile) | 24 WebClientAndroid::WebClientAndroid( |
| 25 Profile* profile, JNIEnv* env, jobject j_delegate) |
19 : impl_(WebClient::CreateInstance(profile, this)) { | 26 : impl_(WebClient::CreateInstance(profile, this)) { |
| 27 delegate_.Reset(env, j_delegate); |
20 } | 28 } |
21 | 29 |
22 WebClientAndroid::~WebClientAndroid() { | 30 WebClientAndroid::~WebClientAndroid() { |
23 } | 31 } |
24 | 32 |
25 static jlong CreateWebClient(JNIEnv* env, jclass jcaller, jobject j_profile) { | 33 void WebClientAndroid::SendCommand( |
| 34 const std::string& command, |
| 35 const WebClient::CommandSuccessCallback& sucess_callback, |
| 36 const WebClient::CommandFailureCallback& failure_callback) { |
| 37 JNIEnv* env = AttachCurrentThread(); |
| 38 Java_WebClient_sendCommand( |
| 39 env, |
| 40 delegate_.obj(), |
| 41 ConvertUTF8ToJavaString(env, command).obj()); |
| 42 } |
| 43 |
| 44 static jlong CreateWebClient( |
| 45 JNIEnv* env, jclass jcaller, jobject j_profile, jobject j_delegate) { |
26 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 46 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
27 return reinterpret_cast<jlong>(new WebClientAndroid(profile)); | 47 return reinterpret_cast<jlong>(new WebClientAndroid( |
| 48 profile, env, j_delegate)); |
28 } | 49 } |
29 | 50 |
30 static void DestroyWebClient( | 51 static void DestroyWebClient( |
31 JNIEnv* env, jclass jcaller, jlong web_client_ptr) { | 52 JNIEnv* env, jclass jcaller, jlong web_client_ptr) { |
32 delete reinterpret_cast<WebClientAndroid*>(web_client_ptr); | 53 delete reinterpret_cast<WebClientAndroid*>(web_client_ptr); |
33 } | 54 } |
34 | 55 |
| 56 static void Connect( |
| 57 JNIEnv* env, jclass jcaller, jlong web_client_ptr, jstring device_id) { |
| 58 reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().Connect( |
| 59 ConvertJavaStringToUTF8(env, device_id)); |
| 60 } |
| 61 |
| 62 static void Disconnect( |
| 63 JNIEnv* env, jclass jcaller, jlong web_client_ptr, jstring device_id) { |
| 64 reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().Disconnect( |
| 65 ConvertJavaStringToUTF8(env, device_id)); |
| 66 } |
| 67 |
| 68 static void DisconnectAll( |
| 69 JNIEnv* env, jclass jcaller, jlong web_client_ptr) { |
| 70 reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().DisconnectAll(); |
| 71 } |
| 72 |
35 } // namespace android | 73 } // namespace android |
36 } // namespace devtools_bridge | 74 } // namespace devtools_bridge |
OLD | NEW |