Esempio n. 1
0
        public static async void RegisterTestResources(IWebBrowser browser)
        {
            var handler = browser.ResourceHandlerFactory as DefaultResourceHandlerFactory;

            if (handler != null)
            {
                const string renderProcessCrashedBody = "<html><body><h1>Render Process Crashed</h1><p>Your seeing this message as the render process has crashed</p></body></html>";
                handler.RegisterHandler(RenderProcessCrashedUrl, ResourceHandler.FromByteArray(ResourceHandler.GetByteArray(renderProcessCrashedBody, Encoding.UTF8)));

                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.FromByteArray(ResourceHandler.GetByteArray(responseBody, Encoding.UTF8)));

                const string unicodeResponseBody = "<html><body>整体满意度</body></html>";
                handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.FromByteArray(ResourceHandler.GetByteArray(unicodeResponseBody, Encoding.UTF8)));

                if (string.IsNullOrEmpty(PluginInformation))
                {
                    var pluginBody = new StringBuilder();
                    pluginBody.Append("<html><body><h1>Plugins</h1><table>");
                    pluginBody.Append("<tr>");
                    pluginBody.Append("<th>Name</th>");
                    pluginBody.Append("<th>Description</th>");
                    pluginBody.Append("<th>Version</th>");
                    pluginBody.Append("<th>Path</th>");
                    pluginBody.Append("</tr>");

                    var plugins = await Cef.GetPlugins();

                    if (plugins.Count == 0)
                    {
                        pluginBody.Append("<tr>");
                        pluginBody.Append("<td colspan='4'>Cef.GetPlugins returned an empty list - likely no plugins were loaded on your system</td>");
                        pluginBody.Append("</tr>");
                        pluginBody.Append("<tr>");
                        pluginBody.Append("<td colspan='4'>You may find that NPAPI/PPAPI need to be enabled</td>");
                        pluginBody.Append("</tr>");
                    }
                    else
                    {
                        foreach (var plugin in plugins)
                        {
                            pluginBody.Append("<tr>");
                            pluginBody.Append("<td>" + plugin.Name + "</td>");
                            pluginBody.Append("<td>" + plugin.Description + "</td>");
                            pluginBody.Append("<td>" + plugin.Version + "</td>");
                            pluginBody.Append("<td>" + plugin.Path + "</td>");
                            pluginBody.Append("</tr>");
                        }
                    }

                    pluginBody.Append("</table></body></html>");

                    PluginInformation = pluginBody.ToString();
                }

                handler.RegisterHandler(PluginsTestUrl, ResourceHandler.FromByteArray(ResourceHandler.GetByteArray(PluginInformation, Encoding.UTF8)));
            }
        }
Esempio n. 2
0
        public IResourceHandler GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request)
        {
            var requestUrl = RequestUrl.FromString(request.Url);

            var api      = GetApi(requestUrl.Api);
            var mimeType = mimeResolver.GetMimeType(Path.GetFileName(requestUrl.Resource));

            return(ResourceHandler.FromByteArray(api.ProcessRequest(requestUrl), mimeType));
        }
Esempio n. 3
0
        public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
        {
            var uri      = new Uri(request.Url);
            var fileName = uri.AbsolutePath.TrimStart('/');

            var file = book.Files.Cast <File?>().SingleOrDefault(f => f !.Path.Equals(fileName, StringComparison.OrdinalIgnoreCase));

            if (file == null)
            {
                return(ResourceHandler.FromString("<html></html>", ".html"));
            }

            return(ResourceHandler.FromByteArray(file.Content, ContentTypeParser.GetMimeTypeContentType(file.ContentType)));
        }
Esempio n. 4
0
        protected override IResourceHandler GetResourceHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request)
        {
            //Notes:
            // - The 'host' portion is entirely ignored by this scheme handler.
            // - If you register a ISchemeHandlerFactory for http/https schemes you should also specify a domain name
            // - Avoid doing lots of processing in this method as it will affect performance.
            // - Uses the Default ResourceHandler implementation
            if (request.Url == "disk://background")
            {
                return(ResourceHandler.FromByteArray(GetBitmapAsByteArray(Resources.notification_background)));
            }

            if (request.Url == "disk://achievement-notification")
            {
                if (AlertsController.Instance.CustomAchievementEnabled)
                {
                    return(ResourceHandler.FromFilePath(Settings.Default.notification_custom_achievement_file, null, true));
                }
                else
                {
                    return(ResourceHandler.FromFilePath("video/achievement-notification.webm", null, true));
                }
            }

            if (request.Url == "disk://mastery-notification")
            {
                if (AlertsController.Instance.CustomMasteryEnabled)
                {
                    return(ResourceHandler.FromFilePath(Settings.Default.notification_custom_mastery_file));
                }
                else
                {
                    return(ResourceHandler.FromFilePath("video/mastery-notification.webm"));
                }
            }

            return(ResourceHandler.FromFilePath("" + request.Url.Replace("disk://", "")));
        }
Esempio n. 5
0
 IResourceHandler IResourceRequestHandler.GetResourceHandler(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request)
 {
     return(ResourceHandler.FromByteArray(data, mimeType));
 }
Esempio n. 6
0
 public static Func <IResourceHandler> ForBytes(byte[] bytes, string mimeType)
 {
     return(() => ResourceHandler.FromByteArray(bytes, mimeType));
 }