|
| 1 | +// Copyright © 2010-2017 The CefSharp Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Collections.Specialized; |
| 8 | +using System.IO; |
| 9 | +using System.Text; |
| 10 | + |
| 11 | +namespace CefSharp |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// FileResourceHandler is used as a placeholder to represent the underlying CefStreamResourceHandler |
| 15 | + /// (Was previously ResourceHandlerType::File to differentiate, going for a more flexible approach now) |
| 16 | + /// </summary> |
| 17 | + public class FileResourceHandler : IResourceHandler |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// Path of the underlying file |
| 21 | + /// </summary> |
| 22 | + public string FilePath { get; private set; } |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Gets or sets the Mime Type. |
| 26 | + /// </summary> |
| 27 | + public string MimeType { get; set; } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Initializes a new instance of the <see cref="FileResourceHandler"/> class. |
| 31 | + /// </summary> |
| 32 | + /// <param name="mimeType">mimeType</param> |
| 33 | + /// <param name="filePath">filePath</param> |
| 34 | + public FileResourceHandler(string mimeType, string filePath) |
| 35 | + { |
| 36 | + if(string.IsNullOrEmpty(mimeType)) |
| 37 | + { |
| 38 | + throw new ArgumentNullException("mimeType", "Please provide a valid mimeType"); |
| 39 | + } |
| 40 | + |
| 41 | + if(string.IsNullOrEmpty(filePath)) |
| 42 | + { |
| 43 | + throw new ArgumentNullException("filePath", "Please provide a valid filePath"); |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + MimeType = mimeType; |
| 48 | + FilePath = filePath; |
| 49 | + } |
| 50 | + |
| 51 | + bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback) |
| 52 | + { |
| 53 | + //Should never be called |
| 54 | + throw new NotImplementedException("This method should never be called"); |
| 55 | + } |
| 56 | + |
| 57 | + void IResourceHandler.GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl) |
| 58 | + { |
| 59 | + //Should never be called |
| 60 | + throw new NotImplementedException("This method should never be called"); |
| 61 | + } |
| 62 | + |
| 63 | + bool IResourceHandler.ReadResponse(Stream dataOut, out int bytesRead, ICallback callback) |
| 64 | + { |
| 65 | + //Should never be called |
| 66 | + throw new NotImplementedException("This method should never be called"); |
| 67 | + } |
| 68 | + |
| 69 | + bool IResourceHandler.CanGetCookie(Cookie cookie) |
| 70 | + { |
| 71 | + //Should never be called |
| 72 | + throw new NotImplementedException("This method should never be called"); |
| 73 | + } |
| 74 | + |
| 75 | + bool IResourceHandler.CanSetCookie(Cookie cookie) |
| 76 | + { |
| 77 | + //Should never be called |
| 78 | + throw new NotImplementedException("This method should never be called"); |
| 79 | + } |
| 80 | + |
| 81 | + void IResourceHandler.Cancel() |
| 82 | + { |
| 83 | + //Should never be called |
| 84 | + throw new NotImplementedException("This method should never be called"); |
| 85 | + } |
| 86 | + |
| 87 | + void IDisposable.Dispose() |
| 88 | + { |
| 89 | + //NOOP |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | + |
0 commit comments