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
Afficher le fichier Open project: cefsharp/CefSharp Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

Called if the request is cancelled
public Cancel ( ) : void
Résultat void

Dispose() public méthode

Dispose of resources here
public Dispose ( ) : void
Résultat void

FromFilePath() public static méthode

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.
Résultat ResourceHandler

FromStream() public static méthode

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.
Résultat ResourceHandler

FromString() public static méthode

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
Résultat ResourceHandler

FromString() public static méthode

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

GetMimeType() public static méthode

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

GetResponse() public méthode

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
Résultat Stream

IResourceHandler() public méthode

public IResourceHandler ( ) : void
Résultat void

IResourceHandler() public méthode

public IResourceHandler ( IResponse response, long &responseLength, string &redirectUrl ) : void
response IResponse
responseLength long
redirectUrl string
Résultat void

ProcessRequestAsync() public méthode

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).
Résultat bool

ResourceHandler() public méthode

Default Constructor
public ResourceHandler ( ) : System
Résultat System