Rendering binary data from byte stream

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.

Rendering binary data from byte stream

Postby frontier » Mon Apr 27, 2015 5:05 am

Hello?

Can CefFrame renders a data(html, img, pdf, ...) from byte stream?
(Byte stream handles local data, not from the web.)
When I use LoadString method, html was well rendered, but img/pdf was crashed. And I think LoadRequest cannot be answer.

Does anybody knows how to render a binary data to cef browser?
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby amaitland » Tue Apr 28, 2015 1:17 am

Implement 'CefRequestHandler::GetResourceHandler`, if the request Url matches you return a stream. Instead of calling LoadString you call LoadURL with your dummy url.

There's sample code in `cefclient` see
https://bitbucket.org/chromiumembedded/ ... ter#cl-465
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Rendering binary data from byte stream

Postby frontier » Tue Apr 28, 2015 1:50 am

Thank you! It could be very helpful!
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby frontier » Fri Jun 26, 2015 12:10 am

I have another problem.

The document what I want to load has "EUC-KR" charset.
But when I load this document with GetResourceHandler method, CEF application always read it with default charset(UTF-8) so rendered document broken.

And can I control response header with CefStreamResourceHandler method's headerMap argument?
I've already try this but it seems to useless.

Why this problem happens?
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby amaitland » Fri Jun 26, 2015 2:01 am

What does your code look like?

You can of course change the browsers default encoding if you wish see apidocs3/projects/%28default%29/_cef_browser_settings_t.html#default_encoding

You may well be able to set a response header. Searching this forum and you'll likely find something.

The other approach I've used previously is to prepend the preamble (encoding) to the beginning of the stream. (I've done this on c#, not sure how you'd implement this in c++)
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Rendering binary data from byte stream

Postby frontier » Fri Jun 26, 2015 2:33 am

Below is my implementaion.

Code: Select all
CefRefPtr<CefResourceHandler> MyHandler::GetResourceHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) {
  CEF_REQUIRE_UI_THREAD();
  if (frame->IsMain() && request->GetURL().ToString() == request_url_) {
    CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData(static_cast<void*>(_html), _htmlSize);
    CefResponse::HeaderMap headermap;
    headermap.insert(std::make_pair("Content-Type", request_content_type_));
    return new CefStreamResourceHandler(200, CefString("OK"), request_mime_, headermap, stream);
  }
}


Of course I know there is command line option "--default-encoding", however, I expect CEF can read http header and change charset.

I just test some documents and found that CEF don't change charset by header Content-Type, but does change charset by meta tag. Is it right?
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby amaitland » Fri Jun 26, 2015 7:06 am

Try accept-charset instead.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Rendering binary data from byte stream

Postby frontier » Sun Jun 28, 2015 9:37 pm

Thank you for answer.
To tell the result, "Accept-Charset" header did not affect.

I implement OnBeforeResourceLoad method like this
Code: Select all
bool MyHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) {
  CEF_REQUIRE_UI_THREAD();
  CefRequest::HeaderMap headermap;
  request->GetHeaderMap(headermap);
  headermap.erase("Accept-Charset");
  headermap.insert(std::make_pair("Accept-Charset", "UTF-8"));
  request->SetHeaderMap(headermap);
  ...
  return false;
}


And I tried to print document.charset at rendered local document.
Code: Select all
console.log(document.charset);

Below is console result
Code: Select all
[0629/111828:INFO:CONSOLE(139)] "ISO-8859-1", source:  (139)


Rendered local document is absolutely same with google's main page(https://www.google.co.kr/).
I have no idea why this happened T.T
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby frontier » Sun Jun 28, 2015 9:57 pm

When load local document with CefStreamResourceHandler and user-defined headerMap, CEF does not change it's default charset to user-defined charset.
But load remote document, CEF does change it's charset to http header's charset.
It means CEF read http header but don't read user-defined response headerMap.

Is there a way let CEF to read http header by CefStreamResourceHandler?

* I'm using CEF 2171 build and centos 7 OS.
frontier
Techie
 
Posts: 16
Joined: Sun Mar 15, 2015 9:30 pm

Re: Rendering binary data from byte stream

Postby amaitland » Mon Jun 29, 2015 9:37 pm

Sounds like a bug. Might be worth checking the issue tracker to see if something similar has been reported already.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Next

Return to Support Forum

Who is online

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