C# Class CefSharp.ResourceHandler

Default implementation of IResourceHandler. This latest implementation provides some simplification, at a minimum you only need to override ProcessRequestAsync. See the project source on GitHub for working examples. used to implement a custom request handler interface. The methods of this class will always be called on the IO thread. Static helper methods are included like FromStream and FromString that make dealing with fixed resources easy.
Inheritance: IResourceHandler
Show file Open project: cefsharp/CefSharp Class Usage Examples

Public Methods

Method Description
Cancel ( ) : void

Called if the request is cancelled

Dispose ( ) : void

Dispose of resources here

FromFilePath ( string fileName, string mimeType = null ) : ResourceHandler

Gets the resource from the file path specified. Use the ResourceHandler.GetMimeType helper method to lookup the mimeType if required.

FromStream ( Stream stream, string mimeType = DefaultMimeType ) : ResourceHandler

Gets the resource from a stream.

FromString ( string text, Encoding encoding = null, bool includePreamble = true, string mimeType = DefaultMimeType ) : ResourceHandler

Gets a ResourceHandler that represents a string. Without a Preamble, Cef will use BrowserSettings.DefaultEncoding to load the html.

FromString ( string text, string fileExtension ) : ResourceHandler

Gets the resource from the string.

GetMimeType ( string extension ) : string

Gets the MIME type of the content.

GetResponse ( IResponse response, long &responseLength, string &redirectUrl ) : Stream

Populate the response stream, response length. When this method is called the response should be fully populated with data. It is possible to redirect to another url at this point in time. NOTE: It's no longer manditory to implement this method, you can simply populate the properties of this instance and they will be set by the default implementation.

IResourceHandler ( ) : void
IResourceHandler ( IResponse response, long &responseLength, string &redirectUrl ) : void
ProcessRequestAsync ( IRequest request, ICallback callback ) : bool

Begin processing the request. If you have the data in memory you can execute the callback immediately and return true. For Async processing you would typically spawn a Task to perform processing, then return true. When the processing is complete execute callback.Continue(); In your processing Task, simply set the StatusCode, StatusText, MimeType, ResponseLength and Stream

ResourceHandler ( ) : System

Default Constructor

Private Methods

Method Description
FromFileName ( string filePath, string fileExtension = null ) : ResourceHandler
GetStream ( string text, Encoding encoding, bool includePreamble ) : MemoryStream
IResourceHandler ( CefSharp.Cookie cookie ) : bool
IResourceHandler ( IRequest request, ICallback callback ) : bool
IResourceHandler ( Stream dataOut, int &bytesRead, ICallback callback ) : bool
ResourceHandler ( string mimeType, ResourceHandlerType type ) : System

Initializes a new instance of the ResourceHandler class.

Method Details

Cancel() public method

Called if the request is cancelled
public Cancel ( ) : void
return void

Dispose() public method

Dispose of resources here
public Dispose ( ) : void
return void

FromFilePath() public static method

Gets the resource from the file path specified. Use the ResourceHandler.GetMimeType helper method to lookup the mimeType if required.
public static FromFilePath ( string fileName, string mimeType = null ) : ResourceHandler
fileName string Location of the file.
mimeType string The mimeType if null then text/html is used.
return ResourceHandler

FromStream() public static method

Gets the resource from a stream.
public static FromStream ( Stream stream, string mimeType = DefaultMimeType ) : ResourceHandler
stream Stream A stream of the resource.
mimeType string Type of MIME.
return ResourceHandler

FromString() public static method

Gets a ResourceHandler that represents a string. Without a Preamble, Cef will use BrowserSettings.DefaultEncoding to load the html.
public static FromString ( string text, Encoding encoding = null, bool includePreamble = true, string mimeType = DefaultMimeType ) : ResourceHandler
text string The html string
encoding System.Text.Encoding Character Encoding
includePreamble bool Include encoding preamble
mimeType string Mime Type
return ResourceHandler

FromString() public static method

Gets the resource from the string.
public static FromString ( string text, string fileExtension ) : ResourceHandler
text string The text.
fileExtension string The file extension.
return ResourceHandler

GetMimeType() public static method

Gets the MIME type of the content.
extension
public static GetMimeType ( string extension ) : string
extension string The extension.
return string

GetResponse() public method

Populate the response stream, response length. When this method is called the response should be fully populated with data. It is possible to redirect to another url at this point in time. NOTE: It's no longer manditory to implement this method, you can simply populate the properties of this instance and they will be set by the default implementation.
public GetResponse ( IResponse response, long &responseLength, string &redirectUrl ) : Stream
response IResponse The response object used to set Headers, StatusCode, etc
responseLength long length of the response
redirectUrl string If set the request will be redirect to specified Url
return Stream

IResourceHandler() public method

public IResourceHandler ( ) : void
return void

IResourceHandler() public method

public IResourceHandler ( IResponse response, long &responseLength, string &redirectUrl ) : void
response IResponse
responseLength long
redirectUrl string
return void

ProcessRequestAsync() public method

Begin processing the request. If you have the data in memory you can execute the callback immediately and return true. For Async processing you would typically spawn a Task to perform processing, then return true. When the processing is complete execute callback.Continue(); In your processing Task, simply set the StatusCode, StatusText, MimeType, ResponseLength and Stream
public ProcessRequestAsync ( IRequest request, ICallback callback ) : bool
request IRequest The request object.
callback ICallback The callback used to Continue or Cancel the request (async).
return bool

ResourceHandler() public method

Default Constructor
public ResourceHandler ( ) : System
return System