Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }