Page 1 of 2
Re: CloseBrowser safely
Posted: Sat Feb 17, 2018 2:33 pm
by salvadordf
If you need several browsers create an array of TDTBrowser and destroy all of them.
If you create browsers with a reference count then it's possible that only the first one will be properly destroyed.
Re: CloseBrowser safely
Posted: Sat Feb 17, 2018 3:43 pm
by salvadordf
Winexcel wrote: Sat Feb 17, 2018 2:57 pm
If you create browsers with a reference count then it's possible that only the first one will be properly destroyed.
FBrowserRefCount is a variable which show how much popup Browsers this browser have.
When popup Browser is closing it invoke TChromium.Browser.CloseBrowser(True) of Main Browser (which created this popup), after that main browser check FBrowserRefCount and if FBrowserRefCount = 0 then it will be destroyed.
I'm developing this mechanism in order to work easy with popup windows and close main browser correctly(when all popup which was created this main browser were closed)
I'm interested, Is it possible?
To be honest, I'm not sure. You're using a custom browser class with a nil owner and that means that you must destroy all the browsers manually.
Using this reference count destruction you would always need to destroy the popups browsers first and then the main browser.
Winexcel wrote: Sat Feb 17, 2018 2:57 pmTo call TChromium.Browser.Host.CloseBrowser(True) more than one time?
Each browser can call CloseBrowser only one time.
Re: CloseBrowser safely
Posted: Sat Feb 17, 2018 4:36 pm
by salvadordf
Winexcel wrote: Sat Feb 17, 2018 4:17 pm
In method doOnClose i call inherited method only one time(when the FBrowserRefCount = 0), but the method
TChromium.Browser.Host.CloseBrowser(True) is triggered method doOnClose many times which may called by popup browsers. It seems to work but I'm not sure that it's a right solution.
When you let CEF create the popups it creates new ICefBrowser instances but CEF uses the same ICefClient and the same TCefBrowserSettings for the new ICefBrowser.
ICefClient is responsible for calling the doOnClose method and all other "doOn..." methods in TChromium. This means that the popup browsers will also call the "doOn..." methods in the main TChromium. In your case, when CEF destroys a popup browser it will call "popupbrowser.host.closebrowser" and this will call the doOnClose method in your TChromium because it has the same ICefClient.
You must return the default values in doOnClose and all other "doOn..." methods if the "browser" parameter is a popup.
Re: CloseBrowser safely
Posted: Sat Feb 17, 2018 5:29 pm
by salvadordf
Please check that CreateClientHandler returns True or you will be using the default ICefClient, which is the ICefClient from the main form.
Re: CloseBrowser safely
Posted: Sun Feb 18, 2018 8:29 pm
by salvadordf
I had some difficulties testing "testpopup.rar" and I couldn't make it show a browser.
Anyway, this is a very complicated issue that needs a new demo so I just uploaded the "PopupBrowser" demo showing all the steps to handle popup windows with custom forms.
Please, read the code comments in the *.pas files.
Re: CloseBrowser safely
Posted: Mon Feb 19, 2018 3:45 pm
by salvadordf
Winexcel wrote: Mon Feb 19, 2018 2:21 pmWhat couldn't you do?
I clicked the "CreateBrowser" button and then the "Load" button but I couldn't see a browser window to click the "Sign in via FaceBook" button.
Winexcel wrote: Mon Feb 19, 2018 2:21 pm
I had rewrote your example on FMX, the example is based on TDTBrowser, I think that it is really more simple to realise counting popup browsers like I did with the variable FBrowsersCount. I'll post my example later, it isn't clean at the moment.
All bug reports, bug fixes and optimizations are welcome!
Winexcel wrote: Mon Feb 19, 2018 2:21 pm
I don't know why, but sometimes my solution on FMX crashes in closing time, but It helps:
I invoke it before CloseBrowser(True).
Loading "about:blank" is one of the steps to close TWebBrowser but CEF3 has a different destruction sequence.
Re: CloseBrowser safely
Posted: Wed Feb 21, 2018 12:46 pm
by salvadordf
Thanks for the demo!
I'll take a look as soon as I can.
Re: CloseBrowser safely
Posted: Fri Feb 23, 2018 10:26 am
by salvadordf
Sorry for the delay.
I took a look at PopupFMX and it seems to destroy the browsers correctly.
To be honest, I'm not sure why it crashes when you don't load "about:blank".
Perhaps CEF3 doesn't support "WindowInfoAsClipWindow" or there's some kind of problem using TThread.Synchronize.
Sorry but I don't know the cause of this problem.
Re: CloseBrowser safely
Posted: Fri Feb 23, 2018 1:26 pm
by salvadordf
Feel free to attach it if you want to share your work with the rest of us.
Re: CloseBrowser safely
Posted: Fri Mar 02, 2018 5:56 pm
by salvadordf
Check that there are no blocked threads in the "Thread Status" tab when you debug your app in Delphi and close a popup browser.
Click on "Program Pause" in the "Run" menu to see what threads are blocked.
Also check that the BrowserOnBeforeClose function only destroys the popup browser.