steven181 wrote:Can you please give me any suggestion?
Without full code this no have sense. CefGlue.1 can't help you 'cause it outdated but many changes was be introduced from CEF by modern 1 & 3 versions.
1. Create scheme handler factory first:
- Code: Select all
class MySchemeHandlerFactory : CefSchemeHandlerFactory
{
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
{
return new MySchemeHandler();
}
}
2. Create scheme handler (resource handler):
- Code: Select all
// very-very-very simple stub
class MySchemeHandler : CefResourceHandler
{
private static int _no;
private bool _completed;
protected override bool ProcessRequest(CefRequest request, CefCallback callback)
{
callback.Continue();
return true;
}
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
{
response.SetHeaderMap();
response.Status = 200;
response.MimeType = "text/html";
response.StatusText = "OK";
responseLength = -1; // unknown content-length
redirectUrl = null; // no-redirect
}
protected override bool ReadResponse(System.IO.Stream response, int bytesToRead, out int bytesRead, CefCallback callback)
{
if (_completed)
{
bytesRead = 0;
return false;
}
else
{
_no++;
// very simple response with one block
var content = Encoding.UTF8.GetBytes("Response #" + _no.ToString());
if (bytesToRead < content.Length) throw new NotImplementedException(); // oops
response.Write(content, 0, content.Length);
bytesRead = content.Length;
_completed = true;
return true;
}
}
protected override bool CanGetCookie(CefCookie cookie)
{
return false;
}
protected override bool CanSetCookie(CefCookie cookie)
{
return false;
}
protected override void Cancel()
{
}
}
3. Register scheme handler factory:
- Code: Select all
CefRuntime.RegisterSchemeHandlerFactory("http", "_app.mycooldomain", new MySchemeHandlerFactory());
If you want use custom scheme name (not http) - then you must also register it within renderers, and they are restricted - body of POST requests are not delivered to scheme handler. So it is much easier use http scheme with own unique domain.
Just follow CEF docs.
Also follow CefRequest/CefResponse GetHeaderMap/SetHeaderMap methods issue - currently this methods not implemented and you can't access to request/response headers (for example to prevent caching). But this issue will be resolved soon.
May be i'm something missing - but it is looks as minimal setup.