From 3d15a3065c272d79011f99f77c1bdd0d8801e290 Mon Sep 17 00:00:00 2001 From: Andy Goryachev Date: Wed, 6 Nov 2024 15:42:27 +0000 Subject: [PATCH] 8342460: Remove calls to doPrivileged in javafx.web Reviewed-by: kcr, arapte --- .../com/sun/javafx/webkit/UIClientImpl.java | 28 ++---- .../sun/javafx/webkit/WebPageClientImpl.java | 10 +-- .../webkit/prism/WCGraphicsPrismContext.java | 10 +-- .../main/java/com/sun/webkit/Disposer.java | 35 ++++---- .../java/com/sun/webkit/MethodHelper.java | 9 +- .../src/main/java/com/sun/webkit/Timer.java | 10 +-- .../main/java/com/sun/webkit/Utilities.java | 17 +--- .../src/main/java/com/sun/webkit/WebPage.java | 89 +++++++------------ .../com/sun/webkit/network/CookieJar.java | 12 +-- .../com/sun/webkit/network/HTTP2Loader.java | 25 ++---- .../sun/webkit/network/NetworkContext.java | 47 +++------- .../sun/webkit/network/PublicSuffixes.java | 52 +++++------ .../webkit/network/SocketStreamHandle.java | 15 +--- .../com/sun/webkit/network/URLLoader.java | 20 +---- .../java/com/sun/webkit/network/URLs.java | 29 +----- .../java/javafx/scene/web/HTMLEditorSkin.java | 16 ++-- .../main/java/javafx/scene/web/WebEngine.java | 11 +-- 17 files changed, 117 insertions(+), 318 deletions(-) diff --git a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java index 39c68d44472..60591abfe63 100644 --- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java +++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,9 +41,6 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -111,31 +108,20 @@ private WebEngine getWebEngine() { return accessor.getEngine(); } - @SuppressWarnings("removal") - private AccessControlContext getAccessContext() { - return accessor.getPage().getAccessControlContext(); - } - @Override public WebPage createPage( boolean menu, boolean status, boolean toolbar, boolean resizable) { final WebEngine w = getWebEngine(); if (w != null && w.getCreatePopupHandler() != null) { final PopupFeatures pf = new PopupFeatures(menu, status, toolbar, resizable); - @SuppressWarnings("removal") - WebEngine popup = AccessController.doPrivileged( - (PrivilegedAction) () -> w.getCreatePopupHandler().call(pf), getAccessContext()); + WebEngine popup = w.getCreatePopupHandler().call(pf); return Accessor.getPageFor(popup); } return null; } - @SuppressWarnings("removal") private void dispatchWebEvent(final EventHandler handler, final WebEvent ev) { - AccessController.doPrivileged((PrivilegedAction) () -> { - handler.handle(ev); - return null; - }, getAccessContext()); + handler.handle(ev); } private void notifyVisibilityChanged(boolean visible) { @@ -197,23 +183,19 @@ private void notifyVisibilityChanged(boolean visible) { } } - @SuppressWarnings("removal") @Override public boolean confirm(final String text) { final WebEngine w = getWebEngine(); if (w != null && w.getConfirmHandler() != null) { - return AccessController.doPrivileged( - (PrivilegedAction) () -> w.getConfirmHandler().call(text), getAccessContext()); + return w.getConfirmHandler().call(text); } return false; } - @SuppressWarnings("removal") @Override public String prompt(String text, String defaultValue) { final WebEngine w = getWebEngine(); if (w != null && w.getPromptHandler() != null) { final PromptData data = new PromptData(text, defaultValue); - return AccessController.doPrivileged( - (PrivilegedAction) () -> w.getPromptHandler().call(data), getAccessContext()); + return w.getPromptHandler().call(data); } return ""; } diff --git a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/WebPageClientImpl.java b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/WebPageClientImpl.java index f71117b9079..e3ce6edb21d 100644 --- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/WebPageClientImpl.java +++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/WebPageClientImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,8 +27,6 @@ import com.sun.javafx.scene.NodeHelper; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import com.sun.javafx.scene.traversal.Direction; import com.sun.javafx.scene.traversal.TraversalMethod; @@ -50,10 +48,8 @@ import com.sun.webkit.graphics.WCRectangle; public final class WebPageClientImpl implements WebPageClient { - @SuppressWarnings("removal") - private static final boolean backBufferSupported = Boolean.valueOf( - AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty( - "com.sun.webkit.pagebackbuffer", "true"))); + private static final boolean backBufferSupported = + Boolean.valueOf(System.getProperty("com.sun.webkit.pagebackbuffer", "true")); private static WebConsoleListener consoleListener = null; private final Accessor accessor; diff --git a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java index 20118b72212..9f9a149040c 100644 --- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java +++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCGraphicsPrismContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,8 +53,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; @@ -81,10 +79,8 @@ public enum Type { private final static PlatformLogger log = PlatformLogger.getLogger(WCGraphicsPrismContext.class.getName()); - @SuppressWarnings("removal") - private final static boolean DEBUG_DRAW_CLIP_SHAPE = Boolean.valueOf( - AccessController.doPrivileged((PrivilegedAction) () -> - System.getProperty("com.sun.webkit.debugDrawClipShape", "false"))); + private final static boolean DEBUG_DRAW_CLIP_SHAPE = + Boolean.valueOf(System.getProperty("com.sun.webkit.debugDrawClipShape", "false")); Graphics baseGraphics; private BaseTransform baseTransform; diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/Disposer.java b/modules/javafx.web/src/main/java/com/sun/webkit/Disposer.java index 94cb67ce4a2..d09048dcb5e 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/Disposer.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/Disposer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,6 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -59,24 +58,20 @@ public final class Disposer implements Runnable { new HashSet<>(); static { - @SuppressWarnings("removal") - var dummy = java.security.AccessController.doPrivileged((PrivilegedAction) () -> { - /* - * The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup tg = Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - - Thread t = new Thread(tg, disposerInstance, "Disposer"); - t.setDaemon(true); - t.setPriority(Thread.MAX_PRIORITY); - t.start(); - return null; - }); + /* + * The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + for (ThreadGroup tgn = tg; + tgn != null; + tg = tgn, tgn = tg.getParent()); + + Thread t = new Thread(tg, disposerInstance, "Disposer"); + t.setDaemon(true); + t.setPriority(Thread.MAX_PRIORITY); + t.start(); } /** diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/MethodHelper.java b/modules/javafx.web/src/main/java/com/sun/webkit/MethodHelper.java index 98c4bc9b648..c630d20b4f7 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/MethodHelper.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/MethodHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,18 +28,13 @@ import com.sun.javafx.reflect.MethodUtil; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; import com.sun.javafx.reflect.ReflectUtil; /** * Utility class to wrap method invocation. */ public class MethodHelper { - @SuppressWarnings("removal") - private static final boolean logAccessErrors - = AccessController.doPrivileged((PrivilegedAction) () - -> Boolean.getBoolean("sun.reflect.debugModuleAccessChecks")); + private static final boolean logAccessErrors = Boolean.getBoolean("sun.reflect.debugModuleAccessChecks"); private static final Module trampolineModule = MethodUtil.getTrampolineModule(); diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/Timer.java b/modules/javafx.web/src/main/java/com/sun/webkit/Timer.java index 9e0e1a9b180..84d66e3696a 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/Timer.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/Timer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,9 +25,6 @@ package com.sun.webkit; -import java.security.AccessController; -import java.security.PrivilegedAction; - public class Timer { private static Timer instance; private static Mode mode; @@ -42,12 +39,9 @@ public static enum Mode { SEPARATE_THREAD } - @SuppressWarnings("removal") public synchronized static Mode getMode() { if (mode == null) { - mode = Boolean.valueOf(AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty( - "com.sun.webkit.platformticks", "true"))) ? Mode.PLATFORM_TICKS : Mode.SEPARATE_THREAD; + mode = Boolean.valueOf(System.getProperty("com.sun.webkit.platformticks", "true")) ? Mode.PLATFORM_TICKS : Mode.SEPARATE_THREAD; } return mode; } diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/Utilities.java b/modules/javafx.web/src/main/java/com/sun/webkit/Utilities.java index 6d4e7251554..9684bf76882 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/Utilities.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/Utilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,9 +28,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.List; import java.util.Set; @@ -120,16 +117,10 @@ private static Object fwkInvokeWithContext(final Method method, } try { - return AccessController.doPrivileged((PrivilegedExceptionAction) - () -> MethodHelper.invoke(method, instance, args), acc); - } catch (PrivilegedActionException ex) { + return MethodHelper.invoke(method, instance, args); + } catch (InvocationTargetException ex) { Throwable cause = ex.getCause(); - if (cause == null) - cause = ex; - else if (cause instanceof InvocationTargetException - && cause.getCause() != null) - cause = cause.getCause(); - throw cause; + throw cause != null ? cause : ex; } } } diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java b/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java index 08a13eae893..4613e6b085f 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,9 +45,6 @@ import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -103,10 +100,6 @@ public final class WebPage { // List of created frames private final Set frames = new HashSet<>(); - // The access control context associated with this object - @SuppressWarnings("removal") - private final AccessControlContext accessControlContext; - // Maps load request identifiers to URLs private final Map requestURLs = new HashMap<>(); @@ -134,48 +127,42 @@ public final class WebPage { private int updateContentCycleID; static { - @SuppressWarnings("removal") - var dummy = AccessController.doPrivileged((PrivilegedAction) () -> { - NativeLibLoader.loadLibrary("jfxwebkit"); - log.finer("jfxwebkit loaded"); - - if (CookieHandler.getDefault() == null) { - boolean setDefault = Boolean.valueOf(System.getProperty( - "com.sun.webkit.setDefaultCookieHandler", - "true")); - if (setDefault) { - CookieHandler.setDefault(new CookieManager()); - } - } - - final boolean useJIT = Boolean.valueOf(System.getProperty( - "com.sun.webkit.useJIT", "true")); - final boolean useDFGJIT = Boolean.valueOf(System.getProperty( - "com.sun.webkit.useDFGJIT", "false")); + NativeLibLoader.loadLibrary("jfxwebkit"); + log.finer("jfxwebkit loaded"); - // TODO: Enable CSS3D by default once it is stabilized. - boolean useCSS3D = Boolean.valueOf(System.getProperty( - "com.sun.webkit.useCSS3D", "false")); - useCSS3D = useCSS3D && Platform.isSupported(ConditionalFeature.SCENE3D); + if (CookieHandler.getDefault() == null) { + boolean setDefault = Boolean.valueOf(System.getProperty( + "com.sun.webkit.setDefaultCookieHandler", + "true")); + if (setDefault) { + CookieHandler.setDefault(new CookieManager()); + } + } - // Initialize WTF, WebCore and JavaScriptCore. - twkInitWebCore(useJIT, useDFGJIT, useCSS3D); + final boolean useJIT = Boolean.valueOf(System.getProperty( + "com.sun.webkit.useJIT", "true")); + final boolean useDFGJIT = Boolean.valueOf(System.getProperty( + "com.sun.webkit.useDFGJIT", "false")); - // Inform the native webkit code when either the JVM or the - // JavaFX runtime is being shutdown - final Runnable shutdownHook = () -> { - synchronized(WebPage.class) { - MainThread.twkSetShutdown(true); - } - }; + // TODO: Enable CSS3D by default once it is stabilized. + boolean useCSS3D = Boolean.valueOf(System.getProperty( + "com.sun.webkit.useCSS3D", "false")); + useCSS3D = useCSS3D && Platform.isSupported(ConditionalFeature.SCENE3D); - // Register shutdown hook with the Java runtime and the Toolkit - Toolkit.getToolkit().addShutdownHook(shutdownHook); - Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook)); + // Initialize WTF, WebCore and JavaScriptCore. + twkInitWebCore(useJIT, useDFGJIT, useCSS3D); - return null; - }); + // Inform the native webkit code when either the JVM or the + // JavaFX runtime is being shutdown + final Runnable shutdownHook = () -> { + synchronized(WebPage.class) { + MainThread.twkSetShutdown(true); + } + }; + // Register shutdown hook with the Java runtime and the Toolkit + Toolkit.getToolkit().addShutdownHook(shutdownHook); + Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook)); } private static boolean firstWebPageCreated = false; @@ -210,10 +197,6 @@ public WebPage(WebPageClient pageClient, this.scrollbarTheme = null; } - @SuppressWarnings("removal") - AccessControlContext tmpAcc = AccessController.getContext(); - accessControlContext = tmpAcc; - hostWindow = new WCFrameView(this); pPage = twkCreatePage(editable); @@ -241,16 +224,6 @@ private WCWidget getHostWindow() { return hostWindow; } - /** - * Returns the access control context associated with this object. - * May be called on any thread. - * @return the access control context associated with this object - */ - @SuppressWarnings("removal") - public AccessControlContext getAccessControlContext() { - return accessControlContext; - } - static boolean lockPage() { return Invoker.getInvoker().lock(PAGE_LOCK); } diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/CookieJar.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/CookieJar.java index 82e54fb4a50..f0d9ea71103 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/CookieJar.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/CookieJar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,6 @@ import java.net.CookieHandler; import java.net.URI; import java.net.URISyntaxException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -42,9 +40,7 @@ private CookieJar() { } private static void fwkPut(String url, String cookie) { - @SuppressWarnings("removal") - CookieHandler handler = - AccessController.doPrivileged((PrivilegedAction) CookieHandler::getDefault); + CookieHandler handler = CookieHandler.getDefault(); if (handler != null) { URI uri = null; try { @@ -66,9 +62,7 @@ private static void fwkPut(String url, String cookie) { } private static String fwkGet(String url, boolean includeHttpOnlyCookies) { - @SuppressWarnings("removal") - CookieHandler handler = - AccessController.doPrivileged((PrivilegedAction) CookieHandler::getDefault); + CookieHandler handler = CookieHandler.getDefault(); if (handler != null) { URI uri = null; try { diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/HTTP2Loader.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/HTTP2Loader.java index 4e1bec56985..bcce0610f7a 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/HTTP2Loader.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/HTTP2Loader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,9 +51,6 @@ import java.net.http.HttpResponse; import java.net.http.HttpTimeoutException; import java.nio.ByteBuffer; -import java.security.AccessControlException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.time.Duration; import java.util.Arrays; import java.util.List; @@ -90,23 +87,18 @@ final class HTTP2Loader extends URLLoaderBase { private final CompletableFuture response; // Use singleton instance of HttpClient to get the maximum benefits - @SuppressWarnings("removal") - private final static HttpClient HTTP_CLIENT = - AccessController.doPrivileged((PrivilegedAction) () -> HttpClient.newBuilder() + private final static HttpClient HTTP_CLIENT = HttpClient.newBuilder() .version(Version.HTTP_2) // this is the default .followRedirects(Redirect.NEVER) // WebCore handles redirection .connectTimeout(Duration.ofSeconds(30)) // FIXME: Add a property to control the timeout .cookieHandler(CookieHandler.getDefault()) - .build()); + .build(); // Singleton instance of direct ByteBuffer to transfer downloaded bytes from // Java to native private static final int DEFAULT_BUFSIZE = 40 * 1024; private final static ByteBuffer BUFFER; static { - @SuppressWarnings("removal") - int bufSize = AccessController.doPrivileged( - (PrivilegedAction) () -> - Integer.valueOf(System.getProperty("jdk.httpclient.bufsize", Integer.toString(DEFAULT_BUFSIZE)))); + int bufSize = Integer.valueOf(System.getProperty("jdk.httpclient.bufsize", Integer.toString(DEFAULT_BUFSIZE))); BUFFER = ByteBuffer.allocateDirect(bufSize); } @@ -398,14 +390,9 @@ private HTTP2Loader(WebPage webPage, return getBodySubscriber(getContentEncoding(rsp)); }; - // Run the HttpClient in the page's access control context - @SuppressWarnings("removal") - var tmpResponse = AccessController.doPrivileged((PrivilegedAction>) () -> { - return HTTP_CLIENT.sendAsync(request, bodyHandler) + this.response = HTTP_CLIENT.sendAsync(request, bodyHandler) .thenAccept($ -> {}) .exceptionally(ex -> didFail(ex.getCause())); - }, webPage.getAccessControlContext()); - this.response = tmpResponse; if (!asynchronous) { waitForRequestToComplete(); @@ -576,8 +563,6 @@ private Void didFail(final Throwable th) { throw th; } catch (MalformedURLException ex) { errorCode = LoadListenerClient.MALFORMED_URL; - } catch (@SuppressWarnings("removal") AccessControlException ex) { - errorCode = LoadListenerClient.PERMISSION_DENIED; } catch (UnknownHostException ex) { errorCode = LoadListenerClient.UNKNOWN_HOST; } catch (NoRouteToHostException ex) { diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/NetworkContext.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/NetworkContext.java index 696cf73c444..2a087e0ffbd 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/NetworkContext.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/NetworkContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,8 +28,6 @@ import static com.sun.webkit.network.URLs.newURL; import java.net.MalformedURLException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; @@ -92,14 +90,10 @@ final class NetworkContext { new URLLoaderThreadFactory()); threadPool.allowCoreThreadTimeOut(true); - @SuppressWarnings("removal") - boolean tmp = AccessController.doPrivileged((PrivilegedAction) () -> { - // Use HTTP2 by default on JDK 12 or later - final var version = Runtime.Version.parse(System.getProperty("java.version")); - final String defaultUseHTTP2 = version.feature() >= 12 ? "true" : "false"; - return Boolean.valueOf(System.getProperty("com.sun.webkit.useHTTP2Loader", defaultUseHTTP2)); - }); - useHTTP2Loader = tmp; + // Use HTTP2 by default on JDK 12 or later + final var version = Runtime.Version.parse(System.getProperty("java.version")); + final String defaultUseHTTP2 = version.feature() >= 12 ? "true" : "false"; + useHTTP2Loader = Boolean.valueOf(System.getProperty("com.sun.webkit.useHTTP2Loader", defaultUseHTTP2)); } /** @@ -218,9 +212,7 @@ private static int fwkGetMaximumHTTPConnectionCountPerHost() { // Our implementation employs HttpURLConnection for all // HTTP exchanges, so return the value of the "http.maxConnections" // system property. - @SuppressWarnings("removal") - int propValue = AccessController.doPrivileged( - (PrivilegedAction) () -> Integer.getInteger("http.maxConnections", -1)); + int propValue = Integer.getInteger("http.maxConnections", -1); if (useHTTP2Loader) { return propValue >= 0 ? propValue : DEFAULT_HTTP2_MAX_CONNECTIONS; @@ -235,13 +227,6 @@ private static final class URLLoaderThreadFactory implements ThreadFactory { private final ThreadGroup group; private final AtomicInteger index = new AtomicInteger(1); - // Need to assert the modifyThread and modifyThreadGroup permission when - // creating the thread from the URLLoaderThreadFactory, so we can - // create the thread with the desired ThreadGroup. - // Note that this is needed when running with a security manager - private static final Permission modifyThreadGroupPerm = new RuntimePermission("modifyThreadGroup"); - private static final Permission modifyThreadPerm = new RuntimePermission("modifyThread"); - private URLLoaderThreadFactory() { @SuppressWarnings("removal") SecurityManager sm = System.getSecurityManager(); @@ -249,22 +234,14 @@ private URLLoaderThreadFactory() { : Thread.currentThread().getThreadGroup(); } - @SuppressWarnings("removal") @Override public Thread newThread(Runnable r) { - // Assert the modifyThread and modifyThreadGroup permissions - return - AccessController.doPrivileged((PrivilegedAction) () -> { - Thread t = new Thread(group, r, - "URL-Loader-" + index.getAndIncrement()); - t.setDaemon(true); - if (t.getPriority() != Thread.NORM_PRIORITY) { - t.setPriority(Thread.NORM_PRIORITY); - } - return t; - }, - null, - modifyThreadGroupPerm, modifyThreadPerm); + Thread t = new Thread(group, r, "URL-Loader-" + index.getAndIncrement()); + t.setDaemon(true); + if (t.getPriority() != Thread.NORM_PRIORITY) { + t.setPriority(Thread.NORM_PRIORITY); + } + return t; } } } diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/PublicSuffixes.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/PublicSuffixes.java index bff84151349..e77f596b8a0 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/PublicSuffixes.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/PublicSuffixes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,9 +25,6 @@ package com.sun.webkit.network; -import com.sun.javafx.logging.PlatformLogger; -import com.sun.javafx.logging.PlatformLogger.Level; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -36,13 +33,14 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.IDN; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BooleanSupplier; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import com.sun.javafx.logging.PlatformLogger; +import com.sun.javafx.logging.PlatformLogger.Level; /** * A collection of static utility methods dealing with "public suffixes". @@ -72,24 +70,20 @@ private enum Rule { /** * The public suffix list file. */ - @SuppressWarnings("removal") - private static final File pslFile = AccessController.doPrivileged((PrivilegedAction) - () -> new File(System.getProperty("java.home"), "lib/security/public_suffix_list.dat")); + private static final File pslFile = new File(System.getProperty("java.home"), "lib/security/public_suffix_list.dat"); /* * Determines whether the public suffix list file is available. */ - @SuppressWarnings("removal") - private static final boolean pslFileExists = AccessController.doPrivileged( - (PrivilegedAction) () -> { - if (!pslFile.exists()) { - logger.warning("Resource not found: " + - "lib/security/public_suffix_list.dat"); - return false; - } - return true; - }); + private static final boolean pslFileExists = ((BooleanSupplier)() -> { + if (!pslFile.exists()) { + logger.warning("Resource not found: " + + "lib/security/public_suffix_list.dat"); + return false; + } + return true; + }).getAsBoolean(); /** @@ -197,19 +191,13 @@ private static Rules createRules(String tld) { } private static InputStream getPubSuffixStream() { - @SuppressWarnings("removal") - InputStream is = AccessController.doPrivileged( - (PrivilegedAction) () -> { - try { - return new FileInputStream(pslFile); - } catch (FileNotFoundException ex) { - logger.warning("Resource not found: " + - "lib/security/public_suffix_list.dat"); - return null; - } - } - ); - return is; + try { + return new FileInputStream(pslFile); + } catch (FileNotFoundException ex) { + logger.warning("Resource not found: " + + "lib/security/public_suffix_list.dat"); + return null; + } } boolean match(String domain) { diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/SocketStreamHandle.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/SocketStreamHandle.java index f6b980ec4cc..afeb9b4b983 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/SocketStreamHandle.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/SocketStreamHandle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,8 +43,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadFactory; @@ -101,7 +99,6 @@ private static SocketStreamHandle fwkCreate(String host, int port, return ssh; } - @SuppressWarnings("removal") private void run() { if (webPage == null) { logger.finest("{0} is not associated with any web " @@ -114,13 +111,7 @@ private void run() { didClose(); return; } - AccessController.doPrivileged((PrivilegedAction) () -> { - doRun(); - return null; - }, webPage.getAccessControlContext()); - } - private void doRun() { Throwable error = null; String errorDescription = null; try { @@ -209,9 +200,7 @@ private void connect() throws IOException { boolean success = false; IOException lastException = null; boolean triedDirectConnection = false; - @SuppressWarnings("removal") - ProxySelector proxySelector = AccessController.doPrivileged( - (PrivilegedAction) () -> ProxySelector.getDefault()); + ProxySelector proxySelector = ProxySelector.getDefault(); if (proxySelector != null) { URI uri; try { diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/URLLoader.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/URLLoader.java index d4ecb40a60a..8dd78330c4f 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/URLLoader.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/URLLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,9 +51,6 @@ import java.net.URLDecoder; import java.net.UnknownHostException; import java.nio.ByteBuffer; -import java.security.AccessControlException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import java.util.Locale; import java.util.Map; @@ -122,20 +119,8 @@ public void fwkCancel() { /** * {@inheritDoc} */ - @SuppressWarnings("removal") @Override public void run() { - // Run the loader in the page's access control context - AccessController.doPrivileged((PrivilegedAction) () -> { - doRun(); - return null; - }, webPage.getAccessControlContext()); - } - - /** - * Executes this loader. - */ - private void doRun() { Throwable error = null; int errorCode = 0; try { @@ -186,9 +171,6 @@ private void doRun() { } catch (MalformedURLException ex) { error = ex; errorCode = LoadListenerClient.MALFORMED_URL; - } catch (@SuppressWarnings("removal") AccessControlException ex) { - error = ex; - errorCode = LoadListenerClient.PERMISSION_DENIED; } catch (UnknownHostException ex) { error = ex; errorCode = LoadListenerClient.UNKNOWN_HOST; diff --git a/modules/javafx.web/src/main/java/com/sun/webkit/network/URLs.java b/modules/javafx.web/src/main/java/com/sun/webkit/network/URLs.java index 9ded1722b90..1f167a9786b 100644 --- a/modules/javafx.web/src/main/java/com/sun/webkit/network/URLs.java +++ b/modules/javafx.web/src/main/java/com/sun/webkit/network/URLs.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,12 +26,8 @@ package com.sun.webkit.network; import java.net.MalformedURLException; -import java.net.NetPermission; import java.net.URL; import java.net.URLStreamHandler; -import java.security.AccessController; -import java.security.Permission; -import java.security.PrivilegedAction; import java.util.Map; /** @@ -47,9 +43,6 @@ public final class URLs { "about", new com.sun.webkit.network.about.Handler(), "data", new com.sun.webkit.network.data.Handler()); - private static final Permission streamHandlerPermission = - new NetPermission("specifyStreamHandler"); - /** * The private default constructor. Ensures non-instantiability. */ @@ -96,25 +89,7 @@ public static URL newURL(final URL context, final String spec) if (handler == null) throw ex; - try { - // We should be able to specify one of our stream handlers for the URL - // when running with a security manager - @SuppressWarnings("removal") - URL result = AccessController.doPrivileged((PrivilegedAction) () -> { - try { - return new URL(context, spec, handler); - } catch (MalformedURLException muex) { - throw new RuntimeException(muex); - } - }, null, streamHandlerPermission); - return result; - - } catch (RuntimeException re) { - if (re.getCause() instanceof MalformedURLException) { - throw (MalformedURLException)re.getCause(); - } - throw re; - } + return new URL(context, spec, handler); } } } diff --git a/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java b/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java index d2fd0be2543..ca158e49e08 100644 --- a/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java +++ b/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,10 +71,6 @@ import com.sun.javafx.scene.web.behavior.HTMLEditorBehavior; import com.sun.webkit.WebPage; import com.sun.javafx.webkit.Accessor; - -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -830,10 +826,9 @@ private Button addButton(ToolBar toolbar, final String iconName, String tooltipT button.getStyleClass().add(styleClass); toolbar.getItems().add(button); - @SuppressWarnings("removal") - Image icon = AccessController.doPrivileged((PrivilegedAction) () -> new Image(HTMLEditorSkin.class.getResource(iconName).toString())); -// button.setGraphic(new ImageView(icon)); + Image icon = new Image(HTMLEditorSkin.class.getResource(iconName).toString()); ((StyleableProperty)button.graphicProperty()).applyStyle(null, new ImageView(icon)); +// button.setGraphic(new ImageView(icon)); button.setTooltip(new Tooltip(tooltipText)); button.setOnAction(event -> { @@ -855,10 +850,9 @@ private ToggleButton addToggleButton(ToolBar toolbar, ToggleGroup toggleGroup, toggleButton.setToggleGroup(toggleGroup); } - @SuppressWarnings("removal") - Image icon = AccessController.doPrivileged((PrivilegedAction) () -> new Image(HTMLEditorSkin.class.getResource(iconName).toString())); + Image icon = new Image(HTMLEditorSkin.class.getResource(iconName).toString()); ((StyleableProperty)toggleButton.graphicProperty()).applyStyle(null, new ImageView(icon)); -// toggleButton.setGraphic(new ImageView(icon)); +// toggleButton.setGraphic(new ImageView(icon)); toggleButton.setTooltip(new Tooltip(tooltipText)); 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 dba4f34d327..b66ceaf15e3 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,8 +66,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.PosixFilePermissions; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -1571,8 +1569,6 @@ private InspectorClientImpl(WebEngine engine) { this.engine = new WeakReference<>(engine); } - - @SuppressWarnings("removal") @Override public boolean sendMessageToFrontend(final String message) { boolean result = false; @@ -1581,10 +1577,7 @@ public boolean sendMessageToFrontend(final String message) { final Callback messageCallback = webEngine.debugger.messageCallback; if (messageCallback != null) { - AccessController.doPrivileged((PrivilegedAction) () -> { - messageCallback.call(message); - return null; - }, webEngine.page.getAccessControlContext()); + messageCallback.call(message); result = true; } }