changeset 229:0256de6a4bf6

Prevent applet from shutting down down if another tab with the same page is opened and closed.
author Deepak Bhole <dbhole@redhat.com>
date Mon, 02 May 2011 14:33:32 -0400
parents a0a061a0560d
children 85cf7fb25642
files ChangeLog plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 28 16:23:11 2011 -0400
+++ b/ChangeLog	Mon May 02 14:33:32 2011 -0400
@@ -1,3 +1,11 @@
+2011-05-02  Deepak Bhole <dbhole@redhat.com>
+
+	* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+	(appletClose): Do not try to stop threads, now that the loader is shared
+	and the thread group for applets on a page is identical. Call dispose from
+	invokeAndWait.
+	(appletSystemExit): Exit the VM when called.
+
 2011-04-28  Omair Majid  <omajid@redhat.com>
 
 	* Makefile.am (javaws, itweb_settings): New variables.
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Thu Apr 28 16:23:11 2011 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Mon May 02 14:33:32 2011 -0400
@@ -1605,15 +1605,26 @@
                 if (cl instanceof JNLPClassLoader.CodeBaseClassLoader)
                     cl = ((JNLPClassLoader.CodeBaseClassLoader) cl).getParentJNLPClassLoader();
 
-                ThreadGroup tg = ((JNLPClassLoader) cl).getApplication().getThreadGroup();
-
                 appletShutdown(p);
                 appletPanels.removeElement(p);
-                dispose();
+                
+                /* TODO: Applets don't always shut down nicely. We 
+                 * need to find a proper way to forcibly closing all threads 
+                 * an applet starts during its lifetime 
+                 */
 
-                if (tg.activeCount() > 0)
-                    tg.stop();
+                try {
+                    SwingUtilities.invokeAndWait(new Runnable() {
+                        public void run() {
+                            dispose();
+                        }
+                    });
+                } catch (Exception e) { // ignore, we are just disposing it
+                }
 
+                // If there are no more applets running, exit the VM
+                // TODO: There is a possible race condition here as count 
+                // can be 0 when an applet is in the initialization phase 
                 if (countApplets() == 0) {
                     appletSystemExit();
                 }
@@ -1624,12 +1635,10 @@
     }
 
     /**
-     * Exit the program.
-     * Exit from the program (if not stand alone) - do no clean-up
+     * This function should be called to halt the VM when all applets are destroyed.
      */
     private void appletSystemExit() {
-        // Do nothing. Exit is handled by another
-        // block of code, called when _all_ applets are gone
+        System.exit(0);
     }
 
     /**