예제 #1
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            var chromiumWebBrowser = (ExtChromiumBrowser)browserControl;

            chromiumWebBrowser.Dispatcher.Invoke(new Action(() =>
            {
                BrowserPopupWin win = new BrowserPopupWin();
                win.ShowInTaskbar   = false;
                win.Height          = 0;
                win.Width           = 0;
                win.Show();

                IntPtr handle = new WindowInteropHelper(win).Handle;
                windowInfo.SetAsChild(handle);

                _scheduler.Run(() =>
                {
                    WaitUtil.Wait(() => chromiumWebBrowser.PostData);

                    IRequest request = null;
                    if (chromiumWebBrowser.PostData != null)
                    {
                        request        = frame.CreateRequest();
                        request.Url    = targetUrl;
                        request.Method = "POST";

                        request.InitializePostData();
                        var element   = request.PostData.CreatePostDataElement();
                        element.Bytes = chromiumWebBrowser.PostData;
                        request.PostData.AddElement(element);
                        chromiumWebBrowser.PostData = null;
                    }

                    chromiumWebBrowser.Dispatcher.Invoke(new Action(() =>
                    {
                        NewWindowEventArgs e = new NewWindowEventArgs(targetUrl, request);
                        chromiumWebBrowser.OnNewWindow(e);
                    }));

                    chromiumWebBrowser.Dispatcher.Invoke(new Action(() =>
                    {
                        win.Close();
                    }));
                });
            }));

            newBrowser = null;
            return(false);
        }
예제 #2
0
        public void Load(string url)
        {
            if (!string.IsNullOrWhiteSpace(url))
            {
                loadingWait.Visibility = Visibility.Visible;
                Url = url;
                _scheduler.Run(() =>
                {
                    #region Wait
                    WaitUtil.Wait(() =>
                    {
                        if (this._browser == null)
                        {
                            return(false);
                        }
                        if (!this._browser.IsInitialized)
                        {
                            return(false);
                        }
                        if (!_isCefInited)
                        {
                            return(false);
                        }
                        bool isBrowserInitialized = false;
                        this.Dispatcher.Invoke(() =>
                        {
                            isBrowserInitialized = this._browser.IsBrowserInitialized;
                        });
                        if (!isBrowserInitialized)
                        {
                            return(false);
                        }
                        return(true);
                    });
                    #endregion

                    _browser.Load(Url);
                });
            }
        }
예제 #3
0
        private void LoadUrl()
        {
            if (_firstLoad)
            {
                _firstLoad = false;

                _scheduler.Run(() =>
                {
                    #region Wait
                    WaitUtil.Wait(() =>
                    {
                        if (this._browser == null)
                        {
                            return(false);
                        }
                        if (!this._browser.IsInitialized)
                        {
                            return(false);
                        }
                        if (!_isCefInited)
                        {
                            return(false);
                        }
                        bool isBrowserInitialized = false;
                        this.Dispatcher.Invoke(() =>
                        {
                            isBrowserInitialized = this._browser.IsBrowserInitialized;
                        });
                        if (!isBrowserInitialized)
                        {
                            return(false);
                        }
                        return(true);
                    });
                    #endregion

                    if (Url == null && SetUrlEvent != null)
                    {
                        try
                        {
                            SetUrlEvent(this, null);
                        }
                        catch (Exception ex)
                        {
                            LogUtil.Error(ex, "BrowserCtrl LoadUrl error 获取URL失败");
                        }
                    }
                    else
                    {
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            loadingWait.Visibility = Visibility.Collapsed;
                        }));
                    }

                    if (Url != null)
                    {
                        try
                        {
                            if (Request == null)
                            {
                                _browser.Load(Url);
                            }
                            else
                            {
                                _browser.Load(Url);
                                _browser.GetMainFrame().LoadRequest(Request);
                                Request = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            LogUtil.Error(ex, "BrowserCtrl LoadUrl error Load URL失败");
                        }
                    }
                    else
                    {
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            loadingWait.Visibility = Visibility.Collapsed;
                        }));
                    }
                });
            }
        }