SEBWIN-362: Ensured load error page is not rendered when a request is aborted.

This commit is contained in:
Damian Büchel 2020-03-18 10:24:22 +01:00
parent 34cf9b9cf4
commit 9e8c5056cf
2 changed files with 33 additions and 5 deletions

View file

@ -112,6 +112,7 @@ namespace SafeExamBrowser.Browser
private void InitializeControl()
{
var contextMenuHandler = new ContextMenuHandler();
var controlLogger = logger.CloneFor($"{nameof(BrowserControl)} #{Id}");
var dialogHandler = new DialogHandler();
var displayHandler = new DisplayHandler();
var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
@ -140,7 +141,17 @@ namespace SafeExamBrowser.Browser
InitializeRequestFilter(requestFilter);
control = new BrowserControl(contextMenuHandler, dialogHandler, displayHandler, downloadHandler, htmlLoader, keyboardHandler, lifeSpanHandler, requestHandler, startUrl);
control = new BrowserControl(
contextMenuHandler,
dialogHandler,
displayHandler,
downloadHandler,
htmlLoader,
keyboardHandler,
lifeSpanHandler,
controlLogger,
requestHandler,
startUrl);
control.AddressChanged += Control_AddressChanged;
control.LoadingStateChanged += Control_LoadingStateChanged;
control.TitleChanged += Control_TitleChanged;

View file

@ -9,6 +9,7 @@
using CefSharp;
using CefSharp.WinForms;
using SafeExamBrowser.Browser.Pages;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Browser;
using SafeExamBrowser.UserInterface.Contracts.Browser.Events;
@ -24,6 +25,7 @@ namespace SafeExamBrowser.Browser
private HtmlLoader htmlLoader;
private IKeyboardHandler keyboardHandler;
private ILifeSpanHandler lifeSpanHandler;
private ILogger logger;
private IRequestHandler requestHandler;
private AddressChangedEventHandler addressChanged;
@ -59,6 +61,7 @@ namespace SafeExamBrowser.Browser
HtmlLoader htmlLoader,
IKeyboardHandler keyboardHandler,
ILifeSpanHandler lifeSpanHandler,
ILogger logger,
IRequestHandler requestHandler,
string url) : base(url)
{
@ -69,6 +72,7 @@ namespace SafeExamBrowser.Browser
this.htmlLoader = htmlLoader;
this.keyboardHandler = keyboardHandler;
this.lifeSpanHandler = lifeSpanHandler;
this.logger = logger;
this.requestHandler = requestHandler;
}
@ -122,12 +126,25 @@ namespace SafeExamBrowser.Browser
private void BrowserControl_LoadError(object sender, LoadErrorEventArgs e)
{
var html = string.Copy(errorPage);
if (e.ErrorCode == CefErrorCode.None)
{
logger.Info($"Request for '{e.FailedUrl}' was successful.");
}
else if (e.ErrorCode == CefErrorCode.Aborted)
{
logger.Info($"Request for '{e.FailedUrl}' was aborted.");
}
else
{
var html = string.Copy(errorPage);
html = html.Replace("%%STATUS%%", $"{e.ErrorText} ({e.ErrorCode})");
html = html.Replace("%%URL%%", e.FailedUrl);
logger.Warn($"Request for '{e.FailedUrl}' failed: {e.ErrorText} ({e.ErrorCode}).");
e.Frame.LoadHtml(html, true);
html = html.Replace("%%STATUS%%", $"{e.ErrorText} ({e.ErrorCode})");
html = html.Replace("%%URL%%", e.FailedUrl);
e.Frame.LoadHtml(html, true);
}
}
}
}