コード例 #1
0
        private void RegisterEventHandler <TEventArgs>(
            IChromelyContainer container,
            CefEventKey key,
            Action <object, TEventArgs, IChromelyContainer> handler)
        {
            var service      = CefEventHandlerTypes.GetHandlerType(key);
            var eventHandler = new ChromelyEventHandler <TEventArgs>(key, (s, e) => handler(s, e, container));

            container.RegisterInstance(service, eventHandler.Key, eventHandler);
        }
コード例 #2
0
        /// <summary>
        /// The set event handlers.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        public static void SetEventHandlers(this CefGlueBrowser browser, IChromelyContainer container)
        {
            try
            {
                foreach (var enumKey in CefEventHandlerTypes.GetAllEventHandlerKeys())
                {
                    object instance = null;

                    var service = CefEventHandlerTypes.GetHandlerType(enumKey);
                    var keyStr  = enumKey.EnumToString();
                    try
                    {
                        if (container.IsRegistered(service, keyStr))
                        {
                            instance = container.GetInstance(service, keyStr);
                        }
                    }
                    catch (Exception exception)
                    {
                        Logger.Instance.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 <LoadingStateChangedEventArgs> 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)
            {
                Logger.Instance.Log.Error(exception);
            }
        }
コード例 #3
0
        private void RegisterEventHandler <T>(IChromelyContainer container, CefEventKey key, ChromelyEventHandler <T> handler)
        {
            var service = CefEventHandlerTypes.GetHandlerType(key);

            container.RegisterInstance(service, handler.Key, handler);
        }