SVN r1190
SVN-Revision: r1190
This commit is contained in:
@@ -25,5 +25,25 @@ namespace Lskj.Control.BrowserSetting2
|
||||
base.OnBeforeClose(browser);
|
||||
}
|
||||
|
||||
protected override bool OnBeforePopup(
|
||||
CefBrowser browser,
|
||||
CefFrame frame,
|
||||
string targetUrl,
|
||||
string targetFrameName,
|
||||
CefWindowOpenDisposition targetDisposition,
|
||||
bool userGesture,
|
||||
CefPopupFeatures popupFeatures,
|
||||
CefWindowInfo windowInfo,
|
||||
ref CefClient client,
|
||||
CefBrowserSettings settings,
|
||||
ref CefDictionaryValue extraInfo,
|
||||
ref bool noJavascriptAccess)
|
||||
{
|
||||
if (BsExternalProtocolHandler.TryHandle(targetUrl))
|
||||
return true;
|
||||
|
||||
return base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition,
|
||||
userGesture, popupFeatures, windowInfo, ref client, settings, ref extraInfo, ref noJavascriptAccess);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,105 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
us
|
||||
using Xilium.CefGlue;
|
||||
|
||||
namespace Lskj.Control.BrowserSetting2
|
||||
{
|
||||
public class BsRequestHandler : CefRequestHandler
|
||||
{
|
||||
private readonly CefResourceRequestHandler externalProtocolResourceRequestHandler = new BsExternalProtocolResourceRequestHandler();
|
||||
|
||||
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
|
||||
{
|
||||
if (BsExternalProtocolHandler.TryMatch(request.Url))
|
||||
return externalProtocolResourceRequestHandler;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
|
||||
{
|
||||
string url = request.Url;
|
||||
|
||||
if (BsExternalProtocolHandler.TryMatch(url))
|
||||
{
|
||||
if (frame == null || frame.IsMain)
|
||||
{
|
||||
BsExternalProtocolHandler.TryHandle(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.OnBeforeBrowse(browser, frame, request, userGesture, isRedirect);
|
||||
}
|
||||
|
||||
protected override bool OnOpenUrlFromTab(CefBrowser browser, CefFrame frame, string targetUrl, CefWindowOpenDisposition targetDisposition, bool userGesture)
|
||||
{
|
||||
if (BsExternalProtocolHandler.TryHandle(targetUrl))
|
||||
return true;
|
||||
|
||||
return base.OnOpenUrlFromTab(browser, frame, targetUrl, targetDisposition, userGesture);
|
||||
}
|
||||
|
||||
protected override void OnRenderProcessTerminated(CefBrowser browser, CefTerminationStatus status)
|
||||
{
|
||||
browser.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class BsExternalProtocolHandler
|
||||
{
|
||||
private const string PrintProtocol = "lskjprint:";
|
||||
|
||||
public static bool TryMatch(string url)
|
||||
{
|
||||
return !string.IsNullOrEmpty(url) && url.StartsWith(PrintProtocol, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool TryHandle(string url)
|
||||
{
|
||||
if (!TryMatch(url))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var processStartInfo = new System.Diagnostics.ProcessStartInfo(url)
|
||||
{
|
||||
UseShellExecute = true
|
||||
};
|
||||
System.Diagnostics.Process.Start(processStartInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(
|
||||
"打开打印程序失败:" + ex.Message,
|
||||
"提示",
|
||||
System.Windows.Forms.MessageBoxButtons.OK,
|
||||
System.Windows.Forms.MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class BsExternalProtocolResourceRequestHandler : CefResourceRequestHandler
|
||||
{
|
||||
protected override CefCookieAccessFilter GetCookieAccessFilter(CefBrowser browser, CefFrame frame, CefRequest request)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnProtocolExecution(CefBrowser browser, CefFrame frame, CefRequest request, ref bool allowOsExecution)
|
||||
{
|
||||
if (BsExternalProtocolHandler.TryMatch(request.Url))
|
||||
{
|
||||
allowOsExecution = true;
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnProtocolExecution(browser, frame, request, ref allowOsExecution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user