Beispiel #1
0
        internal void RestoreSystemProxy()
        {
#if DEBUG
            App.LogInfo("browser RestoreSystemProxy");
#endif
            if (WinInetInterop.RestoreSystemProxy())
            {
                App.LogInfo("browser RestoreSystemProxy succeed");
            }
        }
Beispiel #2
0
        public void SetProxy(EndPoint address, NetworkCredential credential = null)
        {
            if (credential != null)
            {
                throw new NotSupportedException("credential");
            }

#if DEBUG
            App.LogInfo("browser SetProxy {0}", address);
#endif
            if (WinInetInterop.SetConnectionProxy(address.ToString()))
            {
                _isSetProxy = true;
                App.LogInfo("browser SetProxy {0} succeed", address);
            }
        }
Beispiel #3
0
        private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var browser = (WebBrowser)sender;

#if DEBUG
            App.LogInfo("browser_DocumentCompleted {0}@{1}", e.Url, browser.Url);
#endif
            var arg = (ScriptingContext)browser.ObjectForScripting;
            try
            {
                //e.Url不会变res://
                if (!ScriptingContext.CheckDocument(browser.Url))
                {
                    App.LogInfo("browser_DocumentCompleted Cancel {0}", browser.Url);
                    return;
                }
                if (browser.ReadyState != WebBrowserReadyState.Complete)
                {
                    return;
                }

                //发生redirect或iframe load
                if (browser.Url != e.Url)
                {
                    App.LogInfo("browser_DocumentCompleted Redirect {0} to {1}", arg.RequestUrl, e.Url);
                }
                if (this.UseCookies)
                {
                    WinInetInterop.LoadCookies(_cookieContainer, browser.Document.Url);
                }
                ScriptingContext.InjectScript(browser.Document, @"if (typeof ($) == 'undefined') {
            var script = document.createElement('script');
            script.src = 'http://libs.baidu.com/jquery/1.9.0/jquery.js';
            document.getElementsByTagName('head')[0].appendChild(script);
        }
        function Soubiscbot(kind) {
            switch (kind) {
                case 0:
                    var set = [];
                    $(arguments[1]).each(function (i, o) {
                        var me = $(o);
                        var id = me.attr('id');
                        if (!id) {
                            id = Math.random();
                            me.attr('id', id);
                        }
                        set[i] = id;
                    });
                    return set.toString();
                    break;
                case 1:
                    try {
                        return arguments[1]();
                    }
                    catch (ex) {
                        return ex.toString();
                    }
                    break;
                default:
                    return document.documentElement.outerHTML;
                    break;
            }
        }");

                if (this.SendReceiveTimeout != Timeout.Infinite)
                {
                    arg.SendReceiveWaiter.Set();
                }
                //EntryAjax
                arg.SetAjax(browser, AjaxBlockFlags.Block, arg.RequestUrl);
                arg.RegisterLazyLoad(x =>
                {
                    bool isSet   = arg.WaitAjax(this.SendReceiveTimeout, arg.RequestUrl);
                    _isNavigated = true;
                    arg.WaitHandle.Set();
                }, browser);
            }
            catch (Exception ex)
            {
                App.LogError(ex, "browser_DocumentCompleted RequestUrl={0} BrowserUrl={1}", arg.RequestUrl, browser.Url);
            }
        }