示例#1
0
 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;
 }
示例#2
0
        public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
        {
            //NOTE: No need to execute the callback if you return false
            // callback.Continue(true);

            //NOTE: Returning false will trigger the default behaviour, you need to return true to handle yourself.
            return false;
        }
示例#3
0
        //当一个JS alert窗口等在显示的时候,会先调用这个方法,如果返回true,则停止显示窗口,如果返回false,则继续显示窗口
        public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType,
                               string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
        {
            Debug.WriteLine(messageText);

            //callback.Continue(true);
            //return true;

            return(false);
        }
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload,
                              IJsDialogCallback callback)
 {
     //surpressing Is it OK to leave/reload this page?
     if (!callback.IsDisposed)
     {
         callback.Continue(true);
     }
     return(true);
 }
        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;
        }
        /// <summary>
        /// Adds generic ContinueWith for errors and cancellations.
        /// </summary>
        private void HandleErrors(Task task, IJsDialogCallback callback)
        {
            task.ContinueWith(task2 =>
            {
                using (callback)
                {
                    if (task2.IsFaulted)
                    {
                        _logger.LogError(LoggerEventIds.DialogHandlerError, task2.Exception,
                                         "Error in IPositronDialogHandler");

                        callback.Continue(false);
                    }
                    else
                    {
                        _logger.LogError(LoggerEventIds.DialogHandlerError, "Cancellation in IPositronDialogHandler");

                        callback.Continue(false);
                    }
                }
            }, TaskContinuationOptions.NotOnRanToCompletion);
        }
示例#7
0
 bool IJsDialogHandler.OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
 {
     return(true);
 }
示例#8
0
 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));
 }
示例#9
0
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser,
                              string message, bool isReload, IJsDialogCallback callback)
 {
     return(false);
 }
示例#10
0
 bool IJsDialogHandler.OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
 {
     return(false);
 }
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
 {
     callback.Continue(true);
     return(true);
 }
示例#12
0
 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);
 }
示例#13
0
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
 {
     throw new NotImplementedException();
 }
        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
             */
        }
示例#15
0
 /// <summary>
 /// Called to run a dialog asking the user if they want to leave a page. Return false to use the default dialog implementation.
 /// Return true if the application will use a custom dialog or if the callback has been executed immediately.
 /// Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute <paramref name="callback"/>
 /// once the custom dialog is dismissed.
 /// </summary>
 /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
 /// <param name="browser">the browser object</param>
 /// <param name="messageText">message text (optional)</param>
 /// <param name="isReload">indicates a page reload</param>
 /// <param name="callback">Callback can be executed inline or in an async fashion</param>
 /// <returns>Return false to use the default dialog implementation otherwise return true to handle with your own custom implementation.</returns>
 protected virtual bool OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
 {
     return(false);
 }
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
 { return true; }
示例#17
0
        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);
        }
示例#18
0
            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);
            }
示例#19
0
 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);
 }
示例#20
0
        public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
        {
            //NOTE: No need to execute the callback if you return false
            // callback.Continue(true);

            //NOTE: Returning false will trigger the default behaviour, you need to return true to handle yourself.
            return(false);
        }
示例#21
0
 /// <summary>
 /// Called to run a dialog asking the user if they want to leave a page. Return false to use the default dialog implementation.
 /// Return true if the application will use a custom dialog or if the callback has been executed immediately.
 /// Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute <paramref name="callback"/>
 /// once the custom dialog is dismissed.
 /// </summary>
 /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
 /// <param name="browser">the browser object</param>
 /// <param name="messageText">message text (optional)</param>
 /// <param name="isReload">indicates a page reload</param>
 /// <param name="callback">Callback can be executed inline or in an async fashion</param>
 /// <returns>Return false to use the default dialog implementation otherwise return true to handle with your own custom implementation.</returns>
 bool IJsDialogHandler.OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
 {
     return(OnBeforeUnloadDialog(chromiumWebBrowser, browser, messageText, isReload, callback));
 }
示例#22
0
 public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
 {
     throw new NotImplementedException();
 }
示例#23
0
 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);
     }
 }
示例#24
0
        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);
            }
        }
        /// <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);
        }
示例#26
0
 public bool OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
 {
     throw new NotImplementedException();
 }
示例#27
0
        bool IJsDialogHandler.OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
        {
            //Custom implementation would look something like
            // - Create/Show dialog on UI Thread
            // - execute callback once user has responded
            // - callback.Continue(true);
            // - return true

            //NOTE: Returning false will trigger the default behaviour, no need to execute the callback if you return false.
            return(false);
        }
示例#28
0
 public bool OnJSBeforeUnload(IWebBrowser browserControl, IBrowser browser, string message, bool isReload, IJsDialogCallback callback)
 {
     //No need to execute the callback if we return false.
     return false;
 }
示例#29
0
 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);
 }
示例#30
0
 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 OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
 {
     callback.Continue(true);
     return(true);
 }
        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);
        }
示例#33
0
 public bool OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
 {
     return(logic.OnBeforeUnloadDialog(callback));
 }
示例#34
0
        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);
                }
            }
        }
示例#35
0
 public bool OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl,
                        string acceptLang, CefJsDialogType dialogType, string messageText, string defaultPromptText,
                        IJsDialogCallback callback, ref bool suppressMessage)
 {
     return(false);
 }
示例#36
0
        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);
        }