private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) { if (e.Url == "about:blank") { return; } if (_browser.CommandType == CommandType.Login) { if (e.Url.Contains(_currentSiteInfo.LoginUrl)) { _state = WebBrowserState.LoadEnded; } else if (e.Url.Contains("wp-admin")) { _isLoggedIn = true; _timer.Change(100, Timeout.Infinite); } } else if (_browser.CommandType == CommandType.Posting && e.Url.Contains("&action=edit")) { _state = WebBrowserState.LoadEnded; } else if ((_browser.CommandType == CommandType.Updating || _browser.CommandType == CommandType.OpenEdit) && e.Url.Contains(_currentEditUrl)) { _state = WebBrowserState.LoadEnded; } else if (_browser.CommandType == CommandType.OpenNew && e.Url.Contains(_currentSiteInfo.PostNewUrl)) { _state = WebBrowserState.LoadEnded; } }
public void NewTab(string url) { var state = new WebBrowserState(); //var tabPage = new TabPage(url); //var navBox = new WebNavigationBox(); //navBox.Parent = tabPage; //navBox.Dock = DockStyle.Top; //navBox.Visible = true; //navBox.HomeUrl = _application.HomeUrl; //this.cefWebBrowser1=new CefWebBrowser(); var browserCtl = this.cefWebBrowser1; //new CefWebBrowser(); //tabPage.Tag = browserCtl; //browserCtl.Parent = tabPage; //browserCtl.Dock = DockStyle.Fill; //browserCtl.BringToFront(); var browser = browserCtl.WebBrowser; //browser.StartUrl = url; //browser.StartUrl = "http://www.baidu.com"; //navBox.Attach(browser); browser.TitleChanged += (s, e) => { state.Title = e.Title; _pUIThread.Post((_state) => { UpdateTitle(e.Title); }, null); }; browser.AddressChanged += (s, e) => { state.Title = e.Address; //_pUIThread.Post((_state) => { navBox.Address = e.Address; }, null); }; browser.TargetUrlChanged += (s, e) => { state.TargetUrl = e.TargetUrl; // TODO: show targeturl in status bar // _pUIThread.Post((_state) => { UpdateTargetUrl(e.TargetUrl); }, null); }; browser.LoadingStateChanged += (s, e) => { _pUIThread.Post((_state) => { //navBox.CanGoBack = e.CanGoBack; //navBox.CanGoForward = e.CanGoForward; //navBox.Loading = e.Loading; }, null); }; //_tabs.TabPages.Add(tabPage); //_tabs.SelectedTab = tabPage; }
private void UpdateOrPublishPost(ArticleDraft draft) { try { NotifyStatus("发布中... 标题:" + draft.Title); _state = WebBrowserState.Request; var scripts = GetInvokeJS(draft); //每执行一个脚本 等待 foreach (var scriptKv in scripts) { _browser.ExecuteScriptAsync(scriptKv.Value); switch (scriptKv.Key) { case JSType.ADD_META: { _browser.ReqHandler.IsResponceSuccess = IsAddMetaSuccess; _browser.ReqHandler.ResponceSuccess = AddMetaSuccess; //等待添加Meta完成 WaitResponceSuccess(); } break; case JSType.ADD_META_NO_SUBMIT: case JSType.PUBLISH: break; } } _browser.ReqHandler.IsResponceSuccess = IsPublishSuccess; _browser.ReqHandler.ResponceSuccess = PublishSuccess; //等待文章发布/更新 if (!WaitResponceSuccess()) { var logInfo = new StringBuilder(); foreach (var script in scripts) { logInfo.AppendLine(script.Value); } Logger.Info("\n发布超时:" + logInfo); NotifyStatus("发布超时!标题:" + draft.Title); ResetReqHandler(); } } catch (Exception ex) { Logger.Error(ex); } }
private void OpenPage(string sitePostId, Action actionSuc, Action actionFail) { _state = WebBrowserState.Request; string url; if (string.IsNullOrEmpty(sitePostId)) { _currentEditUrl = null; _browser.CommandType = CommandType.OpenNew; url = _currentSiteInfo.PostNewUrl; } else { _currentEditUrl = _currentSiteInfo.PostEditUrl.Replace("SitePostId", sitePostId); _browser.CommandType = CommandType.OpenEdit; url = _currentEditUrl; } NotifyStatus("正在打开页面:" + url); this.InvokeIfRequired(() => _browser.LoadPageAsync(url), true); //等待加载完成 var resultLoad = SpinWait.SpinUntil(() => _state == WebBrowserState.LoadEnded, _timeOutTimeSpan); //超时未打开 if (!resultLoad) { NotifyStatus("打开页面超时:" + url); actionFail(); } else { _timerWait4OpenPageCompleted.Change(100, Timeout.Infinite); _browser.ExecuteScriptAsync("jQuery('#content-tmce').click();"); //确保为可视化界面 _isWaiting4OpenAddOrEdit = true; //打开成功后执行 _actionOpenCompleted = () => { NotifyStatus("打开页面成功"); _browser.CommandType = string.IsNullOrEmpty(sitePostId) ? CommandType.Posting : CommandType.Updating; actionSuc(); }; } }