OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 CONTENT_BROWSER_RENDERER_HOST_JAVA_BOUND_OBJECT_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_BOUND_OBJECT_H_ | |
7 | |
8 #if defined(ENABLE_JAVA_BRIDGE) | |
jam
2011/11/10 17:30:20
is this really needed? if ENABLE_JAVA_BRIDGE is no
Steve Block
2011/11/10 18:17:55
I guess it's not strictly required, because the gy
| |
9 | |
10 #include <jni.h> | |
11 #include <map> | |
12 #include <string> | |
13 | |
14 #include "base/android/scoped_java_ref.h" | |
15 #include "base/memory/linked_ptr.h" | |
16 #include "content/browser/renderer_host/java_method.h" | |
17 #include "third_party/npapi/bindings/npruntime.h" | |
18 | |
19 // Represents a Java object for use in the Java bridge. Holds a global ref to | |
20 // the Java object and provides the ability to invoke methods on it. | |
21 // Interrogation of the Java object for its methods is done lazily. This class | |
22 // is not generally threadsafe. However, it does allow for instances to be | |
23 // created and destroyed on different threads. | |
24 class JavaBoundObject { | |
25 public: | |
26 // Takes a Java object and creates a JavaBoundObject around it. Returns an | |
27 // NPObject with a ref count of one which owns the JavaBoundObject. | |
28 static NPObject* Create(const base::android::JavaRef<jobject>& object); | |
29 | |
30 virtual ~JavaBoundObject(); | |
31 | |
32 // Gets the underlying JavaObject from a JavaBoundObject wrapped as an | |
33 // NPObject. | |
34 static jobject GetJavaObject(NPObject* object); | |
35 | |
36 // Methods to implement the NPObject callbacks. | |
37 bool HasMethod(const std::string& name) const; | |
38 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count, | |
39 NPVariant* result); | |
40 | |
41 private: | |
42 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object); | |
43 | |
44 void EnsureMethodsAreSetUp(); | |
45 | |
46 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
47 bool are_methods_set_up_; | |
48 | |
49 // A map containing the public methods of this Java object. We map from | |
50 // method name to Method instance. We support overloaded methods, so multiple | |
51 // entries in the map may have the same key. Note that we can't use | |
52 // scoped_ptr in STL containers as we can't copy it. | |
53 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap; | |
54 JavaMethodMap methods_; | |
55 | |
56 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject); | |
57 }; | |
58 | |
59 #endif // defined(ENABLE_JAVA_BRIDGE) | |
60 | |
61 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_BOUND_OBJECT_H_ | |
OLD | NEW |