diff --git a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs index 0e7fdee5..fe0496c3 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs @@ -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; } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs index a96f4999..1c9bed9b 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs @@ -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 rawData, AppSettings settings) { var processMainRequests = rawData.TryGetValue(Keys.Browser.Filter.EnableMainRequestFilter, out var value) && value as bool? == true; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs index 7dd85246..c345848d 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs @@ -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); diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs index 2c023fda..a5914309 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs @@ -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; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index 5ba013de..205404ec 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -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"; diff --git a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs index c90e0800..7e964e9f 100644 --- a/SafeExamBrowser.Settings/Browser/BrowserSettings.cs +++ b/SafeExamBrowser.Settings/Browser/BrowserSettings.cs @@ -36,11 +36,6 @@ namespace SafeExamBrowser.Settings.Browser /// public bool AllowPageZoom { get; set; } - /// - /// Determines whether popup windows will be opened or not. - /// - public bool AllowPopups { get; set; } - /// /// The custom user agent to optionally be used for all requests. /// @@ -55,7 +50,12 @@ namespace SafeExamBrowser.Settings.Browser /// The settings to be used for the main browser window. /// public BrowserWindowSettings MainWindow { get; set; } - + + /// + /// Determines how attempts to open a popup are handled. + /// + public PopupPolicy PopupPolicy { get; set; } + /// /// The URL with which the main browser window will be loaded. /// diff --git a/SafeExamBrowser.Settings/Browser/PopupPolicy.cs b/SafeExamBrowser.Settings/Browser/PopupPolicy.cs new file mode 100644 index 00000000..f6d89503 --- /dev/null +++ b/SafeExamBrowser.Settings/Browser/PopupPolicy.cs @@ -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 +{ + /// + /// Defines all policies for browser window popups. + /// + public enum PopupPolicy + { + /// + /// Allows popups to be opened. + /// + Allow, + + /// + /// Blocks all popups. + /// + Block, + + /// + /// Opens popup requests in the same window from which they originate. + /// + SameWindow + } +} diff --git a/SafeExamBrowser.Settings/SafeExamBrowser.Settings.csproj b/SafeExamBrowser.Settings/SafeExamBrowser.Settings.csproj index 0e1102c7..ffdbf7cb 100644 --- a/SafeExamBrowser.Settings/SafeExamBrowser.Settings.csproj +++ b/SafeExamBrowser.Settings/SafeExamBrowser.Settings.csproj @@ -64,6 +64,7 @@ +