<commit_before>﻿//----------------------------------------------------------------------
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved
// Apache License 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//----------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Microsoft.IdentityModel.Clients.ActiveDirectory.Internal
{
    [ComVisible(true)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    public abstract class WindowsFormsWebAuthenticationDialogBase : Form
    {
        private static readonly NavigateErrorStatus NavigateErrorStatus = new NavigateErrorStatus();

        private const int UIWidth = 566;

        private Panel webBrowserPanel;
        private readonly CustomWebBrowser webBrowser;

        private Uri desiredCallbackUri;

        protected string result;

        protected IWin32Window ownerWindow;

        private Keys key = Keys.None;

        /// <summary>
        /// Default constructor
        /// </summary>
        protected WindowsFormsWebAuthenticationDialogBase(object ownerWindow)
        {
            IWin32Window window = ownerWindow as IWin32Window;
            if (window != null)
            {
                this.ownerWindow = window;
            }
            else if (ownerWindow is IntPtr)
            {
                this.ownerWindow = new WindowsFormsWin32Window { Handle = (IntPtr)ownerWindow };
            }
            else if (null == ownerWindow)
            {
                this.ownerWindow = null;
            }
            else
            {
                throw new AdalException(AdalError.InvalidOwnerWindowType,
                    "Invalid owner window type. Expected types are IWin32Window or IntPtr (for window handle).");
            }

            this.webBrowser = new CustomWebBrowser();
            this.webBrowser.PreviewKeyDown += webBrowser_PreviewKeyDown;
            this.InitializeComponent();
        }
        
        private void webBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Back)
            {
                key = Keys.Back;
            }
        }

        /// <summary>
        /// Gets Web Browser control used by the dialog.
        /// </summary>
        public WebBrowser WebBrowser
        {
            get
            {
                return this.webBrowser;
            }
        }

        protected virtual void WebBrowserNavigatingHandler(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (this.webBrowser.IsDisposed)
            {<commit_msg>Addressing code review comment<commit_after>﻿//----------------------------------------------------------------------
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved
// Apache License 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//----------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Microsoft.IdentityModel.Clients.ActiveDirectory.Internal
{
    [ComVisible(true)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    public abstract class WindowsFormsWebAuthenticationDialogBase : Form
    {
        private static readonly NavigateErrorStatus NavigateErrorStatus = new NavigateErrorStatus();

        private const int UIWidth = 566;

        private Panel webBrowserPanel;
        private readonly CustomWebBrowser webBrowser;

        private Uri desiredCallbackUri;

        protected string result;

        protected IWin32Window ownerWindow;

        private Keys key = Keys.None;

        /// <summary>
        /// Default constructor
        /// </summary>
        protected WindowsFormsWebAuthenticationDialogBase(object ownerWindow)
        {
            if (ownerWindow == null)
            {
                this.ownerWindow = null;
            }
            else if (ownerWindow is IWin32Window)
            {
                this.ownerWindow = (IWin32Window)ownerWindow;
            }
            else if (ownerWindow is IntPtr)
            {
                this.ownerWindow = new WindowsFormsWin32Window { Handle = (IntPtr)ownerWindow };
            }
            else
            {
                throw new AdalException(AdalError.InvalidOwnerWindowType, 
                    "Invalid owner window type. Expected types are IWin32Window or IntPtr (for window handle).");
            }

            this.webBrowser = new CustomWebBrowser();
            this.webBrowser.PreviewKeyDown += webBrowser_PreviewKeyDown;
            this.InitializeComponent();
        }
        
        private void webBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Back)
            {
                key = Keys.Back;
            }
        }

        /// <summary>
        /// Gets Web Browser control used by the dialog.
        /// </summary>
        public WebBrowser WebBrowser
        {
            get
            {
                return this.webBrowser;
            }
        }

        protected virtual void WebBrowserNavigatingHandler(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (this.webBrowser.IsDisposed)
            {
{'fraction_non_alphanumeric': 0.11453335396997369, 'fraction_numerical': 0.005881442501160811, 'mean_word_length': 1.7674518201284797, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '375958', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1451, 'n_words': 467}