EO.WebBrowser allows you to intercept or handle any request sent by the browser engine. For example,
you can implement a custom resource handler to serve image or the entire HTML from a database.
It takes a few easy steps to do so, as described in details
here, but the
key step is to implement the code that sends out the result. As demonstrated below:
internal class SampleHandler : ResourceHandler
{
public const string EmbeddedPageUrl = "sample://embedded_page";
public override void ProcessRequest(Request request, Response response)
{
//Only process EmbeddedPageUrl
if (string.Compare(request.Url, EmbeddedPageUrl, true) == 0)
{
//Set content type
response.ContentType = "text/html";
//Copy contents of EmbeddedPage.htm to the output stream
byte[] buffer = new byte[1024];
Stream stream = typeof(SampleHandler).Assembly.GetManifestResourceStream(
"EO.TabbedBrowser.EmbeddedPage.htm");
while (true)
{
int nBytesRead = stream.Read(buffer, 0, buffer.Length);
if (nBytesRead <= 0)
break;
response.OutputStream.Write(buffer, 0, nBytesRead);
}
}
}
....
}
Friend Class SampleHandler
Inherits ResourceHandler
Public Const EmbeddedPageUrl As String = "sample://embedded_page"
Public Overrides Sub ProcessRequest(request As Request, response As Response)
'Only process EmbeddedPageUrl
If String.Compare(request.Url, EmbeddedPageUrl, True) = 0 Then
'Set content type
response.ContentType = "text/html"
'Copy contents of EmbeddedPage.htm to the output stream
Dim buffer As Byte() = New Byte(1023) {}
Dim stream As Stream = _
GetType(SampleHandler).Assembly.GetManifestResourceStream( _
"EO.TabbedBrowser.EmbeddedPage.htm")
While True
Dim nBytesRead As Integer = stream.Read(buffer, 0, buffer.Length)
If nBytesRead <= 0 Then
Exit While
End If
response.OutputStream.Write(buffer, 0, nBytesRead)
End While
End If
End Sub
....
End Class
The TabbedBrowser sample uses the above code to handle special Url "sample://embedded_page" and
serves the whole HTML from an embedded resource file "EmbeddedPage.html". You can download and
install the
See here for detailed
information on how to implement custom resource handler.
|