Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: android_webview/native/callback_jni_bridge.h

Issue 12313042: [android_webview] Add a generic callback JNI bridge. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698