SEBWIN-304: Implemented browser popup policy.

This commit is contained in:
dbuechel 2019-12-12 15:41:05 +01:00
parent a54513259d
commit 1f4043619f
8 changed files with 77 additions and 25 deletions

View file

@ -249,14 +249,19 @@ namespace SafeExamBrowser.Browser
private void LifeSpanHandler_PopupRequested(PopupRequestedEventArgs args)
{
if (settings.AllowPopups)
switch (settings.PopupPolicy)
{
logger.Debug($"Forwarding request to open new window for '{args.Url}'...");
PopupRequested?.Invoke(args);
}
else
{
logger.Debug($"Blocked attempt to open new window for '{args.Url}'.");
case PopupPolicy.Allow:
logger.Debug($"Forwarding request to open new window for '{args.Url}'...");
PopupRequested?.Invoke(args);
break;
case PopupPolicy.SameWindow:
logger.Info($"Discarding request to open new window and loading '{args.Url}' directly...");
control.NavigateTo(args.Url);
break;
default:
logger.Info($"Blocked attempt to open new window for '{args.Url}'.");
break;
}
}

View file

@ -82,14 +82,6 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
}
}
private void MapAllowPopups(AppSettings settings, object value)
{
if (value is bool block)
{
settings.Browser.AllowPopups = !block;
}
}
private void MapAllowReload(AppSettings settings, object value)
{
if (value is bool allow)
@ -116,6 +108,29 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
}
}
private void MapPopupPolicy(AppSettings settings, object value)
{
const int ALLOW = 2;
const int BLOCK = 0;
const int SAME_WINDOW = 1;
if (value is int policy)
{
switch (policy)
{
case ALLOW:
settings.Browser.PopupPolicy = PopupPolicy.Allow;
break;
case BLOCK:
settings.Browser.PopupPolicy = PopupPolicy.Block;
break;
case SAME_WINDOW:
settings.Browser.PopupPolicy = PopupPolicy.SameWindow;
break;
}
}
}
private void MapRequestFilter(IDictionary<string, object> rawData, AppSettings settings)
{
var processMainRequests = rawData.TryGetValue(Keys.Browser.Filter.EnableMainRequestFilter, out var value) && value as bool? == true;

View file

@ -78,8 +78,8 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.AllowPageZoom:
MapAllowPageZoom(settings, value);
break;
case Keys.Browser.AllowPopups:
MapAllowPopups(settings, value);
case Keys.Browser.PopupPolicy:
MapPopupPolicy(settings, value);
break;
case Keys.Browser.AdditionalWindow.AllowAddressBar:
MapAllowAddressBarAdditionalWindow(settings, value);

View file

@ -114,7 +114,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Browser.AllowConfigurationDownloads = true;
settings.Browser.AllowDownloads = true;
settings.Browser.AllowPageZoom = true;
settings.Browser.AllowPopups = true;
settings.Browser.PopupPolicy = PopupPolicy.Allow;
settings.Browser.AdditionalWindow.AllowAddressBar = false;
settings.Browser.AdditionalWindow.AllowBackwardNavigation = true;
settings.Browser.AdditionalWindow.AllowDeveloperConsole = false;

View file

@ -49,9 +49,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string AllowDeveloperConsole = "allowDeveloperConsole";
internal const string AllowDownloads = "allowDownUploads";
internal const string AllowPageZoom = "enableZoomPage";
internal const string AllowPopups = "blockPopUpWindows";
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
internal const string PopupPolicy = "newBrowserWindowByLinkPolicy";
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";

View file

@ -36,11 +36,6 @@ namespace SafeExamBrowser.Settings.Browser
/// </summary>
public bool AllowPageZoom { get; set; }
/// <summary>
/// Determines whether popup windows will be opened or not.
/// </summary>
public bool AllowPopups { get; set; }
/// <summary>
/// The custom user agent to optionally be used for all requests.
/// </summary>
@ -55,7 +50,12 @@ namespace SafeExamBrowser.Settings.Browser
/// The settings to be used for the main browser window.
/// </summary>
public BrowserWindowSettings MainWindow { get; set; }
/// <summary>
/// Determines how attempts to open a popup are handled.
/// </summary>
public PopupPolicy PopupPolicy { get; set; }
/// <summary>
/// The URL with which the main browser window will be loaded.
/// </summary>

View file

@ -0,0 +1,31 @@
/*
* 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/.
*/
namespace SafeExamBrowser.Settings.Browser
{
/// <summary>
/// Defines all policies for browser window popups.
/// </summary>
public enum PopupPolicy
{
/// <summary>
/// Allows popups to be opened.
/// </summary>
Allow,
/// <summary>
/// Blocks all popups.
/// </summary>
Block,
/// <summary>
/// Opens popup requests in the same window from which they originate.
/// </summary>
SameWindow
}
}

View file

@ -64,6 +64,7 @@
<Compile Include="Browser\FilterResult.cs" />
<Compile Include="Browser\FilterRuleSettings.cs" />
<Compile Include="Browser\FilterRuleType.cs" />
<Compile Include="Browser\PopupPolicy.cs" />
<Compile Include="ConfigurationMode.cs" />
<Compile Include="KioskMode.cs" />
<Compile Include="Logging\LogLevel.cs" />