private void txtEditor_WordMouseDown(object sender, ref Compona.Windows.Forms.SyntaxBox.WordMouseEventArgs e)
        {
            string url=e.Word.Text;

            RequestGetEventArgs args = new RequestGetEventArgs();
            args.Url = url;
            StartEvent(this,args);
        }
 // BeforeNavigate event used for post data mapping to forms editor.
 private void web_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
 {
     if ( allowNavigate )
     {
         #region User Action Code
         if ( e.postData != null )
         {
             if ( allowPostContinue )
             {
                 // Posting here
                 htmlDocument =(IHTMLDocument2) web.Document;
                 this.Invoke(new OnPostEventHandler(OnPost),new Object[] {htmlDocument,(byte[])e.postData});
                 e.cancel = false;
             }
         }
         else
         {
             #region Link Navigation
             if ( isLinkNavigation )
             {
                 // link navigation, cancel and let GBWorkspace handle it
                 RequestGetEventArgs args = new RequestGetEventArgs();
                 args.Url = (string)e.uRL;
                 this.StartEvent(this, args);
                 e.cancel=true;
             }
             #endregion
         }
         #endregion
     }
     else
     {
         #region Non User Action Code
         if ( e.postData != null )
         {
             if ( !PendingRedirection )
             {
                 isLinkNavigation = false;
                 htmlDocument =(IHTMLDocument2) web.Document;
                 this.Invoke(new OnPostEventHandler(OnPost),new Object[] {htmlDocument,(byte[])e.postData});
                 e.cancel = false;
             }
             else
             {
                 e.cancel = true;
             }
         }
         else
         {
             if ( (isLinkNavigation) && (!PendingRedirection) )
             {
                 // link navigation, cancel and let GBWorkspace handle it
                 RequestGetEventArgs args = new RequestGetEventArgs();
                 args.Url = (string)e.uRL;
                 this.StartEvent(this, args);
                 e.cancel=true;
                 isLinkNavigation = false;
             }
         }
         #endregion
     }
 }
        /// <summary>
        /// Handles HTTP Redirects.
        /// </summary>
        /// <param name="url"> Url to redirect to.</param>
        internal void GetHttpRedirectRequest(string url)
        {
            RequestGetEventArgs args = new RequestGetEventArgs();
            args.Url = url;
            args.InspectorRequestAction = InspectorAction.InspectorRedirection;

            this.InspectorStartGetEvent(this, args);
        }
 private void lnkNavigate_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
 {
     if ( this.WebSessionRequest.RequestType == HttpRequestType.GET )
     {
         RequestGetEventArgs args = new RequestGetEventArgs();
         args.Url = this.WebSessionRequest.Url.ToString();
         HttpGetEvent(this, args);
     }
 }
        /// <summary>
        /// Loads a Recent Sites node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sitesTree_DoubleClick(object sender, EventArgs e)
        {
            // do not allow selection from root node
            if ( sitesTree.SelectedNode.Parent == null ) return;

            HistoryTreeNode node = (HistoryTreeNode)sitesTree.SelectedNode;

            //			ResponseBuffer resp = sitesTree.GetHttpSiteData(node);
            //			if ( resp != null )
            //			{
                // get cookies
                //CookieCollection cookies = null;
                //cookies = cookieManager.GetCookies(node.Url);

                RequestGetEventArgs requestArgs = new RequestGetEventArgs();
                requestArgs.Url = node.Url.AbsoluteUri;
                this.InspectorStartGetEvent(this, requestArgs);
            //			}
        }
        /// <summary>
        /// Fills the workspace with data retrieve from site.
        /// </summary>
        /// <param name="response">ResponseBuffer</param>
        public void FillWorkspace(ResponseBuffer response)
        {
            if (response.ErrorMessage != String.Empty)
            {
                // reset statusbar
                ChangeStatusBarPanelEvent(this, CleanStatusArgs);

                this.txtMessaging.SelectionColor = Color.Red;
                this.txtMessaging.SelectedText = "Html Browser Error: " + response.ErrorMessage  + "\r\n";

                // Show Error
                textViewerForm.EditorText  = response.ErrorMessage;

                // Stop progress
                this.StopProgressBarEvent(this, new ProgressBarControlEventArgs("Ready"));

                this.InspectorState = GBInspectorState.Error;
            }
            else
            {
                // Set Editor Text
                try
                {
                    textViewerForm.EditorText = response.HttpBody;

                    // save buffer, do not save before error message check
                    this.CurrentResponseBuffer = response;

                    // load forms editor if any
                    if ( formCollection != null )
                    {
                        DisplayForms(formCollection, false);
                    }

                    Uri responseUri = (Uri)response.ResponseHeaderCollection["Response Uri"];

                    // Get Settings from Panel
                    ClientProperties = this.GetHttpPropertiesFromPanel();

                    // Update referer
                    ClientProperties.Referer = responseUri.ToString();

                    // Load properties
                    LoadHttpProperties(this.ClientProperties);

                    // Add to history
                    AddToHistory(response);

                    //					// Add to cookies
                    //					cookieManager.AddCookies(response.CookieCollection);

                    // Fill Lists
                    FillListViews(response);
                    FillCookieListView(response.CookieCollection);

                    // Update address bar
                    RequestGetEventArgs requestArgs = new RequestGetEventArgs();
                    requestArgs.Url = responseUri.ToString();
                    this.UpdateAddressEvent(this, requestArgs);

                    // Update Session Request
                    UpdateSessionRequest(response);

                    EnableFormView();
                    this.InspectorState = GBInspectorState.Complete;

                    // Stop progress only if navigator CanLinkNavigate is true.
                    if ( navForm.CanLinkNavigate )
                    {
                        // reset statusbar
                        ChangeStatusBarPanelEvent(this, CleanStatusArgs);
                        // stop progress bar
                        this.StopProgressBarEvent(this,new ProgressBarControlEventArgs("Ready"));
                    }

                    // Location is found in Hashtable
                    if ( response.ResponseHeaderCollection.ContainsKey("Location") )
                    {
                        // Location is not empty
                        if ( ((string)response.ResponseHeaderCollection["Location"])!=String.Empty )
                        {
                            // Apply direct and log in recording sesion if any.
                            this.ApplyUrlRedirection();

                            // navForm.PendingRedirection = true;
                            //ChangeStatusBarPanelEvent(this,RedirectMessageArgs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string message = ExceptionHandler.RegisterException(ex);
                    MessageBox.Show(message,AppLocation.ApplicationName, MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }
        }
 /// <summary>
 /// Execute a GET from the session designer.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void GetPageFromSessionDesigner(object sender, RequestGetEventArgs args)
 {
     this.InspectorStartGetEvent(this, args);
 }
        /// <summary>
        /// Starts the get event for the inspector.
        /// </summary>
        /// <param name="sender"> The sender object.</param>
        /// <param name="e"> The RequestGetEventArgs.</param>
        private void InspectorStartGetEvent(object sender, RequestGetEventArgs e)
        {
            ArrayList values;
            string urlToNavigate = e.Url;
            if ( e.Form != null )
            {
                values = parser.GetArrayList(e.Form);
                if ( (new Uri(e.Url)).Query.Length == 0 )
                {
                    urlToNavigate = GetForm.AppendToUri(e.Url, values);
                }
            }

            // get cookies
            CookieCollection cookies = null;
            cookies = getForm.CookieManager.GetCookies(new Uri(e.Url));

            // navigate ie
            if  ( e.InspectorRequestAction == InspectorAction.UserGet || e.InspectorRequestAction == InspectorAction.Idle )
                navForm.Navigate(urlToNavigate, cookies, e.InspectorRequestAction);

            // Allows the browser to request first.
            if (!AllowBrowserFirst)
            {
                // Save Web Session
                AddSessionGet(urlToNavigate,(new Uri(urlToNavigate)).Query, e.Form, cookies);

                // Set Inspector State
                InspectorState = GBInspectorState.Requesting;

                // Update progress bar
                StartProgressBarEvent(this,new ProgressBarControlEventArgs("Requesting site..."));

                GetHttpRequest(urlToNavigate,this.CurrentResponseBuffer, cookies);
                //				if ( e.Form == null )
                //				{
                //				}
                //				else
                //				{
                //					GetHttpRequest(e.Url, values, this.CurrentResponseBuffer, cookies);
                //				}
            }
        }
 private void inspector_UpdateAddressEvent(object sender, RequestGetEventArgs e)
 {
     this.cmbAddressUrl.Text = e.Url;
 }
        /// <summary>
        /// Request Post Event from Form Editor.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void formeditor_RequestPostEvent(object sender,RequestPostEventArgs e)
        {
            if ( e.Form.Action == String.Empty )
            {
                MessageBox.Show("Not a postable form. Check source code for any scripting use.\r\nForm name:" + e.Form.Name,AppLocation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Uri uri = (Uri)CurrentResponseBuffer.ResponseHeaderCollection["Response Uri"];

            string formUri = UriResolver.ResolveUrl(uri,e.Form.Action);

            // FormConverter formConverter = new FormConverter();

            if ( e.Method.ToLower() == "post" )
            {
                e.PostData = Encoding.UTF8.GetBytes(parser.GetString(e.Form));
                e.InspectorRequestAction = InspectorAction.UserPost;
                e.CurrentUri = new Uri(formUri);
                this.InspectorStartPostEvent(this, e);
            }
            else
            {
                // Get Request
                RequestGetEventArgs requestArgs = new RequestGetEventArgs();
                requestArgs.InspectorRequestAction = InspectorAction.UserGet;
                requestArgs.Url = formUri;
                requestArgs.Form = e.Form;
                this.InspectorStartGetEvent(this, requestArgs);
            }

            // Add Easy Test options
            //this.RunQuickTests(e);
        }
        private void btnGo_Click(object sender, System.EventArgs e)
        {
            // apply only if enabled
            if ( this.cmbAddressUrl.Enabled )
            {
                // Set focus
                this.cmbAddressUrl.Focus();

                // Validate that selected item is not null
                string url = string.Empty;
                if ( cmbAddressUrl.SelectedItem == null )
                {
                    url = cmbAddressUrl.Text;
                }
                else
                {
                    url = cmbAddressUrl.SelectedItem.ToString();
                }

                // ir no url set, focus and exit
                if ( url.Length == 0 )
                {
                    this.cmbAddressUrl.Focus();
                    return;
                }

                #region Apply more integrated checks
                if ( UrlSchemeValidation(url) )
                {
                    if ( url.IndexOf("://") > -1 )
                    {
                        Uri getScheme = new Uri(url);
                        cmbAddressUrl.Text = url;

                        // check scheme
                        if (( getScheme.Scheme != "http" ) && (getScheme.Scheme != "https"))
                        {
                            MessageBox.Show("Protocol not supported, try with http or https instead.",AppLocation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    else
                    {
                        if ( (!url.ToLower().StartsWith("http://")) || (!url.ToLower().StartsWith("https://")) )
                        {
                            // http as default
                            cmbAddressUrl.Text = "http://" + url;
                        }
                        else
                        {
                            cmbAddressUrl.Text = url;
                        }
                    }

                    // Add item to combo list
                    if ( cmbAddressUrl.Items.IndexOf(cmbAddressUrl.Text) == -1 )
                    {
                        this.cmbAddressUrl.Items.Add(cmbAddressUrl.Text);
                    }

                    RequestGetEventArgs eventArgs = new RequestGetEventArgs();
                    eventArgs.Url = this.cmbAddressUrl.Text;
                    eventArgs.InspectorRequestAction = InspectorAction.UserGet;
                    this.StartEvent(this, eventArgs);
                }
            }
            #endregion
        }
        // BeforeNavigate event used for post data mapping to forms editor.
        private void web_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
        {
            if ( e.postData != null )
            {
                this.postData = (byte[])e.postData;

                Invoke(new OnPostDataMatchEventHandler(OnPostDataSubmitMatch),
                            new Object[] {(byte[])e.postData});
            }
            else
            {
                string url = (string)e.uRL;
                if ( isLinkNavigation )
                {
                    Uri uri = new Uri(url);
                    string queryString = uri.Query;

                    if ( queryString.Length > 0 )
                    {
                        Invoke(new OnQueryStringMatchEventHandler(OnQueryStringSubmitMatch),
                            new Object[] {queryString});
                    }

                    if ( (url.StartsWith("http:"))
                        ||
                        (url.StartsWith("https:")) )
                    {
                        RequestGetEventArgs args = new RequestGetEventArgs();
                        if ( _getformTag != null )
                        {
                            args.Form = _getformTag.CloneTag();
                            _getformTag = null;
                        }
                        args.Url = (string)url;
                        args.InspectorRequestAction = InspectorAction.WebBrowserGet;
                        this.StartEvent(this, args);

                        isLinkNavigation = false;
                    }
                }
            }
        }
        // Fires when the browser ActiveX control finishes loading a document
        private void OnComplete(IHTMLDocument2 htmlDoc)
        {
            // Adds some event handlers to the DOM Document
            AddEventsToDoc(htmlDoc);

            formCollection = HtmlDomTransformation.TransformFormElements(htmlDoc, new Uri(htmlDoc.location.toString()));
            // FIX: This might be no longer neccesary because
            // it injects code into the document.
            //SetFormOnSubmit(htmlDoc);

            // check if it is NewWindow
            if ( isNewWindow )
            {
                RequestGetEventArgs args = new RequestGetEventArgs();
                args.Url = (string)web.LocationURL;
                args.InspectorRequestAction = InspectorAction.WebBrowserGet;
                this.StartEvent(this, args);

                isNewWindow = false;
            }

            // raise load links event
            if ( LoadLinksEvent != null )
            {
                LoadLinksEventArgs args = new LoadLinksEventArgs();
                args.Frames = HtmlDomTransformation.TransformFrameElements(htmlDoc);
                args.Anchors = HtmlDomTransformation.TransformAnchorElements(htmlDoc);
                args.Links = HtmlDomTransformation.TransformLinksElements(htmlDoc);
                LoadLinksEvent.BeginInvoke(this, args, new AsyncCallback(FireAndForget), null);
            }

            // raise load forms event
            if ( LoadFormsEditorEvent != null )
            {
                // Transform form elements to HTML DOM Document.
                LoadFormsEditorEvent.BeginInvoke(this, new LoadFormsEditorEventArgs(postData, formCollection), new AsyncCallback(FireAndForget),null);
            }

            // reset
            inspectorState = InspectorAction.Idle;
        }
        /// <summary>
        /// Go to url and process http request.
        /// </summary>
        private void GoUrl()
        {
            // Add item to combo list
            if ( cmbUrl.Items.IndexOf(cmbUrl.Text) == -1 )
            {
                this.cmbUrl.Items.Add(cmbUrl.Text);
            }

            RequestGetEventArgs args = new RequestGetEventArgs();
            args.Url = this.cmbUrl.Text;
            StartEvent(this,args);
            //GetHttpRequest();
        }
 /// <summary>
 /// Navigates the requested url.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void HttpGetPage(object sender, RequestGetEventArgs e)
 {
     HttpGetPageEvent(this, e);
 }