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)
|
||||||
{
|
{
|
||||||
var result = await control.EvaluateScriptAsync(javascript);
|
control.EvaluateScriptAsync(javascript).ContinueWith(t =>
|
||||||
|
|
||||||
callback(new JavascriptResult()
|
|
||||||
{
|
{
|
||||||
Message = result.Message,
|
callback(new JavascriptResult()
|
||||||
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;
|
* Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET)
|
||||||
using System.Linq;
|
*
|
||||||
using System.Text;
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
using System.Threading.Tasks;
|
* 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
|
namespace SafeExamBrowser.UserInterface.Contracts.Browser.Data
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The data resulting from a Javascript expression evaluation.
|
/// The data resulting from a JavaScript expression evaluation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JavascriptResult
|
public class JavascriptResult
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if the Javascript was evaluated successfully or not.
|
/// Indicates if the JavaScript was evaluated successfully or not.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Success { get; set; }
|
public bool Success { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The data item returned by the Javascript expression.
|
/// The data item returned by the JavaScript expression.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public dynamic Result { get; set; }
|
public object Result { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ using System.ComponentModel;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Automation;
|
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
|
@ -465,7 +464,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows
|
||||||
|
|
||||||
private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var forward = !this.browserControlGetsFocusFromTaskbar;
|
var forward = !browserControlGetsFocusFromTaskbar;
|
||||||
|
|
||||||
// focus the first / last element on the page
|
// focus the first / last element on the page
|
||||||
var javascript = @"
|
var javascript = @"
|
||||||
|
@ -481,7 +480,7 @@ if (typeof __SEB_focusElement === 'undefined') {
|
||||||
setTimeout(function () { item && item.focus && item.focus(); }, 20);
|
setTimeout(function () { item && item.focus && item.focus(); }, 20);
|
||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
this.browserControl.ExecuteJavascript(javascript, result =>
|
browserControl.ExecuteJavascript(javascript, result =>
|
||||||
{
|
{
|
||||||
if (!result.Success)
|
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)
|
if (!result.Success)
|
||||||
{
|
{
|
||||||
|
|
|
@ -459,7 +459,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows
|
||||||
|
|
||||||
private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var forward = !this.browserControlGetsFocusFromTaskbar;
|
var forward = !browserControlGetsFocusFromTaskbar;
|
||||||
|
|
||||||
// focus the first / last element on the page
|
// focus the first / last element on the page
|
||||||
var javascript = @"
|
var javascript = @"
|
||||||
|
@ -475,7 +475,7 @@ if (typeof __SEB_focusElement === 'undefined') {
|
||||||
setTimeout(function () { item && item.focus && item.focus(); }, 20);
|
setTimeout(function () { item && item.focus && item.focus(); }, 20);
|
||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
this.browserControl.ExecuteJavascript(javascript, result =>
|
browserControl.ExecuteJavascript(javascript, result =>
|
||||||
{
|
{
|
||||||
if (!result.Success)
|
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)
|
if (!result.Success)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue