|
6 | 6 | #include "cefpython_public_api.h" |
7 | 7 | #include "DebugLog.h" |
8 | 8 |
|
| 9 | +// ---------------------------------------------------------------------------- |
| 10 | +// CefClient |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | + |
9 | 13 | bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, |
10 | 14 | CefProcessId source_process, |
11 | 15 | CefRefPtr<CefProcessMessage> message) { |
@@ -59,18 +63,6 @@ bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, |
59 | 63 | ", messageName = V8FunctionHandler::Execute"); |
60 | 64 | return false; |
61 | 65 | } |
62 | | - } else if (messageName == "OnBrowserDestroyed") { |
63 | | - CefRefPtr<CefListValue> arguments = message->GetArgumentList(); |
64 | | - if (arguments->GetSize() == 1 && arguments->GetType(0) == VTYPE_INT) { |
65 | | - int browserId = arguments->GetInt(0); |
66 | | - // NOT browser->GetIdentifier()! |
67 | | - ProcessMessage_OnBrowserDestroyed(browserId); |
68 | | - return true; |
69 | | - } else { |
70 | | - DebugLog("Browser: OnProcessMessageReceived(): invalid arguments" \ |
71 | | - ", messageName = OnBrowserDestroyed"); |
72 | | - return false; |
73 | | - } |
74 | 66 | } else if (messageName == "ExecutePythonCallback") { |
75 | 67 | CefRefPtr<CefListValue> arguments = message->GetArgumentList(); |
76 | 68 | if (arguments->GetSize() == 2 |
@@ -99,3 +91,126 @@ bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, |
99 | 91 | } |
100 | 92 | return false; |
101 | 93 | } |
| 94 | + |
| 95 | +// ---------------------------------------------------------------------------- |
| 96 | +// CefLifeSpanHandler |
| 97 | +// ---------------------------------------------------------------------------- |
| 98 | + |
| 99 | +/// |
| 100 | +// Called on the IO thread before a new popup window is created. The |browser| |
| 101 | +// and |frame| parameters represent the source of the popup request. The |
| 102 | +// |target_url| and |target_frame_name| values may be empty if none were |
| 103 | +// specified with the request. The |popupFeatures| structure contains |
| 104 | +// information about the requested popup window. To allow creation of the |
| 105 | +// popup window optionally modify |windowInfo|, |client|, |settings| and |
| 106 | +// |no_javascript_access| and return false. To cancel creation of the popup |
| 107 | +// window return true. The |client| and |settings| values will default to the |
| 108 | +// source browser's values. The |no_javascript_access| value indicates whether |
| 109 | +// the new browser window should be scriptable and in the same process as the |
| 110 | +// source browser. |
| 111 | +/*--cef(optional_param=target_url,optional_param=target_frame_name)--*/ |
| 112 | +bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser, |
| 113 | + CefRefPtr<CefFrame> frame, |
| 114 | + const CefString& target_url, |
| 115 | + const CefString& target_frame_name, |
| 116 | + const CefPopupFeatures& popupFeatures, |
| 117 | + CefWindowInfo& windowInfo, |
| 118 | + CefRefPtr<CefClient>& client, |
| 119 | + CefBrowserSettings& settings, |
| 120 | + bool* no_javascript_access) { |
| 121 | + return false; |
| 122 | +} |
| 123 | + |
| 124 | +/// |
| 125 | +// Called after a new browser is created. |
| 126 | +/// |
| 127 | +/*--cef()--*/ |
| 128 | +void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) { |
| 129 | +} |
| 130 | + |
| 131 | +/// |
| 132 | +// Called when a modal window is about to display and the modal loop should |
| 133 | +// begin running. Return false to use the default modal loop implementation or |
| 134 | +// true to use a custom implementation. |
| 135 | +/// |
| 136 | +/*--cef()--*/ |
| 137 | +bool ClientHandler::RunModal(CefRefPtr<CefBrowser> browser) { |
| 138 | + return false; |
| 139 | +} |
| 140 | + |
| 141 | +/// |
| 142 | +// Called when a browser has recieved a request to close. This may result |
| 143 | +// directly from a call to CefBrowserHost::CloseBrowser() or indirectly if the |
| 144 | +// browser is a top-level OS window created by CEF and the user attempts to |
| 145 | +// close the window. This method will be called after the JavaScript |
| 146 | +// 'onunload' event has been fired. It will not be called for browsers after |
| 147 | +// the associated OS window has been destroyed (for those browsers it is no |
| 148 | +// longer possible to cancel the close). |
| 149 | +// |
| 150 | +// If CEF created an OS window for the browser returning false will send an OS |
| 151 | +// close notification to the browser window's top-level owner (e.g. WM_CLOSE |
| 152 | +// on Windows, performClose: on OS-X and "delete_event" on Linux). If no OS |
| 153 | +// window exists (window rendering disabled) returning false will cause the |
| 154 | +// browser object to be destroyed immediately. Return true if the browser is |
| 155 | +// parented to another window and that other window needs to receive close |
| 156 | +// notification via some non-standard technique. |
| 157 | +// |
| 158 | +// If an application provides its own top-level window it should handle OS |
| 159 | +// close notifications by calling CefBrowserHost::CloseBrowser(false) instead |
| 160 | +// of immediately closing (see the example below). This gives CEF an |
| 161 | +// opportunity to process the 'onbeforeunload' event and optionally cancel the |
| 162 | +// close before DoClose() is called. |
| 163 | +// |
| 164 | +// The CefLifeSpanHandler::OnBeforeClose() method will be called immediately |
| 165 | +// before the browser object is destroyed. The application should only exit |
| 166 | +// after OnBeforeClose() has been called for all existing browsers. |
| 167 | +// |
| 168 | +// If the browser represents a modal window and a custom modal loop |
| 169 | +// implementation was provided in CefLifeSpanHandler::RunModal() this callback |
| 170 | +// should be used to restore the opener window to a usable state. |
| 171 | +// |
| 172 | +// By way of example consider what should happen during window close when the |
| 173 | +// browser is parented to an application-provided top-level OS window. |
| 174 | +// 1. User clicks the window close button which sends an OS close |
| 175 | +// notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and |
| 176 | +// "delete_event" on Linux). |
| 177 | +// 2. Application's top-level window receives the close notification and: |
| 178 | +// A. Calls CefBrowserHost::CloseBrowser(false). |
| 179 | +// B. Cancels the window close. |
| 180 | +// 3. JavaScript 'onbeforeunload' handler executes and shows the close |
| 181 | +// confirmation dialog (which can be overridden via |
| 182 | +// CefJSDialogHandler::OnBeforeUnloadDialog()). |
| 183 | +// 4. User approves the close. |
| 184 | +// 5. JavaScript 'onunload' handler executes. |
| 185 | +// 6. Application's DoClose() handler is called. Application will: |
| 186 | +// A. Call CefBrowserHost::ParentWindowWillClose() to notify CEF that the |
| 187 | +// parent window will be closing. |
| 188 | +// B. Set a flag to indicate that the next close attempt will be allowed. |
| 189 | +// C. Return false. |
| 190 | +// 7. CEF sends an OS close notification. |
| 191 | +// 8. Application's top-level window receives the OS close notification and |
| 192 | +// allows the window to close based on the flag from #6B. |
| 193 | +// 9. Browser OS window is destroyed. |
| 194 | +// 10. Application's CefLifeSpanHandler::OnBeforeClose() handler is called and |
| 195 | +// the browser object is destroyed. |
| 196 | +// 11. Application exits by calling CefQuitMessageLoop() if no other browsers |
| 197 | +// exist. |
| 198 | +/// |
| 199 | +/*--cef()--*/ |
| 200 | +bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) { |
| 201 | + return false; |
| 202 | +} |
| 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 methods on the browser |
| 207 | +// object after this callback returns. If this is a modal window and a custom |
| 208 | +// modal loop implementation was provided in RunModal() this callback should |
| 209 | +// be used to exit the custom modal loop. See DoClose() documentation for |
| 210 | +// additional usage information. |
| 211 | +/// |
| 212 | +/*--cef()--*/ |
| 213 | +void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) { |
| 214 | + REQUIRE_UI_THREAD(); |
| 215 | + LifespanHandler_OnBeforeClose(browser); |
| 216 | +} |
0 commit comments