From 391c4fa59dd2ca454c80034018270852dfa605a4 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 24 Oct 2019 18:41:56 +0200 Subject: [PATCH 1/4] WebView: Allow to load style sheet from jlink images Currently, loading a style sheet file using `WebView.getEngine().setUserStyleSheetLocation(url)` fails if the url start's with `jrt`, i.e. if the file is packaged in an application image using jlink. This is fixed with this PR. --- .../javafx.web/src/main/java/javafx/scene/web/WebEngine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java b/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java index bb2f583a6a0..cd9a0cd4031 100644 --- a/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java +++ b/modules/javafx.web/src/main/java/javafx/scene/web/WebEngine.java @@ -491,7 +491,7 @@ public final BooleanProperty javaScriptEnabledProperty() { * Location of the user stylesheet as a string URL. * *

This should be a local URL, i.e. either {@code 'data:'}, - * {@code 'file:'}, or {@code 'jar:'}. Remote URLs are not allowed + * {@code 'file:'}, {@code 'jar:'}, or {@code 'jrt:'}. Remote URLs are not allowed * for security reasons. * * @defaultValue null @@ -554,6 +554,7 @@ public final StringProperty userStyleSheetLocationProperty() { dataUrl = url; } else if (url.startsWith("file:") || url.startsWith("jar:") || + url.startsWith("jrt:") || url.startsWith("data:")) { try { From f58ddfca7c0b8f145e6530cc6786d47e9075f760 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 14 Apr 2020 15:11:33 +0200 Subject: [PATCH 2/4] Add test --- .../test/java/test/javafx/scene/web/MiscellaneousTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java index 4b69810cd86..0015c44c669 100644 --- a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java +++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java @@ -473,4 +473,8 @@ void waitForCompletion() { assertNull(getEngine().executeScript("window.xmlDoc.body")); }); } + + @Test public void loadJrtCssFileSuccessfully() { + getEngine().setUserStyleSheetLocation("jrt:/javafx.web/html/imported-styles.css"); + } } From 717dd939f5b4843cb2947ec409ba7f409f5f5751 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 2 Aug 2020 11:54:52 +0200 Subject: [PATCH 3/4] Remove whitespace --- .../src/test/java/test/javafx/scene/web/MiscellaneousTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java index 0015c44c669..509fb3a62c9 100644 --- a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java +++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java @@ -473,7 +473,7 @@ void waitForCompletion() { assertNull(getEngine().executeScript("window.xmlDoc.body")); }); } - + @Test public void loadJrtCssFileSuccessfully() { getEngine().setUserStyleSheetLocation("jrt:/javafx.web/html/imported-styles.css"); } From ad72fd630581fcc67d97c31864e925055c4ed5d6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 14 Aug 2020 08:15:38 +0200 Subject: [PATCH 4/4] Update MiscellaneousTest.java --- .../test/javafx/scene/web/MiscellaneousTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java index 509fb3a62c9..3e3ca2b3429 100644 --- a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java +++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java @@ -474,7 +474,17 @@ void waitForCompletion() { }); } - @Test public void loadJrtCssFileSuccessfully() { - getEngine().setUserStyleSheetLocation("jrt:/javafx.web/html/imported-styles.css"); + @Test public void jrtCssFileIsNotRejected() { + submit(() -> { + try { + getEngine().setUserStyleSheetLocation("jrt:/javafx.web/html/imported-styles.css"); + } catch (IllegalArgumentException e) { + // A jrt file is supposed to be a valid argument + throw new AssertionError(e); + } catch (RuntimeException e) { + // The css file cannot be loaded in the tests (since they are not modularized). + // We thus simply ignore this exception here + } + }); } }