/// <summary>
        /// Initializes a new instance of the <see cref="WindowsFormsWebAuthenticationDialogBase" /> class.
        /// </summary>
        /// <param name="ownerWindow"></param>
        protected WindowsFormsWebAuthenticationDialogBase(object ownerWindow)
        {
            // From MSDN (http://msdn.microsoft.com/en-us/library/ie/dn720860(v=vs.85).aspx):
            // The net session count tracks the number of instances of the web browser control.
            // When a web browser control is created, the net session count is incremented. When the control
            // is destroyed, the net session count is decremented. When the net session count reaches zero,
            // the session cookies for the process are cleared. SetQueryNetSessionCount can be used to prevent
            // the session cookies from being cleared for applications where web browser controls are being created
            // and destroyed throughout the lifetime of the application. (Because the application lives longer than
            // a given instance, session cookies must be retained for a longer periods of time.
            int sessionCount = NativeMethods.SetQueryNetSessionCount(NativeMethods.SessionOp.SESSION_QUERY);

            if (sessionCount == 0)
            {
                _ = NativeMethods.SetQueryNetSessionCount(NativeMethods.SessionOp.SESSION_INCREMENT);
            }

            if (ownerWindow == null)
            {
                OwnerWindow = null;
            }
            else if (ownerWindow is IWin32Window)
            {
                OwnerWindow = (IWin32Window)ownerWindow;
            }
            else if (ownerWindow is IntPtr)
            {
                OwnerWindow = new WindowsFormsWin32Window {
                    Handle = (IntPtr)ownerWindow
                };
            }
            else
            {
                throw new PartnerException("Invalid owner window type. Expected types are IWin32Window or IntPtr (for window handle).");
            }

            webBrowser = new CustomWebBrowser();
            webBrowser.PreviewKeyDown += WebBrowser_PreviewKeyDown;
            InitializeComponent();

            WhiteListedSchemes.Add(BrowserScheme);
        }
예제 #2
0
 // Methods
 public CustomWebBrowserEvent(CustomWebBrowser parent)
 {
     this.parent = parent;
 }