Custom scheme: loading a file via redirectUrl

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.

Custom scheme: loading a file via redirectUrl

Postby iUltimateLP » Mon Aug 15, 2016 2:27 pm

Hey guys,
I've been working on a little collection of tests for a game I do, which uses Cef3.
I started up with the cefclient project, and added a bit of stuff to add a custom scheme:
The .cpp can be found here (I don't show the .h file since it only defines the RegisterTestHandler())
How it should work: I can open up a URL like test://something, and it should open file:///C:/Users/Johnny/Desktop/test.html, no matter what the string behind test:// actually is, but instead, it just opens up nothing.. When I put in a http:// URL inside the redirectURL, it works.. Can anybody help me?
Thanks in advance!

Edit: if I load the file:/// path manually, it works. Also, if I reference the test:// URL in a HTML tag, for instance like this: <img src="test://randomstring></img>, it also works, so redirecting does work in HTML tags, but not with just loading a page? Strange..
iUltimateLP
Newbie
 
Posts: 4
Joined: Mon Aug 15, 2016 11:51 am

Re: Custom scheme: loading a file via redirectUrl

Postby magreenblatt » Tue Aug 16, 2016 3:14 am

You can't load a file:// URL from non-file:// URLs. Host all of the files via a custom scheme or request handler, like your test scheme.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Custom scheme: loading a file via redirectUrl

Postby iUltimateLP » Tue Aug 16, 2016 5:53 am

I don't really understand.. I made up something so actually test://folder/file.ext redirects me to file:///C:/Users/Johnny/Desktop/folder/file.ext, and if I for example create a HTML page and put in a <img src="test://picture.png"></img>, that picture actually loads (I open up the HTML via file:/// as well), but I can't load the HTML page itself using test://, although it redirects to the right file-url..
iUltimateLP
Newbie
 
Posts: 4
Joined: Mon Aug 15, 2016 11:51 am

Re: Custom scheme: loading a file via redirectUrl

Postby magreenblatt » Tue Aug 16, 2016 6:22 am

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

Re: Custom scheme: loading a file via redirectUrl

Postby iUltimateLP » Tue Aug 16, 2016 12:00 pm

I read that again,
but I can't find much differences to my code, however I have some questions:
1.
Code: Select all
void MyApp::OnRegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar) {
  // Register "client" as a standard scheme.
  registrar->AddCustomScheme("client", true, false, false);
}

Do I need that, and then do I need to replace client with my scheme name?
The only thing left I find is this:
If the response data is known at request time the CefStreamResourceHandler class provides a convenient default implementation of CefResourceHandler.
Code: Select all
// CefStreamResourceHandler is part of the libcef_dll_wrapper project.
#include “include/wrapper/cef_stream_resource_handler.h”

const std::string& html_content = “<html><body>Hello!</body></html>”;

// Create a stream reader for |html_content|.
CefRefPtr<CefStreamReader> stream =
    CefStreamReader::CreateForData(
        static_cast<void*>(const_cast<char*>(html_content.c_str())),
        html_content.size());

// Constructor for HTTP status code 200 and no custom response headers.
// There’s also a version of the constructor for custom status code and response headers.
return new CefStreamResourceHandler("text/html", stream);


Do I need this in some way?
Thank you for answering me :)
iUltimateLP
Newbie
 
Posts: 4
Joined: Mon Aug 15, 2016 11:51 am

Re: Custom scheme: loading a file via redirectUrl

Postby iUltimateLP » Wed Aug 24, 2016 10:09 am

I'm sorry but I don't understand how I can "host the file on my custom scheme" instead of loading it via file:///. Can any1 help me?
iUltimateLP
Newbie
 
Posts: 4
Joined: Mon Aug 15, 2016 11:51 am


Return to Support Forum

Who is online

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