Ejemplo n.º 1
0
        private WebView CreateNewBrowser()
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var browser = new WebView {
                VerticalAlignment   = System.Windows.VerticalAlignment.Stretch,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                IsJavaScriptEnabled = true,
                IsIndexedDBEnabled  = true,
                IsPrivateNetworkClientServerCapabilityEnabled = true,
                IsScriptNotifyAllowed = true,
            };

            browser.NavigationStarting  += OnBrowserAddressChanged;
            browser.ContentLoading      += OnBrowserLoadingStateChanged;
            browser.DOMContentLoaded    += OnBrowserTitleChanged;
            browser.NavigationCompleted += OnNavigationCompleted;
            browser.NewWindowRequested  += OnNewWindowRequested;
            browser.ScriptNotify        += OnScriptNotify;

            if (!string.IsNullOrEmpty(InitialUrl))
            {
                browser.Navigate(new Uri(InitialUrl));
            }

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

            return(browser);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void CloseTab(int index)
        {
            if (index < 0 || index > _tabs.Count - 1)
            {
                return;
            }

            if (CurrentTab >= index)
            {
                CurrentTab = CurrentTab - 1;
            }

            if (_tabs.Count == 2)
            {
                CurrentTab = 0;
            }

            if (CurrentTab < 0)
            {
                CurrentTab = 0;
            }

            var wvtc = _tabs[index] as ChromiumWebBrowser;

            _tabs.RemoveAt(index);
            TabDetails.RemoveAt(index);
            wvtc?.Dispose();

            CurrentBrowser = _tabs[CurrentTab] as ChromiumWebBrowser;
            _host.Child    = CurrentBrowser;

            if (!(TabDetails[CurrentTab] is TabDetails tabDetails))
            {
                return;
            }
            SendPropertyChange(@"title", tabDetails.Title, CurrentTab);
            SendPropertyChange(@"url", tabDetails.Address, CurrentTab);
            SendPropertyChange(@"isLoading", tabDetails.IsLoading, CurrentTab);
            SendPropertyChange(@"canGoForward", tabDetails.CanGoForward, CurrentTab);
            SendPropertyChange(@"canGoBack", tabDetails.CanGoBack, CurrentTab);
        }