public ExtendedWebBrowser New(bool navigateHome)
        {
            // Create a new tab page
            TabPageEx page = new TabPageEx();
            // Create a new browser control
            BrowserControl browserControl = new BrowserControl();

            // Set the page as the Tag of the browser control, and vice-versa, this will come in handy later
            browserControl.Tag            = page;
            page.Tag                      = browserControl;
            page.Text                     = Properties.Resources.DefaultBrowserTitle;
            browserControl.ShowAddressBar = showAddressBar;
            // Dock the browser control
            browserControl.Dock = DockStyle.Fill;
            // Add the browser control to the tab page
            page.Controls.Add(browserControl);
            if (navigateHome)
            {
                // Navigate to the home page
                browserControl.WebBrowser.GoHome();
            }
            // Wire some events
            browserControl.WebBrowser.StatusTextChanged    += new EventHandler(WebBrowser_StatusTextChanged);
            browserControl.WebBrowser.DocumentTitleChanged += new EventHandler(WebBrowser_DocumentTitleChanged);
            browserControl.WebBrowser.CanGoBackChanged     += new EventHandler(WebBrowser_CanGoBackChanged);
            browserControl.WebBrowser.CanGoForwardChanged  += new EventHandler(WebBrowser_CanGoForwardChanged);
            browserControl.WebBrowser.Navigated            += new WebBrowserNavigatedEventHandler(WebBrowser_Navigated);
            browserControl.WebBrowser.DocumentCompleted    += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
            browserControl.WebBrowser.Quit += new EventHandler(WebBrowser_Quit);
            // Add the new page to the tab control
            _tabControl.TabPages.Add(page);
            _tabControl.SelectedTab = page;
            _tabControl.Visible     = true;
            return(browserControl.WebBrowser);
        }
        void WebBrowser_StatusTextChanged(object sender, EventArgs e)
        {
            // First, see if the active page is calling, or another page
            ExtendedWebBrowser ewb = sender as ExtendedWebBrowser;

            // Return if we got nothing (shouldn't happen)
            if (ewb == null)
            {
                return;
            }

            // This is a little nasty. The Extended Web Browser is nested in
            // a panel, wich is nested in the browser control
            BrowserControl bc = BrowserControlFromBrowser(ewb);

            // The Tag of the BrowserControl should point to the TabPageEx
            TabPageEx page = bc.Tag as TabPageEx;

            // If not, return
            if (page == null)
            {
                return;
            }

            // See if 'page' is the active page
            if (this._tabControl.SelectedTab == page)
            {
                // Yep, send the event that updates the status bar text
                OnStatusTextChanged(new TextChangedEventArgs(ewb.StatusText));
            }
        }
        void WebBrowser_Quit(object sender, EventArgs e)
        {
            // This event is launched when window.close() is called from script
            ExtendedWebBrowser brw = sender as ExtendedWebBrowser;

            if (brw == null)
            {
                return;
            }
            // See which page it was on...
            BrowserControl bc = BrowserControlFromBrowser(brw);

            if (bc == null)
            {
                return;
            }

            TabPageEx page = bc.Tag as TabPageEx;

            if (page == null)
            {
                return;
            }

            // We got a page, remove & dispose it.
            _tabControl.TabPages.Remove(page);
            page.Dispose();

            if (_tabControl.TabPages.Count == 0)
            {
                _tabControl.Visible = false;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Navigate to the typed address
        /// </summary>
        private void Navigate()
        {
            if (blockedSite(this.addressTextBox.Text))
            {
                //hide page
                _browser.Visible = false;

                BrowserControl bc = WindowManager.BrowserControlFromBrowser(_browser);
                // If we got null, return
                if (bc == null)
                {
                    return;
                }

                // The Tag of the BrowserControl should point to the TabPage
                TabPage page = bc.Tag as TabPage;
                // If not, return
                if (page == null)
                {
                    return;
                }

                page.Text        = "Site Blocked";
                page.ToolTipText = "Site Blocked";

                //display block
                lblLoading.Text = "Site Blocked";

                string[] content = new string[] { this.addressTextBox.Text };

                if (mf == null)
                {
                    mf = GetMainFormFromControl(this);
                }

                //log blocked site
                mf.log(MainForm.foundBlockedSitesPath, Encryption.Encrypt(content));

                //refresh loaded found blocked sites
                mf.loadFoundBlockedSites(MainForm.foundBlockedSitesPath);
            }
            else
            {
                lblLoading.Text = "Loading...";

                this.WebBrowser.Navigate(this.addressTextBox.Text);
            }

            //reset loggedInTime since there is activity
            if (mf == null)
            {
                mf = GetMainFormFromControl(this);
            }
            mf.loggedInTime = 0;
        }
Beispiel #5
0
        private void displayPage()
        {
            if (mf == null)
            {
                mf = GetMainFormFromControl(this);
            }
            //check content of document before displaying
            if (mf.LoggedIn || checkContents())
            {
                //display page
                _browser.Visible = true;
            }
            else
            {
                //hide page
                _browser.Visible = false;

                BrowserControl bc = WindowManager.BrowserControlFromBrowser(_browser);
                // If we got null, return
                if (bc == null)
                {
                    return;
                }

                // The Tag of the BrowserControl should point to the TabPage
                TabPage page = bc.Tag as TabPage;
                // If not, return
                if (page == null)
                {
                    return;
                }

                page.Text        = "Page Blocked";
                page.ToolTipText = "Page Blocked";

                //display block
                lblLoading.Text = "Page Blocked";

                ArrayList content = new ArrayList();

                //log blocked terms
                foreach (string term in foundBlockedTerms)
                {
                    content.Add(term.Trim());
                }

                mf.log(MainForm.foundBlockedTermsPath, Encryption.Encrypt((string[])content.ToArray(typeof(string))));

                //refresh loaded found blocked terms
                mf.loadFoundBlockedTerms(MainForm.foundBlockedTermsPath);
            }
        }
        void WebBrowser_DocumentTitleChanged(object sender, EventArgs e)
        {
            // Update the title of the tab page of the control.
            ExtendedWebBrowser ewb = sender as ExtendedWebBrowser;

            // Return if we got nothing (shouldn't happen)
            if (ewb == null)
            {
                return;
            }

            // This is a little nasty. The Extended Web Browser is nested in
            // a panel, wich is nested in the browser control
            BrowserControl bc = BrowserControlFromBrowser(ewb);

            // If we got null, return
            if (bc == null)
            {
                return;
            }

            // The Tag of the BrowserControl should point to the TabPageEx
            TabPageEx page = bc.Tag as TabPageEx;

            // If not, return
            if (page == null)
            {
                return;
            }

            // Update the tabPage
            // Keep it user-friendly, don't do those awful long web page titles
            // in tabs and make sure the title is never empty
            string documentTitle = ewb.DocumentTitle;

            if (string.IsNullOrEmpty(documentTitle))
            {
                documentTitle = Properties.Resources.DefaultBrowserTitle;
            }
            else if (documentTitle.Length > 30)
            {
                documentTitle = documentTitle.Substring(0, 30) + "...";
            }
            page.Text = documentTitle;
            // Set the full title as a tooltip
            page.ToolTipText = ewb.DocumentTitle;
        }