CEF browser with SetAsChild closing parent window

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.

CEF browser with SetAsChild closing parent window

Postby Biohazard » Mon Jun 22, 2020 3:51 pm

Hi,

I'm using CEF 4103 / 83.0.4103.97 in my application as a child window of a window that already exists. When shutting down CEF, I have to close the browser windows to avoid getting an assertion about the browser not being closed when calling CefShutdown. But closing the browser will close the parent window too, which is not managed by CEF or Chromium and should not be closed this way.

I have tracked down the issue to browser_platform_delegate_native_win.cc Line 238, which closes the top level window that CEF is a child of. I don't think this makes much sense, it shouldn't close every window in the hierarchy just because the browser is closed. Changing this to PostMessage(window_info_.window, WM_CLOSE, 0, 0); fixes the issues and seems to work better for me.

Is there a reason for the browser to close the top level window this way and could there be some unexpected consequences with my change?

Thanks.
Biohazard
Techie
 
Posts: 15
Joined: Mon Jun 15, 2020 10:01 am

Re: CEF browser with SetAsChild closing parent window

Postby magreenblatt » Mon Jun 22, 2020 4:46 pm

You should instead implement the CefLifeSpanHandler::DoClose method. See the documentation on that method for usage.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF browser with SetAsChild closing parent window

Postby Biohazard » Mon Jun 22, 2020 5:31 pm

Thanks for the reply (and fixing the forum registration)!

I'm afraid I'm still unsure on what to do after reading the doc for DoClose. What I need to do is close the CEF window, but not close my own top level window yet at all.

The documentation says that returning false from DoClose will cause the WM_CLOSE message to be sent to the top level window, which is what I want to avoid. So I understand that I should return true here to avoid this, but now I don't know what to do next to actually close the browser smoothly, it seems it doesn't close at all now. There are two examples in the documentation too and both assume that I want to close the top level window eventually.

I only had a very swift look and it seems that in CefBrowserHostImpl::CloseContents() if OnClose returns true, it will reset destruction_state_ and do nothing further but I need CefBrowserHostImpl::DestroyBrowser() to be called somehow (after the child window created by CEF was closed, but not my own window).
Biohazard
Techie
 
Posts: 15
Joined: Mon Jun 15, 2020 10:01 am

Re: CEF browser with SetAsChild closing parent window

Postby magreenblatt » Mon Jun 22, 2020 5:44 pm

//
// If the browser's top-level owner window requires a non-standard close
// notification then send that notification from DoClose() and return true.
//


In your case you want to close the browser but not the top-level window, so you can call DestroyWindow(browser->GetHost()->GetWindowHandle()) after returning true from DoClose.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF browser with SetAsChild closing parent window

Postby Biohazard » Mon Jun 22, 2020 6:17 pm

That works, I guess it would be effectively the same as the change I have made to only close window_info_.window in CefBrowserPlatformDelegateNativeWin::CloseHostWindow. But that way I don't have to worry about having to make this modification in the future, thanks!
Biohazard
Techie
 
Posts: 15
Joined: Mon Jun 15, 2020 10:01 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 111 guests