OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |
| 6 #define ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/scoped_java_ref.h" |
| 11 |
| 12 namespace android_webview { |
| 13 |
| 14 class CallbackJNIBridge { |
| 15 public: |
| 16 // Creates a base::Callback the Run() method of which will delegate to the |
| 17 // onReceiveValue method of the Java-side |value_callback| object. |
| 18 // |
| 19 // The returned callback will hold a global reference to the Java object, so |
| 20 // this method should be used with short-lived callbacks only. |
| 21 static base::Callback<void(int)> FromJavaValueCallbackInt( |
| 22 JNIEnv* env, |
| 23 base::android::ScopedJavaLocalRef<jobject> value_callback); |
| 24 |
| 25 // Creates a Java object (an instance that implements the ValueCallback<Int> |
| 26 // interface) the onReceiveValue method of which will delegate to the |
| 27 // supplied |callback|. |
| 28 // The callback's lifespan is tied to the Java object. |
| 29 static base::android::ScopedJavaLocalRef<jobject> ToJavaValueCallbackInt( |
| 30 JNIEnv* env, |
| 31 const base::Callback<void(int)>& callback); |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(CallbackJNIBridge); |
| 35 }; |
| 36 |
| 37 bool RegisterCallbackJNIBridge(JNIEnv* env); |
| 38 |
| 39 } // namespace android_webview |
| 40 |
| 41 #endif // ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |
OLD | NEW |