mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
|
|
namespace CefSharp.Example
|
|
{
|
|
public static class CefExample
|
|
{
|
|
public const string DefaultUrl = "custom://cefsharp/BindingTest.html";
|
|
public const string TestResourceUrl = "http://test/resource/load";
|
|
public const string TestUnicodeResourceUrl = "http://test/resource/loadUnicode";
|
|
|
|
// Use when debugging the actual SubProcess, to make breakpoints etc. inside that project work.
|
|
private static readonly bool DebuggingSubProcess = Debugger.IsAttached;
|
|
|
|
public static void Init()
|
|
{
|
|
var settings = new CefSettings();
|
|
settings.RemoteDebuggingPort = 8088;
|
|
//settings.CefCommandLineArgs.Add("renderer-process-limit", "1");
|
|
//settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog");
|
|
settings.LogSeverity = LogSeverity.Verbose;
|
|
|
|
if (DebuggingSubProcess)
|
|
{
|
|
var architecture = Environment.Is64BitProcess ? "x64" : "x86";
|
|
settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe";
|
|
}
|
|
|
|
settings.RegisterScheme(new CefCustomScheme
|
|
{
|
|
SchemeName = CefSharpSchemeHandlerFactory.SchemeName,
|
|
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
|
|
});
|
|
|
|
if (!Cef.Initialize(settings))
|
|
{
|
|
throw new Exception("Unable to Initialize Cef");
|
|
}
|
|
}
|
|
|
|
public static void RegisterTestResources(IWebBrowser browser)
|
|
{
|
|
var handler = browser.ResourceHandler;
|
|
if (handler != null)
|
|
{
|
|
const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
|
|
handler.RegisterHandler(TestResourceUrl, ResourceHandler.FromString(responseBody));
|
|
|
|
const string unicodeResponseBody = "<html><body>整体满意度</body></html>";
|
|
handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.FromString(unicodeResponseBody));
|
|
}
|
|
}
|
|
}
|
|
}
|