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.

Using the same extension for communication JavaScript with Delphi code in different windows with chrome browser in appli

Post Reply
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Using the same extension for communication JavaScript with Delphi code in different windows with chrome browser in a

Post by salvadordf »

skyknocker wrote: Mon Apr 03, 2017 7:46 pm Hi,

Could you please help me with DCEF extensions of DCEF4. In old version (CEF) it's no problem to use the same extension in several browser windows in one application. Each object instance of extension can communicate with its browser window. But in DCEF it is a real problem for me.

I can have many browser windows with similar tasks, and the same extension is used. So how to isolate each extension to its browser window?

Thanks.
I only have the basic knowledge about javascript extensions but I'll try to explain the code inside the MiniBrowser demo.

The CEF3 document describing extensions is here :
https://bitbucket.org/chromiumembedded/ ... gration.md

The MiniBrowser demo has a TTestExtension class that is registered in the OnWebKitReady event of a custom ProcessHandler when the application is initializing as the previous document says.

TTestExtension can send information back to the browser with a process message. The TTestExtension.mouseover function do this by calling TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg);

TCefv8ContextRef.Current returns the v8 context for the frame that is currently executing JS, so if I understand this correctly, TCefv8ContextRef.Current.Browser.SendProcessMessage should send a message to the right browser even if you have created several browsers in one app.

That message is received in the TChromium.OnProcessMessageReceived event. Even if you create several TChromium objects you should have no problem because each of them will have its own TChromium.OnProcessMessageReceived event to receive the messages from the extension.

As you can see, the extension example in the CEF4Delphi's "MiniBrowser" demo is a copy of the extension example in DCEF3's "guiclient" demo.
If you could make it work in DCEF3, you should have no problems in CEF4Delphi.
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Using the same extension for communication JavaScript with Delphi code in different windows with chrome browser in a

Post by salvadordf »

The CEF3 document says this about the extensions :
Extensions are registered using the CefRegisterExtension() function which should be called from the CefRenderProcessHandler::OnWebKitInitialized() method.
It says "should" instead of "must". Maybe you can register the extensions after the OnWebKitReady event but I haven't tried it.

PS : CefRegisterExtension is called inside TCefRTTIExtension.Register
PS 2 : CefRenderProcessHandler::OnWebKitInitialized = TCefCustomRenderProcessHandler.OnWebKitReady
Post Reply