how can I close beforepopup new tab?

User avatar
crucifyer
Posts: 6
Joined: Mon Dec 14, 2020 8:20 pm

how can I close beforepopup new tab?

Post by crucifyer »

hello.
I modify example vcl TabbedBrowser2 for beforepopup to new tab.
but, popuped tab cannot close.

this is source code.
https://github.com/crucifyer/TabbedBrowser2

thank you!
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how can I close beforepopup new tab?

Post by salvadordf »

Hi,

The MiniBrowser demo also allows CEF to create the popup windows but it sets Chromium1.MultiBrowserMode := True; and it has different code in the TChromium.OnClose and TChromium.OnBeforeClose events.
https://github.com/salvadordf/CEF4Delph ... .pas#L1038

Read all the code comments in the MiniBrowser demo for more details.
User avatar
crucifyer
Posts: 6
Joined: Mon Dec 14, 2020 8:20 pm

Re: how can I close beforepopup new tab?

Post by crucifyer »

I try MultiBrowserMode.
I don't know what is my fault.
I have updated the github example, so please run it once and help.
I want multi tab browser.
thank you.
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how can I close beforepopup new tab?

Post by salvadordf »

Thank you very much for becoming a GitHub sponsor!!! :D

I'll take a look at it tomorrow.

I think it will be esier and safer to add custom popup windows like the PopupBrowser2 demo.
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how can I close beforepopup new tab?

Post by salvadordf »

I just added popup windows to the TabbedBrowser2 demo.

Please, download CEF4Delphi again from GitHub.
User avatar
crucifyer
Posts: 6
Joined: Mon Dec 14, 2020 8:20 pm

Re: how can I close beforepopup new tab?

Post by crucifyer »

I modified the example slightly and added it as a tab, but I still have a problem when I close it.
very difficult.
Please look at my example again.
thank you.
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how can I close beforepopup new tab?

Post by salvadordf »

This is the safest and best solution to have tabs and popup windows with browsers. It has to be complicated because Chromium is a very complex project with multiple processes and threads.

I suggest that you use the new TabbedBrowser2 demo as a template for your application. Add your custom features on top of the demo code.

If you need clarification about some part of that demo just let me know and I'll be glad to add more code comments with explanations.
User avatar
crucifyer
Posts: 6
Joined: Mon Dec 14, 2020 8:20 pm

Re: how can I close beforepopup new tab?

Post by crucifyer »

I did it.
In your example, I'm going to change what opens with clientform to open with tab.
I want "TAB"
please help me~~~~~
User avatar
salvadordf
Posts: 2966
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: how can I close beforepopup new tab?

Post by salvadordf »

The TChromium.OnBeforePopup event is executed in a CEF thread which is different than the main application thread.
This is a crucial detail because Windows controls can't be created and destroy in different threads.

As you can see in the original TabbedBrowser2 demo, we have to follow these steps to open a popup window :
  • Create a hidden child form with an uninitialized web browser. (This is executed in the main application thread)
  • Call TChromium.CreateClientHandler in the hidden child form when the TChromium.OnBeforePopup event is triggered. (This is done in a CEF thread)
  • Show the hidden form.
  • Send a message to the main form to create a new hidden child form in the main application thread.


If you want to use tabs as a replacement for popup forms then you need to follow these steps :
  • Create a hidden TAB with an uninitialized web browser. (This is executed in the main application thread)
  • Call TChromium.CreateClientHandler in the hidden TAB when the TChromium.OnBeforePopup event is triggered. (This is done in a CEF thread)
  • Show the hidden TAB.
  • Send a message to the main form to create a new hidden TAB in the main application thread.


The destruction steps will have to be modified to call TChromium.CloseBrowser only when that browser is initialized.

You need to modify the TBrowserTab.CreateClientHandler_ function because it's executed in a CEF thread and TBrowserFrame should be created in the main application thread inside the hidden tab.

The main destruction waits for all the tabs to be destroyed and it will only send a WM_CLOSE message when BrowserPageCtrl.PageCount is 0. This will have to be modified because there might be hidden tabs with uninitialized browsers that can be destroyed normally with a MyHiddenTab.Free call.
User avatar
crucifyer
Posts: 6
Joined: Mon Dec 14, 2020 8:20 pm

Re: how can I close beforepopup new tab?

Post by crucifyer »

I can't completely fix the error.
I have to give up for the time being.
https://github.com/crucifyer/CEF4TabBrowser
Thank you for your time.
Post Reply