• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
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
12 // distribution.
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.
17 //
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.
29 //
30 // ---------------------------------------------------------------------------
31 //
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.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_
38 #define CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43 
44 ///
45 // Callback interface used for asynchronous continuation of JavaScript dialog
46 // requests.
47 ///
48 /*--cef(source=library)--*/
49 class CefJSDialogCallback : public virtual CefBaseRefCounted {
50  public:
51   ///
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.
54   ///
55   /*--cef(capi_name=cont,optional_param=user_input)--*/
56   virtual void Continue(bool success, const CefString& user_input) = 0;
57 };
58 
59 ///
60 // Implement this interface to handle events related to JavaScript dialogs. The
61 // methods of this class will be called on the UI thread.
62 ///
63 /*--cef(source=client)--*/
64 class CefJSDialogHandler : public virtual CefBaseRefCounted {
65  public:
66   typedef cef_jsdialog_type_t JSDialogType;
67 
68   ///
69   // Called to run a JavaScript dialog. If |origin_url| is non-empty it can be
70   // passed to the CefFormatUrlForSecurityDisplay function to retrieve a secure
71   // and user-friendly display string. 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 to
74   // 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.
83   ///
84   /*--cef(optional_param=origin_url,optional_param=accept_lang,
85           optional_param=message_text,optional_param=default_prompt_text)--*/
OnJSDialog(CefRefPtr<CefBrowser> browser,const CefString & origin_url,JSDialogType dialog_type,const CefString & message_text,const CefString & default_prompt_text,CefRefPtr<CefJSDialogCallback> callback,bool & suppress_message)86   virtual bool OnJSDialog(CefRefPtr<CefBrowser> browser,
87                           const CefString& origin_url,
88                           JSDialogType dialog_type,
89                           const CefString& message_text,
90                           const CefString& default_prompt_text,
91                           CefRefPtr<CefJSDialogCallback> callback,
92                           bool& suppress_message) {
93     return false;
94   }
95 
96   ///
97   // Called to run a dialog asking the user if they want to leave a page. Return
98   // false to use the default dialog implementation. Return true if the
99   // application will use a custom dialog or if the callback has been executed
100   // immediately. Custom dialogs may be either modal or modeless. If a custom
101   // dialog is used the application must execute |callback| once the custom
102   // dialog is dismissed.
103   ///
104   /*--cef(optional_param=message_text)--*/
OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,const CefString & message_text,bool is_reload,CefRefPtr<CefJSDialogCallback> callback)105   virtual bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
106                                     const CefString& message_text,
107                                     bool is_reload,
108                                     CefRefPtr<CefJSDialogCallback> callback) {
109     return false;
110   }
111 
112   ///
113   // Called to cancel any pending dialogs and reset any saved dialog state. Will
114   // be called due to events like page navigation irregardless of whether any
115   // dialogs are currently pending.
116   ///
117   /*--cef()--*/
OnResetDialogState(CefRefPtr<CefBrowser> browser)118   virtual void OnResetDialogState(CefRefPtr<CefBrowser> browser) {}
119 
120   ///
121   // Called when the default implementation dialog is closed.
122   ///
123   /*--cef()--*/
OnDialogClosed(CefRefPtr<CefBrowser> browser)124   virtual void OnDialogClosed(CefRefPtr<CefBrowser> browser) {}
125 };
126 
127 #endif  // CEF_INCLUDE_CEF_JSDIALOG_HANDLER_H_
128