1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_
38 #define CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
45 // Callback interface used for asynchronous continuation of JavaScript dialog
48 /*--cef(source=library)--*/
49 class CefJSDialogCallback : public virtual CefBase {
52 // Continue the JS dialog request. Set |success| to true if the OK button was
53 // pressed. The |user_input| value should be specified for prompt dialogs.
55 /*--cef(capi_name=cont,optional_param=user_input)--*/
56 virtual void Continue(bool success,
57 const CefString& user_input) =0;
62 // Implement this interface to handle events related to JavaScript dialogs. The
63 // methods of this class will be called on the UI thread.
65 /*--cef(source=client)--*/
66 class CefJSDialogHandler : public virtual CefBase {
68 typedef cef_jsdialog_type_t JSDialogType;
71 // Called to run a JavaScript dialog. The |default_prompt_text| value will be
72 // specified for prompt dialogs only. Set |suppress_message| to true and
73 // return false to suppress the message (suppressing messages is preferable
74 // to immediately executing the callback as this is used to detect presumably
75 // malicious behavior like spamming alert messages in onbeforeunload). Set
76 // |suppress_message| to false and return false to use the default
77 // implementation (the default implementation will show one modal dialog at a
78 // time and suppress any additional dialog requests until the displayed dialog
79 // is dismissed). Return true if the application will use a custom dialog or
80 // if the callback has been executed immediately. Custom dialogs may be either
81 // modal or modeless. If a custom dialog is used the application must execute
82 // |callback| once the custom dialog is dismissed.
84 /*--cef(optional_param=origin_url,optional_param=accept_lang,
85 optional_param=message_text,optional_param=default_prompt_text)--*/
86 virtual bool OnJSDialog(CefRefPtr<CefBrowser> browser,
87 const CefString& origin_url,
88 const CefString& accept_lang,
89 JSDialogType dialog_type,
90 const CefString& message_text,
91 const CefString& default_prompt_text,
92 CefRefPtr<CefJSDialogCallback> callback,
93 bool& suppress_message) {
98 // Called to run a dialog asking the user if they want to leave a page. Return
99 // false to use the default dialog implementation. Return true if the
100 // application will use a custom dialog or if the callback has been executed
101 // immediately. Custom dialogs may be either modal or modeless. If a custom
102 // dialog is used the application must execute |callback| once the custom
103 // dialog is dismissed.
105 /*--cef(optional_param=message_text)--*/
106 virtual bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
107 const CefString& message_text,
109 CefRefPtr<CefJSDialogCallback> callback) {
114 // Called to cancel any pending dialogs and reset any saved dialog state. Will
115 // be called due to events like page navigation irregardless of whether any
116 // dialogs are currently pending.
119 virtual void OnResetDialogState(CefRefPtr<CefBrowser> browser) {}
122 // Called when the default implementation dialog is closed.
125 virtual void OnDialogClosed(CefRefPtr<CefBrowser> browser) {}
128 #endif // CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_