Esempio n. 1
0
 /// <summary>Initializes a new instance of the <see cref="CefGlueCustomHandlers" /> class.</summary>
 /// <param name="browserMessageRouter">The browser message router.</param>
 /// <param name="handlers">The client params.</param>
 public CefGlueClient(CefMessageRouterBrowserSide browserMessageRouter, CefGlueCustomHandlers handlers)
 {
     _browserMessageRouter = browserMessageRouter;
     _lifeSpanHandler      = handlers.LifeSpanHandler;
     _loadHandler          = handlers.LoadHandler;
     _requestHandler       = handlers.RequestHandler;
     _displayHandler       = handlers.DisplayHandler;
     _contextMenuHandler   = handlers.ContextMenuHandler;
     _focusHandler         = handlers.FocusHandler;
     _keyboardHandler      = handlers.KeyboardHandler;
     _jsDialogHandler      = handlers.JsDialogHandler;
     _dialogHandler        = handlers.DialogHandler;
     _dragHandler          = handlers.DragHandler;
     _downloadHandler      = handlers.DownloadHandler;
     _findHandler          = handlers.FindHandler;
 }
Esempio n. 2
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="windowInfo">
        /// The window info.
        /// </param>
        public void Create(CefWindowInfo windowInfo)
        {
            if (_client == null)
            {
                var handlers = CefGlueCustomHandlers.Parse(_container, _config, _commandTaskRunner, this);
                _client = new CefGlueClient(this, _browserMessageRouter, handlers);
            }
            if (_settings == null)
            {
                _settings = new CefBrowserSettings();
            }

            _settings.DefaultEncoding             = "UTF-8";
            _settings.FileAccessFromFileUrls      = CefState.Enabled;
            _settings.UniversalAccessFromFileUrls = CefState.Enabled;
            _settings.WebSecurity = CefState.Disabled;

            CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl);
        }
        public static CefGlueCustomHandlers Parse(IChromelyContainer container, IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, CefGlueBrowser browser)
        {
            var handlers = new CefGlueCustomHandlers();

            try
            {
                // Set default handlers
                handlers.LifeSpanHandler    = new CefGlueLifeSpanHandler(config, commandTaskRunner, browser);
                handlers.LoadHandler        = new CefGlueLoadHandler(config, browser);
                handlers.RequestHandler     = new CefGlueRequestHandler(config, commandTaskRunner, browser);
                handlers.DisplayHandler     = new CefGlueDisplayHandler(config, browser);
                handlers.ContextMenuHandler = new CefGlueContextMenuHandler(config);

                // Update custom handlers
                var customHandlers = container.GetAllInstances(typeof(IChromelyCustomHandler));
                if (customHandlers != null && customHandlers.Any())
                {
                    foreach (var handler in customHandlers)
                    {
                        if (handler is CefLifeSpanHandler spanHandler)
                        {
                            handlers.LifeSpanHandler = spanHandler;
                        }
                        if (handler is CefLoadHandler loadHandler)
                        {
                            handlers.LoadHandler = loadHandler;
                        }
                        if (handler is CefRequestHandler requestHandler)
                        {
                            handlers.RequestHandler = requestHandler;
                        }
                        if (handler is CefDisplayHandler displayHandler)
                        {
                            handlers.DisplayHandler = displayHandler;
                        }
                        if (handler is CefContextMenuHandler menuHandler)
                        {
                            handlers.ContextMenuHandler = menuHandler;
                        }
                        if (handler is CefFocusHandler focusHandler)
                        {
                            handlers.FocusHandler = focusHandler;
                        }
                        if (handler is CefKeyboardHandler keyboardHandler)
                        {
                            handlers.KeyboardHandler = keyboardHandler;
                        }
                        if (handler is CefJSDialogHandler jsDialogHandler)
                        {
                            handlers.JsDialogHandler = jsDialogHandler;
                        }
                        if (handler is CefDialogHandler dialogHandler)
                        {
                            handlers.DialogHandler = dialogHandler;
                        }
                        if (handler is CefDragHandler dragHandler)
                        {
                            handlers.DragHandler = dragHandler;
                        }
                        if (handler is CefDownloadHandler downloadHandler)
                        {
                            handlers.DownloadHandler = downloadHandler;
                        }
                        if (handler is CefFindHandler cefFinderhandler)
                        {
                            handlers.FindHandler = cefFinderhandler;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Log.Error(exception);
            }

            return(handlers);
        }