Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk20u Public archive

Commit

Permalink
8296832: Improve Swing platform support
Browse files Browse the repository at this point in the history
Backport-of: a81c810a76d91b79917417ed22e5e5aa530690ca
  • Loading branch information
prsadhuk committed Jan 19, 2023
1 parent 219bc6f commit bb535a0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.swing.text.*;
import javax.swing.text.html.*;

import sun.swing.SwingAccessor;
import sun.swing.SwingUtilities2;

/**
Expand Down Expand Up @@ -220,7 +221,7 @@ public static void updateRenderer(JComponent c, String text) {
View value = null;
View oldValue = (View)c.getClientProperty(BasicHTML.propertyKey);
Boolean htmlDisabled = (Boolean) c.getClientProperty(htmlDisable);
if (htmlDisabled != Boolean.TRUE && BasicHTML.isHTMLString(text)) {
if (!(Boolean.TRUE.equals(htmlDisabled)) && BasicHTML.isHTMLString(text)) {
value = BasicHTML.createHTMLView(c, text);
}
if (value != oldValue && oldValue != null) {
Expand Down Expand Up @@ -376,15 +377,36 @@ public ViewFactory getViewFactory() {
*/
static class BasicHTMLViewFactory extends HTMLEditorKit.HTMLFactory {
public View create(Element elem) {
View view = super.create(elem);

View view = null;
try {
setAllowHTMLObject();
view = super.create(elem);
} finally {
clearAllowHTMLObject();
}
if (view instanceof ImageView) {
((ImageView)view).setLoadsSynchronously(true);
}
return view;
}
}

private static Boolean useOV = null;

@SuppressWarnings("removal")
private static void setAllowHTMLObject() {
if (useOV == null) {
useOV = java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"swing.html.object"));
};
SwingAccessor.setAllowHTMLObject(useOV);
}

private static void clearAllowHTMLObject() {
SwingAccessor.setAllowHTMLObject(null);
}
}

/**
* The subclass of HTMLDocument that is used as the model. getForeground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import javax.swing.text.ViewFactory;
import javax.swing.text.html.parser.ParserDelegator;

import sun.swing.SwingAccessor;
import sun.awt.AppContext;

import static java.nio.charset.StandardCharsets.ISO_8859_1;
Expand Down Expand Up @@ -1402,7 +1403,11 @@ public View create(Element elem) {
(kind == HTML.Tag.TEXTAREA)) {
return new FormView(elem);
} else if (kind == HTML.Tag.OBJECT) {
return new ObjectView(elem);
if (SwingAccessor.getAllowHTMLObject()) {
return new ObjectView(elem);
} else {
return new ObjectView(elem, false);
}
} else if (kind == HTML.Tag.FRAMESET) {
if (elem.getAttributes().isDefined(HTML.Attribute.ROWS)) {
return new FrameSetView(elem, View.Y_AXIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
*/
public class ObjectView extends ComponentView {

private boolean createComp = true; // default

/**
* Creates a new ObjectView object.
*
Expand All @@ -80,13 +82,21 @@ public ObjectView(Element elem) {
super(elem);
}

ObjectView(Element elem, boolean createComp) {
super(elem);
this.createComp = createComp;
}

/**
* Create the component. The classid is used
* as a specification of the classname, which
* we try to load.
*/
@SuppressWarnings("deprecation")
protected Component createComponent() {
if (!createComp) {
return getUnloadableRepresentation();
}
AttributeSet attr = getElement().getAttributes();
String classname = (String) attr.getAttribute(HTML.Attribute.CLASSID);
try {
Expand Down
15 changes: 15 additions & 0 deletions src/java.desktop/share/classes/sun/swing/SwingAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,19 @@ private static void ensureClassInitialized(Class<?> c) {
MethodHandles.lookup().ensureInitialized(c);
} catch (IllegalAccessException e) {}
}

private static ThreadLocal<Boolean> tlObj = new ThreadLocal<Boolean>();

public static Boolean getAllowHTMLObject() {
Boolean b = tlObj.get();
if (b == null) {
return Boolean.TRUE;
} else {
return b;
}
}

public static void setAllowHTMLObject(Boolean val) {
tlObj.set(val);
}
}

0 comments on commit bb535a0

Please sign in to comment.