/// <summary>
/// Registers and loads a <see cref="ResourceHandler"/> that represents the HTML content.
/// </summary>
/// <remarks>
/// `Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps
/// the provided HTML in a <see cref="ResourceHandler"/> and loads the provided url using
/// the <see cref="IWebBrowser.Load"/> method.
/// </remarks>
/// <param name="browser">The ChromiumWebBrowser instance this method extends</param>
/// <param name="html">The HTML content.</param>
/// <param name="url">The URL that will be treated as the address of the content.</param>
/// <param name="encoding">Character Encoding</param>
public static void LoadHtml(this IWebBrowser browser, string html, string url, Encoding encoding)
{
var handler = browser.ResourceHandlerFactory;
if (handler == null)
{
throw new Exception("Implement IResourceHandlerFactory and assign to the ResourceHandlerFactory property to use this feature");
}
var resourceHandler = handler as DefaultResourceHandlerFactory;
if (resourceHandler == null)
{
throw new Exception("LoadHtml can only be used with the default IResourceHandlerFactory(DefaultResourceHandlerFactory) implementation");
}
resourceHandler.RegisterHandler(url, ResourceHandler.FromString(html, encoding, true));
browser.Load(url);
}