-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathFileResourceHandler.cs
More file actions
104 lines (88 loc) · 3.58 KB
/
FileResourceHandler.cs
File metadata and controls
104 lines (88 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright © 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.IO;
using CefSharp.Callback;
namespace CefSharp
{
/// <summary>
/// FileResourceHandler is used as a placeholder class which uses native CEF implementations.
/// CefStreamReader::CreateForFile is used to create a CefStreamReader instance which is passed to
/// a new instance of CefStreamResourceHandler
/// (Was previously ResourceHandlerType::File to differentiate, going for a more flexible approach now)
/// TODO: Move this class into Handler namespace
/// </summary>
public class FileResourceHandler : IResourceHandler
{
/// <summary>
/// Path of the underlying file
/// </summary>
public string FilePath { 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="FileResourceHandler"/> class.
/// </summary>
/// <param name="mimeType">mimeType</param>
/// <param name="filePath">filePath</param>
public FileResourceHandler(string mimeType, string filePath)
{
if (string.IsNullOrEmpty(mimeType))
{
throw new ArgumentNullException("mimeType", "Please provide a valid mimeType");
}
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException("filePath", "Please provide a valid filePath");
}
if (!File.Exists(filePath))
{
throw new FileNotFoundException("Unable to create FileResourceHandler", filePath);
}
MimeType = mimeType;
FilePath = filePath;
}
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");
}
void IResourceHandler.Cancel()
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.Open(IRequest request, out bool handleRequest, ICallback callback)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.Skip(long bytesToSkip, out long bytesSkipped, IResourceSkipCallback callback)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback)
{
//Should never be called
throw new NotImplementedException("This method should never be called");
}
void IDisposable.Dispose()
{
//NOOP
}
}
}