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

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

Issue 10793035: Add flag to Java -> JavaScript to disable exposing inherited methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed commit description. Rebased. Created 8 years, 5 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. Returns an 26 // Takes a Java object and creates a JavaBoundObject around it. Also takes
27 // NPObject with a ref count of one which owns the JavaBoundObject. 27 // a boolean that determines whether or not inherited methods are allowed
28 static NPObject* Create(const base::android::JavaRef<jobject>& object); 28 // to be called as well. This property propagates to all Objects that get
29 // implicitly exposed as return values as well. Returns an NPObject with
30 // a ref count of one which owns the JavaBoundObject.
31 static NPObject* Create(const base::android::JavaRef<jobject>& object,
32 bool allow_inherited_methods);
29 33
30 virtual ~JavaBoundObject(); 34 virtual ~JavaBoundObject();
31 35
32 // Gets a global ref to the underlying JavaObject from a JavaBoundObject 36 // Gets a global ref to the underlying JavaObject from a JavaBoundObject
33 // 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
34 // JavaBoundObject: the caller must NOT release it. 38 // JavaBoundObject: the caller must NOT release it.
35 static jobject GetJavaObject(NPObject* object); 39 static jobject GetJavaObject(NPObject* object);
36 40
37 // Methods to implement the NPObject callbacks. 41 // Methods to implement the NPObject callbacks.
38 bool HasMethod(const std::string& name) const; 42 bool HasMethod(const std::string& name) const;
39 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,
40 NPVariant* result); 44 NPVariant* result);
41 45
42 private: 46 private:
43 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object); 47 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object,
48 bool allow_inherited_methods);
44 49
45 void EnsureMethodsAreSetUp() const; 50 void EnsureMethodsAreSetUp() const;
46 51
47 // The global ref to the underlying Java object that this JavaBoundObject 52 // The global ref to the underlying Java object that this JavaBoundObject
48 // instance represents. 53 // instance represents.
49 base::android::ScopedJavaGlobalRef<jobject> java_object_; 54 base::android::ScopedJavaGlobalRef<jobject> java_object_;
50 55
51 // Map of public methods, from method name to Method instance. Multiple 56 // Map of public methods, from method name to Method instance. Multiple
52 // 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
53 // scoped_ptr in STL containers as we can't copy it. 58 // scoped_ptr in STL containers as we can't copy it.
54 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap; 59 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap;
55 mutable JavaMethodMap methods_; 60 mutable JavaMethodMap methods_;
61 mutable bool are_methods_set_up_;
62
63 bool allow_inherited_methods_;
56 64
57 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject); 65 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject);
58 }; 66 };
59 67
60 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_ 68 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698