Index: android_webview/native/callback_jni_bridge.h |
diff --git a/android_webview/native/callback_jni_bridge.h b/android_webview/native/callback_jni_bridge.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b749bc224d05db8843b1d7a368373c6411517a61 |
--- /dev/null |
+++ b/android_webview/native/callback_jni_bridge.h |
@@ -0,0 +1,41 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |
+#define ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |
+ |
+#include "base/callback.h" |
+#include "base/android/jni_android.h" |
+#include "base/android/scoped_java_ref.h" |
+ |
+namespace android_webview { |
+ |
+class CallbackJNIBridge { |
+ public: |
+ // Creates a base::Callback the Run() method of which will delegate to the |
+ // onReceiveValue method of the Java-side |value_callback| object. |
+ // |
+ // The returned callback will hold a global reference to the Java object, so |
+ // this method should be used with short-lived callbacks only. |
+ static base::Callback<void(int)> FromJavaValueCallbackInt( |
+ JNIEnv* env, |
+ base::android::ScopedJavaLocalRef<jobject> value_callback); |
+ |
+ // Creates a Java object (an instance that implements the ValueCallback<Int> |
+ // interface) the onReceiveValue method of which will delegate to the |
+ // supplied |callback|. |
+ // The callback's lifespan is tied to the Java object. |
+ static base::android::ScopedJavaLocalRef<jobject> ToJavaValueCallbackInt( |
+ JNIEnv* env, |
+ const base::Callback<void(int)>& callback); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(CallbackJNIBridge); |
+}; |
+ |
+bool RegisterCallbackJNIBridge(JNIEnv* env); |
+ |
+} // namespace android_webview |
+ |
+#endif // ANDROID_WEBVIEW_NATIVE_JAVA_CALLBACK_BRIDGE_H_ |