2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2013 The CefSharp Authors. All rights reserved.
|
2015-08-03 10:41:29 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
2017-03-02 14:14:24 +10:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-10-25 11:17:56 +10:00
|
|
|
using System.ComponentModel;
|
2017-03-02 14:14:24 +10:00
|
|
|
using System.IO;
|
2018-09-17 00:46:21 +02:00
|
|
|
using CefSharp.Example.Properties;
|
2017-03-02 14:14:24 +10:00
|
|
|
|
2013-09-18 22:05:30 +03:00
|
|
|
namespace CefSharp.Example
|
|
|
|
|
{
|
2015-10-12 15:10:04 +10:00
|
|
|
public class CefSharpSchemeHandlerFactory : ISchemeHandlerFactory
|
2013-09-18 22:05:30 +03:00
|
|
|
{
|
2013-10-27 10:54:20 +02:00
|
|
|
public const string SchemeName = "custom";
|
2015-09-16 09:05:52 +10:00
|
|
|
public const string SchemeNameTest = "test";
|
2013-09-18 22:05:30 +03:00
|
|
|
|
2022-10-25 11:17:56 +10:00
|
|
|
private static readonly IDictionary<string, object> ResourceDictionary;
|
2017-03-02 14:14:24 +10:00
|
|
|
|
|
|
|
|
static CefSharpSchemeHandlerFactory()
|
|
|
|
|
{
|
2022-10-25 11:17:56 +10:00
|
|
|
ResourceDictionary = new Dictionary<string, object>
|
2017-03-02 14:14:24 +10:00
|
|
|
{
|
|
|
|
|
{ "/home.html", Resources.home_html },
|
|
|
|
|
|
|
|
|
|
{ "/assets/css/shCore.css", Resources.assets_css_shCore_css },
|
|
|
|
|
{ "/assets/css/shCoreDefault.css", Resources.assets_css_shCoreDefault_css },
|
|
|
|
|
{ "/assets/css/docs.css", Resources.assets_css_docs_css },
|
|
|
|
|
{ "/assets/js/application.js", Resources.assets_js_application_js },
|
|
|
|
|
{ "/assets/js/jquery.js", Resources.assets_js_jquery_js },
|
|
|
|
|
{ "/assets/js/shBrushCSharp.js", Resources.assets_js_shBrushCSharp_js },
|
|
|
|
|
{ "/assets/js/shBrushJScript.js", Resources.assets_js_shBrushJScript_js },
|
|
|
|
|
{ "/assets/js/shCore.js", Resources.assets_js_shCore_js },
|
|
|
|
|
|
|
|
|
|
{ "/bootstrap/bootstrap-theme.min.css", Resources.bootstrap_theme_min_css },
|
|
|
|
|
{ "/bootstrap/bootstrap.min.css", Resources.bootstrap_min_css },
|
|
|
|
|
{ "/bootstrap/bootstrap.min.js", Resources.bootstrap_min_js },
|
|
|
|
|
|
|
|
|
|
{ "/BindingTest.html", Resources.BindingTest },
|
2020-07-24 20:42:14 +10:00
|
|
|
{ "/BindingTestNetCore.html", Resources.BindingTestNetCore },
|
|
|
|
|
{ "/BindingTestAsync.js", Resources.BindingTestAsync },
|
|
|
|
|
{ "/BindingTestSync.js", Resources.BindingTestSync },
|
2018-03-05 12:18:44 +10:00
|
|
|
{ "/BindingTestSingle.html", Resources.BindingTestSingle },
|
2018-01-22 10:24:25 +10:00
|
|
|
{ "/LegacyBindingTest.html", Resources.LegacyBindingTest },
|
2019-06-03 21:08:03 +10:00
|
|
|
{ "/PostMessageTest.html", Resources.PostMessageTest },
|
2017-03-02 14:14:24 +10:00
|
|
|
{ "/ExceptionTest.html", Resources.ExceptionTest },
|
|
|
|
|
{ "/PopupTest.html", Resources.PopupTest },
|
|
|
|
|
{ "/SchemeTest.html", Resources.SchemeTest },
|
|
|
|
|
{ "/TooltipTest.html", Resources.TooltipTest },
|
|
|
|
|
{ "/FramedWebGLTest.html", Resources.FramedWebGLTest },
|
|
|
|
|
{ "/MultiBindingTest.html", Resources.MultiBindingTest },
|
|
|
|
|
{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },
|
|
|
|
|
{ "/ResponseFilterTest.html", Resources.ResponseFilterTest },
|
|
|
|
|
{ "/DraggableRegionTest.html", Resources.DraggableRegionTest },
|
2019-04-05 02:58:27 +01:00
|
|
|
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
|
2017-03-02 14:14:24 +10:00
|
|
|
{ "/CssAnimationTest.html", Resources.CssAnimation },
|
2017-03-30 07:55:47 +10:00
|
|
|
{ "/CdmSupportTest.html", Resources.CdmSupportTest },
|
2017-05-05 12:52:59 +10:00
|
|
|
{ "/Recaptcha.html", Resources.Recaptcha },
|
|
|
|
|
{ "/UnicodeExampleGreaterThan32kb.html", Resources.UnicodeExampleGreaterThan32kb },
|
2019-04-26 14:16:42 +10:00
|
|
|
{ "/UnocodeExampleEqualTo32kb.html", Resources.UnocodeExampleEqualTo32kb },
|
2019-06-08 17:21:49 +10:00
|
|
|
{ "/JavascriptCallbackTest.html", Resources.JavascriptCallbackTest },
|
2020-05-19 21:55:16 +10:00
|
|
|
{ "/BindingTestsAsyncTask.html", Resources.BindingTestsAsyncTask },
|
2021-04-06 13:12:44 +10:00
|
|
|
{ "/BindingApiCustomObjectNameTest.html", Resources.BindingApiCustomObjectNameTest },
|
2022-10-25 11:17:56 +10:00
|
|
|
{ "/HelloWorld.html", Resources.HelloWorld },
|
|
|
|
|
{ "/ImageTest.html", Resources.ImageTest }
|
2017-03-02 14:14:24 +10:00
|
|
|
};
|
2022-10-25 11:17:56 +10:00
|
|
|
|
|
|
|
|
ResourceDictionary.Add("/assets/images/beach-2089936_1920.jpg", (byte[])TypeDescriptor.GetConverter(Resources.beach.GetType()).ConvertTo(Resources.beach, typeof(byte[])));
|
2017-03-02 14:14:24 +10:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 20:55:28 +10:00
|
|
|
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
|
2013-09-18 22:05:30 +03:00
|
|
|
{
|
2017-03-02 14:14:24 +10:00
|
|
|
//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.
|
|
|
|
|
// - Use the Default ResourceHandler implementation
|
|
|
|
|
|
|
|
|
|
var uri = new Uri(request.Url);
|
|
|
|
|
var fileName = uri.AbsolutePath;
|
|
|
|
|
|
|
|
|
|
//Load a file directly from Disk
|
|
|
|
|
if (fileName.EndsWith("CefSharp.Core.xml", StringComparison.OrdinalIgnoreCase))
|
2015-07-29 20:55:28 +10:00
|
|
|
{
|
2016-06-16 15:16:30 +10:00
|
|
|
//Convenient helper method to lookup the mimeType
|
2020-03-24 18:08:18 +10:00
|
|
|
var mimeType = Cef.GetMimeType("xml");
|
2016-06-16 15:16:30 +10:00
|
|
|
//Load a resource handler for CefSharp.Core.xml
|
2018-09-10 02:41:13 +02:00
|
|
|
return ResourceHandler.FromFilePath("CefSharp.Core.xml", mimeType, autoDisposeStream: true);
|
2015-07-29 20:55:28 +10:00
|
|
|
}
|
2017-03-02 14:14:24 +10:00
|
|
|
|
2019-09-20 20:38:06 +10:00
|
|
|
if (fileName.EndsWith("Logo.png", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
//Convenient helper method to lookup the mimeType
|
2020-03-24 18:08:18 +10:00
|
|
|
var mimeType = Cef.GetMimeType("png");
|
2019-09-20 20:38:06 +10:00
|
|
|
//Load a resource handler for Logo.png
|
|
|
|
|
return ResourceHandler.FromFilePath("..\\..\\..\\..\\CefSharp.WinForms.Example\\Resources\\chromium-256.png", mimeType, autoDisposeStream: true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 15:09:55 +10:00
|
|
|
if (uri.Host == "cefsharp.com" && schemeName == "https" && (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase)))
|
2017-03-02 14:14:24 +10:00
|
|
|
{
|
|
|
|
|
return new CefSharpSchemeHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.Equals(fileName, "/EmptyResponseFilterTest.html", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2020-03-26 08:13:53 +10:00
|
|
|
return ResourceHandler.FromString("", mimeType: ResourceHandler.DefaultMimeType);
|
2017-03-02 14:14:24 +10:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 11:17:56 +10:00
|
|
|
object resource;
|
|
|
|
|
if (ResourceDictionary.TryGetValue(fileName, out resource))
|
2017-03-02 14:14:24 +10:00
|
|
|
{
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
2022-10-25 11:17:56 +10:00
|
|
|
var mimeType = Cef.GetMimeType(fileExtension);
|
|
|
|
|
|
|
|
|
|
if (resource is string resourceString)
|
|
|
|
|
{
|
|
|
|
|
return ResourceHandler.FromString(resourceString, includePreamble: true, mimeType: mimeType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(resource is byte[] resourceByteArray)
|
|
|
|
|
{
|
|
|
|
|
return ResourceHandler.FromByteArray(resourceByteArray, mimeType: mimeType);
|
|
|
|
|
}
|
2017-03-02 14:14:24 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2013-09-18 22:05:30 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-26 14:16:42 +10:00
|
|
|
}
|