Files
cefsharp/CefSharp/Internals/ByteArrayResourceHandler.cs
T
amaitland 6691d0080a Refactor ResourceHandler, split FileResourceHandler out into it's own class, rather than relaying on ResourceHandlerType - this allows us to add more underlying CEF type wrappers without a huge amount of effort now.
Add new ByteArrayResourceHandler - uses CefStreamReader::CreateForData to load the byte array, for use with CefStreamResourceHandler
Add ResourceHandler.FromByteArray method for ease of use
Change ResourceHandler.FromString to use the new ByteArrayResourceHandler class
2017-05-05 12:55:44 +10:00

94 lines
2.9 KiB
C#

// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
namespace CefSharp
{
/// <summary>
/// ByteArrayResourceHandler is used as a placeholder to represent the underlying CefStreamResourceHandler
/// </summary>
public class ByteArrayResourceHandler : IResourceHandler
{
/// <summary>
/// Underlying byte array that represents the data
/// </summary>
public byte[] Data { get; private set; }
/// <summary>
/// Gets or sets the Mime Type.
/// </summary>
public string MimeType { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ByteArrayResourceHandler"/> class.
/// </summary>
/// <param name="mimeType">mimeType</param>
/// <param name="filePath">filePath</param>
public ByteArrayResourceHandler(string mimeType, byte[] data)
{
if(string.IsNullOrEmpty(mimeType))
{
throw new ArgumentNullException("mimeType", "Please provide a valid mimeType");
}
if(data == null)
{
throw new ArgumentNullException("data", "Please provide a valid array");
}
MimeType = mimeType;
Data = data;
}
bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
void IResourceHandler.GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.ReadResponse(Stream dataOut, out int bytesRead, ICallback callback)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.CanGetCookie(Cookie cookie)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.CanSetCookie(Cookie cookie)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
void IResourceHandler.Cancel()
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
void IDisposable.Dispose()
{
//NOOP
}
}
}