Esempio n. 1
0
        /// <summary>
        /// Raises the <see cref="StartNavigate"/> event
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown when BrowserExtendedNavigatingEventArgs is null</exception>
        protected void OnStartNavigate(BrowserExtendedNavigatingEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (this.StartNavigate != null)
            {
                this.StartNavigate(this, e);
            }
        }
Esempio n. 2
0
            //Implement whichever events you wish
            public void BeforeNavigate2(object pDisp, ref object URL, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
            {
                Uri urlUri = new Uri(URL.ToString());

                string tFrame = null;

                if (targetFrameName != null)
                {
                    tFrame = targetFrameName.ToString();
                }

                BrowserExtendedNavigatingEventArgs args = new BrowserExtendedNavigatingEventArgs(pDisp, urlUri, tFrame, UrlContext.None);

                _Browser.OnStartNavigate(args);

                cancel = args.Cancel;
                pDisp  = args.AutomationObject;
            }
        void _browser_StartNewWindow(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.
            MainWebForm mf = GetMainFormFromControl(sender as Control);

            if (mf == null)
            {
                return;
            }

            // 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 (SettingsHelper.Current.FilterLevel)
                {
                case PopupBlockerFilterLevel.None:
                    allowPopup = true;
                    break;

                case PopupBlockerFilterLevel.Low:
                    // See if this is a secure site
                    if (this.WebBrowser.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))
                {
                    ExtendedWebBrowser ewb = mf.WindowManager.New(false);
                    // The (in)famous application object
                    e.AutomationObject = ewb.Application;
                }
            }
            else
            {
                // Here you could notify the user that the pop-up was blocked
                e.Cancel = true;
            }
        }
Esempio n. 4
0
 // NewWindow3 event, used on Windows XP SP2 and higher
 public void NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
 {
   BrowserExtendedNavigatingEventArgs args = new BrowserExtendedNavigatingEventArgs(ppDisp, new Uri(bstrUrl), null, (UrlContext)dwFlags);
   _Browser.OnStartNewWindow(args);
   Cancel = args.Cancel;
   ppDisp = args.AutomationObject;
 }
Esempio n. 5
0
 //The NewWindow2 event, used on Windows XP SP1 and below
 public void NewWindow2(ref object pDisp, ref bool cancel)
 {
   BrowserExtendedNavigatingEventArgs args = new BrowserExtendedNavigatingEventArgs(pDisp, null, null, UrlContext.None);
   _Browser.OnStartNewWindow(args);
   cancel = args.Cancel;
   pDisp = args.AutomationObject;
 }
Esempio n. 6
0
      //Implement whichever events you wish
      public void BeforeNavigate2(object pDisp, ref object URL, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel)
      {
        Uri urlUri = new Uri(URL.ToString());

        string tFrame = null;
        if (targetFrameName != null)
          tFrame = targetFrameName.ToString();

        BrowserExtendedNavigatingEventArgs args = new BrowserExtendedNavigatingEventArgs(pDisp, urlUri, tFrame, UrlContext.None);
        _Browser.OnStartNavigate(args);

        cancel = args.Cancel;
        pDisp = args.AutomationObject;
      }
Esempio n. 7
0
    /// <summary>
    /// Raises the <see cref="StartNavigate"/> event
    /// </summary>
    /// <exception cref="ArgumentNullException">Thrown when BrowserExtendedNavigatingEventArgs is null</exception>
    protected void OnStartNavigate(BrowserExtendedNavigatingEventArgs e)
    {
      if (e == null)
        throw new ArgumentNullException("e");

      if (this.StartNavigate != null)
        this.StartNavigate(this, e);
    }
Esempio n. 8
0
    void _browser_StartNewWindow(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.
      MainWebForm mf = GetMainFormFromControl(sender as Control);
      if (mf == null)
        return;

      // 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 (SettingsHelper.Current.FilterLevel)
        {
          case PopupBlockerFilterLevel.None:
            allowPopup = true;
            break;
          case PopupBlockerFilterLevel.Low:
            // See if this is a secure site
            if (this.WebBrowser.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))
        {
          ExtendedWebBrowser ewb = mf.WindowManager.New(false);
          // The (in)famous application object
          e.AutomationObject = ewb.Application;
        }
      }
      else
        // Here you could notify the user that the pop-up was blocked
        e.Cancel = true;
      
    }