Exemplo n.º 1
0
        void OnDocumentComplete(object pDisp, ref object URL)
        {
            if (pDisp != this.site)
            {
                return;
            }

            IHTMLDocument2 doc = (IHTMLDocument2)browser.Document;

            if (LoadData("Enabled") == "on")
            {
                browser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER);
                //doc.parentWindow.execScript("window.print();");
                //SendKeys.SendWait("{^P}");
                //doc.parentWindow.execScript("window.close();");
                doc.parentWindow.close();

                string next_url = PopUrl();
                if (next_url != "")
                {
                    browser.Navigate(next_url, 0x800);
                    //doc.parentWindow.execScript("window.onunload = function() {window.open('" + next_url + "')};");
                }

                else
                {
                    SetData("Enabled", "off");
                }
            }
        }
Exemplo n.º 2
0
Arquivo: IE.cs Projeto: minskowl/MY
        /// <summary>
        /// Navigates the specified URL.
        /// </summary>
        /// <param name="URL">The URL.</param>
        /// <param name="Flags">The flags.</param>
        /// <param name="postData">The post data.</param>
        public void Navigate(string URL, BrowserNavConstants Flags, string postData)
        {
            //At runtime, outobj data type is determined and passed as
            //variant of that type. Used for simple data types
            object outobj       = (int)Flags;
            object outtarget    = null;
            object sendPostData = null;
            object headers      = null;


            if (Flags == BrowserNavConstants.navOpenInNewWindow)
            {
                outtarget = "_BLANK";
            }

            if (!string.IsNullOrEmpty(postData))
            {
                sendPostData = Encoding.ASCII.GetBytes(postData);
                headers      = "Content-Type: application/x-www-form-urlencoded" + Convert.ToChar(10) + Convert.ToChar(13);
            }



            ie.Navigate(URL, ref outobj, ref outtarget, ref sendPostData, ref headers);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles Browser Application error messages
        /// </summary>
        /// <param name="topLevelhWnd"></param>
        /// <param name="hwnd"></param>
        /// <param name="process"></param>
        /// <param name="title"></param>
        /// <param name="notification"></param>
        /// <returns></returns>
        private static void navigateOnSTAThread(object navigateUrl)
        {
            IWebBrowser2 iWebBrowser2 = IWebBrowser2FromHandle(ieHwnd);
            object       empty        = null;

            // Can allow more parameters later if needed.
            iWebBrowser2.Navigate((string)navigateUrl, ref empty, ref empty, ref empty, ref empty);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the page using external com browser IE.
        /// </summary>
        /// <param name="page">The page request.</param>
        /// <returns>true if successful</returns>
        private bool GetExternal(HTTPRequest page)
        {
            // Delay before getting page
            // Bugfix: Moved over from LoadPage because it affected GetInternal as well.
            // GetInternal already get's delayed when calling HTTPTransaction.HTTPGet/Transaction
            if (page.Delay > 0)
            {
                Thread.Sleep(page.Delay);
            }

            // Use External Browser (IE) to get HTML page
            // IE downloads all linked graphics ads, etc
            // IE will run Javascript source if required to renderthe page
            if (_IE == null)
            {
                _IE = new InternetExplorer();
            }

            IWebBrowser2 webBrowser = (IWebBrowser2)_IE;

            object empty = Missing.Value;

            // check if request is POST or GET
            if (page.PostQuery != null)
            {
                ASCIIEncoding encoding = new ASCIIEncoding();
                object        postData = (object)encoding.GetBytes(page.PostQuery);
                object        header   = (object)"Content-Type: application/x-www-form-urlencoded\n\r";
                webBrowser.Navigate(page.Url, ref empty, ref empty, ref postData, ref header);
            }
            else
            {
                webBrowser.Navigate(page.Url, ref empty, ref empty, ref empty, ref empty);
            }

            while (webBrowser.Busy == true)
            {
                Thread.Sleep(500);
            }
            HTMLDocumentClass doc = (HTMLDocumentClass)webBrowser.Document;

            _strPageSource = doc.body.innerHTML;

            return(true);
        }
        void BrowserAquiredCheck(object obj)
        {
            string urlString = obj as string;

            if (urlString != BrowserId)
            {
                if (browserAquiredTimer != null)
                {
                    browserAquiredTimer.Dispose();
                }
                browserAquiredTimer = null;
                return;
            }

            if (web == null)
            {
                if (this._WebBrowserExtendedState == Microsoft.Uii.Csr.Browser.Web.WebBrowserExtendedState.BrowserNotAcquired)
                {
                    StartBrowser();
                    SinkEvents();
                    browserAquiredTimer = new System.Threading.Timer(new TimerCallback(BrowserAquiredCheck), urlString, TimeSpan.FromMilliseconds(2000), TimeSpan.Zero);
                }
                else if (DateTime.Now - browserAquiredStart > TimeSpan.FromSeconds(45))
                {
                    if (browserAquiredTimer != null)
                    {
                        browserAquiredTimer.Dispose();
                    }
                    browserAquiredTimer = null;
                    return;
                }
                else
                {   // try again in a few moments
                    browserAquiredTimer = new System.Threading.Timer(new TimerCallback(BrowserAquiredCheck), urlString, TimeSpan.FromMilliseconds(500), TimeSpan.Zero);
                }
                return;
            }
            else
            {
                PreNavigate(urlString);
                try
                {
                    web.Navigate(urlString);
                }
                catch (InvalidCastException)
                {
                    // can happen if the browser has closed but we haven't recognized it yet
                    ResetBrowser(urlString);
                    return;
                }
                PostNavigate(urlString);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Navigate to a specific web site or refresh the display with the Html or Body
        /// content previously set.
        /// </summary>
        /// <param name="url">Web Site to navigate. Use an empty string or null as parameter
        /// value to activate the display with the Html/Body content.</param>
        public void Navigate(string url)
        {
            if (url == null || url == String.Empty)
            {
                url = "about:blank";
            }

            if (!IsHandleCreated)
            {
                this.url = url;
                return;
            }

            Object flags       = 0;
            Object targetFrame = String.Empty;
            Object postData    = String.Empty;
            Object headers     = String.Empty;

            try {
                control.Navigate(url, ref flags, ref targetFrame, ref postData, ref headers);
            } catch {}
        }
Exemplo n.º 7
0
        void BrowserAquiredCheck(object obj)
        {
            string urlString = obj as string;

            if (urlString != BrowserId)
            {
                if (browserAquiredTimer != null)
                {
                    browserAquiredTimer.Dispose();
                }
                browserAquiredTimer = null;
                return;
            }

            if (web == null)
            {
                if (true == (bool)Dispatcher.Invoke(new System.Func <bool>(() =>
                {
                    try
                    {
                        if (webBrowser is System.Windows.Controls.WebBrowser)
                        {
                            if (((System.Windows.Controls.WebBrowser)webBrowser).Handle == IntPtr.Zero)
                            {
                                return(false);
                            }
                            web = GetIWebBrowser2(((System.Windows.Controls.WebBrowser)webBrowser).Handle);
                        }
                        else
                        {
                            Debug.Assert(false);    // TODO:
                        }
                        if (web == null)
                        {
                            return(false);
                        }
                        return(true);
                    }
                    catch { }
                    return(true);
                })))
                {
                    if (browserAquiredTimer != null)
                    {
                        browserAquiredTimer.Dispose();
                    }
                    browserAquiredTimer = null;
                    Dispatcher.Invoke(new System.Action(() =>
                    {
                        try
                        {
                            this._WebBrowserEventSink.BrowserObjectAppeared(web, false, 0);
                            this._WebBrowserEventSink.Advise(web);
                        }
                        catch { }
                        try
                        {
                            web.Navigate(urlString);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine("Error in webBrowser.Navigate(" + urlString + ") " + ex.Message);
                        }
                    }));
                    return;
                }
                else
                {
                    if (DateTime.Now - browserAquiredStart > TimeSpan.FromSeconds(45))
                    {
                        if (browserAquiredTimer != null)
                        {
                            browserAquiredTimer.Dispose();
                        }
                        browserAquiredTimer = null;
                        return;
                    }
                    else
                    {   // try again in a few moments
                        browserAquiredTimer = new System.Threading.Timer(new TimerCallback(BrowserAquiredCheck), urlString, TimeSpan.FromMilliseconds(500), TimeSpan.Zero);
                    }
                }
            }
            else
            {
                web.Navigate(urlString);
            }
        }
 void IWebBrowser2.Navigate(string URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers)
 {
     _EmbeddedWebBrowserAsIWebBrowser2.Navigate(URL, ref Flags, ref TargetFrameName, ref PostData, ref Headers);
 }
Exemplo n.º 9
0
        public void Navigate(string url)
        {
            IsReady = false;

            _ie.Navigate(url);
        }