2017-07-21 10:04:27 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2017-07-21 10:04:27 +02:00
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client.Operations
|
2017-07-21 10:04:27 +02:00
|
|
|
|
{
|
2019-10-01 16:24:10 +02:00
|
|
|
|
internal class BrowserOperation : ClientOperation
|
2017-07-21 10:04:27 +02:00
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
private readonly IActionCenter actionCenter;
|
|
|
|
|
private readonly ILogger logger;
|
|
|
|
|
private readonly ITaskbar taskbar;
|
|
|
|
|
private readonly ITaskview taskview;
|
|
|
|
|
private readonly IUserInterfaceFactory uiFactory;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override event ActionRequiredEventHandler ActionRequired { add { } remove { } }
|
|
|
|
|
public override event StatusChangedEventHandler StatusChanged;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
|
2017-07-26 14:36:20 +02:00
|
|
|
|
public BrowserOperation(
|
2019-03-08 11:43:52 +01:00
|
|
|
|
IActionCenter actionCenter,
|
2019-10-01 16:24:10 +02:00
|
|
|
|
ClientContext context,
|
2017-07-21 10:04:27 +02:00
|
|
|
|
ILogger logger,
|
|
|
|
|
ITaskbar taskbar,
|
2019-12-06 17:42:46 +01:00
|
|
|
|
ITaskview taskview,
|
2019-10-01 16:24:10 +02:00
|
|
|
|
IUserInterfaceFactory uiFactory) : base(context)
|
2017-07-21 10:04:27 +02:00
|
|
|
|
{
|
2019-03-08 11:43:52 +01:00
|
|
|
|
this.actionCenter = actionCenter;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.taskbar = taskbar;
|
2019-12-05 11:54:43 +01:00
|
|
|
|
this.taskview = taskview;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
this.uiFactory = uiFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Perform()
|
2017-07-21 10:04:27 +02:00
|
|
|
|
{
|
2017-07-24 15:29:17 +02:00
|
|
|
|
logger.Info("Initializing browser...");
|
2018-10-03 15:42:50 +02:00
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeBrowser);
|
2017-07-21 10:04:27 +02:00
|
|
|
|
|
2020-01-10 10:25:51 +01:00
|
|
|
|
if (Context.Settings.Browser.EnableBrowser)
|
2019-11-06 08:45:37 +01:00
|
|
|
|
{
|
2020-01-10 10:25:51 +01:00
|
|
|
|
Context.Browser.Initialize();
|
|
|
|
|
|
|
|
|
|
if (Context.Settings.ActionCenter.EnableActionCenter)
|
|
|
|
|
{
|
|
|
|
|
actionCenter.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.ActionCenter), true);
|
|
|
|
|
}
|
2019-11-06 08:45:37 +01:00
|
|
|
|
|
2020-01-10 10:25:51 +01:00
|
|
|
|
if (Context.Settings.Taskbar.EnableTaskbar)
|
|
|
|
|
{
|
|
|
|
|
taskbar.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.Taskbar), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taskview.Add(Context.Browser);
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-11-06 08:45:37 +01:00
|
|
|
|
{
|
2020-01-10 10:25:51 +01:00
|
|
|
|
logger.Info("Browser application is disabled for this session.");
|
2019-11-06 08:45:37 +01:00
|
|
|
|
}
|
2018-02-28 15:49:06 +01:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Revert()
|
2017-07-21 10:04:27 +02:00
|
|
|
|
{
|
2017-07-24 17:31:28 +02:00
|
|
|
|
logger.Info("Terminating browser...");
|
2018-10-03 15:42:50 +02:00
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_TerminateBrowser);
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2020-01-10 10:25:51 +01:00
|
|
|
|
if (Context.Settings.Browser.EnableBrowser)
|
|
|
|
|
{
|
|
|
|
|
Context.Browser.Terminate();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Browser application was disabled for this session.");
|
|
|
|
|
}
|
2018-10-10 09:19:03 +02:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2017-07-21 10:04:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|