/// <summary>
        /// Registers custom handler.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="implementation">
        /// The implementation.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyConfiguration"/> object.
        /// </returns>
        public virtual ChromelyConfiguration RegisterCustomHandler(CefHandlerKey key, Type implementation)
        {
            var service = CefHandlerFakeTypes.GetHandlerType(key);
            var keyStr  = key.EnumToString();

            IoC.RegisterPerRequest(service, keyStr, implementation);

            return(this);
        }
Example #2
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <returns>
        /// The <see cref="CefGlueClientParams"/>.
        /// </returns>
        public static CefGlueClientParams Create(CefGlueBrowser browser)
        {
            var clientParams = new CefGlueClientParams {
                Browser = browser
            };

            try
            {
                foreach (var enumKey in CefHandlerFakeTypes.GetAllHandlerKeys())
                {
                    object instance = null;

                    var service = CefHandlerFakeTypes.GetHandlerType(enumKey);
                    var keyStr  = enumKey.EnumToString();
                    try
                    {
                        if (IoC.IsRegistered(service, keyStr))
                        {
                            instance = IoC.GetInstance(service, keyStr);
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error(exception);
                    }

                    switch (enumKey)
                    {
                    case CefHandlerKey.LifeSpanHandler:
                        if (instance is CefLifeSpanHandler spanHandler)
                        {
                            clientParams.LifeSpanHandler = spanHandler;
                        }
                        else
                        {
                            clientParams.LifeSpanHandler = new CefGlueLifeSpanHandler();
                        }

                        break;

                    case CefHandlerKey.LoadHandler:
                        if (instance is CefLoadHandler loadHandler)
                        {
                            clientParams.LoadHandler = loadHandler;
                        }
                        else
                        {
                            clientParams.LoadHandler = new CefGlueLoadHandler();
                        }

                        break;

                    case CefHandlerKey.RequestHandler:
                        if (instance is CefRequestHandler requestHandler)
                        {
                            clientParams.RequestHandler = requestHandler;
                        }
                        else
                        {
                            clientParams.RequestHandler = new CefGlueRequestHandler();
                        }

                        break;

                    case CefHandlerKey.DisplayHandler:
                        if (instance is CefDisplayHandler displayHandler)
                        {
                            clientParams.DisplayHandler = displayHandler;
                        }
                        else
                        {
                            clientParams.DisplayHandler = new CefGlueDisplayHandler();
                        }

                        break;

                    case CefHandlerKey.ContextMenuHandler:
                        if (instance is CefContextMenuHandler menuHandler)
                        {
                            clientParams.ContextMenuHandler = menuHandler;
                        }
                        else
                        {
                            clientParams.ContextMenuHandler = new CefGlueContextMenuHandler();
                        }

                        break;

                    case CefHandlerKey.FocusHandler:
                        if (instance is CefFocusHandler focusHandler)
                        {
                            clientParams.FocusHandler = focusHandler;
                        }

                        break;

                    case CefHandlerKey.KeyboardHandler:
                        if (instance is CefKeyboardHandler keyboardHandler)
                        {
                            clientParams.KeyboardHandler = keyboardHandler;
                        }

                        break;

                    case CefHandlerKey.JsDialogHandler:
                        if (instance is CefJSDialogHandler jsDialogHandler)
                        {
                            clientParams.JsDialogHandler = jsDialogHandler;
                        }

                        break;

                    case CefHandlerKey.DialogHandler:
                        if (instance is CefDialogHandler dialogHandler)
                        {
                            clientParams.DialogHandler = dialogHandler;
                        }

                        break;

                    case CefHandlerKey.DragHandler:
                        if (instance is CefDragHandler dragHandler)
                        {
                            clientParams.DragHandler = dragHandler;
                        }

                        break;

                    case CefHandlerKey.GeolocationHandler:
                        if (instance is CefGeolocationHandler geolocationHandler)
                        {
                            clientParams.GeolocationHandler = geolocationHandler;
                        }

                        break;

                    case CefHandlerKey.DownloadHandler:
                        if (instance is CefDownloadHandler downloadHandler)
                        {
                            clientParams.DownloadHandler = downloadHandler;
                        }

                        break;

                    case CefHandlerKey.FindHandler:
                        if (instance is CefFindHandler handler)
                        {
                            clientParams.FindHandler = handler;
                        }

                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(clientParams);
        }
        /// <summary>
        /// The set handlers.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        public static void SetHandlers(this ChromiumWebBrowser browser)
        {
            try
            {
                foreach (var enumKey in CefHandlerFakeTypes.GetAllHandlerKeys())
                {
                    object instance = null;

                    var service = CefHandlerFakeTypes.GetHandlerType(enumKey);
                    var keyStr  = enumKey.EnumToString();
                    try
                    {
                        if (IoC.IsRegistered(service, keyStr))
                        {
                            instance = IoC.GetInstance(service, keyStr);
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error(exception);
                    }

                    switch (enumKey)
                    {
                    case CefHandlerKey.LifeSpanHandler:
                        if (instance is ILifeSpanHandler lifeSpanHandler)
                        {
                            browser.LifeSpanHandler = lifeSpanHandler;
                        }

                        break;

                    case CefHandlerKey.LoadHandler:
                        if (instance is ILoadHandler loadHandler)
                        {
                            browser.LoadHandler = loadHandler;
                        }

                        break;

                    case CefHandlerKey.RequestHandler:
                        if (instance is IRequestHandler requestHandler)
                        {
                            browser.RequestHandler = requestHandler;
                        }
                        else
                        {
                            browser.RequestHandler = new CefSharpRequestHandler();
                        }

                        break;

                    case CefHandlerKey.DisplayHandler:
                        if (instance is IDisplayHandler displayHandler)
                        {
                            browser.DisplayHandler = displayHandler;
                        }

                        break;

                    case CefHandlerKey.ContextMenuHandler:
                        if (instance is IContextMenuHandler contextMenuHandler)
                        {
                            browser.MenuHandler = contextMenuHandler;
                        }
                        else
                        {
                            browser.MenuHandler = new CefSharpContextMenuHandler();
                        }

                        break;

                    case CefHandlerKey.FocusHandler:
                        if (instance is IFocusHandler focusHandler)
                        {
                            browser.FocusHandler = focusHandler;
                        }

                        break;

                    case CefHandlerKey.KeyboardHandler:
                        if (instance is IKeyboardHandler keyboardHandler)
                        {
                            browser.KeyboardHandler = keyboardHandler;
                        }

                        break;

                    case CefHandlerKey.JsDialogHandler:
                        if (instance is IJsDialogHandler jsDialogHandler)
                        {
                            browser.JsDialogHandler = jsDialogHandler;
                        }

                        break;

                    case CefHandlerKey.DialogHandler:
                        if (instance is IDialogHandler dialogHandler)
                        {
                            browser.DialogHandler = dialogHandler;
                        }

                        break;

                    case CefHandlerKey.DragHandler:
                        if (instance is IDragHandler dragHandler)
                        {
                            browser.DragHandler = dragHandler;
                        }

                        break;

                    case CefHandlerKey.GeolocationHandler:
                        if (instance is IGeolocationHandler geolocationHandler)
                        {
                            browser.GeolocationHandler = geolocationHandler;
                        }

                        break;

                    case CefHandlerKey.DownloadHandler:
                        if (instance is IDownloadHandler downloadHandler)
                        {
                            browser.DownloadHandler = downloadHandler;
                        }

                        break;

                    case CefHandlerKey.FindHandler:
                        if (instance is IFindHandler findHandler)
                        {
                            browser.FindHandler = findHandler;
                        }

                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }