-
Notifications
You must be signed in to change notification settings - Fork 279
Registering Resource Handlers
Resource files (html, css, javasctipt etc) can be loaded in 3 different ways:
- real website (e.g
http://google.com
) - file protocol (e.g
file:///{appDirectory}app/chromely.html
) - local resource (e.g
local://app/chromely.html
)
The preferred option is via local resources. For local resource processing a custom (or default) handler must be registered.
Registration of a resource handler requires 2 steps:
- Registration of a url scheme
- Registration of a custom resource 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": "local",
"host": "",
"urlSchemeType": "resource",
"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.Resource, false),
});
}
}
A registered url scheme must be matched to custom resource handler. If no resource handler is provided, Chromely uses the provided CefGlueResourceSchemeHandler.
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.
Custom scheme handler:
public class CustomResourceSchemeHandler : CefResourceHandler
{
}
Custom scheme handler factory:
See CefGlueResourceSchemeHandlerFactory for more information.
public class CustomResourceSchemeHandlerFactory : CefSchemeHandlerFactory
{
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
{
return new CustomResourceSchemeHandler();
}
}
Handler factory registration:
public class DemoChromelyApp : ChromelyBasicApp
{
public override void Configure(IChromelyContainer container)
{
base.Configure(container);
container.RegisterSingleton(typeof(IChromelyResourceHandlerFactory), "custom-01", typeof(CustomResourceSchemeHandlerFactory));
}
}
Important!
- IChromelyResourceHandlerFactory 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