コード例 #1
0
ファイル: CefExample.cs プロジェクト: intuiface/CefSharp
        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.FromString(renderProcessCrashedBody));

                const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
                var          response     = ResourceHandler.FromString(responseBody);
                handler.RegisterHandler(TestResourceUrl, response);

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

                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.FromString(PluginInformation));
            }
        }
コード例 #2
0
        public static async void RegisterTestResources(IWebBrowser browser)
        {
            var handler = browser.ResourceHandlerFactory as DefaultResourceHandlerFactory;

            if (handler != null)
            {
                const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
                var          response     = ResourceHandler.FromString(responseBody);
                response.Headers.Add("HeaderTest1", "HeaderTest1Value");
                handler.RegisterHandler(TestResourceUrl, response);

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

                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>");

                    try
                    {
                        var plugins = await Cef.GetPlugins();

                        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>");
                        }
                    }
                    catch (TaskCanceledException ex)
                    {
                        pluginBody.Append("<tr>");
                        pluginBody.Append("<td colspan='4'>Cef.GetPlugins Timed out - 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>");
                    }

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

                    PluginInformation = pluginBody.ToString();
                }

                handler.RegisterHandler(PluginsTestUrl, ResourceHandler.FromString(PluginInformation));
            }
        }
コード例 #3
0
ファイル: CefExample.cs プロジェクト: SpecNefteGaz/CefSharp
        public static async void RegisterTestResources(IWebBrowser browser)
        {
            var handler = browser.ResourceHandlerFactory as DefaultResourceHandlerFactory;

            if (handler != null)
            {
                const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
                var          response     = ResourceHandler.FromString(responseBody);
                response.Headers.Add("HeaderTest1", "HeaderTest1Value");
                handler.RegisterHandler(TestResourceUrl, response);

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

                var plugins = await Cef.GetPlugins();

                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>");

                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>");


                handler.RegisterHandler("custom://cefsharp/plugins", ResourceHandler.FromString(pluginBody.ToString()));
            }
        }