Skip to content

Commit 9846193

Browse files
Yuri NesterenkoRealCLanger
authored andcommitted
8296832: Improve Swing platform support
Reviewed-by: mbalao Backport-of: a81c810a76d91b79917417ed22e5e5aa530690ca
1 parent 7592194 commit 9846193

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.swing.text.*;
3434
import javax.swing.text.html.*;
3535

36+
import sun.swing.SwingAccessor;
3637
import sun.swing.SwingUtilities2;
3738

3839
/**
@@ -220,7 +221,7 @@ public static void updateRenderer(JComponent c, String text) {
220221
View value = null;
221222
View oldValue = (View)c.getClientProperty(BasicHTML.propertyKey);
222223
Boolean htmlDisabled = (Boolean) c.getClientProperty(htmlDisable);
223-
if (htmlDisabled != Boolean.TRUE && BasicHTML.isHTMLString(text)) {
224+
if (!(Boolean.TRUE.equals(htmlDisabled)) && BasicHTML.isHTMLString(text)) {
224225
value = BasicHTML.createHTMLView(c, text);
225226
}
226227
if (value != oldValue && oldValue != null) {
@@ -376,15 +377,36 @@ public ViewFactory getViewFactory() {
376377
*/
377378
static class BasicHTMLViewFactory extends HTMLEditorKit.HTMLFactory {
378379
public View create(Element elem) {
379-
View view = super.create(elem);
380380

381+
View view = null;
382+
try {
383+
setAllowHTMLObject();
384+
view = super.create(elem);
385+
} finally {
386+
clearAllowHTMLObject();
387+
}
381388
if (view instanceof ImageView) {
382389
((ImageView)view).setLoadsSynchronously(true);
383390
}
384391
return view;
385392
}
386-
}
387393

394+
private static Boolean useOV = null;
395+
396+
@SuppressWarnings("removal")
397+
private static void setAllowHTMLObject() {
398+
if (useOV == null) {
399+
useOV = java.security.AccessController.doPrivileged(
400+
new sun.security.action.GetBooleanAction(
401+
"swing.html.object"));
402+
};
403+
SwingAccessor.setAllowHTMLObject(useOV);
404+
}
405+
406+
private static void clearAllowHTMLObject() {
407+
SwingAccessor.setAllowHTMLObject(null);
408+
}
409+
}
388410

389411
/**
390412
* The subclass of HTMLDocument that is used as the model. getForeground

src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.security.AccessController;
4242
import java.security.PrivilegedAction;
4343
import javax.swing.text.html.parser.ParserDelegator;
44+
import sun.swing.SwingAccessor;
4445

4546
/**
4647
* The Swing JEditorPane text component supports different kinds
@@ -1326,7 +1327,11 @@ public View create(Element elem) {
13261327
(kind == HTML.Tag.TEXTAREA)) {
13271328
return new FormView(elem);
13281329
} else if (kind == HTML.Tag.OBJECT) {
1329-
return new ObjectView(elem);
1330+
if (SwingAccessor.getAllowHTMLObject()) {
1331+
return new ObjectView(elem);
1332+
} else {
1333+
return new ObjectView(elem, false);
1334+
}
13301335
} else if (kind == HTML.Tag.FRAMESET) {
13311336
if (elem.getAttributes().isDefined(HTML.Attribute.ROWS)) {
13321337
return new FrameSetView(elem, View.Y_AXIS);

src/java.desktop/share/classes/javax/swing/text/html/ObjectView.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
*/
7272
public class ObjectView extends ComponentView {
7373

74+
private boolean createComp = true; // default
75+
7476
/**
7577
* Creates a new ObjectView object.
7678
*
@@ -80,13 +82,21 @@ public ObjectView(Element elem) {
8082
super(elem);
8183
}
8284

85+
ObjectView(Element elem, boolean createComp) {
86+
super(elem);
87+
this.createComp = createComp;
88+
}
89+
8390
/**
8491
* Create the component. The classid is used
8592
* as a specification of the classname, which
8693
* we try to load.
8794
*/
8895
@SuppressWarnings("deprecation")
8996
protected Component createComponent() {
97+
if (!createComp) {
98+
return getUnloadableRepresentation();
99+
}
90100
AttributeSet attr = getElement().getAttributes();
91101
String classname = (String) attr.getAttribute(HTML.Attribute.CLASSID);
92102
try {

src/java.desktop/share/classes/sun/swing/SwingAccessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,19 @@ private static void ensureClassInitialized(Class<?> c) {
283283
MethodHandles.lookup().ensureInitialized(c);
284284
} catch (IllegalAccessException e) {}
285285
}
286+
287+
private static ThreadLocal<Boolean> tlObj = new ThreadLocal<Boolean>();
288+
289+
public static Boolean getAllowHTMLObject() {
290+
Boolean b = tlObj.get();
291+
if (b == null) {
292+
return Boolean.TRUE;
293+
} else {
294+
return b;
295+
}
296+
}
297+
298+
public static void setAllowHTMLObject(Boolean val) {
299+
tlObj.set(val);
300+
}
286301
}

0 commit comments

Comments
 (0)