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

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

Issue 8509019: Add JavaBoundObject (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 9 years, 1 month 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
(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_JAVA_BOUND_OBJECT_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
7
8 #include <jni.h>
9 #include <map>
10 #include <string>
11
12 #include "base/android/scoped_java_ref.h"
13 #include "base/memory/linked_ptr.h"
14 #include "content/browser/renderer_host/java/java_method.h"
15 #include "third_party/npapi/bindings/npruntime.h"
16
17 // 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.
18 // the Java object and provides the ability to invoke methods on it.
19 // Interrogation of the Java object for its methods is done lazily. This class
20 // is not generally threadsafe. However, it does allow for instances to be
21 // created and destroyed on different threads.
22 class JavaBoundObject {
23 public:
24 // Takes a Java object and creates a JavaBoundObject around it. Returns an
25 // NPObject with a ref count of one which owns the JavaBoundObject.
26 static NPObject* Create(const base::android::JavaRef<jobject>& object);
27
28 virtual ~JavaBoundObject();
29
30 // Gets the underlying JavaObject from a JavaBoundObject wrapped as an
31 // NPObject.
32 static jobject GetJavaObject(NPObject* object);
33
34 // Methods to implement the NPObject callbacks.
35 bool HasMethod(const std::string& name) const;
36 bool Invoke(const std::string& name, const NPVariant* args, size_t arg_count,
37 NPVariant* result);
38
39 private:
40 explicit JavaBoundObject(const base::android::JavaRef<jobject>& object);
41
42 void EnsureMethodsAreSetUp();
43
44 // 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.
45 // than a ScopedJavaGlobalRef, as the global ref will be added and dropped on
46 // different threads.
47 jobject java_object_;
48 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
49
50 // 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.
51 // method name to Method instance. We support overloaded methods, so multiple
52 // entries in the map may have the same key. Note that we can't use
53 // scoped_ptr in STL containers as we can't copy it.
54 typedef std::multimap<std::string, linked_ptr<JavaMethod> > JavaMethodMap;
55 JavaMethodMap methods_;
56
57 DISALLOW_IMPLICIT_CONSTRUCTORS(JavaBoundObject);
58 };
59
60 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BOUND_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698