Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Configuration

softoille@gmail.com edited this page Nov 29, 2019 · 1 revision

Introduction

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

The following properties are set:

Property Description
AppArgs CEF app arguments
StartUrl CEF start url
HostWidth CEF host start width
HostHeight CEF host start height
LogSeverity CEF log severity
LogFile CEF log file
PerformDependencyCheck CEF dependency check flag
Locale CEF locale
DebuggingMode - (true or false) To allow for DevTool to be launched at all times whether in debug mode or not. This is only valid if the default ContextMenu handler is used. If the default handler is overwritten this is no longer valid unless re-implemented.

The following handlers are set:

Use default logger or set a new one Use default IOC container or set a new one Use of default resource scheme handler
Use of default url/http scheme handler Use of default JS handler (CefSharp only) Use of default Websocket handler (CefGlue only)
Add/register custom command line arguments Add/register custom setting properties Registration of custom local resource handlers
Registration of custom url/http schemes Registration of external url schemes Registration of custom scheme handlers
Registration of custom Javascript objects Register custom message router handlers (CefGlue) Register custom Websocket handler (CefGlue)
Registration of custom event handlers

Basic Usage

ChromelyConfiguration is fluently set. Sample Configuration:

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .WithAppArgs(args)
                              .WithHostBounds(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 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 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 add additional CEF3 command line arguments

Both CefSharp and CefGlue will be launched with common command line arguments. Extra arguments can be added.

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .WithCommandLineArg("no-sandbox", "1")
                              .WithCommandLineArg("device-scale-factor", "1")
                              ....

How to add custom settings

Both CefSharp and CefGlue will be launched with common setting properties. This can be overwritten by creating custom settings.

This will require setting:

  • Key - that can be found at - CefSettingKeys.
  • The value to be set. It can be actual value [bool, int, string], or string that is "parsable" to actual value.
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, full_path_to_subprocess)
                              .WithCustomSetting(CefSettingKeys.SingleProcess, true)
                              ....

How to add custom handlers

Both CefSharp and CefGlue come with few default handlers like CefSharpContextMenuHandler for CefSharp, CefGlueContextMenuHandler for CefGllue. These handlers can be replaced with custom handlers and new one can be added. This is done via registering custom handling using RegisterCustomHandler.

This will require setting:

  • Key - that can be found at - CefHandlerKey.
  • The value to be set. This has to be valid handler class. It MUST inherit from CefSharp, CefGlue provided handler base classes or interfaces.
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                             .RegisterCustomHandler(CefHandlerKey.LifeSpanHandler, typeof(CustomLifeSpanHandler))
                             .RegisterCustomHandler(CefHandlerKey.LoadHandler, typeof(CustomLoadHandler))
                             .RegisterCustomHandler(CefHandlerKey.RequestHandler, typeof(CustomRequestHandler))
                             .RegisterCustomHandler(CefHandlerKey.DisplayHandler, typeof(CustomDisplayHandler))
                             .RegisterCustomHandler(CefHandlerKey.ContextMenuHandler, typeof(CustomContextMenuHandler));
                              ....

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 that can be 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 local resource handlers

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

Notes:

  1. This controls how html and other files are loaded. See Local Resource Loading with a Custom Scheme Handler.
  2. Though they use same scheme handling base class, resource handling is different from scheme handling.

One or more custom local resource handlers can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterSchemeHandler("local", string.Empty, new CustomChromelySchemeHandler1())
                              .RegisterSchemeHandler("myscheme", string.Empty, new CustomChromelySchemeHandler2())
                              .....

How to register custom scheme handlers

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

Notes:

  1. This is for IPC.
  2. Though they use same scheme handling base class, scheme handling and resource handling are different.

One or more custom scheme handlers can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterSchemeHandler("http", "chromely.com", new CefSharpHttpSchemeHandlerFactory())
                              .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 can always be used.

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

How to register Websocket handler (Only CefGlue apps)

For more on Websocket see - Real time with Websocket.

ONLY one Websocket handler can be registered using either the default handler or registering a custom handler with:

Using default:

  ----
  .UseDefaultWebsocketHandler(address: string.Empty, port: 8181, onloadstartserver: true);
  ----

Register new handler:

  ----
  .RegisterWebsocketHandler(address: string.Empty, port: 8181, onloadstartserver: true, sockeHandler: new NewCustomWebsocketHandler);
  ----

- NewCustomWebsocketHandler must implement IChromelyWebsocketHandler interface.
Clone this wiki locally