2017-07-14 10:28:59 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-15 15:55:34 +01:00
|
|
|
|
using System;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-08 13:53:38 +02:00
|
|
|
|
using System.Net.Http;
|
2019-09-12 12:31:17 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2020-05-15 16:13:15 +02:00
|
|
|
|
using CefSharp;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
using CefSharp.WinForms.Handler;
|
|
|
|
|
using CefSharp.WinForms.Host;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts.Events;
|
2019-09-06 08:13:27 +02:00
|
|
|
|
using SafeExamBrowser.Browser.Contracts.Events;
|
2019-09-24 08:53:29 +02:00
|
|
|
|
using SafeExamBrowser.Browser.Contracts.Filters;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
using SafeExamBrowser.Browser.Events;
|
2019-09-13 09:17:14 +02:00
|
|
|
|
using SafeExamBrowser.Browser.Filters;
|
2018-03-08 07:35:58 +01:00
|
|
|
|
using SafeExamBrowser.Browser.Handlers;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
using SafeExamBrowser.Browser.Wrapper;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
2020-10-05 23:37:23 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
2021-04-19 12:45:37 +02:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.Resources.Icons;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2023-03-08 00:01:20 +01:00
|
|
|
|
using SafeExamBrowser.Settings;
|
2019-09-10 11:01:49 +02:00
|
|
|
|
using SafeExamBrowser.Settings.Browser;
|
2019-12-18 08:24:55 +01:00
|
|
|
|
using SafeExamBrowser.Settings.Browser.Filter;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Browser;
|
2020-01-22 15:16:11 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Browser.Data;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
2020-08-05 22:55:38 +02:00
|
|
|
|
using Syroot.Windows.IO;
|
2020-05-15 16:13:15 +02:00
|
|
|
|
using BrowserSettings = SafeExamBrowser.Settings.Browser.BrowserSettings;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
using DisplayHandler = SafeExamBrowser.Browser.Handlers.DisplayHandler;
|
2020-05-15 16:13:15 +02:00
|
|
|
|
using Request = SafeExamBrowser.Browser.Contracts.Filters.Request;
|
2020-08-03 14:41:25 +02:00
|
|
|
|
using ResourceHandler = SafeExamBrowser.Browser.Handlers.ResourceHandler;
|
2020-05-15 16:13:15 +02:00
|
|
|
|
using TitleChangedEventHandler = SafeExamBrowser.Applications.Contracts.Events.TitleChangedEventHandler;
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Browser
|
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
internal class BrowserWindow : Contracts.IBrowserWindow
|
2017-07-14 10:28:59 +02:00
|
|
|
|
{
|
2022-05-31 12:34:01 +02:00
|
|
|
|
private const string CLEAR_FIND_TERM = "thisisahacktoclearthesearchresultsasitappearsthatthereisnosuchfunctionalityincef";
|
2019-05-22 11:42:31 +02:00
|
|
|
|
private const double ZOOM_FACTOR = 0.2;
|
|
|
|
|
|
2021-10-18 12:06:10 +02:00
|
|
|
|
private readonly AppConfig appConfig;
|
2024-03-04 14:27:49 +01:00
|
|
|
|
private readonly Clipboard clipboard;
|
2021-10-18 12:06:10 +02:00
|
|
|
|
private readonly IFileSystemDialog fileSystemDialog;
|
|
|
|
|
private readonly IHashAlgorithm hashAlgorithm;
|
|
|
|
|
private readonly HttpClient httpClient;
|
|
|
|
|
private readonly IKeyGenerator keyGenerator;
|
|
|
|
|
private readonly IModuleLogger logger;
|
|
|
|
|
private readonly IMessageBox messageBox;
|
2023-03-08 00:01:20 +01:00
|
|
|
|
private readonly SessionMode sessionMode;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
private readonly Dictionary<int, BrowserWindow> popups;
|
2022-02-04 13:41:11 +01:00
|
|
|
|
private readonly BrowserSettings settings;
|
|
|
|
|
private readonly string startUrl;
|
2021-10-18 12:06:10 +02:00
|
|
|
|
private readonly IText text;
|
|
|
|
|
private readonly IUserInterfaceFactory uiFactory;
|
|
|
|
|
|
2022-05-31 12:34:01 +02:00
|
|
|
|
private (string term, bool isInitial, bool caseSensitive, bool forward) findParameters;
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private IBrowserWindow window;
|
2019-05-22 11:42:31 +02:00
|
|
|
|
private double zoomLevel;
|
2019-01-23 09:37:47 +01:00
|
|
|
|
|
2019-12-18 08:24:55 +01:00
|
|
|
|
private WindowSettings WindowSettings
|
2019-01-23 09:37:47 +01:00
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
get { return IsMainWindow ? settings.MainWindow : settings.AdditionalWindow; }
|
2019-01-23 09:37:47 +01:00
|
|
|
|
}
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
internal IBrowserControl Control { get; private set; }
|
2019-11-29 14:59:54 +01:00
|
|
|
|
internal int Id { get; }
|
2019-11-28 17:22:04 +01:00
|
|
|
|
|
2019-12-05 11:54:43 +01:00
|
|
|
|
public IntPtr Handle { get; private set; }
|
2019-11-15 16:00:03 +01:00
|
|
|
|
public IconResource Icon { get; private set; }
|
2024-02-13 11:04:36 +01:00
|
|
|
|
public bool IsMainWindow { get; private set; }
|
2019-11-28 17:22:04 +01:00
|
|
|
|
public string Title { get; private set; }
|
2024-02-13 11:04:36 +01:00
|
|
|
|
public string Url { get; private set; }
|
2019-11-28 17:22:04 +01:00
|
|
|
|
|
2022-02-04 13:41:11 +01:00
|
|
|
|
internal event WindowClosedEventHandler Closed;
|
2019-11-28 17:22:04 +01:00
|
|
|
|
internal event DownloadRequestedEventHandler ConfigurationDownloadRequested;
|
2023-11-01 13:52:39 +01:00
|
|
|
|
internal event LoseFocusRequestedEventHandler LoseFocusRequested;
|
2019-11-28 17:22:04 +01:00
|
|
|
|
internal event PopupRequestedEventHandler PopupRequested;
|
2020-09-21 19:22:15 +02:00
|
|
|
|
internal event ResetRequestedEventHandler ResetRequested;
|
2019-12-19 15:02:40 +01:00
|
|
|
|
internal event TerminationRequestedEventHandler TerminationRequested;
|
2023-11-01 13:52:39 +01:00
|
|
|
|
internal event UserIdentifierDetectedEventHandler UserIdentifierDetected;
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
2019-01-17 16:15:10 +01:00
|
|
|
|
public event IconChangedEventHandler IconChanged;
|
2019-11-28 17:22:04 +01:00
|
|
|
|
public event TitleChangedEventHandler TitleChanged;
|
2017-07-28 09:12:17 +02:00
|
|
|
|
|
2022-02-04 13:41:11 +01:00
|
|
|
|
public BrowserWindow(
|
2018-06-29 09:50:20 +02:00
|
|
|
|
AppConfig appConfig,
|
2024-03-04 14:27:49 +01:00
|
|
|
|
Clipboard clipboard,
|
2020-01-22 15:16:11 +01:00
|
|
|
|
IFileSystemDialog fileSystemDialog,
|
2020-10-05 23:37:23 +02:00
|
|
|
|
IHashAlgorithm hashAlgorithm,
|
2022-02-23 13:59:36 +01:00
|
|
|
|
int id,
|
|
|
|
|
bool isMainWindow,
|
2021-10-18 12:06:10 +02:00
|
|
|
|
IKeyGenerator keyGenerator,
|
2018-08-31 15:29:36 +02:00
|
|
|
|
IModuleLogger logger,
|
2022-02-23 13:59:36 +01:00
|
|
|
|
IMessageBox messageBox,
|
2023-03-08 00:01:20 +01:00
|
|
|
|
SessionMode sessionMode,
|
2022-02-23 13:59:36 +01:00
|
|
|
|
BrowserSettings settings,
|
|
|
|
|
string startUrl,
|
2018-06-21 07:56:25 +02:00
|
|
|
|
IText text,
|
2022-02-23 13:59:36 +01:00
|
|
|
|
IUserInterfaceFactory uiFactory)
|
2018-03-14 11:13:30 +01:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
this.appConfig = appConfig;
|
2024-03-04 14:27:49 +01:00
|
|
|
|
this.clipboard = clipboard;
|
2020-01-22 15:16:11 +01:00
|
|
|
|
this.fileSystemDialog = fileSystemDialog;
|
2020-10-05 23:37:23 +02:00
|
|
|
|
this.hashAlgorithm = hashAlgorithm;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
this.httpClient = new HttpClient();
|
|
|
|
|
this.Id = id;
|
2024-02-13 11:04:36 +01:00
|
|
|
|
this.IsMainWindow = isMainWindow;
|
2021-10-18 12:06:10 +02:00
|
|
|
|
this.keyGenerator = keyGenerator;
|
2018-08-31 15:29:36 +02:00
|
|
|
|
this.logger = logger;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
this.messageBox = messageBox;
|
|
|
|
|
this.popups = new Dictionary<int, BrowserWindow>();
|
2023-03-08 00:01:20 +01:00
|
|
|
|
this.sessionMode = sessionMode;
|
2018-03-14 11:13:30 +01:00
|
|
|
|
this.settings = settings;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
this.startUrl = startUrl;
|
2018-03-14 11:13:30 +01:00
|
|
|
|
this.text = text;
|
|
|
|
|
this.uiFactory = uiFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 12:30:00 +02:00
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
2019-11-28 17:22:04 +01:00
|
|
|
|
window.BringToForeground();
|
2019-08-30 12:30:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 13:41:11 +01:00
|
|
|
|
internal void Close()
|
2019-09-06 08:13:27 +02:00
|
|
|
|
{
|
2022-02-04 13:41:11 +01:00
|
|
|
|
window.Close();
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Destroy();
|
2019-09-06 08:13:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 16:47:18 +02:00
|
|
|
|
internal void Focus(bool forward)
|
|
|
|
|
{
|
|
|
|
|
if (forward)
|
|
|
|
|
{
|
|
|
|
|
window.FocusToolbar(forward);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.FocusBrowser();
|
|
|
|
|
Activate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
internal void InitializeControl()
|
2017-07-14 10:28:59 +02:00
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
var cefSharpControl = default(ICefSharpControl);
|
2024-03-04 14:27:49 +01:00
|
|
|
|
var controlLogger = logger.CloneFor($"{nameof(BrowserControl)} #{Id}");
|
2020-01-20 16:13:08 +01:00
|
|
|
|
var dialogHandler = new DialogHandler();
|
2019-01-17 16:15:10 +01:00
|
|
|
|
var displayHandler = new DisplayHandler();
|
2019-12-19 15:02:40 +01:00
|
|
|
|
var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
|
2020-09-29 14:01:17 +02:00
|
|
|
|
var downloadHandler = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings);
|
2019-01-17 11:12:17 +01:00
|
|
|
|
var keyboardHandler = new KeyboardHandler();
|
2024-03-13 17:38:10 +01:00
|
|
|
|
var renderHandler = new RenderProcessMessageHandler(appConfig, clipboard, keyGenerator, settings, text);
|
2019-09-13 09:17:14 +02:00
|
|
|
|
var requestFilter = new RequestFilter();
|
2019-12-19 15:02:40 +01:00
|
|
|
|
var requestLogger = logger.CloneFor($"{nameof(RequestHandler)} #{Id}");
|
2023-03-08 00:01:20 +01:00
|
|
|
|
var resourceHandler = new ResourceHandler(appConfig, requestFilter, keyGenerator, logger, sessionMode, settings, WindowSettings, text);
|
2022-02-23 13:59:36 +01:00
|
|
|
|
var requestHandler = new RequestHandler(appConfig, requestFilter, requestLogger, resourceHandler, settings, WindowSettings);
|
2018-06-21 07:56:25 +02:00
|
|
|
|
|
2019-11-15 16:00:03 +01:00
|
|
|
|
Icon = new BrowserIconResource();
|
|
|
|
|
|
2024-02-13 11:04:36 +01:00
|
|
|
|
if (IsMainWindow)
|
2022-02-23 13:59:36 +01:00
|
|
|
|
{
|
|
|
|
|
cefSharpControl = new CefSharpBrowserControl(CreateLifeSpanHandlerForMainWindow(), startUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cefSharpControl = new CefSharpPopupControl();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 16:13:08 +01:00
|
|
|
|
dialogHandler.DialogRequested += DialogHandler_DialogRequested;
|
2019-01-17 16:15:10 +01:00
|
|
|
|
displayHandler.FaviconChanged += DisplayHandler_FaviconChanged;
|
2019-05-22 11:42:31 +02:00
|
|
|
|
displayHandler.ProgressChanged += DisplayHandler_ProgressChanged;
|
2018-10-30 11:24:28 +01:00
|
|
|
|
downloadHandler.ConfigurationDownloadRequested += DownloadHandler_ConfigurationDownloadRequested;
|
2022-05-13 12:03:06 +02:00
|
|
|
|
downloadHandler.DownloadAborted += DownloadHandler_DownloadAborted;
|
2020-01-22 15:16:11 +01:00
|
|
|
|
downloadHandler.DownloadUpdated += DownloadHandler_DownloadUpdated;
|
2020-08-10 21:42:51 +02:00
|
|
|
|
keyboardHandler.FindRequested += KeyboardHandler_FindRequested;
|
2022-05-13 16:47:18 +02:00
|
|
|
|
keyboardHandler.FocusAddressBarRequested += KeyboardHandler_FocusAddressBarRequested;
|
2020-10-05 23:37:23 +02:00
|
|
|
|
keyboardHandler.HomeNavigationRequested += HomeNavigationRequested;
|
2019-01-18 16:11:33 +01:00
|
|
|
|
keyboardHandler.ReloadRequested += ReloadRequested;
|
2022-05-13 16:47:18 +02:00
|
|
|
|
keyboardHandler.TabPressed += KeyboardHandler_TabPressed;
|
2019-01-18 16:11:33 +01:00
|
|
|
|
keyboardHandler.ZoomInRequested += ZoomInRequested;
|
|
|
|
|
keyboardHandler.ZoomOutRequested += ZoomOutRequested;
|
|
|
|
|
keyboardHandler.ZoomResetRequested += ZoomResetRequested;
|
2019-12-19 15:02:40 +01:00
|
|
|
|
requestHandler.QuitUrlVisited += RequestHandler_QuitUrlVisited;
|
2019-09-12 12:31:17 +02:00
|
|
|
|
requestHandler.RequestBlocked += RequestHandler_RequestBlocked;
|
2023-11-01 13:52:39 +01:00
|
|
|
|
resourceHandler.UserIdentifierDetected += (id) => UserIdentifierDetected?.Invoke(id);
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2019-09-24 08:53:29 +02:00
|
|
|
|
InitializeRequestFilter(requestFilter);
|
|
|
|
|
|
2024-03-04 14:27:49 +01:00
|
|
|
|
Control = new BrowserControl(clipboard, cefSharpControl, dialogHandler, displayHandler, downloadHandler, keyboardHandler, controlLogger, renderHandler, requestHandler);
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.AddressChanged += Control_AddressChanged;
|
|
|
|
|
Control.LoadFailed += Control_LoadFailed;
|
|
|
|
|
Control.LoadingStateChanged += Control_LoadingStateChanged;
|
|
|
|
|
Control.TitleChanged += Control_TitleChanged;
|
|
|
|
|
|
|
|
|
|
Control.Initialize();
|
2019-09-24 08:53:29 +02:00
|
|
|
|
logger.Debug("Initialized browser control.");
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
internal void InitializeWindow()
|
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
window = uiFactory.CreateBrowserWindow(Control, settings, IsMainWindow, this.logger);
|
2022-02-23 13:59:36 +01:00
|
|
|
|
window.AddressChanged += Window_AddressChanged;
|
|
|
|
|
window.BackwardNavigationRequested += Window_BackwardNavigationRequested;
|
|
|
|
|
window.Closed += Window_Closed;
|
|
|
|
|
window.Closing += Window_Closing;
|
|
|
|
|
window.DeveloperConsoleRequested += Window_DeveloperConsoleRequested;
|
|
|
|
|
window.FindRequested += Window_FindRequested;
|
|
|
|
|
window.ForwardNavigationRequested += Window_ForwardNavigationRequested;
|
|
|
|
|
window.HomeNavigationRequested += HomeNavigationRequested;
|
2021-11-24 08:42:07 +01:00
|
|
|
|
window.LoseFocusRequested += Window_LoseFocusRequested;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
window.ReloadRequested += ReloadRequested;
|
|
|
|
|
window.ZoomInRequested += ZoomInRequested;
|
|
|
|
|
window.ZoomOutRequested += ZoomOutRequested;
|
|
|
|
|
window.ZoomResetRequested += ZoomResetRequested;
|
|
|
|
|
window.UpdateZoomLevel(CalculateZoomPercentage());
|
|
|
|
|
window.Show();
|
|
|
|
|
window.BringToForeground();
|
|
|
|
|
|
|
|
|
|
Handle = window.Handle;
|
|
|
|
|
|
|
|
|
|
logger.Debug("Initialized browser window.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ILifeSpanHandler CreateLifeSpanHandlerForMainWindow()
|
|
|
|
|
{
|
|
|
|
|
return LifeSpanHandler
|
|
|
|
|
.Create(() => LifeSpanHandler_CreatePopup())
|
|
|
|
|
.OnBeforePopupCreated((wb, b, f, u, t, d, g, s) => LifeSpanHandler_PopupRequested(u))
|
|
|
|
|
.OnPopupCreated((c, u) => LifeSpanHandler_PopupCreated(c))
|
|
|
|
|
.OnPopupDestroyed((c, b) => LifeSpanHandler_PopupDestroyed(c))
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 08:53:29 +02:00
|
|
|
|
private void InitializeRequestFilter(IRequestFilter requestFilter)
|
|
|
|
|
{
|
2019-09-13 09:17:14 +02:00
|
|
|
|
if (settings.Filter.ProcessContentRequests || settings.Filter.ProcessMainRequests)
|
|
|
|
|
{
|
|
|
|
|
var factory = new RuleFactory();
|
|
|
|
|
|
|
|
|
|
foreach (var settings in settings.Filter.Rules)
|
|
|
|
|
{
|
|
|
|
|
var rule = factory.CreateRule(settings.Type);
|
|
|
|
|
|
|
|
|
|
rule.Initialize(settings);
|
|
|
|
|
requestFilter.Load(rule);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.Debug($"Initialized request filter with {settings.Filter.Rules.Count} rule(s).");
|
|
|
|
|
|
2019-09-24 08:53:29 +02:00
|
|
|
|
if (requestFilter.Process(new Request { Url = settings.StartUrl }) != FilterResult.Allow)
|
|
|
|
|
{
|
|
|
|
|
var rule = factory.CreateRule(FilterRuleType.Simplified);
|
2019-09-10 11:01:49 +02:00
|
|
|
|
|
2019-09-24 08:53:29 +02:00
|
|
|
|
rule.Initialize(new FilterRuleSettings { Expression = settings.StartUrl, Result = FilterResult.Allow });
|
|
|
|
|
requestFilter.Load(rule);
|
|
|
|
|
|
2020-09-29 14:01:17 +02:00
|
|
|
|
logger.Debug($"Automatically created filter rule to allow start URL{(WindowSettings.UrlPolicy.CanLog() ? $" '{settings.StartUrl}'" : "")}.");
|
2019-09-24 08:53:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-06 08:13:27 +02:00
|
|
|
|
}
|
2018-08-31 15:29:36 +02:00
|
|
|
|
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private void Control_AddressChanged(string address)
|
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Info($"Navigated{(WindowSettings.UrlPolicy.CanLog() ? $" to '{address}'" : "")}.");
|
2024-02-13 11:04:36 +01:00
|
|
|
|
|
|
|
|
|
Url = address;
|
2017-07-31 20:22:53 +02:00
|
|
|
|
window.UpdateAddress(address);
|
2020-09-29 14:01:17 +02:00
|
|
|
|
|
|
|
|
|
if (WindowSettings.UrlPolicy == UrlPolicy.Always || WindowSettings.UrlPolicy == UrlPolicy.BeforeTitle)
|
|
|
|
|
{
|
|
|
|
|
Title = address;
|
|
|
|
|
window.UpdateTitle(address);
|
|
|
|
|
TitleChanged?.Invoke(address);
|
|
|
|
|
}
|
2022-05-31 12:34:01 +02:00
|
|
|
|
|
|
|
|
|
AutoFind();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 16:47:18 +02:00
|
|
|
|
private void Control_LoadFailed(int errorCode, string errorText, bool isMainRequest, string url)
|
2020-05-15 16:13:15 +02:00
|
|
|
|
{
|
2022-05-13 16:47:18 +02:00
|
|
|
|
switch (errorCode)
|
2020-05-15 16:13:15 +02:00
|
|
|
|
{
|
2022-05-13 16:47:18 +02:00
|
|
|
|
case (int) CefErrorCode.Aborted:
|
|
|
|
|
logger.Info($"Request{(WindowSettings.UrlPolicy.CanLog() ? $" for '{url}'" : "")} was aborted.");
|
|
|
|
|
break;
|
|
|
|
|
case (int) CefErrorCode.InternetDisconnected:
|
|
|
|
|
logger.Info($"Request{(WindowSettings.UrlPolicy.CanLog() ? $" for '{url}'" : "")} has failed due to loss of internet connection.");
|
|
|
|
|
break;
|
|
|
|
|
case (int) CefErrorCode.None:
|
|
|
|
|
logger.Info($"Request{(WindowSettings.UrlPolicy.CanLog() ? $" for '{url}'" : "")} was successful.");
|
|
|
|
|
break;
|
|
|
|
|
case (int) CefErrorCode.UnknownUrlScheme:
|
|
|
|
|
logger.Info($"Request{(WindowSettings.UrlPolicy.CanLog() ? $" for '{url}'" : "")} has an unknown URL scheme and will be handled by the OS.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
HandleUnknownLoadFailure(errorCode, errorText, isMainRequest, url);
|
|
|
|
|
break;
|
2020-08-06 14:26:40 +02:00
|
|
|
|
}
|
2022-05-13 16:47:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleUnknownLoadFailure(int errorCode, string errorText, bool isMainRequest, string url)
|
|
|
|
|
{
|
|
|
|
|
var requestInfo = $"{errorText} ({errorCode}, {(isMainRequest ? "main" : "resource")} request)";
|
|
|
|
|
|
|
|
|
|
logger.Warn($"Request{(WindowSettings.UrlPolicy.CanLogError() ? $" for '{url}'" : "")} failed: {requestInfo}.");
|
|
|
|
|
|
|
|
|
|
if (isMainRequest)
|
2020-05-15 16:13:15 +02:00
|
|
|
|
{
|
2020-08-06 14:30:37 +02:00
|
|
|
|
var title = text.Get(TextKey.Browser_LoadErrorTitle);
|
2022-05-13 16:47:18 +02:00
|
|
|
|
var message = text.Get(TextKey.Browser_LoadErrorMessage).Replace("%%URL%%", WindowSettings.UrlPolicy.CanLogError() ? url : "") + $" {requestInfo}";
|
2020-05-15 16:13:15 +02:00
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Task.Run(() => messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: window)).ContinueWith(_ => Control.NavigateBackwards());
|
2020-05-15 16:13:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 08:50:08 +01:00
|
|
|
|
private void Control_LoadingStateChanged(bool isLoading)
|
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
window.CanNavigateBackwards = WindowSettings.AllowBackwardNavigation && Control.CanNavigateBackwards;
|
|
|
|
|
window.CanNavigateForwards = WindowSettings.AllowForwardNavigation && Control.CanNavigateForwards;
|
2018-03-01 08:50:08 +01:00
|
|
|
|
window.UpdateLoadingState(isLoading);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private void Control_TitleChanged(string title)
|
|
|
|
|
{
|
2020-09-29 14:01:17 +02:00
|
|
|
|
if (WindowSettings.UrlPolicy != UrlPolicy.Always)
|
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
window.UpdateTitle(Title);
|
|
|
|
|
TitleChanged?.Invoke(Title);
|
|
|
|
|
}
|
2017-07-31 20:22:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 16:13:08 +01:00
|
|
|
|
private void DialogHandler_DialogRequested(DialogRequestedEventArgs args)
|
|
|
|
|
{
|
2020-01-24 10:19:11 +01:00
|
|
|
|
var isDownload = args.Operation == FileSystemOperation.Save;
|
|
|
|
|
var isUpload = args.Operation == FileSystemOperation.Open;
|
|
|
|
|
var isAllowed = (isDownload && settings.AllowDownloads) || (isUpload && settings.AllowUploads);
|
2020-08-05 22:55:38 +02:00
|
|
|
|
var initialPath = default(string);
|
|
|
|
|
|
|
|
|
|
if (isDownload)
|
|
|
|
|
{
|
|
|
|
|
initialPath = args.InitialPath;
|
|
|
|
|
}
|
2022-02-04 13:41:11 +01:00
|
|
|
|
else if (string.IsNullOrEmpty(settings.DownAndUploadDirectory))
|
|
|
|
|
{
|
|
|
|
|
initialPath = KnownFolders.Downloads.ExpandedPath;
|
|
|
|
|
}
|
2020-08-05 22:55:38 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-04 13:41:11 +01:00
|
|
|
|
initialPath = Environment.ExpandEnvironmentVariables(settings.DownAndUploadDirectory);
|
2020-08-05 22:55:38 +02:00
|
|
|
|
}
|
2020-01-20 16:13:08 +01:00
|
|
|
|
|
2020-01-24 10:19:11 +01:00
|
|
|
|
if (isAllowed)
|
2020-01-20 16:13:08 +01:00
|
|
|
|
{
|
2020-08-05 22:55:38 +02:00
|
|
|
|
var result = fileSystemDialog.Show(
|
|
|
|
|
args.Element,
|
|
|
|
|
args.Operation,
|
|
|
|
|
initialPath,
|
|
|
|
|
title: args.Title,
|
|
|
|
|
parent: window,
|
2023-03-09 22:49:54 +01:00
|
|
|
|
restrictNavigation: !settings.AllowCustomDownAndUploadLocation,
|
|
|
|
|
showElementPath: settings.ShowFileSystemElementPath);
|
2020-01-24 10:19:11 +01:00
|
|
|
|
|
|
|
|
|
if (result.Success)
|
|
|
|
|
{
|
|
|
|
|
args.FullPath = result.FullPath;
|
|
|
|
|
args.Success = result.Success;
|
|
|
|
|
logger.Debug($"User selected path '{result.FullPath}' when asked to {args.Operation}->{args.Element}.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"User aborted file system dialog to {args.Operation}->{args.Element}.");
|
|
|
|
|
}
|
2020-01-20 16:13:08 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-24 10:19:11 +01:00
|
|
|
|
logger.Info($"Blocked file system dialog to {args.Operation}->{args.Element}, as {(isDownload ? "downloading" : "uploading")} is not allowed.");
|
2022-05-13 12:03:06 +02:00
|
|
|
|
ShowDownUploadNotAllowedMessage(isDownload);
|
2020-01-20 16:13:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 16:15:10 +01:00
|
|
|
|
private void DisplayHandler_FaviconChanged(string uri)
|
|
|
|
|
{
|
2020-06-22 11:31:42 +02:00
|
|
|
|
Task.Run(() =>
|
2019-05-08 13:53:38 +02:00
|
|
|
|
{
|
2020-06-22 11:31:42 +02:00
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Head, uri);
|
|
|
|
|
var response = httpClient.SendAsync(request).ContinueWith(task =>
|
2019-05-08 13:53:38 +02:00
|
|
|
|
{
|
2020-06-22 11:31:42 +02:00
|
|
|
|
if (task.IsCompleted && task.Result.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Icon = new BrowserIconResource(uri);
|
|
|
|
|
|
|
|
|
|
IconChanged?.Invoke(Icon);
|
|
|
|
|
window.UpdateIcon(Icon);
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-05-08 13:53:38 +02:00
|
|
|
|
});
|
2019-01-17 16:15:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 11:42:31 +02:00
|
|
|
|
private void DisplayHandler_ProgressChanged(double value)
|
|
|
|
|
{
|
|
|
|
|
window.UpdateProgress(value);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 11:24:28 +01:00
|
|
|
|
private void DownloadHandler_ConfigurationDownloadRequested(string fileName, DownloadEventArgs args)
|
|
|
|
|
{
|
2018-11-08 09:39:52 +01:00
|
|
|
|
if (settings.AllowConfigurationDownloads)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"Forwarding download request for configuration file '{fileName}'.");
|
|
|
|
|
ConfigurationDownloadRequested?.Invoke(fileName, args);
|
2019-09-04 15:12:59 +02:00
|
|
|
|
|
|
|
|
|
if (args.AllowDownload)
|
|
|
|
|
{
|
2019-09-25 08:45:20 +02:00
|
|
|
|
logger.Debug($"Download request for configuration file '{fileName}' was granted.");
|
2019-09-04 15:12:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"Download request for configuration file '{fileName}' was denied.");
|
|
|
|
|
messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle, parent: window);
|
|
|
|
|
}
|
2018-11-08 09:39:52 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"Discarded download request for configuration file '{fileName}'.");
|
|
|
|
|
}
|
2018-10-30 11:24:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 12:03:06 +02:00
|
|
|
|
private void DownloadHandler_DownloadAborted()
|
|
|
|
|
{
|
|
|
|
|
ShowDownUploadNotAllowedMessage();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
private void DownloadHandler_DownloadUpdated(DownloadItemState state)
|
|
|
|
|
{
|
|
|
|
|
window.UpdateDownloadState(state);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 23:37:23 +02:00
|
|
|
|
private void HomeNavigationRequested()
|
|
|
|
|
{
|
2024-02-13 11:04:36 +01:00
|
|
|
|
if (IsMainWindow && (settings.UseStartUrlAsHomeUrl || !string.IsNullOrWhiteSpace(settings.HomeUrl)))
|
2020-10-05 23:37:23 +02:00
|
|
|
|
{
|
|
|
|
|
var navigate = false;
|
|
|
|
|
var url = settings.UseStartUrlAsHomeUrl ? settings.StartUrl : settings.HomeUrl;
|
|
|
|
|
|
|
|
|
|
if (settings.HomeNavigationRequiresPassword && !string.IsNullOrWhiteSpace(settings.HomePasswordHash))
|
|
|
|
|
{
|
|
|
|
|
var message = text.Get(TextKey.PasswordDialog_BrowserHomePasswordRequired);
|
|
|
|
|
var title = !string.IsNullOrWhiteSpace(settings.HomeNavigationMessage) ? settings.HomeNavigationMessage : text.Get(TextKey.PasswordDialog_BrowserHomePasswordRequiredTitle);
|
|
|
|
|
var dialog = uiFactory.CreatePasswordDialog(message, title);
|
|
|
|
|
var result = dialog.Show(window);
|
|
|
|
|
|
|
|
|
|
if (result.Success)
|
|
|
|
|
{
|
|
|
|
|
var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
|
|
|
|
|
|
|
|
|
|
if (settings.HomePasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
navigate = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
messageBox.Show(TextKey.MessageBox_InvalidHomePassword, TextKey.MessageBox_InvalidHomePasswordTitle, icon: MessageBoxIcon.Warning, parent: window);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var message = text.Get(TextKey.MessageBox_BrowserHomeQuestion);
|
|
|
|
|
var title = !string.IsNullOrWhiteSpace(settings.HomeNavigationMessage) ? settings.HomeNavigationMessage : text.Get(TextKey.MessageBox_BrowserHomeQuestionTitle);
|
|
|
|
|
var result = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question, window);
|
|
|
|
|
|
|
|
|
|
navigate = result == MessageBoxResult.Yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (navigate)
|
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.NavigateTo(url);
|
2020-10-05 23:37:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 21:42:51 +02:00
|
|
|
|
private void KeyboardHandler_FindRequested()
|
|
|
|
|
{
|
2020-08-11 17:52:51 +02:00
|
|
|
|
if (settings.AllowFind)
|
|
|
|
|
{
|
|
|
|
|
window.ShowFindbar();
|
|
|
|
|
}
|
2020-08-10 21:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 16:47:18 +02:00
|
|
|
|
private void KeyboardHandler_FocusAddressBarRequested()
|
2022-05-02 15:18:38 +02:00
|
|
|
|
{
|
|
|
|
|
window.FocusAddressBar();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 16:47:18 +02:00
|
|
|
|
private void KeyboardHandler_TabPressed(bool shiftPressed)
|
|
|
|
|
{
|
2024-03-04 14:27:49 +01:00
|
|
|
|
Control.ExecuteJavaScript("document.activeElement.tagName", result =>
|
2022-05-13 16:47:18 +02:00
|
|
|
|
{
|
2022-05-31 12:49:32 +02:00
|
|
|
|
if (result.Result is string tagName && tagName?.ToUpper() == "BODY")
|
2022-05-13 16:47:18 +02:00
|
|
|
|
{
|
|
|
|
|
// This means the user is now at the start of the focus / tabIndex chain in the website.
|
|
|
|
|
if (shiftPressed)
|
|
|
|
|
{
|
|
|
|
|
window.FocusToolbar(!shiftPressed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoseFocusRequested?.Invoke(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
private ChromiumHostControl LifeSpanHandler_CreatePopup()
|
|
|
|
|
{
|
|
|
|
|
var args = new PopupRequestedEventArgs();
|
|
|
|
|
|
|
|
|
|
PopupRequested?.Invoke(args);
|
|
|
|
|
|
|
|
|
|
var control = args.Window.Control.EmbeddableControl as ChromiumHostControl;
|
|
|
|
|
var id = control.GetHashCode();
|
|
|
|
|
var window = args.Window;
|
|
|
|
|
|
|
|
|
|
popups[id] = window;
|
|
|
|
|
window.Closed += (_) => popups.Remove(id);
|
|
|
|
|
|
|
|
|
|
return control;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LifeSpanHandler_PopupCreated(ChromiumHostControl control)
|
2019-01-17 11:12:17 +01:00
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
var id = control.GetHashCode();
|
|
|
|
|
var window = popups[id];
|
|
|
|
|
|
|
|
|
|
window.InitializeWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LifeSpanHandler_PopupDestroyed(ChromiumHostControl control)
|
|
|
|
|
{
|
|
|
|
|
var id = control.GetHashCode();
|
|
|
|
|
var window = popups[id];
|
|
|
|
|
|
|
|
|
|
window.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PopupCreation LifeSpanHandler_PopupRequested(string targetUrl)
|
|
|
|
|
{
|
|
|
|
|
var creation = PopupCreation.Cancel;
|
|
|
|
|
var validCurrentUri = Uri.TryCreate(Control.Address, UriKind.Absolute, out var currentUri);
|
|
|
|
|
var validNewUri = Uri.TryCreate(targetUrl, UriKind.Absolute, out var newUri);
|
2019-12-13 16:10:10 +01:00
|
|
|
|
var sameHost = validCurrentUri && validNewUri && string.Equals(currentUri.Host, newUri.Host, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
2019-12-12 15:41:05 +01:00
|
|
|
|
switch (settings.PopupPolicy)
|
2019-01-17 11:12:17 +01:00
|
|
|
|
{
|
2019-12-12 15:41:05 +01:00
|
|
|
|
case PopupPolicy.Allow:
|
2019-12-13 16:10:10 +01:00
|
|
|
|
case PopupPolicy.AllowSameHost when sameHost:
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Debug($"Forwarding request to open new window{(WindowSettings.UrlPolicy.CanLog() ? $" for '{targetUrl}'" : "")}...");
|
|
|
|
|
creation = PopupCreation.Continue;
|
2019-12-12 15:41:05 +01:00
|
|
|
|
break;
|
2019-12-13 16:10:10 +01:00
|
|
|
|
case PopupPolicy.AllowSameWindow:
|
|
|
|
|
case PopupPolicy.AllowSameHostAndWindow when sameHost:
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Info($"Discarding request to open new window and loading{(WindowSettings.UrlPolicy.CanLog() ? $" '{targetUrl}'" : "")} directly...");
|
|
|
|
|
Control.NavigateTo(targetUrl);
|
2019-12-12 15:41:05 +01:00
|
|
|
|
break;
|
2019-12-13 16:10:10 +01:00
|
|
|
|
case PopupPolicy.AllowSameHost when !sameHost:
|
|
|
|
|
case PopupPolicy.AllowSameHostAndWindow when !sameHost:
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Info($"Blocked request to open new window{(WindowSettings.UrlPolicy.CanLog() ? $" for '{targetUrl}'" : "")} as it targets a different host.");
|
2019-12-13 16:10:10 +01:00
|
|
|
|
break;
|
2019-12-12 15:41:05 +01:00
|
|
|
|
default:
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Info($"Blocked request to open new window{(WindowSettings.UrlPolicy.CanLog() ? $" for '{targetUrl}'" : "")}.");
|
2019-12-12 15:41:05 +01:00
|
|
|
|
break;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
}
|
2022-02-23 13:59:36 +01:00
|
|
|
|
|
|
|
|
|
return creation;
|
2019-01-17 11:12:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 15:02:40 +01:00
|
|
|
|
private void RequestHandler_QuitUrlVisited(string url)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2020-09-21 19:22:15 +02:00
|
|
|
|
if (settings.ResetOnQuitUrl)
|
2019-12-19 15:02:40 +01:00
|
|
|
|
{
|
2020-09-21 19:22:15 +02:00
|
|
|
|
logger.Info("Forwarding request to reset browser...");
|
|
|
|
|
ResetRequested?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (settings.ConfirmQuitUrl)
|
2019-12-19 15:02:40 +01:00
|
|
|
|
{
|
2020-09-21 19:22:15 +02:00
|
|
|
|
var message = text.Get(TextKey.MessageBox_BrowserQuitUrlConfirmation);
|
|
|
|
|
var title = text.Get(TextKey.MessageBox_BrowserQuitUrlConfirmationTitle);
|
|
|
|
|
var result = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question, window);
|
|
|
|
|
var terminate = result == MessageBoxResult.Yes;
|
|
|
|
|
|
|
|
|
|
if (terminate)
|
|
|
|
|
{
|
2020-09-29 14:01:17 +02:00
|
|
|
|
logger.Info($"User confirmed termination via quit URL{(WindowSettings.UrlPolicy.CanLog() ? $" '{url}'" : "")}, forwarding request...");
|
2020-09-21 19:22:15 +02:00
|
|
|
|
TerminationRequested?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-29 14:01:17 +02:00
|
|
|
|
logger.Info($"User aborted termination via quit URL{(WindowSettings.UrlPolicy.CanLog() ? $" '{url}'" : "")}.");
|
2020-09-21 19:22:15 +02:00
|
|
|
|
}
|
2019-12-19 15:02:40 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-29 14:01:17 +02:00
|
|
|
|
logger.Info($"Automatically requesting termination due to quit URL{(WindowSettings.UrlPolicy.CanLog() ? $" '{url}'" : "")}...");
|
2020-09-21 19:22:15 +02:00
|
|
|
|
TerminationRequested?.Invoke();
|
2019-12-19 15:02:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 12:31:17 +02:00
|
|
|
|
private void RequestHandler_RequestBlocked(string url)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
2020-09-29 14:01:17 +02:00
|
|
|
|
var message = text.Get(TextKey.MessageBox_BrowserNavigationBlocked).Replace("%%URL%%", WindowSettings.UrlPolicy.CanLogError() ? url : "");
|
2019-09-12 12:31:17 +02:00
|
|
|
|
var title = text.Get(TextKey.MessageBox_BrowserNavigationBlockedTitle);
|
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.TitleChanged -= Control_TitleChanged;
|
2019-09-24 08:53:29 +02:00
|
|
|
|
|
2019-12-19 15:02:40 +01:00
|
|
|
|
if (url.Equals(startUrl, StringComparison.OrdinalIgnoreCase))
|
2019-09-24 08:53:29 +02:00
|
|
|
|
{
|
|
|
|
|
window.UpdateTitle($"*** {title} ***");
|
2019-11-28 17:22:04 +01:00
|
|
|
|
TitleChanged?.Invoke($"*** {title} ***");
|
2019-09-24 08:53:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 12:31:17 +02:00
|
|
|
|
messageBox.Show(message, title, parent: window);
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.TitleChanged += Control_TitleChanged;
|
2019-09-12 12:31:17 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 16:11:33 +01:00
|
|
|
|
private void ReloadRequested()
|
2017-07-31 20:22:53 +02:00
|
|
|
|
{
|
2019-01-23 09:37:47 +01:00
|
|
|
|
if (WindowSettings.AllowReloading && WindowSettings.ShowReloadWarning)
|
2019-01-18 16:11:33 +01:00
|
|
|
|
{
|
|
|
|
|
var result = messageBox.Show(TextKey.MessageBox_ReloadConfirmation, TextKey.MessageBox_ReloadConfirmationTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question, window);
|
|
|
|
|
|
|
|
|
|
if (result == MessageBoxResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug("The user confirmed reloading the current page...");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Reload();
|
2019-01-18 16:11:33 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug("The user aborted reloading the current page.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-23 09:37:47 +01:00
|
|
|
|
else if (WindowSettings.AllowReloading)
|
2019-01-18 16:11:33 +01:00
|
|
|
|
{
|
|
|
|
|
logger.Debug("Reloading current page...");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Reload();
|
2019-01-18 16:11:33 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug("Blocked reload attempt, as the user is not allowed to reload web pages.");
|
|
|
|
|
}
|
2017-07-31 20:22:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 12:03:06 +02:00
|
|
|
|
private void ShowDownUploadNotAllowedMessage(bool isDownload = true)
|
|
|
|
|
{
|
|
|
|
|
var message = isDownload ? TextKey.MessageBox_DownloadNotAllowed : TextKey.MessageBox_UploadNotAllowed;
|
|
|
|
|
var title = isDownload ? TextKey.MessageBox_DownloadNotAllowedTitle : TextKey.MessageBox_UploadNotAllowedTitle;
|
|
|
|
|
|
|
|
|
|
messageBox.Show(message, title, icon: MessageBoxIcon.Warning, parent: window);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 16:11:33 +01:00
|
|
|
|
private void Window_AddressChanged(string address)
|
2017-07-31 20:22:53 +02:00
|
|
|
|
{
|
2019-03-15 15:55:34 +01:00
|
|
|
|
var isValid = Uri.TryCreate(address, UriKind.Absolute, out _) || Uri.TryCreate($"https://{address}", UriKind.Absolute, out _);
|
|
|
|
|
|
|
|
|
|
if (isValid)
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"The user requested to navigate to '{address}', the URI is valid.");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.NavigateTo(address);
|
2019-03-15 15:55:34 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"The user requested to navigate to '{address}', but the URI is not valid.");
|
|
|
|
|
window.UpdateAddress(string.Empty);
|
|
|
|
|
}
|
2017-07-31 20:22:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_BackwardNavigationRequested()
|
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
logger.Debug("Navigating backwards...");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.NavigateBackwards();
|
2017-07-14 10:28:59 +02:00
|
|
|
|
}
|
2017-07-24 17:31:28 +02:00
|
|
|
|
|
2019-11-29 14:59:54 +01:00
|
|
|
|
private void Window_Closing()
|
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Debug($"Window is closing...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Closed()
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"Window has been closed.");
|
|
|
|
|
Control.Destroy();
|
2022-02-04 13:41:11 +01:00
|
|
|
|
Closed?.Invoke(Id);
|
2019-11-29 14:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 11:42:31 +02:00
|
|
|
|
private void Window_DeveloperConsoleRequested()
|
|
|
|
|
{
|
|
|
|
|
logger.Debug("Showing developer console...");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.ShowDeveloperConsole();
|
2019-05-22 11:42:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 21:42:51 +02:00
|
|
|
|
private void Window_FindRequested(string term, bool isInitial, bool caseSensitive, bool forward = true)
|
|
|
|
|
{
|
2020-08-11 17:52:51 +02:00
|
|
|
|
if (settings.AllowFind)
|
|
|
|
|
{
|
2022-05-31 12:34:01 +02:00
|
|
|
|
findParameters.caseSensitive = caseSensitive;
|
|
|
|
|
findParameters.forward = forward;
|
|
|
|
|
findParameters.isInitial = isInitial;
|
|
|
|
|
findParameters.term = term;
|
|
|
|
|
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Find(term, isInitial, caseSensitive, forward);
|
2020-08-11 17:52:51 +02:00
|
|
|
|
}
|
2020-08-10 21:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 20:22:53 +02:00
|
|
|
|
private void Window_ForwardNavigationRequested()
|
2017-07-24 17:31:28 +02:00
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
logger.Debug("Navigating forwards...");
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.NavigateForwards();
|
2017-07-24 17:31:28 +02:00
|
|
|
|
}
|
2019-01-18 16:11:33 +01:00
|
|
|
|
|
2021-11-24 08:42:07 +01:00
|
|
|
|
private void Window_LoseFocusRequested(bool forward)
|
|
|
|
|
{
|
|
|
|
|
LoseFocusRequested?.Invoke(forward);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 16:11:33 +01:00
|
|
|
|
private void ZoomInRequested()
|
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
if (settings.AllowPageZoom && CalculateZoomPercentage() < 300)
|
2019-01-18 16:11:33 +01:00
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
zoomLevel += ZOOM_FACTOR;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Zoom(zoomLevel);
|
2019-05-22 11:42:31 +02:00
|
|
|
|
window.UpdateZoomLevel(CalculateZoomPercentage());
|
|
|
|
|
logger.Debug($"Increased page zoom to {CalculateZoomPercentage()}%.");
|
2019-01-18 16:11:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ZoomOutRequested()
|
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
if (settings.AllowPageZoom && CalculateZoomPercentage() > 25)
|
2019-01-18 16:11:33 +01:00
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
zoomLevel -= ZOOM_FACTOR;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Zoom(zoomLevel);
|
2019-05-22 11:42:31 +02:00
|
|
|
|
window.UpdateZoomLevel(CalculateZoomPercentage());
|
|
|
|
|
logger.Debug($"Decreased page zoom to {CalculateZoomPercentage()}%.");
|
2019-01-18 16:11:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ZoomResetRequested()
|
|
|
|
|
{
|
|
|
|
|
if (settings.AllowPageZoom)
|
|
|
|
|
{
|
2019-05-22 11:42:31 +02:00
|
|
|
|
zoomLevel = 0;
|
2022-02-23 13:59:36 +01:00
|
|
|
|
Control.Zoom(0);
|
2019-05-22 11:42:31 +02:00
|
|
|
|
window.UpdateZoomLevel(CalculateZoomPercentage());
|
|
|
|
|
logger.Debug($"Reset page zoom to {CalculateZoomPercentage()}%.");
|
2019-01-18 16:11:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-22 11:42:31 +02:00
|
|
|
|
|
2022-05-31 12:34:01 +02:00
|
|
|
|
private void AutoFind()
|
|
|
|
|
{
|
|
|
|
|
if (settings.AllowFind && !string.IsNullOrEmpty(findParameters.term) && !CLEAR_FIND_TERM.Equals(findParameters.term, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
Control.Find(findParameters.term, findParameters.isInitial, findParameters.caseSensitive, findParameters.forward);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 11:42:31 +02:00
|
|
|
|
private double CalculateZoomPercentage()
|
|
|
|
|
{
|
|
|
|
|
return (zoomLevel * 25.0) + 100.0;
|
|
|
|
|
}
|
2017-07-14 10:28:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|