From 514414e322d52912baa55e2d2daa057d0a2dcd6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 13 Mar 2024 17:38:10 +0100 Subject: [PATCH] SEBWIN-820, #764: Fixed missing content of isolated clipboard after navigation or reload. --- SafeExamBrowser.Browser/BrowserWindow.cs | 2 +- .../Handlers/RenderProcessMessageHandler.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SafeExamBrowser.Browser/BrowserWindow.cs b/SafeExamBrowser.Browser/BrowserWindow.cs index 04ab75d8c..dc67d5a79 100644 --- a/SafeExamBrowser.Browser/BrowserWindow.cs +++ b/SafeExamBrowser.Browser/BrowserWindow.cs @@ -158,7 +158,7 @@ internal void InitializeControl() var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}"); var downloadHandler = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings); var keyboardHandler = new KeyboardHandler(); - var renderHandler = new RenderProcessMessageHandler(appConfig, keyGenerator, settings, text); + var renderHandler = new RenderProcessMessageHandler(appConfig, clipboard, keyGenerator, settings, text); var requestFilter = new RequestFilter(); var requestLogger = logger.CloneFor($"{nameof(RequestHandler)} #{Id}"); var resourceHandler = new ResourceHandler(appConfig, requestFilter, keyGenerator, logger, sessionMode, settings, WindowSettings, text); diff --git a/SafeExamBrowser.Browser/Handlers/RenderProcessMessageHandler.cs b/SafeExamBrowser.Browser/Handlers/RenderProcessMessageHandler.cs index d6e33d213..71c041c09 100644 --- a/SafeExamBrowser.Browser/Handlers/RenderProcessMessageHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/RenderProcessMessageHandler.cs @@ -18,14 +18,16 @@ namespace SafeExamBrowser.Browser.Handlers internal class RenderProcessMessageHandler : IRenderProcessMessageHandler { private readonly AppConfig appConfig; + private readonly Clipboard clipboard; private readonly ContentLoader contentLoader; private readonly IKeyGenerator keyGenerator; private readonly BrowserSettings settings; private readonly IText text; - internal RenderProcessMessageHandler(AppConfig appConfig, IKeyGenerator keyGenerator, BrowserSettings settings, IText text) + internal RenderProcessMessageHandler(AppConfig appConfig, Clipboard clipboard, IKeyGenerator keyGenerator, BrowserSettings settings, IText text) { this.appConfig = appConfig; + this.clipboard = clipboard; this.contentLoader = new ContentLoader(text); this.keyGenerator = keyGenerator; this.settings = settings; @@ -37,18 +39,23 @@ public void OnContextCreated(IWebBrowser chromiumWebBrowser, IBrowser browser, I var browserExamKey = keyGenerator.CalculateBrowserExamKeyHash(settings.ConfigurationKey, settings.BrowserExamKeySalt, frame.Url); var configurationKey = keyGenerator.CalculateConfigurationKeyHash(settings.ConfigurationKey, frame.Url); var api = contentLoader.LoadApi(browserExamKey, configurationKey, appConfig.ProgramBuildVersion); - var clipboard = contentLoader.LoadClipboard(); + var clipboardScript = contentLoader.LoadClipboard(); frame.ExecuteJavaScriptAsync(api); if (!settings.AllowPrint) { - frame.ExecuteJavaScriptAsync($"window.print = function(){{ alert('{text.Get(TextKey.Browser_PrintNotAllowed)}') }}"); + frame.ExecuteJavaScriptAsync($"window.print = function() {{ alert('{text.Get(TextKey.Browser_PrintNotAllowed)}') }}"); } if (settings.UseIsolatedClipboard) { - frame.ExecuteJavaScriptAsync(clipboard); + frame.ExecuteJavaScriptAsync(clipboardScript); + + if (clipboard.Content != default) + { + frame.ExecuteJavaScriptAsync($"SafeExamBrowser.clipboard.update('', '{clipboard.Content}');"); + } } }