This commit is contained in:
parent
b4e0493b31
commit
82e8166fd5
4 changed files with 26 additions and 24 deletions
|
@ -62,15 +62,16 @@ namespace SafeExamBrowser.Browser
|
|||
}
|
||||
}
|
||||
|
||||
public async void ExecuteJavascript(string javascript, Action<JavascriptResult> callback)
|
||||
public void ExecuteJavascript(string javascript, Action<JavascriptResult> callback)
|
||||
{
|
||||
control.EvaluateScriptAsync(javascript).ContinueWith(t =>
|
||||
{
|
||||
var result = await control.EvaluateScriptAsync(javascript);
|
||||
|
||||
callback(new JavascriptResult()
|
||||
{
|
||||
Message = result.Message,
|
||||
Result = result.Result,
|
||||
Success = result.Success
|
||||
Message = t.Result.Message,
|
||||
Result = t.Result.Result,
|
||||
Success = t.Result.Success
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// The data resulting from a Javascript expression evaluation.
|
||||
/// The data resulting from a JavaScript expression evaluation.
|
||||
/// </summary>
|
||||
public class JavascriptResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the Javascript was evaluated successfully or not.
|
||||
/// Indicates if the JavaScript was evaluated successfully or not.
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data item returned by the Javascript expression.
|
||||
/// The data item returned by the JavaScript expression.
|
||||
/// </summary>
|
||||
public dynamic Result { get; set; }
|
||||
public object Result { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue