Exemplo n.º 1
0
        public ChromiumWebBrowser AddNewBrowserTab(string url, bool focusNewTab = true, string refererUrl = null)
        {
            return((ChromiumWebBrowser)this.Invoke((Func <ChromiumWebBrowser>) delegate {
                // check if already exists
                foreach (BrowserTabStripItem tab in TabPages.Items)
                {
                    SharpTab tab2 = (SharpTab)tab.Tag;
                    if (tab2 != null && (tab2.CurURL == url))
                    {
                        TabPages.SelectedItem = tab;
                        return tab2.Browser;
                    }
                }

                BrowserTabStripItem tabStrip = new BrowserTabStripItem();
                tabStrip.Title = "New Tab";
                TabPages.Items.Insert(TabPages.Items.Count - 1, tabStrip);
                newStrip = tabStrip;

                SharpTab newTab = AddNewBrowser(newStrip, url);
                newTab.RefererURL = refererUrl;
                if (focusNewTab)
                {
                    timer1.Enabled = true;
                }
                return newTab.Browser;
            }));
        }
Exemplo n.º 2
0
 public void OpenDownloadsTab()
 {
     if (downloadsStrip != null && ((ChromiumWebBrowser)downloadsStrip.Controls[0]).Address == DownloadsURL)
     {
         TabPages.SelectedItem = downloadsStrip;
     }
     else
     {
         ChromiumWebBrowser brw = AddNewBrowserTab(DownloadsURL);
         downloadsStrip = (BrowserTabStripItem)brw.Parent;
     }
 }
Exemplo n.º 3
0
        private void OnTabsChanged(TabStripItemChangedEventArgs e)
        {
            ChromiumWebBrowser browser = null;

            try {
                browser = ((ChromiumWebBrowser)e.Item.Controls[0]);
            } catch (System.Exception ex) { }


            if (e.ChangeType == BrowserTabStripItemChangeTypes.SelectionChanged)
            {
                if (TabPages.SelectedItem == tabStripAdd)
                {
                    AddBlankTab();
                }
                else
                {
                    browser = CurBrowser;

                    SetFormURL(browser.Address);
                    SetFormTitle(browser.Tag.ConvertToString() ?? "New Tab");


                    EnableBackButton(browser.CanGoBack);
                    EnableForwardButton(browser.CanGoForward);
                }
            }

            if (e.ChangeType == BrowserTabStripItemChangeTypes.Removed)
            {
                if (e.Item == downloadsStrip)
                {
                    downloadsStrip = null;
                }
                if (browser != null)
                {
                    browser.Dispose();
                }
            }

            if (e.ChangeType == BrowserTabStripItemChangeTypes.Changed)
            {
                if (browser != null)
                {
                    if (currentFullURL != "about:blank")
                    {
                        browser.Focus();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private SharpTab AddNewBrowser(BrowserTabStripItem tabStrip, String url)
        {
            if (url == "")
            {
                url = NewTabURL;
            }
            ChromiumWebBrowser browser = new ChromiumWebBrowser(url);

            // set config
            ConfigureBrowser(browser);

            // set layout
            browser.Dock = DockStyle.Fill;
            tabStrip.Controls.Add(browser);
            browser.BringToFront();

            // add events
            browser.StatusMessage       += Browser_StatusMessage;
            browser.LoadingStateChanged += Browser_LoadingStateChanged;
            browser.TitleChanged        += Browser_TitleChanged;
            browser.LoadError           += Browser_LoadError;
            browser.AddressChanged      += Browser_URLChanged;
            browser.DownloadHandler      = dHandler;
            browser.MenuHandler          = mHandler;
            browser.LifeSpanHandler      = lHandler;
            browser.KeyboardHandler      = kHandler;
            browser.RequestHandler       = rHandler;

            // new tab obj
            SharpTab tab = new SharpTab {
                IsOpen      = true,
                Browser     = browser,
                Tab         = tabStrip,
                OrigURL     = url,
                CurURL      = url,
                Title       = "New Tab",
                DateCreated = DateTime.Now
            };

            // save tab obj in tabstrip
            tabStrip.Tag = tab;

            if (url.StartsWith(InternalURL + ":"))
            {
                browser.JavascriptObjectRepository.Register("host", host, true, BindingOptions.DefaultBinder);
            }
            return(tab);
        }
Exemplo n.º 5
0
        private void SetTabTitle(ChromiumWebBrowser browser, string text)
        {
            text = text.Trim();
            if (IsBlank(text))
            {
                text = "New Tab";
            }

            // save text
            browser.Tag = text;

            // get tab of given browser
            BrowserTabStripItem tabStrip = (BrowserTabStripItem)browser.Parent;

            tabStrip.Title = text;


            // if current tab
            if (browser == CurBrowser)
            {
                SetFormTitle(text);
            }
        }