Working on browser configuration.
This commit is contained in:
parent
f6d4a281a6
commit
714d300758
20 changed files with 181 additions and 49 deletions
|
@ -12,6 +12,7 @@ using System.Linq;
|
|||
using CefSharp;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
||||
namespace SafeExamBrowser.Browser
|
||||
|
@ -33,8 +34,8 @@ namespace SafeExamBrowser.Browser
|
|||
{
|
||||
var cefSettings = new CefSettings
|
||||
{
|
||||
CachePath = settings.BrowserCachePath,
|
||||
LogFile = settings.BrowserLogFile
|
||||
CachePath = settings.Browser.CachePath,
|
||||
LogFile = settings.Browser.LogFile
|
||||
};
|
||||
|
||||
var success = Cef.Initialize(cefSettings, true, null);
|
||||
|
@ -65,7 +66,7 @@ namespace SafeExamBrowser.Browser
|
|||
private void CreateNewInstance()
|
||||
{
|
||||
var control = new BrowserControl("www.duckduckgo.com");
|
||||
var window = uiFactory.CreateBrowserWindow(control);
|
||||
var window = uiFactory.CreateBrowserWindow(control, settings.Browser);
|
||||
var instance = new BrowserApplicationInstance("DuckDuckGo");
|
||||
|
||||
instance.RegisterWindow(window);
|
||||
|
|
|
@ -62,7 +62,8 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="AboutNotificationIconResource.cs" />
|
||||
<Compile Include="AboutNotificationInfo.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="Settings\BrowserSettings.cs" />
|
||||
<Compile Include="Settings\SettingsImpl.cs" />
|
||||
<Compile Include="WorkingArea.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
46
SafeExamBrowser.Configuration/Settings/BrowserSettings.cs
Normal file
46
SafeExamBrowser.Configuration/Settings/BrowserSettings.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2017 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.IO;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
|
||||
namespace SafeExamBrowser.Configuration.Settings
|
||||
{
|
||||
public class BrowserSettings : IBrowserSettings
|
||||
{
|
||||
private ISettings settings;
|
||||
|
||||
public BrowserSettings(ISettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public bool AllowAddressBar => true;
|
||||
|
||||
public bool AllowBackwardNavigation => false;
|
||||
|
||||
public bool AllowDebugConsole => true;
|
||||
|
||||
public bool AllowForwardNavigation => false;
|
||||
|
||||
public bool AllowReloading => false;
|
||||
|
||||
public string CachePath
|
||||
{
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), settings.AppDataFolderName, "Cache"); }
|
||||
}
|
||||
|
||||
public bool FullScreenMode => throw new NotImplementedException();
|
||||
|
||||
public string LogFile
|
||||
{
|
||||
get { return Path.Combine(settings.LogFolderPath, $"{settings.RuntimeIdentifier}_Browser.txt"); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,33 +9,35 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
|
||||
namespace SafeExamBrowser.Configuration
|
||||
{
|
||||
public class Settings : ISettings
|
||||
/// <remarks>
|
||||
/// TODO: Replace with proper implementation once configuration aspects are clear...
|
||||
/// </remarks>
|
||||
public class SettingsImpl : ISettings
|
||||
{
|
||||
private const string AppDataFolder = "SafeExamBrowser";
|
||||
private static readonly string LogFileDate = DateTime.Now.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
|
||||
|
||||
public SettingsImpl()
|
||||
{
|
||||
Browser = new BrowserSettings(this);
|
||||
}
|
||||
|
||||
public string AppDataFolderName => "SafeExamBrowser";
|
||||
|
||||
public string ApplicationLogFile
|
||||
{
|
||||
get { return Path.Combine(LogFolderPath, $"{LogFileDate}_Application.txt"); }
|
||||
get { return Path.Combine(LogFolderPath, $"{RuntimeIdentifier}_Application.txt"); }
|
||||
}
|
||||
|
||||
public string BrowserLogFile
|
||||
{
|
||||
get { return Path.Combine(LogFolderPath, $"{LogFileDate}_Browser.txt"); }
|
||||
}
|
||||
|
||||
public string BrowserCachePath
|
||||
{
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Cache"); }
|
||||
}
|
||||
public IBrowserSettings Browser { get; private set; }
|
||||
|
||||
public string LogFolderPath
|
||||
{
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolder, "Logs"); }
|
||||
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolderName, "Logs"); }
|
||||
}
|
||||
|
||||
public string ProgramCopyright
|
||||
|
@ -70,5 +72,7 @@ namespace SafeExamBrowser.Configuration
|
|||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
public string RuntimeIdentifier => LogFileDate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2017 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.Contracts.Configuration.Settings
|
||||
{
|
||||
public interface IBrowserSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the user should be allowed to change the URL of a browser window.
|
||||
/// </summary>
|
||||
bool AllowAddressBar { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user should be allowed to navigate backwards in a browser window.
|
||||
/// </summary>
|
||||
bool AllowBackwardNavigation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user should be allowed to open the debug console of a browser window.
|
||||
/// </summary>
|
||||
bool AllowDebugConsole { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user should be allowed to navigate forwards in a browser window.
|
||||
/// </summary>
|
||||
bool AllowForwardNavigation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the user should be allowed to reload webpages.
|
||||
/// </summary>
|
||||
bool AllowReloading { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The path where the browser cache is to be stored.
|
||||
/// </summary>
|
||||
string CachePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The file path under which the browser log is to be stored.
|
||||
/// </summary>
|
||||
string LogFile { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the main browser window should be rendered in fullscreen mode, i.e. without window frame.
|
||||
/// </summary>
|
||||
bool FullScreenMode { get; }
|
||||
}
|
||||
}
|
|
@ -6,24 +6,24 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
namespace SafeExamBrowser.Contracts.Configuration
|
||||
namespace SafeExamBrowser.Contracts.Configuration.Settings
|
||||
{
|
||||
public interface ISettings
|
||||
{
|
||||
/// <summary>
|
||||
/// The name used for the application data folder.
|
||||
/// </summary>
|
||||
string AppDataFolderName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The file path under which the application log is to be stored.
|
||||
/// </summary>
|
||||
string ApplicationLogFile { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The path where the browser cache is to be stored.
|
||||
/// All browser-related settings.
|
||||
/// </summary>
|
||||
string BrowserCachePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The file path under which the browser log is to be stored.
|
||||
/// </summary>
|
||||
string BrowserLogFile { get; }
|
||||
IBrowserSettings Browser { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The path where the log files are to be stored.
|
||||
|
@ -44,5 +44,10 @@ namespace SafeExamBrowser.Contracts.Configuration
|
|||
/// The program version of the application (i.e. the executing assembly).
|
||||
/// </summary>
|
||||
string ProgramVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A string uniquely identifying the runtime of the application, used e.g. for the log file names.
|
||||
/// </summary>
|
||||
string RuntimeIdentifier { get; }
|
||||
}
|
||||
}
|
|
@ -66,7 +66,8 @@
|
|||
<Compile Include="Configuration\IApplicationInfo.cs" />
|
||||
<Compile Include="Configuration\IApplicationInstance.cs" />
|
||||
<Compile Include="Configuration\INotificationInfo.cs" />
|
||||
<Compile Include="Configuration\ISettings.cs" />
|
||||
<Compile Include="Configuration\Settings\IBrowserSettings.cs" />
|
||||
<Compile Include="Configuration\Settings\ISettings.cs" />
|
||||
<Compile Include="Behaviour\IShutdownController.cs" />
|
||||
<Compile Include="Behaviour\IStartupController.cs" />
|
||||
<Compile Include="Configuration\IWorkingArea.cs" />
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
|
||||
namespace SafeExamBrowser.Contracts.UserInterface
|
||||
|
@ -21,7 +22,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
|||
/// <summary>
|
||||
/// Creates a new browser window loaded with the given browser control.
|
||||
/// </summary>
|
||||
IBrowserWindow CreateBrowserWindow(IBrowserControl control);
|
||||
IBrowserWindow CreateBrowserWindow(IBrowserControl control, IBrowserSettings settings);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a taskbar notification, initialized with the given notification information.
|
||||
|
|
|
@ -10,7 +10,7 @@ using System.Collections.Generic;
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
|
|
@ -11,7 +11,7 @@ using System.Collections.Generic;
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
|
|
@ -10,7 +10,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
|
||||
namespace SafeExamBrowser.Core.Logging
|
||||
|
|
|
@ -7,20 +7,25 @@
|
|||
*/
|
||||
|
||||
using System.Windows;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface
|
||||
{
|
||||
public partial class BrowserWindow : Window, IBrowserWindow
|
||||
{
|
||||
public BrowserWindow(IBrowserControl browserControl)
|
||||
private IBrowserSettings settings;
|
||||
|
||||
public event WindowCloseHandler OnClose;
|
||||
|
||||
public BrowserWindow(IBrowserControl browserControl, IBrowserSettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
|
||||
InitializeComponent();
|
||||
InitializeBrowserWindow(browserControl);
|
||||
}
|
||||
|
||||
public event WindowCloseHandler OnClose;
|
||||
|
||||
public void BringToForeground()
|
||||
{
|
||||
if (WindowState == WindowState.Minimized)
|
||||
|
@ -38,6 +43,18 @@ namespace SafeExamBrowser.UserInterface
|
|||
BrowserControlHost.Child = browserControl as System.Windows.Forms.Control;
|
||||
}
|
||||
|
||||
UrlTextBox.IsEnabled = settings.AllowAddressBar;
|
||||
UrlTextBox.Visibility = settings.AllowAddressBar ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
ReloadButton.IsEnabled = settings.AllowReloading;
|
||||
ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
BackButton.IsEnabled = settings.AllowBackwardNavigation;
|
||||
BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
ForwardButton.IsEnabled = settings.AllowForwardNavigation;
|
||||
ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
Closing += (o, args) => OnClose?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace SafeExamBrowser.UserInterface.Controls
|
|||
private IApplicationInstance instance;
|
||||
|
||||
public delegate void OnClickHandler(Guid instanceId);
|
||||
|
||||
public event OnClickHandler Click;
|
||||
|
||||
public ApplicationInstanceButton(IApplicationInstance instance, IApplicationInfo info)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
using SafeExamBrowser.UserInterface.ViewModels;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
using System.Threading;
|
||||
using System.Windows;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
using SafeExamBrowser.UserInterface.Controls;
|
||||
|
@ -22,9 +23,9 @@ namespace SafeExamBrowser.UserInterface
|
|||
return new ApplicationButton(info);
|
||||
}
|
||||
|
||||
public IBrowserWindow CreateBrowserWindow(IBrowserControl control)
|
||||
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, IBrowserSettings settings)
|
||||
{
|
||||
return new BrowserWindow(control);
|
||||
return new BrowserWindow(control, settings);
|
||||
}
|
||||
|
||||
public ITaskbarNotification CreateNotification(INotificationInfo info)
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace SafeExamBrowser.UserInterface.ViewModels
|
|||
{
|
||||
private Timer timer;
|
||||
|
||||
public string Date { get; private set; }
|
||||
public string Time { get; private set; }
|
||||
public string ToolTip { get; private set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public DateTimeViewModel()
|
||||
|
@ -25,10 +29,6 @@ namespace SafeExamBrowser.UserInterface.ViewModels
|
|||
timer.Start();
|
||||
}
|
||||
|
||||
public string Date { get; private set; }
|
||||
public string Time { get; private set; }
|
||||
public string ToolTip { get; private set; }
|
||||
|
||||
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
var date = DateTime.Now;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2017 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/.
|
||||
|
@ -17,7 +17,7 @@ namespace SafeExamBrowser
|
|||
{
|
||||
public class App : Application
|
||||
{
|
||||
private static readonly Mutex mutex = new Mutex(true, "safe_exam_browser_single_instance_mutex");
|
||||
private static readonly Mutex Mutex = new Mutex(true, "safe_exam_browser_single_instance_mutex");
|
||||
private CompositionRoot instances = new CompositionRoot();
|
||||
|
||||
[STAThread]
|
||||
|
@ -33,7 +33,7 @@ namespace SafeExamBrowser
|
|||
}
|
||||
finally
|
||||
{
|
||||
mutex.Close();
|
||||
Mutex.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ namespace SafeExamBrowser
|
|||
|
||||
private static bool NoInstanceRunning()
|
||||
{
|
||||
return mutex.WaitOne(TimeSpan.Zero, true);
|
||||
return Mutex.WaitOne(TimeSpan.Zero, true);
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2017 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/.
|
||||
|
@ -11,6 +11,7 @@ using SafeExamBrowser.Browser;
|
|||
using SafeExamBrowser.Configuration;
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Configuration;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.Monitoring;
|
||||
|
@ -53,7 +54,7 @@ namespace SafeExamBrowser
|
|||
browserInfo = new BrowserApplicationInfo();
|
||||
logger = new Logger();
|
||||
nativeMethods = new NativeMethods();
|
||||
settings = new Settings();
|
||||
settings = new SettingsImpl();
|
||||
Taskbar = new Taskbar();
|
||||
textResource = new XmlTextResource();
|
||||
uiFactory = new UserInterfaceFactory();
|
||||
|
|
Loading…
Reference in a new issue