SEBWIN-510: Changed initialization of JavaScript API.

This commit is contained in:
Damian Büchel 2022-07-22 15:38:07 +02:00
parent 1f5efc748d
commit b4e0493b31
14 changed files with 261 additions and 42 deletions

View file

@ -7,14 +7,9 @@
*/ */
using System; using System;
using System.Threading.Tasks;
using CefSharp; using CefSharp;
using SafeExamBrowser.Browser.Content;
using SafeExamBrowser.Browser.Wrapper; using SafeExamBrowser.Browser.Wrapper;
using SafeExamBrowser.Browser.Wrapper.Events; using SafeExamBrowser.Browser.Wrapper.Events;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Configuration.Contracts.Cryptography;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser;
using SafeExamBrowser.UserInterface.Contracts.Browser.Data; using SafeExamBrowser.UserInterface.Contracts.Browser.Data;
using SafeExamBrowser.UserInterface.Contracts.Browser.Events; using SafeExamBrowser.UserInterface.Contracts.Browser.Events;
@ -23,14 +18,12 @@ namespace SafeExamBrowser.Browser
{ {
internal class BrowserControl : IBrowserControl internal class BrowserControl : IBrowserControl
{ {
private readonly AppConfig appConfig;
private readonly ContentLoader contentLoader;
private readonly ICefSharpControl control; private readonly ICefSharpControl control;
private readonly IDialogHandler dialogHandler; private readonly IDialogHandler dialogHandler;
private readonly IDisplayHandler displayHandler; private readonly IDisplayHandler displayHandler;
private readonly IDownloadHandler downloadHandler; private readonly IDownloadHandler downloadHandler;
private readonly IKeyboardHandler keyboardHandler; private readonly IKeyboardHandler keyboardHandler;
private readonly IKeyGenerator generator; private readonly IRenderProcessMessageHandler renderProcessMessageHandler;
private readonly IRequestHandler requestHandler; private readonly IRequestHandler requestHandler;
public string Address => control.Address; public string Address => control.Address;
@ -44,24 +37,20 @@ namespace SafeExamBrowser.Browser
public event TitleChangedEventHandler TitleChanged; public event TitleChangedEventHandler TitleChanged;
public BrowserControl( public BrowserControl(
AppConfig appConfig,
ICefSharpControl control, ICefSharpControl control,
IDialogHandler dialogHandler, IDialogHandler dialogHandler,
IDisplayHandler displayHandler, IDisplayHandler displayHandler,
IDownloadHandler downloadHandler, IDownloadHandler downloadHandler,
IKeyboardHandler keyboardHandler, IKeyboardHandler keyboardHandler,
IKeyGenerator generator, IRenderProcessMessageHandler renderProcessMessageHandler,
IRequestHandler requestHandler, IRequestHandler requestHandler)
IText text)
{ {
this.appConfig = appConfig;
this.contentLoader = new ContentLoader(text);
this.control = control; this.control = control;
this.dialogHandler = dialogHandler; this.dialogHandler = dialogHandler;
this.displayHandler = displayHandler; this.displayHandler = displayHandler;
this.downloadHandler = downloadHandler; this.downloadHandler = downloadHandler;
this.keyboardHandler = keyboardHandler; this.keyboardHandler = keyboardHandler;
this.generator = generator; this.renderProcessMessageHandler = renderProcessMessageHandler;
this.requestHandler = requestHandler; this.requestHandler = requestHandler;
} }
@ -97,10 +86,12 @@ namespace SafeExamBrowser.Browser
control.BeforeBrowse += (w, b, f, r, u, i, a) => a.Value = requestHandler.OnBeforeBrowse(w, b, f, r, u, i); control.BeforeBrowse += (w, b, f, r, u, i, a) => a.Value = requestHandler.OnBeforeBrowse(w, b, f, r, u, i);
control.BeforeDownload += (w, b, d, c) => downloadHandler.OnBeforeDownload(w, b, d, c); control.BeforeDownload += (w, b, d, c) => downloadHandler.OnBeforeDownload(w, b, d, c);
control.CanDownload += (w, b, u, r, a) => a.Value = downloadHandler.CanDownload(w, b, u, r); control.CanDownload += (w, b, u, r, a) => a.Value = downloadHandler.CanDownload(w, b, u, r);
control.ContextCreated += (w, b, f) => renderProcessMessageHandler.OnContextCreated(w, b, f);
control.ContextReleased += (w, b, f) => renderProcessMessageHandler.OnContextReleased(w, b, f);
control.DownloadUpdated += (w, b, d, c) => downloadHandler.OnDownloadUpdated(w, b, d, c); control.DownloadUpdated += (w, b, d, c) => downloadHandler.OnDownloadUpdated(w, b, d, c);
control.FaviconUrlChanged += (w, b, u) => displayHandler.OnFaviconUrlChange(w, b, u); control.FaviconUrlChanged += (w, b, u) => displayHandler.OnFaviconUrlChange(w, b, u);
control.FileDialogRequested += (w, b, m, t, d, f, c) => dialogHandler.OnFileDialog(w, b, m, t, d, f, c); control.FileDialogRequested += (w, b, m, t, d, f, c) => dialogHandler.OnFileDialog(w, b, m, t, d, f, c);
control.FrameLoadStart += Control_FrameLoadStart; control.FocusedNodeChanged += (w, b, f, n) => renderProcessMessageHandler.OnFocusedNodeChanged(w, b, f, n);
control.IsBrowserInitializedChanged += Control_IsBrowserInitializedChanged; control.IsBrowserInitializedChanged += Control_IsBrowserInitializedChanged;
control.KeyEvent += (w, b, t, k, n, m, s) => keyboardHandler.OnKeyEvent(w, b, t, k, n, m, s); control.KeyEvent += (w, b, t, k, n, m, s) => keyboardHandler.OnKeyEvent(w, b, t, k, n, m, s);
control.LoadError += (o, e) => LoadFailed?.Invoke((int) e.ErrorCode, e.ErrorText, e.Frame.IsMain, e.FailedUrl); control.LoadError += (o, e) => LoadFailed?.Invoke((int) e.ErrorCode, e.ErrorText, e.Frame.IsMain, e.FailedUrl);
@ -110,6 +101,7 @@ namespace SafeExamBrowser.Browser
control.PreKeyEvent += (IWebBrowser w, IBrowser b, KeyType t, int k, int n, CefEventFlags m, bool i, ref bool s, GenericEventArgs a) => a.Value = keyboardHandler.OnPreKeyEvent(w, b, t, k, n, m, i, ref s); control.PreKeyEvent += (IWebBrowser w, IBrowser b, KeyType t, int k, int n, CefEventFlags m, bool i, ref bool s, GenericEventArgs a) => a.Value = keyboardHandler.OnPreKeyEvent(w, b, t, k, n, m, i, ref s);
control.ResourceRequestHandlerRequired += (IWebBrowser w, IBrowser b, IFrame f, IRequest r, bool n, bool d, string i, ref bool h, ResourceRequestEventArgs a) => a.Handler = requestHandler.GetResourceRequestHandler(w, b, f, r, n, d, i, ref h); control.ResourceRequestHandlerRequired += (IWebBrowser w, IBrowser b, IFrame f, IRequest r, bool n, bool d, string i, ref bool h, ResourceRequestEventArgs a) => a.Handler = requestHandler.GetResourceRequestHandler(w, b, f, r, n, d, i, ref h);
control.TitleChanged += (o, e) => TitleChanged?.Invoke(e.Title); control.TitleChanged += (o, e) => TitleChanged?.Invoke(e.Title);
control.UncaughtExceptionEvent += (w, b, f, e) => renderProcessMessageHandler.OnUncaughtException(w, b, f, e);
} }
public void NavigateBackwards() public void NavigateBackwards()
@ -142,18 +134,6 @@ namespace SafeExamBrowser.Browser
control.BrowserCore.SetZoomLevel(level); control.BrowserCore.SetZoomLevel(level);
} }
private void Control_FrameLoadStart(object sender, FrameLoadStartEventArgs e)
{
Task.Run(() =>
{
var browserExamKey = generator.CalculateBrowserExamKeyHash(e.Url);
var configurationKey = generator.CalculateConfigurationKeyHash(e.Url);
var api = contentLoader.LoadApi(browserExamKey, configurationKey, appConfig.ProgramBuildVersion);
e.Frame.ExecuteJavaScriptAsync(api);
});
}
private void Control_IsBrowserInitializedChanged(object sender, EventArgs e) private void Control_IsBrowserInitializedChanged(object sender, EventArgs e)
{ {
if (control.IsBrowserInitialized) if (control.IsBrowserInitialized)

View file

@ -145,12 +145,12 @@ namespace SafeExamBrowser.Browser
internal void InitializeControl() internal void InitializeControl()
{ {
var cefSharpControl = default(ICefSharpControl); var cefSharpControl = default(ICefSharpControl);
var contextMenuHandler = new ContextMenuHandler();
var dialogHandler = new DialogHandler(); var dialogHandler = new DialogHandler();
var displayHandler = new DisplayHandler(); var displayHandler = new DisplayHandler();
var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}"); var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
var downloadHandler = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings); var downloadHandler = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings);
var keyboardHandler = new KeyboardHandler(); var keyboardHandler = new KeyboardHandler();
var renderProcessMessageHandler = new RenderProcessMessageHandler(appConfig, keyGenerator, text);
var requestFilter = new RequestFilter(); var requestFilter = new RequestFilter();
var requestLogger = logger.CloneFor($"{nameof(RequestHandler)} #{Id}"); var requestLogger = logger.CloneFor($"{nameof(RequestHandler)} #{Id}");
var resourceHandler = new ResourceHandler(appConfig, requestFilter, keyGenerator, logger, settings, WindowSettings, text); var resourceHandler = new ResourceHandler(appConfig, requestFilter, keyGenerator, logger, settings, WindowSettings, text);
@ -187,16 +187,7 @@ namespace SafeExamBrowser.Browser
InitializeRequestFilter(requestFilter); InitializeRequestFilter(requestFilter);
Control = new BrowserControl( Control = new BrowserControl(cefSharpControl, dialogHandler, displayHandler, downloadHandler, keyboardHandler, renderProcessMessageHandler, requestHandler);
appConfig,
cefSharpControl,
dialogHandler,
displayHandler,
downloadHandler,
keyboardHandler,
keyGenerator,
requestHandler,
text);
Control.AddressChanged += Control_AddressChanged; Control.AddressChanged += Control_AddressChanged;
Control.LoadFailed += Control_LoadFailed; Control.LoadFailed += Control_LoadFailed;
Control.LoadingStateChanged += Control_LoadingStateChanged; Control.LoadingStateChanged += Control_LoadingStateChanged;

View file

@ -100,7 +100,7 @@ namespace SafeExamBrowser.Browser.Handlers
{ {
logger.Debug($"Download of '{downloadItem.FullPath}' {(downloadItem.IsComplete ? "is complete" : "was cancelled")}."); logger.Debug($"Download of '{downloadItem.FullPath}' {(downloadItem.IsComplete ? "is complete" : "was cancelled")}.");
if (callbacks.TryRemove(downloadItem.Id, out DownloadFinishedCallback finished) && finished != null) if (callbacks.TryRemove(downloadItem.Id, out var finished) && finished != null)
{ {
Task.Run(() => finished.Invoke(downloadItem.IsComplete, downloadItem.Url, downloadItem.FullPath)); Task.Run(() => finished.Invoke(downloadItem.IsComplete, downloadItem.Url, downloadItem.FullPath));
} }

View file

@ -0,0 +1,51 @@
/*
* 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/.
*/
using CefSharp;
using SafeExamBrowser.Browser.Content;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Configuration.Contracts.Cryptography;
using SafeExamBrowser.I18n.Contracts;
namespace SafeExamBrowser.Browser.Handlers
{
internal class RenderProcessMessageHandler : IRenderProcessMessageHandler
{
private readonly AppConfig appConfig;
private readonly ContentLoader contentLoader;
private readonly IKeyGenerator keyGenerator;
internal RenderProcessMessageHandler(AppConfig appConfig, IKeyGenerator keyGenerator, IText text)
{
this.appConfig = appConfig;
this.contentLoader = new ContentLoader(text);
this.keyGenerator = keyGenerator;
}
public void OnContextCreated(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
var browserExamKey = keyGenerator.CalculateBrowserExamKeyHash(frame.Url);
var configurationKey = keyGenerator.CalculateConfigurationKeyHash(frame.Url);
var api = contentLoader.LoadApi(browserExamKey, configurationKey, appConfig.ProgramBuildVersion);
frame.ExecuteJavaScriptAsync(api);
}
public void OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
}
public void OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
}
public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
}
}
}

View file

@ -38,7 +38,6 @@ namespace SafeExamBrowser.Browser.Handlers
private readonly IKeyGenerator keyGenerator; private readonly IKeyGenerator keyGenerator;
private readonly ILogger logger; private readonly ILogger logger;
private readonly BrowserSettings settings; private readonly BrowserSettings settings;
private readonly IText text;
private readonly WindowSettings windowSettings; private readonly WindowSettings windowSettings;
private IResourceHandler contentHandler; private IResourceHandler contentHandler;
@ -63,7 +62,6 @@ namespace SafeExamBrowser.Browser.Handlers
this.logger = logger; this.logger = logger;
this.settings = settings; this.settings = settings;
this.windowSettings = windowSettings; this.windowSettings = windowSettings;
this.text = text;
} }
protected override IResourceHandler GetResourceHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IRequest request) protected override IResourceHandler GetResourceHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IRequest request)

View file

@ -117,9 +117,12 @@
<Compile Include="Wrapper\Events\BeforeBrowseEventHandler.cs" /> <Compile Include="Wrapper\Events\BeforeBrowseEventHandler.cs" />
<Compile Include="Wrapper\Events\BeforeDownloadEventHandler.cs" /> <Compile Include="Wrapper\Events\BeforeDownloadEventHandler.cs" />
<Compile Include="Wrapper\Events\CanDownloadEventHandler.cs" /> <Compile Include="Wrapper\Events\CanDownloadEventHandler.cs" />
<Compile Include="Wrapper\Events\ContextCreatedEventHandler.cs" />
<Compile Include="Wrapper\Events\ContextReleasedEventHandler.cs" />
<Compile Include="Wrapper\Events\DownloadUpdatedEventHandler.cs" /> <Compile Include="Wrapper\Events\DownloadUpdatedEventHandler.cs" />
<Compile Include="Wrapper\Events\FaviconUrlChangedEventHandler.cs" /> <Compile Include="Wrapper\Events\FaviconUrlChangedEventHandler.cs" />
<Compile Include="Wrapper\Events\FileDialogRequestedEventHandler.cs" /> <Compile Include="Wrapper\Events\FileDialogRequestedEventHandler.cs" />
<Compile Include="Wrapper\Events\FocusedNodeChangedEventHandler.cs" />
<Compile Include="Wrapper\Events\KeyEventHandler.cs" /> <Compile Include="Wrapper\Events\KeyEventHandler.cs" />
<Compile Include="Wrapper\Events\LoadingProgressChangedEventHandler.cs" /> <Compile Include="Wrapper\Events\LoadingProgressChangedEventHandler.cs" />
<Compile Include="Wrapper\Events\GenericEventArgs.cs" /> <Compile Include="Wrapper\Events\GenericEventArgs.cs" />
@ -127,11 +130,13 @@
<Compile Include="Wrapper\Events\PreKeyEventHandler.cs" /> <Compile Include="Wrapper\Events\PreKeyEventHandler.cs" />
<Compile Include="Wrapper\Events\ResourceRequestEventArgs.cs" /> <Compile Include="Wrapper\Events\ResourceRequestEventArgs.cs" />
<Compile Include="Wrapper\Events\ResourceRequestEventHandler.cs" /> <Compile Include="Wrapper\Events\ResourceRequestEventHandler.cs" />
<Compile Include="Wrapper\Events\UncaughtExceptionEventHandler.cs" />
<Compile Include="Wrapper\Extensions.cs" /> <Compile Include="Wrapper\Extensions.cs" />
<Compile Include="Wrapper\Handlers\DialogHandlerSwitch.cs" /> <Compile Include="Wrapper\Handlers\DialogHandlerSwitch.cs" />
<Compile Include="Wrapper\Handlers\DisplayHandlerSwitch.cs" /> <Compile Include="Wrapper\Handlers\DisplayHandlerSwitch.cs" />
<Compile Include="Wrapper\Handlers\DownloadHandlerSwitch.cs" /> <Compile Include="Wrapper\Handlers\DownloadHandlerSwitch.cs" />
<Compile Include="Wrapper\Handlers\KeyboardHandlerSwitch.cs" /> <Compile Include="Wrapper\Handlers\KeyboardHandlerSwitch.cs" />
<Compile Include="Wrapper\Handlers\RenderProcessMessageHandlerSwitch.cs" />
<Compile Include="Wrapper\Handlers\RequestHandlerSwitch.cs" /> <Compile Include="Wrapper\Handlers\RequestHandlerSwitch.cs" />
<Compile Include="Wrapper\ICefSharpControl.cs" /> <Compile Include="Wrapper\ICefSharpControl.cs" />
</ItemGroup> </ItemGroup>

View file

@ -21,14 +21,18 @@ namespace SafeExamBrowser.Browser.Wrapper
public event BeforeBrowseEventHandler BeforeBrowse; public event BeforeBrowseEventHandler BeforeBrowse;
public event BeforeDownloadEventHandler BeforeDownload; public event BeforeDownloadEventHandler BeforeDownload;
public event CanDownloadEventHandler CanDownload; public event CanDownloadEventHandler CanDownload;
public event ContextCreatedEventHandler ContextCreated;
public event ContextReleasedEventHandler ContextReleased;
public event DownloadUpdatedEventHandler DownloadUpdated; public event DownloadUpdatedEventHandler DownloadUpdated;
public event FaviconUrlChangedEventHandler FaviconUrlChanged; public event FaviconUrlChangedEventHandler FaviconUrlChanged;
public event FileDialogRequestedEventHandler FileDialogRequested; public event FileDialogRequestedEventHandler FileDialogRequested;
public event FocusedNodeChangedEventHandler FocusedNodeChanged;
public event KeyEventHandler KeyEvent; public event KeyEventHandler KeyEvent;
public event LoadingProgressChangedEventHandler LoadingProgressChanged; public event LoadingProgressChangedEventHandler LoadingProgressChanged;
public event OpenUrlFromTabEventHandler OpenUrlFromTab; public event OpenUrlFromTabEventHandler OpenUrlFromTab;
public event PreKeyEventHandler PreKeyEvent; public event PreKeyEventHandler PreKeyEvent;
public event ResourceRequestEventHandler ResourceRequestHandlerRequired; public event ResourceRequestEventHandler ResourceRequestHandlerRequired;
public event UncaughtExceptionEventHandler UncaughtExceptionEvent;
public CefSharpBrowserControl(ILifeSpanHandler lifeSpanHandler, string url) : base(url) public CefSharpBrowserControl(ILifeSpanHandler lifeSpanHandler, string url) : base(url)
{ {
@ -38,6 +42,7 @@ namespace SafeExamBrowser.Browser.Wrapper
KeyboardHandler = new KeyboardHandlerSwitch(); KeyboardHandler = new KeyboardHandlerSwitch();
LifeSpanHandler = lifeSpanHandler; LifeSpanHandler = lifeSpanHandler;
MenuHandler = new ContextMenuHandler(); MenuHandler = new ContextMenuHandler();
RenderProcessMessageHandler = new RenderProcessMessageHandlerSwitch();
RequestHandler = new RequestHandlerSwitch(); RequestHandler = new RequestHandlerSwitch();
} }
@ -71,6 +76,16 @@ namespace SafeExamBrowser.Browser.Wrapper
CanDownload?.Invoke(webBrowser, browser, url, requestMethod, args); CanDownload?.Invoke(webBrowser, browser, url, requestMethod, args);
} }
public void OnContextCreated(IWebBrowser webBrowser, IBrowser browser, IFrame frame)
{
ContextCreated?.Invoke(webBrowser, browser, frame);
}
public void OnContextReleased(IWebBrowser webBrowser, IBrowser browser, IFrame frame)
{
ContextReleased?.Invoke(webBrowser, browser, frame);
}
public void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) public void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{ {
DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback); DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback);
@ -86,6 +101,11 @@ namespace SafeExamBrowser.Browser.Wrapper
FileDialogRequested?.Invoke(webBrowser, browser, mode, title, defaultFilePath, acceptFilters, callback); FileDialogRequested?.Invoke(webBrowser, browser, mode, title, defaultFilePath, acceptFilters, callback);
} }
public void OnFocusedNodeChanged(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
FocusedNodeChanged?.Invoke(webBrowser, browser, frame, node);
}
public void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) public void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{ {
KeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey); KeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey);
@ -105,5 +125,10 @@ namespace SafeExamBrowser.Browser.Wrapper
{ {
PreKeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey, ref isKeyboardShortcut, args); PreKeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey, ref isKeyboardShortcut, args);
} }
public void OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
UncaughtExceptionEvent?.Invoke(webBrowser, browser, frame, exception);
}
} }
} }

View file

@ -19,14 +19,18 @@ namespace SafeExamBrowser.Browser.Wrapper
public event BeforeBrowseEventHandler BeforeBrowse; public event BeforeBrowseEventHandler BeforeBrowse;
public event BeforeDownloadEventHandler BeforeDownload; public event BeforeDownloadEventHandler BeforeDownload;
public event CanDownloadEventHandler CanDownload; public event CanDownloadEventHandler CanDownload;
public event ContextCreatedEventHandler ContextCreated;
public event ContextReleasedEventHandler ContextReleased;
public event DownloadUpdatedEventHandler DownloadUpdated; public event DownloadUpdatedEventHandler DownloadUpdated;
public event FaviconUrlChangedEventHandler FaviconUrlChanged; public event FaviconUrlChangedEventHandler FaviconUrlChanged;
public event FileDialogRequestedEventHandler FileDialogRequested; public event FileDialogRequestedEventHandler FileDialogRequested;
public event FocusedNodeChangedEventHandler FocusedNodeChanged;
public event KeyEventHandler KeyEvent; public event KeyEventHandler KeyEvent;
public event LoadingProgressChangedEventHandler LoadingProgressChanged; public event LoadingProgressChangedEventHandler LoadingProgressChanged;
public event OpenUrlFromTabEventHandler OpenUrlFromTab; public event OpenUrlFromTabEventHandler OpenUrlFromTab;
public event PreKeyEventHandler PreKeyEvent; public event PreKeyEventHandler PreKeyEvent;
public event ResourceRequestEventHandler ResourceRequestHandlerRequired; public event ResourceRequestEventHandler ResourceRequestHandlerRequired;
public event UncaughtExceptionEventHandler UncaughtExceptionEvent;
void ICefSharpControl.Dispose(bool disposing) void ICefSharpControl.Dispose(bool disposing)
{ {
@ -66,6 +70,16 @@ namespace SafeExamBrowser.Browser.Wrapper
CanDownload?.Invoke(webBrowser, browser, url, requestMethod, args); CanDownload?.Invoke(webBrowser, browser, url, requestMethod, args);
} }
public void OnContextCreated(IWebBrowser webBrowser, IBrowser browser, IFrame frame)
{
ContextCreated?.Invoke(webBrowser, browser, frame);
}
public void OnContextReleased(IWebBrowser webBrowser, IBrowser browser, IFrame frame)
{
ContextReleased?.Invoke(webBrowser, browser, frame);
}
public void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) public void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{ {
DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback); DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback);
@ -81,6 +95,11 @@ namespace SafeExamBrowser.Browser.Wrapper
FileDialogRequested?.Invoke(webBrowser, browser, mode, title, defaultFilePath, acceptFilters, callback); FileDialogRequested?.Invoke(webBrowser, browser, mode, title, defaultFilePath, acceptFilters, callback);
} }
public void OnFocusedNodeChanged(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
FocusedNodeChanged?.Invoke(webBrowser, browser, frame, node);
}
public void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) public void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{ {
KeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey); KeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey);
@ -100,5 +119,10 @@ namespace SafeExamBrowser.Browser.Wrapper
{ {
PreKeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey, ref isKeyboardShortcut, args); PreKeyEvent?.Invoke(webBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey, ref isKeyboardShortcut, args);
} }
public void OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
UncaughtExceptionEvent?.Invoke(webBrowser, browser, frame, exception);
}
} }
} }

View file

@ -0,0 +1,14 @@
/*
* 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/.
*/
using CefSharp;
namespace SafeExamBrowser.Browser.Wrapper.Events
{
internal delegate void ContextCreatedEventHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame);
}

View file

@ -0,0 +1,14 @@
/*
* 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/.
*/
using CefSharp;
namespace SafeExamBrowser.Browser.Wrapper.Events
{
internal delegate void ContextReleasedEventHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame);
}

View file

@ -0,0 +1,14 @@
/*
* 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/.
*/
using CefSharp;
namespace SafeExamBrowser.Browser.Wrapper.Events
{
internal delegate void FocusedNodeChangedEventHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IDomNode node);
}

View file

@ -0,0 +1,14 @@
/*
* 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/.
*/
using CefSharp;
namespace SafeExamBrowser.Browser.Wrapper.Events
{
internal delegate void UncaughtExceptionEventHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception);
}

View file

@ -0,0 +1,81 @@
/*
* 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/.
*/
using CefSharp;
using CefSharp.WinForms;
using CefSharp.WinForms.Host;
namespace SafeExamBrowser.Browser.Wrapper.Handlers
{
internal class RenderProcessMessageHandlerSwitch : IRenderProcessMessageHandler
{
public void OnContextCreated(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
if (browser.IsPopup)
{
var control = ChromiumHostControl.FromBrowser(browser) as CefSharpPopupControl;
control?.OnContextCreated(chromiumWebBrowser, browser, frame);
}
else
{
var control = ChromiumWebBrowser.FromBrowser(browser) as CefSharpBrowserControl;
control?.OnContextCreated(chromiumWebBrowser, browser, frame);
}
}
public void OnContextReleased(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
{
if (browser.IsPopup)
{
var control = ChromiumHostControl.FromBrowser(browser) as CefSharpPopupControl;
control?.OnContextReleased(chromiumWebBrowser, browser, frame);
}
else
{
var control = ChromiumWebBrowser.FromBrowser(browser) as CefSharpBrowserControl;
control?.OnContextReleased(chromiumWebBrowser, browser, frame);
}
}
public void OnFocusedNodeChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IDomNode node)
{
if (browser.IsPopup)
{
var control = ChromiumHostControl.FromBrowser(browser) as CefSharpPopupControl;
control?.OnFocusedNodeChanged(chromiumWebBrowser, browser, frame, node);
}
else
{
var control = ChromiumWebBrowser.FromBrowser(browser) as CefSharpBrowserControl;
control?.OnFocusedNodeChanged(chromiumWebBrowser, browser, frame, node);
}
}
public void OnUncaughtException(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
{
if (browser.IsPopup)
{
var control = ChromiumHostControl.FromBrowser(browser) as CefSharpPopupControl;
control?.OnUncaughtException(chromiumWebBrowser, browser, frame, exception);
}
else
{
var control = ChromiumWebBrowser.FromBrowser(browser) as CefSharpBrowserControl;
control?.OnUncaughtException(chromiumWebBrowser, browser, frame, exception);
}
}
}
}

View file

@ -22,14 +22,18 @@ namespace SafeExamBrowser.Browser.Wrapper
event BeforeBrowseEventHandler BeforeBrowse; event BeforeBrowseEventHandler BeforeBrowse;
event BeforeDownloadEventHandler BeforeDownload; event BeforeDownloadEventHandler BeforeDownload;
event CanDownloadEventHandler CanDownload; event CanDownloadEventHandler CanDownload;
event ContextCreatedEventHandler ContextCreated;
event ContextReleasedEventHandler ContextReleased;
event DownloadUpdatedEventHandler DownloadUpdated; event DownloadUpdatedEventHandler DownloadUpdated;
event FaviconUrlChangedEventHandler FaviconUrlChanged; event FaviconUrlChangedEventHandler FaviconUrlChanged;
event FileDialogRequestedEventHandler FileDialogRequested; event FileDialogRequestedEventHandler FileDialogRequested;
event FocusedNodeChangedEventHandler FocusedNodeChanged;
event KeyEventHandler KeyEvent; event KeyEventHandler KeyEvent;
event LoadingProgressChangedEventHandler LoadingProgressChanged; event LoadingProgressChangedEventHandler LoadingProgressChanged;
event OpenUrlFromTabEventHandler OpenUrlFromTab; event OpenUrlFromTabEventHandler OpenUrlFromTab;
event PreKeyEventHandler PreKeyEvent; event PreKeyEventHandler PreKeyEvent;
event ResourceRequestEventHandler ResourceRequestHandlerRequired; event ResourceRequestEventHandler ResourceRequestHandlerRequired;
event UncaughtExceptionEventHandler UncaughtExceptionEvent;
void Dispose(bool disposing); void Dispose(bool disposing);
void GetAuthCredentials(IWebBrowser webBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback, GenericEventArgs args); void GetAuthCredentials(IWebBrowser webBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback, GenericEventArgs args);
@ -38,12 +42,16 @@ namespace SafeExamBrowser.Browser.Wrapper
void OnBeforeBrowse(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect, GenericEventArgs args); void OnBeforeBrowse(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect, GenericEventArgs args);
void OnBeforeDownload(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback); void OnBeforeDownload(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback);
void OnCanDownload(IWebBrowser webBrowser, IBrowser browser, string url, string requestMethod, GenericEventArgs args); void OnCanDownload(IWebBrowser webBrowser, IBrowser browser, string url, string requestMethod, GenericEventArgs args);
void OnContextCreated(IWebBrowser webBrowser, IBrowser browser, IFrame frame);
void OnContextReleased(IWebBrowser webBrowser, IBrowser browser, IFrame frame);
void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback); void OnDownloadUpdated(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback);
void OnFaviconUrlChange(IWebBrowser webBrowser, IBrowser browser, IList<string> urls); void OnFaviconUrlChange(IWebBrowser webBrowser, IBrowser browser, IList<string> urls);
void OnFileDialog(IWebBrowser webBrowser, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, IFileDialogCallback callback); void OnFileDialog(IWebBrowser webBrowser, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, IFileDialogCallback callback);
void OnFocusedNodeChanged(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IDomNode node);
void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey); void OnKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey);
void OnLoadingProgressChange(IWebBrowser webBrowser, IBrowser browser, double progress); void OnLoadingProgressChange(IWebBrowser webBrowser, IBrowser browser, double progress);
void OnOpenUrlFromTab(IWebBrowser webBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture, GenericEventArgs args); void OnOpenUrlFromTab(IWebBrowser webBrowser, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture, GenericEventArgs args);
void OnPreKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut, GenericEventArgs args); void OnPreKeyEvent(IWebBrowser webBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut, GenericEventArgs args);
void OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception);
} }
} }