Page 1 of 1

CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Fri Jul 10, 2020 3:59 pm
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!

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Sat Jul 11, 2020 8:19 am
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.

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Sat Jul 11, 2020 1:31 pm
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.

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Sun Jul 12, 2020 7:35 am
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

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Sun Jul 12, 2020 1:47 pm
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, '');

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Mon Jul 13, 2020 8:49 am
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.

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Tue Jul 14, 2020 1:55 am
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.

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Tue Jul 14, 2020 5:32 pm
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!

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Wed Jul 15, 2020 8:04 am
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.

Re: CEF_CREATENEXTCHILD in popup browser2 memo

Posted: Wed Jul 15, 2020 4:08 pm
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!