Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: 8342453: Remove calls to doPrivileged in javafx.graphics/com.sun.javafx.tk #4

Draft
wants to merge 1 commit into
base: 8341090-remove-sm
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.nio.ByteBuffer;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -102,8 +101,7 @@ public abstract class Toolkit {

private static final Map gradientMap = new WeakHashMap();

@SuppressWarnings("removal")
private static final boolean verbose = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.verbose"));
private static final boolean verbose = Boolean.getBoolean("javafx.verbose");

private static final String[] msLibNames = {
"api-ms-win-core-console-l1-1-0",
Expand Down Expand Up @@ -200,13 +198,9 @@ public static synchronized Toolkit getToolkit() {
return TOOLKIT;
}

@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
// Get the javafx.version and javafx.runtime.version from a preconstructed
// java class, VersionInfo, created at build time.
VersionInfo.setupSystemProperties();
return null;
});
// Get the javafx.version and javafx.runtime.version from a preconstructed
// java class, VersionInfo, created at build time.
VersionInfo.setupSystemProperties();

// Load required Microsoft runtime DLLs on Windows platforms
if (PlatformUtil.isWindows()) {
Expand All @@ -216,9 +210,6 @@ public static synchronized Toolkit getToolkit() {
boolean userSpecifiedToolkit = true;

// Check a system property to see if there is a specific toolkit to use.
// This is not a doPriviledged check so that applications running
// with a security manager cannot use this unless they have permission
// to read system properties.
String forcedToolkit = null;
try {
forcedToolkit = System.getProperty("javafx.toolkit");
Expand Down Expand Up @@ -397,10 +388,7 @@ private void runPulse(final TKPulseListener listener,
throw new IllegalStateException("Invalid AccessControlContext");
}

AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
listener.pulse();
return null;
}, acc);
listener.pulse();
}

public void firePulse() {
Expand Down Expand Up @@ -536,15 +524,7 @@ protected void notifyShutdownHooks() {
public void notifyWindowListeners(final List<TKStage> windows) {
for (Map.Entry<TKListener,AccessControlContext> entry : toolkitListeners.entrySet()) {
final TKListener listener = entry.getKey();
final AccessControlContext acc = entry.getValue();
if (acc == null) {
throw new IllegalStateException("Invalid AccessControlContext");
}

AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
listener.changedTopLevelWindows(windows);
return null;
}, acc);
listener.changedTopLevelWindows(windows);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.image.PixelFormat;
import java.nio.IntBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import com.sun.javafx.cursor.CursorFrame;
import com.sun.javafx.embed.AbstractEvents;
import com.sun.javafx.embed.EmbeddedSceneDTInterface;
Expand Down Expand Up @@ -205,16 +203,12 @@ public boolean traverseOut(Direction dir) {
return false;
}

@SuppressWarnings("removal")
@Override
public void setSize(final int width, final int height) {
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener != null) {
sceneListener.changedSize(width, height);
}
return null;
}, getAccessControlContext());
if (sceneListener != null) {
sceneListener.changedSize(width, height);
}
});
}

Expand Down Expand Up @@ -275,7 +269,6 @@ protected Color getClearColor() {
return super.getClearColor();
}

@SuppressWarnings("removal")
@Override
public void mouseEvent(final int type, final int button,
final boolean primaryBtnDown, final boolean middleBtnDown, final boolean secondaryBtnDown,
Expand All @@ -285,10 +278,7 @@ public void mouseEvent(final int type, final int button,
final boolean popupTrigger)
{
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener == null) {
return null;
}
if (sceneListener != null) {
// Click events are generated in Scene, so we don't expect them here
assert type != AbstractEvents.MOUSEEVENT_CLICKED;
EventType<MouseEvent> eventType = AbstractEvents.mouseIDToFXEventID(type);
Expand All @@ -299,12 +289,10 @@ public void mouseEvent(final int type, final int button,
primaryBtnDown, middleBtnDown, secondaryBtnDown,
backBtnDown, forwardBtnDown
);
return null;
}, getAccessControlContext());
}
});
}

@SuppressWarnings("removal")
@Override
public void scrollEvent(final int type,
final double scrollX, final double scrollY,
Expand All @@ -316,129 +304,98 @@ public void scrollEvent(final int type,
final boolean inertia) {
{
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener == null) {
return null;
}
if (sceneListener != null) {
sceneListener.scrollEvent(AbstractEvents.scrollIDToFXEventType(type), scrollX, scrollY, totalScrollX, totalScrollY, xMultiplier, yMultiplier,
0, 0, 0, 0, 0, x, y, xAbs, yAbs, shift, ctrl, alt, meta, false, inertia);
return null;
}, getAccessControlContext());
}
});
}
}

@SuppressWarnings("removal")
@Override
public void inputMethodEvent(final EventType<InputMethodEvent> type,
final ObservableList<InputMethodTextRun> composed, final String committed,
final int caretPosition) {
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener != null) {
sceneListener.inputMethodEvent(type, composed, committed, caretPosition);
}
return null;
});
if (sceneListener != null) {
sceneListener.inputMethodEvent(type, composed, committed, caretPosition);
}
});
}

@SuppressWarnings("removal")
@Override
public void menuEvent(final int x, final int y, final int xAbs, final int yAbs, final boolean isKeyboardTrigger) {
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener != null) {
sceneListener.menuEvent(x, y, xAbs, yAbs, isKeyboardTrigger);
}
return null;
}, getAccessControlContext());
if (sceneListener != null) {
sceneListener.menuEvent(x, y, xAbs, yAbs, isKeyboardTrigger);
}
});
}

@SuppressWarnings("removal")
@Override
public void keyEvent(final int type, final int key, final char[] ch, final int modifiers) {
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener != null) {
boolean shiftDown = (modifiers & AbstractEvents.MODIFIER_SHIFT) != 0;
boolean controlDown = (modifiers & AbstractEvents.MODIFIER_CONTROL) != 0;
boolean altDown = (modifiers & AbstractEvents.MODIFIER_ALT) != 0;
boolean metaDown = (modifiers & AbstractEvents.MODIFIER_META) != 0;

String str = new String(ch);
String text = str; // TODO: this must be a text like "HOME", "F1", or "A"
KeyCode code = KeyCodeMap.valueOf(key);
if (code == null) {
code = KeyCode.UNDEFINED;
}
javafx.scene.input.KeyEvent keyEvent = new javafx.scene.input.KeyEvent(
AbstractEvents.keyIDToFXEventType(type),
str, text, code,
shiftDown, controlDown, altDown, metaDown);
sceneListener.keyEvent(keyEvent);
if (sceneListener != null) {
boolean shiftDown = (modifiers & AbstractEvents.MODIFIER_SHIFT) != 0;
boolean controlDown = (modifiers & AbstractEvents.MODIFIER_CONTROL) != 0;
boolean altDown = (modifiers & AbstractEvents.MODIFIER_ALT) != 0;
boolean metaDown = (modifiers & AbstractEvents.MODIFIER_META) != 0;

String str = new String(ch);
String text = str; // TODO: this must be a text like "HOME", "F1", or "A"
KeyCode code = KeyCodeMap.valueOf(key);
if (code == null) {
code = KeyCode.UNDEFINED;
}
return null;
}, getAccessControlContext());
javafx.scene.input.KeyEvent keyEvent = new javafx.scene.input.KeyEvent(
AbstractEvents.keyIDToFXEventType(type),
str, text, code,
shiftDown, controlDown, altDown, metaDown);
sceneListener.keyEvent(keyEvent);
}
});
}

@SuppressWarnings("removal")
@Override
public void zoomEvent(final int type, final double zoomFactor, final double totalZoomFactor,
final double x, final double y, final double screenX, final double screenY,
boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
{
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener == null) {
return null;
}
if (sceneListener != null) {
sceneListener.zoomEvent(AbstractEvents.zoomIDToFXEventType(type),
zoomFactor, totalZoomFactor,
x, y, screenX, screenY,
shift, ctrl, alt, meta, false, inertia);
return null;
}, getAccessControlContext());
}
});
}

@SuppressWarnings("removal")
@Override
public void rotateEvent(final int type, final double angle, final double totalAngle,
final double x, final double y, final double screenX, final double screenY,
boolean shift, boolean ctrl, boolean alt, boolean meta, boolean inertia)
{
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener == null) {
return null;
}
sceneListener.rotateEvent(AbstractEvents.rotateIDToFXEventType(type),
angle, totalAngle,
x, y, screenX, screenY,
shift, ctrl, alt, meta, false, inertia);
return null;
}, getAccessControlContext());
if (sceneListener != null) {
sceneListener.rotateEvent(AbstractEvents.rotateIDToFXEventType(type),
angle, totalAngle,
x, y, screenX, screenY,
shift, ctrl, alt, meta, false, inertia);
}
});
}

@SuppressWarnings("removal")
@Override
public void swipeEvent(final int type, final double x, final double y, final double screenX, final double screenY,
boolean shift, boolean ctrl, boolean alt, boolean meta)
{
Platform.runLater(() -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (sceneListener == null) {
return null;
}
if (sceneListener != null) {
sceneListener.swipeEvent(AbstractEvents.swipeIDToFXEventType(type),
0, x, y, screenX, screenY,
shift, ctrl, alt, meta, false);
return null;
}, getAccessControlContext());
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
package com.sun.javafx.tk.quantum;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;

import com.sun.javafx.embed.AbstractEvents;
Expand Down Expand Up @@ -220,13 +218,8 @@ public void toFront() {
host.ungrabFocus();
}

@SuppressWarnings("removal")
private void notifyStageListener(final Runnable r) {
AccessControlContext acc = getAccessControlContext();
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
r.run();
return null;
}, acc);
r.run();
}
private void notifyStageListenerLater(final Runnable r) {
Platform.runLater(() -> notifyStageListener(r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javafx.stage.StageStyle;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.atomic.AtomicBoolean;
import com.sun.glass.ui.Clipboard;
import com.sun.glass.ui.ClipboardAssistance;
Expand Down Expand Up @@ -247,21 +246,17 @@ public void clearEntireSceneDirty() {
@Override
public TKClipboard createDragboard(boolean isDragSource) {
ClipboardAssistance assistant = new ClipboardAssistance(Clipboard.DND) {
@SuppressWarnings("removal")
@Override
public void actionPerformed(final int performedAction) {
super.actionPerformed(performedAction);
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
if (dragSourceListener != null) {
dragSourceListener.dragDropEnd(0, 0, 0, 0,
QuantumToolkit.clipboardActionToTransferMode(performedAction));
}
} finally {
QuantumClipboard.releaseCurrentDragboard();
try {
if (dragSourceListener != null) {
dragSourceListener.dragDropEnd(0, 0, 0, 0,
QuantumToolkit.clipboardActionToTransferMode(performedAction));
}
return null;
}, getAccessControlContext());
} finally {
QuantumClipboard.releaseCurrentDragboard();
}
}
};
return QuantumClipboard.getDragboardInstance(assistant, isDragSource);
Expand Down
Loading
Loading