2022-07-22 15:38:07 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2022-07-22 15:38:07 +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 CefSharp;
|
|
|
|
|
using SafeExamBrowser.Browser.Content;
|
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
|
|
|
|
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
2022-07-25 20:25:42 +02:00
|
|
|
|
using BrowserSettings = SafeExamBrowser.Settings.Browser.BrowserSettings;
|
2022-07-22 15:38:07 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Browser.Handlers
|
|
|
|
|
{
|
|
|
|
|
internal class RenderProcessMessageHandler : IRenderProcessMessageHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly AppConfig appConfig;
|
2024-03-13 17:38:10 +01:00
|
|
|
|
private readonly Clipboard clipboard;
|
2022-07-22 15:38:07 +02:00
|
|
|
|
private readonly ContentLoader contentLoader;
|
|
|
|
|
private readonly IKeyGenerator keyGenerator;
|
2022-07-25 20:25:42 +02:00
|
|
|
|
private readonly BrowserSettings settings;
|
|
|
|
|
private readonly IText text;
|
2022-07-22 15:38:07 +02:00
|
|
|
|
|
2024-03-13 17:38:10 +01:00
|
|
|
|
internal RenderProcessMessageHandler(AppConfig appConfig, Clipboard clipboard, IKeyGenerator keyGenerator, BrowserSettings settings, IText text)
|
2022-07-22 15:38:07 +02:00
|
|
|
|
{
|
|
|
|
|
this.appConfig = appConfig;
|
2024-03-13 17:38:10 +01:00
|
|
|
|
this.clipboard = clipboard;
|
2022-07-22 15:38:07 +02:00
|
|
|
|
this.contentLoader = new ContentLoader(text);
|
|
|
|
|
this.keyGenerator = keyGenerator;
|
2022-07-25 20:25:42 +02:00
|
|
|
|
this.settings = settings;
|
|
|
|
|
this.text = text;
|
2022-07-22 15:38:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnContextCreated(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
|
|
|
|
|
{
|
2023-03-02 23:48:11 +01:00
|
|
|
|
var browserExamKey = keyGenerator.CalculateBrowserExamKeyHash(settings.ConfigurationKey, settings.BrowserExamKeySalt, frame.Url);
|
|
|
|
|
var configurationKey = keyGenerator.CalculateConfigurationKeyHash(settings.ConfigurationKey, frame.Url);
|
2022-07-22 15:38:07 +02:00
|
|
|
|
var api = contentLoader.LoadApi(browserExamKey, configurationKey, appConfig.ProgramBuildVersion);
|
2024-03-13 17:38:10 +01:00
|
|
|
|
var clipboardScript = contentLoader.LoadClipboard();
|
2024-08-29 10:08:36 +02:00
|
|
|
|
var pageZoomScript = contentLoader.LoadPageZoom();
|
2022-07-22 15:38:07 +02:00
|
|
|
|
|
|
|
|
|
frame.ExecuteJavaScriptAsync(api);
|
2022-07-25 20:25:42 +02:00
|
|
|
|
|
2024-08-29 10:08:36 +02:00
|
|
|
|
if (!settings.AllowPageZoom)
|
|
|
|
|
{
|
|
|
|
|
frame.ExecuteJavaScriptAsync(pageZoomScript);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-25 20:25:42 +02:00
|
|
|
|
if (!settings.AllowPrint)
|
|
|
|
|
{
|
2024-03-13 17:38:10 +01:00
|
|
|
|
frame.ExecuteJavaScriptAsync($"window.print = function() {{ alert('{text.Get(TextKey.Browser_PrintNotAllowed)}') }}");
|
2022-07-25 20:25:42 +02:00
|
|
|
|
}
|
2023-07-21 09:31:59 +02:00
|
|
|
|
|
|
|
|
|
if (settings.UseIsolatedClipboard)
|
|
|
|
|
{
|
2024-03-13 17:38:10 +01:00
|
|
|
|
frame.ExecuteJavaScriptAsync(clipboardScript);
|
|
|
|
|
|
|
|
|
|
if (clipboard.Content != default)
|
|
|
|
|
{
|
|
|
|
|
frame.ExecuteJavaScriptAsync($"SafeExamBrowser.clipboard.update('', '{clipboard.Content}');");
|
|
|
|
|
}
|
2023-07-21 09:31:59 +02:00
|
|
|
|
}
|
2022-07-22 15:38:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|