示例#1
0
        protected ScriptDialogDeferral CreateScriptDialogDeferral(CefJSDialogCallback callback)
        {
            var deferral = new ScriptDialogDeferral(this, callback);

            _scriptDialogDeferral = deferral;
            return(deferral);
        }
示例#2
0
 internal JsDialogEventArgs(CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback)
 {
     DialogType        = dialogType;
     MessageText       = messageText;
     DefaultPromptText = defaultPromptText;
     Callback          = callback;
     SuppressMessage   = false;
     Handled           = false;
 }
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType,
                                           string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            _currentCallback = callback;
            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                _mainWorker.InvokeCefDialog(message_text, default_prompt_text, DialogEventType.Alert);
                break;

            case CefJSDialogType.Confirm:
                _mainWorker.InvokeCefDialog(message_text, default_prompt_text, DialogEventType.Confirm);
                break;

            case CefJSDialogType.Prompt:
                _mainWorker.InvokeCefDialog(message_text, default_prompt_text, DialogEventType.Prompt);
                break;
            }

            suppress_message = false;
            return(true);
        }
示例#4
0
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, string acceptLang,
                                           CefJSDialogType dialogType, string message_text, string default_prompt_text,
                                           CefJSDialogCallback callback, out bool suppress_message)
        {
            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                if (message_text.StartsWith("$Print$"))
                {
                    var str = message_text.Substring(7);
                    var ieb = new IEBrowser();
                    ieb.Print(str);
                    ieb.Show();
                    suppress_message = true;
                    return(false);
                }
                MessageBox.Show(message_text, "系统提示");
                suppress_message = true;
                return(false);

            case CefJSDialogType.Confirm:
                var dr = MessageBox.Show(message_text, "系统提示", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    callback.Continue(true, string.Empty);
                    suppress_message = false;
                    return(true);
                }
                callback.Continue(false, string.Empty);
                suppress_message = false;
                return(true);

            case CefJSDialogType.Prompt:
                MessageBox.Show("系统不支持prompt形式的提示框", "UTMP系统提示");
                break;
            }
            suppress_message = true;
            return(false);
        }
 /// <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="browser"></param>
 /// <param name="messageText"></param>
 /// <param name="isReload"></param>
 /// <param name="callback"></param>
 /// <returns></returns>
 internal protected virtual bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     return(false);
 }
 /// <summary>
 /// Called to run a JavaScript dialog. 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="browser"></param>
 /// <param name="originUrl">
 /// If <paramref name="originUrl"/> is non-empty it can be passed to the CefFormatUrlForSecurityDisplay
 /// function to retrieve a secure and user-friendly display string.
 /// </param>
 /// <param name="dialogType"></param>
 /// <param name="messageText"></param>
 /// <param name="defaultPromptText">
 /// The <paramref name="defaultPromptText"/> value will be specified for prompt dialogs only.
 /// </param>
 /// <param name="callback"></param>
 /// <param name="suppressMessage">
 /// Set <paramref name="suppressMessage"/> to 1 and return false to suppress the message (suppressing messages
 /// is preferable to immediately executing the callback as this is used to detect presumably malicious behavior
 /// like spamming alert messages in onbeforeunload). Set <paramref name="suppressMessage"/> to 0 and return false
 /// to use the default implementation (the default implementation will show one modal dialog at a time and suppress
 /// any additional dialog request until the displayed dialog is dismissed).
 /// </param>
 /// <returns></returns>
 internal protected virtual bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, ref int suppressMessage)
 {
     return(false);
 }
 protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     return(false); // use default
 }
示例#8
0
 protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     return(logic.OnBeforeUnloadDialog(callback));
 }
示例#9
0
 protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     //throw new NotImplementedException();
     return(true);
 }
示例#10
0
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            bool result = false;

            suppress_message = true;
            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                MessageBox.Show(message_text, "POS1");
                break;

            case CefJSDialogType.Confirm:
                MessageBox.Show(message_text, "POS1", MessageBoxButtons.OKCancel);
                break;
            }
            return(result);
        }
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            bool   success = false;
            string input   = null;

            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                success = this.ShowJSAlert(message_text);
                break;

            case CefJSDialogType.Confirm:
                success = this.ShowJSConfirm(message_text);
                break;

            case CefJSDialogType.Prompt:
                success = this.ShowJSPromt(message_text, default_prompt_text, out input);
                break;
            }

            callback.Continue(success, input);
            suppress_message = false;
            return(true);
        }
示例#12
0
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType,
                                           string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            bool   success;
            string input = null;

            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                success = ShowJSAlert(message_text);
                break;

            case CefJSDialogType.Confirm:
                success = ShowJSConfirm(message_text);
                break;

            case CefJSDialogType.Prompt:
                success = ShowJSPromt(message_text, default_prompt_text, out input);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dialogType), dialogType, null);
            }

            callback.Continue(success, input);
            suppress_message = false;
            return(true);
        }
示例#13
0
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                _owner.InvokeIfRequired(() =>
                {
                    MessageBox.Show(_owner.HostWindow, message_text, Resources.Messages.JSDialog_AlertDialog_Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    callback.Continue(true, null);
                });

                suppress_message = false;
                return(true);

            case CefJSDialogType.Confirm:
                _owner.InvokeIfRequired(() =>
                {
                    var retval = MessageBox.Show(_owner.HostWindow, message_text, Resources.Messages.JSDialog_AlertDialog_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (retval == DialogResult.Yes)
                    {
                        callback.Continue(true, null);
                    }
                    else
                    {
                        callback.Continue(false, null);
                    }
                });


                suppress_message = false;
                return(true);
            }

            suppress_message = false;
            return(false);
        }
 protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
 {
     suppress_message = false;
     return(false);
 }
        protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback 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);
        }
示例#16
0
 protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
 {
     if (dialogType == CefJSDialogType.Alert)
     {
         MessageBox.Show(message_text, "CEF");
         suppress_message = true;
         return(false);
     }
     if (dialogType == CefJSDialogType.Confirm)
     {
         DialogResult dialogResult = MessageBox.Show(message_text, "CEF", MessageBoxButtons.OKCancel);
         if (dialogResult == DialogResult.OK)
         {
             callback.Continue(true, string.Empty);
             suppress_message = false;
             return(true);
         }
         if (dialogResult == DialogResult.Cancel)
         {
             callback.Continue(false, string.Empty);
             suppress_message = false;
             return(true);
         }
     }
     suppress_message = true;
     return(false);
 }
示例#17
0
        /// <inheritdoc />
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, ref int suppressMessage)
        {
            ScriptDialogDeferral dialogDeferral = CreateScriptDialogDeferral(callback);
            var ea = new ScriptDialogOpeningRoutedEventArgs(originUrl, (ScriptDialogKind)dialogType, messageText, defaultPromptText, dialogDeferral);

            WebView.RaiseScriptDialogOpening(ea);
            suppressMessage = ea.Suppress ? 1 : 0;
            if (!ea.Handled)
            {
                ((IDisposable)dialogDeferral).Dispose();
            }
            return(ea.Handled);
        }
 public void Continue(bool success, string input)
 {
     _currentCallback?.Continue(success, input);
     _currentCallback = null;
 }
示例#19
0
        /// <inheritdoc />
        protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
        {
            ScriptDialogDeferral dialogDeferral = CreateScriptDialogDeferral(callback);
            var ea = new ScriptDialogOpeningRoutedEventArgs(messageText, isReload, dialogDeferral);

            WebView.RaiseScriptDialogOpening(ea);
            if (!ea.Handled)
            {
                ((IDisposable)dialogDeferral).Dispose();
            }
            return(ea.Handled);
        }
示例#20
0
 protected internal unsafe override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, ref int suppressMessage)
 {
     return(_implementation.OnJSDialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, ref suppressMessage));
 }
示例#21
0
        protected override Boolean OnJSDialog(CefBrowser browser, String originUrl, String acceptLang, CefJSDialogType dialogType, String messageText, String defaultPromptText, CefJSDialogCallback callback, out Boolean suppressMessage)
        {
            Log.Trace("JSDialogHandler.OnJSDialog( browser: {0}, originUrl: {1}, acceptLang: {2}, dialogType: {3}, messageText: {4}, defaultPromptText: {5} )",
                      browser.Identifier,
                      originUrl,
                      acceptLang,
                      Enum.GetName(typeof(CefJSDialogType), dialogType),
                      messageText,
                      defaultPromptText);

            suppressMessage = true;

            switch (dialogType)
            {
            case CefJSDialogType.Alert:

                if (this.Client.HandleJavascriptAlertDialog != null)
                {
                    this.Client.HandleJavascriptAlertDialog(originUrl, messageText);
                    return(true);
                }

                break;

            case CefJSDialogType.Confirm:

                if (this.Client.HandleJavascriptConfirmDialog != null)
                {
                    Boolean confirmed;
                    this.Client.HandleJavascriptConfirmDialog(originUrl, messageText, out confirmed);
                    callback.Continue(confirmed, null);
                    return(true);
                }

                break;

            case CefJSDialogType.Prompt:

                if (this.Client.HandleJavascriptPromptDialog != null)
                {
                    String responseText;
                    this.Client.HandleJavascriptPromptDialog(originUrl, messageText, out responseText);
                    callback.Continue(responseText != null, responseText);
                    return(true);
                }

                break;
            }

            return(false);
        }
示例#22
0
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, string acceptLang, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
        {
            switch (dialogType)
            {
            case CefJSDialogType.Alert:
                //LoadingUtil.ShowInformationMessage(message_text, "系统提示");
                suppress_message = true;
                return(false);

                break;

            case CefJSDialogType.Confirm:
                var dr = MessageBox.Show(message_text, "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    callback.Continue(true, string.Empty);
                    suppress_message = false;
                    return(true);
                }
                else
                {
                    callback.Continue(false, string.Empty);
                    suppress_message = false;
                    return(true);
                }
                break;

            case CefJSDialogType.Prompt:
                //var prompt = new FrmPrompt(message_text, "系统提示", default_prompt_text);
                //if (prompt.ShowDialog() == DialogResult.OK)
                //{
                //    callback.Continue(true, prompt.Content);
                //    suppress_message = false;
                //    return true;
                //}
                //else
                //{
                //    callback.Continue(false, string.Empty);
                //    suppress_message = false;
                //    return true;
                //}
                break;
            }
            suppress_message = true;
            return(false);
        }
示例#23
0
 protected internal override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     return(base.OnBeforeUnloadDialog(browser, messageText, isReload, callback));
 }
示例#24
0
 protected override Boolean OnBeforeUnloadDialog(CefBrowser browser, String messageText, Boolean isReload, CefJSDialogCallback callback)
 {
     Log.Trace("JSDialogHandler.OnBeforeUnloadDialog");
     Log.Trace("JSDialogHandler.OnBeforeUnloadDialog( browser: {0}, messageText: {1}, isReload: {2} )",
               browser.Identifier,
               messageText,
               isReload);
     callback.Continue(true, null);
     return(true);
 }
示例#25
0
 protected internal unsafe override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
 {
     return(_implementation.OnBeforeUnloadDialog(browser, messageText, isReload, callback));
 }
        protected override bool OnJSDialog(CefBrowser browser, string originUrl, string acceptLang, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, out bool suppressMessage)
        {
            var ea = new JsDialogEventArgs(dialogType, messageText, defaultPromptText, callback);

            _core.OnJSDialog(ea);
            suppressMessage = ea.Handled && ea.SuppressMessage;
            return(ea.Handled);
        }
示例#27
0
 protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string messageText, string defaultPromptText, CefJSDialogCallback callback, out bool suppressMessage)
 {
     return(logic.OnJSDialog(ConvertDialogType(dialogType), messageText, callback, out suppressMessage));
 }
        protected override bool OnBeforeUnloadDialog(CefBrowser browser, string messageText, bool isReload, CefJSDialogCallback callback)
        {
            var ea = new UnloadDialogEventArgs(messageText, callback);

            _core.OnBeforeUnloadDialog(ea);
            return(ea.Handled);
        }
 internal UnloadDialogEventArgs(string messageText, CefJSDialogCallback callback)
 {
     MessageText = messageText;
     Callback    = callback;
 }
            protected override bool OnJSDialog(CefBrowser browser, string originUrl, CefJSDialogType dialogType, string message_text, string default_prompt_text, CefJSDialogCallback callback, out bool suppress_message)
            {
                suppress_message = false;

                var javacriptDialogShown = OwnerWebView.JavacriptDialogShown;

                if (javacriptDialogShown == null)
                {
                    return(false);
                }

                void Close()
                {
                    callback.Continue(true, "");
                    callback.Dispose();
                }

                javacriptDialogShown.Invoke(message_text, Close);
                return(true);
            }