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

Configuration

mattkol edited this page Mar 4, 2018 · 39 revisions

Most required Cef configuration is done via ChromelyConfiguration class. ChromelyConfiguration provides default values that can be used as-is or set new properties.

The followings are configured:

AppArgs  - Cef app arguments
StartUrl - Cef start url
HostWidth - Cef start width
HostHeight -  Cef start height
LogSeverity - Cef log severity
LogFile - Cef log file

Use default logger or set a new one
Use default IOC container or set a new one
Registration of custom url schemes
Registration of external url schemes
Registration of custom scheme handlers
Registration of custom Javascript objects

ChromelyConfiguration is fluently set. Sample Configuration:

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .WithAppArgs(args)
                              .WithHostSize(1200, 900)
                              .WithLogFile("logs\\chromely.cef_new.log")
                              .WithStartUrl(startUrl)
                              .WithLogSeverity(LogSeverity.Info)
                              .UseDefaultLogger("logs\\chromely_new.log", true)
                              .RegisterSchemeHandler("http", "chromely.com", new CefGlueSchemeHandlerFactory());

How to set new logger (or use default)

Chromely provides a simple default logger. This can be set in the configuration. The default file can be changed and also if the logs can also be written to the console.

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .UseDefaultLogger("logs\\chromely_new.log", true)
                              ....

A new logger (of type IChromelyLogger) can be set.

IChromelyLogger logger = new NewLogger();
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                               ....
                              .WithLogger(logger)
                              ....

How to set new IOC Container

A new IOC container (of type IChromelyContainer) can be set prior to setting the configuration object or set passing via constructor (create). *** This must be done prior to other registrations otherwise the default container will kick in during these registrations and will be lost (invalid). ONLY one IOC container is required.

// The IOC container must implement the IChromelyContainer interface.
IChromelyContainer newContainer = new CustomContainer();
IoC.Container = newContainer;

Or:

// The IOC container must implement the IChromelyContainer interface.
IChromelyContainer newContainer = new CustomContainer();
ChromelyConfiguration config = ChromelyConfiguration()
                              .Create(newContainer)
                              .....

How to register custom url schemes

Custom url schemes can be just custom (can be used as developer pleases) or custom external urls. External urls are urls opened by the default browser - externally to Chromely (e.g - www.google.com). For more on external url registration see - External Url Registration. One or more custom url schemes can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterCustomrUrlScheme("http", "chromely.com")
                              .RegisterCustomrUrlScheme("test", "test.com")
                              .RegisterExternaleUrlScheme("https", "google.com")
                              .RegisterExternaleUrlScheme("https", "https://github.com/mattkol/Chromely")
                              .....

How to register custom scheme handlers

For more on custom scheme handling registration see - Custom Scheme Handling.

One or more custom scheme handlers can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterSchemeHandler("http", "chromely.com", new CefGlueSchemeHandlerFactory())
                              .RegisterSchemeHandler("http", "chromely2.com", new CustomSchemeHandlerFactory())
                              .....

How to register custom Javascript objects (Only CefSharp apps)

For more on custom Javascript objects registration see - Custom Javascript Object.

One or more custom Javascript objects can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterJsHandler("boundControllerAsync", new CefSharpBoundObject(), null, true);
                              .RegisterJsHandler("boundControllerAsync2", new NewCefSharpBoundObject(), null, true);
                              .....

How to register generic message router handlers (Only CefGlue apps)

For more on generic message router handlers registration see - Generic Message Routing.

One or more generic message router handlers can be registered with:

**** If no object is registered, the default Handler will be used.

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterMessageRouterHandler(new NewMessageRouter());
                              .RegisterMessageRouterHandler(new NewMessageRouter2());
                              .....