Skip to content

Commit

Permalink
SEBWIN-820, #764: Fixed missing content of isolated clipboard after n…
Browse files Browse the repository at this point in the history
…avigation or reload.
  • Loading branch information
dbuechel committed Mar 13, 2024
1 parent 4b222df commit 514414e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SafeExamBrowser.Browser/BrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions SafeExamBrowser.Browser/Handlers/RenderProcessMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}');");
}
}
}

Expand Down

0 comments on commit 514414e

Please sign in to comment.