コード例 #1
0
        public static CefOptions GetCefOptions(this IAppFrame frame, FrameOptions options, FrameOptions oldOptions = null, object injectObj = null)
        {
            var cefOptions = new CefOptions
            {
                ContentPath   = options.ContentPath,
                InjectObjName = injectObj == null ? null : GlobalConfig.AppOptions.InjectObjName,
                GetInjectObj  = () => injectObj
            };

            if (oldOptions == null)
            {
                cefOptions.JsDialogHandler = new CefJsDialogHandler(frame);
            }

            //todo cef加载完成后,handler不可改
            //因draggable是可改选项,所以要加上这个判断,以减少创建CefDragHandler实例数,满足此条件代表之前的窗口没有设置过
            if ((oldOptions == null || !oldOptions.Draggable) && options.Draggable)
            {
                cefOptions.DragHandler = new CefDragHandler(frame);
            }

            if (options.IsMain == true)
            {
                cefOptions.KeyboardHandler = new CefKeyboardHandler();
            }

            return(cefOptions);
        }
コード例 #2
0
        public static void LoadBrowser(IWebBrowser browser, CefOptions cefOptions)
        {
            if (browser != null)
            {
                if (cefOptions.LifeSpanHandler != null)
                {
                    browser.LifeSpanHandler = cefOptions.LifeSpanHandler;
                }

                if (cefOptions.MenuHandler != null)
                {
                    browser.MenuHandler = cefOptions.MenuHandler;
                }

                if (cefOptions.DragHandler != null)
                {
                    browser.DragHandler = cefOptions.DragHandler;
                }

                if (cefOptions.JsDialogHandler != null)
                {
                    browser.JsDialogHandler = cefOptions.JsDialogHandler;
                }

                if (cefOptions.KeyboardHandler != null)
                {
                    browser.KeyboardHandler = cefOptions.KeyboardHandler;
                }

                browser.RequestHandler = new DefaultRequestHandler();
                //browser.ConsoleMessage += Browser_ConsoleMessage;
                if (!string.IsNullOrEmpty(cefOptions.InjectObjName))
                {
                    var injectObj = cefOptions.GetInjectObj();
                    if (injectObj == null)
                    {
                        //AppLogger.Instance.Log("inject object is null");
                    }
                    else
                    {
                        browser.RegisterJsObject(cefOptions.InjectObjName, injectObj);
                    }
                }
            }
        }
コード例 #3
0
        private void LoadCEF(CefOptions cefOptions, object extendParam = null)
        {
            var _contentPath = string.Empty;

            if (!string.IsNullOrEmpty(cefOptions.ContentPath) && cefOptions.ContentPath.StartsWith("chrome://"))
            {
                _contentPath = cefOptions.ContentPath;
            }
            else
            {
                _contentPath = cefOptions.IsRelativeContent ? Path.Combine(cefOptions.BasePath, cefOptions.ContentPath) : cefOptions.ContentPath;
            }

            if (!cefOptions.IsRelativeContent && !Uri.IsWellFormedUriString(_contentPath, UriKind.RelativeOrAbsolute))
            {
                throw new ArgumentException("invalid content path found", _contentPath);
            }

            var checkPath = _contentPath;
            var param     = string.Empty;
            var pathArray = _contentPath.Split('?');

            if (pathArray.Length > 1)
            {
                checkPath = pathArray[0];
                param     = $"?{pathArray[1]}";
            }

            //如果本地存在文件,需要将本地路径中的特殊字符转掉,通常发生在debug环境下
            if (File.Exists(checkPath))
            {
                _contentPath = checkPath.ToAppPath() + param;
            }

            if (this._localBrowser == null)
            {
                this.InitLocalBrowser(_contentPath, extendParam);
                CefManager.LoadBrowser(this._localBrowser, cefOptions);
            }
            else if (this._localBrowser.Address != _contentPath)
            {
                this._localBrowser.Load(_contentPath);
            }
        }