SEBWIN-302: Implemented configuration of internal PDF reader.
This commit is contained in:
parent
cf2a74f6ce
commit
603c268839
6 changed files with 81 additions and 5 deletions
|
@ -156,10 +156,16 @@ namespace SafeExamBrowser.Browser
|
||||||
|
|
||||||
cefSettings.CefCommandLineArgs.Add("touch-events", "enabled");
|
cefSettings.CefCommandLineArgs.Add("touch-events", "enabled");
|
||||||
|
|
||||||
|
if (!settings.AllowPdfReader)
|
||||||
|
{
|
||||||
|
cefSettings.CefCommandLineArgs.Add("disable-pdf-extension", "");
|
||||||
|
}
|
||||||
|
|
||||||
logger.Debug($"Cache path: {cefSettings.CachePath}");
|
logger.Debug($"Cache path: {cefSettings.CachePath}");
|
||||||
logger.Debug($"Engine version: Chromium {Cef.ChromiumVersion}, CEF {Cef.CefVersion}, CefSharp {Cef.CefSharpVersion}");
|
logger.Debug($"Engine version: Chromium {Cef.ChromiumVersion}, CEF {Cef.CefVersion}, CefSharp {Cef.CefSharpVersion}");
|
||||||
logger.Debug($"Log file: {cefSettings.LogFile}");
|
logger.Debug($"Log file: {cefSettings.LogFile}");
|
||||||
logger.Debug($"Log severity: {cefSettings.LogSeverity}");
|
logger.Debug($"Log severity: {cefSettings.LogSeverity}");
|
||||||
|
logger.Debug($"PDF reader: {(settings.AllowPdfReader ? "Enabled" : "Disabled")}");
|
||||||
|
|
||||||
return cefSettings;
|
return cefSettings;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Mime;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -76,6 +77,22 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
return base.OnBeforeResourceLoad(webBrowser, browser, frame, request, callback);
|
return base.OnBeforeResourceLoad(webBrowser, browser, frame, request, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnResourceResponse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
||||||
|
{
|
||||||
|
var abort = true;
|
||||||
|
|
||||||
|
if (RedirectToDisablePdfToolbar(request, response, out var url))
|
||||||
|
{
|
||||||
|
chromiumWebBrowser.Load(url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
abort = base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return abort;
|
||||||
|
}
|
||||||
|
|
||||||
private void AppendCustomUserAgent(IRequest request)
|
private void AppendCustomUserAgent(IRequest request)
|
||||||
{
|
{
|
||||||
var headers = new NameValueCollection(request.Headers);
|
var headers = new NameValueCollection(request.Headers);
|
||||||
|
@ -100,20 +117,20 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
|
|
||||||
private bool Block(IRequest request)
|
private bool Block(IRequest request)
|
||||||
{
|
{
|
||||||
|
var block = false;
|
||||||
|
|
||||||
if (settings.Filter.ProcessContentRequests)
|
if (settings.Filter.ProcessContentRequests)
|
||||||
{
|
{
|
||||||
var result = filter.Process(new Request { Url = request.Url });
|
var result = filter.Process(new Request { Url = request.Url });
|
||||||
var block = result == FilterResult.Block;
|
|
||||||
|
|
||||||
if (block)
|
if (result == FilterResult.Block)
|
||||||
{
|
{
|
||||||
|
block = true;
|
||||||
logger.Info($"Blocked content request for '{request.Url}'.");
|
logger.Info($"Blocked content request for '{request.Url}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsMailtoUrl(string url)
|
private bool IsMailtoUrl(string url)
|
||||||
|
@ -121,6 +138,23 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
return url.StartsWith(Uri.UriSchemeMailto);
|
return url.StartsWith(Uri.UriSchemeMailto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool RedirectToDisablePdfToolbar(IRequest request, IResponse response, out string url)
|
||||||
|
{
|
||||||
|
const string DISABLE_PDF_TOOLBAR = "#toolbar=0";
|
||||||
|
var isPdf = response.Headers["Content-Type"] == MediaTypeNames.Application.Pdf;
|
||||||
|
var hasFragment = request.Url.Contains(DISABLE_PDF_TOOLBAR);
|
||||||
|
var redirect = settings.AllowPdfReader && !settings.AllowPdfReaderToolbar && isPdf && !hasFragment;
|
||||||
|
|
||||||
|
url = request.Url + DISABLE_PDF_TOOLBAR;
|
||||||
|
|
||||||
|
if (redirect)
|
||||||
|
{
|
||||||
|
logger.Info($"Redirecting to '{url}' to disable PDF reader toolbar.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect;
|
||||||
|
}
|
||||||
|
|
||||||
private void ReplaceSebScheme(IRequest request)
|
private void ReplaceSebScheme(IRequest request)
|
||||||
{
|
{
|
||||||
if (Uri.IsWellFormedUriString(request.Url, UriKind.RelativeOrAbsolute))
|
if (Uri.IsWellFormedUriString(request.Url, UriKind.RelativeOrAbsolute))
|
||||||
|
|
|
@ -36,6 +36,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
case Keys.Browser.AllowPageZoom:
|
case Keys.Browser.AllowPageZoom:
|
||||||
MapAllowPageZoom(settings, value);
|
MapAllowPageZoom(settings, value);
|
||||||
break;
|
break;
|
||||||
|
case Keys.Browser.AllowPdfReaderToolbar:
|
||||||
|
MapAllowPdfReaderToolbar(settings, value);
|
||||||
|
break;
|
||||||
case Keys.Browser.AdditionalWindow.AllowAddressBar:
|
case Keys.Browser.AdditionalWindow.AllowAddressBar:
|
||||||
MapAllowAddressBarAdditionalWindow(settings, value);
|
MapAllowAddressBarAdditionalWindow(settings, value);
|
||||||
break;
|
break;
|
||||||
|
@ -60,6 +63,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
case Keys.Browser.DownloadDirectory:
|
case Keys.Browser.DownloadDirectory:
|
||||||
MapDownloadDirectory(settings, value);
|
MapDownloadDirectory(settings, value);
|
||||||
break;
|
break;
|
||||||
|
case Keys.Browser.DownloadPdfFiles:
|
||||||
|
MapDownloadPdfFiles(settings, value);
|
||||||
|
break;
|
||||||
case Keys.Browser.EnableBrowser:
|
case Keys.Browser.EnableBrowser:
|
||||||
MapEnableBrowser(settings, value);
|
MapEnableBrowser(settings, value);
|
||||||
break;
|
break;
|
||||||
|
@ -197,6 +203,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapAllowPdfReaderToolbar(AppSettings settings, object value)
|
||||||
|
{
|
||||||
|
if (value is bool allow)
|
||||||
|
{
|
||||||
|
settings.Browser.AllowPdfReaderToolbar = allow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MapAllowReload(AppSettings settings, object value)
|
private void MapAllowReload(AppSettings settings, object value)
|
||||||
{
|
{
|
||||||
if (value is bool allow)
|
if (value is bool allow)
|
||||||
|
@ -221,6 +235,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapDownloadPdfFiles(AppSettings settings, object value)
|
||||||
|
{
|
||||||
|
if (value is bool download)
|
||||||
|
{
|
||||||
|
settings.Browser.AllowPdfReader = !download;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MapEnableBrowser(AppSettings settings, object value)
|
private void MapEnableBrowser(AppSettings settings, object value)
|
||||||
{
|
{
|
||||||
if (value is bool enable)
|
if (value is bool enable)
|
||||||
|
|
|
@ -126,6 +126,8 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
||||||
settings.Browser.AllowCustomDownloadLocation = false;
|
settings.Browser.AllowCustomDownloadLocation = false;
|
||||||
settings.Browser.AllowDownloads = true;
|
settings.Browser.AllowDownloads = true;
|
||||||
settings.Browser.AllowPageZoom = true;
|
settings.Browser.AllowPageZoom = true;
|
||||||
|
settings.Browser.AllowPdfReader = true;
|
||||||
|
settings.Browser.AllowPdfReaderToolbar = false;
|
||||||
settings.Browser.AllowUploads = true;
|
settings.Browser.AllowUploads = true;
|
||||||
settings.Browser.MainWindow.AllowAddressBar = false;
|
settings.Browser.MainWindow.AllowAddressBar = false;
|
||||||
settings.Browser.MainWindow.AllowBackwardNavigation = false;
|
settings.Browser.MainWindow.AllowBackwardNavigation = false;
|
||||||
|
|
|
@ -46,9 +46,11 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
||||||
internal const string AllowDeveloperConsole = "allowDeveloperConsole";
|
internal const string AllowDeveloperConsole = "allowDeveloperConsole";
|
||||||
internal const string AllowDownloadsAndUploads = "allowDownUploads";
|
internal const string AllowDownloadsAndUploads = "allowDownUploads";
|
||||||
internal const string AllowPageZoom = "enableZoomPage";
|
internal const string AllowPageZoom = "enableZoomPage";
|
||||||
|
internal const string AllowPdfReaderToolbar = "allowPDFReaderToolbar";
|
||||||
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
|
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
|
||||||
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
|
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
|
||||||
internal const string DownloadDirectory = "downloadDirectoryWin";
|
internal const string DownloadDirectory = "downloadDirectoryWin";
|
||||||
|
internal const string DownloadPdfFiles = "downloadPDFFiles";
|
||||||
internal const string EnableBrowser = "enableSebBrowser";
|
internal const string EnableBrowser = "enableSebBrowser";
|
||||||
internal const string PopupPolicy = "newBrowserWindowByLinkPolicy";
|
internal const string PopupPolicy = "newBrowserWindowByLinkPolicy";
|
||||||
internal const string PopupBlockForeignHost = "newBrowserWindowByLinkBlockForeign";
|
internal const string PopupBlockForeignHost = "newBrowserWindowByLinkBlockForeign";
|
||||||
|
|
|
@ -41,6 +41,16 @@ namespace SafeExamBrowser.Settings.Browser
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AllowPageZoom { get; set; }
|
public bool AllowPageZoom { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the internal PDF reader of the browser application is enabled. If not, documents will be downloaded by default.
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowPdfReader { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the toolbar of the internal PDF reader (which allows to e.g. download or print a document) will be enabled.
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowPdfReaderToolbar { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the user will be allowed to upload files.
|
/// Determines whether the user will be allowed to upload files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue