d3587a16f1
Rollback tag: pre-current-browser-sync-20260818
216 lines
7.7 KiB
C#
216 lines
7.7 KiB
C#
using Lskj.Business;
|
|
using Lskj.Model;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Xilium.CefGlue;
|
|
|
|
namespace Lskj.Control.BrowserSetting
|
|
{
|
|
public class BsClient : CefClient
|
|
{
|
|
public FrmWebBrowser frmWebBrowser;
|
|
public int rightKeyFlag;
|
|
public event EventHandler OnCreated;
|
|
private readonly CefLifeSpanHandler lifeSpanHandler;
|
|
private readonly CefDownloadHandler downloadHandler;
|
|
private readonly CefKeyboardHandler keyboardHandler;
|
|
private readonly CefFocusHandler focusHandler;
|
|
private readonly CefRequestHandler requestHandler;
|
|
private readonly CefContextMenuHandler contextMenuHandler;
|
|
public BsClient(int RightKeyFlag = 0)
|
|
{
|
|
if (SystemInfo.Instance.BrowserRight) RightKeyFlag = 1;
|
|
lifeSpanHandler = new BsLifeSpanHandler(this);
|
|
downloadHandler = new BsDownloadHandler(this);
|
|
keyboardHandler = new BsKeyboardHandler();
|
|
focusHandler = new BsFocusHandler();
|
|
requestHandler = new BsRequestHandler();
|
|
contextMenuHandler = new BsContextMenuHandler(RightKeyFlag);
|
|
}
|
|
protected override CefLifeSpanHandler GetLifeSpanHandler()
|
|
{
|
|
return lifeSpanHandler;
|
|
}
|
|
protected override CefDownloadHandler GetDownloadHandler()
|
|
{
|
|
return downloadHandler;
|
|
}
|
|
protected override CefKeyboardHandler GetKeyboardHandler()
|
|
{
|
|
return keyboardHandler;
|
|
}
|
|
protected override CefFocusHandler GetFocusHandler()
|
|
{
|
|
return focusHandler;
|
|
}
|
|
protected override CefRequestHandler GetRequestHandler()
|
|
{
|
|
return requestHandler;
|
|
}
|
|
protected override CefContextMenuHandler GetContextMenuHandler()
|
|
{
|
|
return contextMenuHandler;
|
|
}
|
|
protected override bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
|
|
{
|
|
try
|
|
{
|
|
return OnProcessMessageReceivedCore(browser, frame, sourceProcess, message);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
ReportProcessMessageFailure(exception);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private bool OnProcessMessageReceivedCore(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
|
|
{
|
|
if (message.Name.Equals("OpenModule"))
|
|
{
|
|
string arg0 = message.Arguments.GetString(0);
|
|
string arg1 = message.Arguments.GetString(1);
|
|
string arg2 = message.Arguments.GetString(2);
|
|
string arg3 = message.Arguments.GetString(3);
|
|
string arg4 = message.Arguments.GetString(4);
|
|
if (ERPInfo.Instance.MainControl.InvokeRequired)
|
|
{
|
|
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
|
|
{
|
|
BsOpenModuleHandler.OpenModule(arg0, arg1, arg2, arg3, arg4);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
BrowserSetting.BsOpenModuleHandler.OpenModule(arg0, arg1, arg2, arg3, arg4);
|
|
}
|
|
}
|
|
else if (message.Name.Equals("OpenOnRightClick"))
|
|
{
|
|
string arg0 = message.Arguments.GetString(0);
|
|
string arg1 = message.Arguments.GetString(1);
|
|
string arg2 = message.Arguments.GetString(2);
|
|
string arg3 = message.Arguments.GetString(3);
|
|
if (ERPInfo.Instance.MainControl.InvokeRequired)
|
|
{
|
|
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
|
|
{
|
|
BsOpenModuleHandler.OpenRightModule(arg0, arg1, arg2, arg3);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
BsOpenModuleHandler.OpenRightModule(arg0, arg1, arg2, arg3);
|
|
}
|
|
}
|
|
else if (message.Name.Equals("CloseWin"))
|
|
{
|
|
if (frmWebBrowser != null && frmWebBrowser.Parent != null && frmWebBrowser.Parent.Parent != null && frmWebBrowser.Parent.Parent is BaseForm baseForm)
|
|
{
|
|
if (baseForm.InvokeRequired)
|
|
{
|
|
baseForm.Invoke(new Action(() =>
|
|
{
|
|
baseForm.DialogResult = DialogResult.OK;
|
|
baseForm.Close();
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
baseForm.DialogResult = DialogResult.OK;
|
|
baseForm.Close();
|
|
}
|
|
}
|
|
}
|
|
else if (message.Name.Equals("SelectPro"))
|
|
{
|
|
string arg0 = message.Arguments.GetString(0);
|
|
string arg1 = message.Arguments.GetString(1);
|
|
bool isclose = arg1!=null&&!string.IsNullOrWhiteSpace(arg1) && arg1.Equals("1") ? true : false;
|
|
if (frmWebBrowser != null && frmWebBrowser.Parent != null && frmWebBrowser.Parent.Parent != null && frmWebBrowser.Parent.Parent is BaseForm baseForm)
|
|
{
|
|
if (baseForm.InvokeRequired)
|
|
{
|
|
baseForm.Invoke(new Action(() =>
|
|
{
|
|
BsOpenModuleHandler.AddReturnRow(arg0);
|
|
if (isclose)
|
|
{
|
|
baseForm.DialogResult = DialogResult.OK;
|
|
baseForm.Close();
|
|
}
|
|
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
BsOpenModuleHandler.AddReturnRow(arg0);
|
|
if (isclose)
|
|
{
|
|
baseForm.DialogResult = DialogResult.OK;
|
|
baseForm.Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return base.OnProcessMessageReceived(browser, frame, sourceProcess, message);
|
|
}
|
|
|
|
private static void ReportProcessMessageFailure(Exception exception)
|
|
{
|
|
try
|
|
{
|
|
LogHelper.Instance.WriteError(exception);
|
|
}
|
|
catch
|
|
{
|
|
// Logging must never rethrow across the native CEF callback.
|
|
}
|
|
|
|
Action showError = () =>
|
|
{
|
|
try
|
|
{
|
|
MessageUtil.Show(exception);
|
|
}
|
|
catch
|
|
{
|
|
// Error reporting must never terminate the browser callback.
|
|
}
|
|
};
|
|
|
|
try
|
|
{
|
|
System.Windows.Forms.Control mainControl = ERPInfo.Instance.MainControl;
|
|
if (mainControl == null || mainControl.IsDisposed || !mainControl.IsHandleCreated)
|
|
return;
|
|
|
|
if (mainControl.InvokeRequired)
|
|
mainControl.BeginInvoke(showError);
|
|
else
|
|
showError();
|
|
}
|
|
catch
|
|
{
|
|
// The main window may close while the CEF callback is reporting.
|
|
}
|
|
}
|
|
public void Created(CefBrowser cefBrowser)
|
|
{
|
|
if (OnCreated != null)
|
|
{
|
|
OnCreated(cefBrowser, EventArgs.Empty);
|
|
}
|
|
}
|
|
}
|
|
}
|