Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Howto: Custom Request Scheme Handler #247

Closed
mattkol opened this issue Oct 4, 2020 · 0 comments
Closed

Howto: Custom Request Scheme Handler #247

mattkol opened this issue Oct 4, 2020 · 0 comments

Comments

@mattkol
Copy link
Member

mattkol commented Oct 4, 2020

CustomRequestHandler.zip

    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            AppBuilder
            .Create()
            .UseApp<DemoApp>()
            .Build()
            .Run(args);
        }
    }

    public class DemoApp : ChromelyBasicApp
    {
        public override void ConfigureServices(ServiceCollection services)
        {
            base.ConfigureServices(services);
            services.AddSingleton(typeof(CustomRequestSchemeHandlerFactory), typeof(CustomRequestSchemeHandlerFactory));
            services.AddSingleton(typeof(IChromelySchemeHandler), typeof(CustomSchemeHandler));

            RegisterControllerAssembly(services, typeof(DemoApp).Assembly);
        }
    }
    public class CustomSchemeHandler : IChromelySchemeHandler
    {
        public CustomSchemeHandler(CustomRequestSchemeHandlerFactory schemeHandlerFactory)
        {
            Name = "MyCustomRequestSchemeHamdler";
            // Scheme: myscheme
            // Host: custom - mapped to folder name containing resource files
            //http://custom.com/customcontroller/hello";
            Scheme = new UrlScheme("mycustomrequestcheme", "http", "custom.com", string.Empty, UrlSchemeType.LocalRquest);
            HandlerFactory = schemeHandlerFactory;
            IsCorsEnabled = true;
            IsSecure = false;
        }

        public string Name { get; set; }
        public UrlScheme Scheme { get; set; }

        // Needed for CefSharp
        public object Handler { get; set; }
        public object HandlerFactory { get; set; }
        public bool IsCorsEnabled { get; set; }
        public bool IsSecure { get; set; }
    }
    public class CustomRequestSchemeHandler : CefResourceHandler
    {
    }
    public class CustomRequestSchemeHandlerFactory : CefSchemeHandlerFactory
    {
         protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
        {
            return new CustomRequestSchemeHandler();
        }
    }
    [ControllerProperty(Name = "CustomController")]
    public class CustomController : ChromelyController
    {
    }
@mattkol mattkol closed this as completed Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant