예제 #1
0
        public void Init()
        {
            InitializeComponent();
            IsManipulationEnabled = true;
            // ReSharper disable once UseObjectOrCollectionInitializer
            _host = new WindowsFormsHost();
            _host.IsManipulationEnabled = true;

            Loaded += CefView_Loaded;
            var settings = new CefSettings {
                RemoteDebuggingPort = RemoteDebuggingPort,
                CachePath           = CachePath,
                UserAgent           = UserAgent
            };

            CefSharpSettings.ShutdownOnExit = false;

            switch (LogLevel)
            {
            case 0:
                settings.LogSeverity = LogSeverity.Default;
                break;

            case 1:
                settings.LogSeverity = LogSeverity.Verbose;
                break;

            case 2:
                settings.LogSeverity = LogSeverity.Info;
                break;

            case 3:
                settings.LogSeverity = LogSeverity.Warning;
                break;

            case 4:
                settings.LogSeverity = LogSeverity.Error;
                break;

            case 99:
                settings.LogSeverity = LogSeverity.Disable;
                break;

            default:
                settings.LogSeverity = LogSeverity.Disable;
                break;
            }
            settings.WindowlessRenderingEnabled = false;
            settings.BrowserSubprocessPath      = BrowserSubprocessPath;

            foreach (var kvp in CommandLineArgs)
            {
                settings.CefCommandLineArgs.Add(kvp.Key, kvp.Value);
            }

            Cef.EnableHighDPISupport();
            // ReSharper disable once InvertIf
            if (Cef.Initialize(settings))
            {
                Browser = new ChromiumWebBrowser(InitialUrl)
                {
                    Dock = DockStyle.Fill
                };

                Browser.RegisterAsyncJsObject("webViewANE", new BoundObject(), BindingOptions.DefaultBinder);


                // ReSharper disable once UseObjectOrCollectionInitializer
                var dh = new DownloadHandler();
                dh.OnDownloadUpdatedFired += OnDownloadUpdatedFired;
                dh.OnBeforeDownloadFired  += OnDownloadFired;

                // ReSharper disable once UseObjectOrCollectionInitializer
                var kh = new KeyboardHandler();
                kh.OnKeyEventFired += OnKeyEventFired;

                if (EnableDownloads)
                {
                    Browser.DownloadHandler = dh;
                }
                Browser.KeyboardHandler = kh;

                // ReSharper disable once UseObjectOrCollectionInitializer
                var gh = new GeolocationHandler();
                gh.OnPermissionResult     += OnPermissionResult;
                Browser.GeolocationHandler = gh;


                // ReSharper disable once UseObjectOrCollectionInitializer
                var sh = new LifeSpanHandler(PopupBehaviour, PopupDimensions);
                sh.OnPermissionPopup += OnPermissionPopup;

                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 rh = new RequestHandler(WhiteList);
                rh.OnUrlBlockedFired += OnUrlBlockedFired;

                Browser.RequestHandler = rh;

                _host.Child = Browser;

                MainGrid.Children.Add(_host);
            }
        }
예제 #2
0
        private ChromiumWebBrowser CreateNewBrowser()
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var browser = new ChromiumWebBrowser(InitialUrl)
            {
                Dock = DockStyle.Fill
            };

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

            // ReSharper disable once UseObjectOrCollectionInitializer
            var dh = new DownloadHandler();

            dh.OnDownloadUpdatedFired += OnDownloadUpdatedFired;
            dh.OnBeforeDownloadFired  += OnDownloadFired;

            // ReSharper disable once UseObjectOrCollectionInitializer
            KeyboardHandler = new KeyboardHandler(Context);
            KeyboardHandler.OnKeyEventFired += OnKeyEventFired;

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

            // ReSharper disable once UseObjectOrCollectionInitializer
            var gh = new GeolocationHandler();

            gh.OnPermissionResult     += OnPermissionResult;
            browser.GeolocationHandler = gh;


            // ReSharper disable once UseObjectOrCollectionInitializer
            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;
            browser.DisplayHandler               = new DisplayHandler();

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

            // ReSharper disable once UseObjectOrCollectionInitializer
            var rh = new RequestHandler(WhiteList, BlackList);

            rh.OnUrlBlockedFired += OnUrlBlockedFired;

            browser.RequestHandler = rh;

            _tabs.Add(browser);
            TabDetails.Add(new TabDetails());

            return(browser);
        }