Skip to content

Commit e772ae7

Browse files
committed
Merge branch 'JsBinding/Wip2' into JsBinding_WIP
2 parents 3f9bbb4 + 99040f9 commit e772ae7

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

CefSharp.BrowserSubprocess.Core/TypeUtils.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,20 @@ namespace CefSharp
182182
std::vector<CefString> keys;
183183
if (obj->GetKeys(keys))
184184
{
185-
Dictionary<String^, Object^>^ result = gcnew Dictionary<String^, Object^>();
185+
auto array = gcnew List<Object^>();
186186

187187
for (int i = 0; i < arrLength; i++)
188188
{
189-
std::string p_key = keys[i].ToString();
190-
String^ p_keyStr = stdToString(p_key);
191-
192-
if ((obj->HasValue(keys[i])) && (!p_keyStr->StartsWith("__")))
189+
auto data = obj->GetValue(keys[i]);
190+
if (data != nullptr)
193191
{
194-
CefRefPtr<CefV8Value> data;
195-
196-
data = obj->GetValue(keys[i]);
197-
if (data != nullptr)
198-
{
199-
Object^ p_data = TypeUtils::ConvertFromCef(data);
192+
auto p_data = TypeUtils::ConvertFromCef(data);
200193

201-
result->Add(p_keyStr, p_data);
202-
}
194+
array->Add(p_data);
203195
}
204196
}
205197

206-
return result;
198+
return array->ToArray();
207199
}
208200
}
209201

CefSharp.BrowserSubprocess/CefRenderProcess.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,21 @@ public Task<JavascriptResponse> EvaluateScriptAsync(int browserId, long frameId,
113113

114114
var task = factory.StartNew(() =>
115115
{
116-
return browser.DoEvaluateScript(frameId, script);
116+
try
117+
{
118+
var response = browser.DoEvaluateScript(frameId, script);
119+
120+
return response;
121+
}
122+
catch (Exception ex)
123+
{
124+
return new JavascriptResponse
125+
{
126+
Success = false,
127+
Message = ex.ToString()
128+
};
129+
}
130+
117131
}, TaskCreationOptions.AttachedToParent);
118132

119133
return timeout.HasValue ? task.WithTimeout(timeout.Value) : task;

CefSharp.Example/Resources/BindingTest.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
}
2020
</script>
2121
</p>
22+
23+
<p>
24+
Function delegate to c# method
25+
<br />
26+
<script type="text/javascript">
27+
function myFunction(functionParam)
28+
{
29+
return functionParam();
30+
}
31+
32+
document.write("echoMyProperty result: " + myFunction(bound.echoMyProperty));
33+
</script>
34+
</p>
2235

2336
Methods on bound object 'bound':<br />
2437
<ul>

CefSharp/Internals/BrowserProcessServiceHost.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Net.Security;
77
using System.ServiceModel;
8+
using System.ServiceModel.Channels;
89
using System.ServiceModel.Description;
910
using System.Threading.Tasks;
1011

@@ -66,11 +67,22 @@ protected override void OnClosed()
6667
operationContextTaskCompletionSource = null;
6768
}
6869

69-
public static NetNamedPipeBinding CreateBinding()
70+
public static CustomBinding CreateBinding()
7071
{
7172
var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
7273
binding.MaxReceivedMessageSize = SixteenMegaBytesInBytes;
73-
return binding;
74+
binding.ReceiveTimeout = TimeSpan.MaxValue;
75+
binding.SendTimeout = TimeSpan.MaxValue;
76+
binding.OpenTimeout = TimeSpan.MaxValue;
77+
binding.CloseTimeout = TimeSpan.MaxValue;
78+
79+
// Ensure binding connection stays open indefinitely until closed
80+
var customBinding = new CustomBinding(binding);
81+
var connectionSettings = customBinding.Elements.Find<NamedPipeTransportBindingElement>().ConnectionPoolSettings;
82+
connectionSettings.IdleTimeout = TimeSpan.MaxValue;
83+
connectionSettings.MaxOutboundConnectionsPerEndpoint = 0;
84+
85+
return customBinding;
7486
}
7587
}
7688
}

CefSharp/JavascriptResponse.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using System.Runtime.Serialization;
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
23

34
namespace CefSharp
45
{
56
[DataContract]
7+
[KnownType(typeof(object[]))]
8+
[KnownType(typeof(Dictionary<string,object>))]
69
public class JavascriptResponse
710
{
811
[DataMember]

CefSharp3.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CefSharp.BrowserSubprocess.
5555
{7B495581-2271-4F41-9476-ACB86E8C864F} = {7B495581-2271-4F41-9476-ACB86E8C864F}
5656
EndProjectSection
5757
EndProject
58+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9F4008EF-0182-48C6-B0E8-972252DC3F72}"
59+
ProjectSection(SolutionItems) = preProject
60+
.nuget\packages.config = .nuget\packages.config
61+
EndProjectSection
62+
EndProject
5863
Global
5964
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6065
Debug|Mixed Platforms = Debug|Mixed Platforms

0 commit comments

Comments
 (0)