Reputation: 15797
I am playing with CefGlue (the .net wrapper around chromium embedded") I need to make some proof of concept so I create my own special html files that contains what I need to test. However I can't find a way to load those files.
The CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url);
requires an url and there is no overloaded method that accepts the content as string. So the question is: How to load html file from disk?
Upvotes: 1
Views: 1836
Reputation: 15797
I found a solution: just pass the full path to the file in the url parameter and everything works fine. It's just like chrome opening file from disk so I don't know why I did not tried that the first time.
Upvotes: 2
Reputation: 804
I've not used CefGlue - but in general you can use a custom cef resource handler to load the file. Briefly, when CEF sees your URL, they will call through a resource override handler you set up, which will then read that resource into a byte stream. In our case we read an html file compiled into our application resources. In your case I suppose you could also read the resource from disk at that time, though I've not done this. If you can compile resources into your C# app, you can add the html file into the Resources if you prefer.
We pass the url to CreateBrowserSync() in our case, and CEF ends up calling our ResourceHandler to load it. The CefClient c++ sample has an excellent example of this, see resource_util_win.cpp.
This is set up in a Handler override in CefResourceHandler. We overrode GetResourceHandler, their example overrides ProcessRequest in SchemeHandler. See scheme_test.cpp in the CefClient sample.
Most of the code from their samples is pretty boiler plate and you should be able to use what they have as the basis for your implementation - it's really too much code to list it all out here though.
Upvotes: 2