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.

TChromium control - Initialization issue

john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

Re: TChromium control - Initialization issue

Post by john.augustine »

Hi,

Could you please help me on my below mentioned things?

My application is using TWebBrowser and i am trying to replace with TChromium (CEF4 Delphi).

I am using CEFWindowParent and TChromium.

Need your help on following things:

1) How to achieve "OnBeforeNavigate2" (which is in TWebBrowser) in TChromium (CEF4 Delphi)?

2) I am using TWebBrowser in one of my screen
2.1) I have method called LoadSummary(aHTML: String).
2.2) Having 4 Comboboxe's in my screen
2.3) Calling LoadSummary(aHTML: String) on each ComboBox "OnChange" event. Because i need to load the chromium browser based on the value
selected in combobox
2.4) In "FormShow" the data is loading properly in chromium browser (here also calling LoadSummary). But when i choose the the combobox value
then the browser is flickering and not able to select the value from ComboBox. I mean, whenever i try to select the data from ComboBox
immediately browser is flickering (not black screen).
Please help me to address this issue.

procedure TSummaryDialog.LoadSummaryPPT(aSummary: string);
var
lTempFilename: string;
browser: ICefBrowser;
begin
//lTempFilename := fFileCache.SaveToFile('html', aSummary);
//dChromiumBrowser.LoadURL(lTempFilename);
fSummary := aSummary;
dChromiumBrowser.LoadString(aSummary);
end;

//This will run after "FormShow" event
procedure TSummaryDialog.BrowserCreatedMsg(var aMessage : TMessage);
var
browser: ICefBrowser;
lTempFilename: string;
begin
CEFWindowParent.UpdateSize;
try
browser := TCefBrowserRef.UnWrap(Pointer(aMessage.WParam));
if browser.IsSame(dChromiumBrowser.Browser) then
begin
lTempFilename := fFileCache.SaveToFile('html', fSummary);
browser.MainFrame.LoadUrl(lTempFilename);
end;
finally
browser := nil
end;
end;

procedure TSummaryDialog.FormShow(Sender: TObject);
begin
if not(dChromiumBrowser.CreateBrowser(CEFWindowParent, '')) then
dLoadTimer.Enabled := True;
end;

procedure TSummaryDialog.dLoadTimerTimer(Sender: TObject);
begin
dLoadTimer.Enabled := False;
if not(dChromiumBrowser.CreateBrowser(CEFWindowParent, '')) and
not(dChromiumBrowser.Initialized) then
dLoadTimer.Enabled := True;
end;
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium control - Initialization issue

Post by salvadordf »

john.augustine wrote: Sat Jul 25, 2020 7:24 pm 1) How to achieve "OnBeforeNavigate2" (which is in TWebBrowser) in TChromium (CEF4 Delphi)?
Try TChromium.OnBeforeBrowse :
https://magpcss.org/ceforum/apidocs3/pr ... bool,bool)
john.augustine wrote: Sat Jul 25, 2020 7:24 pm 2) I am using TWebBrowser in one of my screen
2.1) I have method called LoadSummary(aHTML: String).
2.2) Having 4 Comboboxe's in my screen
2.3) Calling LoadSummary(aHTML: String) on each ComboBox "OnChange" event. Because i need to load the chromium browser based on the value
selected in combobox
2.4) In "FormShow" the data is loading properly in chromium browser (here also calling LoadSummary). But when i choose the the combobox value
then the browser is flickering and not able to select the value from ComboBox. I mean, whenever i try to select the data from ComboBox
immediately browser is flickering (not black screen).
Please help me to address this issue.
Perhaps the combobox is forcing the browser to load the same summary multiple times. Check that the contents are different before loading them again.
john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

Re: TChromium control - Initialization issue

Post by john.augustine »

Sure, Thank you so much!. I will try the same!

Kindly let me know the corresponding event in "CEF4 Delphi" for below mentioned TWebBrowser events.

1) OnDownloadComplete (I hope OnLoadEnd in CEF4 Delphi)
2) OnDocumentComplete (?? Not Sure)

Thanks & Regards,
John
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium control - Initialization issue

Post by salvadordf »

john.augustine wrote: Sun Jul 26, 2020 7:56 am 1) OnDownloadComplete (I hope OnLoadEnd in CEF4 Delphi)
This is the description of that event :
http://docs.embarcadero.com/products/ra ... plete.html
Write an OnDownloadComplete event handler to take specific action after the Web browser stops a downloading operation. For example, use the OnDownloadComplete event to stop an download indication that is started in an OnDownloadBegin event handler.
Note: Unlike the OnNavigateComplete2 event, OnDownloadComplete occurs even if the Web browser does not successfully navigate to an URL.
This event would be equivalent to TChromium.OnDownloadUpdated and checking the "downloadItem" properties. Check the MiniBrowser demo to see how to download files.
john.augustine wrote: Sun Jul 26, 2020 7:56 am 2) OnDocumentComplete (?? Not Sure)
This is the description of that event :
http://docs.embarcadero.com/products/ra ... plete.html
Write an OnDocumentComplete event handler to take specific action when a frame or document is fully loaded into the Web browser .For a document without frames, this event occurs once when the document finishes loading. On a document containing multiple frames, this event occurs once for each frame. When the multiple-frame document finishes loading, the Web browser fires the event one final time.
This event would be equivalent to TChromium.OnLoadEnd

For more TChromium events read this :
https://www.briskbard.com/index.php?lan ... =cef#usage

As you can see in that document, TChromium has the functions, procedures and events of :
  • CefBrowser
  • CefBrowserHost
  • CefClient
  • CefContextMenuHandler
  • CefDialogHandler
  • CefDisplayHandler
  • CefDownloadHandler
  • CefDragHandler
  • CefFindHandler
  • CefFocusHandler
  • CefJSDialogHandler
  • CefKeyboardHandler
  • CefLifeSpanHandler
  • CefLoadHandler
  • CefRenderHandler
  • CefRequestHandler
  • CefResourceRequestHandler
  • CefCookieAccessFilter
  • CefRequestContextHandler
  • CefMediaObserver
  • CefAudioHandler
  • CefDevToolsMessageObserver
Check TChromiumCore source code and you will see that the events are grouped and they have a CEF class or interface name in a comment before each group.
For all the details about that CEF class you have to click on its link at :
https://www.briskbard.com/index.php?lan ... =cef#usage
john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

Re: TChromium control - Initialization issue

Post by john.augustine »

Thank you so much for your detailed answers!

John
john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

CEF4 Delphi - 1 Primary and 2 Background processes are running in Task Manager when launching my application

Post by john.augustine »

Hi,

I am seeing 1 Primary and 2 Background processes are running in Task Manager when launching my application.
Not sure, if this is expected behavior or not. If "Yes" then could you please explain the reason for 2 background processes.

Thanks & Regards,
John Augustine
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium control - Initialization issue

Post by salvadordf »

Chromium creates those processes. Chromium's developers decided several years ago that it was safer to handle certain tasks in different processes instead of using threads.

Read this for more details about those processes :
http://www.chromium.org/developers/desi ... chitecture

All CEF based applications create 1 or more of these process types : "browser", "gpu", "renderer", "utility" (Network service), etc.
john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

Re: TChromium control - Initialization issue

Post by john.augustine »

Thank you so much for the info!

John
john.augustine
Posts: 48
Joined: Fri Jul 10, 2020 1:33 pm

Re: TChromium control - Initialization issue

Post by john.augustine »

Hi,

In my application (Delphi), using CEF4 browser at more than one place.

In one of the form > on "FormDestroy" event > i called "dChromiumBrowser.CloseBrowser(True)". Due to this, application login screen is appearing again.

Is calling "CloseBrowser" is mandatory at "FormDestroy" Or "FormClose" event?

Kindly provide your thoughts/advice on this.

Thanks & Regards,
John
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromium control - Initialization issue

Post by salvadordf »

You can destroy browsers without closing the main form but you have to follow the proper destruction sequence.

The TabbedBrowser2 demo shows how to create and destroy browsers which are included in frames but the main form remains open.
Post Reply