Chromium Code Reviews| Index: components/devtools_bridge/test/android/client/web_client_android.cc |
| diff --git a/components/devtools_bridge/test/android/client/web_client_android.cc b/components/devtools_bridge/test/android/client/web_client_android.cc |
| index 8287a24690479744c602fc4092e1be9a3be85723..d05b31950817f31387e0c75da5046ff22c707fdf 100644 |
| --- a/components/devtools_bridge/test/android/client/web_client_android.cc |
| +++ b/components/devtools_bridge/test/android/client/web_client_android.cc |
| @@ -4,10 +4,17 @@ |
| #include "components/devtools_bridge/test/android/client/web_client_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/json/json_writer.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_android.h" |
| #include "jni/WebClient_jni.h" |
| +using base::android::AttachCurrentThread; |
| +using base::android::ConvertJavaStringToUTF8; |
| +using base::android::ConvertUTF8ToJavaString; |
| + |
| namespace devtools_bridge { |
| namespace android { |
| @@ -15,16 +22,37 @@ bool WebClientAndroid::RegisterNatives(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |
| -WebClientAndroid::WebClientAndroid(Profile* profile) |
| +WebClientAndroid::WebClientAndroid( |
| + Profile* profile, JNIEnv* env, jobject j_delegate) |
| : impl_(WebClient::CreateInstance(profile, this)) { |
| + delegate_.Reset(env, j_delegate); |
| } |
| WebClientAndroid::~WebClientAndroid() { |
| } |
| -static jlong CreateWebClient(JNIEnv* env, jclass jcaller, jobject j_profile) { |
| +void WebClientAndroid::SendCommand( |
| + const base::DictionaryValue* command, |
| + const WebClient::CommandSuccessCallback& sucess_callback, |
| + const WebClient::CommandFailureCallback& failure_callback) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + std::string json; |
| + if (!base::JSONWriter::Write(command, &json)) { |
|
mnaganov (inactive)
2014/11/21 21:19:38
I think it makes sense to serialize to JSON much e
SeRya
2014/11/24 11:10:06
Good point. Done.
|
| + failure_callback.Run(); |
| + return; |
| + } |
| + |
| + Java_WebClient_sendCommand( |
| + env, |
| + delegate_.obj(), |
| + ConvertUTF8ToJavaString(env, json).obj()); |
| +} |
| + |
| +static jlong CreateWebClient( |
| + JNIEnv* env, jclass jcaller, jobject j_profile, jobject j_delegate) { |
| Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| - return reinterpret_cast<jlong>(new WebClientAndroid(profile)); |
| + return reinterpret_cast<jlong>(new WebClientAndroid( |
| + profile, env, j_delegate)); |
| } |
| static void DestroyWebClient( |
| @@ -32,5 +60,22 @@ static void DestroyWebClient( |
| delete reinterpret_cast<WebClientAndroid*>(web_client_ptr); |
| } |
| +static void Connect( |
| + JNIEnv* env, jclass jcaller, jlong web_client_ptr, jstring device_id) { |
| + reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().Connect( |
| + ConvertJavaStringToUTF8(env, device_id)); |
| +} |
| + |
| +static void Disconnect( |
| + JNIEnv* env, jclass jcaller, jlong web_client_ptr, jstring device_id) { |
| + reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().Disconnect( |
| + ConvertJavaStringToUTF8(env, device_id)); |
| +} |
| + |
| +static void DisconnectAll( |
| + JNIEnv* env, jclass jcaller, jlong web_client_ptr) { |
| + reinterpret_cast<WebClientAndroid*>(web_client_ptr)->impl().DisconnectAll(); |
| +} |
| + |
| } // namespace android |
| } // namespace devtools_bridge |