]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/cef_life_span_handler.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / cef_life_span_handler.h
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_LIFE_SPAN_HANDLER_H_
38 #define CEF_INCLUDE_CEF_LIFE_SPAN_HANDLER_H_
39 #pragma once
40
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43
44 class CefClient;
45
46 ///
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
49 // indicated.
50 ///
51 /*--cef(source=client)--*/
52 class CefLifeSpanHandler : public virtual CefBase {
53  public:
54   typedef cef_window_open_disposition_t WindowOpenDisposition;
55
56   ///
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,
79                              bool user_gesture,
80                              const CefPopupFeatures& popupFeatures,
81                              CefWindowInfo& windowInfo,
82                              CefRefPtr<CefClient>& client,
83                              CefBrowserSettings& settings,
84                              bool* no_javascript_access) {
85     return false;
86   }
87
88   ///
89   // Called after a new browser is created.
90   ///
91   /*--cef()--*/
92   virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) {}
93
94   ///
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.
98   ///
99   /*--cef()--*/
100   virtual bool RunModal(CefRefPtr<CefBrowser> browser) { return false; }
101
102   ///
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).
110   //
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.
118   //
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.
124   //
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.
128   //
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.
132   //
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.
148   //     B. Return false.
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
156   //     exist.
157   ///
158   /*--cef()--*/
159   virtual bool DoClose(CefRefPtr<CefBrowser> browser) { return false; }
160
161   ///
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.
168   ///
169   /*--cef()--*/
170   virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) {}
171 };
172
173 #endif  // CEF_INCLUDE_CEF_LIFE_SPAN_HANDLER_H_