Example #1
0
 public CefGlueClient(CefGlueClientParams clientParams)
 {
     m_core               = clientParams.Browser;
     m_lifeSpanHandler    = clientParams.LifeSpanHandler;
     m_loadHandler        = clientParams.LoadHandler;
     m_requestHandler     = clientParams.RequestHandler;
     m_displayHandler     = clientParams.DisplayHandler;
     m_contextMenuHandler = clientParams.ContextMenuHandler;
     m_focusHandler       = clientParams.FocusHandler;
     m_keyboardHandler    = clientParams.KeyboardHandler;
     m_jsDialogHandler    = clientParams.JSDialogHandler;
     m_dialogHandler      = clientParams.DialogHandler;
     m_dragHandler        = clientParams.DragHandler;
     m_geolocationHandler = clientParams.GeolocationHandler;
     m_downloadHandler    = clientParams.DownloadHandler;
     m_findHandler        = clientParams.FindHandler;
 }
        /// <summary>
        /// The set event handlers.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        public static void SetEventHandlers(this CefGlueBrowser browser)
        {
            try
            {
                foreach (var enumKey in CefEventHandlerFakeTypes.GetAllEventHandlerKeys())
                {
                    object instance = null;

                    var service = CefEventHandlerFakeTypes.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 CefEventKey.None:
                        break;

                    case CefEventKey.FrameLoadStart:
                        if (instance is ChromelyEventHandler <FrameLoadStartEventArgs> frameLoadStart)
                        {
                            browser.FrameLoadStart += frameLoadStart.Handler;
                        }

                        break;

                    case CefEventKey.AddressChanged:
                        if (instance is ChromelyEventHandler <AddressChangedEventArgs> addressChanged)
                        {
                            browser.AddressChanged += addressChanged.Handler;
                        }

                        break;

                    case CefEventKey.TitleChanged:
                        if (instance is ChromelyEventHandler <TitleChangedEventArgs> titleChanged)
                        {
                            browser.TitleChanged += titleChanged.Handler;
                        }

                        break;

                    case CefEventKey.FrameLoadEnd:
                        if (instance is ChromelyEventHandler <FrameLoadEndEventArgs> frameLoadEnd)
                        {
                            browser.FrameLoadEnd += frameLoadEnd.Handler;
                        }

                        break;

                    case CefEventKey.LoadingStateChanged:
                        if (instance is ChromelyEventHandler <LoadingStateChangeEventArgs> loadingStateChanged)
                        {
                            browser.LoadingStateChanged += loadingStateChanged.Handler;
                        }

                        break;

                    case CefEventKey.ConsoleMessage:
                        if (instance is ChromelyEventHandler <ConsoleMessageEventArgs> consoleMessage)
                        {
                            browser.ConsoleMessage += consoleMessage.Handler;
                        }

                        break;

                    case CefEventKey.StatusMessage:
                        if (instance is ChromelyEventHandler <StatusMessageEventArgs> statusMessage)
                        {
                            browser.StatusMessage += statusMessage.Handler;
                        }

                        break;

                    case CefEventKey.LoadError:
                        if (instance is ChromelyEventHandler <LoadErrorEventArgs> loadError)
                        {
                            browser.LoadError += loadError.Handler;
                        }

                        break;

                    case CefEventKey.TooltipChanged:
                        if (instance is ChromelyEventHandler <TooltipEventArgs> tooltipChanged)
                        {
                            browser.TooltipChanged += tooltipChanged.Handler;
                        }

                        break;

                    case CefEventKey.BeforeClose:
                        if (instance is ChromelyEventHandler <BeforeCloseEventArgs> beforeClose)
                        {
                            browser.BeforeClose += beforeClose.Handler;
                        }

                        break;

                    case CefEventKey.BeforePopup:
                        if (instance is ChromelyEventHandler <BeforePopupEventArgs> beforePopup)
                        {
                            browser.BeforePopup += beforePopup.Handler;
                        }

                        break;

                    case CefEventKey.PluginCrashed:
                        if (instance is ChromelyEventHandler <PluginCrashedEventArgs> pluginCrashed)
                        {
                            browser.PluginCrashed += pluginCrashed.Handler;
                        }

                        break;

                    case CefEventKey.RenderProcessTerminated:
                        if (instance is ChromelyEventHandler <RenderProcessTerminatedEventArgs> renderProcessTerminated)
                        {
                            browser.RenderProcessTerminated += renderProcessTerminated.Handler;
                        }

                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Example #3
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);
        }
Example #4
0
        public static CefGlueClientParams Create(CefGlueBrowser browser)
        {
            CefGlueClientParams clientParams = new CefGlueClientParams();

            clientParams.Browser = browser;

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

                    Type   service = CefHandlerDummyTypes.GetHandlerType(enumKey);
                    string 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 != null) && (instance is CefLifeSpanHandler))
                        {
                            clientParams.LifeSpanHandler = (CefLifeSpanHandler)instance;
                        }
                        else
                        {
                            clientParams.LifeSpanHandler = new CefGlueLifeSpanHandler();
                        }
                        break;

                    case CefHandlerKey.LoadHandler:
                        if ((instance != null) && (instance is CefLoadHandler))
                        {
                            clientParams.LoadHandler = (CefLoadHandler)instance;
                        }
                        else
                        {
                            clientParams.LoadHandler = new CefGlueLoadHandler();
                        }
                        break;

                    case CefHandlerKey.RequestHandler:
                        if ((instance != null) && (instance is CefRequestHandler))
                        {
                            clientParams.RequestHandler = (CefRequestHandler)instance;
                        }
                        else
                        {
                            clientParams.RequestHandler = new CefGlueRequestHandler();
                        }
                        break;

                    case CefHandlerKey.DisplayHandler:
                        if ((instance != null) && (instance is CefDisplayHandler))
                        {
                            clientParams.DisplayHandler = (CefDisplayHandler)instance;
                        }
                        else
                        {
                            clientParams.DisplayHandler = new CefGlueDisplayHandler();
                        }
                        break;

                    case CefHandlerKey.ContextMenuHandler:
                        if ((instance != null) && (instance is CefContextMenuHandler))
                        {
                            clientParams.ContextMenuHandler = (CefContextMenuHandler)instance;
                        }
                        else
                        {
                            clientParams.ContextMenuHandler = new CefGlueContextMenuHandler();
                        }
                        break;

                    case CefHandlerKey.FocusHandler:
                        if ((instance != null) && (instance is CefFocusHandler))
                        {
                            clientParams.FocusHandler = (CefFocusHandler)instance;
                        }
                        break;

                    case CefHandlerKey.KeyboardHandler:
                        if ((instance != null) && (instance is CefKeyboardHandler))
                        {
                            clientParams.KeyboardHandler = (CefKeyboardHandler)instance;
                        }
                        break;

                    case CefHandlerKey.JSDialogHandler:
                        if ((instance != null) && (instance is CefJSDialogHandler))
                        {
                            clientParams.JSDialogHandler = (CefJSDialogHandler)instance;
                        }
                        break;

                    case CefHandlerKey.DialogHandler:
                        if ((instance != null) && (instance is CefDialogHandler))
                        {
                            clientParams.DialogHandler = (CefDialogHandler)instance;
                        }
                        break;

                    case CefHandlerKey.DragHandler:
                        if ((instance != null) && (instance is CefDragHandler))
                        {
                            clientParams.DragHandler = (CefDragHandler)instance;
                        }
                        break;

                    case CefHandlerKey.GeolocationHandler:
                        if ((instance != null) && (instance is CefGeolocationHandler))
                        {
                            clientParams.GeolocationHandler = (CefGeolocationHandler)instance;
                        }
                        break;

                    case CefHandlerKey.DownloadHandler:
                        if ((instance != null) && (instance is CefDownloadHandler))
                        {
                            clientParams.DownloadHandler = (CefDownloadHandler)instance;
                        }
                        break;

                    case CefHandlerKey.FindHandler:
                        if ((instance != null) && (instance is CefFindHandler))
                        {
                            clientParams.FindHandler = (CefFindHandler)instance;
                        }
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(clientParams);
        }