SEBWIN-510: Changed initialization of JavaScript API.
This commit is contained in:
parent
1f5efc748d
commit
b4e0493b31
14 changed files with 261 additions and 42 deletions
|
@ -7,14 +7,9 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CefSharp;
|
||||
using SafeExamBrowser.Browser.Content;
|
||||
using SafeExamBrowser.Browser.Wrapper;
|
||||
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.Data;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Browser.Events;
|
||||
|
@ -23,14 +18,12 @@ namespace SafeExamBrowser.Browser
|
|||
{
|
||||
internal class BrowserControl : IBrowserControl
|
||||
{
|
||||
private readonly AppConfig appConfig;
|
||||
private readonly ContentLoader contentLoader;
|
||||
private readonly ICefSharpControl control;
|
||||
private readonly IDialogHandler dialogHandler;
|
||||
private readonly IDisplayHandler displayHandler;
|
||||
private readonly IDownloadHandler downloadHandler;
|
||||
private readonly IKeyboardHandler keyboardHandler;
|
||||
private readonly IKeyGenerator generator;
|
||||
private readonly IRenderProcessMessageHandler renderProcessMessageHandler;
|
||||
private readonly IRequestHandler requestHandler;
|
||||
|
||||
public string Address => control.Address;
|
||||
|
@ -44,24 +37,20 @@ namespace SafeExamBrowser.Browser
|
|||
public event TitleChangedEventHandler TitleChanged;
|
||||
|
||||
public BrowserControl(
|
||||
AppConfig appConfig,
|
||||
ICefSharpControl control,
|
||||
IDialogHandler dialogHandler,
|
||||
IDisplayHandler displayHandler,
|
||||
IDownloadHandler downloadHandler,
|
||||
IKeyboardHandler keyboardHandler,
|
||||
IKeyGenerator generator,
|
||||
IRequestHandler requestHandler,
|
||||
IText text)
|
||||
IRenderProcessMessageHandler renderProcessMessageHandler,
|
||||
IRequestHandler requestHandler)
|
||||
{
|
||||
this.appConfig = appConfig;
|
||||
this.contentLoader = new ContentLoader(text);
|
||||
this.control = control;
|
||||
this.dialogHandler = dialogHandler;
|
||||
this.displayHandler = displayHandler;
|
||||
this.downloadHandler = downloadHandler;
|
||||
this.keyboardHandler = keyboardHandler;
|
||||
this.generator = generator;
|
||||
this.renderProcessMessageHandler = renderProcessMessageHandler;
|
||||
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.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.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.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.FrameLoadStart += Control_FrameLoadStart;
|
||||
control.FocusedNodeChanged += (w, b, f, n) => renderProcessMessageHandler.OnFocusedNodeChanged(w, b, f, n);
|
||||
control.IsBrowserInitializedChanged += Control_IsBrowserInitializedChanged;
|
||||
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);
|
||||
|
@ -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.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.UncaughtExceptionEvent += (w, b, f, e) => renderProcessMessageHandler.OnUncaughtException(w, b, f, e);
|
||||
}
|
||||
|
||||
public void NavigateBackwards()
|
||||
|
@ -142,18 +134,6 @@ namespace SafeExamBrowser.Browser
|
|||
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)
|
||||
{
|
||||
if (control.IsBrowserInitialized)
|
||||
|
|
|
@ -145,12 +145,12 @@ namespace SafeExamBrowser.Browser
|
|||
internal void InitializeControl()
|
||||
{
|
||||
var cefSharpControl = default(ICefSharpControl);
|
||||
var contextMenuHandler = new ContextMenuHandler();
|
||||
var dialogHandler = new DialogHandler();
|
||||
var displayHandler = new DisplayHandler();
|
||||
var downloadLogger = logger.CloneFor($"{nameof(DownloadHandler)} #{Id}");
|
||||
var downloadHandler = new DownloadHandler(appConfig, downloadLogger, settings, WindowSettings);
|
||||
var keyboardHandler = new KeyboardHandler();
|
||||
var renderProcessMessageHandler = new RenderProcessMessageHandler(appConfig, keyGenerator, text);
|
||||
var requestFilter = new RequestFilter();
|
||||
var requestLogger = logger.CloneFor($"{nameof(RequestHandler)} #{Id}");
|
||||
var resourceHandler = new ResourceHandler(appConfig, requestFilter, keyGenerator, logger, settings, WindowSettings, text);
|
||||
|
@ -187,16 +187,7 @@ namespace SafeExamBrowser.Browser
|
|||
|
||||
InitializeRequestFilter(requestFilter);
|
||||
|
||||
Control = new BrowserControl(
|
||||
appConfig,
|
||||
cefSharpControl,
|
||||
dialogHandler,
|
||||
displayHandler,
|
||||
downloadHandler,
|
||||
keyboardHandler,
|
||||
keyGenerator,
|
||||
requestHandler,
|
||||
text);
|
||||
Control = new BrowserControl(cefSharpControl, dialogHandler, displayHandler, downloadHandler, keyboardHandler, renderProcessMessageHandler, requestHandler);
|
||||
Control.AddressChanged += Control_AddressChanged;
|
||||
Control.LoadFailed += Control_LoadFailed;
|
||||
Control.LoadingStateChanged += Control_LoadingStateChanged;
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace SafeExamBrowser.Browser.Handlers
|
|||
{
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,6 @@ namespace SafeExamBrowser.Browser.Handlers
|
|||
private readonly IKeyGenerator keyGenerator;
|
||||
private readonly ILogger logger;
|
||||
private readonly BrowserSettings settings;
|
||||
private readonly IText text;
|
||||
private readonly WindowSettings windowSettings;
|
||||
|
||||
private IResourceHandler contentHandler;
|
||||
|
@ -63,7 +62,6 @@ namespace SafeExamBrowser.Browser.Handlers
|
|||
this.logger = logger;
|
||||
this.settings = settings;
|
||||
this.windowSettings = windowSettings;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
protected override IResourceHandler GetResourceHandler(IWebBrowser webBrowser, IBrowser browser, IFrame frame, IRequest request)
|
||||
|
|
|
@ -117,9 +117,12 @@
|
|||
<Compile Include="Wrapper\Events\BeforeBrowseEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\BeforeDownloadEventHandler.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\FaviconUrlChangedEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\FileDialogRequestedEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\FocusedNodeChangedEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\KeyEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\LoadingProgressChangedEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\GenericEventArgs.cs" />
|
||||
|
@ -127,11 +130,13 @@
|
|||
<Compile Include="Wrapper\Events\PreKeyEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\ResourceRequestEventArgs.cs" />
|
||||
<Compile Include="Wrapper\Events\ResourceRequestEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Events\UncaughtExceptionEventHandler.cs" />
|
||||
<Compile Include="Wrapper\Extensions.cs" />
|
||||
<Compile Include="Wrapper\Handlers\DialogHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\Handlers\DisplayHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\Handlers\DownloadHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\Handlers\KeyboardHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\Handlers\RenderProcessMessageHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\Handlers\RequestHandlerSwitch.cs" />
|
||||
<Compile Include="Wrapper\ICefSharpControl.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -21,14 +21,18 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
public event BeforeBrowseEventHandler BeforeBrowse;
|
||||
public event BeforeDownloadEventHandler BeforeDownload;
|
||||
public event CanDownloadEventHandler CanDownload;
|
||||
public event ContextCreatedEventHandler ContextCreated;
|
||||
public event ContextReleasedEventHandler ContextReleased;
|
||||
public event DownloadUpdatedEventHandler DownloadUpdated;
|
||||
public event FaviconUrlChangedEventHandler FaviconUrlChanged;
|
||||
public event FileDialogRequestedEventHandler FileDialogRequested;
|
||||
public event FocusedNodeChangedEventHandler FocusedNodeChanged;
|
||||
public event KeyEventHandler KeyEvent;
|
||||
public event LoadingProgressChangedEventHandler LoadingProgressChanged;
|
||||
public event OpenUrlFromTabEventHandler OpenUrlFromTab;
|
||||
public event PreKeyEventHandler PreKeyEvent;
|
||||
public event ResourceRequestEventHandler ResourceRequestHandlerRequired;
|
||||
public event UncaughtExceptionEventHandler UncaughtExceptionEvent;
|
||||
|
||||
public CefSharpBrowserControl(ILifeSpanHandler lifeSpanHandler, string url) : base(url)
|
||||
{
|
||||
|
@ -38,6 +42,7 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
KeyboardHandler = new KeyboardHandlerSwitch();
|
||||
LifeSpanHandler = lifeSpanHandler;
|
||||
MenuHandler = new ContextMenuHandler();
|
||||
RenderProcessMessageHandler = new RenderProcessMessageHandlerSwitch();
|
||||
RequestHandler = new RequestHandlerSwitch();
|
||||
}
|
||||
|
||||
|
@ -71,6 +76,16 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
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)
|
||||
{
|
||||
DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback);
|
||||
|
@ -86,6 +101,11 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public void OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
|
||||
{
|
||||
UncaughtExceptionEvent?.Invoke(webBrowser, browser, frame, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,18 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
public event BeforeBrowseEventHandler BeforeBrowse;
|
||||
public event BeforeDownloadEventHandler BeforeDownload;
|
||||
public event CanDownloadEventHandler CanDownload;
|
||||
public event ContextCreatedEventHandler ContextCreated;
|
||||
public event ContextReleasedEventHandler ContextReleased;
|
||||
public event DownloadUpdatedEventHandler DownloadUpdated;
|
||||
public event FaviconUrlChangedEventHandler FaviconUrlChanged;
|
||||
public event FileDialogRequestedEventHandler FileDialogRequested;
|
||||
public event FocusedNodeChangedEventHandler FocusedNodeChanged;
|
||||
public event KeyEventHandler KeyEvent;
|
||||
public event LoadingProgressChangedEventHandler LoadingProgressChanged;
|
||||
public event OpenUrlFromTabEventHandler OpenUrlFromTab;
|
||||
public event PreKeyEventHandler PreKeyEvent;
|
||||
public event ResourceRequestEventHandler ResourceRequestHandlerRequired;
|
||||
public event UncaughtExceptionEventHandler UncaughtExceptionEvent;
|
||||
|
||||
void ICefSharpControl.Dispose(bool disposing)
|
||||
{
|
||||
|
@ -66,6 +70,16 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
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)
|
||||
{
|
||||
DownloadUpdated?.Invoke(webBrowser, browser, downloadItem, callback);
|
||||
|
@ -81,6 +95,11 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public void OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception)
|
||||
{
|
||||
UncaughtExceptionEvent?.Invoke(webBrowser, browser, frame, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,14 +22,18 @@ namespace SafeExamBrowser.Browser.Wrapper
|
|||
event BeforeBrowseEventHandler BeforeBrowse;
|
||||
event BeforeDownloadEventHandler BeforeDownload;
|
||||
event CanDownloadEventHandler CanDownload;
|
||||
event ContextCreatedEventHandler ContextCreated;
|
||||
event ContextReleasedEventHandler ContextReleased;
|
||||
event DownloadUpdatedEventHandler DownloadUpdated;
|
||||
event FaviconUrlChangedEventHandler FaviconUrlChanged;
|
||||
event FileDialogRequestedEventHandler FileDialogRequested;
|
||||
event FocusedNodeChangedEventHandler FocusedNodeChanged;
|
||||
event KeyEventHandler KeyEvent;
|
||||
event LoadingProgressChangedEventHandler LoadingProgressChanged;
|
||||
event OpenUrlFromTabEventHandler OpenUrlFromTab;
|
||||
event PreKeyEventHandler PreKeyEvent;
|
||||
event ResourceRequestEventHandler ResourceRequestHandlerRequired;
|
||||
event UncaughtExceptionEventHandler UncaughtExceptionEvent;
|
||||
|
||||
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);
|
||||
|
@ -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 OnBeforeDownload(IWebBrowser webBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback);
|
||||
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 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 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 OnLoadingProgressChange(IWebBrowser webBrowser, IBrowser browser, double progress);
|
||||
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 OnUncaughtException(IWebBrowser webBrowser, IBrowser browser, IFrame frame, JavascriptException exception);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue