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.

CEF_CREATENEXTCHILD in popup browser2 memo

Post Reply
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

1.
May the child form can be created in TMainForm.CreateClientHandler function.
I found that child form is created befor the popup event(PostMessage(Handle, CEF_CREATENEXTCHILD, 0, 0);). Is it to accelerate the procedure or another reason?

2. IF ApplyPopupFeatures was not executed, The new window will show nothing. Why?


Keen for your help, thank you!
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by salvadordf »

coater wrote: Fri Jul 10, 2020 3:59 pm 1.May the child form can be created in TMainForm.CreateClientHandler function.
I found that child form is created befor the popup event(PostMessage(Handle, CEF_CREATENEXTCHILD, 0, 0);). Is it to accelerate the procedure or another reason?
The VCL is not thread safe and TChromium.OnBeforePopup is executed in a CEF thread different from the main application thread.
If you create and destroy controls in different threads you will have errors.
coater wrote: Fri Jul 10, 2020 3:59 pm2. IF ApplyPopupFeatures was not executed, The new window will show nothing. Why?
Some of my tests showed web content even without the ApplyPopupFeatures call. Perhaps there's a timing issue and CEF needs to resize the new popup window to refresh everything.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

I got it, thank you again!

I leanrd popupbrowser2 carefully, but I'm still confused.

Code: Select all

procedure TChildForm.FormCreate(Sender: TObject);

begin
  //form1.create(self);
  FCanClose := False;
  FClosing  := False;
  //I add the following code and delete chromium1 and CEFWindowParent1 component.
  Chromium1:= TChromium.Create(self);
  //Chromium1.CreateBrowser(CEFWindowParent1,'') ;
  Chromium1.onBeforePopup := MainForm.Chromium1_onBeforePopup ;
  CEFWindowParent1:= TCEFWindowParent.Create(self);
  CEFWindowParent1.Align := alClient;
  CEFWindowParent1.Color := clWhite;
  CEFWindowParent1.parent := self;
  self.Show;
end;
  //I add the following code
procedure TChildForm.Button1Click(Sender: TObject);
begin
  Chromium1.CreateBrowser(CEFWindowParent1,'') ;
  Chromium1.LoadURL(FHomepage);
end;

After I click button1, everything is correct.
I chlick a link and a popup window will show, but the popup window has no content.

CEFWindowParent1.HandleAllocated and
Chromium1.CreateClientHandler(client, False) : false in debug.
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by salvadordf »

You need to use the TChromium.DefaultURL property with the first URL for that browser or wait for the TChromium.OnAfterCreated event.

Read this for more details :
viewtopic.php?f=8&t=1391#p5773
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

Thank you!
My problem is that the popup window has no content.

If I add the following coade popupwindow will has no content.(If the code was eclude when popup, the popup window will has content).
I debug this, and fond that it is because of FHandler <> nil in function TChromiumCore.CreateClientHandler(aIsOSR : boolean)

FChromium.CreateBrowser(FCEFWindowParent, '');
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by salvadordf »

If FHandler is not nil then it means that it was already assigned in a previous TChromium.CreateClientHandler call.

The code in the attachment seems to be mixing the MiniBrowser demo, which lets CEF handle the new popup windows, with part of the PopupBrowser2 demo which handles the new popup windows in a radically different way.

I'm not sure what you need for your application but perhaps you're trying to use a demo intended for other purposes.

The PopupBrowser2 demo show how to use custom child forms made with Delphi when the user clicks on a HTML link in main browser that needs a new window.

This is a different situation than the ToolBoxBrowser demo where the user clicks on a VCL button to show a new Delphi form which includes a web browser.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

Thank you!

I was testing and learn how to control a pop window and create new browser form by mixing minibrowser and toolbox and popup2 demos.

I think that Chromium1.CreateBrowser(CEFWindowParent1,'') will use TChromiumCore.CreateClientHandler(aIsOSR : boolean), so FHandler <> nil.

How to clear FHandler assigned to Chromium1 ?

-----------If I use the same child form to operate a new url or a new pop window, it is needed.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

1.it is very strang that after TChildForm.CreateClientHandler CEFWindowParent which created from form thread will change to another thread!(the form was docked and it's parent was not desktop )
2.If the form was not docked created thread of CEFWindowParent was still the form.

when it wa destoryed access violation error will happen(situation 1).

Why this happened and how to free it?

Keen for your help, thank you!
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by salvadordf »

coater wrote: Tue Jul 14, 2020 1:55 am I was testing and learn how to control a pop window and create new browser form by mixing minibrowser and toolbox and popup2 demos.
I think that Chromium1.CreateBrowser(CEFWindowParent1,'') will use TChromiumCore.CreateClientHandler(aIsOSR : boolean), so FHandler <> nil.
How to clear FHandler assigned to Chromium1 ?
TChromium is not designed to clear the handlers.
coater wrote: Tue Jul 14, 2020 1:55 am -----------If I use the same child form to operate a new url or a new pop window, it is needed.
You can create a new form for new URLs dynamically and keep the hidden forms for the popup windows.
coater wrote: Tue Jul 14, 2020 5:32 pm 1.it is very strang that after TChildForm.CreateClientHandler CEFWindowParent which created from form thread will change to another thread!(the form was docked and it's parent was not desktop )
2.If the form was not docked created thread of CEFWindowParent was still the form.
when it wa destoryed access violation error will happen(situation 1).
Why this happened and how to free it?
VCL is not thread safe and you will have errors if you create VCL forms inside the TChromium events. Sometimes the VCL code recreates the handles when you modify them and you will have the same problem.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Post by coater »

Thank you very much!
I leaned from you and know to avoid creating vlc component in chromium event.
I found that it is because of handle over long and long hours.
If handle was not assigned(visited) by main thread, the cefparent will be assinged to cef thread! Why this happened?

Thank you for your help!
Post Reply