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

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: Update comment based on nit. 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. The
27 // a boolean that determines whether or not inherited methods are allowed 27 // |require_annotation| flag specifies whether or not only methods with the
28 // to be called as well. This property propagates to all Objects that get 28 // JavascriptInterface annotation are exposed to JavaScript. This property
29 // implicitly exposed as return values as well. Returns an NPObject with 29 // propagates to all Objects that get implicitly exposed as return values as
30 // a ref count of one which owns the JavaBoundObject. 30 // well. Returns an NPObject with a ref count of one which owns the
31 // JavaBoundObject.
31 static NPObject* Create(const base::android::JavaRef<jobject>& object, 32 static NPObject* Create(const base::android::JavaRef<jobject>& object,
32 bool allow_inherited_methods); 33 bool require_annotation);
33 34
34 virtual ~JavaBoundObject(); 35 virtual ~JavaBoundObject();
35 36
36 // Gets a global ref to the underlying JavaObject from a JavaBoundObject 37 // 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 38 // wrapped as an NPObject. Ownership of the global ref is retained by the
38 // JavaBoundObject: the caller must NOT release it. 39 // JavaBoundObject: the caller must NOT release it.
39 static jobject GetJavaObject(NPObject* object); 40 static jobject GetJavaObject(NPObject* object);
40 41
41 // Methods to implement the NPObject callbacks. 42 // Methods to implement the NPObject callbacks.
42 bool HasMethod(const std::string& name) const; 43 bool HasMethod(const std::string& name) const;
43 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count, 44 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count,
44 NPVariant* result); 45 NPVariant* result);
45 46
46 private: 47 private:
47 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object, 48 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object,
48 bool allow_inherited_methods); 49 bool require_annotation);
49 50
50 void EnsureMethodsAreSetUp() const; 51 void EnsureMethodsAreSetUp() const;
51 52
52 // The global ref to the underlying Java object that this JavaBoundObject 53 // The global ref to the underlying Java object that this JavaBoundObject
53 // instance represents. 54 // instance represents.
54 base::android::ScopedJavaGlobalRef<jobject> java_object_; 55 base::android::ScopedJavaGlobalRef<jobject> java_object_;
55 56
56 // Map of public methods, from method name to Method instance. Multiple 57 // 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 58 // 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. 59 // scoped_ptr in STL containers as we can't copy it.
59 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap; 60 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap;
60 mutable JavaMethodMap methods_; 61 mutable JavaMethodMap methods_;
61 mutable bool are_methods_set_up_; 62 mutable bool are_methods_set_up_;
62 63
63 bool allow_inherited_methods_; 64 const bool require_annotation_;
64 65
65 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject); 66 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject);
66 }; 67 };
67 68
69 bool RegisterJavaBoundObject(JNIEnv* env);
Yaron 2012/08/07 18:12:35 Nit: make this a static member function of above c
70
68 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ 71 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.cc ('k') | content/browser/renderer_host/java/java_bound_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698