From 85826289b91e7b4f31327ec5a96b21ac61348f0b Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Sat, 30 Nov 2024 16:08:12 -0800 Subject: [PATCH 1/2] Call MapTool.showDocument() on Swing thread for HTML5 --- .../maptool/client/ui/htmlframe/HTMLWebViewManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLWebViewManager.java b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLWebViewManager.java index 7f4becc55a..1e2fdbb421 100644 --- a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLWebViewManager.java +++ b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLWebViewManager.java @@ -585,8 +585,8 @@ private void fixHref(org.w3c.dom.events.Event event) { // Java bug JDK-8199014 workaround webEngine.executeScript(String.format(SCRIPT_ANCHOR, href.substring(1))); } else if (!href2.startsWith("javascript")) { - // non-macrolink, non-anchor link, non-javascript code - MapTool.showDocument(href); // show in usual browser + // non-macrolink, non-anchor link, non-javascript code. Show in usual browser + SwingUtilities.invokeLater(() -> MapTool.showDocument(href)); } event.preventDefault(); // don't change webview } From 9850edab542d6350e61fa91dba464921f5812485 Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Sat, 30 Nov 2024 16:08:54 -0800 Subject: [PATCH 2/2] Clean up and clarify MapTool.showDocument() - Mention the threading requirements in the docs - Check that the browse action is supported before we try to use it - Avoid needlessly reparsing the URI --- src/main/java/net/rptools/maptool/client/MapTool.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/MapTool.java b/src/main/java/net/rptools/maptool/client/MapTool.java index 91e8b01391..68e3cd98f3 100644 --- a/src/main/java/net/rptools/maptool/client/MapTool.java +++ b/src/main/java/net/rptools/maptool/client/MapTool.java @@ -480,11 +480,15 @@ public static BackupManager getBackupManager() { * be called from any uncontrolled macros as there are both security and denial-of-service attacks * possible. * + *

This should not be called from any uncontrolled macros as there are both security and + * denial-of-service attacks possible. + * + *

This must be called on the AWT thread. + * * @param url the URL to pass to the browser. */ public static void showDocument(String url) { - if (Desktop.isDesktopSupported()) { - String lowerCaseUrl = url.toLowerCase(); + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { String urlToBrowse = url; Desktop desktop = Desktop.getDesktop(); URI uri = null; @@ -492,8 +496,8 @@ public static void showDocument(String url) { uri = new URI(urlToBrowse); if (uri.getScheme() == null) { urlToBrowse = "https://" + urlToBrowse; + uri = new URI(urlToBrowse); } - uri = new URI(urlToBrowse); desktop.browse(uri); } catch (Exception e) { MapTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e);