Skip to content

Commit 15e52d8

Browse files
committed
8253696: WebEngine refuses to load local "file:///" CSS stylesheets when using JDK 15
Reviewed-by: kcr
1 parent 5b42b64 commit 15e52d8

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

modules/javafx.web/src/main/java/com/sun/webkit/network/URLLoader.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -867,13 +867,15 @@ private static long extractContentLength(URLConnection c) {
867867
*/
868868
private static String extractHeaders(URLConnection c) {
869869
StringBuilder sb = new StringBuilder();
870-
Map<String, List<String>> headers = c.getHeaderFields();
871-
for (Map.Entry<String, List<String>> entry: headers.entrySet()) {
872-
String key = entry.getKey();
873-
List<String> values = entry.getValue();
874-
for (String value : values) {
875-
sb.append(key != null ? key : "");
876-
sb.append(':').append(value).append('\n');
870+
if (c instanceof HttpURLConnection) {
871+
Map<String, List<String>> headers = c.getHeaderFields();
872+
for (Map.Entry<String, List<String>> entry: headers.entrySet()) {
873+
String key = entry.getKey();
874+
List<String> values = entry.getValue();
875+
for (String value : values) {
876+
sb.append(key != null ? key : "");
877+
sb.append(':').append(value).append('\n');
878+
}
877879
}
878880
}
879881
return sb.toString();

modules/javafx.web/src/test/java/test/javafx/scene/web/LoadTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -192,6 +192,16 @@ private void testLoadEmpty(String url) {
192192
assertNotNull("Document is null", webEngine.getDocument());
193193
}
194194

195+
@Test public void testLoadLocalCSS() {
196+
load(new File("src/test/resources/test/html/dom.html"));
197+
submit(() -> {
198+
assertEquals("Font weight should be bold", "bold", (String) getEngine().executeScript(
199+
"window.getComputedStyle(document.getElementById('p3')).getPropertyValue('font-weight')"));
200+
assertEquals("font style should be italic", "italic", (String) getEngine().executeScript(
201+
"window.getComputedStyle(document.getElementById('p3')).getPropertyValue('font-style')"));
202+
});
203+
}
204+
195205
/**
196206
* @test
197207
* @bug 8140501

modules/javafx.web/src/test/resources/test/html/dom.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<p id="p1">Things <b>do</b> change</p>
3232
<p id="p2">Again <i>and</i> again</p>
3333

34+
<!-- used by testLoadLocalCSS -->
35+
<p id="p3" class="head2">Sample Text</p>
36+
3437
<!-- used by testNodeTypes -->
3538
<p id="showcase-paragraph">
3639
text<!--comment--><span class="spanclass">spantext</span></p>

0 commit comments

Comments
 (0)