Validate JPEG & PNG downloads before used?

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.

Validate JPEG & PNG downloads before used?

Postby HarmlessDave » Mon Nov 20, 2017 2:52 pm

The Chromium developers are still working on a fix for large image decoding causing memory use of more than 1 GB of RAM, so we are looking into adding a hack to get around the problem.

For any images over a certain file size, we want to open the image and check the resolution. If it is too large to decode safely in chromium then we want to swap it for a stock image that says the image needs to be resized.

Do we need to create our own CefResourceHandler for all http: and https: traffic, override events in the stock one, or do something else? Any suggestions and tips would be very helpful.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Validate JPEG & PNG downloads before used?

Postby magreenblatt » Mon Nov 20, 2017 4:07 pm

You could use CefRequestHandler::GetResourceHandler. The added difficulty is that you can't just look for file extensions -- you'll also have to check the returned Content-Type.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Validate JPEG & PNG downloads before used?

Postby HarmlessDave » Mon Nov 27, 2017 6:40 pm

magreenblatt wrote:You could use CefRequestHandler::GetResourceHandler. The added difficulty is that you can't just look for file extensions -- you'll also have to check the returned Content-Type.


I've been looking into this but am a little lost since the samples I see in the CEF tests use local data, and the CefResourceHandler functions are pure virtual so there is apparently no built-in behavior.

If I override the CEFClient GetResourceHandler to return my own CefResourceHandler, does the existing scheme handler provide any help with fetching the data? Are there library functions I can call?

For example, looking at the unit tests it looks like ProcessRequest() fetches the data needed for GetResponseHeaders() but they all "cheat" by using local data. Is there anything in CEF to call to really fetch the HTTP(S) data from the remote site while still giving me a chance to inspect and if needed replace it? Or do I need to add my own network code for this? Similarly, for ReadResponse() do I need to do network calls myself?

I can do this in WinInet if I need to, but I want to make sure I'm not reinventing the wheel.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Validate JPEG & PNG downloads before used?

Postby magreenblatt » Mon Nov 27, 2017 6:54 pm

magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Validate JPEG & PNG downloads before used?

Postby HarmlessDave » Mon Nov 27, 2017 7:13 pm

magreenblatt wrote:You can use CefURLRequest. See https://bitbucket.org/chromiumembedded/ ... t-requests


Thanks. Something like this?

handler:: ProcessRequest - copy the CefCallback pointer, begin the CefURLRequest, return true;

url_request_client:: OnRequestComplete - call handler -> ProcessRequestContinue()* to handle the results and call the cached CefCallback pointer

* a new function not an override
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Validate JPEG & PNG downloads before used?

Postby magreenblatt » Mon Nov 27, 2017 7:33 pm

Sounds about right.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 26 guests