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

Registering Custom Scheme Handlers

Robin Gabriël edited this page Feb 23, 2020 · 2 revisions

Inter-process Communication (IPC) in Chromely uses the Restful model. It has a method (GET, POST..). While a resource has an identifier, which is a Uniform Resource Identifier (URI) that uniquely identifies that resource.

A fully qualified resource will be in the following format: scheme://host/resource_relative_path

In this example: http://chromely.com/democontroller/movies translates to:

scheme: http 
host: chromely.com
resource_relative_path : /democontroller/movies

Registration of a custom scheme handler requires 2 steps:

  1. Registration of a url scheme
  2. Registration of a custom scheme handler factory

1. Registration of a url scheme

You can register a url scheme either in config file or via C# code.

  • Using config file
"urlSchemes": [
    {
      "name": "custom-01",
      "baseUrl": "",
      "scheme": "http",
      "host": "chromely.com",
      "urlSchemeType": "custom",
      "baseUrlStrict": false
    },
]
  • Using C# code
public class DefaultConfiguration : IChromelyConfiguration
{
    public DefaultConfiguration()
    {
        UrlSchemes.AddRange(new List<UrlScheme>()
        {
            new UrlScheme("custom-01", "local", string.Empty, string.Empty, UrlSchemeType.Custom, false),
        });
        
    }
}

2. Registration of a custom scheme handler factory

A registered url scheme must be matched to custom scheme handler. If no custom handler is provided, Chromely uses the provided CefGlueHttpSchemeHandler.

Registering a custom scheme requires creating both a custom scheme handler and custom scheme handler factory. The factory is then registered with the IOC container.

  • Create a scheme handler:
public class CustomHttpSchemeHandler : CefResourceHandler
{
}
  • Create a custom scheme handler factory:

See CefGlueHttpSchemeHandlerFactory for more information.

public class CustomHttpSchemeHandlerFactory : CefSchemeHandlerFactory
{
    protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
    {
        return new CustomHttpSchemeHandler();
    }
}
  • Finally register the handler factory:
public class DemoChromelyApp : ChromelyBasicApp
{
    public override void Configure(IChromelyContainer container)
    {
        base.Configure(container);
        container.RegisterSingleton(typeof(IChromelySchemeHandlerFactory), "custom-01", typeof(CustomHttpSchemeHandlerFactory));
    }
}

Important!

  • IChromelySchemeHandlerFactory is just a placeholder and should not be implemented/used elsewhere.
  • The name ex. "custom-01" used in url scheme must match the key used in factory registration.