How to load HTML after LoadString() deprecation

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.

How to load HTML after LoadString() deprecation

Postby codelimit » Wed Nov 20, 2019 4:36 am

Good day, community.

Usually I load local HTML with well-known simple way as:
Code: Select all
frame->LoadURL("about:blank");
frame->LoadString(html, url);


After 3904 build update with https://bitbucket.org/chromiumembedded/cef/commits/18b5f727017ba0d5816687536cbeefe4b640c9ef we got LoadString() removed. How do i load local HTML now?

Thank you,
Best regards
codelimit
Techie
 
Posts: 30
Joined: Mon Nov 04, 2019 11:48 am

Re: How to load HTML after LoadString() deprecation

Postby salvadordf » Wed Nov 20, 2019 5:09 am

Hi,

There are several workarounds but perhaps the easiest is to create a DATA url with the encoded HTML contents and call LoadUrl with that url.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: How to load HTML after LoadString() deprecation

Postby HarmlessDave » Mon Nov 25, 2019 7:56 pm

You can look at "void LoadErrorPage" in CefClient for an example, and "test_runner::GetDataURI" for a function to build one.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: How to load HTML after LoadString() deprecation

Postby codelimit » Wed Nov 27, 2019 2:31 pm

HarmlessDave wrote:You can look at "void LoadErrorPage" in CefClient for an example, and "test_runner::GetDataURI" for a function to build one.


Thanks a lot, sir! That's exactly what I'm looking for.

Also, as mentioned before
There are several workarounds
As I understand, the above method is the easiest way of loading local html. Can someone point me the "most correct/right" way? Just for or educational purposes.
codelimit
Techie
 
Posts: 30
Joined: Mon Nov 04, 2019 11:48 am

Re: How to load HTML after LoadString() deprecation

Postby francoismarchal » Fri Nov 29, 2019 11:39 am

Dear all, I was also using LoadString(content, url), and using the sample of LoadErrorPage I now use LoadURL( GetDataURI( content) )

The problem I have is that it works only if the frame is empty.

If there was already an url loaded, it does nothing

I tried to call

LoadURL( "about:blank")
LoadURL( GetDataURI( content ) )

but if it cleans well the previous URL and sets an empty page, I still cannot load my content after.

Any clue?

Please help, I'm stuck with the broken printing in 77 and need to go to 78!!!!
francoismarchal
Newbie
 
Posts: 5
Joined: Fri Sep 23, 2016 4:26 am

Re: How to load HTML after LoadString() deprecation

Postby HarmlessDave » Fri Nov 29, 2019 10:51 pm

francoismarchal wrote:Dear all, I was also using LoadString(content, url), and using the sample of LoadErrorPage I now use LoadURL( GetDataURI( content) )

The problem I have is that it works only if the frame is empty.

If there was already an url loaded, it does nothing

I tried to call

LoadURL( "about:blank")
LoadURL( GetDataURI( content ) )

but if it cleans well the previous URL and sets an empty page, I still cannot load my content after.

Any clue?

Please help, I'm stuck with the broken printing in 77 and need to go to 78!!!!


Can you reproduce this in CEFClient / CEFSimple? Say by loading Google.com then replacing it with your own page?
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: How to load HTML after LoadString() deprecation

Postby francoismarchal » Mon Dec 02, 2019 10:23 am

I did that and it works on the client. After investigating, my problem is more general, I can't load _any_ url after having loaded a first one... When I look at the inspector, in the Network tab, I well see my requested URLs arriving, but the request are marked as pending. So something has changed since v77 but I have no idea what may I have done wrong.
francoismarchal
Newbie
 
Posts: 5
Joined: Fri Sep 23, 2016 4:26 am

Re: How to load HTML after LoadString() deprecation

Postby HarmlessDave » Mon Dec 02, 2019 12:56 pm

francoismarchal wrote:I did that and it works on the client. After investigating, my problem is more general, I can't load _any_ url after having loaded a first one... When I look at the inspector, in the Network tab, I well see my requested URLs arriving, but the request are marked as pending. So something has changed since v77 but I have no idea what may I have done wrong.


You should start a new post for that problem then once you've gathered more information. People will probably ask if you can reproduce that issue in CefClient too. Before posting you might try adding some of your customizations to CefClient to try to track down which one is causing the issue.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: How to load HTML after LoadString() deprecation

Postby codelimit » Fri Dec 13, 2019 9:35 am

Thanks to all again.

But i faced another problem. Input is not html file's path, but buffered html, i.e. string that contains html src. Also this htmls contain images (i.e. <img src="some_stuff">). When i use data: scheme, images are not drawn. How can i provide a path for them?
All that i have is html's directory path, and src. No html name present.

Best regards.
codelimit
Techie
 
Posts: 30
Joined: Mon Nov 04, 2019 11:48 am

Re: How to load HTML after LoadString() deprecation

Postby codelimit » Tue Dec 17, 2019 7:59 am

Okay. What i have done for now

I added resource manager instance, and use AddContentProvider (url, html_src, "text/html", 0, std::string());

Url - custom scheme name + full path of the directory that contains html and related files (for ex. "myapp://somedir/somesubdir")
Html_src - is a std::string with html source (for ex. "<html>...</html>")

Also i have custom scheme handling.

So how it works now:
after about_button_press event I call

void load_html (std::string html_src, std::string dir)
{
resource_manager->AddContentProvider (url, html_src, "text/html", 0, std::string());
frame->loadUrl(dir);
}

For given url I create content provider that loads html_src as html. Then it creates html's internal resource request (ex. "logo.png"). So url becomes "myapp://somedir/somesubdir/logo.png". It handled by custom scheme's resource handler (for "myapp" scheme), that loads image source.

At least it works. As i understood AddContentProvider can be called on any thread.

Now the question is where is a correct place to remove provider? With above code it will create provider again and again while i visit and leave "about" page.
At this moment I use OnResourceLoadComplete(), and call removeAllProviders. But that means that on EVERY "OnResourceLoadComplete" i have removeAllProviders called. Even despite none was added.

Can someone comment this workaround?
Best regards.
codelimit
Techie
 
Posts: 30
Joined: Mon Nov 04, 2019 11:48 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 31 guests