-
Notifications
You must be signed in to change notification settings - Fork 278
Registering Custom Scheme Handlers
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:
- Registration of a url scheme
- Registration of a custom scheme handler factory
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),
});
}
}
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.
Chromely
Getting Started
Networking
Resources
Debugging
Detailed documentation on:
- Getting Started
- Configuring Chromely
- Loading Html
- Resource Handling
- Configuring Message Routing
- Register Ajax/XHR Handlers
- JavaScript Execution
- Scheme Registration
- Scheme Handlers
- Custom Http Handlers
- How to use commands
- Custom CEF Handlers
- Chromely on Raspberry Pi
- How to use app settings
- CEF binaries download
- Using DevTools