2017-07-14 10:28:59 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-14 10:28:59 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2017-07-31 20:22:53 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2017-07-24 17:31:28 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Browser
|
|
|
|
|
{
|
|
|
|
|
public class BrowserApplicationInstance : IApplicationInstance
|
|
|
|
|
{
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private IBrowserControl control;
|
|
|
|
|
private IBrowserWindow window;
|
|
|
|
|
|
2017-07-14 10:28:59 +02:00
|
|
|
|
public Guid Id { get; private set; }
|
|
|
|
|
public string Name { get; private set; }
|
2017-07-31 20:22:53 +02:00
|
|
|
|
public IWindow Window { get { return window; } }
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
2017-08-02 08:31:12 +02:00
|
|
|
|
public event TerminatedEventHandler Terminated;
|
2017-07-31 20:22:53 +02:00
|
|
|
|
public event NameChangedEventHandler NameChanged;
|
2017-07-28 09:12:17 +02:00
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
public BrowserApplicationInstance(BrowserSettings settings, IText text, IUserInterfaceFactory uiFactory, bool isMainInstance)
|
2017-07-14 10:28:59 +02:00
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
|
|
|
|
control = new BrowserControl(settings, text);
|
|
|
|
|
control.AddressChanged += Control_AddressChanged;
|
2018-03-01 08:50:08 +01:00
|
|
|
|
control.LoadingStateChanged += Control_LoadingStateChanged;
|
2017-07-31 20:22:53 +02:00
|
|
|
|
control.TitleChanged += Control_TitleChanged;
|
|
|
|
|
|
|
|
|
|
window = uiFactory.CreateBrowserWindow(control, settings);
|
|
|
|
|
window.IsMainWindow = isMainInstance;
|
|
|
|
|
window.Closing += () => Terminated?.Invoke(Id);
|
|
|
|
|
window.AddressChanged += Window_AddressChanged;
|
|
|
|
|
window.ReloadRequested += Window_ReloadRequested;
|
|
|
|
|
window.BackwardNavigationRequested += Window_BackwardNavigationRequested;
|
|
|
|
|
window.ForwardNavigationRequested += Window_ForwardNavigationRequested;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Control_AddressChanged(string address)
|
|
|
|
|
{
|
|
|
|
|
window.UpdateAddress(address);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 08:50:08 +01:00
|
|
|
|
private void Control_LoadingStateChanged(bool isLoading)
|
|
|
|
|
{
|
|
|
|
|
window.UpdateLoadingState(isLoading);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private void Control_TitleChanged(string title)
|
|
|
|
|
{
|
|
|
|
|
window.UpdateTitle(title);
|
|
|
|
|
NameChanged?.Invoke(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_AddressChanged(string address)
|
|
|
|
|
{
|
|
|
|
|
control.NavigateTo(address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_ReloadRequested()
|
|
|
|
|
{
|
|
|
|
|
control.Reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_BackwardNavigationRequested()
|
|
|
|
|
{
|
|
|
|
|
control.NavigateBackwards();
|
2017-07-14 10:28:59 +02:00
|
|
|
|
}
|
2017-07-24 17:31:28 +02:00
|
|
|
|
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private void Window_ForwardNavigationRequested()
|
2017-07-24 17:31:28 +02:00
|
|
|
|
{
|
2017-07-31 20:22:53 +02:00
|
|
|
|
control.NavigateForwards();
|
2017-07-24 17:31:28 +02:00
|
|
|
|
}
|
2017-07-14 10:28:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|