SIGN IN SIGN UP
cefsharp / CefSharp UNCLAIMED

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework

0 0 0 C#
// 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.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
2018-09-17 00:46:21 +02:00
using CefSharp.Example.Properties;
namespace CefSharp.Example
{
public class CefSharpSchemeHandlerFactory : ISchemeHandlerFactory
{
2013-10-27 10:54:20 +02:00
public const string SchemeName = "custom";
public const string SchemeNameTest = "test";
private static readonly IDictionary<string, object> ResourceDictionary;
static CefSharpSchemeHandlerFactory()
{
ResourceDictionary = new Dictionary<string, object>
{
{ "/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 },
{ "/BindingTestNetCore.html", Resources.BindingTestNetCore },
{ "/BindingTestAsync.js", Resources.BindingTestAsync },
{ "/BindingTestSync.js", Resources.BindingTestSync },
{ "/BindingTestSingle.html", Resources.BindingTestSingle },
Implement Javascript Binding v2 (#2247) * JSB Rewrite - Add CefSharp.RegisterBoundObject javascript method To get around the problem of IPC timing, I've reversed the communication, now it's the render process requesting the bound objects, the implementation is incomplete at this stage, more just a basic proof of concept Rewrite BindingTest.html using QUnit One of the tests doesn't map correctly as it requires def user interaction TODO: - Get objects by name - Rename Messages.h values that relate to this change so they are more descriptive - Better error handling - Caching of objects within a render process - Investigate global context options, don't think it's possible to call an async method directly in the global context # Conflicts: # CefSharp.Example/Resources/BindingTest.html * JSB Improve Request/Response message names * BindingTest.html - Output stress test results * Remove JavascriptRootObject was leftover from time we used WCF to transmit objects * JavascriptObjectRepository - Objects are now sent in the same list with an IsAsync flag Separation when sending over IPC with two unique lists isn't necessary * JavascriptObjectRepository - Return objects by name or return all by default Untabify CefAppUnmanagedWrapper.cpp Add minor comment to CefBrowserWrapper for a reminder that we use Frame Identifier as dictionary key * Add //TODO: JSB comments for work that's left to be done Ideally within a render process we cache bound objects once they've been communicated, It would also be nice to make multiple binding requests so objects can later be added dynamically * JSB Allow multiple calls to CefSharp.RegisterBoundObject Update BindingTest.html to name two distinct calls to different bound objects * JSB - Add some notes about caching, no working implementation yet * JSB - Dynamically Register object on Request * JSB Add ability to unbind an object and rename RegisterBoundObject to BindObjectAsync # Conflicts: # CefSharp.Example/Resources/BindingTest.html * JSB BindObjectAsync - if objects already bound then return false * JSB - Ignore Indexer properties Were previously throwing an exception * JSB - Add LegacyJavascriptBindingEnabled option so preserve existing behaviour This is only useful for SPA application and those that only navigate to pages hosting within a single domain. Any sort of cross-site navigation and a new render process will be spawned and objects won't be bound automatically (You can use the new methods to request they're bound yourself, at least in theory, more testing required on this) * Add LegacyBindingTest.html Current disabled by default. To enable uncomment CefSharpSettings.LegacyJavascriptBindingEnabled = true; in CefExample.cs * RegisterJsObject and RegisterAsyncJsObject can now only be used when CefSharpSettings.LegacyJavascriptBindingEnabled = true See https://github.com/cefsharp/CefSharp/issues/2246 for details
2018-01-22 10:24:25 +10:00
{ "/LegacyBindingTest.html", Resources.LegacyBindingTest },
{ "/PostMessageTest.html", Resources.PostMessageTest },
{ "/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 },
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
{ "/CssAnimationTest.html", Resources.CssAnimation },
{ "/CdmSupportTest.html", Resources.CdmSupportTest },
{ "/Recaptcha.html", Resources.Recaptcha },
{ "/UnicodeExampleGreaterThan32kb.html", Resources.UnicodeExampleGreaterThan32kb },
{ "/UnocodeExampleEqualTo32kb.html", Resources.UnocodeExampleEqualTo32kb },
{ "/JavascriptCallbackTest.html", Resources.JavascriptCallbackTest },
{ "/BindingTestsAsyncTask.html", Resources.BindingTestsAsyncTask },
{ "/BindingApiCustomObjectNameTest.html", Resources.BindingApiCustomObjectNameTest },
{ "/HelloWorld.html", Resources.HelloWorld },
{ "/ImageTest.html", Resources.ImageTest }
};
ResourceDictionary.Add("/assets/images/beach-2089936_1920.jpg", (byte[])TypeDescriptor.GetConverter(Resources.beach.GetType()).ConvertTo(Resources.beach, typeof(byte[])));
}
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, 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.
// - 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))
{
//Convenient helper method to lookup the mimeType
var mimeType = Cef.GetMimeType("xml");
//Load a resource handler for CefSharp.Core.xml
return ResourceHandler.FromFilePath("CefSharp.Core.xml", mimeType, autoDisposeStream: true);
}
if (fileName.EndsWith("Logo.png", StringComparison.OrdinalIgnoreCase))
{
//Convenient helper method to lookup the mimeType
var mimeType = Cef.GetMimeType("png");
//Load a resource handler for Logo.png
return ResourceHandler.FromFilePath("..\\..\\..\\..\\CefSharp.WinForms.Example\\Resources\\chromium-256.png", mimeType, autoDisposeStream: true);
}
if (uri.Host == "cefsharp.com" && schemeName == "https" && (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase) ||
string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase)))
{
return new CefSharpSchemeHandler();
}
if (string.Equals(fileName, "/EmptyResponseFilterTest.html", StringComparison.OrdinalIgnoreCase))
{
return ResourceHandler.FromString("", mimeType: ResourceHandler.DefaultMimeType);
}
object resource;
if (ResourceDictionary.TryGetValue(fileName, out resource))
{
var fileExtension = Path.GetExtension(fileName);
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);
}
}
return null;
}
}
}