mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
Merge branch 'JsBinding_WIP' of https://github.com/bjarteskogoy/CefSharp into JsBinding/Wip2
This commit is contained in:
@@ -132,5 +132,37 @@ namespace CefSharp.BrowserSubprocess
|
||||
|
||||
return timeout.HasValue ? task.WithTimeout(timeout.Value) : task;
|
||||
}
|
||||
|
||||
public IAsyncResult BeginEvaluateScriptAsync(int browserId, long frameId, string script, TimeSpan? timeout, AsyncCallback callback, object state)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<JavascriptResponse>(state);
|
||||
var task = EvaluateScriptAsync(browserId, frameId, script, timeout);
|
||||
task.ContinueWith(t =>
|
||||
{
|
||||
if (t.IsFaulted)
|
||||
{
|
||||
tcs.TrySetException(t.Exception.InnerExceptions);
|
||||
}
|
||||
else if (t.IsCanceled)
|
||||
{
|
||||
tcs.TrySetCanceled();
|
||||
}
|
||||
else
|
||||
{
|
||||
tcs.TrySetResult(t.Result);
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
});
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
public JavascriptResponse EndEvaluateScriptAsync(IAsyncResult result)
|
||||
{
|
||||
return ((Task<JavascriptResponse>)result).Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,11 @@ namespace CefSharp.Internals
|
||||
public Task<JavascriptResponse> EvaluateScriptAsync(int browserId, long frameId, string script, TimeSpan? timeout)
|
||||
{
|
||||
var operationContextTask = operationContextTaskCompletionSource.Task;
|
||||
|
||||
return operationContextTask.ContinueWith(t =>
|
||||
{
|
||||
var context = t.Result;
|
||||
var renderProcess = context.GetCallbackChannel<IRenderProcess>();
|
||||
return renderProcess.EvaluateScriptAsync(browserId, frameId, script, timeout);
|
||||
return Task.Factory.FromAsync<JavascriptResponse>(renderProcess.BeginEvaluateScriptAsync(browserId, frameId, script, timeout, null, null), renderProcess.EndEvaluateScriptAsync);
|
||||
}).Unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace CefSharp.Internals
|
||||
[ServiceContract]
|
||||
public interface IRenderProcess
|
||||
{
|
||||
[OperationContract]
|
||||
Task<JavascriptResponse> EvaluateScriptAsync(int browserId, long frameId, string script, TimeSpan? timeout);
|
||||
[OperationContract(AsyncPattern=true)]
|
||||
IAsyncResult BeginEvaluateScriptAsync(int browserId, long frameId, string script, TimeSpan? timeout, AsyncCallback callback, object state);
|
||||
|
||||
JavascriptResponse EndEvaluateScriptAsync(IAsyncResult result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user