Chromium Code Reviews| Index: content/browser/renderer_host/java/java_bound_object.h |
| 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 0000000000000000000000000000000000000000..020b467e521bb7d1177072325e4d0817ed81fe26 |
| --- /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" |
| + |
| +// Represents a Java object for use in the Java bridge. Holds a global ref to |
|
M-A Ruel
2011/11/11 13:31:13
I'd add a first line summary:
// Wrapper around j
Steve Block
2011/11/11 16:05:20
Done.
|
| +// 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(); |
| + |
| + // A global ref to the underlying Java object. We use a naked jobject, rather |
|
M-A Ruel
2011/11/11 13:31:13
// Global ref ..
'A' doesn't convey information h
Steve Block
2011/11/11 16:05:20
Done.
|
| + // than a ScopedJavaGlobalRef, as the global ref will be added and dropped on |
| + // different threads. |
| + jobject java_object_; |
| + bool are_methods_set_up_; |
|
M-A Ruel
2011/11/11 13:31:13
Isn't it redundant? I mean, is there a moment wher
Steve Block
2011/11/11 16:05:20
I guess so, as I don't think it's possible to crea
|
| + |
| + // A map containing the public methods of this Java object. We map from |
|
M-A Ruel
2011/11/11 13:31:13
Similarly;
// Public methods map from method name
Steve Block
2011/11/11 16:05:20
Done.
|
| + // method name to Method instance. We support overloaded methods, so multiple |
| + // entries in the map may have the same key. 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; |
| + JavaMethodMap methods_; |
| + |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject); |
| +}; |
| + |
| +#endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ |