1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.IO;
- using Cbdx.Tests.Resources;
- using CefSharp;
- using CefSharp.WinForms;
- namespace Cbdx.Tests.CefRelated
- {
- internal static class CefInit
- {
- public static readonly string ResourceSchemeName = $"cef-custom-scheme-{Guid.NewGuid()}".ToLower();
- public static readonly string ResourceDomainName = $"app-{Guid.NewGuid()}";
- public static readonly string ResourceRootUrl = $"{ResourceSchemeName}://{ResourceDomainName}/";
- public static void Init()
- {
- CefSharpSettings.LegacyJavascriptBindingEnabled = true;
- var settings = new CefSettings();
- settings.BrowserSubprocessPath = Path.Combine(Environment.Is64BitProcess ? "x64" : "x86", settings.BrowserSubprocessPath);
- settings.LogSeverity = LogSeverity.Disable;
- settings.CefCommandLineArgs.Add("-incognito", "");
- settings.CefCommandLineArgs.Add("--disable-application-cache", "");
- settings.CefCommandLineArgs.Add("--disable-cache", "");
- settings.CefCommandLineArgs.Add("--disable-gpu-program-cache", "");
- settings.CefCommandLineArgs.Add("--disable-gpu-shader-disk-cache", "");
- settings.CefCommandLineArgs.Add("--disable-local-storage", "");
- settings.RegisterScheme(new CefCustomScheme
- {
- SchemeName = ResourceSchemeName,
- DomainName = ResourceDomainName,
- SchemeHandlerFactory = new ResourceSchemeHandlerFactory(),
- });
- Cef.Initialize(settings);
- }
- public static void Quit()
- {
- Cef.Shutdown();
- }
- }
- internal class ResourceSchemeHandlerFactory : ISchemeHandlerFactory
- {
- IResourceHandler ISchemeHandlerFactory.Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
- {
- var path = new Uri(request.Url).LocalPath.TrimStart('/');
- var resource = ResourceLoader.GetBinResource(path);
- return null != resource
- ? new ResourceHandler(ResourceHandler.GetMimeType(Path.GetExtension(path)), new MemoryStream(resource, false), true)
- : null;
- }
- }
- }
|