OnBeforeClose is being called for twice when popup is closed

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnBeforeClose is being called for twice when popup is closed

Postby mpawar » Thu Apr 21, 2016 8:33 am

I have the following scenario:

The windows are provided by the application and the browser window is parented to those windows.
For popups, they are initially parented to a temp window and then reparented to the actual window (as done in cefclient example).
All the application provided windows share the same class and the windowproc.

When I close the popup window the following sequence takes place:

- WM_CLOSE is received with hWnd of the popup window
- CefBrowserHost::CloseBrowser(false) is called
- DoClose is called on the popup browser
- IsClosing flag is set
- WM_CLOSE returns 0 to cancel the close.
- WM_CLOSE is received again with hWnd of the popup window
- Since the IsClosing flag is set, the WM_CLOSE is handled by the DefWndProc
- The popup window is closed
- OnBeforeClose is called for the popup browser

Till here everything is working just fine.

The problem I am having is that OnBeforeClose is called again for the main browser (IsPopup == false) which is causing the CefQuitMessageLoop to be called and shutting down the entire application.

I am not sure why OnBeforeClose is being called twice. I am not able to track why the main window/browser receives a shutdown event.
mpawar
Newbie
 
Posts: 8
Joined: Thu Oct 22, 2015 3:25 pm

Re: OnBeforeClose is being called for twice when popup is cl

Postby magreenblatt » Thu Apr 21, 2016 8:41 am

What OS and CEF version?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeClose is being called for twice when popup is cl

Postby mpawar » Thu Apr 21, 2016 4:20 pm

I am using CEF 3.2526.1373 (32 bit) on Windows 8.1 Update 1 (64 bit)
mpawar
Newbie
 
Posts: 8
Joined: Thu Oct 22, 2015 3:25 pm

Re: OnBeforeClose is being called for twice when popup is cl

Postby magreenblatt » Thu Apr 21, 2016 4:25 pm

Check the places where you're calling CloseBrowser() or window.close() JavaScript in your application. You're probably calling it an additional time for the main window.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

[Solved] OnBeforeClose called for twice when popup is closed

Postby mpawar » Thu Apr 21, 2016 5:44 pm

Thank you for pointing me in the right direction.

I was not checking on which window WM_DESTROY was called and was directly calling PostQuitMessage(0)
This terminated the windows message pump and CefShutdown was called closing all the open browsers.
mpawar
Newbie
 
Posts: 8
Joined: Thu Oct 22, 2015 3:25 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 118 guests