Page 1 of 1

Custom scheme for file URLS ignore is_local option

PostPosted: Mon May 07, 2018 9:23 am
by robertozuru
Hello there!

I have a question that's really annoying. I'm using Unreal Engine 4 embedded CEF, my use case involves the use of POST requests to send files to some destination.

Googling around I found out that I needed to register a custom scheme for "file" and enable is_local, and I also had to set "disable-web-security" and "allow-runing-insecure-content" to cef. I did it and it worked well. It was on version 3.2693 on windows x64.

When Epic games updated CEF to 3.3071, AddCustomScheme changed signature adding three more parameters. One of that parameters specifically allowed for CORS. The problem is that in this version, even with cors set to true, won't let me access file:/// URLS (Denied unauthorized request for file:///path.blabla). Here is how I register the scheme
Code: Select all
void FCEFBrowserApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) {
   registrar->AddCustomScheme("file", true, true, false, false, true, false);
}


And here is where I add my custom parameters
Code: Select all
void FCEFBrowserApp::OnBeforeCommandLineProcessing(const CefString& ProcessType, CefRefPtr< CefCommandLine > CommandLine)
{
   CommandLine->AppendSwitch("disable-gpu");
   CommandLine->AppendSwitch("disable-gpu-compositing");

   CommandLine->AppendSwitch("allow-running-insecure-content");
   CommandLine->AppendSwitch("enable-media-stream");
   CommandLine->AppendSwitch("disable-web-security");
   CommandLine->AppendSwitch("enable-local-file-accesses");

#if !PLATFORM_MAC
   CommandLine->AppendSwitch("enable-begin-frame-scheduling");
#endif
}


Since this happened after cef version change, could be that I need something different to enable cors and local access to cef?
I tried setting "enable-local-file-accesses" but with no luck. I guess I'm missing something, but I don't know what.
Being that a specifically embedded version of cef, it's not possible for me to update or downgrade it without taking care of unreal source code too, and this is out of the question.

Thanks in advance for your support.

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Mon May 07, 2018 10:19 am
by magreenblatt
Don't use a custom scheme for "file". Use http/https instead. See https://bitbucket.org/chromiumembedded/ ... t-handling

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Mon May 07, 2018 10:42 am
by robertozuru
magreenblatt wrote:Don't use a custom scheme for "file". Use http/https instead. See https://bitbucket.org/chromiumembedded/ ... t-handling

Thanks for your answer.
I landed on that page before, I tried to register custom scheme to http but obviously it didn't work. I suppose that I have to change the url from file:// to http:// as well, I didn't do that because I supposed that local file links did not work on other schemas.

For example, I have file:///C:/myfile.jpg
I change schema name from "file" to "http" (setting cors enabled)
I change URL of file to http://C:/myfile.jpg

Is that correct?

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Mon May 07, 2018 11:35 am
by magreenblatt
No, you would change the URL to http://yourdomain.com/myfile.jpg and handle the resource request as described in the above link.

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Tue May 08, 2018 1:39 am
by robertozuru
The problem here is I'm trying to upload a local file, I have no local webserver that's serving it and I won't have any anytime soon.

I'll try to be more specific about my case:
These files I'm trying to upload are generated by the game. I have a web browser inside my game that is used to display the "upload user interface" where I can upload these saves, then a JS application inside the browser used to take the local file and send it to a remote server. Unfortunately this situation cannot be changed right now, I know there are better ways to do it but actually I'm forced to pass trough the web browser and the sent JS application itself.

Since I don't have any local webserver I think there's no way for me to link the file like that. Maybe I can trick CEF to recover specific domains from local directories? Otherwise I think I cannot circumvent these specific restrictions about local files.

I'm sorry if these kind of questions looks trivial to you, it really seems to me that cef is designed to (legitimally) prevent local file access and I cannot do anything about it.

Regards
RB

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Tue May 08, 2018 1:59 am
by ndesktop
You do not need a local webserver. You can add a custom scheme (either a custom scheme, such as game://, but http:// will do it, too) and request files like
game://filesroot/file1.html
From inside the scheme handler you parse like a regular protocol, load the file1.html from game files collection, get the bytes and return a normal 200 OK with content-length=filesize in bytes and file content.
Inside cefclient scheme test there is a starting example.

Re: Custom scheme for file URLS ignore is_local option

PostPosted: Tue May 08, 2018 3:00 am
by robertozuru
ndesktop wrote:You do not need a local webserver. You can add a custom scheme (either a custom scheme, such as game://, but http:// will do it, too) and request files like
game://filesroot/file1.html
From inside the scheme handler you parse like a regular protocol, load the file1.html from game files collection, get the bytes and return a normal 200 OK with content-length=filesize in bytes and file content.
Inside cefclient scheme test there is a starting example.


Nice, I'll give it a try, thank you all for your suggestions