예제 #1
0
        public virtual ChromelyConfiguration RegisterCustomHandler(CefHandlerKey key, Type implementation)
        {
            Type   service = CefHandlerDummyTypes.GetHandlerType(key);
            string keyStr  = key.EnumToString();

            IoC.RegisterPerRequest(service, keyStr, implementation);

            return(this);
        }
        public static void SetHandlers(this ChromiumWebBrowser 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 ILifeSpanHandler))
                        {
                            browser.LifeSpanHandler = (ILifeSpanHandler)instance;
                        }
                        break;

                    case CefHandlerKey.LoadHandler:
                        if ((instance != null) && (instance is ILoadHandler))
                        {
                            browser.LoadHandler = (ILoadHandler)instance;
                        }
                        break;

                    case CefHandlerKey.RequestHandler:
                        if ((instance != null) && (instance is IRequestHandler))
                        {
                            browser.RequestHandler = (IRequestHandler)instance;
                        }
                        else
                        {
                            browser.RequestHandler = new CefSharpRequestHandler();
                        }
                        break;

                    case CefHandlerKey.DisplayHandler:
                        if ((instance != null) && (instance is IDisplayHandler))
                        {
                            browser.DisplayHandler = (IDisplayHandler)instance;
                        }
                        break;

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

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

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

                    case CefHandlerKey.JSDialogHandler:
                        if ((instance != null) && (instance is IJsDialogHandler))
                        {
                            browser.JsDialogHandler = (IJsDialogHandler)instance;
                        }
                        break;

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

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

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

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

                    case CefHandlerKey.FindHandler:
                        if ((instance != null) && (instance is IFindHandler))
                        {
                            browser.FindHandler = (IFindHandler)instance;
                        }
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
예제 #3
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);
        }