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

Side by Side Diff: content/browser/renderer_host/java/java_bound_object.h

Issue 10830173: JavaBridge should use Annotation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "content/browser/renderer_host/java/java_method.h" 14 #include "content/browser/renderer_host/java/java_method.h"
15 #include "third_party/npapi/bindings/npruntime.h" 15 #include "third_party/npapi/bindings/npruntime.h"
16 16
17 // Wrapper around a Java object. 17 // Wrapper around a Java object.
18 // 18 //
19 // Represents a Java object for use in the Java bridge. Holds a global ref to 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. 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 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 22 // is not generally threadsafe. However, it does allow for instances to be
23 // created and destroyed on different threads. 23 // created and destroyed on different threads.
24 class JavaBoundObject { 24 class JavaBoundObject {
25 public: 25 public:
26 // Takes a Java object and creates a JavaBoundObject around it. Also takes 26 // Takes a Java object and creates a JavaBoundObject around it. Also takes
27 // a boolean that determines whether or not inherited methods are allowed 27 // a boolean that determines whether or not methods require the safe
28 // to be called as well. This property propagates to all Objects that get 28 // annotation to be exposed. This property propagates to all Objects that
joth 2012/08/04 20:38:28 takes a boolean that determines whether or not met
Steve Block 2012/08/06 12:12:30 Or 'The require_safe_annotation flag specifies whe
palmer 2012/08/06 17:31:26 +1 to this version of the explanation.
David Trainor- moved to gerrit 2012/08/06 23:42:33 Done.
29 // implicitly exposed as return values as well. Returns an NPObject with 29 // get implicitly exposed as return values as well. Returns an NPObject with
30 // a ref count of one which owns the JavaBoundObject. 30 // a ref count of one which owns the JavaBoundObject.
31 static NPObject* Create(const base::android::JavaRef<jobject>& object, 31 static NPObject* Create(const base::android::JavaRef<jobject>& object,
32 bool allow_inherited_methods); 32 bool require_safe_annotation);
33 33
34 virtual ~JavaBoundObject(); 34 virtual ~JavaBoundObject();
35 35
36 // Gets a global ref to the underlying JavaObject from a JavaBoundObject 36 // Gets a global ref to the underlying JavaObject from a JavaBoundObject
37 // wrapped as an NPObject. Ownership of the global ref is retained by the 37 // wrapped as an NPObject. Ownership of the global ref is retained by the
38 // JavaBoundObject: the caller must NOT release it. 38 // JavaBoundObject: the caller must NOT release it.
39 static jobject GetJavaObject(NPObject* object); 39 static jobject GetJavaObject(NPObject* object);
40 40
41 // Methods to implement the NPObject callbacks. 41 // Methods to implement the NPObject callbacks.
42 bool HasMethod(const std::string& name) const; 42 bool HasMethod(const std::string& name) const;
43 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count, 43 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count,
44 NPVariant* result); 44 NPVariant* result);
45 45
46 private: 46 private:
47 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object, 47 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object,
48 bool allow_inherited_methods); 48 bool require_safe_annotation);
49 49
50 void EnsureMethodsAreSetUp() const; 50 void EnsureMethodsAreSetUp() const;
51 51
52 // The global ref to the underlying Java object that this JavaBoundObject 52 // The global ref to the underlying Java object that this JavaBoundObject
53 // instance represents. 53 // instance represents.
54 base::android::ScopedJavaGlobalRef<jobject> java_object_; 54 base::android::ScopedJavaGlobalRef<jobject> java_object_;
55 55
56 // Map of public methods, from method name to Method instance. Multiple 56 // Map of public methods, from method name to Method instance. Multiple
57 // entries will be present for overloaded methods. Note that we can't use 57 // entries will be present for overloaded methods. Note that we can't use
58 // scoped_ptr in STL containers as we can't copy it. 58 // scoped_ptr in STL containers as we can't copy it.
59 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap; 59 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap;
60 mutable JavaMethodMap methods_; 60 mutable JavaMethodMap methods_;
61 mutable bool are_methods_set_up_; 61 mutable bool are_methods_set_up_;
62 62
63 bool allow_inherited_methods_; 63 bool require_safe_annotation_;
joth 2012/08/04 20:38:28 const bool
David Trainor- moved to gerrit 2012/08/06 23:42:33 Done.
64 64
65 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject); 65 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject);
66 }; 66 };
67 67
68 bool RegisterJavaBoundObject(JNIEnv* env);
69
68 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ 70 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698