コード例 #1
0
        /**
         *  初始化浏览器页面对象。
         */
        public void InitBrowser(ChromiumWebBrowser Browser)
        {
            // 浏览器菜单对象
            // 实现上下文菜单功能(应该是右键出来的上下文菜单)
            Browser.MenuHandler = new MenuHandler();
            // this 指代 MainWindow 对象
            LifeSpanHandler lifeSpanHandler = new LifeSpanHandler(this);

            // 浏览器生命周期处理
            Browser.LifeSpanHandler = lifeSpanHandler;
            // 开启新的页面的生命周期
            lifeSpanHandler.OpenInNewTab += Life_OpenInNewTab;
            Browser.RequestHandler        = new TangRequestHandler(this);

            Browser.PreviewTextInput += (o, e) =>
            {
                foreach (var character in e.Text)
                {
                    // 根据浏览器对象获取浏览器实例、
                    // 根据实例找到当前浏览器主机对象发送按键事件
                    // WM.CHAR,当一个WM_KEYDOWN消息被TranslateMessage函数翻译后,
                    // WM_CHAR消息会被发布到键盘焦点的窗口中。WM_CHAR消息包含了被按下的键的字符代码。
                    Browser.GetBrowser().GetHost().SendKeyEvent((int)WM.CHAR, (int)character, 0);
                }
                e.Handled = true;
            };
        }
コード例 #2
0
ファイル: CefView.cs プロジェクト: rozd/WebViewANE
        private ChromiumWebBrowser CreateNewBrowser()
        {
            var browser = new ChromiumWebBrowser(InitialUrl?.Url)
            {
                Dock = DockStyle.Fill
            };

            browser.JavascriptObjectRepository.Register("webViewANE", new BoundObject(Context), true,
                                                        BindingOptions.DefaultBinder);

            var dh = new DownloadHandler(DownloadPath);

            dh.OnDownloadUpdatedFired += OnDownloadUpdated;
            dh.OnBeforeDownloadFired  += OnBeforeDownload;

            KeyboardHandler = new KeyboardHandler(Context);
            KeyboardHandler.OnKeyEventFired += OnKeyEvent;

            if (EnableDownloads)
            {
                browser.DownloadHandler = dh;
            }

            browser.KeyboardHandler = KeyboardHandler;

            var sh = new LifeSpanHandler(PopupBehaviour, PopupDimensions);

            sh.OnPermissionPopup                += OnPermissionPopup;
            sh.OnPopupBlock                     += OnPopupBlock;
            browser.LifeSpanHandler              = sh;
            browser.FrameLoadEnd                += OnFrameLoaded;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.LoadingStateChanged         += OnBrowserLoadingStateChanged;
            browser.LoadError                   += OnLoadError;
            browser.IsBrowserInitializedChanged += OnBrowserInitialized;
            browser.StatusMessage               += OnStatusMessage;
            var displayHandler = new DisplayHandler();

            displayHandler.OnLoadingProgressChangeFired += OnLoadingProgressChange;
            browser.DisplayHandler = displayHandler;

            if (!ContextMenuEnabled)
            {
                browser.MenuHandler = new MenuHandler();
            }

            var rh = new CefRequestHandler(WhiteList, BlackList);

            rh.OnUrlBlockedFired += OnUrlBlocked;

            browser.RequestHandler = rh;
            _tabs.Add(browser);
            TabDetails.Add(new TabDetails());

            return(browser);
        }
コード例 #3
0
ファイル: BrowserClient.cs プロジェクト: xmcy0011/NanUI
        internal BrowserClient(IChromiumWebBrowser browser)
        {
            this.browser = browser;
            this.lifeSpanHandler = new LifeSpanHandler(this);
            this.requestHandler = new RequestHandler(this);

            this.GetLifeSpanHandler += (s, e) => e.SetReturnValue(lifeSpanHandler);
            this.GetRequestHandler += (s, e) => e.SetReturnValue(requestHandler);
        }
コード例 #4
0
        private void InitializeControl()
        {
            var contextMenuHandler = new ContextMenuHandler();
            var dialogHandler      = new DialogHandler();
            var displayHandler     = new DisplayHandler();
            var downloadLogger     = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
            var downloadHandler    = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings);
            var keyboardHandler    = new KeyboardHandler();
            var lifeSpanHandler    = new LifeSpanHandler();
            var requestFilter      = new RequestFilter();
            var requestLogger      = logger.CloneFor($"{nameof(RequestHandler)} #{Id}");
            var resourceHandler    = new ResourceHandler(appConfig, requestFilter, logger, settings, WindowSettings, text);
            var requestHandler     = new RequestHandler(appConfig, requestFilter, requestLogger, resourceHandler, settings, WindowSettings, text);

            Icon = new BrowserIconResource();

            dialogHandler.DialogRequested  += DialogHandler_DialogRequested;
            displayHandler.FaviconChanged  += DisplayHandler_FaviconChanged;
            displayHandler.ProgressChanged += DisplayHandler_ProgressChanged;
            downloadHandler.ConfigurationDownloadRequested += DownloadHandler_ConfigurationDownloadRequested;
            downloadHandler.DownloadUpdated           += DownloadHandler_DownloadUpdated;
            keyboardHandler.FindRequested             += KeyboardHandler_FindRequested;
            keyboardHandler.HomeNavigationRequested   += HomeNavigationRequested;
            keyboardHandler.ReloadRequested           += ReloadRequested;
            keyboardHandler.ZoomInRequested           += ZoomInRequested;
            keyboardHandler.ZoomOutRequested          += ZoomOutRequested;
            keyboardHandler.ZoomResetRequested        += ZoomResetRequested;
            lifeSpanHandler.PopupRequested            += LifeSpanHandler_PopupRequested;
            resourceHandler.SessionIdentifierDetected += (id) => SessionIdentifierDetected?.Invoke(id);
            requestHandler.QuitUrlVisited             += RequestHandler_QuitUrlVisited;
            requestHandler.RequestBlocked             += RequestHandler_RequestBlocked;

            InitializeRequestFilter(requestFilter);

            control = new BrowserControl(
                contextMenuHandler,
                dialogHandler,
                displayHandler,
                downloadHandler,
                keyboardHandler,
                lifeSpanHandler,
                requestHandler,
                startUrl);
            control.AddressChanged      += Control_AddressChanged;
            control.LoadFailed          += Control_LoadFailed;
            control.LoadingStateChanged += Control_LoadingStateChanged;
            control.TitleChanged        += Control_TitleChanged;

            control.Initialize();
            logger.Debug("Initialized browser control.");
        }
コード例 #5
0
        public FormMain()
        {
            if (!IsAgreed())
            {
                Environment.Exit(0);
            }

            InitializeComponent();

            var settings = new CefSettings();
            var current  = AppDomain.CurrentDomain.BaseDirectory;
            var flash    = $@"{current}plugins\pepper flash\23.0.0.207\pepflashplayer.dll";

            if (File.Exists(flash))
            {
                settings.CefCommandLineArgs.Add("ppapi-flash-path", flash);
            }

            if (YoponSetting.I.HideSandboxError)
            {
                settings.BrowserSubprocessPath =
                    typeof(Sandbox.HideAlert.Program).Assembly.Location;
            }

            settings.CachePath = $@"{current}data";

            Cef.Initialize(settings);

            CEFEngine = new ChromiumWebBrowser("http://pigg.ameba.jp/");

            var lifeSpanHandler = new LifeSpanHandler();

            lifeSpanHandler.PopupRequest +=
                x => Process.Start(x);

            CEFEngine.LifeSpanHandler        = lifeSpanHandler;
            CEFEngine.ResourceHandlerFactory = new PiggResourceHandlerFactory();
            CEFEngine.BrowserSettings        = BrowserSettings;
            CEFEngine.Dock = DockStyle.Fill;
            panel1.Controls.Add(CEFEngine);

            if (YoponSetting.I.IsDebugMode)
            {
                DisplayMenuDebug();
            }
        }
コード例 #6
0
        private void InitializeControl()
        {
            var contextMenuHandler = new ContextMenuHandler();
            var displayHandler     = new DisplayHandler();
            var downloadLogger     = logger.CloneFor($"{nameof(DownloadHandler)} {Id}");
            var downloadHandler    = new DownloadHandler(appConfig, settings, downloadLogger);
            var keyboardHandler    = new KeyboardHandler();
            var lifeSpanHandler    = new LifeSpanHandler();
            var requestFilter      = new RequestFilter();
            var requestLogger      = logger.CloneFor($"{nameof(RequestHandler)} {Id}");
            var requestHandler     = new RequestHandler(appConfig, settings.Filter, requestFilter, requestLogger, text);

            displayHandler.FaviconChanged  += DisplayHandler_FaviconChanged;
            displayHandler.ProgressChanged += DisplayHandler_ProgressChanged;
            downloadHandler.ConfigurationDownloadRequested += DownloadHandler_ConfigurationDownloadRequested;
            keyboardHandler.ReloadRequested    += ReloadRequested;
            keyboardHandler.ZoomInRequested    += ZoomInRequested;
            keyboardHandler.ZoomOutRequested   += ZoomOutRequested;
            keyboardHandler.ZoomResetRequested += ZoomResetRequested;
            lifeSpanHandler.PopupRequested     += LifeSpanHandler_PopupRequested;
            requestHandler.RequestBlocked      += RequestHandler_RequestBlocked;

            if (settings.Filter.ProcessContentRequests || settings.Filter.ProcessMainRequests)
            {
                var factory = new RuleFactory();

                foreach (var settings in settings.Filter.Rules)
                {
                    var rule = factory.CreateRule(settings.Type);

                    rule.Initialize(settings);
                    requestFilter.Load(rule);
                }

                logger.Debug($"Initialized request filter with {settings.Filter.Rules.Count} rule(s).");
            }

            control = new BrowserControl(contextMenuHandler, displayHandler, downloadHandler, keyboardHandler, lifeSpanHandler, requestHandler, url);
            control.AddressChanged      += Control_AddressChanged;
            control.LoadingStateChanged += Control_LoadingStateChanged;
            control.TitleChanged        += Control_TitleChanged;

            control.Initialize();
            logger.Debug("Initialized browser control.");
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client"/> class.
        /// </summary>
        public Client()
            : base()
        {
            LifeSpanHandler = new LifeSpanHandler();
            DisplayHandler  = new DisplayHandler();
            LoadHandler     = new LoadHandler();
            RequestHandler  = new RequestHandler();
            KeyboardHandler = new KeyboardHandler();

            // set events
            LifeSpanHandler.BrowserCreated += (sender, e) => {
                if (BrowserCreated != null)
                {
                    BrowserCreated(this, e);
                }
            };

            // native calls
            V8NativeBrowserHandler = new V8NativeBrowserHandler(NativeFunctionAttribute.GetMethods <Client, Func <string, object> >(this));
        }
コード例 #8
0
        internal void Initialize()
        {
            var contextMenuHandler = new ContextMenuHandler();
            var displayHandler     = new DisplayHandler();
            var downloadLogger     = logger.CloneFor($"{nameof(DownloadHandler)} {Id}");
            var downloadHandler    = new DownloadHandler(appConfig, settings, downloadLogger);
            var keyboardHandler    = new KeyboardHandler();
            var lifeSpanHandler    = new LifeSpanHandler();
            var requestHandler     = new RequestHandler(appConfig);

            displayHandler.FaviconChanged  += DisplayHandler_FaviconChanged;
            displayHandler.ProgressChanged += DisplayHandler_ProgressChanged;
            downloadHandler.ConfigurationDownloadRequested += DownloadHandler_ConfigurationDownloadRequested;
            keyboardHandler.ReloadRequested    += ReloadRequested;
            keyboardHandler.ZoomInRequested    += ZoomInRequested;
            keyboardHandler.ZoomOutRequested   += ZoomOutRequested;
            keyboardHandler.ZoomResetRequested += ZoomResetRequested;
            lifeSpanHandler.PopupRequested     += LifeSpanHandler_PopupRequested;

            control = new BrowserControl(contextMenuHandler, displayHandler, downloadHandler, keyboardHandler, lifeSpanHandler, requestHandler, url);
            control.AddressChanged      += Control_AddressChanged;
            control.LoadingStateChanged += Control_LoadingStateChanged;
            control.TitleChanged        += Control_TitleChanged;
            control.Initialize();

            logger.Debug("Initialized browser control.");

            window                 = uiFactory.CreateBrowserWindow(control, settings, isMainInstance);
            window.Closing        += () => Terminated?.Invoke(Id);
            window.AddressChanged += Window_AddressChanged;
            window.BackwardNavigationRequested += Window_BackwardNavigationRequested;
            window.DeveloperConsoleRequested   += Window_DeveloperConsoleRequested;
            window.ForwardNavigationRequested  += Window_ForwardNavigationRequested;
            window.ReloadRequested             += ReloadRequested;
            window.ZoomInRequested             += ZoomInRequested;
            window.ZoomOutRequested            += ZoomOutRequested;
            window.ZoomResetRequested          += ZoomResetRequested;
            window.UpdateZoomLevel(CalculateZoomPercentage());

            logger.Debug("Initialized browser window.");
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client"/> class.
        /// </summary>
        public Client()
            : base()
        {
            LifeSpanHandler = new LifeSpanHandler();
            DisplayHandler  = new DisplayHandler();
            LoadHandler     = new LoadHandler();
            RequestHandler  = new RequestHandler();
            KeyboardHandler = new KeyboardHandler();

            // set events
            LifeSpanHandler.BrowserCreated += (sender, e) =>
            {
                if (BrowserCreated != null)
                {
                    BrowserCreated(this, e);
                }
            };

            // native calls
            NativeMessageHandler = new NativeMessageHandler();
        }
コード例 #10
0
ファイル: MainWindow.cs プロジェクト: inspera/Chrominimum
        private void InitializeBrowser()
        {
            var requestLogger   = logger.CloneFor($"{nameof(RequestHandler)} #{Id}");
            var requestFilter   = new RequestFilter();
            var resourceHandler = new ResourceHandler(settings, requestFilter, logger, text);
            var requestHandler  = new RequestHandler(requestLogger, settings, requestFilter, resourceHandler, text);

            requestHandler.QuitUrlVisited += RequestHandler_QuitUrlVisited;

            var lifeSpanHandler = new LifeSpanHandler();

            lifeSpanHandler.PopupRequested += LifeSpanHandler_PopupRequested;

            var downloadLogger  = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
            var downloadHandler = new DownloadHandler(settings, downloadLogger);

            downloadHandler.DownloadUpdated += DownloadHandler_DownloadUpdated;

            var keyboardHandler = new KeyboardHandler();

            keyboardHandler.ReloadRequested += ReloadRequested;

            InitializeRequestFilter(requestFilter);

            browser = new ChromiumWebBrowser(startUrl)
            {
                Dock = DockStyle.Fill
            };

            browser.DisplayHandler  = new DisplayHandler(this);
            browser.KeyboardHandler = keyboardHandler;
            browser.LifeSpanHandler = lifeSpanHandler;
            browser.LoadError      += Browser_LoadError;
            browser.MenuHandler     = new ContextMenuHandler();
            browser.TitleChanged   += Browser_TitleChanged;
            browser.RequestHandler  = requestHandler;
            browser.DownloadHandler = downloadHandler;

            Controls.Add(browser);
        }
コード例 #11
0
        public void InitializeCefSharp()
        {
            var settings = new CefSettings();
            var current  = AppDomain.CurrentDomain.BaseDirectory;
            var flash    = $@"{current}plugins\pepper flash\23.0.0.207\pepflashplayer.dll";

            if (File.Exists(flash))
            {
                settings.CefCommandLineArgs.Add("ppapi-flash-path", flash);
            }
            settings.CachePath = $@"{current}data";
            Cef.Initialize(settings);
            CEFEngine = new ChromiumWebBrowser("http://www.nyafuri.com/TypeShoot/jp.html");
            var lifeSpanHandler = new LifeSpanHandler();

            lifeSpanHandler.PopupRequest    += x => Process.Start(x);
            CEFEngine.LifeSpanHandler        = lifeSpanHandler;
            CEFEngine.ResourceHandlerFactory = new HttpResourceHandlerFactory();
            CEFEngine.BrowserSettings        = BrowserSettings;
            CEFEngine.Dock = DockStyle.Fill;
            CefSharpPanel.Controls.Add(CEFEngine);
        }
コード例 #12
0
 public void Initialize()
 {
     sut = new LifeSpanHandler();
 }
コード例 #13
0
 protected override bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture)
 {
     return(LifeSpanHandler.HandleLinkClick(browserControl, targetDisposition, targetUrl));
 }
コード例 #14
0
 public WebClient(WebBrowser core)
 {
     _lifeSpanHandler = new LifeSpanHandler(core);
     _displayHandler  = new DisplayHandler(core);
     _loadHandler     = new LoadHandler(core);
 }
コード例 #15
0
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled,
                                     ChromiumWebBrowser browser = null, IWindowInfo windoInfo = null)
        {
            InitializeComponent();
            initialURL = url;


            //add an if statement to initialize the settings once. else the app is going to crash
            if (CefSharp.Cef.IsInitialized == false)
            {
                string appdata   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string cachePath = Path.Combine(appdata, "FilteredChromeBrowser", "cache");
                if (!Directory.Exists(cachePath))
                {
                    Directory.CreateDirectory(cachePath);
                }

                CefSettings Settings = new CefSettings();
                Settings.CachePath = cachePath;  //always set the cachePath, else this wont work
                Settings.CefCommandLineArgs.Add("no-proxy-server", "1");


                CefSharp.Cef.Initialize(Settings);
            }

            if (browser == null || windoInfo == null)
            {
                browser = new ChromiumWebBrowser("about:blank")
                {
                    Dock = DockStyle.Fill
                };

                CefSharpSettings.LegacyJavascriptBindingEnabled = true;
                browser.RegisterJsObject("print", new EmptyObject());
                this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;
            }
            else
            {
                var rect = browserPanel.ClientRectangle;
                windoInfo.SetAsChild(browserPanel.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom);
            }

            browserPanel.Controls.Add(browser);
            Browser = browser;

            browser.MenuHandler = new MenuHandler(new Action(() => {
                this.InvokeOnUiThreadIfRequired(() => { ToggleBottomToolStrip(); });
            }));
            myPageNavigationManager = new WinFormsRequestHandler(openNewTab);
            browser.RequestHandler  = myPageNavigationManager;
            browser.JsDialogHandler = new JsDialogHandler();

            var dm = new DownloadHandler(CefSharp.WinForms.Example.Properties.Settings.Default.saveFolder);

            dm.OnDownloadUpdatedFired += Dm_OnDownloadUpdatedFired;
            browser.DownloadHandler    = dm;


            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }
            else
            {
                //When MultiThreadedMessageLoop is disabled we don't need the
                //CefSharp focus handler implementation.
                browser.FocusHandler = null;
            }

            //Handling DevTools docked inside the same window requires
            //an instance of the LifeSpanHandler all the window events,
            //e.g. creation, resize, moving, closing etc.
            myLifeSpanHandler       = new LifeSpanHandler(openPopupsAsTabs: true);
            browser.LifeSpanHandler = myLifeSpanHandler;


            browser.LoadingStateChanged         += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage              += OnBrowserConsoleMessage;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.StatusMessage               += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError += OnLoadError;

            browser.FrameLoadEnd += Browser_FrameLoadEnd;

            browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged;



            browser.RenderProcessMessageHandler = new RenderProcessMessageHandler();
            browser.DisplayHandler = new DisplayHandler();
            //browser.MouseDown += OnBrowserMouseClick;
            browser.HandleCreated += OnBrowserHandleCreated;
            //browser.ResourceHandlerFactory = new FlashResourceHandlerFactory();


            //CefExample.RegisterTestResources(browser);


            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);

            DisplayOutput(version);
        }
コード例 #16
0
 public LifeSpanHandlerBuilder(CreatePopupChromiumHostControl chromiumHostControlCreatedDelegate)
 {
     handler = new LifeSpanHandler(chromiumHostControlCreatedDelegate);
 }
コード例 #17
0
        public BrowserTabUserControl(Action <string, int?> openNewTab, string url, bool multiThreadedMessageLoopEnabled)
        {
            InitializeComponent();

            var browser = new ChromiumWebBrowser(url)
            {
                Dock = DockStyle.Fill
            };

            browserPanel.Controls.Add(browser);

            Browser = browser;

            browser.MenuHandler     = new MenuHandler();
            browser.RequestHandler  = new WinFormsRequestHandler(openNewTab);
            browser.JsDialogHandler = new JsDialogHandler();
            browser.DownloadHandler = new DownloadHandler();
            browser.AudioHandler    = new CefSharp.Handler.AudioHandler();
            browser.FrameHandler    = new CefSharp.Handler.FrameHandler();

            if (multiThreadedMessageLoopEnabled)
            {
                browser.KeyboardHandler = new KeyboardHandler();
            }

            //The CefSharp.WinForms.Handler.LifeSpanHandler implementation
            //allows for Popups to be hosted in Controls/Tabs
            //This example also demonstrates docking DevTools in a SplitPanel
            browser.LifeSpanHandler = LifeSpanHandler
                                      .Create()
                                      .OnPopupCreated((ctrl, targetUrl) =>
            {
                //Don't try using ctrl.FindForm() here as
                //the control hasn't been attached to a parent yet.
                if (FindForm() is BrowserForm owner)
                {
                    owner.AddTab(ctrl, targetUrl);
                }
            })
                                      .OnPopupDestroyed((ctrl, popupBrowser) =>
            {
                //If we docked  DevTools (hosted it ourselves rather than the default popup)
                //Used when the BrowserTabUserControl.ShowDevToolsDocked method is called
                if (popupBrowser.MainFrame.Url.Equals("devtools://devtools/devtools_app.html"))
                {
                    //Dispose of the parent control we used to host DevTools, this will release the DevTools window handle
                    //and the ILifeSpanHandler.OnBeforeClose() will be call after.
                    ctrl.Dispose();
                }
                else
                {
                    //If browser is disposed or the handle has been released then we don't
                    //need to remove the tab in this example. The user likely used the
                    // File -> Close Tab menu option which also calls BrowserForm.RemoveTab
                    if (!ctrl.IsDisposed && ctrl.IsHandleCreated)
                    {
                        if (ctrl.FindForm() is BrowserForm owner)
                        {
                            var windowHandle = popupBrowser.GetHost().GetWindowHandle();

                            owner.RemoveTab(windowHandle);
                        }

                        ctrl.Dispose();
                    }
                }
            })
                                      .Build();

            browser.LoadingStateChanged         += OnBrowserLoadingStateChanged;
            browser.ConsoleMessage              += OnBrowserConsoleMessage;
            browser.TitleChanged                += OnBrowserTitleChanged;
            browser.AddressChanged              += OnBrowserAddressChanged;
            browser.StatusMessage               += OnBrowserStatusMessage;
            browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
            browser.LoadError += OnLoadError;

#if NETCOREAPP
            browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), options: BindingOptions.DefaultBinder);
#else
            browser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync: false, options: BindingOptions.DefaultBinder);
            browser.JavascriptObjectRepository.Register("boundAsync", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
#endif

            //If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet
            //bound, then ResolveObject will be called, you can then register it
            browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
            {
                var repo = e.ObjectRepository;
                if (e.ObjectName == "boundAsync2")
                {
#if NETCOREAPP
                    repo.Register("boundAsync2", new AsyncBoundObject(), options: BindingOptions.DefaultBinder);
#else
                    repo.Register("boundAsync2", new AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
#endif
                }
            };

            browser.RenderProcessMessageHandler = new RenderProcessMessageHandler();
            browser.DisplayHandler = new DisplayHandler();
            //browser.MouseDown += OnBrowserMouseClick;
            browser.HandleCreated += OnBrowserHandleCreated;
            //browser.ResourceHandlerFactory = new FlashResourceHandlerFactory();
            this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;

            var eventObject = new ScriptedMethodsBoundObject();
            eventObject.EventArrived += OnJavascriptEventArrived;
            // Use the default of camelCaseJavascriptNames
            // .Net methods starting with a capitol will be translated to starting with a lower case letter when called from js
#if !NETCOREAPP
            browser.JavascriptObjectRepository.Register("boundEvent", eventObject, isAsync: false, options: BindingOptions.DefaultBinder);
#endif

            CefExample.RegisterTestResources(browser);

            var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
            //Set label directly, don't use DisplayOutput as call would be a NOOP (no valid handle yet).
            outputLabel.Text = version;
        }
コード例 #18
0
 private CustomWebClient(WebBrowser core, IPopupHandler popupHandler) : base(core)
 {
     LifeSpanHandler = new LifeSpanHandler(core, popupHandler);
 }
コード例 #19
-1
ファイル: CefMainWindow.cs プロジェクト: qlprimer/HotelSys
        /// <summary>
        /// this is done just once, to globally initialize CefSharp/CEF
        /// </summary>
        private void InitBrowser()
        {
            CefSettings settings = new CefSettings();

            settings.Locale                = "zh_CN";
            settings.CachePath             = System.IO.Directory.GetCurrentDirectory() + @"/BrowserCache";
            settings.AcceptLanguageList    = "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3";
            settings.LocalesDirPath        = System.IO.Directory.GetCurrentDirectory() + @"/localeDir";
            settings.LogFile               = System.IO.Directory.GetCurrentDirectory() + @"/LogData";
            settings.PersistSessionCookies = true;
            settings.UserDataPath          = System.IO.Directory.GetCurrentDirectory() + @"/UserData";
            settings.UserAgent             = UserAgent;

            settings.IgnoreCertificateErrors = true;



            Cef.Initialize(settings);

            dHandler = new DownloadHandler(this);
            lHandler = new LifeSpanHandler(this);
            mHandler = new ContextMenuHandler(this);
            kHandler = new KeyboardHandler(this);
            rHandler = new RequestHandler(this);



            host = new HostHandler(this);

            AddNewBrowser(CefFaTabStripItem, HomepageURL);
        }