From 6523c4ce42c211d58c4c86019bb248ee8e79a376 Mon Sep 17 00:00:00 2001 From: Christopher-Marcel Esser Date: Fri, 18 Nov 2022 11:00:45 +0100 Subject: [PATCH] Allow setting the host domain for loaded webview files. --- Source/SpiderEye.Core/Application.cs | 5 +++++ Source/SpiderEye.Linux/GtkWebview.cs | 5 ++++- Source/SpiderEye.Mac/CocoaWebview.cs | 5 ++++- Source/SpiderEye.Windows/EdgiumWebview.cs | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Source/SpiderEye.Core/Application.cs b/Source/SpiderEye.Core/Application.cs index 83d80647..048c7cc7 100644 --- a/Source/SpiderEye.Core/Application.cs +++ b/Source/SpiderEye.Core/Application.cs @@ -24,6 +24,11 @@ public static class Application /// public static WindowCollection OpenWindows { get; } + /// + /// Gets or sets the domain to use as the custom host when loading webview files. + /// + public static string? CustomHostDomain { get; set; } + /// /// Gets or sets the content provider for loading webview files. /// diff --git a/Source/SpiderEye.Linux/GtkWebview.cs b/Source/SpiderEye.Linux/GtkWebview.cs index 286f32ad..17a9b34c 100644 --- a/Source/SpiderEye.Linux/GtkWebview.cs +++ b/Source/SpiderEye.Linux/GtkWebview.cs @@ -59,7 +59,10 @@ static GtkWebview() UriSchemeCallbackDelegate = UriSchemeCallback; const string scheme = "spidereye"; - CustomHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); + CustomHost = new Uri( + Application.CustomHostDomain is string customHostDomain + ? $"{scheme}://{customHostDomain}" + : UriTools.GetRandomResourceUrl(scheme)); IntPtr context = WebKit.Context.GetDefault(); using GLibString gscheme = scheme; diff --git a/Source/SpiderEye.Mac/CocoaWebview.cs b/Source/SpiderEye.Mac/CocoaWebview.cs index 39f1ddc8..58ff12c7 100644 --- a/Source/SpiderEye.Mac/CocoaWebview.cs +++ b/Source/SpiderEye.Mac/CocoaWebview.cs @@ -65,7 +65,10 @@ public CocoaWebview(WebviewBridge bridge) schemeHandler = SchemeHandlerDefinition.CreateInstance(this); const string scheme = "spidereye"; - customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); + customHost = new Uri( + Application.CustomHostDomain is string customHostDomain + ? $"{scheme}://{customHostDomain}" + : UriTools.GetRandomResourceUrl(scheme)); ObjC.Call(configuration, "setURLSchemeHandler:forURLScheme:", schemeHandler.Handle, NSString.Create(scheme)); ObjC.Call(manager, "addScriptMessageHandler:name:", callbackClass.Handle, NSString.Create("external")); diff --git a/Source/SpiderEye.Windows/EdgiumWebview.cs b/Source/SpiderEye.Windows/EdgiumWebview.cs index a7c0f1ca..f634199e 100644 --- a/Source/SpiderEye.Windows/EdgiumWebview.cs +++ b/Source/SpiderEye.Windows/EdgiumWebview.cs @@ -49,7 +49,10 @@ public EdgiumWebview(WebviewBridge bridge) this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); const string scheme = "http"; - customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); + customHost = new Uri( + Application.CustomHostDomain is string customHostDomain + ? $"{scheme}://{customHostDomain}" + : UriTools.GetRandomResourceUrl(scheme)); webview = new WebView2(); webview.NavigationStarting += Webview_NavigationStarting;