aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorAdam Domurad <[email protected]>2013-06-03 12:25:50 -0400
committerAdam Domurad <[email protected]>2013-06-03 12:25:50 -0400
commit2b421696ee6061ca529ebd9a26d6cd47203bfc9f (patch)
tree5cc26f14567ba2d413a73318f8e431d0f32faa8f /plugin
parent0fa3a1ac219c218d2c489b10c8ce70a108c50b10 (diff)
Handle resizing plugin message more robustly by not blocking worker thread
Diffstat (limited to 'plugin')
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginAppletViewer.java83
1 files changed, 46 insertions, 37 deletions
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
index 8aab9ac..b66f52b 100644
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
@@ -677,53 +677,62 @@ public class PluginAppletViewer extends XEmbeddedFrame
PluginDebug.debug("Applet panel ", panel, " initialized");
}
- public void handleMessage(int reference, String message) {
- if (message.startsWith("width")) {
+ /* Resizes an applet panel, waiting for the applet to initialze.
+ * Should be done asynchronously to avoid the chance of deadlock. */
+ private void resizeAppletPanel(final int width, final int height) {
+ // Wait for panel to come alive
+ waitForAppletInit(panel);
- // Wait for panel to come alive
- waitForAppletInit(panel);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ panel.updateSizeInAtts(height, width);
- // 0 => width, 1=> width_value, 2 => height, 3=> height_value
- String[] dimMsg = message.split(" ");
+ setSize(width, height);
- final int height = Integer.parseInt(dimMsg[3]);
- final int width = Integer.parseInt(dimMsg[1]);
+ // There is a rather odd drawing bug whereby resizing
+ // the panel makes no difference on initial call
+ // because the panel thinks that it is already the
+ // right size. Validation has no effect there either.
+ // So we work around by setting size to 1, validating,
+ // and then setting to the right size and validating
+ // again. This is not very efficient, and there is
+ // probably a better way -- but resizing happens
+ // quite infrequently, so for now this is how we do it
- panel.updateSizeInAtts(height, width);
+ panel.setSize(1, 1);
+ panel.validate();
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
+ panel.setSize(width, height);
+ panel.validate();
- setSize(width, height);
+ panel.applet.resize(width, height);
+ panel.applet.validate();
+ }
+ });
+ }
- // There is a rather odd drawing bug whereby resizing
- // the panel makes no difference on initial call
- // because the panel thinks that it is already the
- // right size. Validation has no effect there either.
- // So we work around by setting size to 1, validating,
- // and then setting to the right size and validating
- // again. This is not very efficient, and there is
- // probably a better way -- but resizing happens
- // quite infrequently, so for now this is how we do it
+ public void handleMessage(int reference, String message) {
+ if (message.startsWith("width")) {
- panel.setSize(1, 1);
- panel.validate();
+ // 0 => width, 1=> width_value, 2 => height, 3=> height_value
+ String[] dimMsg = message.split(" ");
- panel.setSize(width, height);
- panel.validate();
+ final int width = Integer.parseInt(dimMsg[1]);
+ final int height = Integer.parseInt(dimMsg[3]);
- panel.applet.resize(width, height);
- panel.applet.validate();
- }
- });
- } catch (InterruptedException e) {
- // do nothing
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // do nothing
- e.printStackTrace();
- }
+ /* Resize the applet asynchronously, to avoid the chance of
+ * deadlock while waiting for the applet to initialize.
+ *
+ * In general, worker threads should spawn new threads for any blocking operations. */
+ Thread resizeAppletThread = new Thread("resizeAppletThread") {
+ @Override
+ public void run() {
+ resizeAppletPanel(width, height);
+ }
+ };
+
+ /* Let it eventually complete */
+ resizeAppletThread.start();
} else if (message.startsWith("GetJavaObject")) {