• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2022 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 // This file was generated by the CEF translator tool and should not edited
33 // by hand. See the translator.README.txt file in the tools directory for
34 // more information.
35 //
36 // $hash=34a6559587adbd0dc3143989a8c6e49e0664b43e$
37 //
38 
39 #ifndef CEF_INCLUDE_CAPI_CEF_LIFE_SPAN_HANDLER_CAPI_H_
40 #define CEF_INCLUDE_CAPI_CEF_LIFE_SPAN_HANDLER_CAPI_H_
41 #pragma once
42 
43 #include "include/capi/cef_base_capi.h"
44 #include "include/capi/cef_browser_capi.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 struct _cef_client_t;
51 
52 ///
53 // Implement this structure to handle events related to browser life span. The
54 // functions of this structure will be called on the UI thread unless otherwise
55 // indicated.
56 ///
57 typedef struct _cef_life_span_handler_t {
58   ///
59   // Base structure.
60   ///
61   cef_base_ref_counted_t base;
62 
63   ///
64   // Called on the UI thread before a new popup browser is created. The
65   // |browser| and |frame| values represent the source of the popup request. The
66   // |target_url| and |target_frame_name| values indicate where the popup
67   // browser should navigate and may be NULL if not specified with the request.
68   // The |target_disposition| value indicates where the user intended to open
69   // the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
70   // be true (1) if the popup was opened via explicit user gesture (e.g.
71   // clicking a link) or false (0) if the popup opened automatically (e.g. via
72   // the DomContentLoaded event). The |popupFeatures| structure contains
73   // additional information about the requested popup window. To allow creation
74   // of the popup browser optionally modify |windowInfo|, |client|, |settings|
75   // and |no_javascript_access| and return false (0). To cancel creation of the
76   // popup browser return true (1). The |client| and |settings| values will
77   // default to the source browser's values. If the |no_javascript_access| value
78   // is set to false (0) the new browser will not be scriptable and may not be
79   // hosted in the same renderer process as the source browser. Any
80   // modifications to |windowInfo| will be ignored if the parent browser is
81   // wrapped in a cef_browser_view_t. Popup browser creation will be canceled if
82   // the parent browser is destroyed before the popup browser creation completes
83   // (indicated by a call to OnAfterCreated for the popup browser). The
84   // |extra_info| parameter provides an opportunity to specify extra information
85   // specific to the created popup browser that will be passed to
86   // cef_render_process_handler_t::on_browser_created() in the render process.
87   ///
88   int(CEF_CALLBACK* on_before_popup)(
89       struct _cef_life_span_handler_t* self,
90       struct _cef_browser_t* browser,
91       struct _cef_frame_t* frame,
92       const cef_string_t* target_url,
93       const cef_string_t* target_frame_name,
94       cef_window_open_disposition_t target_disposition,
95       int user_gesture,
96       const struct _cef_popup_features_t* popupFeatures,
97       struct _cef_window_info_t* windowInfo,
98       struct _cef_client_t** client,
99       struct _cef_browser_settings_t* settings,
100       struct _cef_dictionary_value_t** extra_info,
101       int* no_javascript_access);
102 
103   ///
104   // Called after a new browser is created. It is now safe to begin performing
105   // actions with |browser|. cef_frame_handler_t callbacks related to initial
106   // main frame creation will arrive before this callback. See
107   // cef_frame_handler_t documentation for additional usage information.
108   ///
109   void(CEF_CALLBACK* on_after_created)(struct _cef_life_span_handler_t* self,
110                                        struct _cef_browser_t* browser);
111 
112   ///
113   // Called when a browser has recieved a request to close. This may result
114   // directly from a call to cef_browser_host_t::*close_browser() or indirectly
115   // if the browser is parented to a top-level window created by CEF and the
116   // user attempts to close that window (by clicking the 'X', for example). The
117   // do_close() function will be called after the JavaScript 'onunload' event
118   // has been fired.
119   //
120   // An application should handle top-level owner window close notifications by
121   // calling cef_browser_host_t::try_close_browser() or
122   // cef_browser_host_t::CloseBrowser(false (0)) instead of allowing the window
123   // to close immediately (see the examples below). This gives CEF an
124   // opportunity to process the 'onbeforeunload' event and optionally cancel the
125   // close before do_close() is called.
126   //
127   // When windowed rendering is enabled CEF will internally create a window or
128   // view to host the browser. In that case returning false (0) from do_close()
129   // will send the standard close notification to the browser's top-level owner
130   // window (e.g. WM_CLOSE on Windows, performClose: on OS X, "delete_event" on
131   // Linux or cef_window_delegate_t::can_close() callback from Views). If the
132   // browser's host window/view has already been destroyed (via view hierarchy
133   // tear-down, for example) then do_close() will not be called for that browser
134   // since is no longer possible to cancel the close.
135   //
136   // When windowed rendering is disabled returning false (0) from do_close()
137   // will cause the browser object to be destroyed immediately.
138   //
139   // If the browser's top-level owner window requires a non-standard close
140   // notification then send that notification from do_close() and return true
141   // (1).
142   //
143   // The cef_life_span_handler_t::on_before_close() function will be called
144   // after do_close() (if do_close() is called) and immediately before the
145   // browser object is destroyed. The application should only exit after
146   // on_before_close() has been called for all existing browsers.
147   //
148   // The below examples describe what should happen during window close when the
149   // browser is parented to an application-provided top-level window.
150   //
151   // Example 1: Using cef_browser_host_t::try_close_browser(). This is
152   // recommended for clients using standard close handling and windows created
153   // on the browser process UI thread. 1.  User clicks the window close button
154   // which sends a close notification to
155   //     the application's top-level window.
156   // 2.  Application's top-level window receives the close notification and
157   //     calls TryCloseBrowser() (which internally calls CloseBrowser(false)).
158   //     TryCloseBrowser() returns false so the client cancels the window close.
159   // 3.  JavaScript 'onbeforeunload' handler executes and shows the close
160   //     confirmation dialog (which can be overridden via
161   //     CefJSDialogHandler::OnBeforeUnloadDialog()).
162   // 4.  User approves the close. 5.  JavaScript 'onunload' handler executes. 6.
163   // CEF sends a close notification to the application's top-level window
164   //     (because DoClose() returned false by default).
165   // 7.  Application's top-level window receives the close notification and
166   //     calls TryCloseBrowser(). TryCloseBrowser() returns true so the client
167   //     allows the window close.
168   // 8.  Application's top-level window is destroyed. 9.  Application's
169   // on_before_close() handler is called and the browser object
170   //     is destroyed.
171   // 10. Application exits by calling cef_quit_message_loop() if no other
172   // browsers
173   //     exist.
174   //
175   // Example 2: Using cef_browser_host_t::CloseBrowser(false (0)) and
176   // implementing the do_close() callback. This is recommended for clients using
177   // non-standard close handling or windows that were not created on the browser
178   // process UI thread. 1.  User clicks the window close button which sends a
179   // close notification to
180   //     the application's top-level window.
181   // 2.  Application's top-level window receives the close notification and:
182   //     A. Calls CefBrowserHost::CloseBrowser(false).
183   //     B. Cancels the window close.
184   // 3.  JavaScript 'onbeforeunload' handler executes and shows the close
185   //     confirmation dialog (which can be overridden via
186   //     CefJSDialogHandler::OnBeforeUnloadDialog()).
187   // 4.  User approves the close. 5.  JavaScript 'onunload' handler executes. 6.
188   // Application's do_close() handler is called. Application will:
189   //     A. Set a flag to indicate that the next close attempt will be allowed.
190   //     B. Return false.
191   // 7.  CEF sends an close notification to the application's top-level window.
192   // 8.  Application's top-level window receives the close notification and
193   //     allows the window to close based on the flag from #6B.
194   // 9.  Application's top-level window is destroyed. 10. Application's
195   // on_before_close() handler is called and the browser object
196   //     is destroyed.
197   // 11. Application exits by calling cef_quit_message_loop() if no other
198   // browsers
199   //     exist.
200   ///
201   int(CEF_CALLBACK* do_close)(struct _cef_life_span_handler_t* self,
202                               struct _cef_browser_t* browser);
203 
204   ///
205   // Called just before a browser is destroyed. Release all references to the
206   // browser object and do not attempt to execute any functions on the browser
207   // object (other than IsValid, GetIdentifier or IsSame) after this callback
208   // returns. cef_frame_handler_t callbacks related to final main frame
209   // destruction will arrive after this callback and cef_browser_t::IsValid will
210   // return false (0) at that time. Any in-progress network requests associated
211   // with |browser| will be aborted when the browser is destroyed, and
212   // cef_resource_request_handler_t callbacks related to those requests may
213   // still arrive on the IO thread after this callback. See cef_frame_handler_t
214   // and do_close() documentation for additional usage information.
215   ///
216   void(CEF_CALLBACK* on_before_close)(struct _cef_life_span_handler_t* self,
217                                       struct _cef_browser_t* browser);
218 } cef_life_span_handler_t;
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif  // CEF_INCLUDE_CAPI_CEF_LIFE_SPAN_HANDLER_CAPI_H_
225