Пример #1
0
        internal static frmWebBrowser Create(string caption)
        {
            int?windowNo = Numerator.NextNumber;

            if (!windowNo.HasValue)
            {
                _instanceCnt++;
                windowNo = _instanceCnt;
            }
            frmWebBrowser frm        = new frmWebBrowser();
            string        tmpCaption = String.Format("WebBrowser {0}", windowNo);

            if (!String.IsNullOrEmpty(caption))
            {
                tmpCaption = caption;
            }

            frm.Text     = tmpCaption;
            frm.TabText  = tmpCaption;
            frm.WindowNo = windowNo;

            return(frm);
        }
Пример #2
0
        private void OnStartNewWindow(object sender, BrowserExtendedNavigatingEventArgs e)
        {
            // Here we do the pop-up blocker work

            // Note that in Windows 2000 or lower this event will fire, but the
            // event arguments will not contain any useful information
            // for blocking pop-ups.

            // There are 4 filter levels.
            // None: Allow all pop-ups
            // Low: Allow pop-ups from secure sites
            // Medium: Block most pop-ups
            // High: Block all pop-ups (Use Ctrl to override)

            // We need the instance of the main form, because this holds the instance
            // to the WindowManager.

            PopupBlockerFilterLevel lvl = PopupBlockerFilterLevel.Medium;

            if (ConfigHelper.Current != null || ConfigHelper.Current.GeneralOptions != null)
            {
                lvl = ConfigHelper.Current.GeneralOptions.WebBrowser_PopupBlockerFilterLevel;
            }


            // Allow a popup when there is no information available or when the Ctrl key is pressed
            bool allowPopup = (e.NavigationContext == UrlContext.None) || ((e.NavigationContext & UrlContext.OverrideKey) == UrlContext.OverrideKey);

            if (!allowPopup)
            {
                // Give None, Low & Medium still a chance.
                switch (lvl)
                {
                case PopupBlockerFilterLevel.None:
                    allowPopup = true;
                    break;

                case PopupBlockerFilterLevel.Low:
                    // See if this is a secure site
                    if (this.browser.EncryptionLevel != WebBrowserEncryptionLevel.Insecure)
                    {
                        allowPopup = true;
                    }
                    else
                    {
                        // Not a secure site, handle this like the medium filter
                        goto case PopupBlockerFilterLevel.Medium;
                    }
                    break;

                case PopupBlockerFilterLevel.Medium:
                    // This is the most dificult one.
                    // Only when the user first inited and the new window is user inited
                    if ((e.NavigationContext & UrlContext.UserFirstInited) == UrlContext.UserFirstInited && (e.NavigationContext & UrlContext.UserInited) == UrlContext.UserInited)
                    {
                        allowPopup = true;
                    }
                    break;
                }
            }

            if (allowPopup)
            {
                // Check wheter it's a HTML dialog box. If so, allow the popup but do not open a new tab
                if (!((e.NavigationContext & UrlContext.HtmlDialog) == UrlContext.HtmlDialog))
                {
                    frmWebBrowser frm = WebBrowserFactory.CreateAndBrowse(e.Frame, e.Url.ToString());
                    e.AutomationObject = frm.browser.Application;
                    WebBrowserFactory.ShowWebBrowser(frm);
                }
            }
            else
            {
                // Here you could notify the user that the pop-up was blocked
                MessageBox.Show("Popup was blocked.\r\n" + e.Url.ToString(), "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
            }
        }
Пример #3
0
        private void toolStripButton11_Click(object sender, EventArgs e)
        {
            frmWebBrowser frm = WebBrowserFactory.CreateAndBrowse();

            WebBrowserFactory.ShowWebBrowser(frm);
        }