Skip to content

Commit

Permalink
8342461: Remove calls to doPrivileged in javafx.web/{android,ios}
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, jvos
  • Loading branch information
Jose Pereda committed Nov 28, 2024
1 parent f7566ad commit a45e33c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 110 deletions.
15 changes: 3 additions & 12 deletions modules/javafx.web/src/android/java/com/sun/webkit/Timer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, 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
Expand All @@ -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;
Expand All @@ -44,14 +41,8 @@ public static enum Mode {

public synchronized static Mode getMode() {
if (mode == null) {
mode = Boolean.valueOf(AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return 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;
}
Expand Down
18 changes: 3 additions & 15 deletions modules/javafx.web/src/android/java/com/sun/webkit/WebPage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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
Expand All @@ -26,9 +26,6 @@
package com.sun.webkit;

import java.io.StringReader;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.LinkedList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
Expand All @@ -43,13 +40,8 @@
public final class WebPage {

static {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.out.println ("[JVDBG] I will load the webview system library");
System.loadLibrary("webview");
return null;
}
});
System.out.println ("[JVDBG] I will load the webview system library");
System.loadLibrary("webview");
}
public static int DND_DST_DROP;
public static int DND_SRC_DROP;
Expand Down Expand Up @@ -187,10 +179,6 @@ public void dispatchInspectorMessageFromFrontend(String message) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public AccessControlContext getAccessControlContext() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public void open(long mainFrame, String url) {
getNativePeer().loadUrl(url);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, 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
Expand Down Expand Up @@ -46,8 +46,6 @@
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javafx.animation.AnimationTimer;
import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -1328,12 +1326,7 @@ public boolean sendMessageToFrontend(final String message) {
final Callback<String,Void> messageCallback =
webEngine.debugger.messageCallback;
if (messageCallback != null) {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override public Void run() {
messageCallback.call(message);
return null;
}
}, webEngine.page.getAccessControlContext());
messageCallback.call(message);
result = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,10 +35,6 @@
import java.util.Collections;
import java.util.List;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;

import com.sun.javafx.reflect.ReflectUtil;


Expand Down Expand Up @@ -172,14 +168,7 @@ private Object cast(Class<?> desiredType, Object value) throws Exception {
// returns JSON-encoded result
public String call(final String methodName, final String args) throws CallException {
try {
@SuppressWarnings("removal")
String result = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
return callWorker(methodName, args);
}
}, getJSBridge().getAccessControlContext());
return result;
return callWorker(methodName, args);
} catch (Exception e) {
if (e instanceof CallException) {
throw (CallException) e;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020, 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
Expand Down Expand Up @@ -78,9 +78,6 @@
import com.sun.javafx.scene.traversal.TraversalEngine;
import com.sun.javafx.scene.traversal.TraverseListener;

import java.security.AccessController;
import java.security.PrivilegedAction;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -762,11 +759,7 @@ public void handle(ActionEvent event) {

// fgColorButton.applyCss();
// ColorPickerSkin fgColorPickerSkin = (ColorPickerSkin) fgColorButton.getSkin();
// String fgIcon = AccessController.doPrivileged(new PrivilegedAction<String>() {
// @Override public String run() {
// return HTMLEditorSkin.class.getResource(resources.getString("foregroundColorIcon")).toString();
// }
// });
// String fgIcon = HTMLEditorSkin.class.getResource(resources.getString("foregroundColorIcon")).toString();
// ((StyleableProperty)fgColorPickerSkin.imageUrlProperty()).applyStyle(null,fgIcon);

fgColorButton.setValue(DEFAULT_FG_COLOR);
Expand All @@ -788,11 +781,7 @@ public void handle(ActionEvent event) {

// bgColorButton.applyCss();
// ColorPickerSkin bgColorPickerSkin = (ColorPickerSkin) bgColorButton.getSkin();
// String bgIcon = AccessController.doPrivileged(new PrivilegedAction<String>() {
// @Override public String run() {
// return HTMLEditorSkin.class.getResource(resources.getString("backgroundColorIcon")).toString();
// }
// });
// String bgIcon = HTMLEditorSkin.class.getResource(resources.getString("backgroundColorIcon")).toString();
// ((StyleableProperty)bgColorPickerSkin.imageUrlProperty()).applyStyle(null,bgIcon);

bgColorButton.setValue(DEFAULT_BG_COLOR);
Expand Down Expand Up @@ -823,12 +812,7 @@ private Button addButton(ToolBar toolbar, final String iconName, String tooltipT
button.getStyleClass().add(styleClass);
toolbar.getItems().add(button);

@SuppressWarnings("removal")
Image icon = AccessController.doPrivileged(new PrivilegedAction<Image>() {
@Override public Image run() {
return new Image(HTMLEditorSkin.class.getResource(iconName).toString());
}
});
Image icon = new Image(HTMLEditorSkin.class.getResource(iconName).toString());
// button.setGraphic(new ImageView(icon));
((StyleableProperty)button.graphicProperty()).applyStyle(null,new ImageView(icon));
button.setTooltip(new Tooltip(tooltipText));
Expand All @@ -855,12 +839,7 @@ private ToggleButton addToggleButton(ToolBar toolbar, ToggleGroup toggleGroup,
toggleButton.setToggleGroup(toggleGroup);
}

@SuppressWarnings("removal")
Image icon = AccessController.doPrivileged(new PrivilegedAction<Image>() {
@Override public Image run() {
return 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));

Expand Down Expand Up @@ -903,12 +882,7 @@ private void updateNodeOrientation() {
if (orientation == RIGHT_TO_LEFT) {
try {
final String iconName = resources.getString("numbersIcon-rtl");
@SuppressWarnings("removal")
Image icon = AccessController.doPrivileged(new PrivilegedAction<Image>() {
@Override public Image run() {
return new Image(HTMLEditorSkin.class.getResource(iconName).toString());
}
});
Image icon = new Image(HTMLEditorSkin.class.getResource(iconName).toString());
numbersButton.setGraphic(new ImageView(icon));
} catch (java.util.MissingResourceException ex) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,7 +28,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.security.AccessControlContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -103,11 +102,6 @@ String getJavaBridge() {
return javaBridge;
}

@SuppressWarnings("removal")
AccessControlContext getAccessControlContext() {
return webEngine.getAccessControlContext();
}

private void populateObject(String jsName, ExportedJavaObject jsObj) {
if (exportedObjectsByJSIds.containsValue(jsObj)) {
return;
Expand Down
23 changes: 1 addition & 22 deletions modules/javafx.web/src/ios/java/javafx/scene/web/WebEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
import com.sun.javafx.tk.TKPulseListener;
import com.sun.javafx.tk.Toolkit;
import java.io.StringReader;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javafx.beans.property.*;
import javafx.geometry.Rectangle2D;

Expand Down Expand Up @@ -517,9 +514,6 @@ public WebEngine() {
* Creates a new engine and loads a Web page into it.
*/
public WebEngine(String url) {
@SuppressWarnings("removal")
AccessControlContext tmpAcc = AccessController.getContext();
accessControlContext = tmpAcc;
js2javaBridge = new JS2JavaBridge(this);
load(url);
}
Expand Down Expand Up @@ -949,23 +943,8 @@ void onAlertNotify(String text) {
}
}

@SuppressWarnings("removal")
final private AccessControlContext accessControlContext;

@SuppressWarnings("removal")
AccessControlContext getAccessControlContext() {
return accessControlContext;
}

private void dispatchWebEvent(final EventHandler handler, final WebEvent ev) {
@SuppressWarnings("removal")
Void result = AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
handler.handle(ev);
return null;
}
}, getAccessControlContext());
handler.handle(ev);
}

private class DebuggerImpl implements Debugger {
Expand Down

0 comments on commit a45e33c

Please sign in to comment.