1 // Copyright (c) 2021 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=d7521ac4f73dabd876344400a165d15954c770b0$ 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. This callback will be the first 105 // notification that references |browser|. 106 /// 107 void(CEF_CALLBACK* on_after_created)(struct _cef_life_span_handler_t* self, 108 struct _cef_browser_t* browser); 109 110 /// 111 // Called when a browser has recieved a request to close. This may result 112 // directly from a call to cef_browser_host_t::*close_browser() or indirectly 113 // if the browser is parented to a top-level window created by CEF and the 114 // user attempts to close that window (by clicking the 'X', for example). The 115 // do_close() function will be called after the JavaScript 'onunload' event 116 // has been fired. 117 // 118 // An application should handle top-level owner window close notifications by 119 // calling cef_browser_host_t::try_close_browser() or 120 // cef_browser_host_t::CloseBrowser(false (0)) instead of allowing the window 121 // to close immediately (see the examples below). This gives CEF an 122 // opportunity to process the 'onbeforeunload' event and optionally cancel the 123 // close before do_close() is called. 124 // 125 // When windowed rendering is enabled CEF will internally create a window or 126 // view to host the browser. In that case returning false (0) from do_close() 127 // will send the standard close notification to the browser's top-level owner 128 // window (e.g. WM_CLOSE on Windows, performClose: on OS X, "delete_event" on 129 // Linux or cef_window_delegate_t::can_close() callback from Views). If the 130 // browser's host window/view has already been destroyed (via view hierarchy 131 // tear-down, for example) then do_close() will not be called for that browser 132 // since is no longer possible to cancel the close. 133 // 134 // When windowed rendering is disabled returning false (0) from do_close() 135 // will cause the browser object to be destroyed immediately. 136 // 137 // If the browser's top-level owner window requires a non-standard close 138 // notification then send that notification from do_close() and return true 139 // (1). 140 // 141 // The cef_life_span_handler_t::on_before_close() function will be called 142 // after do_close() (if do_close() is called) and immediately before the 143 // browser object is destroyed. The application should only exit after 144 // on_before_close() has been called for all existing browsers. 145 // 146 // The below examples describe what should happen during window close when the 147 // browser is parented to an application-provided top-level window. 148 // 149 // Example 1: Using cef_browser_host_t::try_close_browser(). This is 150 // recommended for clients using standard close handling and windows created 151 // on the browser process UI thread. 1. User clicks the window close button 152 // which sends a close notification to 153 // the application's top-level window. 154 // 2. Application's top-level window receives the close notification and 155 // calls TryCloseBrowser() (which internally calls CloseBrowser(false)). 156 // TryCloseBrowser() returns false so the client cancels the window close. 157 // 3. JavaScript 'onbeforeunload' handler executes and shows the close 158 // confirmation dialog (which can be overridden via 159 // CefJSDialogHandler::OnBeforeUnloadDialog()). 160 // 4. User approves the close. 5. JavaScript 'onunload' handler executes. 6. 161 // CEF sends a close notification to the application's top-level window 162 // (because DoClose() returned false by default). 163 // 7. Application's top-level window receives the close notification and 164 // calls TryCloseBrowser(). TryCloseBrowser() returns true so the client 165 // allows the window close. 166 // 8. Application's top-level window is destroyed. 9. Application's 167 // on_before_close() handler is called and the browser object 168 // is destroyed. 169 // 10. Application exits by calling cef_quit_message_loop() if no other 170 // browsers 171 // exist. 172 // 173 // Example 2: Using cef_browser_host_t::CloseBrowser(false (0)) and 174 // implementing the do_close() callback. This is recommended for clients using 175 // non-standard close handling or windows that were not created on the browser 176 // process UI thread. 1. User clicks the window close button which sends a 177 // close notification to 178 // the application's top-level window. 179 // 2. Application's top-level window receives the close notification and: 180 // A. Calls CefBrowserHost::CloseBrowser(false). 181 // B. Cancels the window close. 182 // 3. JavaScript 'onbeforeunload' handler executes and shows the close 183 // confirmation dialog (which can be overridden via 184 // CefJSDialogHandler::OnBeforeUnloadDialog()). 185 // 4. User approves the close. 5. JavaScript 'onunload' handler executes. 6. 186 // Application's do_close() handler is called. Application will: 187 // A. Set a flag to indicate that the next close attempt will be allowed. 188 // B. Return false. 189 // 7. CEF sends an close notification to the application's top-level window. 190 // 8. Application's top-level window receives the close notification and 191 // allows the window to close based on the flag from #6B. 192 // 9. Application's top-level window is destroyed. 10. Application's 193 // on_before_close() handler is called and the browser object 194 // is destroyed. 195 // 11. Application exits by calling cef_quit_message_loop() if no other 196 // browsers 197 // exist. 198 /// 199 int(CEF_CALLBACK* do_close)(struct _cef_life_span_handler_t* self, 200 struct _cef_browser_t* browser); 201 202 /// 203 // Called just before a browser is destroyed. Release all references to the 204 // browser object and do not attempt to execute any functions on the browser 205 // object (other than GetIdentifier or IsSame) after this callback returns. 206 // This callback will be the last notification that references |browser| on 207 // the UI thread. Any in-progress network requests associated with |browser| 208 // will be aborted when the browser is destroyed, and 209 // cef_resource_request_handler_t callbacks related to those requests may 210 // still arrive on the IO thread after this function is called. See do_close() 211 // documentation for additional usage information. 212 /// 213 void(CEF_CALLBACK* on_before_close)(struct _cef_life_span_handler_t* self, 214 struct _cef_browser_t* browser); 215 } cef_life_span_handler_t; 216 217 #ifdef __cplusplus 218 } 219 #endif 220 221 #endif // CEF_INCLUDE_CAPI_CEF_LIFE_SPAN_HANDLER_CAPI_H_ 222