public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { switch (dialogType) { case CefJsDialogType.Alert: MessageBox.Show(messageText); suppressMessage = true; return false; case CefJsDialogType.Confirm: var dr = MessageBox.Show(messageText, "提示", MessageBoxButton.YesNo); if (dr == MessageBoxResult.Yes) callback.Continue(true); else callback.Continue(false); suppressMessage = false; return true; case CefJsDialogType.Prompt: MessageBox.Show("系统不支持prompt形式的提示框", "UTMP系统提示"); break; } //如果suppressMessage被设置为true,并且函数返回值为false,将阻止页面打开JS的弹出窗口。 //如果suppressMessage被设置为false,并且函数返回值也是false,页面将会打开这个JS弹出窗口。 suppressMessage = true; return false; }
private static JsDialogType ConvertDialogType(CefJsDialogType type) { return(type switch { CefJsDialogType.Alert => JsDialogType.Alert, CefJsDialogType.Confirm => JsDialogType.Confirm, CefJsDialogType.Prompt => JsDialogType.Prompt, _ => JsDialogType.Unknown });
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { switch (dialogType) { case CefJsDialogType.Alert: MessageBox.Show(messageText, "L'auto-cadet", MessageBoxButtons.OK); callback.Continue(true); return true; case CefJsDialogType.Confirm: var result = MessageBox.Show(messageText, "L'auto-cadet", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); callback.Continue(result == DialogResult.Yes); return true; } return false; }
bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { ((ChromiumWebBrowser)browserControl).InvokeSafe(() => { FormMessage form = new FormMessage(Program.BrandName, messageText, MessageBoxIcon.None); TextBox input = null; if (dialogType == CefJsDialogType.Alert) { form.AcceptButton = form.AddButton("OK"); } else if (dialogType == CefJsDialogType.Confirm) { form.CancelButton = form.AddButton("No", DialogResult.No); form.AcceptButton = form.AddButton("Yes"); } else if (dialogType == CefJsDialogType.Prompt) { form.CancelButton = form.AddButton("Cancel", DialogResult.Cancel); form.AcceptButton = form.AddButton("OK"); input = new TextBox { Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, Location = new Point(27, form.ActionPanelY - 46), Size = new Size(form.ClientSize.Width - 54, 20) }; form.Controls.Add(input); form.ActiveControl = input; form.Height += input.Size.Height + input.Margin.Vertical; } bool success = form.ShowDialog() == DialogResult.OK; if (input == null) { callback.Continue(success); } else { callback.Continue(success, input.Text); input.Dispose(); } form.Dispose(); }); return(true); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { OnJSDialogShow?.Invoke(messageText); return(messageText == "下载速度太快,请稍后再试!"); //throw new NotImplementedException(); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { callback.Continue(true); return(true); }
bool IJsDialogHandler.OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { return(false); }
public bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { System.Diagnostics.Debug.WriteLine($"[OnJSDialog] Url:{originUrl} msg:{messageText}"); callback.Continue(false); return(true); }
public bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { System.Console.WriteLine("---------------"); return(true); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { throw new NotImplementedException(); }
bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { ((ChromiumWebBrowser)browserControl).InvokeSafe(() => { FormMessage form; TextBox input = null; if (dialogType == CefJsDialogType.Alert) { form = CreateMessageForm("Browser Message", messageText); form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused); } else if (dialogType == CefJsDialogType.Confirm) { form = CreateMessageForm("Browser Confirmation", messageText); form.AddButton(FormMessage.No, DialogResult.No, ControlType.Cancel); form.AddButton(FormMessage.Yes, ControlType.Focused); } else if (dialogType == CefJsDialogType.Prompt) { form = CreateMessageForm("Browser Prompt", messageText); form.AddButton(FormMessage.Cancel, DialogResult.Cancel, ControlType.Cancel); form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused); float dpiScale = form.GetDPIScale(); int inputPad = form.HasIcon ? 43 : 0; input = new TextBox { Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, Location = new Point(BrowserUtils.Scale(22 + inputPad, dpiScale), form.ActionPanelY - BrowserUtils.Scale(46, dpiScale)), Size = new Size(form.ClientSize.Width - BrowserUtils.Scale(44 + inputPad, dpiScale), 20) }; form.Controls.Add(input); form.ActiveControl = input; form.Height += input.Size.Height + input.Margin.Vertical; } else { callback.Continue(false); return; } bool success = form.ShowDialog() == DialogResult.OK; if (input == null) { callback.Continue(success); } else { callback.Continue(success, input.Text); input.Dispose(); } form.Dispose(); }); return(true); }
public bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { var targetBrowser = (ChromiumWebBrowser)chromiumWebBrowser; switch (dialogType) { case CefJsDialogType.Alert: { wfChromiumWebBrowser.Dispatcher.Invoke(() => { JsAlertDialog.ShowDialog(messageText, wfChromiumWebBrowser.Title); }); suppressMessage = true; return(false); } case CefJsDialogType.Confirm: { wfChromiumWebBrowser.Dispatcher.Invoke(() => { JsConfirmDialog.ShowDialog(messageText, wfChromiumWebBrowser.Title, result => { callback.Continue(result == true); }); }); suppressMessage = false; return(true); } case CefJsDialogType.Prompt: { wfChromiumWebBrowser.Dispatcher.Invoke(() => { JsPromptDialog.ShowDialog(messageText, wfChromiumWebBrowser.Title, defaultPromptText, result => { callback.Continue(result != null, result); }); }); suppressMessage = false; return(true); } } return(false); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { try { var wpfBrowser = browserControl as ChromiumWebBrowser; var window = wpfBrowser?.Parent as PositronWindow; if (window == null) { // Ignore if not within a Positron window callback.Dispose(); suppressMessage = false; return(false); } DialogContext context = dialogType == CefJsDialogType.Prompt ? new PromptDialogContext { PromptText = defaultPromptText } : new DialogContext(); context.Window = window; context.OriginUrl = new Uri(originUrl); context.MessageText = messageText; var dialogHandler = _serviceProvider.GetService <IPositronDialogHandler>(); if (dialogHandler == null) { // Use default behavior callback.Dispose(); suppressMessage = false; return(false); } bool handled; switch (dialogType) { case CefJsDialogType.Alert: handled = HandleAlert(dialogHandler, context, callback); break; case CefJsDialogType.Confirm: handled = HandleConfirmation(dialogHandler, context, callback); break; case CefJsDialogType.Prompt: handled = HandlePrompt(dialogHandler, (PromptDialogContext)context, callback); break; default: handled = false; _logger.LogWarning(LoggerEventIds.UnknownDialogType, "Unknown dialog type: {0}", dialogType); break; } suppressMessage = !handled && context.SuppressDefaultDialog; return(handled); } catch (Exception ex) { _logger.LogError(LoggerEventIds.DialogHandlerError, ex, "Error in IPositronDialogHandler"); callback.Dispose(); suppressMessage = false; return(false); } }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { MainWindow.WriteLog(String.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name)); callback.Continue(true, messageText); return(true); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { var result = false; var form = this._targetForm as Form; try { if (form != null) { form.InvokeActionSafely(() => { form.Focus(); form.TopMost = true; }); } var title = GlobalConfig.AppOptions.Title ?? GlobalConfig.AppOptions.Name ?? "CefBox"; if (dialogType == CefJsDialogType.Alert) { //todo title is configed MessageBox.Show(messageText, title, MessageBoxButtons.OK, MessageBoxIcon.Warning); suppressMessage = true; result = false; } else if (dialogType == CefJsDialogType.Confirm) { var flag = MessageBox.Show(messageText, title, MessageBoxButtons.YesNo, MessageBoxIcon.Information); callback?.Continue(flag == DialogResult.Yes); result = true; } return(result); } finally { if (form != null) { form.InvokeActionSafely(() => form.TopMost = false); } } }
bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { if (messageText == "欢迎登录邮箱") { IFrame frame = browser.GetFrame("emailLogin"); Match mUrl = Regex.Match(frame.Url, @"(http:\/\/" + SysParams.MailWeb + @"\/)(\?login\=1)?", RegexOptions.IgnoreCase); if (mUrl.Groups[1].Success) { if (mUrl.Groups[2].Success) { string js = string.Format(@"document.getElementById('selenium_login_email').value='{0}';", mailAccount); js += string.Format(@"document.getElementById('selenium_login_password').value='{0}';", mailPassWord); js += @"document.getElementById('selenium_login_signin_button').click();"; frame.EvaluateScriptAsync(js); } else { //LoadUrl(string.Format(SysParams.Page_PersonalInfo, SysParams.AppServer, "123")); } } //suppressMessage = false; //return true; } return(false); }
public bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { while (true) { System.Threading.Thread.Sleep(1000); } switch (dialogType) { case CefJsDialogType.Prompt: // alert callback.Continue(true, "asd"); return(true); case CefJsDialogType.Alert: // alert //MessageBox.Show(messageText, "Notice", MessageBoxButton.OK); callback.Continue(true); return(true); case CefJsDialogType.Confirm: // confirm var result = MessageBox.Show(messageText, "Notice", MessageBoxButton.YesNo, MessageBoxImage.Warning); callback.Continue(result == MessageBoxResult.Yes); return(true); } return(false); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { if (dialogType == CefJsDialogType.Alert) { UMessageBox.Show(messageText, "人井监控管理系统", MessageBoxButtons.OK, MessageBoxIcon.Information); suppressMessage = true; return(false); } else { return(true); } }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { if (dialogType == CefJsDialogType.Alert) { suppressMessage = true; MessageBox.Show(messageText, _viewName); return(true); } return(false); }
/// <summary> /// Chrome is showing a dialog /// </summary> public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { switch (dialogType) { case CefJsDialogType.Alert: this.Alert(messageText); //suppressMessage = true; callback.Continue(true); break; case CefJsDialogType.Confirm: //suppressMessage = true; var retVal = this.Confirm(messageText, "Confirm"); callback.Continue(retVal); break; } return(true); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { bool success = false; foreach (var preparedDialog in PreparedDialogActions) { if (preparedDialog.ExpectedDefaultPromptValue == null || (preparedDialog.ExpectedDefaultPromptValue.IsRegex.Value && Regex.IsMatch(defaultPromptText, preparedDialog.ExpectedDefaultPromptValue.Value.Value) || !preparedDialog.ExpectedDefaultPromptValue.IsRegex.Value && defaultPromptText == preparedDialog.ExpectedDefaultPromptValue.Value.Value)) { if (preparedDialog.ExpectedMessageText == null || (preparedDialog.ExpectedMessageText.IsRegex.Value && Regex.IsMatch(messageText, preparedDialog.ExpectedMessageText.Value.Value) || !preparedDialog.ExpectedMessageText.IsRegex.Value && messageText == preparedDialog.ExpectedMessageText.Value.Value)) { if (preparedDialog.ExpectedDialogType == GetJsPrompt.DialogTypes.Nope || (preparedDialog.ExpectedDialogType.ToString() == dialogType.ToString())) { if (callback.IsDisposed) { break; } if (preparedDialog.SetText) { callback.Continue(preparedDialog.SetSuccess, preparedDialog.Text); } else { callback.Continue(preparedDialog.SetSuccess); } HandledJsDialogs.Add(new JsDialog() { DefaultPromptText = defaultPromptText, DialogType = dialogType, MessageText = messageText, OriginUrl = originUrl, Callback = callback, SucessfullyHandled = true, }); return(true); } } } } HandledJsDialogs.Add(new JsDialog() { DefaultPromptText = defaultPromptText, DialogType = dialogType, MessageText = messageText, OriginUrl = originUrl, Callback = callback, SucessfullyHandled = false }); suppressMessage = true; return(false); /* * Different types of dialogs: * Prompt: https://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt * Confirm: https://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm * Alert: https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert */ }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { Log.ShowLog(TAG, "OnJSDialog " + messageText); if (messageText.Contains(VALIED_NG)) { // return true; } return(false); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { bool skipDialog = _preventJsDialogs; string inputText = ""; bool success = true; if (_jsHandlerScript != null) { string dtype = Enum.GetName(typeof(CefJsDialogType), dialogType).ToLower(); // set all values Tools.JSEngine.Instance.SetValue("dialog_type", dtype); Tools.JSEngine.Instance.SetValue("dialog_messageText", messageText); Tools.JSEngine.Instance.SetValue("dialog_url", originUrl); Tools.JSEngine.Instance.SetValue("dialog_success", ""); if (dialogType == CefJsDialogType.Prompt) { Tools.JSEngine.Instance.SetValue("dialog_inputtext", ""); } string result = Tools.JSEngine.Instance.ExecuteResult(_jsHandlerScript, " for parameter '" + _jsHandlerParameterName + "': "); if (result != null) { skipDialog = result.ToLower() == "true"; } if (dialogType == CefJsDialogType.Prompt) { inputText = Tools.JSEngine.Instance.GetValue("dialog_inputtext"); } if (dialogType != CefJsDialogType.Alert) { string succVal = Tools.JSEngine.Instance.GetValue("dialog_success"); if (succVal != null) { success = succVal.ToLower() == "true"; } } } if (skipDialog) { if (dialogType == CefJsDialogType.Prompt) { callback.Continue(success, inputText); } else { callback.Continue(success); } return(true); } else { return(false); } }
public bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { return(logic.OnJSDialog(ConvertDialogType(dialogType), messageText, callback, out suppressMessage)); }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { suppressMessage = true; return false; }
public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { return(false); }
bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage) { if (dialogType != CefJsDialogType.Alert && dialogType != CefJsDialogType.Confirm) { return(false); } ((ChromiumWebBrowser)browserControl).InvokeSafe(() => { FormMessage form = new FormMessage(Program.BrandName, messageText, MessageBoxIcon.None); Button btnConfirm; if (dialogType == CefJsDialogType.Alert) { btnConfirm = form.AddButton("OK"); } else if (dialogType == CefJsDialogType.Confirm) { form.AddButton("No"); btnConfirm = form.AddButton("Yes"); } else { return; } if (form.ShowDialog() == DialogResult.OK && form.ClickedButton == btnConfirm) { callback.Continue(true); } else { callback.Continue(false); } form.Dispose(); }); return(true); }