Cleaned and restructured browser settings namespace.

This commit is contained in:
dbuechel 2019-12-18 08:24:55 +01:00
parent 5b3a2a3861
commit 42eccef565
32 changed files with 140 additions and 132 deletions

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Contracts.Filters
{

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Contracts.Filters
{

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Contracts.Filters
{

View file

@ -11,7 +11,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Browser.Filters;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.UnitTests.Filters
{

View file

@ -10,7 +10,7 @@ using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SafeExamBrowser.Browser.Filters;
using SafeExamBrowser.Browser.Filters.Rules;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.UnitTests.Filters
{

View file

@ -11,7 +11,7 @@ using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Browser.Filters.Rules;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.UnitTests.Filters.Rules
{

View file

@ -11,7 +11,7 @@ using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Browser.Filters.Rules;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.UnitTests.Filters.Rules
{

View file

@ -21,6 +21,7 @@ using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Proxy;
using SafeExamBrowser.Settings.Logging;
using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;

View file

@ -21,6 +21,7 @@ using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Browser;
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
@ -44,7 +45,7 @@ namespace SafeExamBrowser.Browser
private string url;
private double zoomLevel;
private BrowserWindowSettings WindowSettings
private WindowSettings WindowSettings
{
get { return isMainInstance ? settings.MainWindow : settings.AdditionalWindow; }
}

View file

@ -9,7 +9,7 @@
using System;
using System.Collections.Generic;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Filters
{

View file

@ -9,7 +9,7 @@
using System;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Browser.Filters.Rules;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Filters
{

View file

@ -9,7 +9,7 @@
using System;
using System.Text.RegularExpressions;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Filters.Rules
{

View file

@ -9,7 +9,7 @@
using System;
using System.Text.RegularExpressions;
using SafeExamBrowser.Browser.Contracts.Filters;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Filters.Rules
{

View file

@ -13,7 +13,7 @@ using SafeExamBrowser.Browser.Events;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
using BrowserSettings = SafeExamBrowser.Settings.Browser.BrowserSettings;
namespace SafeExamBrowser.Browser.Handlers

View file

@ -17,20 +17,21 @@ using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Browser.Handlers
{
internal class ResourceHandler : CefSharp.Handler.ResourceRequestHandler
{
private AppConfig appConfig;
private BrowserFilterSettings settings;
private FilterSettings settings;
private ILogger logger;
private IRequestFilter filter;
private IResourceHandler contentHandler;
private IResourceHandler pageHandler;
private IText text;
internal ResourceHandler(AppConfig appConfig, BrowserFilterSettings settings, IRequestFilter filter, ILogger logger, IText text)
internal ResourceHandler(AppConfig appConfig, FilterSettings settings, IRequestFilter filter, ILogger logger, IText text)
{
this.appConfig = appConfig;
this.filter = filter;

View file

@ -9,6 +9,8 @@
using System.Collections.Generic;
using SafeExamBrowser.Settings;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Filter;
using SafeExamBrowser.Settings.Browser.Proxy;
using SafeExamBrowser.Settings.UserInterface;
namespace SafeExamBrowser.Configuration.ConfigurationData
@ -272,7 +274,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
private void MapFtpProxy(AppSettings settings, IDictionary<string, object> data)
{
var proxy = new ProxySettings { Protocol = ProxyProtocol.Ftp };
var proxy = new ProxyConfiguration { Protocol = ProxyProtocol.Ftp };
if (data.TryGetValue(Keys.Browser.Proxy.Ftp.Host, out var v) && v is string host)
{
@ -304,7 +306,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
private void MapHttpProxy(AppSettings settings, IDictionary<string, object> data)
{
var proxy = new ProxySettings { Protocol = ProxyProtocol.Http };
var proxy = new ProxyConfiguration { Protocol = ProxyProtocol.Http };
if (data.TryGetValue(Keys.Browser.Proxy.Http.Host, out var v) && v is string host)
{
@ -336,7 +338,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
private void MapHttpsProxy(AppSettings settings, IDictionary<string, object> data)
{
var proxy = new ProxySettings { Protocol = ProxyProtocol.Https };
var proxy = new ProxyConfiguration { Protocol = ProxyProtocol.Https };
if (data.TryGetValue(Keys.Browser.Proxy.Https.Host, out var v) && v is string host)
{
@ -368,7 +370,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
private void MapSocksProxy(AppSettings settings, IDictionary<string, object> data)
{
var proxy = new ProxySettings { Protocol = ProxyProtocol.Socks };
var proxy = new ProxyConfiguration { Protocol = ProxyProtocol.Socks };
if (data.TryGetValue(Keys.Browser.Proxy.Socks.Host, out var v) && v is string host)
{
@ -458,13 +460,13 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
switch (position)
{
case LEFT:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Left;
settings.Browser.AdditionalWindow.Position = WindowPosition.Left;
break;
case CENTER:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Center;
settings.Browser.AdditionalWindow.Position = WindowPosition.Center;
break;
case RIGHT:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Right;
settings.Browser.AdditionalWindow.Position = WindowPosition.Right;
break;
}
}
@ -481,13 +483,13 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
switch (position)
{
case LEFT:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Left;
settings.Browser.MainWindow.Position = WindowPosition.Left;
break;
case CENTER:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Center;
settings.Browser.MainWindow.Position = WindowPosition.Center;
break;
case RIGHT:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Right;
settings.Browser.MainWindow.Position = WindowPosition.Right;
break;
}
}

View file

@ -11,6 +11,7 @@ using System.IO;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Settings;
using SafeExamBrowser.Settings.Browser;
using SafeExamBrowser.Settings.Browser.Proxy;
using SafeExamBrowser.Settings.Logging;
using SafeExamBrowser.Settings.Service;
using SafeExamBrowser.Settings.UserInterface;
@ -116,7 +117,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Browser.AdditionalWindow.AllowForwardNavigation = true;
settings.Browser.AdditionalWindow.AllowReloading = true;
settings.Browser.AdditionalWindow.FullScreenMode = false;
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Right;
settings.Browser.AdditionalWindow.Position = WindowPosition.Right;
settings.Browser.AdditionalWindow.RelativeHeight = 100;
settings.Browser.AdditionalWindow.RelativeWidth = 50;
settings.Browser.AdditionalWindow.ShowReloadWarning = false;

View file

@ -1,56 +0,0 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using System.Collections.Generic;
namespace SafeExamBrowser.Settings.Browser
{
/// <summary>
/// Defines the proxy settings for the browser engine.
/// </summary>
[Serializable]
public class BrowserProxySettings
{
/// <summary>
/// Determines whether proxy auto-configuration should be used. Requires a valid URL defined in <see cref="AutoConfigureUrl"/>.
/// </summary>
public bool AutoConfigure { get; set; }
/// <summary>
/// A valid URL to a proxy auto-configuration file (.pac). Is only evaluated if <see cref="AutoConfigure"/> is enabled.
/// </summary>
public string AutoConfigureUrl { get; set; }
/// <summary>
/// Forces proxy auto-detection by the browser engine.
/// </summary>
public bool AutoDetect { get; set; }
/// <summary>
/// A list of hosts for which all proxy settings should be bypassed.
/// </summary>
public IList<string> BypassList { get; set; }
/// <summary>
/// The proxy policy to be used.
/// </summary>
public ProxyPolicy Policy { get; set; }
/// <summary>
/// Defines all proxies to be used.
/// </summary>
public IList<ProxySettings> Proxies { get; set; }
public BrowserProxySettings()
{
BypassList = new List<string>();
Proxies = new List<ProxySettings>();
}
}
}

View file

@ -19,7 +19,7 @@ namespace SafeExamBrowser.Settings.Browser
/// <summary>
/// The settings to be used for additional browser windows.
/// </summary>
public BrowserWindowSettings AdditionalWindow { get; set; }
public WindowSettings AdditionalWindow { get; set; }
/// <summary>
/// Determines whether the user will be allowed to download configuration files.
@ -44,12 +44,12 @@ namespace SafeExamBrowser.Settings.Browser
/// <summary>
/// The settings to be used for the browser request filter.
/// </summary>
public BrowserFilterSettings Filter { get; set; }
public FilterSettings Filter { get; set; }
/// <summary>
/// The settings to be used for the main browser window.
/// </summary>
public BrowserWindowSettings MainWindow { get; set; }
public WindowSettings MainWindow { get; set; }
/// <summary>
/// Determines how attempts to open a popup are handled.
@ -59,7 +59,7 @@ namespace SafeExamBrowser.Settings.Browser
/// <summary>
/// Determines the proxy settings to be used by the browser.
/// </summary>
public BrowserProxySettings Proxy { get; set; }
public ProxySettings Proxy { get; set; }
/// <summary>
/// The URL with which the main browser window will be loaded.
@ -73,10 +73,10 @@ namespace SafeExamBrowser.Settings.Browser
public BrowserSettings()
{
AdditionalWindow = new BrowserWindowSettings();
Filter = new BrowserFilterSettings();
MainWindow = new BrowserWindowSettings();
Proxy = new BrowserProxySettings();
AdditionalWindow = new WindowSettings();
Filter = new FilterSettings();
MainWindow = new WindowSettings();
Proxy = new ProxySettings();
}
}
}

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Settings.Browser
namespace SafeExamBrowser.Settings.Browser.Filter
{
/// <summary>
/// Defines all possible results of a request filter operation.

View file

@ -8,7 +8,7 @@
using System;
namespace SafeExamBrowser.Settings.Browser
namespace SafeExamBrowser.Settings.Browser.Filter
{
/// <summary>
/// Defines the settings for a request filter rule.

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Settings.Browser
namespace SafeExamBrowser.Settings.Browser.Filter
{
/// <summary>
/// Defines all possible filter rule types.

View file

@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using SafeExamBrowser.Settings.Browser.Filter;
namespace SafeExamBrowser.Settings.Browser
{
@ -15,7 +16,7 @@ namespace SafeExamBrowser.Settings.Browser
/// Defines all settings for the request filter of the browser.
/// </summary>
[Serializable]
public class BrowserFilterSettings
public class FilterSettings
{
/// <summary>
/// Defines whether content requests for a web page should be filtered according to the defined <see cref="Rules"/>.
@ -32,7 +33,7 @@ namespace SafeExamBrowser.Settings.Browser
/// </summary>
public IList<FilterRuleSettings> Rules { get; set; }
public BrowserFilterSettings()
public FilterSettings()
{
Rules = new List<FilterRuleSettings>();
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace SafeExamBrowser.Settings.Browser.Proxy
{
/// <summary>
/// Defines the configuration of a proxy server.
/// </summary>
[Serializable]
public class ProxyConfiguration
{
/// <summary>
/// The host name or IP address of the proxy server.
/// </summary>
public string Host { get; set; }
/// <summary>
/// The password to be used for authentication.
/// </summary>
public string Password { get; set; }
/// <summary>
/// The port of the proxy server.
/// </summary>
public int Port { get; set; }
/// <summary>
/// The protocol of the proxy server.
/// </summary>
public ProxyProtocol Protocol { get; set; }
/// <summary>
/// Determines whether the proxy server requires authentication.
/// </summary>
public bool RequiresAuthentication { get; set; }
/// <summary>
/// The username to be used for authentication.
/// </summary>
public string Username { get; set; }
}
}

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Settings.Browser
namespace SafeExamBrowser.Settings.Browser.Proxy
{
/// <summary>
/// Defines all currently supported proxy policies for the browser.
@ -14,12 +14,12 @@ namespace SafeExamBrowser.Settings.Browser
public enum ProxyPolicy
{
/// <summary>
/// Use custom proxy settings as defined in <see cref="BrowserProxySettings"/>.
/// Use custom proxy settings as defined in <see cref="ProxySettings"/>.
/// </summary>
Custom,
/// <summary>
/// Use the proxy settings of the operating system (i.e. ignore all custom settings defined in <see cref="BrowserProxySettings"/>).
/// Use the proxy settings of the operating system (i.e. ignore all custom settings defined in <see cref="ProxySettings"/>).
/// </summary>
System
}

View file

@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace SafeExamBrowser.Settings.Browser
namespace SafeExamBrowser.Settings.Browser.Proxy
{
/// <summary>
/// Defines all protocols currently supported for proxies.

View file

@ -7,43 +7,51 @@
*/
using System;
using System.Collections.Generic;
using SafeExamBrowser.Settings.Browser.Proxy;
namespace SafeExamBrowser.Settings.Browser
{
/// <summary>
/// Defines the settings for a proxy server.
/// Defines the proxy settings for the browser engine.
/// </summary>
[Serializable]
public class ProxySettings
{
/// <summary>
/// The host name or IP address of the proxy server.
/// Determines whether proxy auto-configuration should be used. Requires a valid URL defined in <see cref="AutoConfigureUrl"/>.
/// </summary>
public string Host { get; set; }
public bool AutoConfigure { get; set; }
/// <summary>
/// The password to be used for authentication.
/// A valid URL to a proxy auto-configuration file (.pac). Is only evaluated if <see cref="AutoConfigure"/> is enabled.
/// </summary>
public string Password { get; set; }
public string AutoConfigureUrl { get; set; }
/// <summary>
/// The port of the proxy server.
/// Forces proxy auto-detection by the browser engine.
/// </summary>
public int Port { get; set; }
public bool AutoDetect { get; set; }
/// <summary>
/// The protocol of the proxy server.
/// A list of hosts for which all proxy settings should be bypassed.
/// </summary>
public ProxyProtocol Protocol { get; set; }
public IList<string> BypassList { get; set; }
/// <summary>
/// Determines whether the proxy server requires authentication.
/// The proxy policy to be used.
/// </summary>
public bool RequiresAuthentication { get; set; }
public ProxyPolicy Policy { get; set; }
/// <summary>
/// The username to be used for authentication.
/// Defines all proxies to be used.
/// </summary>
public string Username { get; set; }
public IList<ProxyConfiguration> Proxies { get; set; }
public ProxySettings()
{
BypassList = new List<string>();
Proxies = new List<ProxyConfiguration>();
}
}
}

View file

@ -11,7 +11,7 @@ namespace SafeExamBrowser.Settings.Browser
/// <summary>
/// Defines the initial position of a browser window.
/// </summary>
public enum BrowserWindowPosition
public enum WindowPosition
{
Left,
Center,

View file

@ -14,7 +14,7 @@ namespace SafeExamBrowser.Settings.Browser
/// Defines all settings for a window of the browser engine.
/// </summary>
[Serializable]
public class BrowserWindowSettings
public class WindowSettings
{
/// <summary>
/// Optionally defines the height of the browser window in physical pixels.
@ -59,7 +59,7 @@ namespace SafeExamBrowser.Settings.Browser
/// <summary>
/// Determines the initial position of the browser window (if it is not maximized).
/// </summary>
public BrowserWindowPosition Position { get; set; }
public WindowPosition Position { get; set; }
/// <summary>
/// Optionally defines the height of the browser window as percentage of the working area height.

View file

@ -57,18 +57,18 @@
<Compile Include="Applications\ApplicationSettings.cs" />
<Compile Include="Applications\BlacklistApplication.cs" />
<Compile Include="Applications\WhitelistApplication.cs" />
<Compile Include="Browser\BrowserFilterSettings.cs" />
<Compile Include="Browser\FilterSettings.cs" />
<Compile Include="Browser\BrowserSettings.cs" />
<Compile Include="Browser\BrowserWindowPosition.cs" />
<Compile Include="Browser\BrowserWindowSettings.cs" />
<Compile Include="Browser\FilterResult.cs" />
<Compile Include="Browser\FilterRuleSettings.cs" />
<Compile Include="Browser\FilterRuleType.cs" />
<Compile Include="Browser\WindowPosition.cs" />
<Compile Include="Browser\WindowSettings.cs" />
<Compile Include="Browser\Filter\FilterResult.cs" />
<Compile Include="Browser\Filter\FilterRuleSettings.cs" />
<Compile Include="Browser\Filter\FilterRuleType.cs" />
<Compile Include="Browser\PopupPolicy.cs" />
<Compile Include="Browser\ProxyPolicy.cs" />
<Compile Include="Browser\BrowserProxySettings.cs" />
<Compile Include="Browser\ProxyProtocol.cs" />
<Compile Include="Browser\Proxy\ProxyPolicy.cs" />
<Compile Include="Browser\ProxySettings.cs" />
<Compile Include="Browser\Proxy\ProxyProtocol.cs" />
<Compile Include="Browser\Proxy\ProxyConfiguration.cs" />
<Compile Include="ConfigurationMode.cs" />
<Compile Include="KioskMode.cs" />
<Compile Include="Logging\LogLevel.cs" />

View file

@ -34,7 +34,7 @@ namespace SafeExamBrowser.UserInterface.Desktop
private IText text;
private WindowClosingEventHandler closing;
private BrowserWindowSettings WindowSettings
private WindowSettings WindowSettings
{
get { return isMainWindow ? settings.MainWindow : settings.AdditionalWindow; }
}
@ -310,13 +310,13 @@ namespace SafeExamBrowser.UserInterface.Desktop
switch (WindowSettings.Position)
{
case BrowserWindowPosition.Left:
case WindowPosition.Left:
Left = 0;
break;
case BrowserWindowPosition.Center:
case WindowPosition.Center:
Left = (SystemParameters.WorkArea.Width / 2) - (Width / 2);
break;
case BrowserWindowPosition.Right:
case WindowPosition.Right:
Left = SystemParameters.WorkArea.Width - Width;
break;
}

View file

@ -34,7 +34,7 @@ namespace SafeExamBrowser.UserInterface.Mobile
private IText text;
private WindowClosingEventHandler closing;
private BrowserWindowSettings WindowSettings
private WindowSettings WindowSettings
{
get { return isMainWindow ? settings.MainWindow : settings.AdditionalWindow; }
}
@ -319,13 +319,13 @@ namespace SafeExamBrowser.UserInterface.Mobile
switch (WindowSettings.Position)
{
case BrowserWindowPosition.Left:
case WindowPosition.Left:
Left = 0;
break;
case BrowserWindowPosition.Center:
case WindowPosition.Center:
Left = (SystemParameters.WorkArea.Width / 2) - (Width / 2);
break;
case BrowserWindowPosition.Right:
case WindowPosition.Right:
Left = SystemParameters.WorkArea.Width - Width;
break;
}