Switching from EmbeddedWB -> CEF

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Switching from EmbeddedWB -> CEF

Postby Sillicoid » Thu Jul 03, 2014 9:22 am

Hi,

i am currently trying to switch an application using EmbeddedWB to CEF. During that, some problems occurred, and a little help or input would be nice.
To understand some questions you should know, that i dont want to use external web-Content but to show dynamically generated (html) content.

1) In EmbeddedWB i could load the content during ShowFrame. Using CEF this does not work, it only works in my refresh-method when i press F5 after the frame has been created. I cant use OnAfterCreated, because at that Point i dont have the content that should be displayed. Any good practise here? To use custom content, i have to first initialize the view with browser.GetMainFrame.LoadURL('about.blank') followed with LoadString(<html>, 'about:blank'). Is this correct or should i use some kind of own namespace in the second param?

2) Setting the HTML-Content works fine, but in the file we use Images from resource-files -> <img src="res://<SomeRessourceContent>"> . I did not find an easy way to get those Images displayed. What is the suggested method to do this? As i can remember using EmbeddedWB there was no to implement something to get those Images (probably because the activeX-Environment had more access to the local files). I get the requested resource-info using BeforeResourceLoad, so do i need to pass the image in that resource stream or is there an easier way?

3) Further we use HREFs to open other Windows or use specific functions of the program (like <a href="=<SomeID>?<SomeParam>">. I tried several events provided by TChromium (like OnBeforeBrowse) but i found no way to get those data/params-Infos.
As i see from your examples, the perfect solution would be to switch those href-commands to JavaScript-calls and Register own Extension(?)-Handlers. As the current concept works fine at the moment, it would be nice if there is a way using the existing html-code for a quick start.

Thanks for your Feedback,
Sillicoid
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am

Re: Switching from EmbeddedWB -> CEF

Postby magreenblatt » Thu Jul 03, 2014 10:06 am

Sillicoid wrote:1) In EmbeddedWB i could load the content during ShowFrame. Using CEF this does not work, it only works in my refresh-method when i press F5 after the frame has been created. I cant use OnAfterCreated, because at that Point i dont have the content that should be displayed. Any good practise here? To use custom content, i have to first initialize the view with browser.GetMainFrame.LoadURL('about.blank') followed with LoadString(<html>, 'about:blank'). Is this correct or should i use some kind of own namespace in the second param?

2) Setting the HTML-Content works fine, but in the file we use Images from resource-files -> <img src="res://<SomeRessourceContent>"> . I did not find an easy way to get those Images displayed. What is the suggested method to do this? As i can remember using EmbeddedWB there was no to implement something to get those Images (probably because the activeX-Environment had more access to the local files). I get the requested resource-info using BeforeResourceLoad, so do i need to pass the image in that resource stream or is there an easier way?

You should use custom request handling. See https://code.google.com/p/chromiumembed ... t_Handling

Sillicoid wrote:3) Further we use HREFs to open other Windows or use specific functions of the program (like <a href="=<SomeID>?<SomeParam>">. I tried several events provided by TChromium (like OnBeforeBrowse) but i found no way to get those data/params-Infos.
As i see from your examples, the perfect solution would be to switch those href-commands to JavaScript-calls and Register own Extension(?)-Handlers. As the current concept works fine at the moment, it would be nice if there is a way using the existing html-code for a quick start.

You're better off using JavaScript because href links will cause the page to navigate, and that's probably not what you want. To cancel navigation you would need to use OnBeforeNavigation in the renderer process, and then you can retrieve the URL via request->GetURL(). In either case you need to communicate back from the renderer process to the browser process. See https://code.google.com/p/chromiumembed ... ation_(IPC)
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Switching from EmbeddedWB -> CEF

Postby Sillicoid » Fri Jul 04, 2014 7:42 am

Thanks for the Feedback. It was indeed very easy to implement the necessary SchemeHandler(for .res-content) and JavascriptHandler for the Javascript-Calls. Everything works perfectly ;)
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am

Re: Switching from EmbeddedWB -> CEF

Postby Sillicoid » Mon Jul 07, 2014 2:03 am

Hi, is there a way to "preload" data to an invisible TChromium-browser?
I am stuck at the following problem:

I can load custom data (browser.GetMainFrame.LoadString) during OnSetFocus and during a manual refresh (catching F5). But it seems all LoadString-Commands that are called in other methods during the OnShow-Events for example are ignored.

Where is the suggested point to load initial data into TChromium?
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am

Re: Switching from EmbeddedWB -> CEF

Postby Sillicoid » Mon Jul 07, 2014 2:50 am

Got it, problem was that at these points there was no reference to "GetMainFrame" and i had to call Load('about:blank') directly on the TChromium-object to initialize.
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am

Re: Switching from EmbeddedWB -> CEF

Postby Sillicoid » Tue Jul 15, 2014 1:56 am

Hi, so finally i got everything working as intended using my own navigation handlers (TCefv8HandlerOwn) and resource handlers (TCefSchemeHandlerOwn). I was a little bit confused, that those are appearently registered application-wide and dont rely on the current namespace, so i had to use different JS-Function-Names for each seperated TChromium-Browser i use. Is that the way it works or is there any way to register the handlers only to one specific browser-instance?

Another problem is, that i get an exception/crash when closing the application during the finalization-Part (see callstack below). We are using Chromium in Delphi2010.
This only happens, when the Chromium is at least refreshed once or looses its focus. If i just load the page and close the application there are no errors. What is supposed to happen at this point / what am i possibly doing wrong here? Do i have to manually unregister all handlers in source?

exception class : EAccessViolation
exception message : Zugriffsverletzung bei Adresse 73843BF1. Lesen von Adresse 73843BF1.

main thread ($9e8):
12a4fde3 +6eb23 libcef.dll cef_shutdown
005652f8 +0000c application.exe ceflib 8486 +3 CefShutDown
00569c9d +0001d application.exe ceflib 12116 +0 Finalization
5000b2a6 +0003e rtl140.bpl System 12622 +24 FinalizeUnits

Thanks for your Feedback.
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am

Re: Switching from EmbeddedWB -> CEF

Postby magreenblatt » Tue Jul 15, 2014 10:22 am

Sillicoid wrote:Is that the way it works or is there any way to register the handlers only to one specific browser-instance?

The CEF3 C++ API provides a CefRequestHandler::GetResourceHandler method. I don't know if it's exposed via the Delphi wrapper.

Sillicoid wrote:Another problem is, that i get an exception/crash when closing the application during the finalization-Part (see callstack below). We are using Chromium in Delphi2010.
This only happens, when the Chromium is at least refreshed once or looses its focus. If i just load the page and close the application there are no errors. What is supposed to happen at this point / what am i possibly doing wrong here? Do i have to manually unregister all handlers in source?

If you're using a Debug build of libcef then this might be an assertion because you're still holding a CEF object reference when CefShutdown is called. You'll likely need to debug the problem to identify the reference type that's causing the issue. It may also be a bug in the Delphi wrapper and not in your application specifically.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Switching from EmbeddedWB -> CEF

Postby Sillicoid » Wed Jul 16, 2014 3:49 am

Okay, i think could get rid of that exception by adding
Code: Select all
Initialization
  CefLoadLibDefault;

finalization
  CefShutDown;

to my main form. At least it did not crash for several trys now ;)
Sillicoid
Newbie
 
Posts: 8
Joined: Thu Jul 03, 2014 8:49 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 77 guests