SEBWIN-304: Implemented same host policies for browser popups.
This commit is contained in:
parent
1f4043619f
commit
eb3a87016e
6 changed files with 49 additions and 25 deletions
|
@ -249,18 +249,28 @@ namespace SafeExamBrowser.Browser
|
|||
|
||||
private void LifeSpanHandler_PopupRequested(PopupRequestedEventArgs args)
|
||||
{
|
||||
var validCurrentUri = Uri.TryCreate(control.Address, UriKind.Absolute, out var currentUri);
|
||||
var validNewUri = Uri.TryCreate(args.Url, UriKind.Absolute, out var newUri);
|
||||
var sameHost = validCurrentUri && validNewUri && string.Equals(currentUri.Host, newUri.Host, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
switch (settings.PopupPolicy)
|
||||
{
|
||||
case PopupPolicy.Allow:
|
||||
case PopupPolicy.AllowSameHost when sameHost:
|
||||
logger.Debug($"Forwarding request to open new window for '{args.Url}'...");
|
||||
PopupRequested?.Invoke(args);
|
||||
break;
|
||||
case PopupPolicy.SameWindow:
|
||||
case PopupPolicy.AllowSameWindow:
|
||||
case PopupPolicy.AllowSameHostAndWindow when sameHost:
|
||||
logger.Info($"Discarding request to open new window and loading '{args.Url}' directly...");
|
||||
control.NavigateTo(args.Url);
|
||||
break;
|
||||
case PopupPolicy.AllowSameHost when !sameHost:
|
||||
case PopupPolicy.AllowSameHostAndWindow when !sameHost:
|
||||
logger.Info($"Blocked request to open new window for '{args.Url}' as it targets a different host.");
|
||||
break;
|
||||
default:
|
||||
logger.Info($"Blocked attempt to open new window for '{args.Url}'.");
|
||||
logger.Info($"Blocked request to open new window for '{args.Url}'.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,26 +108,26 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
|||
}
|
||||
}
|
||||
|
||||
private void MapPopupPolicy(AppSettings settings, object value)
|
||||
private void MapPopupPolicy(IDictionary<string, object> rawData, AppSettings settings)
|
||||
{
|
||||
const int ALLOW = 2;
|
||||
const int BLOCK = 0;
|
||||
const int SAME_WINDOW = 1;
|
||||
|
||||
if (value is int policy)
|
||||
var hasPolicy = rawData.TryGetValue(Keys.Browser.PopupPolicy, out var policy);
|
||||
var blockForeignHost = rawData.TryGetValue(Keys.Browser.PopupBlockForeignHost, out var value) && value as bool? == true;
|
||||
|
||||
switch (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;
|
||||
}
|
||||
case ALLOW:
|
||||
settings.Browser.PopupPolicy = blockForeignHost ? PopupPolicy.AllowSameHost : PopupPolicy.Allow;
|
||||
break;
|
||||
case BLOCK:
|
||||
settings.Browser.PopupPolicy = PopupPolicy.Block;
|
||||
break;
|
||||
case SAME_WINDOW:
|
||||
settings.Browser.PopupPolicy = blockForeignHost ? PopupPolicy.AllowSameHostAndWindow : PopupPolicy.AllowSameWindow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
|||
}
|
||||
|
||||
MapApplicationLogAccess(rawData, settings);
|
||||
MapRequestFilter(rawData, settings);
|
||||
MapKioskMode(rawData, settings);
|
||||
MapPopupPolicy(rawData, settings);
|
||||
MapRequestFilter(rawData, settings);
|
||||
MapUserAgentMode(rawData, settings);
|
||||
}
|
||||
|
||||
|
@ -78,9 +79,6 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
|||
case Keys.Browser.AllowPageZoom:
|
||||
MapAllowPageZoom(settings, value);
|
||||
break;
|
||||
case Keys.Browser.PopupPolicy:
|
||||
MapPopupPolicy(settings, value);
|
||||
break;
|
||||
case Keys.Browser.AdditionalWindow.AllowAddressBar:
|
||||
MapAllowAddressBarAdditionalWindow(settings, value);
|
||||
break;
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
|
|||
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
|
||||
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
|
||||
internal const string PopupPolicy = "newBrowserWindowByLinkPolicy";
|
||||
internal const string PopupBlockForeignHost = "newBrowserWindowByLinkBlockForeign";
|
||||
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
|
||||
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";
|
||||
|
||||
|
|
|
@ -14,18 +14,28 @@ namespace SafeExamBrowser.Settings.Browser
|
|||
public enum PopupPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows popups to be opened.
|
||||
/// Allows all popups.
|
||||
/// </summary>
|
||||
Allow,
|
||||
|
||||
/// <summary>
|
||||
/// Blocks all popups.
|
||||
/// Allows only popups which target the same host as the window from which they originate.
|
||||
/// </summary>
|
||||
Block,
|
||||
AllowSameHost,
|
||||
|
||||
/// <summary>
|
||||
/// Opens popup requests in the same window from which they originate.
|
||||
/// Allows only popups which target the same host as the window from which they originate and opens every request directly in the respective window.
|
||||
/// </summary>
|
||||
SameWindow
|
||||
AllowSameHostAndWindow,
|
||||
|
||||
/// <summary>
|
||||
/// Allows all popups but opens every request directly in the window from which it originates.
|
||||
/// </summary>
|
||||
AllowSameWindow,
|
||||
|
||||
/// <summary>
|
||||
/// Blocks all popups.
|
||||
/// </summary>
|
||||
Block
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser
|
|||
/// </summary>
|
||||
public interface IBrowserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The address which is currently loaded.
|
||||
/// </summary>
|
||||
string Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether a backward navigation can be performed.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue