forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemeHandler.cs
More file actions
53 lines (46 loc) · 1.55 KB
/
Copy pathSchemeHandler.cs
File metadata and controls
53 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using CefSharp.Example.Properties;
namespace CefSharp.Example
{
class SchemeHandlerFactory : ISchemeHandlerFactory
{
public ISchemeHandler Create()
{
return new SchemeHandler();
}
}
class SchemeHandler : ISchemeHandler
{
private readonly IDictionary<string, string> resources;
public SchemeHandler()
{
resources = new Dictionary<string, string>
{
{ "BindingTest.html", Resources.BindingTest },
{ "PopupTest.html", Resources.PopupTest },
{ "SchemeTest.html", Resources.SchemeTest },
{ "TooltipTest.html", Resources.TooltipTest },
};
}
public bool ProcessRequestAsync(IRequest request, SchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback)
{
var uri = new Uri(request.Url);
var segments = uri.Segments;
var file = segments[segments.Length - 1];
string resource;
if (resources.TryGetValue(file, out resource) &&
!String.IsNullOrEmpty(resource))
{
var bytes = Encoding.UTF8.GetBytes(resource);
response.ResponseStream = new MemoryStream(bytes);
response.MimeType = "text/html";
requestCompletedCallback();
return true;
}
return false;
}
}
}