mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
removed unnecessary code from previous js callback implementation
This commit is contained in:
@@ -31,16 +31,6 @@ namespace CefSharp
|
||||
}
|
||||
}
|
||||
|
||||
JavascriptResponse^ CefBrowserWrapper::DoCallback(System::Int64 callbackId, array<Object^>^ parameters)
|
||||
{
|
||||
return _callbackRegistry->Execute(callbackId, parameters);
|
||||
}
|
||||
|
||||
void CefBrowserWrapper::DestroyJavascriptCallback(Int64 id)
|
||||
{
|
||||
_callbackRegistry->Deregister(id);
|
||||
}
|
||||
|
||||
JavascriptCallbackRegistry^ CefBrowserWrapper::CallbackRegistry::get()
|
||||
{
|
||||
return _callbackRegistry;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace CefSharp
|
||||
property bool IsPopup;
|
||||
|
||||
// This allows us to create the WCF proxies back to our parent process.
|
||||
property DuplexChannelFactory<IBrowserProcess^>^ ChannelFactory;
|
||||
property ChannelFactory<IBrowserProcess^>^ ChannelFactory;
|
||||
|
||||
// The serialized registered object data waiting to be used.
|
||||
property JavascriptRootObject^ JavascriptRootObject;
|
||||
@@ -58,9 +58,5 @@ namespace CefSharp
|
||||
|
||||
// The WCF proxy to the parent process.
|
||||
property IBrowserProcess^ BrowserProcess;
|
||||
|
||||
JavascriptResponse^ DoCallback(System::Int64 callbackId, array<Object^>^ parameters);
|
||||
|
||||
void DestroyJavascriptCallback(Int64 id);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using TaskExtensions = CefSharp.Internals.TaskExtensions;
|
||||
namespace CefSharp.BrowserSubprocess
|
||||
{
|
||||
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults=true)]
|
||||
public class CefRenderProcess : CefSubProcess, IRenderProcess
|
||||
public class CefRenderProcess : CefSubProcess
|
||||
{
|
||||
private int? parentBrowserId;
|
||||
private List<CefBrowserWrapper> browsers = new List<CefBrowserWrapper>();
|
||||
@@ -56,8 +56,7 @@ namespace CefSharp.BrowserSubprocess
|
||||
|
||||
var binding = BrowserProcessServiceHost.CreateBinding();
|
||||
|
||||
var channelFactory = new DuplexChannelFactory<IBrowserProcess>(
|
||||
this,
|
||||
var channelFactory = new ChannelFactory<IBrowserProcess>(
|
||||
binding,
|
||||
new EndpointAddress(serviceName)
|
||||
);
|
||||
@@ -112,80 +111,5 @@ namespace CefSharp.BrowserSubprocess
|
||||
browser.BrowserProcess = null;
|
||||
browser.JavascriptRootObject = null;
|
||||
}
|
||||
|
||||
public IAsyncResult BeginJavascriptCallbackAsync(int browserId, long callbackId, object[] parameters, TimeSpan? timeout, AsyncCallback callback, object state)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<JavascriptResponse>(state);
|
||||
var task = JavascriptCallbackAsync(browserId, callbackId, parameters, 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 EndJavascriptCallbackAsync(IAsyncResult result)
|
||||
{
|
||||
return ((Task<JavascriptResponse>)result).Result;
|
||||
}
|
||||
|
||||
public void DestroyJavascriptCallback(int browserId, long id)
|
||||
{
|
||||
var browser = browsers.FirstOrDefault(x => x.BrowserId == browserId);
|
||||
if (browser != null)
|
||||
{
|
||||
browser.DestroyJavascriptCallback(id);
|
||||
}
|
||||
}
|
||||
|
||||
private Task<JavascriptResponse> JavascriptCallbackAsync(int browserId, long callbackId, object[] parameters, TimeSpan? timeout)
|
||||
{
|
||||
var factory = RenderThreadTaskFactory;
|
||||
var browser = browsers.FirstOrDefault(x => x.BrowserId == browserId);
|
||||
if (browser == null)
|
||||
{
|
||||
return TaskExtensions.FromResult(new JavascriptResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = string.Format("Browser with Id {0} not found in Render Sub Process.", browserId)
|
||||
});
|
||||
}
|
||||
|
||||
var task = factory.StartNew(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = browser.DoCallback(callbackId, parameters);
|
||||
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JavascriptResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = ex.ToString()
|
||||
};
|
||||
}
|
||||
}, TaskCreationOptions.AttachedToParent);
|
||||
|
||||
return timeout.HasValue ? task.WithTimeout(timeout.Value) : task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,6 @@
|
||||
<Compile Include="CefCursorType.cs" />
|
||||
<Compile Include="Internals\IJavascriptCallbackFactory.cs" />
|
||||
<Compile Include="Internals\IntPtrExtensions.cs" />
|
||||
<Compile Include="Internals\JavascriptCallbackFactory.cs" />
|
||||
<Compile Include="Internals\JavascriptCallbackProxy.cs" />
|
||||
<Compile Include="Internals\JavascriptCallback.cs" />
|
||||
<Compile Include="Internals\JavascriptCallbackEndpointBehavior.cs" />
|
||||
<Compile Include="Internals\JavascriptCallbackSurrogate.cs" />
|
||||
@@ -189,7 +187,6 @@
|
||||
<Compile Include="IRequestHandler.cs" />
|
||||
<Compile Include="ISchemeHandler.cs" />
|
||||
<Compile Include="ISchemeHandlerFactory.cs" />
|
||||
<Compile Include="Internals\IRenderProcess.cs" />
|
||||
<Compile Include="IWebBrowser.cs" />
|
||||
<Compile Include="Internals\IWebBrowserInternal.cs" />
|
||||
<Compile Include="Internals\Kernel32.cs" />
|
||||
|
||||
@@ -78,29 +78,6 @@ namespace CefSharp.Internals
|
||||
}
|
||||
}
|
||||
|
||||
internal Task<JavascriptResponse> JavascriptCallback(int browserId, long id, object[] parameters, TimeSpan? timeout)
|
||||
{
|
||||
var operationContextTask = operationContextTaskCompletionSource.Task;
|
||||
return operationContextTask.ContinueWith(t =>
|
||||
{
|
||||
var context = t.Result;
|
||||
var renderProcess = context.GetCallbackChannel<IRenderProcess>();
|
||||
var asyncResult = renderProcess.BeginJavascriptCallbackAsync(browserId, id, parameters, timeout, null, null);
|
||||
return Task.Factory.FromAsync<JavascriptResponse>(asyncResult, renderProcess.EndJavascriptCallbackAsync);
|
||||
}).Unwrap();
|
||||
}
|
||||
|
||||
internal void DestroyJavascriptCallback(int browserId, long id)
|
||||
{
|
||||
var operationContextTask = operationContextTaskCompletionSource.Task;
|
||||
operationContextTask.ContinueWith(t =>
|
||||
{
|
||||
var context = t.Result;
|
||||
var renderProcess = context.GetCallbackChannel<IRenderProcess>();
|
||||
renderProcess.DestroyJavascriptCallback(browserId, id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnClosed()
|
||||
{
|
||||
base.OnClosed();
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.ServiceModel;
|
||||
|
||||
namespace CefSharp.Internals
|
||||
{
|
||||
[ServiceContract(CallbackContract = typeof(IRenderProcess), SessionMode = SessionMode.Required)]
|
||||
[ServiceContract(SessionMode = SessionMode.Required)]
|
||||
[ServiceKnownType(typeof(object[]))]
|
||||
[ServiceKnownType(typeof(Dictionary<string, object>))]
|
||||
[ServiceKnownType(typeof(JavascriptObject))]
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CefSharp.Internals
|
||||
{
|
||||
[ServiceContract]
|
||||
public interface IRenderProcess
|
||||
{
|
||||
[OperationContract(AsyncPattern = true)]
|
||||
IAsyncResult BeginJavascriptCallbackAsync(int browserId, long callbackId, object[] parameters, TimeSpan? timeout, AsyncCallback callback, object state);
|
||||
|
||||
JavascriptResponse EndJavascriptCallbackAsync(IAsyncResult result);
|
||||
|
||||
[OperationContract]
|
||||
void DestroyJavascriptCallback(int browserId, long id);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ namespace CefSharp.Internals
|
||||
private static readonly List<string> Methods = new List<string>
|
||||
{
|
||||
ReflectionUtils.GetMethodName<IBrowserProcess>(p => p.CallMethod(0, null, null)),
|
||||
ReflectionUtils.GetMethodName<IRenderProcess>(p => p.BeginJavascriptCallbackAsync(0, 0, null, null, null, null)).Substring(5),
|
||||
};
|
||||
|
||||
private readonly IJavascriptCallbackFactory callbackFactory;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace CefSharp.Internals
|
||||
{
|
||||
public class JavascriptCallbackFactory : IJavascriptCallbackFactory
|
||||
{
|
||||
private readonly WeakReference browserProcessServiceHost;
|
||||
|
||||
public JavascriptCallbackFactory(WeakReference browserProcessServiceHost)
|
||||
{
|
||||
this.browserProcessServiceHost = browserProcessServiceHost;
|
||||
}
|
||||
|
||||
public IJavascriptCallback Create(JavascriptCallback callback)
|
||||
{
|
||||
return new JavascriptCallbackProxy(callback.Id, callback.BrowserId, browserProcessServiceHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// Copyright © 2010-2015 The CefSharp Project. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ServiceModel;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CefSharp.Internals
|
||||
{
|
||||
/// <summary>
|
||||
/// JavascriptCallbackProxy is a wrapper class around the WCF BrowserProcess.
|
||||
/// When the render process detects a function as param or return type it will add a
|
||||
/// <see cref="JavascriptCallback"/> that identifies the function. On the server side
|
||||
/// WCF Transforms <see cref="JavascriptCallback"/> into <see cref="JavascriptCallbackProxy"/>
|
||||
/// using the <see cref="JavascriptCallbackSurrogate"/> class.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
internal sealed class JavascriptCallbackProxy : DisposableResource, IJavascriptCallback
|
||||
{
|
||||
private readonly long id;
|
||||
private readonly int browserId;
|
||||
private readonly WeakReference browserProcessWeakReference;
|
||||
|
||||
public JavascriptCallbackProxy(long id, int browserId, WeakReference browserProcessWeakReference)
|
||||
{
|
||||
this.id = id;
|
||||
this.browserId = browserId;
|
||||
this.browserProcessWeakReference = browserProcessWeakReference;
|
||||
}
|
||||
|
||||
public Task<JavascriptResponse> ExecuteAsync(params object[] parms)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
throw new ObjectDisposedException("JavascriptCallbackProxy is already disposed.");
|
||||
}
|
||||
|
||||
var browserProcess = (BrowserProcessServiceHost)browserProcessWeakReference.Target;
|
||||
if (browserProcess == null)
|
||||
{
|
||||
throw new ObjectDisposedException("BrowserProcessServiceHost is already disposed.");
|
||||
}
|
||||
|
||||
return browserProcess.JavascriptCallback(browserId, id, parms, null);
|
||||
}
|
||||
|
||||
protected override void DoDispose(bool isDisposing)
|
||||
{
|
||||
var browserProcess = (BrowserProcessServiceHost)browserProcessWeakReference.Target;
|
||||
if (!IsDisposed && browserProcess != null && browserProcess.State == CommunicationState.Opened)
|
||||
{
|
||||
browserProcess.DestroyJavascriptCallback(browserId, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace CefSharp.Internals
|
||||
{
|
||||
if (type == typeof (JavascriptCallback))
|
||||
{
|
||||
return typeof (JavascriptCallbackProxy);
|
||||
return typeof (IJavascriptCallback);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user