Example #1
0
        public CrBrowser(MainForm form, string address)
        {
            this._form = form;

            // 初始化浏览器
            browser = new ChromiumWebBrowser(address);

            // BrowserSettings 必须在 Controls.Add 之前
            BrowserSettings browserSettings = new BrowserSettings
            {
                // FileAccessFromFileUrls 必须 Enabled
                // 不然 AJAX 请求 file:// 会显示:
                // Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
                FileAccessFromFileUrls      = CefState.Enabled,
                UniversalAccessFromFileUrls = CefState.Enabled,
                DefaultEncoding             = "UTF-8",
                BackgroundColor             = (uint)ColorTranslator.FromHtml("#21252b").ToArgb()
            };

            browserSettings.WebSecurity = CefState.Disabled; // 开启跨域请求支持
            browser.BrowserSettings     = browserSettings;

            browser.MenuHandler     = new MenuHandler(this);
            browser.LifeSpanHandler = new LifeSpanHandler();
            browser.LoadHandler     = new LoadHandler();
            browser.DragHandler     = new DragDropHandler();
            browser.RequestHandler  = new RequestHandler();

            browser.FrameLoadStart += Browser_FrameLoadStart;
            browser.FrameLoadEnd   += Browser_onFrameLoadEnd;
            browser.IsBrowserInitializedChanged += Browser_onIsBrowserInitializedChanged;

            // 向前端暴露 C# 函数
            CefSharpSettings.LegacyJavascriptBindingEnabled = true; // Need Update: https://github.com/cefsharp/CefSharp/issues/2246
            browser.RegisterAsyncJsObject("AppAction", new AppAction(_form, this));
            browser.RegisterAsyncJsObject("TaskController", new TaskControllerAction(_form, this));
            browser.RegisterAsyncJsObject("UpdateAction", new UpdateAction(_form, this));

            downloadManager = new DownloadManager(this);
        }
Example #2
0
 public CrDownloadsCallBack(DownloadManager downloadManager)
 {
     _DownloadManager = downloadManager;
 }