Windows, tabbed UI, JavaScript closing tab sends WM_DESTROY

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Windows, tabbed UI, JavaScript closing tab sends WM_DESTROY

Postby HarmlessDave » Tue Dec 02, 2014 8:32 pm

I have a main window, with multiple browser windows as children of it, and a tab control to set the active / visible window.

What is happening is if the current tab runs some JavaScript that says to close itself, the browser seems to be sending WM_DESTROY to the main window parent, killing my app.

16:49:52 - WM_DESTROY = 1312418 (the parent not the browser window)
16:49:52 - ClientHandler::OnBeforeClose id=3

So browser with id #3 closes itself, but also closes the parent. This is not the case of the last window closing, there are 2 other windows open.

It happens before ClientHandler::OnBeforeClose so I can't try to do something like set its parent window to null. The JavaScript is not under my control.

Is there some other event I can trap that happens before WM_DESTROY is sent? Also, what is the right way to detach the browser from the parent so it stops trying to destroy it? Will setting the browser window's parent to NULL be enough or do I need to set some member variable or call some function?
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Windows, tabbed UI, JavaScript closing tab sends WM_DEST

Postby Czarek » Tue Dec 02, 2014 11:52 pm

How about introducing a wrapping window? main window -> wrapping window -> cef browser.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Windows, tabbed UI, JavaScript closing tab sends WM_DEST

Postby HarmlessDave » Wed Dec 03, 2014 4:15 am

Thanks, I thought of that too but I haven't tried doing it yet since it's a good amount of work to add it to my code.

I was hoping for something a little cleaner than that, some event I can use to detach the browser before it destroys its parent, but if there is none then I guess I'll have to add then wrapper window.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Windows, tabbed UI, JavaScript closing tab sends WM_DEST

Postby magreenblatt » Wed Dec 03, 2014 4:29 am

HarmlessDave wrote:Is there some other event I can trap that happens before WM_DESTROY is sent?

Implement CefLifeSpanHandler::DoClose.

HarmlessDave wrote:Also, what is the right way to detach the browser from the parent so it stops trying to destroy it? Will setting the browser window's parent to NULL be enough or do I need to set some member variable or call some function?

Do you want to keep the browser or destroy it? If you want to destroy the browser call CefBrowserHost::CloseBrowser. If you want to re-use the browser set the parent to a temporary hidden window.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Windows, tabbed UI, JavaScript closing tab sends WM_DEST

Postby HarmlessDave » Wed Dec 03, 2014 1:40 pm

Thanks, that was the event I needed. Adding this allowed other windows (besides the first, main window) to close without killing the app:

Code: Select all
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
....

  if (browser->GetIdentifier() != m_BrowserId)
  {
     SetParent(browser->GetHost()->GetWindowHandle(), NULL);
  }


The rest of the code is copied from the cef sample, so for the main window it does the browser->GetHost()->ParentWindowWillClose(); and I still let it close the parent / app.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Windows, tabbed UI, JavaScript closing tab sends WM_DEST

Postby Cyber » Tue Dec 16, 2014 4:27 pm

Hey, *ahem*, I don't suppose you'd like to share a little of that tabbed Windows code? I'm trying to get it going that way now and it would be really handy. :D
Cyber
Newbie
 
Posts: 2
Joined: Tue Dec 16, 2014 4:24 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 17 guests

cron