namespace ZenFulcrum.EmbeddedBrowser { /// /// Generates HTML for errors for page load failures. /// /// In the past we had a single static HTML page that we'd load, followed by a CallFunction() invocation to set the error /// details. The JS call can be iffy at times when an error is going on, so now we just go with straight HTML and no JavaScript. /// /// The Real Solution™ is to have some form of page interstitials and/or a proper error page concept. /// public static class ErrorGenerator { private const string htmlIntro = @" "; private const string htmlOutro = @""; private const string loadTemplate = @"

Load Error

{mainError}

{detail}

"; private const string sadTemplate = @"

Page Crashed

The renderer process for this page is no longer running.

"; /// /// Quick and dirty htmlspecialchars. /// (Given we don't have access to System.Net.WebUtility.HtmlDecode.) /// private static string Encode(string text) { return text.Replace("&", "&").Replace("\"", """).Replace("<", "<").Replace(">", ">"); } public static string GenerateFetchError(JSONNode err) { return htmlIntro + loadTemplate .Replace("{mainError}", Encode("Failed to load " + err["url"])) .Replace("{detail}", Encode(err["error"])) + htmlOutro ; } public static string GenerateCertError(JSONNode err) { return htmlIntro + loadTemplate .Replace("{mainError}", Encode("Failed to load " + err["url"])) .Replace("{detail}", Encode(err["error"])) + htmlOutro ; } public static string GenerateSadTabError() { return htmlIntro + sadTemplate + htmlOutro; } } }