fix(browser): contain CEF callback failures
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Lskj.Business;
|
using Lskj.Business;
|
||||||
using Lskj.Model;
|
using Lskj.Model;
|
||||||
|
using Lskj.Util;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -56,6 +57,19 @@ namespace Lskj.Control.BrowserSetting
|
|||||||
return contextMenuHandler;
|
return contextMenuHandler;
|
||||||
}
|
}
|
||||||
protected override bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message)
|
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"))
|
if (message.Name.Equals("OpenModule"))
|
||||||
{
|
{
|
||||||
@@ -150,6 +164,46 @@ namespace Lskj.Control.BrowserSetting
|
|||||||
|
|
||||||
return base.OnProcessMessageReceived(browser, frame, sourceProcess, message);
|
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)
|
public void Created(CefBrowser cefBrowser)
|
||||||
{
|
{
|
||||||
if (OnCreated != null)
|
if (OnCreated != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user