diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index 563e41d1..8b416bdb 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -62,15 +62,16 @@ namespace SafeExamBrowser.Browser } } - public async void ExecuteJavascript(string javascript, Action callback) + public void ExecuteJavascript(string javascript, Action callback) { - var result = await control.EvaluateScriptAsync(javascript); - - callback(new JavascriptResult() + control.EvaluateScriptAsync(javascript).ContinueWith(t => { - Message = result.Message, - Result = result.Result, - Success = result.Success + callback(new JavascriptResult() + { + Message = t.Result.Message, + Result = t.Result.Result, + Success = t.Result.Success + }); }); } diff --git a/SafeExamBrowser.UserInterface.Contracts/Browser/Data/JavascriptResult.cs b/SafeExamBrowser.UserInterface.Contracts/Browser/Data/JavascriptResult.cs index 82459ff0..57cc15b3 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Browser/Data/JavascriptResult.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Browser/Data/JavascriptResult.cs @@ -1,29 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +/* + * Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET) + * + * 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/. + */ namespace SafeExamBrowser.UserInterface.Contracts.Browser.Data { /// - /// The data resulting from a Javascript expression evaluation. + /// The data resulting from a JavaScript expression evaluation. /// public class JavascriptResult { /// - /// Indicates if the Javascript was evaluated successfully or not. + /// Indicates if the JavaScript was evaluated successfully or not. /// public bool Success { get; set; } /// - /// The error message, in case of an unsuccessful evaluation of the Javascript expression. + /// The error message, in case of an unsuccessful evaluation of the JavaScript expression. /// public string Message { get; set; } /// - /// The data item returned by the Javascript expression. + /// The data item returned by the JavaScript expression. /// - public dynamic Result { get; set; } + public object Result { get; set; } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index ddf32010..b4d9833a 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -11,7 +11,6 @@ using System.ComponentModel; using System.Reflection; using System.Threading.Tasks; using System.Windows; -using System.Windows.Automation; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Interop; @@ -465,7 +464,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { - var forward = !this.browserControlGetsFocusFromTaskbar; + var forward = !browserControlGetsFocusFromTaskbar; // focus the first / last element on the page var javascript = @" @@ -481,7 +480,7 @@ if (typeof __SEB_focusElement === 'undefined') { setTimeout(function () { item && item.focus && item.focus(); }, 20); } }"; - this.browserControl.ExecuteJavascript(javascript, result => + browserControl.ExecuteJavascript(javascript, result => { if (!result.Success) { @@ -489,7 +488,7 @@ if (typeof __SEB_focusElement === 'undefined') { } }); - this.browserControl.ExecuteJavascript("__SEB_focusElement(" + forward.ToString().ToLower() + ")", result => + browserControl.ExecuteJavascript("__SEB_focusElement(" + forward.ToString().ToLower() + ")", result => { if (!result.Success) { diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs index e35aa756..426decae 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs @@ -459,7 +459,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { - var forward = !this.browserControlGetsFocusFromTaskbar; + var forward = !browserControlGetsFocusFromTaskbar; // focus the first / last element on the page var javascript = @" @@ -475,7 +475,7 @@ if (typeof __SEB_focusElement === 'undefined') { setTimeout(function () { item && item.focus && item.focus(); }, 20); } }"; - this.browserControl.ExecuteJavascript(javascript, result => + browserControl.ExecuteJavascript(javascript, result => { if (!result.Success) { @@ -483,7 +483,7 @@ if (typeof __SEB_focusElement === 'undefined') { } }); - this.browserControl.ExecuteJavascript("__SEB_focusElement(" + forward.ToString().ToLower() + ")", result => + browserControl.ExecuteJavascript("__SEB_focusElement(" + forward.ToString().ToLower() + ")", result => { if (!result.Success) {