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_LIFE_SPAN_HANDLER_H_
38 #define CEF_INCLUDE_CEF_LIFE_SPAN_HANDLER_H_
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
47 // Implement this interface to handle events related to browser life span. The
48 // methods of this class will be called on the UI thread unless otherwise
51 /*--cef(source=client)--*/
52 class CefLifeSpanHandler : public virtual CefBase {
54 typedef cef_window_open_disposition_t WindowOpenDisposition;
57 // Called on the IO thread before a new popup browser is created. The
58 // |browser| and |frame| values represent the source of the popup request. The
59 // |target_url| and |target_frame_name| values indicate where the popup
60 // browser should navigate and may be empty if not specified with the request.
61 // The |target_disposition| value indicates where the user intended to open
62 // the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
63 // be true if the popup was opened via explicit user gesture (e.g. clicking a
64 // link) or false if the popup opened automatically (e.g. via the
65 // DomContentLoaded event). The |popupFeatures| structure contains additional
66 // information about the requested popup window. To allow creation of the
67 // popup browser optionally modify |windowInfo|, |client|, |settings| and
68 // |no_javascript_access| and return false. To cancel creation of the popup
69 // browser return true. The |client| and |settings| values will default to the
70 // source browser's values. If the |no_javascript_access| value is set to
71 // false the new browser will not be scriptable and may not be hosted in the
72 // same renderer process as the source browser.
73 /*--cef(optional_param=target_url,optional_param=target_frame_name)--*/
74 virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
75 CefRefPtr<CefFrame> frame,
76 const CefString& target_url,
77 const CefString& target_frame_name,
78 WindowOpenDisposition target_disposition,
80 const CefPopupFeatures& popupFeatures,
81 CefWindowInfo& windowInfo,
82 CefRefPtr<CefClient>& client,
83 CefBrowserSettings& settings,
84 bool* no_javascript_access) {
89 // Called after a new browser is created.
92 virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) {}
95 // Called when a modal window is about to display and the modal loop should
96 // begin running. Return false to use the default modal loop implementation or
97 // true to use a custom implementation.
100 virtual bool RunModal(CefRefPtr<CefBrowser> browser) { return false; }
103 // Called when a browser has recieved a request to close. This may result
104 // directly from a call to CefBrowserHost::CloseBrowser() or indirectly if the
105 // browser is a top-level OS window created by CEF and the user attempts to
106 // close the window. This method will be called after the JavaScript
107 // 'onunload' event has been fired. It will not be called for browsers after
108 // the associated OS window has been destroyed (for those browsers it is no
109 // longer possible to cancel the close).
111 // If CEF created an OS window for the browser returning false will send an OS
112 // close notification to the browser window's top-level owner (e.g. WM_CLOSE
113 // on Windows, performClose: on OS-X and "delete_event" on Linux). If no OS
114 // window exists (window rendering disabled) returning false will cause the
115 // browser object to be destroyed immediately. Return true if the browser is
116 // parented to another window and that other window needs to receive close
117 // notification via some non-standard technique.
119 // If an application provides its own top-level window it should handle OS
120 // close notifications by calling CefBrowserHost::CloseBrowser(false) instead
121 // of immediately closing (see the example below). This gives CEF an
122 // opportunity to process the 'onbeforeunload' event and optionally cancel the
123 // close before DoClose() is called.
125 // The CefLifeSpanHandler::OnBeforeClose() method will be called immediately
126 // before the browser object is destroyed. The application should only exit
127 // after OnBeforeClose() has been called for all existing browsers.
129 // If the browser represents a modal window and a custom modal loop
130 // implementation was provided in CefLifeSpanHandler::RunModal() this callback
131 // should be used to restore the opener window to a usable state.
133 // By way of example consider what should happen during window close when the
134 // browser is parented to an application-provided top-level OS window.
135 // 1. User clicks the window close button which sends an OS close
136 // notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and
137 // "delete_event" on Linux).
138 // 2. Application's top-level window receives the close notification and:
139 // A. Calls CefBrowserHost::CloseBrowser(false).
140 // B. Cancels the window close.
141 // 3. JavaScript 'onbeforeunload' handler executes and shows the close
142 // confirmation dialog (which can be overridden via
143 // CefJSDialogHandler::OnBeforeUnloadDialog()).
144 // 4. User approves the close.
145 // 5. JavaScript 'onunload' handler executes.
146 // 6. Application's DoClose() handler is called. Application will:
147 // A. Set a flag to indicate that the next close attempt will be allowed.
149 // 7. CEF sends an OS close notification.
150 // 8. Application's top-level window receives the OS close notification and
151 // allows the window to close based on the flag from #6B.
152 // 9. Browser OS window is destroyed.
153 // 10. Application's CefLifeSpanHandler::OnBeforeClose() handler is called and
154 // the browser object is destroyed.
155 // 11. Application exits by calling CefQuitMessageLoop() if no other browsers
159 virtual bool DoClose(CefRefPtr<CefBrowser> browser) { return false; }
162 // Called just before a browser is destroyed. Release all references to the
163 // browser object and do not attempt to execute any methods on the browser
164 // object after this callback returns. If this is a modal window and a custom
165 // modal loop implementation was provided in RunModal() this callback should
166 // be used to exit the custom modal loop. See DoClose() documentation for
167 // additional usage information.
170 virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) {}
173 #endif // CEF_INCLUDE_CEF_LIFE_SPAN_HANDLER_H_