/hg/icedtea6: plugin: Fix PR565: allow applets to have their own...
omajid at icedtea.classpath.org
omajid at icedtea.classpath.org
Thu Oct 14 13:00:18 PDT 2010
changeset 519a6f970eba in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=519a6f970eba
author: Omair Majid <omajid at redhat.com>
date: Thu Oct 14 15:59:52 2010 -0400
plugin: Fix PR565: allow applets to have their own look and feels
2010-10-14 Omair Majid <omajid at redhat.com>
Fixes PR565
* NEWS: Update with fix.
* netx/net/sourceforge/jnlp/Launcher.java: Make mainGroup package-
private so NetxPanel can access it. (createThreadGroup): Only
create a new AppThreadGroup if not a plugin. (run): Update
comments and make dependence on SunToolkit explicit.
* netx/net/sourceforge/jnlp/NetxPanel.java (run): New method.
Create a new AppContext for the applet. (createAppletThread):
Create a new AppThreadGroup and start the applet thread in that
ThreadGroup.
* netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java: Add
new private variable appContext. (ApplicationInstance):
Initialize appContext. (getAppContext): New method.
* netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java:
Extend AWTSecurityManager. (JNLPSecurityManager): Save the
AppContext. (getAppContext): New method. Traverse the stack to
find the application and return its AppContext.
diffstat:
6 files changed, 123 insertions(+), 7 deletions(-)
ChangeLog | 22 ++++++
NEWS | 1
netx/net/sourceforge/jnlp/Launcher.java | 23 +++++--
netx/net/sourceforge/jnlp/NetxPanel.java | 24 +++++++
netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java | 21 ++++++
netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java | 39 +++++++++++-
diffs (285 lines):
diff -r be9262040bbc -r 519a6f970eba ChangeLog
--- a/ChangeLog Thu Oct 14 13:25:44 2010 +0200
+++ b/ChangeLog Thu Oct 14 15:59:52 2010 -0400
@@ -1,3 +1,25 @@ 2010-10-14 Matthias Klose <doko at ubuntu
+2010-10-14 Omair Majid <omajid at redhat.com>
+
+ Fixes PR565
+ * NEWS: Update with fix.
+ * netx/net/sourceforge/jnlp/Launcher.java:
+ Make mainGroup package-private so NetxPanel can access it.
+ (createThreadGroup): Only create a new AppThreadGroup if not a plugin.
+ (run): Update comments and make dependence on SunToolkit explicit.
+ * netx/net/sourceforge/jnlp/NetxPanel.java
+ (run): New method. Create a new AppContext for the applet.
+ (createAppletThread): Create a new AppThreadGroup and start the applet
+ thread in that ThreadGroup.
+ * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java:
+ Add new private variable appContext.
+ (ApplicationInstance): Initialize appContext.
+ (getAppContext): New method.
+ * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java:
+ Extend AWTSecurityManager.
+ (JNLPSecurityManager): Save the AppContext.
+ (getAppContext): New method. Traverse the stack to find the application
+ and return its AppContext.
+
2010-10-14 Matthias Klose <doko at ubuntu.com>
* configure.ac: New option --with-llvm-config.
diff -r be9262040bbc -r 519a6f970eba NEWS
--- a/NEWS Thu Oct 14 13:25:44 2010 +0200
+++ b/NEWS Thu Oct 14 15:59:52 2010 -0400
@@ -45,6 +45,7 @@ New in release 1.10 (2010-XX-XX):
- PR556: Applet initialization code is prone to race conditions
- PR557: Applet opens in a separate window if tab is closed when the applet loads
- PR519: 100% CPU usage when displaying applets in Webkit based browsers
+ - PR565: UIDefaults.getUI fails with jgoodies:looks 2.3.1
New in release 1.9.1 (2010-10-13):
diff -r be9262040bbc -r 519a6f970eba netx/net/sourceforge/jnlp/Launcher.java
--- a/netx/net/sourceforge/jnlp/Launcher.java Thu Oct 14 13:25:44 2010 +0200
+++ b/netx/net/sourceforge/jnlp/Launcher.java Thu Oct 14 15:59:52 2010 -0400
@@ -49,6 +49,8 @@ import net.sourceforge.jnlp.util.Reflect
import javax.swing.SwingUtilities;
+import sun.awt.SunToolkit;
+
/**
* Launches JNLPFiles either in the foreground or background.<p>
*
@@ -69,7 +71,7 @@ public class Launcher {
private static String R(String key) { return JNLPRuntime.getMessage(key); }
/** shared thread group */
- private static final ThreadGroup mainGroup = new ThreadGroup(R("LAllThreadGroup"));
+ /*package*/ static final ThreadGroup mainGroup = new ThreadGroup(R("LAllThreadGroup"));
/** the handler */
private LaunchHandler handler = null;
@@ -668,9 +670,21 @@ public class Launcher {
/**
* Create a thread group for the JNLP file.
+ *
+ * Note: if the JNLPFile is an applet (ie it is a subclass of PluginBridge)
+ * then this method simply returns the existing ThreadGroup. The applet
+ * ThreadGroup has to be created at an earlier point in the applet code.
*/
protected AppThreadGroup createThreadGroup(JNLPFile file) {
- return new AppThreadGroup(mainGroup, file.getTitle());
+ AppThreadGroup appThreadGroup = null;
+
+ if (file instanceof PluginBridge) {
+ appThreadGroup = (AppThreadGroup) Thread.currentThread().getThreadGroup();
+ } else {
+ appThreadGroup = new AppThreadGroup(mainGroup, file.getTitle());
+ }
+
+ return appThreadGroup;
}
/**
@@ -796,9 +810,10 @@ public class Launcher {
public void run() {
try {
- // Do not create new AppContext if we're using NetX and gcjwebplugin.
+ // Do not create new AppContext if we're using NetX and icedteaplugin.
+ // The plugin needs an AppContext too, but it has to be created earlier.
if (context && !isPlugin)
- new Reflect().invokeStatic("sun.awt.SunToolkit", "createNewAppContext");
+ SunToolkit.createNewAppContext();
if (isPlugin) {
// Do not display download indicators if we're using gcjwebplugin.
diff -r be9262040bbc -r 519a6f970eba netx/net/sourceforge/jnlp/NetxPanel.java
--- a/netx/net/sourceforge/jnlp/NetxPanel.java Thu Oct 14 13:25:44 2010 +0200
+++ b/netx/net/sourceforge/jnlp/NetxPanel.java Thu Oct 14 15:59:52 2010 -0400
@@ -22,6 +22,7 @@
package net.sourceforge.jnlp;
+import net.sourceforge.jnlp.runtime.AppThreadGroup;
import net.sourceforge.jnlp.runtime.AppletInstance;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
@@ -29,6 +30,7 @@ import java.util.Hashtable;
import java.util.Hashtable;
import sun.applet.AppletViewerPanel;
+import sun.awt.SunToolkit;
/**
* This panel calls into netx to run an applet, and pipes the display
@@ -54,6 +56,18 @@ public class NetxPanel extends AppletVie
this(documentURL, atts);
this.exitOnFailure = exitOnFailure;
this.appletAlive = true;
+ }
+
+ @Override
+ public void run() {
+ /*
+ * create an AppContext for this thread associated with this particular
+ * plugin instance (which runs in a different thread group from the rest
+ * of the plugin).
+ */
+ SunToolkit.createNewAppContext();
+
+ super.run();
}
//Overriding to use Netx classloader. You might need to relax visibility
@@ -125,9 +139,17 @@ public class NetxPanel extends AppletVie
}
}
+ /**
+ * Creates a new Thread (in a new applet-specific ThreadGroup) for running
+ * the applet
+ */
// Reminder: Relax visibility in sun.applet.AppletPanel
protected synchronized void createAppletThread() {
- handler = new Thread(this);
+ // when this was being done (incorrectly) in Launcher, the call was
+ // new AppThreadGroup(mainGroup, file.getTitle());
+ ThreadGroup tg = new AppThreadGroup(Launcher.mainGroup,
+ this.documentURL.toString());
+ handler = new Thread(tg, this);
handler.start();
}
diff -r be9262040bbc -r 519a6f970eba netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java
--- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Thu Oct 14 13:25:44 2010 +0200
+++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Thu Oct 14 15:59:52 2010 -0400
@@ -26,6 +26,8 @@ import java.security.ProtectionDomain;
import java.security.ProtectionDomain;
import javax.swing.event.EventListenerList;
+
+import sun.awt.AppContext;
import net.sourceforge.jnlp.JNLPFile;
import net.sourceforge.jnlp.PropertyDesc;
@@ -61,6 +63,16 @@ public class ApplicationInstance {
/** the classloader */
private ClassLoader loader;
+ /**
+ * Every application/applet gets its own AppContext. This allows us to do
+ * things like have two different look and feels for two different applets
+ * (running in the same VM), allows untrusted programs to manipulate the
+ * event queue (safely) and (possibly) more.<p>
+ *
+ * It is set to the AppContext which created this ApplicationInstance
+ */
+ private AppContext appContext;
+
/** whether the application has stopped running */
private boolean stopped = false;
@@ -74,13 +86,15 @@ public class ApplicationInstance {
private boolean isSigned = false;
/**
- * Create an application instance for the file.
+ * Create an application instance for the file. This should be done in the
+ * appropriate {@link ThreadGroup} only.
*/
public ApplicationInstance(JNLPFile file, ThreadGroup group, ClassLoader loader) {
this.file = file;
this.group = group;
this.loader = loader;
this.isSigned = ((JNLPClassLoader) loader).getSigning();
+ this.appContext = AppContext.getAppContext();
}
/**
@@ -297,4 +311,9 @@ public class ApplicationInstance {
public boolean isSigned() {
return isSigned;
}
+
+ public AppContext getAppContext() {
+ return appContext;
+ }
+
}
diff -r be9262040bbc -r 519a6f970eba netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java
--- a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java Thu Oct 14 13:25:44 2010 +0200
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java Thu Oct 14 15:59:52 2010 -0400
@@ -37,6 +37,8 @@ import net.sourceforge.jnlp.security.Sec
import net.sourceforge.jnlp.security.SecurityWarningDialog;
import net.sourceforge.jnlp.services.ServiceUtil;
import net.sourceforge.jnlp.util.WeakList;
+import sun.awt.AWTSecurityManager;
+import sun.awt.AppContext;
import sun.security.util.SecurityConstants;
/**
@@ -53,7 +55,7 @@ import sun.security.util.SecurityConstan
* @author <a href="mailto:jmaxwell at users.sourceforge.net">Jon A. Maxwell (JAM)</a> - initial author
* @version $Revision: 1.17 $
*/
-class JNLPSecurityManager extends SecurityManager {
+class JNLPSecurityManager extends AWTSecurityManager {
// todo: some apps like JDiskReport can close the VM even when
// an exit class is set - fix!
@@ -108,6 +110,13 @@ class JNLPSecurityManager extends Securi
private boolean exitAllowed = true;
/**
+ * The AppContext of the main application (netx). We need to store this here
+ * so we can return this when no code from an external application is
+ * running on the thread
+ */
+ private AppContext mainAppContext;
+
+ /**
* Creates a JNLP SecurityManager.
*/
JNLPSecurityManager() {
@@ -118,6 +127,8 @@ class JNLPSecurityManager extends Securi
if (!JNLPRuntime.isHeadless())
new JWindow().getOwner();
+
+ mainAppContext = AppContext.getAppContext();
}
/**
@@ -501,4 +512,30 @@ class JNLPSecurityManager extends Securi
exitAllowed = false;
}
+ /**
+ * This returns the appropriate {@link AppContext}. Hooks in AppContext
+ * check if the current {@link SecurityManager} is an instance of
+ * AWTSecurityManager and if so, call this method to give it a chance to
+ * return the appropriate appContext based on the application that is
+ * running.<p>
+ *
+ * This can be called from any thread (possibly a swing thread) to find out
+ * the AppContext for the thread (which may correspond to a particular
+ * applet).
+ */
+ @Override
+ public AppContext getAppContext() {
+ ApplicationInstance app = getApplication();
+ if (app == null) {
+ /*
+ * if we cannot find an application based on the code on the stack,
+ * then assume it is the main application
+ */
+ return mainAppContext;
+ } else {
+ return app.getAppContext();
+ }
+
+ }
+
}
More information about the distro-pkg-dev
mailing list