|
7 | 7 | using System.Linq; |
8 | 8 | using System.Reflection; |
9 | 9 | using System.Threading; |
10 | | -using CefSharp.ModelBinding; |
11 | 10 | using CefSharp.Event; |
12 | 11 | using System.Threading.Tasks; |
13 | 12 |
|
@@ -37,7 +36,7 @@ public class JavascriptObjectRepository : IJavascriptObjectRepository |
37 | 36 | private static long lastId; |
38 | 37 |
|
39 | 38 | public event EventHandler<JavascriptBindingEventArgs> ResolveObject; |
40 | | - public event EventHandler<JavascriptBindingEventArgs> ObjectBoundInJavascript; |
| 39 | + public event EventHandler<JavascriptBindingCompleteEventArgs> ObjectBoundInJavascript; |
41 | 40 |
|
42 | 41 | /// <summary> |
43 | 42 | /// A hash from assigned object ids to the objects, |
@@ -67,6 +66,8 @@ public bool IsBound(string name) |
67 | 66 | return objects.Values.Any(x => x.Name == name); |
68 | 67 | } |
69 | 68 |
|
| 69 | + //Ideally this would internal, unfurtunately it's used in C++ |
| 70 | + //and it's hard to expose internals |
70 | 71 | public List<JavascriptObject> GetObjects(List<string> names = null) |
71 | 72 | { |
72 | 73 | //If there are no objects names or the count is 0 then we will raise |
@@ -96,23 +97,17 @@ public List<JavascriptObject> GetObjects(List<string> names = null) |
96 | 97 | } |
97 | 98 |
|
98 | 99 |
|
99 | | - public void ObjectsBound(List<string> names) |
| 100 | + public void ObjectsBound(List<string> objs) |
100 | 101 | { |
101 | | - //TODO: JSB Should this be a single event invocation or |
102 | | - // one per object that was bound??? (Currently one per object) |
103 | | - |
104 | 102 | //Execute on Threadpool so we don't unnessicarily block the CEF IO thread |
105 | 103 | var handler = ObjectBoundInJavascript; |
106 | 104 | if(handler != null) |
107 | 105 | { |
108 | 106 | Task.Run(() => |
109 | 107 | { |
110 | | - foreach (var name in names) |
| 108 | + foreach (var obj in objs) |
111 | 109 | { |
112 | | - if (handler != null) |
113 | | - { |
114 | | - handler(this, new JavascriptBindingEventArgs(this, name)); |
115 | | - } |
| 110 | + handler?.Invoke(this, new JavascriptBindingCompleteEventArgs(this, obj, false, false)); |
116 | 111 | } |
117 | 112 | }); |
118 | 113 | } |
@@ -161,7 +156,7 @@ public void Register(string name, object value, bool isAsync, BindingOptions opt |
161 | 156 | AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false, camelCaseJavascriptNames: camelCaseJavascriptNames); |
162 | 157 | } |
163 | 158 |
|
164 | | - public bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception) |
| 159 | + internal bool TryCallMethod(long objectId, string name, object[] parameters, out object result, out string exception) |
165 | 160 | { |
166 | 161 | exception = ""; |
167 | 162 | result = null; |
@@ -297,7 +292,7 @@ public bool TryCallMethod(long objectId, string name, object[] parameters, out o |
297 | 292 | return false; |
298 | 293 | } |
299 | 294 |
|
300 | | - public bool TryGetProperty(long objectId, string name, out object result, out string exception) |
| 295 | + internal bool TryGetProperty(long objectId, string name, out object result, out string exception) |
301 | 296 | { |
302 | 297 | exception = ""; |
303 | 298 | result = null; |
@@ -327,7 +322,7 @@ public bool TryGetProperty(long objectId, string name, out object result, out st |
327 | 322 | return false; |
328 | 323 | } |
329 | 324 |
|
330 | | - public bool TrySetProperty(long objectId, string name, object value, out string exception) |
| 325 | + internal bool TrySetProperty(long objectId, string name, object value, out string exception) |
331 | 326 | { |
332 | 327 | exception = ""; |
333 | 328 | JavascriptObject obj; |
@@ -429,12 +424,7 @@ private void AnalyseObjectForBinding(JavascriptObject obj, bool analyseMethods, |
429 | 424 |
|
430 | 425 | private void RaiseResolveObjectEvent(string name) |
431 | 426 | { |
432 | | - var handler = ResolveObject; |
433 | | - |
434 | | - if(handler != null) |
435 | | - { |
436 | | - handler(this, new JavascriptBindingEventArgs(this, name)); |
437 | | - } |
| 427 | + ResolveObject?.Invoke(this, new JavascriptBindingEventArgs(this, name)); |
438 | 428 | } |
439 | 429 |
|
440 | 430 | private static JavascriptMethod CreateJavaScriptMethod(MethodInfo methodInfo, bool camelCaseJavascriptNames) |
|
0 commit comments