Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

Commit 957719e

Browse files
committed
Fixing issue #254.
1 parent 2ec8f96 commit 957719e

4 files changed

Lines changed: 59 additions & 14 deletions

File tree

src/Chromely.CefSharp/Browser/Handlers/DefaultAssemblyResourceSchemeHandler.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace Chromely.CefSharp.Browser
1919
/// </summary>
2020
public class DefaultAssemblyResourceSchemeHandler : ResourceHandler
2121
{
22+
private const string STATUSTEXT_OK = "OK";
23+
private const string STATUSTEXT_ZEROFILESIZE = "Resource loading error: file size is zero.";
24+
private const string STATUSTEXT_FILENOTFOUND = "File not found.";
25+
private const string STATUSTEXT_BADREQUEST = "Resource loading error.";
26+
2227
protected readonly IChromelyRequestSchemeHandlerProvider _requestSchemeHandlerProvider;
2328
protected Regex _regex = new Regex("[/]");
2429
protected Stream _stream;
@@ -47,9 +52,26 @@ public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback c
4752
var fileAbsolutePath = u.AbsolutePath;
4853
var file = u.Authority + fileAbsolutePath;
4954

50-
// Check if file exists and not empty
5155
var fileInfo = new FileInfo(file);
52-
if ((fileInfo.Exists) && fileInfo.Length > 0)
56+
// Check if file exists
57+
if (!fileInfo.Exists)
58+
{
59+
StatusCode = (int)HttpStatusCode.NotFound;
60+
StatusText = STATUSTEXT_FILENOTFOUND;
61+
callback.Continue();
62+
63+
Logger.Instance.Log.LogWarning($"File: {file}: {StatusText}");
64+
}
65+
// Check if file exists but empty
66+
else if (fileInfo.Length == 0)
67+
{
68+
StatusCode = (int)HttpStatusCode.BadRequest;
69+
StatusText = STATUSTEXT_ZEROFILESIZE;
70+
callback.Continue();
71+
72+
Logger.Instance.Log.LogWarning($"File: {file}: {StatusText}");
73+
}
74+
else
5375
{
5476
Task.Run(() =>
5577
{
@@ -68,6 +90,8 @@ public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback c
6890
catch (Exception exception)
6991
{
7092
_stream = null;
93+
StatusCode = (int)HttpStatusCode.BadRequest;
94+
StatusText = STATUSTEXT_BADREQUEST;
7195
Logger.Instance.Log.LogError(exception, exception.Message);
7296
}
7397

@@ -136,6 +160,7 @@ protected void SetResponseInfoOnSuccess()
136160
ResponseLength = _stream.Length;
137161
MimeType = _mimeType;
138162
StatusCode = (int)HttpStatusCode.OK;
163+
StatusText = STATUSTEXT_OK;
139164
Stream = _stream;
140165
}
141166
}

src/Chromely.CefSharp/Browser/Handlers/DefaultResourceSchemeHandler.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ namespace Chromely.CefSharp.Browser
1717
/// </summary>
1818
public class DefaultResourceSchemeHandler : ResourceHandler
1919
{
20+
private const string STATUSTEXT_OK = "OK";
21+
private const string STATUSTEXT_ZEROFILESIZE = "Resource loading error: file size is zero.";
22+
private const string STATUSTEXT_FILENOTFOUND = "File not found.";
23+
private const string STATUSTEXT_BADREQUEST = "Resource loading error.";
24+
2025
protected Stream _stream;
2126
protected string _mimeType;
2227

@@ -40,9 +45,26 @@ public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback c
4045
var u = new Uri(request.Url);
4146
var file = u.Authority + u.AbsolutePath;
4247

43-
// Check if file exists and not empty
4448
var fileInfo = new FileInfo(file);
45-
if ((fileInfo.Exists) && fileInfo.Length > 0)
49+
// Check if file exists
50+
if (!fileInfo.Exists)
51+
{
52+
StatusCode = (int)HttpStatusCode.NotFound;
53+
StatusText = STATUSTEXT_FILENOTFOUND;
54+
callback.Continue();
55+
56+
Logger.Instance.Log.LogWarning($"File: {file}: {StatusText}");
57+
}
58+
// Check if file exists but empty
59+
else if (fileInfo.Length == 0)
60+
{
61+
StatusCode = (int)HttpStatusCode.BadRequest;
62+
StatusText = STATUSTEXT_ZEROFILESIZE;
63+
callback.Continue();
64+
65+
Logger.Instance.Log.LogWarning($"File: {file}: {StatusText}");
66+
}
67+
else
4668
{
4769
Task.Run(() =>
4870
{
@@ -62,6 +84,8 @@ public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback c
6284
catch (Exception exception)
6385
{
6486
_stream = null;
87+
StatusCode = (int)HttpStatusCode.BadRequest;
88+
StatusText = STATUSTEXT_BADREQUEST;
6589
Logger.Instance.Log.LogError(exception, exception.Message);
6690
}
6791

@@ -76,14 +100,9 @@ public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback c
76100
}
77101
}
78102
});
79-
return CefReturnValue.ContinueAsync;
80103
}
81-
else
82-
{
83-
StatusCode = (int)HttpStatusCode.NotFound;
84-
callback.Continue();
85-
return CefReturnValue.ContinueAsync;
86-
}
104+
105+
return CefReturnValue.ContinueAsync;
87106
}
88107

89108
protected virtual void SetResponseInfoOnSuccess()
@@ -94,6 +113,7 @@ protected virtual void SetResponseInfoOnSuccess()
94113
ResponseLength = _stream.Length;
95114
MimeType = _mimeType;
96115
StatusCode = (int)HttpStatusCode.OK;
116+
StatusText = STATUSTEXT_OK;
97117
Stream = _stream;
98118
}
99119
}

src/Chromely.CefSharp/Chromely.CefSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<Description>Chromely CefSharp implementation - this is in NetStandard as it can be used in both .NET Framework, .NET Core 3 and .NET 5 (Windows Only). Chromely.CefSharp version naming is based Chromely and Chromium versions implemented- major.minor.chromuim version.patch e.g 1.0.71.0.</Description>
1515
<Copyright>Copyright © 2017-2020 Chromely Projects</Copyright>
1616
<PackageLicenseUrl>https://github.com/chromelyapps/Chromely/blob/master/LICENSE.md</PackageLicenseUrl>
17-
<PackageProjectUrl>https://github.com/chromelyapps/Chromely</PackageProjectUrl>
17+
<PackageProjectUrl>https://github.com/chromelyapps/CefSharp</PackageProjectUrl>
1818
<PackageIconUrl>https://github.com/chromelyapps/Chromely/blob/master/nugets/chromely.ico?raw=true</PackageIconUrl>
1919
<PackageTags>CEF Chromium HTML5 Desktop Chromely CefSharp NetStandard .NET Core 3 .NET 5</PackageTags>
2020
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -24,7 +24,7 @@
2424
- Adding a configurable option - UseOnlyCefMessageLoop - https://github.com/chromelyapps/CefSharp/commit/29b26f293baea1430d4f2f1990a79d7416041a39
2525
</PackageReleaseNotes>
2626
<RepositoryType>Github Repository</RepositoryType>
27-
<RepositoryUrl>https://github.com/chromelyapps/Chromely</RepositoryUrl>
27+
<RepositoryUrl>https://github.com/chromelyapps/CefSharp</RepositoryUrl>
2828
<Configurations>Debug;Release;ReleaseLinux;DebugLinux</Configurations>
2929
<Platforms>AnyCPU</Platforms>
3030
</PropertyGroup>

src/Chromely.CefSharp/NativeHost/Frameless/DwmFramelessController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private void MouseLLHook_MouseMoveHandler(object sender, MouseMoveEventArgs even
416416
eventArgs.DeltaChangeSize != null &&
417417
!eventArgs.DeltaChangeSize.IsEmpty)
418418
{
419-
SetWindowPos(_windowHandle, IntPtr.Zero, eventArgs.DeltaChangeSize.Width, eventArgs.DeltaChangeSize.Height, 0, 0,
419+
SetWindowPos(_windowHandle, IntPtr.Zero, 0, 0, eventArgs.DeltaChangeSize.Width, eventArgs.DeltaChangeSize.Height,
420420
SWP.NOACTIVATE
421421
| SWP.NOZORDER
422422
| SWP.NOOWNERZORDER

0 commit comments

Comments
 (0)