Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

TChromiumWindow.CloseBrowser and onbeforeunload

Post Reply
jchoover
Posts: 14
Joined: Tue Apr 30, 2019 5:45 pm

TChromiumWindow.CloseBrowser and onbeforeunload

Post by jchoover »

https://www.briskbard.com/forum/viewtopic.php?p=156#p156

If I don't care about onbeforeunload, is there any harm in not calling CloseBrowser, and allowing the immediate natural destruction sequence?

TLDR, in my application I have a TFrame based component which hosts the TChromiumWindow. I embed this frame in a modal form for previewing PDF's. If I don't add the CloseBrowser call, I am not noticing any negative impacts using both the debug and release builds of CEF.

In other portions of the application, the same component is used as is (not in a form that we close). When I navigate via an external control to different area's, the container will simply call Object.Free to destroy the old "area browser", to replace that with another component, which may or may not be another TChromiumWindow frame. In this use case, If I do call close browser, then there is a race condition. Because I've been triggered by Free, I would be stuck with the dreaded Application.ProcessMessages.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromiumWindow.CloseBrowser and onbeforeunload

Post by salvadordf »

Hi,

Following the destruction steps is the recommended way to destroy a CEF browser.
See the SimpleBrowser demo for all the details.

In the case of TChromiumWindow you need to do this :
  • Implement TForm.OnCloseQuery event, set CanClose to False and call TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
  • The TChromiumWindow.OnClose event sets FCanClose to true and sends WM_CLOSE to the form.
If you use TChromiumWindow inside a frame you will have to wait until the TChromiumWindow.OnClose event is triggered before destroying the frame.

Even if simply destroying the browser seems to work sometimes I would not recommend doing that.
Post Reply