OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GIN_JAVA_METHOD_INVOCATION_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_GIN_JAVA_METHOD_INVOCATION_HELPER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_GIN_JAVA_METHOD_INVOCATION_HELPER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_GIN_JAVA_METHOD_INVOCATION_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "content/browser/renderer_host/java/gin_java_bound_object.h" | 14 #include "content/browser/renderer_host/java/gin_java_bound_object.h" |
15 #include "content/browser/renderer_host/java/java_type.h" | 15 #include "content/browser/renderer_host/java/java_type.h" |
| 16 #include "content/common/android/gin_java_bridge_errors.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 class JavaMethod; | 21 class JavaMethod; |
21 | 22 |
22 // Instances of this class are created and initialized on the UI thread, do | 23 // Instances of this class are created and initialized on the UI thread, do |
23 // their work on the background thread, and then again examined on the UI | 24 // their work on the background thread, and then again examined on the UI |
24 // thread. They don't work on both threads simultaneously, though. | 25 // thread. They don't work on both threads simultaneously, though. |
25 class CONTENT_EXPORT GinJavaMethodInvocationHelper | 26 class CONTENT_EXPORT GinJavaMethodInvocationHelper |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void Init(DispatcherDelegate* dispatcher); | 62 void Init(DispatcherDelegate* dispatcher); |
62 | 63 |
63 // Called on the background thread | 64 // Called on the background thread |
64 void Invoke(); | 65 void Invoke(); |
65 | 66 |
66 // Called on the UI thread | 67 // Called on the UI thread |
67 bool HoldsPrimitiveResult(); | 68 bool HoldsPrimitiveResult(); |
68 const base::ListValue& GetPrimitiveResult(); | 69 const base::ListValue& GetPrimitiveResult(); |
69 const base::android::JavaRef<jobject>& GetObjectResult(); | 70 const base::android::JavaRef<jobject>& GetObjectResult(); |
70 const base::android::JavaRef<jclass>& GetSafeAnnotationClass(); | 71 const base::android::JavaRef<jclass>& GetSafeAnnotationClass(); |
71 const std::string& GetErrorMessage(); | 72 const GinJavaBridgeError GetInvocationError(); |
72 | 73 |
73 private: | 74 private: |
74 friend class base::RefCountedThreadSafe<GinJavaMethodInvocationHelper>; | 75 friend class base::RefCountedThreadSafe<GinJavaMethodInvocationHelper>; |
75 ~GinJavaMethodInvocationHelper(); | 76 ~GinJavaMethodInvocationHelper(); |
76 | 77 |
77 // Called on the UI thread | 78 // Called on the UI thread |
78 void BuildObjectRefsFromListValue(DispatcherDelegate* dispatcher, | 79 void BuildObjectRefsFromListValue(DispatcherDelegate* dispatcher, |
79 const base::Value* list_value); | 80 const base::Value* list_value); |
80 void BuildObjectRefsFromDictionaryValue(DispatcherDelegate* dispatcher, | 81 void BuildObjectRefsFromDictionaryValue(DispatcherDelegate* dispatcher, |
81 const base::Value* dict_value); | 82 const base::Value* dict_value); |
82 | 83 |
83 bool AppendObjectRef(DispatcherDelegate* dispatcher, | 84 bool AppendObjectRef(DispatcherDelegate* dispatcher, |
84 const base::Value* raw_value); | 85 const base::Value* raw_value); |
85 | 86 |
86 // Called on the background thread. | 87 // Called on the background thread. |
87 void InvokeMethod(jobject object, | 88 void InvokeMethod(jobject object, |
88 jclass clazz, | 89 jclass clazz, |
89 const JavaType& return_type, | 90 const JavaType& return_type, |
90 jmethodID id, | 91 jmethodID id, |
91 jvalue* parameters); | 92 jvalue* parameters); |
92 void SetInvocationFailure(const char* error_message); | 93 void SetInvocationError(GinJavaBridgeError error); |
93 void SetPrimitiveResult(const base::ListValue& result_wrapper); | 94 void SetPrimitiveResult(const base::ListValue& result_wrapper); |
94 void SetObjectResult( | 95 void SetObjectResult( |
95 const base::android::JavaRef<jobject>& object, | 96 const base::android::JavaRef<jobject>& object, |
96 const base::android::JavaRef<jclass>& safe_annotation_clazz); | 97 const base::android::JavaRef<jclass>& safe_annotation_clazz); |
97 | 98 |
98 typedef std::map<GinJavaBoundObject::ObjectID, | 99 typedef std::map<GinJavaBoundObject::ObjectID, |
99 JavaObjectWeakGlobalRef> ObjectRefs; | 100 JavaObjectWeakGlobalRef> ObjectRefs; |
100 | 101 |
101 scoped_ptr<ObjectDelegate> object_; | 102 scoped_ptr<ObjectDelegate> object_; |
102 const std::string method_name_; | 103 const std::string method_name_; |
103 scoped_ptr<base::ListValue> arguments_; | 104 scoped_ptr<base::ListValue> arguments_; |
104 ObjectRefs object_refs_; | 105 ObjectRefs object_refs_; |
105 bool holds_primitive_result_; | 106 bool holds_primitive_result_; |
106 scoped_ptr<base::ListValue> primitive_result_; | 107 scoped_ptr<base::ListValue> primitive_result_; |
107 std::string error_message_; | 108 GinJavaBridgeError invocation_error_; |
108 base::android::ScopedJavaGlobalRef<jobject> object_result_; | 109 base::android::ScopedJavaGlobalRef<jobject> object_result_; |
109 base::android::ScopedJavaGlobalRef<jclass> safe_annotation_clazz_; | 110 base::android::ScopedJavaGlobalRef<jclass> safe_annotation_clazz_; |
110 | 111 |
111 DISALLOW_COPY_AND_ASSIGN(GinJavaMethodInvocationHelper); | 112 DISALLOW_COPY_AND_ASSIGN(GinJavaMethodInvocationHelper); |
112 }; | 113 }; |
113 | 114 |
114 } // namespace content | 115 } // namespace content |
115 | 116 |
116 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_GIN_JAVA_METHOD_INVOCATION_HELPER_
H_ | 117 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_GIN_JAVA_METHOD_INVOCATION_HELPER_
H_ |
OLD | NEW |