From 45ec6d2da0ab26504ff8e434fc2542f3baa59b5e Mon Sep 17 00:00:00 2001 From: wixoa Date: Mon, 22 Apr 2024 23:46:34 -0400 Subject: [PATCH] Remove `usr://` custom scheme in BROWSER controls (#1760) --- OpenDreamClient/Interface/Controls/ControlBrowser.cs | 9 +++++---- OpenDreamClient/Interface/DreamInterfaceManager.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBrowser.cs b/OpenDreamClient/Interface/Controls/ControlBrowser.cs index ddc2e0c2ef..fb5f58fdb8 100644 --- a/OpenDreamClient/Interface/Controls/ControlBrowser.cs +++ b/OpenDreamClient/Interface/Controls/ControlBrowser.cs @@ -72,12 +72,13 @@ public override void Output(string value, string? jsFunction) { for (var i = 0; i < parts.Length; i++) { parts[i] = "\""+HttpUtility.JavaScriptStringEncode(HttpUtility.UrlDecode(parts[i]))+"\""; //wrap in quotes and encode for JS } + // Insert the values directly into JS and execute it (what could go wrong??) _webView.ExecuteJavaScript($"{jsFunction}({string.Join(",", parts)})"); } - public void SetFileSource(ResPath filepath, bool userData) { - _webView.Url = (userData ? "usr://127.0.0.1/" : "res://127.0.0.1/") + filepath; // hostname must be the localhost IP for TGUI to work properly + public void SetFileSource(ResPath filepath) { + _webView.Url = "http://127.0.0.1/" + filepath; // hostname must be the localhost IP for TGUI to work properly } private void BeforeBrowseHandler(IBeforeBrowseContext context) { @@ -108,7 +109,7 @@ private void BeforeBrowseHandler(IBeforeBrowseContext context) { private void RequestHandler(IRequestHandlerContext context) { Uri newUri = new Uri(context.Url); - if (newUri.Scheme == "usr") { + if (newUri is { Scheme: "http", Host: "127.0.0.1" }) { Stream stream; HttpStatusCode status; var path = new ResPath(newUri.AbsolutePath); @@ -119,7 +120,7 @@ private void RequestHandler(IRequestHandlerContext context) { stream = Stream.Null; status = HttpStatusCode.NotFound; } catch (Exception e) { - _sawmill.Error($"Exception while loading file from usr://:\n{e}"); + _sawmill.Error($"Exception while loading file from {newUri}:\n{e}"); stream = Stream.Null; status = HttpStatusCode.InternalServerError; } diff --git a/OpenDreamClient/Interface/DreamInterfaceManager.cs b/OpenDreamClient/Interface/DreamInterfaceManager.cs index 27ff8650ab..77d82ae850 100644 --- a/OpenDreamClient/Interface/DreamInterfaceManager.cs +++ b/OpenDreamClient/Interface/DreamInterfaceManager.cs @@ -222,7 +222,7 @@ private void RxBrowse(MsgBrowse pBrowse) { } var cacheFile = _dreamResource.CreateCacheFile(htmlFileName + ".html", pBrowse.HtmlSource); - outputBrowser.SetFileSource(cacheFile, true); + outputBrowser.SetFileSource(cacheFile); popup?.Open(); }