summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/java/java_bound_object.h
diff options
context:
space:
mode:
authorsteveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 17:08:35 +0000
committersteveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 17:08:35 +0000
commitebed17c7823a01b70934460d2cbe0fec70261a41 (patch)
treefe6a0e5e62f5e6a02a1f8dc07abc9dd6af9fbe79 /content/browser/renderer_host/java/java_bound_object.h
parent3826a8a0942fd634616d009a45f5eafb7ee567c6 (diff)
downloadchromium_src-ebed17c7823a01b70934460d2cbe0fec70261a41.zip
chromium_src-ebed17c7823a01b70934460d2cbe0fec70261a41.tar.gz
chromium_src-ebed17c7823a01b70934460d2cbe0fec70261a41.tar.bz2
Add JavaBoundObject
This represents a Java object for use in the Java bridge. It handles all of the JNI required to interrogate the Java object and call methods on it. Also adds some JNI utility methods to simpify the new code. BUG=96703 Review URL: http://codereview.chromium.org/8509019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109645 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/java/java_bound_object.h')
-rw-r--r--content/browser/renderer_host/java/java_bound_object.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/content/browser/renderer_host/java/java_bound_object.h b/content/browser/renderer_host/java/java_bound_object.h
new file mode 100644
index 0000000..dffb2f9
--- /dev/null
+++ b/content/browser/renderer_host/java/java_bound_object.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2011 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 CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
+#define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
+
+#include <jni.h>
+#include <map>
+#include <string>
+
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/linked_ptr.h"
+#include "content/browser/renderer_host/java/java_method.h"
+#include "third_party/npapi/bindings/npruntime.h"
+
+// Wrapper around a Java object.
+//
+// Represents a Java object for use in the Java bridge. Holds a global ref to
+// the Java object and provides the ability to invoke methods on it.
+// Interrogation of the Java object for its methods is done lazily. This class
+// is not generally threadsafe. However, it does allow for instances to be
+// created and destroyed on different threads.
+class JavaBoundObject {
+ public:
+ // Takes a Java object and creates a JavaBoundObject around it. Returns an
+ // NPObject with a ref count of one which owns the JavaBoundObject.
+ static NPObject* Create(const base::android::JavaRef<jobject>& object);
+
+ virtual ~JavaBoundObject();
+
+ // Gets the underlying JavaObject from a JavaBoundObject wrapped as an
+ // NPObject.
+ static jobject GetJavaObject(NPObject* object);
+
+ // Methods to implement the NPObject callbacks.
+ bool HasMethod(const std::string& name) const;
+ bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count,
+ NPVariant* result);
+
+ private:
+ explicit JavaBoundObject(const base::android::JavaRef<jobject>& object);
+
+ void EnsureMethodsAreSetUp() const;
+
+ // Global ref to the underlying Java object. We use a naked jobject, rather
+ // than a ScopedJavaGlobalRef, as the global ref will be added and dropped on
+ // different threads.
+ jobject java_object_;
+
+ // Map of public methods, from method name to Method instance. Multiple
+ // entries will be present for overloaded methods. Note that we can't use
+ // scoped_ptr in STL containers as we can't copy it.
+ typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap;
+ mutable JavaMethodMap methods_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject);
+};
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_