kyy
2025-07-02 07558e32634314eec359ec8437d97bdc5def64f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
 
namespace CefSharp.Handler
{
    /// <summary>
    /// Inherit from this class to handle events related to JavaScript dialogs.
    /// The methods of this class will be called on the CEF UI thread. 
    /// </summary>
    public class JsDialogHandler : IJsDialogHandler
    {
        /// <summary>
        /// Called to run a JavaScript dialog.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        /// <param name="originUrl">originating url</param>
        /// <param name="dialogType">Dialog Type</param>
        /// <param name="messageText">Message Text</param>
        /// <param name="defaultPromptText">value will be specified for prompt dialogs only</param>
        /// <param name="callback">Callback can be executed inline or in an async fashion</param>
        /// <param name="suppressMessage">Set suppressMessage to true 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 suppressMessage to false and return false to use the default implementation (the default implementation will show one modal dialog at a time and suppress any additional dialog requests until the displayed dialog is dismissed).</param>
        /// <returns>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 |callback| once the custom dialog is dismissed.</returns>
        bool IJsDialogHandler.OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
        {
            return OnJSDialog(chromiumWebBrowser, browser, originUrl, dialogType, messageText, defaultPromptText, callback, ref suppressMessage);
        }
 
        /// <summary>
        /// Called to run a JavaScript dialog.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        /// <param name="originUrl">originating url</param>
        /// <param name="dialogType">Dialog Type</param>
        /// <param name="messageText">Message Text</param>
        /// <param name="defaultPromptText">value will be specified for prompt dialogs only</param>
        /// <param name="callback">Callback can be executed inline or in an async fashion</param>
        /// <param name="suppressMessage">Set suppressMessage to true 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 suppressMessage to false and return false to use the default implementation (the default implementation will show one modal dialog at a time and suppress any additional dialog requests until the displayed dialog is dismissed).</param>
        /// <returns>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 |callback| once the custom dialog is dismissed.</returns>
        protected virtual bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
        {
            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="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);
        }
 
        /// <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;
        }
 
        /// <summary>
        /// Called to cancel any pending dialogs and reset any saved dialog state. Will
        /// be called due to events like page navigation irregardless of whether any
        /// dialogs are currently pending.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        void IJsDialogHandler.OnResetDialogState(IWebBrowser chromiumWebBrowser, IBrowser browser)
        {
            OnResetDialogState(chromiumWebBrowser, browser);
        }
 
        /// <summary>
        /// Called to cancel any pending dialogs and reset any saved dialog state. Will
        /// be called due to events like page navigation irregardless of whether any
        /// dialogs are currently pending.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        protected virtual void OnResetDialogState(IWebBrowser chromiumWebBrowser, IBrowser browser)
        {
 
        }
 
        /// <summary>
        /// Called when the default implementation dialog is closed.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        void IJsDialogHandler.OnDialogClosed(IWebBrowser chromiumWebBrowser, IBrowser browser)
        {
            OnDialogClosed(chromiumWebBrowser, browser);
        }
 
        /// <summary>
        /// Called when the default implementation dialog is closed.
        /// </summary>
        /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>
        /// <param name="browser">the browser object</param>
        protected virtual void OnDialogClosed(IWebBrowser chromiumWebBrowser, IBrowser browser)
        {
 
        }
    }
}