aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/icedteanp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/icedteanp')
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSException.java4
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSObject.java82
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java3
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSProxy.java27
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSRunnable.java46
-rw-r--r--plugin/icedteanp/java/netscape/javascript/JSUtil.java17
-rw-r--r--plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java2
-rw-r--r--plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java41
-rw-r--r--plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java10
-rw-r--r--plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java6
-rw-r--r--plugin/icedteanp/java/sun/applet/JavaConsole.java8
-rw-r--r--plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java222
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java1958
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginAppletViewer.java3622
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginCallRequest.java22
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java28
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginClassLoader.java15
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java19
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginCookieManager.java43
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginDebug.java9
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginException.java18
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginMain.java155
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java361
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java204
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginObjectStore.java24
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java30
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginProxySelector.java4
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginStreamHandler.java585
-rw-r--r--plugin/icedteanp/java/sun/applet/RequestQueue.java12
-rw-r--r--plugin/icedteanp/java/sun/applet/TestEnv.java13
-rw-r--r--plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java9
31 files changed, 3788 insertions, 3811 deletions
diff --git a/plugin/icedteanp/java/netscape/javascript/JSException.java b/plugin/icedteanp/java/netscape/javascript/JSException.java
index 5fbb750..35d72a7 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSException.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSException.java
@@ -44,8 +44,7 @@ package netscape.javascript;
* returns an error.
*/
-public
-class JSException extends RuntimeException {
+public class JSException extends RuntimeException {
public static final int EXCEPTION_TYPE_EMPTY = -1;
public static final int EXCEPTION_TYPE_VOID = 0;
public static final int EXCEPTION_TYPE_OBJECT = 1;
@@ -140,4 +139,3 @@ class JSException extends RuntimeException {
}
}
-
diff --git a/plugin/icedteanp/java/netscape/javascript/JSObject.java b/plugin/icedteanp/java/netscape/javascript/JSObject.java
index 31cd973..293f2be 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSObject.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSObject.java
@@ -55,8 +55,6 @@ import java.security.BasicPermission;
import sun.applet.PluginAppletViewer;
import sun.applet.PluginDebug;
-
-
/**
* JSObject allows Java to manipulate objects that are
* defined in JavaScript.
@@ -90,17 +88,17 @@ import sun.applet.PluginDebug;
*/
public final class JSObject {
/* the internal object data */
- private long internal;
+ private long internal;
/**
* initialize
*/
private static void initClass() {
- PluginDebug.debug ("JSObject.initClass");
+ PluginDebug.debug("JSObject.initClass");
}
static {
- PluginDebug.debug ("JSObject INITIALIZER");
+ PluginDebug.debug("JSObject INITIALIZER");
}
/**
@@ -131,20 +129,21 @@ public final class JSObject {
// Although this check is inefficient, it should happen only once
// during applet init, so we look the other way
- StackTraceElement[] stack = Thread.currentThread().getStackTrace();
+ StackTraceElement[] stack = Thread.currentThread().getStackTrace();
boolean mayProceed = false;
- for (int i=0; i < stack.length; i++) {
+ for (int i = 0; i < stack.length; i++) {
if (stack[i].getClassName().equals("netscape.javascript.JSObject") &&
- stack[i].getMethodName().equals("getWindow")) {
+ stack[i].getMethodName().equals("getWindow")) {
mayProceed = true;
}
}
- if (!mayProceed) throw ace;
+ if (!mayProceed)
+ throw ace;
}
- PluginDebug.debug ("JSObject long CONSTRUCTOR");
+ PluginDebug.debug("JSObject long CONSTRUCTOR");
internal = jsobj_addr;
}
@@ -152,36 +151,31 @@ public final class JSObject {
* Retrieves a named member of a JavaScript object.
* Equivalent to "this.<i>name</i>" in JavaScript.
*/
- public Object getMember(String name)
- {
- PluginDebug.debug ("JSObject.getMember " + name);
+ public Object getMember(String name) {
+ PluginDebug.debug("JSObject.getMember " + name);
Object o = PluginAppletViewer.getMember(internal, name);
- PluginDebug.debug ("JSObject.getMember GOT " + o);
+ PluginDebug.debug("JSObject.getMember GOT " + o);
return o;
}
-
/**
* Retrieves an indexed member of a JavaScript object.
* Equivalent to "this[<i>index</i>]" in JavaScript.
*/
// public Object getMember(int index) { return getSlot(index); }
- public Object getSlot(int index)
- {
- PluginDebug.debug ("JSObject.getSlot " + index);
+ public Object getSlot(int index) {
+ PluginDebug.debug("JSObject.getSlot " + index);
return PluginAppletViewer.getSlot(internal, index);
}
-
/**
* Sets a named member of a JavaScript object.
* Equivalent to "this.<i>name</i> = <i>value</i>" in JavaScript.
*/
- public void setMember(String name, Object value)
- {
- PluginDebug.debug ("JSObject.setMember " + name + " " + value);
+ public void setMember(String name, Object value) {
+ PluginDebug.debug("JSObject.setMember " + name + " " + value);
PluginAppletViewer.setMember(internal, name, value);
}
@@ -193,103 +187,87 @@ public final class JSObject {
// public void setMember(int index, Object value) {
// setSlot(index, value);
// }
- public void setSlot(int index, Object value)
- {
- PluginDebug.debug ("JSObject.setSlot " + index + " " + value);
+ public void setSlot(int index, Object value) {
+ PluginDebug.debug("JSObject.setSlot " + index + " " + value);
PluginAppletViewer.setSlot(internal, index, value);
}
-
// TODO: toString, finalize.
/**
* Removes a named member of a JavaScript object.
*/
- public void removeMember(String name)
- {
- PluginDebug.debug ("JSObject.removeMember " + name);
+ public void removeMember(String name) {
+ PluginDebug.debug("JSObject.removeMember " + name);
PluginAppletViewer.removeMember(internal, name);
}
-
/**
* Calls a JavaScript method.
* Equivalent to "this.<i>methodName</i>(<i>args</i>[0], <i>args</i>[1], ...)" in JavaScript.
*/
- public Object call(String methodName, Object args[])
- {
+ public Object call(String methodName, Object args[]) {
if (args == null)
- args = new Object[0];
+ args = new Object[0];
- PluginDebug.debug ("JSObject.call " + methodName);
+ PluginDebug.debug("JSObject.call " + methodName);
for (int i = 0; i < args.length; i++)
- PluginDebug.debug (" " + args[i]);
+ PluginDebug.debug(" " + args[i]);
PluginDebug.debug("");
return PluginAppletViewer.call(internal, methodName, args);
}
-
/**
* Evaluates a JavaScript expression. The expression is a string
* of JavaScript source code which will be evaluated in the context
* given by "this".
*/
- public Object eval(String s)
- {
+ public Object eval(String s) {
PluginDebug.debug("JSObject.eval " + s);
return PluginAppletViewer.eval(internal, s);
}
-
/**
* Converts a JSObject to a String.
*/
- public String toString()
- {
+ public String toString() {
PluginDebug.debug("JSObject.toString");
return PluginAppletViewer.javascriptToString(internal);
}
-
// should use some sort of identifier rather than String
// is "property" the right word?
// native String[] listProperties();
-
/**
* get a JSObject for the window containing the given applet
*/
- public static JSObject getWindow(Applet applet)
- {
+ public static JSObject getWindow(Applet applet) {
PluginDebug.debug("JSObject.getWindow");
// FIXME: handle long case as well.
long internal = 0;
internal = ((PluginAppletViewer)
applet.getAppletContext()).getWindow();
- PluginDebug.debug ("GOT IT: " + internal);
+ PluginDebug.debug("GOT IT: " + internal);
return new JSObject(internal);
}
-
/**
* Finalization decrements the reference count on the corresponding
* JavaScript object.
*/
- protected void finalize()
- {
+ protected void finalize() {
PluginDebug.debug("JSObject.finalize ");
PluginAppletViewer.JavaScriptFinalize(internal);
}
-
/**
* Override java.lang.Object.equals() because identity is not preserved
* with instances of JSObject.
*/
- public boolean equals(Object obj)
- {
+ public boolean equals(Object obj) {
PluginDebug.debug("JSObject.equals " + obj);
return false;
diff --git a/plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java b/plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java
index f8e510f..b955b6c 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java
@@ -34,12 +34,11 @@ or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
+
package netscape.javascript;
import java.security.BasicPermission;
-
public class JSObjectCreatePermission extends BasicPermission {
public JSObjectCreatePermission() {
super("JSObjectCreate");
diff --git a/plugin/icedteanp/java/netscape/javascript/JSProxy.java b/plugin/icedteanp/java/netscape/javascript/JSProxy.java
index e4f1f6e..c9ac50e 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSProxy.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSProxy.java
@@ -43,16 +43,25 @@
*/
package netscape.javascript;
+
import java.applet.Applet;
public interface JSProxy {
- Object getMember(JSObject jso, String name);
- Object getSlot(JSObject jso, int index);
- void setMember(JSObject jso, String name, Object value);
- void setSlot(JSObject jso, int index, Object value);
- void removeMember(JSObject jso, String name);
- Object call(JSObject jso, String methodName, Object args[]);
- Object eval(JSObject jso, String s);
- String toString(JSObject jso);
- JSObject getWindow(Applet applet);
+ Object getMember(JSObject jso, String name);
+
+ Object getSlot(JSObject jso, int index);
+
+ void setMember(JSObject jso, String name, Object value);
+
+ void setSlot(JSObject jso, int index, Object value);
+
+ void removeMember(JSObject jso, String name);
+
+ Object call(JSObject jso, String methodName, Object args[]);
+
+ Object eval(JSObject jso, String s);
+
+ String toString(JSObject jso);
+
+ JSObject getWindow(Applet applet);
}
diff --git a/plugin/icedteanp/java/netscape/javascript/JSRunnable.java b/plugin/icedteanp/java/netscape/javascript/JSRunnable.java
index 8f1cf72..df245a7 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSRunnable.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSRunnable.java
@@ -45,28 +45,28 @@ import sun.applet.PluginDebug;
* Runs a JavaScript object with a run() method in a separate thread.
*/
public class JSRunnable implements Runnable {
- private JSObject runnable;
+ private JSObject runnable;
- public JSRunnable(JSObject runnable) {
- this.runnable = runnable;
- synchronized(this) {
- new Thread(this).start();
- try {
- this.wait();
- } catch (InterruptedException ie) {
- }
- }
- }
-
- public void run() {
- try {
- runnable.call("run", null);
- synchronized(this) {
- notifyAll();
- }
- } catch (Throwable t) {
- PluginDebug.debug(t.toString());
- t.printStackTrace(System.err);
- }
- }
+ public JSRunnable(JSObject runnable) {
+ this.runnable = runnable;
+ synchronized (this) {
+ new Thread(this).start();
+ try {
+ this.wait();
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+
+ public void run() {
+ try {
+ runnable.call("run", null);
+ synchronized (this) {
+ notifyAll();
+ }
+ } catch (Throwable t) {
+ PluginDebug.debug(t.toString());
+ t.printStackTrace(System.err);
+ }
+ }
}
diff --git a/plugin/icedteanp/java/netscape/javascript/JSUtil.java b/plugin/icedteanp/java/netscape/javascript/JSUtil.java
index 47bc6e6..14dfda0 100644
--- a/plugin/icedteanp/java/netscape/javascript/JSUtil.java
+++ b/plugin/icedteanp/java/netscape/javascript/JSUtil.java
@@ -39,21 +39,22 @@
/* ** */
package netscape.javascript;
+
import java.io.*;
public class JSUtil {
/* Return the stack trace of an exception or error as a String */
public static String getStackTrace(Throwable t) {
- ByteArrayOutputStream captureStream;
- PrintWriter p;
-
- captureStream = new ByteArrayOutputStream();
- p = new PrintWriter(captureStream);
+ ByteArrayOutputStream captureStream;
+ PrintWriter p;
+
+ captureStream = new ByteArrayOutputStream();
+ p = new PrintWriter(captureStream);
- t.printStackTrace(p);
- p.flush();
+ t.printStackTrace(p);
+ p.flush();
- return captureStream.toString();
+ return captureStream.toString();
}
}
diff --git a/plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java b/plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java
index c7ce827..abaeb55 100644
--- a/plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java
+++ b/plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package netscape.security;
-public class ForbiddenTargetException extends RuntimeException{
+public class ForbiddenTargetException extends RuntimeException {
private static final long serialVersionUID = 1271219852541058396L;
diff --git a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java
index 6e0defd..c758bac 100644
--- a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java
+++ b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java
@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
import java.security.AccessControlContext;
@@ -43,30 +42,30 @@ import java.util.HashMap;
public class AppletSecurityContextManager {
- // Context identifier -> PluginAppletSecurityContext object.
- // FIXME: make private
- private static HashMap<Integer, PluginAppletSecurityContext> contexts =
- new HashMap<Integer, PluginAppletSecurityContext>();
+ // Context identifier -> PluginAppletSecurityContext object.
+ // FIXME: make private
+ private static HashMap<Integer, PluginAppletSecurityContext> contexts =
+ new HashMap<Integer, PluginAppletSecurityContext>();
- public static void addContext(int identifier, PluginAppletSecurityContext context) {
- contexts.put(identifier, context);
- }
+ public static void addContext(int identifier, PluginAppletSecurityContext context) {
+ contexts.put(identifier, context);
+ }
- public static PluginAppletSecurityContext getSecurityContext(int identifier) {
- return contexts.get(identifier);
- }
+ public static PluginAppletSecurityContext getSecurityContext(int identifier) {
+ return contexts.get(identifier);
+ }
- public static void dumpStore(int identifier) {
- contexts.get(identifier).dumpStore();
- }
+ public static void dumpStore(int identifier) {
+ contexts.get(identifier).dumpStore();
+ }
- public static void handleMessage(int identifier, int reference, String src, String[] privileges, String message) {
- PluginDebug.debug(identifier + " -- " + src + " -- " + reference + " -- " + message + " CONTEXT= " + contexts.get(identifier));
- AccessControlContext callContext = null;
+ public static void handleMessage(int identifier, int reference, String src, String[] privileges, String message) {
+ PluginDebug.debug(identifier + " -- " + src + " -- " + reference + " -- " + message + " CONTEXT= " + contexts.get(identifier));
+ AccessControlContext callContext = null;
- privileges = privileges != null ? privileges : new String[0];
- callContext = contexts.get(identifier).getAccessControlContext(privileges, src);
+ privileges = privileges != null ? privileges : new String[0];
+ callContext = contexts.get(identifier).getAccessControlContext(privileges, src);
- contexts.get(identifier).handleMessage(reference, src, callContext, message);
- }
+ contexts.get(identifier).handleMessage(reference, src, callContext, message);
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java b/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
index 7a0a623..5d143a6 100644
--- a/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
+++ b/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
@@ -37,27 +37,25 @@ exception statement from your version. */
package sun.applet;
-
public class GetMemberPluginCallRequest extends PluginCallRequest {
Object object = null;
public GetMemberPluginCallRequest(String message, Long reference) {
super(message, reference);
- PluginDebug.debug ("GetMemberPluginCall " + message);
+ PluginDebug.debug("GetMemberPluginCall " + message);
}
public void parseReturn(String message) {
- PluginDebug.debug ("GetMemberParseReturn GOT: " + message);
+ PluginDebug.debug("GetMemberParseReturn GOT: " + message);
String[] args = message.split(" ");
// FIXME: Is it even possible to distinguish between null and void
// here?
if (args[3] != "null" && args[3] != "void")
- object = AppletSecurityContextManager.getSecurityContext(0).getObject(Integer.parseInt(args[3]));
+ object = AppletSecurityContextManager.getSecurityContext(0).getObject(Integer.parseInt(args[3]));
setDone(true);
}
public Object getObject() {
- return this.object;
+ return this.object;
}
}
-
diff --git a/plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java b/plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java
index 9c13726..aa46a86 100644
--- a/plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java
+++ b/plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java
@@ -40,8 +40,6 @@ package sun.applet;
import java.security.AccessControlContext;
import java.security.ProtectionDomain;
-
-
public class GetWindowPluginCallRequest extends PluginCallRequest {
// FIXME: look into int vs long JavaScript internal values.
long internal;
@@ -51,7 +49,7 @@ public class GetWindowPluginCallRequest extends PluginCallRequest {
}
public void parseReturn(String message) {
- PluginDebug.debug ("GetWindowParseReturn GOT: " + message);
+ PluginDebug.debug("GetWindowParseReturn GOT: " + message);
String[] args = message.split(" ");
// FIXME: add thread ID to messages to support multiple
// threads using the netscape.javascript package.
@@ -60,6 +58,6 @@ public class GetWindowPluginCallRequest extends PluginCallRequest {
}
public Long getObject() {
- return this.internal;
+ return this.internal;
}
}
diff --git a/plugin/icedteanp/java/sun/applet/JavaConsole.java b/plugin/icedteanp/java/sun/applet/JavaConsole.java
index ad255bd..ae33343 100644
--- a/plugin/icedteanp/java/sun/applet/JavaConsole.java
+++ b/plugin/icedteanp/java/sun/applet/JavaConsole.java
@@ -267,9 +267,9 @@ public class JavaConsole {
System.out.println(" ----");
System.out.println("Available Classloaders: ");
Set<String> loaders = PluginAppletSecurityContext.getLoaderInfo().keySet();
- for (String loader: loaders) {
+ for (String loader : loaders) {
System.out.println(loader + "\n"
- + " codebase = "
+ + " codebase = "
+ PluginAppletSecurityContext.getLoaderInfo().get(loader));
}
System.out.println(" ----");
@@ -278,7 +278,7 @@ public class JavaConsole {
private void printMemoryInfo() {
System.out.println(" ----- ");
System.out.println(" Memory Info:");
- System.out.println(" Max Memory: "
+ System.out.println(" Max Memory: "
+ String.format("%1$10d", Runtime.getRuntime().maxMemory()));
System.out.println(" Total Memory: "
+ String.format("%1$10d", Runtime.getRuntime().totalMemory()));
@@ -304,7 +304,7 @@ public class JavaConsole {
final JavaConsole console = new JavaConsole();
- boolean toShowConsole = false;
+ boolean toShowConsole = false;
for (int i = 0; i < args.length; i++) {
if (args[i] == "--show-console") {
diff --git a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
index a1b3147..cd1801a 100644
--- a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
+++ b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
@@ -197,7 +197,8 @@ public class MethodOverloadResolver {
suppliedParam, paramTypeClass);
methodCost += (Integer) costAndCastedObj[0];
- if ((Integer) costAndCastedObj[0] < 0) break;
+ if ((Integer) costAndCastedObj[0] < 0)
+ break;
Object castedObj = paramTypeClass.isPrimitive() ? costAndCastedObj[1]
: paramTypeClass.cast(costAndCastedObj[1]);
@@ -218,7 +219,7 @@ public class MethodOverloadResolver {
}
if ((methodCost > 0 && methodCost < lowestCost) ||
- paramTypes.length == 0) {
+ paramTypes.length == 0) {
ret = methodAndArgs;
lowestCost = methodCost;
}
@@ -261,7 +262,8 @@ public class MethodOverloadResolver {
suppliedParam, paramTypeClass);
constructorCost += (Integer) costAndCastedObj[0];
- if ((Integer) costAndCastedObj[0] < 0) break;
+ if ((Integer) costAndCastedObj[0] < 0)
+ break;
Object castedObj = paramTypeClass.isPrimitive() ? costAndCastedObj[1]
: paramTypeClass.cast(costAndCastedObj[1]);
@@ -282,7 +284,7 @@ public class MethodOverloadResolver {
}
if ((constructorCost > 0 && constructorCost < lowestCost) ||
- paramTypes.length == 0) {
+ paramTypes.length == 0) {
ret = constructorAndArgs;
lowestCost = constructorCost;
}
@@ -297,14 +299,14 @@ public class MethodOverloadResolver {
Integer cost = new Integer(0);
Object castedObj;
- Class<?> suppliedParamClass = suppliedParam != null ? suppliedParam.getClass() : null ;
+ Class<?> suppliedParamClass = suppliedParam != null ? suppliedParam.getClass() : null;
// Either both are an array, or neither are
boolean suppliedParamIsArray = suppliedParamClass != null && suppliedParamClass.isArray();
if (paramTypeClass.isArray() != suppliedParamIsArray &&
- !paramTypeClass.equals(Object.class) &&
+ !paramTypeClass.equals(Object.class) &&
!paramTypeClass.equals(String.class)) {
- ret[0] = Integer.MIN_VALUE; // Not allowed
+ ret[0] = Integer.MIN_VALUE; // Not allowed
ret[1] = suppliedParam;
return ret;
}
@@ -317,7 +319,7 @@ public class MethodOverloadResolver {
if (paramTypeClass.isArray()) {
Object newArray = Array.newInstance(paramTypeClass.getComponentType(), Array.getLength(suppliedParam));
- for (int i=0; i < Array.getLength(suppliedParam); i++) {
+ for (int i = 0; i < Array.getLength(suppliedParam); i++) {
Object original = Array.get(suppliedParam, i);
// When dealing with arrays, we represent empty slots with
@@ -331,7 +333,7 @@ public class MethodOverloadResolver {
Object[] costAndCastedObject = getCostAndCastedObject(original, paramTypeClass.getComponentType());
if ((Integer) costAndCastedObject[0] < 0) {
- ret[0] = Integer.MIN_VALUE; // Not allowed
+ ret[0] = Integer.MIN_VALUE; // Not allowed
ret[1] = suppliedParam;
return ret;
}
@@ -364,15 +366,14 @@ public class MethodOverloadResolver {
cost += 1; // Numeric type to the analogous Java primitive type
castedObj = suppliedParam; // Let auto-boxing handle it
} else if (suppliedParamClass.equals(paramTypeClass)) {
- cost += 3; // Class type to Class type where the types are equal
- castedObj = suppliedParam;
+ cost += 3; // Class type to Class type where the types are equal
+ castedObj = suppliedParam;
} else if (isNum(suppliedParam) &&
(paramTypeClass.isPrimitive() ||
- java.lang.Number.class.isAssignableFrom(paramTypeClass) ||
- java.lang.Character.class.isAssignableFrom(paramTypeClass) ||
+ java.lang.Number.class.isAssignableFrom(paramTypeClass) ||
+ java.lang.Character.class.isAssignableFrom(paramTypeClass) ||
java.lang.Byte.class.isAssignableFrom(paramTypeClass)
- )
- ) {
+ )) {
cost += 4; // Numeric type to a different primitive type
if (suppliedParam.toString().equals("true"))
@@ -389,10 +390,9 @@ public class MethodOverloadResolver {
} else if (suppliedParam instanceof java.lang.String &&
isNum(suppliedParam) &&
(paramTypeClass.isInstance(java.lang.Number.class) ||
- paramTypeClass.isInstance(java.lang.Character.class) ||
- paramTypeClass.isInstance(java.lang.Byte.class) ||
- paramTypeClass.isPrimitive())
- ) {
+ paramTypeClass.isInstance(java.lang.Character.class) ||
+ paramTypeClass.isInstance(java.lang.Byte.class) ||
+ paramTypeClass.isPrimitive())) {
cost += 5; // String to numeric type
if (suppliedParam.toString().equals("true"))
@@ -404,10 +404,9 @@ public class MethodOverloadResolver {
castedObj = (char) Short.decode(suppliedParam.toString()).shortValue();
else
castedObj = getNum(suppliedParam.toString(), paramTypeClass);
- } else if (suppliedParam instanceof java.lang.String &&
+ } else if (suppliedParam instanceof java.lang.String &&
(paramTypeClass.equals(java.lang.Boolean.class) ||
- paramTypeClass.equals(java.lang.Boolean.TYPE))
- ){
+ paramTypeClass.equals(java.lang.Boolean.TYPE))) {
cost += 5; // Same cost as above
castedObj = new Boolean(suppliedParam.toString().length() > 0);
@@ -437,7 +436,7 @@ public class MethodOverloadResolver {
Method[] allMethods = c.getMethods();
ArrayList<Method> matchingMethods = new ArrayList<Method>(5);
- for (Method m: allMethods) {
+ for (Method m : allMethods) {
if (m.getName().equals(name) && m.getParameterTypes().length == paramCount)
matchingMethods.add(m);
}
@@ -449,7 +448,7 @@ public class MethodOverloadResolver {
Constructor[] allConstructors = c.getConstructors();
ArrayList<Constructor> matchingConstructors = new ArrayList<Constructor>(5);
- for (Constructor cs: allConstructors) {
+ for (Constructor cs : allConstructors) {
if (cs.getParameterTypes().length == paramCount)
matchingConstructors.add(cs);
}
@@ -480,7 +479,7 @@ public class MethodOverloadResolver {
return o.getClass();
}
- private static boolean isNum (Object o) {
+ private static boolean isNum(Object o) {
if (o instanceof java.lang.Number)
return true;
@@ -497,18 +496,19 @@ public class MethodOverloadResolver {
try {
Long.parseLong((String) o); // whole number test
return true;
- } catch (NumberFormatException nfe) {}
+ } catch (NumberFormatException nfe) {
+ }
try {
Float.parseFloat((String) o); // decimal
return true;
- } catch (NumberFormatException nfe) {}
-
+ } catch (NumberFormatException nfe) {
+ }
return false;
}
- private static Number getNum (String s, Class<?> c) throws NumberFormatException {
+ private static Number getNum(String s, Class<?> c) throws NumberFormatException {
Number n;
if (s.contains("."))
@@ -518,39 +518,39 @@ public class MethodOverloadResolver {
// See if we need to collapse first
if (c.equals(java.lang.Integer.class) ||
- c.equals(java.lang.Integer.TYPE)) {
+ c.equals(java.lang.Integer.TYPE)) {
return n.intValue();
}
if (c.equals(java.lang.Long.class) ||
- c.equals(java.lang.Long.TYPE)) {
+ c.equals(java.lang.Long.TYPE)) {
return n.longValue();
}
if (c.equals(java.lang.Short.class) ||
- c.equals(java.lang.Short.TYPE)) {
+ c.equals(java.lang.Short.TYPE)) {
return n.shortValue();
}
if (c.equals(java.lang.Float.class) ||
- c.equals(java.lang.Float.TYPE)) {
+ c.equals(java.lang.Float.TYPE)) {
return n.floatValue();
}
if (c.equals(java.lang.Double.class) ||
- c.equals(java.lang.Double.TYPE)) {
+ c.equals(java.lang.Double.TYPE)) {
return n.doubleValue();
}
if (c.equals(java.lang.Byte.class) ||
- c.equals(java.lang.Byte.TYPE)) {
+ c.equals(java.lang.Byte.TYPE)) {
return n.byteValue();
}
return n;
}
- private static String printList (Object[] oList) {
+ private static String printList(Object[] oList) {
String ret = "";
@@ -562,7 +562,7 @@ public class MethodOverloadResolver {
ret += oStr;
ret += ", ";
}
- ret = ret.substring(0, ret.length()-2); // remove last ", "
+ ret = ret.substring(0, ret.length() - 2); // remove last ", "
ret += " }";
return ret;
@@ -573,7 +573,7 @@ public class MethodOverloadResolver {
String ret = new String();
- for (int i=0; i < Array.getLength(array); i++) {
+ for (int i = 0; i < Array.getLength(array); i++) {
Object element = Array.get(array, i);
if (element != null) {
@@ -600,97 +600,147 @@ public class MethodOverloadResolver {
class FooClass {
- public FooClass() {}
+ public FooClass() {
+ }
- public FooClass(Boolean b, int i) {}
+ public FooClass(Boolean b, int i) {
+ }
- public FooClass(Boolean b, Integer i) {}
+ public FooClass(Boolean b, Integer i) {
+ }
- public FooClass(Boolean b, short s) {}
+ public FooClass(Boolean b, short s) {
+ }
- public FooClass(String s, int i) {}
+ public FooClass(String s, int i) {
+ }
- public FooClass(String s, Integer i) {}
+ public FooClass(String s, Integer i) {
+ }
- public FooClass(java.lang.Number num) {}
+ public FooClass(java.lang.Number num) {
+ }
- public FooClass(java.lang.Integer integer) {}
+ public FooClass(java.lang.Integer integer) {
+ }
- public FooClass(long l) {}
+ public FooClass(long l) {
+ }
- public FooClass(double d) {}
+ public FooClass(double d) {
+ }
- public FooClass(float f) {}
+ public FooClass(float f) {
+ }
- public FooClass(JSObject j) {}
+ public FooClass(JSObject j) {
+ }
- public FooClass(BarClass1 b) {}
+ public FooClass(BarClass1 b) {
+ }
- public FooClass(BarClass2 b) {}
+ public FooClass(BarClass2 b) {
+ }
- public FooClass(String s) {}
+ public FooClass(String s) {
+ }
- public FooClass(byte b) {}
+ public FooClass(byte b) {
+ }
- public FooClass(String s, Float f) {}
+ public FooClass(String s, Float f) {
+ }
- public FooClass (int i) {}
+ public FooClass(int i) {
+ }
- public void FooClass() {}
+ public void FooClass() {
+ }
- public void FooClass(boolean b) {}
+ public void FooClass(boolean b) {
+ }
+ public void foo(Boolean b, int i) {
+ }
- public void foo(Boolean b, int i) {}
+ public void foo(Boolean b, Integer i) {
+ }
- public void foo(Boolean b, Integer i) {}
+ public void foo(Boolean b, short s) {
+ }
- public void foo(Boolean b, short s) {}
+ public void foo_string_int(String s, int i) {
+ }
- public void foo_string_int(String s, int i) {}
+ public void foo_string_int(String s, Integer i) {
+ }
- public void foo_string_int(String s, Integer i) {}
+ public void foo_jsobj(JSObject j) {
+ }
- public void foo_jsobj(JSObject j) {}
+ public void foo_jsobj(String s) {
+ }
- public void foo_jsobj(String s) {}
+ public void foo_classtype(java.lang.Number num) {
+ }
- public void foo_classtype(java.lang.Number num) {}
+ public void foo_classtype(java.lang.Integer integer) {
+ }
- public void foo_classtype(java.lang.Integer integer) {}
+ public void foo_multiprim(int i) {
+ }
- public void foo_multiprim(int i) {}
+ public void foo_multiprim(long l) {
+ }
- public void foo_multiprim(long l) {}
+ public void foo_multiprim(float f) {
+ }
- public void foo_multiprim(float f) {}
+ public void foo_multiprim(double d) {
+ }
- public void foo_multiprim(double d) {}
+ public void foo_float(float f) {
+ }
- public void foo_float(float f) {}
+ public void foo_float(String s) {
+ }
- public void foo_float(String s) {}
+ public void foo_float(JSObject j) {
+ }
- public void foo_float(JSObject j) {}
+ public void foo_class(BarClass1 b) {
+ }
- public void foo_class(BarClass1 b) {}
+ public void foo_class(BarClass2 b) {
+ }
- public void foo_class(BarClass2 b) {}
+ public void foo_strandbyteonly(String s) {
+ }
- public void foo_strandbyteonly(String s) {}
+ public void foo_strandbyteonly(byte b) {
+ }
- public void foo_strandbyteonly(byte b) {}
+ public void foo_str_and_float(String s, Float f) {
+ }
- public void foo_str_and_float(String s, Float f) {}
+ public void foo_int_only(int i) {
+ }
- public void foo_int_only (int i) {}
+ public void foo_noargs() {
+ }
- public void foo_noargs() {}
+ public void foo_boolonly(boolean b) {
+ }
+}
+
+class BarClass1 {
+}
- public void foo_boolonly(boolean b) {}
+class BarClass2 extends BarClass1 {
}
-class BarClass1 {}
-class BarClass2 extends BarClass1 {}
-class BarClass3 extends BarClass2 {}
-class JSObject {}
+class BarClass3 extends BarClass2 {
+}
+
+class JSObject {
+}
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
index e2db130..ead88c3 100644
--- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
@@ -64,380 +64,377 @@ import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import netscape.javascript.JSObjectCreatePermission;
-
-
class Signature {
- private String signature;
- private int currentIndex;
- private List<Class> typeList;
- private static final char ARRAY = '[';
- private static final char OBJECT = 'L';
- private static final char SIGNATURE_ENDCLASS = ';';
- private static final char SIGNATURE_FUNC = '(';
- private static final char SIGNATURE_ENDFUNC = ')';
- private static final char VOID = 'V';
- private static final char BOOLEAN = 'Z';
- private static final char BYTE = 'B';
- private static final char CHARACTER = 'C';
- private static final char SHORT = 'S';
- private static final char INTEGER = 'I';
- private static final char LONG = 'J';
- private static final char FLOAT = 'F';
- private static final char DOUBLE = 'D';
-
- private String nextTypeName() {
- char key = signature.charAt(currentIndex++);
-
- switch (key) {
- case ARRAY:
- return nextTypeName() + "[]";
-
- case OBJECT:
- int endClass = signature.indexOf(SIGNATURE_ENDCLASS, currentIndex);
- String retVal = signature.substring(currentIndex, endClass);
- retVal = retVal.replace('/', '.');
- currentIndex = endClass + 1;
- return retVal;
-
- // FIXME: generated bytecode with classes named after
- // primitives will not work in this scheme -- those
- // classes will be incorrectly treated as primitive
- // types.
- case VOID:
- return "void";
- case BOOLEAN:
- return "boolean";
- case BYTE:
- return "byte";
- case CHARACTER:
- return "char";
- case SHORT:
- return "short";
- case INTEGER:
- return "int";
- case LONG:
- return "long";
- case FLOAT:
- return "float";
- case DOUBLE:
- return "double";
-
- case SIGNATURE_ENDFUNC:
- return null;
-
- case SIGNATURE_FUNC:
- return nextTypeName();
-
- default:
- throw new IllegalArgumentException(
+ private String signature;
+ private int currentIndex;
+ private List<Class> typeList;
+ private static final char ARRAY = '[';
+ private static final char OBJECT = 'L';
+ private static final char SIGNATURE_ENDCLASS = ';';
+ private static final char SIGNATURE_FUNC = '(';
+ private static final char SIGNATURE_ENDFUNC = ')';
+ private static final char VOID = 'V';
+ private static final char BOOLEAN = 'Z';
+ private static final char BYTE = 'B';
+ private static final char CHARACTER = 'C';
+ private static final char SHORT = 'S';
+ private static final char INTEGER = 'I';
+ private static final char LONG = 'J';
+ private static final char FLOAT = 'F';
+ private static final char DOUBLE = 'D';
+
+ private String nextTypeName() {
+ char key = signature.charAt(currentIndex++);
+
+ switch (key) {
+ case ARRAY:
+ return nextTypeName() + "[]";
+
+ case OBJECT:
+ int endClass = signature.indexOf(SIGNATURE_ENDCLASS, currentIndex);
+ String retVal = signature.substring(currentIndex, endClass);
+ retVal = retVal.replace('/', '.');
+ currentIndex = endClass + 1;
+ return retVal;
+
+ // FIXME: generated bytecode with classes named after
+ // primitives will not work in this scheme -- those
+ // classes will be incorrectly treated as primitive
+ // types.
+ case VOID:
+ return "void";
+ case BOOLEAN:
+ return "boolean";
+ case BYTE:
+ return "byte";
+ case CHARACTER:
+ return "char";
+ case SHORT:
+ return "short";
+ case INTEGER:
+ return "int";
+ case LONG:
+ return "long";
+ case FLOAT:
+ return "float";
+ case DOUBLE:
+ return "double";
+
+ case SIGNATURE_ENDFUNC:
+ return null;
+
+ case SIGNATURE_FUNC:
+ return nextTypeName();
+
+ default:
+ throw new IllegalArgumentException(
"Invalid JNI signature character '" + key + "'");
- }
}
+ }
- public Signature(String signature, ClassLoader cl) {
- this.signature = signature;
- currentIndex = 0;
- typeList = new ArrayList<Class>(10);
-
- String elem;
- while (currentIndex < signature.length()) {
- elem = nextTypeName();
-
- if (elem == null) // end of signature
- continue;
-
- // System.out.println ("NEXT TYPE: " + elem);
- Class primitive = primitiveNameToType(elem);
- if (primitive != null)
- typeList.add(primitive);
- else {
- // System.out.println ("HERE1");
- int dimsize = 0;
- int n = elem.indexOf('[');
- if (n != -1) {
- // System.out.println ("HERE2");
- String arrayType = elem.substring(0, n);
- dimsize++;
- n = elem.indexOf('[', n + 1);
- // System.out.println ("HERE2.5");
- while (n != -1) {
- dimsize++;
- n = elem.indexOf('[', n + 1);
- // System.out.println ("HERE2.8");
- }
- int[] dims = new int[dimsize];
- primitive = primitiveNameToType(arrayType);
- // System.out.println ("HERE3");
- if (primitive != null) {
- typeList.add(Array.newInstance(primitive, dims)
+ public Signature(String signature, ClassLoader cl) {
+ this.signature = signature;
+ currentIndex = 0;
+ typeList = new ArrayList<Class>(10);
+
+ String elem;
+ while (currentIndex < signature.length()) {
+ elem = nextTypeName();
+
+ if (elem == null) // end of signature
+ continue;
+
+ // System.out.println ("NEXT TYPE: " + elem);
+ Class primitive = primitiveNameToType(elem);
+ if (primitive != null)
+ typeList.add(primitive);
+ else {
+ // System.out.println ("HERE1");
+ int dimsize = 0;
+ int n = elem.indexOf('[');
+ if (n != -1) {
+ // System.out.println ("HERE2");
+ String arrayType = elem.substring(0, n);
+ dimsize++;
+ n = elem.indexOf('[', n + 1);
+ // System.out.println ("HERE2.5");
+ while (n != -1) {
+ dimsize++;
+ n = elem.indexOf('[', n + 1);
+ // System.out.println ("HERE2.8");
+ }
+ int[] dims = new int[dimsize];
+ primitive = primitiveNameToType(arrayType);
+ // System.out.println ("HERE3");
+ if (primitive != null) {
+ typeList.add(Array.newInstance(primitive, dims)
.getClass());
- // System.out.println ("HERE4");
- } else
- typeList.add(Array.newInstance(
+ // System.out.println ("HERE4");
+ } else
+ typeList.add(Array.newInstance(
getClass(arrayType, cl), dims).getClass());
- } else {
- typeList.add(getClass(elem, cl));
- }
- }
+ } else {
+ typeList.add(getClass(elem, cl));
}
- if (signature.length() < 2) {
- throw new IllegalArgumentException("Invalid JNI signature '"
+ }
+ }
+ if (signature.length() < 2) {
+ throw new IllegalArgumentException("Invalid JNI signature '"
+ signature + "'");
- }
}
+ }
- public static Class getClass(String name, ClassLoader cl) {
-
- Class c = null;
+ public static Class getClass(String name, ClassLoader cl) {
- try {
- c = Class.forName(name);
- } catch (ClassNotFoundException cnfe) {
+ Class c = null;
- PluginDebug.debug("Class " + name + " not found in primordial loader. Looking in " + cl);
- try {
- c = cl.loadClass(name);
- } catch (ClassNotFoundException e) {
- throw (new RuntimeException(new ClassNotFoundException("Unable to find class " + name)));
- }
- }
-
- return c;
+ try {
+ c = Class.forName(name);
+ } catch (ClassNotFoundException cnfe) {
+
+ PluginDebug.debug("Class " + name + " not found in primordial loader. Looking in " + cl);
+ try {
+ c = cl.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ throw (new RuntimeException(new ClassNotFoundException("Unable to find class " + name)));
+ }
}
- public static Class primitiveNameToType(String name) {
- if (name.equals("void"))
- return Void.TYPE;
- else if (name.equals("boolean"))
- return Boolean.TYPE;
- else if (name.equals("byte"))
- return Byte.TYPE;
- else if (name.equals("char"))
- return Character.TYPE;
- else if (name.equals("short"))
- return Short.TYPE;
- else if (name.equals("int"))
- return Integer.TYPE;
- else if (name.equals("long"))
- return Long.TYPE;
- else if (name.equals("float"))
- return Float.TYPE;
- else if (name.equals("double"))
- return Double.TYPE;
- else
- return null;
- }
+ return c;
+ }
- public Class[] getClassArray() {
- return typeList.subList(0, typeList.size()).toArray(new Class[] {});
- }
+ public static Class primitiveNameToType(String name) {
+ if (name.equals("void"))
+ return Void.TYPE;
+ else if (name.equals("boolean"))
+ return Boolean.TYPE;
+ else if (name.equals("byte"))
+ return Byte.TYPE;
+ else if (name.equals("char"))
+ return Character.TYPE;
+ else if (name.equals("short"))
+ return Short.TYPE;
+ else if (name.equals("int"))
+ return Integer.TYPE;
+ else if (name.equals("long"))
+ return Long.TYPE;
+ else if (name.equals("float"))
+ return Float.TYPE;
+ else if (name.equals("double"))
+ return Double.TYPE;
+ else
+ return null;
+ }
+
+ public Class[] getClassArray() {
+ return typeList.subList(0, typeList.size()).toArray(new Class[] {});
+ }
}
public class PluginAppletSecurityContext {
- private static Hashtable<ClassLoader, URL> classLoaders = new Hashtable<ClassLoader, URL>();
- private static Hashtable<Integer, ClassLoader> instanceClassLoaders = new Hashtable<Integer, ClassLoader>();
+ private static Hashtable<ClassLoader, URL> classLoaders = new Hashtable<ClassLoader, URL>();
+ private static Hashtable<Integer, ClassLoader> instanceClassLoaders = new Hashtable<Integer, ClassLoader>();
- // FIXME: make private
- public PluginObjectStore store = new PluginObjectStore();
- private Throwable throwable = null;
- private ClassLoader liveconnectLoader = ClassLoader.getSystemClassLoader();
- int identifier = 0;
+ // FIXME: make private
+ public PluginObjectStore store = new PluginObjectStore();
+ private Throwable throwable = null;
+ private ClassLoader liveconnectLoader = ClassLoader.getSystemClassLoader();
+ int identifier = 0;
- public static PluginStreamHandler streamhandler;
+ public static PluginStreamHandler streamhandler;
- long startTime = 0;
+ long startTime = 0;
- public PluginAppletSecurityContext(int identifier) {
- this.identifier = identifier;
-
- // We need a security manager.. and since there is a good chance that
- // an applet will be loaded at some point, we should make it the SM
- // that JNLPRuntime will try to install
- if (System.getSecurityManager() == null) {
- JNLPRuntime.initialize(/* isApplication */ false);
- }
+ public PluginAppletSecurityContext(int identifier) {
+ this.identifier = identifier;
- JNLPRuntime.disableExit();
-
- URL u = null;
- try {
- u = new URL("file://");
- } catch (Exception e) {
- e.printStackTrace();
- }
+ // We need a security manager.. and since there is a good chance that
+ // an applet will be loaded at some point, we should make it the SM
+ // that JNLPRuntime will try to install
+ if (System.getSecurityManager() == null) {
+ JNLPRuntime.initialize(/* isApplication */false);
+ }
+ JNLPRuntime.disableExit();
- this.classLoaders.put(liveconnectLoader, u);
+ URL u = null;
+ try {
+ u = new URL("file://");
+ } catch (Exception e) {
+ e.printStackTrace();
}
- private static <V> V parseCall(String s, ClassLoader cl, Class<V> c) {
- if (c == Integer.class)
- return c.cast(new Integer(s));
- else if (c == String.class)
- return c.cast(new String(s));
- else if (c == Signature.class)
- return c.cast(new Signature(s, cl));
- else
- throw new RuntimeException("Unexpected call value.");
- }
+ this.classLoaders.put(liveconnectLoader, u);
+ }
- private Object parseArgs(String s, Class c) {
- if (c == Boolean.TYPE || c == Boolean.class)
- return new Boolean(s);
- else if (c == Byte.TYPE || c == Byte.class)
- return new Byte(s);
- else if (c == Character.TYPE || c == Character.class) {
- String[] bytes = s.split("_");
- int low = Integer.parseInt(bytes[0]);
- int high = Integer.parseInt(bytes[1]);
- int full = ((high << 8) & 0x0ff00) | (low & 0x0ff);
- return new Character((char) full);
- } else if (c == Short.TYPE || c == Short.class)
- return new Short(s);
- else if (c == Integer.TYPE || c == Integer.class)
- return new Integer(s);
- else if (c == Long.TYPE || c == Long.class)
- return new Long(s);
- else if (c == Float.TYPE || c == Float.class)
- return new Float(s);
- else if (c == Double.TYPE || c == Double.class)
- return new Double(s);
- else
- return store.getObject(new Integer(s));
- }
+ private static <V> V parseCall(String s, ClassLoader cl, Class<V> c) {
+ if (c == Integer.class)
+ return c.cast(new Integer(s));
+ else if (c == String.class)
+ return c.cast(new String(s));
+ else if (c == Signature.class)
+ return c.cast(new Signature(s, cl));
+ else
+ throw new RuntimeException("Unexpected call value.");
+ }
- public void associateSrc(ClassLoader cl, URL src) {
- PluginDebug.debug("Associating " + cl + " with " + src);
- this.classLoaders.put(cl, src);
- }
+ private Object parseArgs(String s, Class c) {
+ if (c == Boolean.TYPE || c == Boolean.class)
+ return new Boolean(s);
+ else if (c == Byte.TYPE || c == Byte.class)
+ return new Byte(s);
+ else if (c == Character.TYPE || c == Character.class) {
+ String[] bytes = s.split("_");
+ int low = Integer.parseInt(bytes[0]);
+ int high = Integer.parseInt(bytes[1]);
+ int full = ((high << 8) & 0x0ff00) | (low & 0x0ff);
+ return new Character((char) full);
+ } else if (c == Short.TYPE || c == Short.class)
+ return new Short(s);
+ else if (c == Integer.TYPE || c == Integer.class)
+ return new Integer(s);
+ else if (c == Long.TYPE || c == Long.class)
+ return new Long(s);
+ else if (c == Float.TYPE || c == Float.class)
+ return new Float(s);
+ else if (c == Double.TYPE || c == Double.class)
+ return new Double(s);
+ else
+ return store.getObject(new Integer(s));
+ }
+
+ public void associateSrc(ClassLoader cl, URL src) {
+ PluginDebug.debug("Associating " + cl + " with " + src);
+ this.classLoaders.put(cl, src);
+ }
public void associateInstance(Integer i, ClassLoader cl) {
PluginDebug.debug("Associating " + cl + " with instance " + i);
this.instanceClassLoaders.put(i, cl);
}
- public static void setStreamhandler(PluginStreamHandler sh) {
- streamhandler = sh;
- }
-
- public static Map<String, String> getLoaderInfo() {
- Hashtable<String, String> map = new Hashtable<String, String>();
+ public static void setStreamhandler(PluginStreamHandler sh) {
+ streamhandler = sh;
+ }
- for (ClassLoader loader : PluginAppletSecurityContext.classLoaders.keySet()) {
- map.put(loader.getClass().getName(), classLoaders.get(loader).toString());
- }
+ public static Map<String, String> getLoaderInfo() {
+ Hashtable<String, String> map = new Hashtable<String, String>();
- return map;
+ for (ClassLoader loader : PluginAppletSecurityContext.classLoaders.keySet()) {
+ map.put(loader.getClass().getName(), classLoaders.get(loader).toString());
}
- public void handleMessage(int reference, String src, AccessControlContext callContext, String message) {
+ return map;
+ }
+
+ public void handleMessage(int reference, String src, AccessControlContext callContext, String message) {
- startTime = new java.util.Date().getTime();
+ startTime = new java.util.Date().getTime();
+
+ try {
+ if (message.startsWith("FindClass")) {
+ ClassLoader cl = null;
+ Class c = null;
+ cl = liveconnectLoader;
+ String[] args = message.split(" ");
+ Integer instance = new Integer(args[1]);
+ String className = args[2].replace('/', '.');
+ PluginDebug.debug("Searching for class " + className + " in " + cl);
try {
- if (message.startsWith("FindClass")) {
- ClassLoader cl = null;
- Class c = null;
- cl = liveconnectLoader;
- String[] args = message.split(" ");
- Integer instance = new Integer(args[1]);
- String className = args[2].replace('/', '.');
- PluginDebug.debug("Searching for class " + className + " in " + cl);
-
- try {
- c = cl.loadClass(className);
- store.reference(c);
- write(reference, "FindClass " + store.getIdentifier(c));
- } catch (ClassNotFoundException cnfe) {
-
- cl = this.instanceClassLoaders.get(instance);
- PluginDebug.debug("Not found. Looking in " + cl);
+ c = cl.loadClass(className);
+ store.reference(c);
+ write(reference, "FindClass " + store.getIdentifier(c));
+ } catch (ClassNotFoundException cnfe) {
+
+ cl = this.instanceClassLoaders.get(instance);
+ PluginDebug.debug("Not found. Looking in " + cl);
if (instance != 0 && cl != null) {
- try {
- c = cl.loadClass(className);
- store.reference(c);
- write(reference, "FindClass " + store.getIdentifier(c));
- } catch (ClassNotFoundException cnfe2) {
- write(reference, "FindClass 0");
- }
- } else {
- write(reference, "FindClass 0");
- }
- }
+ try {
+ c = cl.loadClass(className);
+ store.reference(c);
+ write(reference, "FindClass " + store.getIdentifier(c));
+ } catch (ClassNotFoundException cnfe2) {
+ write(reference, "FindClass 0");
+ }
+ } else {
+ write(reference, "FindClass 0");
+ }
+ }
- } else if (message.startsWith("GetStaticMethodID")
+ } else if (message.startsWith("GetStaticMethodID")
|| message.startsWith("GetMethodID")) {
- String[] args = message.split(" ");
- Integer classID = parseCall(args[1], null, Integer.class);
- String methodName = parseCall(args[2], null, String.class);
- Signature signature = parseCall(args[3], ((Class) store.getObject(classID)).getClassLoader(), Signature.class);
- Object[] a = signature.getClassArray();
+ String[] args = message.split(" ");
+ Integer classID = parseCall(args[1], null, Integer.class);
+ String methodName = parseCall(args[2], null, String.class);
+ Signature signature = parseCall(args[3], ((Class) store.getObject(classID)).getClassLoader(), Signature.class);
+ Object[] a = signature.getClassArray();
- Class<?> c;
+ Class<?> c;
- if (message.startsWith("GetStaticMethodID") ||
+ if (message.startsWith("GetStaticMethodID") ||
methodName.equals("<init>") ||
methodName.equals("<clinit>"))
- c = (Class<?>) store.getObject(classID);
- else
- c = store.getObject(classID).getClass();
-
- Method m = null;
- Constructor cs = null;
- Object o = null;
- if (methodName.equals("<init>")
+ c = (Class<?>) store.getObject(classID);
+ else
+ c = store.getObject(classID).getClass();
+
+ Method m = null;
+ Constructor cs = null;
+ Object o = null;
+ if (methodName.equals("<init>")
|| methodName.equals("<clinit>")) {
- o = cs = c.getConstructor(signature.getClassArray());
- store.reference(cs);
- } else {
- o = m = c.getMethod(methodName, signature.getClassArray());
- store.reference(m);
- }
- PluginDebug.debug(o + " has id " + store.getIdentifier(o));
- write(reference, args[0] + " " + store.getIdentifier(o));
- } else if (message.startsWith("GetStaticFieldID")
+ o = cs = c.getConstructor(signature.getClassArray());
+ store.reference(cs);
+ } else {
+ o = m = c.getMethod(methodName, signature.getClassArray());
+ store.reference(m);
+ }
+ PluginDebug.debug(o + " has id " + store.getIdentifier(o));
+ write(reference, args[0] + " " + store.getIdentifier(o));
+ } else if (message.startsWith("GetStaticFieldID")
|| message.startsWith("GetFieldID")) {
- String[] args = message.split(" ");
- Integer classID = parseCall(args[1], null, Integer.class);
- Integer fieldID = parseCall(args[2], null, Integer.class);
- String fieldName = (String) store.getObject(fieldID);
+ String[] args = message.split(" ");
+ Integer classID = parseCall(args[1], null, Integer.class);
+ Integer fieldID = parseCall(args[2], null, Integer.class);
+ String fieldName = (String) store.getObject(fieldID);
- Class<?> c = (Class<?>) store.getObject(classID);
+ Class<?> c = (Class<?>) store.getObject(classID);
- PluginDebug.debug("GetStaticFieldID/GetFieldID got class=" + c.getName());
+ PluginDebug.debug("GetStaticFieldID/GetFieldID got class=" + c.getName());
- Field f = null;
- f = c.getField(fieldName);
+ Field f = null;
+ f = c.getField(fieldName);
- store.reference(f);
+ store.reference(f);
- write(reference, "GetStaticFieldID " + store.getIdentifier(f));
- } else if (message.startsWith("GetStaticField")) {
- String[] args = message.split(" ");
- String type = parseCall(args[1], null, String.class);
- Integer classID = parseCall(args[1], null, Integer.class);
- Integer fieldID = parseCall(args[2], null, Integer.class);
+ write(reference, "GetStaticFieldID " + store.getIdentifier(f));
+ } else if (message.startsWith("GetStaticField")) {
+ String[] args = message.split(" ");
+ String type = parseCall(args[1], null, String.class);
+ Integer classID = parseCall(args[1], null, Integer.class);
+ Integer fieldID = parseCall(args[2], null, Integer.class);
- final Class<?> c = (Class<?>) store.getObject(classID);
- final Field f = (Field) store.getObject(fieldID);
+ final Class<?> c = (Class<?>) store.getObject(classID);
+ final Field f = (Field) store.getObject(fieldID);
- AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- checkPermission(src, c, acc);
+ AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
+ checkPermission(src, c, acc);
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
- public Object run() {
- try {
- return f.get(c);
- } catch (Throwable t) {
- return t;
- }
- }
- }, acc);
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ try {
+ return f.get(c);
+ } catch (Throwable t) {
+ return t;
+ }
+ }
+ }, acc);
- if (ret instanceof Throwable)
- throw (Throwable) ret;
+ if (ret instanceof Throwable)
+ throw (Throwable) ret;
if (ret == null) {
write(reference, "GetStaticField literalreturn null");
@@ -449,7 +446,7 @@ public class PluginAppletSecurityContext {
write(reference, "GetStaticField literalreturn " + ret);
} else if (f.getType() == Float.TYPE
|| f.getType() == Double.TYPE) {
- write(reference, "GetStaticField literalreturn " + String.format("%308.308e", ret));
+ write(reference, "GetStaticField literalreturn " + String.format("%308.308e", ret));
} else if (f.getType() == Character.TYPE) {
write(reference, "GetStaticField literalreturn " + (int) (Character) ret);
} else {
@@ -457,7 +454,7 @@ public class PluginAppletSecurityContext {
store.reference(ret);
write(reference, "GetStaticField " + store.getIdentifier(ret));
}
- } else if (message.startsWith("GetValue")) {
+ } else if (message.startsWith("GetValue")) {
String[] args = message.split(" ");
Integer index = parseCall(args[1], null, Integer.class);
@@ -491,56 +488,56 @@ public class PluginAppletSecurityContext {
}
} else if (message.startsWith("SetStaticField") ||
message.startsWith("SetField")) {
- String[] args = message.split(" ");
- Integer classOrObjectID = parseCall(args[1], null, Integer.class);
- Integer fieldID = parseCall(args[2], null, Integer.class);
- Object value = store.getObject(parseCall(args[3], null, Integer.class));
+ String[] args = message.split(" ");
+ Integer classOrObjectID = parseCall(args[1], null, Integer.class);
+ Integer fieldID = parseCall(args[2], null, Integer.class);
+ Object value = store.getObject(parseCall(args[3], null, Integer.class));
- final Object o = store.getObject(classOrObjectID);
- final Field f = (Field) store.getObject(fieldID);
+ final Object o = store.getObject(classOrObjectID);
+ final Field f = (Field) store.getObject(fieldID);
- final Object fValue = MethodOverloadResolver.getCostAndCastedObject(value, f.getType())[1];
+ final Object fValue = MethodOverloadResolver.getCostAndCastedObject(value, f.getType())[1];
- AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- checkPermission(src,
+ AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
+ checkPermission(src,
message.startsWith("SetStaticField") ? (Class) o : o.getClass(),
acc);
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
- public Object run() {
- try {
- f.set(o, fValue);
- } catch (Throwable t) {
- return t;
- }
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ try {
+ f.set(o, fValue);
+ } catch (Throwable t) {
+ return t;
+ }
- return null;
- }
- }, acc);
+ return null;
+ }
+ }, acc);
- if (ret instanceof Throwable)
- throw (Throwable) ret;
+ if (ret instanceof Throwable)
+ throw (Throwable) ret;
- write(reference, "SetField");
- } else if (message.startsWith("GetObjectArrayElement")) {
- String[] args = message.split(" ");
- Integer arrayID = parseCall(args[1], null, Integer.class);
- Integer index = parseCall(args[2], null, Integer.class);
+ write(reference, "SetField");
+ } else if (message.startsWith("GetObjectArrayElement")) {
+ String[] args = message.split(" ");
+ Integer arrayID = parseCall(args[1], null, Integer.class);
+ Integer index = parseCall(args[2], null, Integer.class);
- Object ret = Array.get(store.getObject(arrayID), index);
- Class retClass = store.getObject(arrayID).getClass().getComponentType(); // prevent auto-boxing influence
+ Object ret = Array.get(store.getObject(arrayID), index);
+ Class retClass = store.getObject(arrayID).getClass().getComponentType(); // prevent auto-boxing influence
if (ret == null) {
write(reference, "GetObjectArrayElement literalreturn null");
} else if (retClass == Boolean.TYPE
|| retClass == Byte.TYPE
|| retClass == Short.TYPE
- || retClass== Integer.TYPE
- || retClass== Long.TYPE) {
+ || retClass == Integer.TYPE
+ || retClass == Long.TYPE) {
write(reference, "GetObjectArrayElement literalreturn " + ret);
} else if (retClass == Float.TYPE
|| retClass == Double.TYPE) {
- write(reference, "GetObjectArrayElement literalreturn " + String.format("%308.308e", ret));
+ write(reference, "GetObjectArrayElement literalreturn " + String.format("%308.308e", ret));
} else if (retClass == Character.TYPE) {
write(reference, "GetObjectArrayElement literalreturn " + (int) (Character) ret);
} else {
@@ -549,61 +546,61 @@ public class PluginAppletSecurityContext {
write(reference, "GetObjectArrayElement " + store.getIdentifier(ret));
}
- } else if (message.startsWith("SetObjectArrayElement")) {
- String[] args = message.split(" ");
- Integer arrayID = parseCall(args[1], null, Integer.class);
- Integer index = parseCall(args[2], null, Integer.class);
- Integer objectID = parseCall(args[3], null, Integer.class);
-
- Object value = store.getObject(objectID);
-
- // Cast the object to appropriate type before insertion
- value = MethodOverloadResolver.getCostAndCastedObject(value, store.getObject(arrayID).getClass().getComponentType())[1];
-
- //if (value == null &&
- // store.getObject(arrayID).getClass().getComponentType().isPrimitive()) {
- // value = 0;
- //}
-
- Array.set(store.getObject(arrayID), index, value);
-
- write(reference, "SetObjectArrayElement");
- } else if (message.startsWith("GetArrayLength")) {
- String[] args = message.split(" ");
- Integer arrayID = parseCall(args[1], null, Integer.class);
-
- //System.out.println("ARRAYID: " + arrayID);
- Object o = store.getObject(arrayID);
- int len = 0;
- len = Array.getLength(o);
- // System.out.println ("Returning array length: " + len);
-
- // System.out.println ("array length: " + o + " " + len);
- write(reference, "GetArrayLength " + Array.getLength(o));
- } else if (message.startsWith("GetField")) {
- String[] args = message.split(" ");
- String type = parseCall(args[1], null, String.class);
- Integer objectID = parseCall(args[1], null, Integer.class);
- Integer fieldID = parseCall(args[2], null, Integer.class);
-
- final Object o = store.getObject(objectID);
- final Field f = (Field) store.getObject(fieldID);
-
- AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- checkPermission(src, o.getClass(), acc);
-
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
- public Object run() {
- try {
- return f.get(o);
- } catch (Throwable t) {
- return t;
- }
- }
- }, acc);
-
- if (ret instanceof Throwable)
- throw (Throwable) ret;
+ } else if (message.startsWith("SetObjectArrayElement")) {
+ String[] args = message.split(" ");
+ Integer arrayID = parseCall(args[1], null, Integer.class);
+ Integer index = parseCall(args[2], null, Integer.class);
+ Integer objectID = parseCall(args[3], null, Integer.class);
+
+ Object value = store.getObject(objectID);
+
+ // Cast the object to appropriate type before insertion
+ value = MethodOverloadResolver.getCostAndCastedObject(value, store.getObject(arrayID).getClass().getComponentType())[1];
+
+ //if (value == null &&
+ // store.getObject(arrayID).getClass().getComponentType().isPrimitive()) {
+ // value = 0;
+ //}
+
+ Array.set(store.getObject(arrayID), index, value);
+
+ write(reference, "SetObjectArrayElement");
+ } else if (message.startsWith("GetArrayLength")) {
+ String[] args = message.split(" ");
+ Integer arrayID = parseCall(args[1], null, Integer.class);
+
+ //System.out.println("ARRAYID: " + arrayID);
+ Object o = store.getObject(arrayID);
+ int len = 0;
+ len = Array.getLength(o);
+ // System.out.println ("Returning array length: " + len);
+
+ // System.out.println ("array length: " + o + " " + len);
+ write(reference, "GetArrayLength " + Array.getLength(o));
+ } else if (message.startsWith("GetField")) {
+ String[] args = message.split(" ");
+ String type = parseCall(args[1], null, String.class);
+ Integer objectID = parseCall(args[1], null, Integer.class);
+ Integer fieldID = parseCall(args[2], null, Integer.class);
+
+ final Object o = store.getObject(objectID);
+ final Field f = (Field) store.getObject(fieldID);
+
+ AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
+ checkPermission(src, o.getClass(), acc);
+
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ try {
+ return f.get(o);
+ } catch (Throwable t) {
+ return t;
+ }
+ }
+ }, acc);
+
+ if (ret instanceof Throwable)
+ throw (Throwable) ret;
if (ret == null) {
write(reference, "GetField literalreturn null");
@@ -615,7 +612,7 @@ public class PluginAppletSecurityContext {
write(reference, "GetField literalreturn " + ret);
} else if (f.getType() == Float.TYPE
|| f.getType() == Double.TYPE) {
- write(reference, "GetField literalreturn " + String.format("%308.308e", ret));
+ write(reference, "GetField literalreturn " + String.format("%308.308e", ret));
} else if (f.getType() == Character.TYPE) {
write(reference, "GetField literalreturn " + (int) (Character) ret);
} else {
@@ -624,39 +621,39 @@ public class PluginAppletSecurityContext {
write(reference, "GetField " + store.getIdentifier(ret));
}
- } else if (message.startsWith("GetObjectClass")) {
- int oid = Integer.parseInt(message.substring("GetObjectClass"
+ } else if (message.startsWith("GetObjectClass")) {
+ int oid = Integer.parseInt(message.substring("GetObjectClass"
.length() + 1));
- // System.out.println ("GETTING CLASS FOR: " + oid);
- Class<?> c = store.getObject(oid).getClass();
- // System.out.println (" OBJ: " + store.getObject(oid));
- // System.out.println (" CLS: " + c);
- store.reference(c);
-
- write(reference, "GetObjectClass " + store.getIdentifier(c));
- } else if (message.startsWith("CallMethod") ||
+ // System.out.println ("GETTING CLASS FOR: " + oid);
+ Class<?> c = store.getObject(oid).getClass();
+ // System.out.println (" OBJ: " + store.getObject(oid));
+ // System.out.println (" CLS: " + c);
+ store.reference(c);
+
+ write(reference, "GetObjectClass " + store.getIdentifier(c));
+ } else if (message.startsWith("CallMethod") ||
message.startsWith("CallStaticMethod")) {
- String[] args = message.split(" ");
- Integer objectID = parseCall(args[1], null, Integer.class);
- String methodName = parseCall(args[2], null, String.class);
- Object o = null;
- Class<?> c;
-
- if (message.startsWith("CallMethod")) {
- o = store.getObject(objectID);
- c = o.getClass();
- } else {
- c = (Class<?>) store.getObject(objectID);
- }
+ String[] args = message.split(" ");
+ Integer objectID = parseCall(args[1], null, Integer.class);
+ String methodName = parseCall(args[2], null, String.class);
+ Object o = null;
+ Class<?> c;
+
+ if (message.startsWith("CallMethod")) {
+ o = store.getObject(objectID);
+ c = o.getClass();
+ } else {
+ c = (Class<?>) store.getObject(objectID);
+ }
- // length -3 to discard first 3, + 2 for holding object
- // and method name
- Object[] arguments = new Object[args.length - 1];
- arguments[0] = c;
- arguments[1] = methodName;
+ // length -3 to discard first 3, + 2 for holding object
+ // and method name
+ Object[] arguments = new Object[args.length - 1];
+ arguments[0] = c;
+ arguments[1] = methodName;
for (int i = 0; i < args.length - 3; i++) {
- arguments[i+2] = store.getObject(parseCall(args[3 + i], null, Integer.class));
- PluginDebug.debug("GOT ARG: " + arguments[i+2]);
+ arguments[i + 2] = store.getObject(parseCall(args[3 + i], null, Integer.class));
+ PluginDebug.debug("GOT ARG: " + arguments[i + 2]);
}
Object[] matchingMethodAndArgs = MethodOverloadResolver.getMatchingMethod(arguments);
@@ -666,175 +663,175 @@ public class PluginAppletSecurityContext {
return;
}
- final Method m = (Method) matchingMethodAndArgs[0];
- Object[] castedArgs = new Object[matchingMethodAndArgs.length - 1];
- for (int i=0; i < castedArgs.length; i++) {
- castedArgs[i] = matchingMethodAndArgs[i+1];
- }
+ final Method m = (Method) matchingMethodAndArgs[0];
+ Object[] castedArgs = new Object[matchingMethodAndArgs.length - 1];
+ for (int i = 0; i < castedArgs.length; i++) {
+ castedArgs[i] = matchingMethodAndArgs[i + 1];
+ }
- String collapsedArgs = "";
- for (Object arg : castedArgs) {
- collapsedArgs += " " + arg;
- }
+ String collapsedArgs = "";
+ for (Object arg : castedArgs) {
+ collapsedArgs += " " + arg;
+ }
- PluginDebug.debug("Calling method " + m + " on object " + o
+ PluginDebug.debug("Calling method " + m + " on object " + o
+ " (" + c + ") with " + collapsedArgs);
- AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- checkPermission(src, c, acc);
-
- final Object[] fArguments = castedArgs;
- final Object callableObject = o;
- // Set the method accessible prior to calling. See:
- // http://forums.sun.com/thread.jspa?threadID=332001&start=15&tstart=0
- m.setAccessible(true);
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
- public Object run() {
- try {
- return m.invoke(callableObject, fArguments);
- } catch (Throwable t) {
- return t;
- }
- }
- }, acc);
-
- if (ret instanceof Throwable)
- throw (Throwable) ret;
-
- String retO;
- if (ret == null) {
- retO = "null";
- } else {
- retO = m.getReturnType().toString();
- }
+ AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
+ checkPermission(src, c, acc);
- PluginDebug.debug("Calling " + m + " on " + o + " with "
+ final Object[] fArguments = castedArgs;
+ final Object callableObject = o;
+ // Set the method accessible prior to calling. See:
+ // http://forums.sun.com/thread.jspa?threadID=332001&start=15&tstart=0
+ m.setAccessible(true);
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ try {
+ return m.invoke(callableObject, fArguments);
+ } catch (Throwable t) {
+ return t;
+ }
+ }
+ }, acc);
+
+ if (ret instanceof Throwable)
+ throw (Throwable) ret;
+
+ String retO;
+ if (ret == null) {
+ retO = "null";
+ } else {
+ retO = m.getReturnType().toString();
+ }
+
+ PluginDebug.debug("Calling " + m + " on " + o + " with "
+ collapsedArgs + " and that returned: " + ret
+ " of type " + retO);
- if (m.getReturnType().equals(java.lang.Void.class) ||
+ if (m.getReturnType().equals(java.lang.Void.class) ||
m.getReturnType().equals(java.lang.Void.TYPE)) {
write(reference, "CallMethod literalreturn void");
} else if (ret == null) {
- write(reference, "CallMethod literalreturn null");
- } else if (m.getReturnType() == Boolean.TYPE
+ write(reference, "CallMethod literalreturn null");
+ } else if (m.getReturnType() == Boolean.TYPE
|| m.getReturnType() == Byte.TYPE
|| m.getReturnType() == Short.TYPE
|| m.getReturnType() == Integer.TYPE
|| m.getReturnType() == Long.TYPE) {
- write(reference, "CallMethod literalreturn " + ret);
+ write(reference, "CallMethod literalreturn " + ret);
} else if (m.getReturnType() == Float.TYPE
|| m.getReturnType() == Double.TYPE) {
- write(reference, "CallMethod literalreturn " + String.format("%308.308e", ret));
- } else if (m.getReturnType() == Character.TYPE) {
- write(reference, "CallMethod literalreturn " + (int) (Character) ret);
- } else {
- // Track returned object.
- store.reference(ret);
- write(reference, "CallMethod " + store.getIdentifier(ret));
- }
- } else if (message.startsWith("GetSuperclass")) {
- String[] args = message.split(" ");
- Integer classID = parseCall(args[1], null, Integer.class);
- Class<?> c = null;
- Class<?> ret = null;
-
- c = (Class) store.getObject(classID);
- ret = c.getSuperclass();
- store.reference(ret);
-
- write(reference, "GetSuperclass " + store.getIdentifier(ret));
- } else if (message.startsWith("IsAssignableFrom")) {
- String[] args = message.split(" ");
- Integer classID = parseCall(args[1], null, Integer.class);
- Integer superclassID = parseCall(args[2], null, Integer.class);
-
- boolean result = false;
- Class<?> clz = (Class<?>) store.getObject(classID);
- Class<?> sup = (Class<?>) store.getObject(superclassID);
-
- result = sup.isAssignableFrom(clz);
-
- write(reference, "IsAssignableFrom " + (result ? "1" : "0"));
- } else if (message.startsWith("IsInstanceOf")) {
- String[] args = message.split(" ");
- Integer objectID = parseCall(args[1], null, Integer.class);
- Integer classID = parseCall(args[2], null, Integer.class);
-
- boolean result = false;
- Object o = store.getObject(objectID);
- Class<?> c = (Class<?>) store.getObject(classID);
-
- result = c.isInstance(o);
-
- write(reference, "IsInstanceOf " + (result ? "1" : "0"));
- } else if (message.startsWith("GetStringUTFLength")) {
- String[] args = message.split(" ");
- Integer stringID = parseCall(args[1], null, Integer.class);
-
- String o = null;
- byte[] b = null;
- o = (String) store.getObject(stringID);
- b = o.getBytes("UTF-8");
- // System.out.println ("STRING UTF-8 LENGTH: " + o + " " +
- // b.length);
-
- write(reference, "GetStringUTFLength " + o.length());
- } else if (message.startsWith("GetStringLength")) {
- String[] args = message.split(" ");
- Integer stringID = parseCall(args[1], null, Integer.class);
-
- String o = null;
- byte[] b = null;
- o = (String) store.getObject(stringID);
- b = o.getBytes("UTF-16LE");
- // System.out.println ("STRING UTF-16 LENGTH: " + o + " " +
- // b.length);
-
- // System.out.println ("Java: GetStringLength " + b.length);
- write(reference, "GetStringLength " + o.length());
- } else if (message.startsWith("GetStringUTFChars")) {
- String[] args = message.split(" ");
- Integer stringID = parseCall(args[1], null, Integer.class);
-
- String o = null;
- byte[] b = null;
- StringBuffer buf = null;
- o = (String) store.getObject(stringID);
- b = o.getBytes("UTF-8");
- buf = new StringBuffer(b.length * 2);
- buf.append(b.length);
- for (int i = 0; i < b.length; i++)
- buf
+ write(reference, "CallMethod literalreturn " + String.format("%308.308e", ret));
+ } else if (m.getReturnType() == Character.TYPE) {
+ write(reference, "CallMethod literalreturn " + (int) (Character) ret);
+ } else {
+ // Track returned object.
+ store.reference(ret);
+ write(reference, "CallMethod " + store.getIdentifier(ret));
+ }
+ } else if (message.startsWith("GetSuperclass")) {
+ String[] args = message.split(" ");
+ Integer classID = parseCall(args[1], null, Integer.class);
+ Class<?> c = null;
+ Class<?> ret = null;
+
+ c = (Class) store.getObject(classID);
+ ret = c.getSuperclass();
+ store.reference(ret);
+
+ write(reference, "GetSuperclass " + store.getIdentifier(ret));
+ } else if (message.startsWith("IsAssignableFrom")) {
+ String[] args = message.split(" ");
+ Integer classID = parseCall(args[1], null, Integer.class);
+ Integer superclassID = parseCall(args[2], null, Integer.class);
+
+ boolean result = false;
+ Class<?> clz = (Class<?>) store.getObject(classID);
+ Class<?> sup = (Class<?>) store.getObject(superclassID);
+
+ result = sup.isAssignableFrom(clz);
+
+ write(reference, "IsAssignableFrom " + (result ? "1" : "0"));
+ } else if (message.startsWith("IsInstanceOf")) {
+ String[] args = message.split(" ");
+ Integer objectID = parseCall(args[1], null, Integer.class);
+ Integer classID = parseCall(args[2], null, Integer.class);
+
+ boolean result = false;
+ Object o = store.getObject(objectID);
+ Class<?> c = (Class<?>) store.getObject(classID);
+
+ result = c.isInstance(o);
+
+ write(reference, "IsInstanceOf " + (result ? "1" : "0"));
+ } else if (message.startsWith("GetStringUTFLength")) {
+ String[] args = message.split(" ");
+ Integer stringID = parseCall(args[1], null, Integer.class);
+
+ String o = null;
+ byte[] b = null;
+ o = (String) store.getObject(stringID);
+ b = o.getBytes("UTF-8");
+ // System.out.println ("STRING UTF-8 LENGTH: " + o + " " +
+ // b.length);
+
+ write(reference, "GetStringUTFLength " + o.length());
+ } else if (message.startsWith("GetStringLength")) {
+ String[] args = message.split(" ");
+ Integer stringID = parseCall(args[1], null, Integer.class);
+
+ String o = null;
+ byte[] b = null;
+ o = (String) store.getObject(stringID);
+ b = o.getBytes("UTF-16LE");
+ // System.out.println ("STRING UTF-16 LENGTH: " + o + " " +
+ // b.length);
+
+ // System.out.println ("Java: GetStringLength " + b.length);
+ write(reference, "GetStringLength " + o.length());
+ } else if (message.startsWith("GetStringUTFChars")) {
+ String[] args = message.split(" ");
+ Integer stringID = parseCall(args[1], null, Integer.class);
+
+ String o = null;
+ byte[] b = null;
+ StringBuffer buf = null;
+ o = (String) store.getObject(stringID);
+ b = o.getBytes("UTF-8");
+ buf = new StringBuffer(b.length * 2);
+ buf.append(b.length);
+ for (int i = 0; i < b.length; i++)
+ buf
.append(" "
+ Integer
.toString(((int) b[i]) & 0x0ff, 16));
- // System.out.println ("Java: GetStringUTFChars: " + o);
- // //System.out.println ("String UTF BYTES: " + buf);
- write(reference, "GetStringUTFChars " + buf);
- } else if (message.startsWith("GetStringChars")) {
- String[] args = message.split(" ");
- Integer stringID = parseCall(args[1], null, Integer.class);
-
- String o = null;
- byte[] b = null;
- StringBuffer buf = null;
- o = (String) store.getObject(stringID);
- // FIXME: LiveConnect uses UCS-2.
- b = o.getBytes("UTF-16LE");
- buf = new StringBuffer(b.length * 2);
- buf.append(b.length);
- for (int i = 0; i < b.length; i++)
- buf
+ // System.out.println ("Java: GetStringUTFChars: " + o);
+ // //System.out.println ("String UTF BYTES: " + buf);
+ write(reference, "GetStringUTFChars " + buf);
+ } else if (message.startsWith("GetStringChars")) {
+ String[] args = message.split(" ");
+ Integer stringID = parseCall(args[1], null, Integer.class);
+
+ String o = null;
+ byte[] b = null;
+ StringBuffer buf = null;
+ o = (String) store.getObject(stringID);
+ // FIXME: LiveConnect uses UCS-2.
+ b = o.getBytes("UTF-16LE");
+ buf = new StringBuffer(b.length * 2);
+ buf.append(b.length);
+ for (int i = 0; i < b.length; i++)
+ buf
.append(" "
+ Integer
.toString(((int) b[i]) & 0x0ff, 16));
- PluginDebug.debug("Java: GetStringChars: " + o);
- PluginDebug.debug(" String BYTES: " + buf);
- write(reference, "GetStringChars " + buf);
- } else if (message.startsWith("GetToStringValue")) {
+ PluginDebug.debug("Java: GetStringChars: " + o);
+ PluginDebug.debug(" String BYTES: " + buf);
+ write(reference, "GetStringChars " + buf);
+ } else if (message.startsWith("GetToStringValue")) {
String[] args = message.split(" ");
Integer objectID = parseCall(args[1], null, Integer.class);
@@ -853,23 +850,23 @@ public class PluginAppletSecurityContext {
write(reference, "GetToStringValue " + buf);
} else if (message.startsWith("NewArray")) {
- String[] args = message.split(" ");
- String type = parseCall(args[1], null, String.class);
- Integer length = parseCall(args[2], null, Integer.class);
-
- // System.out.println ("CALLING: NewArray: " + type + " " +
- // length + " "
- // + Signature.primitiveNameToType(type));
-
- Object newArray = null;
-
- Class c;
- if (type.equals("bool")) {
- c = Boolean.class;
- } else if (type.equals("double")) {
- c = Double.class;
- } else if (type.equals("int")) {
- c = Integer.class;
+ String[] args = message.split(" ");
+ String type = parseCall(args[1], null, String.class);
+ Integer length = parseCall(args[2], null, Integer.class);
+
+ // System.out.println ("CALLING: NewArray: " + type + " " +
+ // length + " "
+ // + Signature.primitiveNameToType(type));
+
+ Object newArray = null;
+
+ Class c;
+ if (type.equals("bool")) {
+ c = Boolean.class;
+ } else if (type.equals("double")) {
+ c = Double.class;
+ } else if (type.equals("int")) {
+ c = Integer.class;
} else if (type.equals("string")) {
c = String.class;
} else if (isInt(type)) {
@@ -878,14 +875,14 @@ public class PluginAppletSecurityContext {
c = JSObject.class;
}
- if (args.length > 3)
- newArray = Array.newInstance(c, new int[] { length, parseCall(args[3], null, Integer.class)});
- else
- newArray = Array.newInstance(c, length);
+ if (args.length > 3)
+ newArray = Array.newInstance(c, new int[] { length, parseCall(args[3], null, Integer.class) });
+ else
+ newArray = Array.newInstance(c, length);
- store.reference(newArray);
- write(reference, "NewArray " + store.getIdentifier(newArray));
- } else if (message.startsWith("HasMethod")) {
+ store.reference(newArray);
+ write(reference, "NewArray " + store.getIdentifier(newArray));
+ } else if (message.startsWith("HasMethod")) {
String[] args = message.split(" ");
Integer classNameID = parseCall(args[1], null, Integer.class);
Integer methodNameID = parseCall(args[2], null, Integer.class);
@@ -895,11 +892,11 @@ public class PluginAppletSecurityContext {
Method method = null;
Method[] classMethods = c.getMethods();
- for (Method m: classMethods) {
- if (m.getName().equals(methodName)) {
- method = m;
- break;
- }
+ for (Method m : classMethods) {
+ if (m.getName().equals(methodName)) {
+ method = m;
+ break;
+ }
}
int hasMethod = (method != null) ? 1 : 0;
@@ -926,37 +923,37 @@ public class PluginAppletSecurityContext {
Field field = null;
Field[] classFields = c.getFields();
- for (Field f: classFields) {
- if (f.getName().equals(fieldName)) {
- field = f;
- break;
- }
+ for (Field f : classFields) {
+ if (f.getName().equals(fieldName)) {
+ field = f;
+ break;
+ }
}
int hasField = (field != null) ? 1 : 0;
write(reference, "HasField " + hasField);
} else if (message.startsWith("NewObjectArray")) {
- String[] args = message.split(" ");
- Integer length = parseCall(args[1], null, Integer.class);
- Integer classID = parseCall(args[2], null, Integer.class);
- Integer objectID = parseCall(args[3], null, Integer.class);
+ String[] args = message.split(" ");
+ Integer length = parseCall(args[1], null, Integer.class);
+ Integer classID = parseCall(args[2], null, Integer.class);
+ Integer objectID = parseCall(args[3], null, Integer.class);
- // System.out.println ("CALLING: NewObjectArray: " +
- // classID + " " + length + " "
- // + objectID);
+ // System.out.println ("CALLING: NewObjectArray: " +
+ // classID + " " + length + " "
+ // + objectID);
- Object newArray = null;
- newArray = Array.newInstance((Class) store.getObject(classID),
+ Object newArray = null;
+ newArray = Array.newInstance((Class) store.getObject(classID),
length);
- Object[] array = (Object[]) newArray;
- for (int i = 0; i < array.length; i++)
- array[i] = store.getObject(objectID);
- store.reference(newArray);
- write(reference, "NewObjectArray "
+ Object[] array = (Object[]) newArray;
+ for (int i = 0; i < array.length; i++)
+ array[i] = store.getObject(objectID);
+ store.reference(newArray);
+ write(reference, "NewObjectArray "
+ store.getIdentifier(newArray));
- } else if (message.startsWith("NewObjectWithConstructor")) {
+ } else if (message.startsWith("NewObjectWithConstructor")) {
String[] args = message.split(" ");
Integer classID = parseCall(args[1], null, Integer.class);
@@ -979,7 +976,7 @@ public class PluginAppletSecurityContext {
Class c = (Class) store.getObject(classID);
checkPermission(src, c, acc);
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
return m.newInstance(fArguments);
@@ -997,9 +994,9 @@ public class PluginAppletSecurityContext {
write(reference, "NewObject " + store.getIdentifier(ret));
} else if (message.startsWith("NewObject")) {
- String[] args = message.split(" ");
- Integer classID = parseCall(args[1], null, Integer.class);
- Class c = (Class) store.getObject(classID);
+ String[] args = message.split(" ");
+ Integer classID = parseCall(args[1], null, Integer.class);
+ Class c = (Class) store.getObject(classID);
final Constructor cons;
final Object[] fArguments;
@@ -1037,26 +1034,26 @@ public class PluginAppletSecurityContext {
" with " + collapsedArgs);
AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- checkPermission(src, c, acc);
+ checkPermission(src, c, acc);
- Object ret = AccessController.doPrivileged(new PrivilegedAction<Object> () {
- public Object run() {
- try {
- return cons.newInstance(fArguments);
- } catch (Throwable t) {
- return t;
- }
- }
- }, acc);
+ Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ try {
+ return cons.newInstance(fArguments);
+ } catch (Throwable t) {
+ return t;
+ }
+ }
+ }, acc);
- if (ret instanceof Throwable)
- throw (Throwable) ret;
+ if (ret instanceof Throwable)
+ throw (Throwable) ret;
- store.reference(ret);
+ store.reference(ret);
- write(reference, "NewObject " + store.getIdentifier(ret));
+ write(reference, "NewObject " + store.getIdentifier(ret));
- } else if (message.startsWith("NewStringUTF")) {
+ } else if (message.startsWith("NewStringUTF")) {
PluginDebug.debug("MESSAGE: " + message);
String[] args = message.split(" ");
int length = new Integer(args[1]);
@@ -1075,7 +1072,7 @@ public class PluginAppletSecurityContext {
store.reference(ret);
write(reference, "NewStringUTF " + store.getIdentifier(ret));
- } else if (message.startsWith("NewString")) {
+ } else if (message.startsWith("NewString")) {
PluginDebug.debug("MESSAGE: " + message);
String[] args = message.split(" ");
Integer strlength = parseCall(args[1], null, Integer.class);
@@ -1099,383 +1096,382 @@ public class PluginAppletSecurityContext {
store.reference(ret);
write(reference, "NewString " + store.getIdentifier(ret));
- } else if (message.startsWith("ExceptionOccurred")) {
- PluginDebug.debug("EXCEPTION: " + throwable);
- if (throwable != null)
- store.reference(throwable);
- write(reference, "ExceptionOccurred "
+ } else if (message.startsWith("ExceptionOccurred")) {
+ PluginDebug.debug("EXCEPTION: " + throwable);
+ if (throwable != null)
+ store.reference(throwable);
+ write(reference, "ExceptionOccurred "
+ store.getIdentifier(throwable));
- } else if (message.startsWith("ExceptionClear")) {
- if (throwable != null && store.contains(throwable))
- store.unreference(store.getIdentifier(throwable));
- throwable = null;
- write(reference, "ExceptionClear");
- } else if (message.startsWith("DeleteGlobalRef")) {
- String[] args = message.split(" ");
- Integer id = parseCall(args[1], null, Integer.class);
- store.unreference(id);
- write(reference, "DeleteGlobalRef");
- } else if (message.startsWith("DeleteLocalRef")) {
- String[] args = message.split(" ");
- Integer id = parseCall(args[1], null, Integer.class);
- store.unreference(id);
- write(reference, "DeleteLocalRef");
- } else if (message.startsWith("NewGlobalRef")) {
- String[] args = message.split(" ");
- Integer id = parseCall(args[1], null, Integer.class);
- store.reference(store.getObject(id));
- write(reference, "NewGlobalRef " + id);
- } else if (message.startsWith("GetClassName")) {
- String[] args = message.split(" ");
- Integer objectID = parseCall(args[1], null, Integer.class);
- Object o = store.getObject(objectID);
- write(reference, "GetClassName " + o.getClass().getName());
- } else if (message.startsWith("GetClassID")) {
+ } else if (message.startsWith("ExceptionClear")) {
+ if (throwable != null && store.contains(throwable))
+ store.unreference(store.getIdentifier(throwable));
+ throwable = null;
+ write(reference, "ExceptionClear");
+ } else if (message.startsWith("DeleteGlobalRef")) {
+ String[] args = message.split(" ");
+ Integer id = parseCall(args[1], null, Integer.class);
+ store.unreference(id);
+ write(reference, "DeleteGlobalRef");
+ } else if (message.startsWith("DeleteLocalRef")) {
+ String[] args = message.split(" ");
+ Integer id = parseCall(args[1], null, Integer.class);
+ store.unreference(id);
+ write(reference, "DeleteLocalRef");
+ } else if (message.startsWith("NewGlobalRef")) {
+ String[] args = message.split(" ");
+ Integer id = parseCall(args[1], null, Integer.class);
+ store.reference(store.getObject(id));
+ write(reference, "NewGlobalRef " + id);
+ } else if (message.startsWith("GetClassName")) {
+ String[] args = message.split(" ");
+ Integer objectID = parseCall(args[1], null, Integer.class);
+ Object o = store.getObject(objectID);
+ write(reference, "GetClassName " + o.getClass().getName());
+ } else if (message.startsWith("GetClassID")) {
String[] args = message.split(" ");
Integer objectID = parseCall(args[1], null, Integer.class);
store.reference(store.getObject(objectID).getClass());
write(reference, "GetClassID " + store.getIdentifier(store.getObject(objectID).getClass()));
}
- } catch (Throwable t) {
- t.printStackTrace();
- String msg = t.getCause() != null ? t.getCause().getMessage() : t.getMessage();
-
- // add an identifier string to let javaside know of the type of error
- // check for cause as well, since the top level exception will be InvocationTargetException in most cases
- if (t instanceof AccessControlException || t.getCause() instanceof AccessControlException) {
- msg = "LiveConnectPermissionNeeded " + msg;
- }
-
- write(reference, " Error " + msg);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ String msg = t.getCause() != null ? t.getCause().getMessage() : t.getMessage();
+
+ // add an identifier string to let javaside know of the type of error
+ // check for cause as well, since the top level exception will be InvocationTargetException in most cases
+ if (t instanceof AccessControlException || t.getCause() instanceof AccessControlException) {
+ msg = "LiveConnectPermissionNeeded " + msg;
+ }
- // ExceptionOccured is only called after Callmethod() by mozilla. So
- // for exceptions that are not related to CallMethod, we need a way
- // to log them. This is how we do it.. send an error message to the
- // c++ side to let it know that something went wrong, and it will do
- // the right thing to let mozilla know
+ write(reference, " Error " + msg);
- // Store the cause as the actual exception. This is needed because
- // the exception we get here will always be an
- // "InvocationTargetException" due to the use of reflection above
- if (message.startsWith("CallMethod") || message.startsWith("CallStaticMethod"))
- throwable = t.getCause();
- }
+ // ExceptionOccured is only called after Callmethod() by mozilla. So
+ // for exceptions that are not related to CallMethod, we need a way
+ // to log them. This is how we do it.. send an error message to the
+ // c++ side to let it know that something went wrong, and it will do
+ // the right thing to let mozilla know
+ // Store the cause as the actual exception. This is needed because
+ // the exception we get here will always be an
+ // "InvocationTargetException" due to the use of reflection above
+ if (message.startsWith("CallMethod") || message.startsWith("CallStaticMethod"))
+ throwable = t.getCause();
}
- /**
- * Checks if the calling script is allowed to access the specified class
- *
- * @param jsSrc The source of the script
- * @param target The target class that the script is trying to access
- * @param acc AccessControlContext for this execution
- * @throws AccessControlException If the script has insufficient permissions
- */
- public void checkPermission(String jsSrc, Class target, AccessControlContext acc) throws AccessControlException {
- // NPRuntime does not allow cross-site calling. We therefore always
- // allow this, for the time being
- return;
- }
+ }
- private void write(int reference, String message) {
- PluginDebug.debug("appletviewer writing " + message);
- streamhandler.write("context " + identifier + " reference " + reference
- + " " + message);
- }
+ /**
+ * Checks if the calling script is allowed to access the specified class
+ *
+ * @param jsSrc The source of the script
+ * @param target The target class that the script is trying to access
+ * @param acc AccessControlContext for this execution
+ * @throws AccessControlException If the script has insufficient permissions
+ */
+ public void checkPermission(String jsSrc, Class target, AccessControlContext acc) throws AccessControlException {
+ // NPRuntime does not allow cross-site calling. We therefore always
+ // allow this, for the time being
+ return;
+ }
- public void prePopulateLCClasses() {
-
- int classID;
-
- prepopulateClass("netscape/javascript/JSObject");
- classID = prepopulateClass("netscape/javascript/JSException");
- prepopulateMethod(classID, "<init>", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)");
- prepopulateMethod(classID, "<init>", "(ILjava/lang/Object;)");
- prepopulateField(classID, "lineno");
- prepopulateField(classID, "tokenIndex");
- prepopulateField(classID, "source");
- prepopulateField(classID, "filename");
- prepopulateField(classID, "wrappedExceptionType");
- prepopulateField(classID, "wrappedException");
-
- classID = prepopulateClass("netscape/javascript/JSUtil");
- prepopulateMethod(classID, "getStackTrace", "(Ljava/lang/Throwable;)");
-
- prepopulateClass("java/lang/Object");
- classID = prepopulateClass("java/lang/Class");
- prepopulateMethod(classID, "getMethods", "()");
- prepopulateMethod(classID, "getConstructors", "()");
- prepopulateMethod(classID, "getFields", "()");
- prepopulateMethod(classID, "getName", "()");
- prepopulateMethod(classID, "isArray", "()");
- prepopulateMethod(classID, "getComponentType", "()");
- prepopulateMethod(classID, "getModifiers", "()");
-
-
- classID = prepopulateClass("java/lang/reflect/Method");
- prepopulateMethod(classID, "getName", "()");
- prepopulateMethod(classID, "getParameterTypes", "()");
- prepopulateMethod(classID, "getReturnType", "()");
- prepopulateMethod(classID, "getModifiers", "()");
-
- classID = prepopulateClass("java/lang/reflect/Constructor");
- prepopulateMethod(classID, "getParameterTypes", "()");
- prepopulateMethod(classID, "getModifiers", "()");
-
- classID = prepopulateClass("java/lang/reflect/Field");
- prepopulateMethod(classID, "getName", "()");
- prepopulateMethod(classID, "getType", "()");
- prepopulateMethod(classID, "getModifiers", "()");
-
- classID = prepopulateClass("java/lang/reflect/Array");
- prepopulateMethod(classID, "newInstance", "(Ljava/lang/Class;I)");
-
- classID = prepopulateClass("java/lang/Throwable");
- prepopulateMethod(classID, "toString", "()");
- prepopulateMethod(classID, "getMessage", "()");
-
- classID = prepopulateClass("java/lang/System");
- prepopulateMethod(classID, "identityHashCode", "(Ljava/lang/Object;)");
-
- classID = prepopulateClass("java/lang/Boolean");
- prepopulateMethod(classID, "booleanValue", "()");
- prepopulateMethod(classID, "<init>", "(Z)");
-
- classID = prepopulateClass("java/lang/Double");
- prepopulateMethod(classID, "doubleValue", "()");
- prepopulateMethod(classID, "<init>", "(D)");
-
- classID = prepopulateClass("java/lang/Void");
- prepopulateField(classID, "TYPE");
-
- prepopulateClass("java/lang/String");
- prepopulateClass("java/applet/Applet");
- }
+ private void write(int reference, String message) {
+ PluginDebug.debug("appletviewer writing " + message);
+ streamhandler.write("context " + identifier + " reference " + reference
+ + " " + message);
+ }
- private int prepopulateClass(String name) {
- name = name.replace('/', '.');
- ClassLoader cl = liveconnectLoader;
- Class c = null;
+ public void prePopulateLCClasses() {
+
+ int classID;
+
+ prepopulateClass("netscape/javascript/JSObject");
+ classID = prepopulateClass("netscape/javascript/JSException");
+ prepopulateMethod(classID, "<init>", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)");
+ prepopulateMethod(classID, "<init>", "(ILjava/lang/Object;)");
+ prepopulateField(classID, "lineno");
+ prepopulateField(classID, "tokenIndex");
+ prepopulateField(classID, "source");
+ prepopulateField(classID, "filename");
+ prepopulateField(classID, "wrappedExceptionType");
+ prepopulateField(classID, "wrappedException");
+
+ classID = prepopulateClass("netscape/javascript/JSUtil");
+ prepopulateMethod(classID, "getStackTrace", "(Ljava/lang/Throwable;)");
+
+ prepopulateClass("java/lang/Object");
+ classID = prepopulateClass("java/lang/Class");
+ prepopulateMethod(classID, "getMethods", "()");
+ prepopulateMethod(classID, "getConstructors", "()");
+ prepopulateMethod(classID, "getFields", "()");
+ prepopulateMethod(classID, "getName", "()");
+ prepopulateMethod(classID, "isArray", "()");
+ prepopulateMethod(classID, "getComponentType", "()");
+ prepopulateMethod(classID, "getModifiers", "()");
+
+ classID = prepopulateClass("java/lang/reflect/Method");
+ prepopulateMethod(classID, "getName", "()");
+ prepopulateMethod(classID, "getParameterTypes", "()");
+ prepopulateMethod(classID, "getReturnType", "()");
+ prepopulateMethod(classID, "getModifiers", "()");
+
+ classID = prepopulateClass("java/lang/reflect/Constructor");
+ prepopulateMethod(classID, "getParameterTypes", "()");
+ prepopulateMethod(classID, "getModifiers", "()");
+
+ classID = prepopulateClass("java/lang/reflect/Field");
+ prepopulateMethod(classID, "getName", "()");
+ prepopulateMethod(classID, "getType", "()");
+ prepopulateMethod(classID, "getModifiers", "()");
+
+ classID = prepopulateClass("java/lang/reflect/Array");
+ prepopulateMethod(classID, "newInstance", "(Ljava/lang/Class;I)");
+
+ classID = prepopulateClass("java/lang/Throwable");
+ prepopulateMethod(classID, "toString", "()");
+ prepopulateMethod(classID, "getMessage", "()");
+
+ classID = prepopulateClass("java/lang/System");
+ prepopulateMethod(classID, "identityHashCode", "(Ljava/lang/Object;)");
+
+ classID = prepopulateClass("java/lang/Boolean");
+ prepopulateMethod(classID, "booleanValue", "()");
+ prepopulateMethod(classID, "<init>", "(Z)");
+
+ classID = prepopulateClass("java/lang/Double");
+ prepopulateMethod(classID, "doubleValue", "()");
+ prepopulateMethod(classID, "<init>", "(D)");
+
+ classID = prepopulateClass("java/lang/Void");
+ prepopulateField(classID, "TYPE");
+
+ prepopulateClass("java/lang/String");
+ prepopulateClass("java/applet/Applet");
+ }
- try {
- c = cl.loadClass(name);
- store.reference(c);
- } catch (ClassNotFoundException cnfe) {
- // do nothing ... this should never happen
- cnfe.printStackTrace();
- }
+ private int prepopulateClass(String name) {
+ name = name.replace('/', '.');
+ ClassLoader cl = liveconnectLoader;
+ Class c = null;
- return store.getIdentifier(c);
+ try {
+ c = cl.loadClass(name);
+ store.reference(c);
+ } catch (ClassNotFoundException cnfe) {
+ // do nothing ... this should never happen
+ cnfe.printStackTrace();
}
- private int prepopulateMethod(int classID, String methodName, String signatureStr) {
- Signature signature = parseCall(signatureStr, ((Class) store.getObject(classID)).getClassLoader(), Signature.class);
- Object[] a = signature.getClassArray();
+ return store.getIdentifier(c);
+ }
- Class<?> c = (Class<?>) store.getObject(classID);
- Method m = null;
- Constructor cs = null;
- Object o = null;
+ private int prepopulateMethod(int classID, String methodName, String signatureStr) {
+ Signature signature = parseCall(signatureStr, ((Class) store.getObject(classID)).getClassLoader(), Signature.class);
+ Object[] a = signature.getClassArray();
- try {
- if (methodName.equals("<init>")
- || methodName.equals("<clinit>")) {
- o = cs = c.getConstructor(signature.getClassArray());
- store.reference(cs);
- } else {
- o = m = c.getMethod(methodName, signature.getClassArray());
- store.reference(m);
- }
- } catch (NoSuchMethodException e) {
- // should never happen
- e.printStackTrace();
- }
+ Class<?> c = (Class<?>) store.getObject(classID);
+ Method m = null;
+ Constructor cs = null;
+ Object o = null;
- return store.getIdentifier(m);
+ try {
+ if (methodName.equals("<init>")
+ || methodName.equals("<clinit>")) {
+ o = cs = c.getConstructor(signature.getClassArray());
+ store.reference(cs);
+ } else {
+ o = m = c.getMethod(methodName, signature.getClassArray());
+ store.reference(m);
+ }
+ } catch (NoSuchMethodException e) {
+ // should never happen
+ e.printStackTrace();
}
- private int prepopulateField(int classID, String fieldName) {
+ return store.getIdentifier(m);
+ }
- Class<?> c = (Class<?>) store.getObject(classID);
- Field f = null;
- try {
- f = c.getField(fieldName);
- } catch (SecurityException e) {
- // should never happen
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- // should never happen
- e.printStackTrace();
- }
+ private int prepopulateField(int classID, String fieldName) {
- store.reference(f);
- return store.getIdentifier(f);
+ Class<?> c = (Class<?>) store.getObject(classID);
+ Field f = null;
+ try {
+ f = c.getField(fieldName);
+ } catch (SecurityException e) {
+ // should never happen
+ e.printStackTrace();
+ } catch (NoSuchFieldException e) {
+ // should never happen
+ e.printStackTrace();
}
- public void dumpStore() {
- store.dump();
- }
+ store.reference(f);
+ return store.getIdentifier(f);
+ }
- public Object getObject(int identifier) {
- return store.getObject(identifier);
- }
+ public void dumpStore() {
+ store.dump();
+ }
- public int getIdentifier(Object o) {
- return store.getIdentifier(o);
- }
+ public Object getObject(int identifier) {
+ return store.getObject(identifier);
+ }
- public void store(Object o) {
- store.reference(o);
- }
+ public int getIdentifier(Object o) {
+ return store.getIdentifier(o);
+ }
- /**
- * Returns a "closed" AccessControlContext i.e. no permissions to get out of sandbox.
- */
- public AccessControlContext getClosedAccessControlContext() {
- // Deny everything
- Permissions p = new Permissions();
- ProtectionDomain pd = new ProtectionDomain(null, p);
- return new AccessControlContext(new ProtectionDomain[] {pd});
- }
+ public void store(Object o) {
+ store.reference(o);
+ }
+
+ /**
+ * Returns a "closed" AccessControlContext i.e. no permissions to get out of sandbox.
+ */
+ public AccessControlContext getClosedAccessControlContext() {
+ // Deny everything
+ Permissions p = new Permissions();
+ ProtectionDomain pd = new ProtectionDomain(null, p);
+ return new AccessControlContext(new ProtectionDomain[] { pd });
+ }
- public AccessControlContext getAccessControlContext(String[] nsPrivilegeList, String src) {
-
-/*
- for (int i=0; i < nsPrivilegeList.length; i++) {
- String privilege = nsPrivilegeList[i];
-
- if (privilege.equals("UniversalAccept")) {
- SocketPermission sp = new SocketPermission("*", "accept,resolve");
- grantedPermissions.add(sp);
- } else if (privilege.equals("UniversalAwtEventQueueAccess")) {
- AWTPermission awtp = new AWTPermission("accessEventQueue");
- grantedPermissions.add(awtp);
- } else if (privilege.equals("UniversalConnect")) {
- SocketPermission sp = new SocketPermission("*", "connect,resolve");
- grantedPermissions.add(sp);
- } else if (privilege.equals("UniversalListen")) {
- SocketPermission sp = new SocketPermission("*", "listen,resolve");
- grantedPermissions.add(sp);
- } else if (privilege.equals("UniversalExecAccess")) {
- FilePermission fp = new FilePermission("<<ALL FILES>>", "execute");
- RuntimePermission rtp = new RuntimePermission("setIO");
- grantedPermissions.add(fp);
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalExitAccess")) {
- // Doesn't matter what the permissions are. Do not allow VM to exit.. we
- // use a single VM for the entire browser lifecycle once invoked, we
- // cannot let it exit
-
- //RuntimePermission rtp = new RuntimePermission("exitVM.*");
- //grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalFileDelete")) {
- FilePermission fp = new FilePermission("<<ALL FILES>>", "delete");
- grantedPermissions.add(fp);
- } else if (privilege.equals("UniversalFileRead")) {
- FilePermission fp = new FilePermission("<<ALL FILES>>", "read");
- grantedPermissions.add(fp);
- } else if (privilege.equals("UniversalFileWrite")) {
- FilePermission fp = new FilePermission("<<ALL FILES>>", "write");
- grantedPermissions.add(fp);
- } else if (privilege.equals("UniversalFdRead")) {
- RuntimePermission rtp = new RuntimePermission("readFileDescriptor");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalFdWrite")) {
- RuntimePermission rtp = new RuntimePermission("writeFileDescriptor");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalLinkAccess")) {
- RuntimePermission rtp = new RuntimePermission("loadLibrary.*");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalListen")) {
- SocketPermission sp = new SocketPermission("*", "listen");
- grantedPermissions.add(sp);
- } else if (privilege.equals("UniversalMulticast")) {
- SocketPermission sp = new SocketPermission("*", "accept,connect,resolve");
- grantedPermissions.add(sp);
- } else if (privilege.equals("UniversalPackageAccess")) {
- RuntimePermission rtp = new RuntimePermission("defineClassInPackage.*");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalPackageDefinition")) {
- RuntimePermission rtp = new RuntimePermission("accessClassInPackage.*");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalPrintJobAccess")) {
- RuntimePermission rtp = new RuntimePermission("queuePrintJob");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalPropertyRead")) {
- PropertyPermission pp = new PropertyPermission("*", "read");
- grantedPermissions.add(pp);
- } else if (privilege.equals("UniversalPropertyWrite")) {
- PropertyPermission pp = new PropertyPermission("*", "write");
- grantedPermissions.add(pp);
- } else if (privilege.equals("UniversalSetFactory")) {
- RuntimePermission rtp = new RuntimePermission("setFactory");
- grantedPermissions.add(rtp);
- } else if (privilege.equals("UniversalSystemClipboardAccess")) {
- AWTPermission awtp = new AWTPermission("accessClipboard");
- grantedPermissions.add(awtp);
- } else if (privilege.equals("UniversalThreadAccess")) {
- RuntimePermission rtp1 = new RuntimePermission("modifyThread");
- RuntimePermission rtp2 = new RuntimePermission("stopThread");
- grantedPermissions.add(rtp1);
- grantedPermissions.add(rtp2);
- } else if (privilege.equals("UniversalThreadGroupAccess")) {
- RuntimePermission rtp1 = new RuntimePermission("modifyThreadGroup");
- RuntimePermission rtp2 = new RuntimePermission("modifyThread");
- RuntimePermission rtp3 = new RuntimePermission("stopThread");
- grantedPermissions.add(rtp1);
- grantedPermissions.add(rtp2);
- grantedPermissions.add(rtp3);
- } else if (privilege.equals("UniversalTopLevelWindow")) {
- AWTPermission awtp = new AWTPermission("topLevelWindow");
- grantedPermissions.add(awtp);
- } else if (privilege.equals("UniversalBrowserRead")) {
- BrowserReadPermission bp = new BrowserReadPermission();
- grantedPermissions.add(bp);
- } else if (privilege.equals("UniversalJavaPermissions")) {
- AllPermission ap = new AllPermission();
- grantedPermissions.add(ap);
+ public AccessControlContext getAccessControlContext(String[] nsPrivilegeList, String src) {
+
+ /*
+ for (int i=0; i < nsPrivilegeList.length; i++) {
+ String privilege = nsPrivilegeList[i];
+
+ if (privilege.equals("UniversalAccept")) {
+ SocketPermission sp = new SocketPermission("*", "accept,resolve");
+ grantedPermissions.add(sp);
+ } else if (privilege.equals("UniversalAwtEventQueueAccess")) {
+ AWTPermission awtp = new AWTPermission("accessEventQueue");
+ grantedPermissions.add(awtp);
+ } else if (privilege.equals("UniversalConnect")) {
+ SocketPermission sp = new SocketPermission("*", "connect,resolve");
+ grantedPermissions.add(sp);
+ } else if (privilege.equals("UniversalListen")) {
+ SocketPermission sp = new SocketPermission("*", "listen,resolve");
+ grantedPermissions.add(sp);
+ } else if (privilege.equals("UniversalExecAccess")) {
+ FilePermission fp = new FilePermission("<<ALL FILES>>", "execute");
+ RuntimePermission rtp = new RuntimePermission("setIO");
+ grantedPermissions.add(fp);
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalExitAccess")) {
+ // Doesn't matter what the permissions are. Do not allow VM to exit.. we
+ // use a single VM for the entire browser lifecycle once invoked, we
+ // cannot let it exit
+
+ //RuntimePermission rtp = new RuntimePermission("exitVM.*");
+ //grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalFileDelete")) {
+ FilePermission fp = new FilePermission("<<ALL FILES>>", "delete");
+ grantedPermissions.add(fp);
+ } else if (privilege.equals("UniversalFileRead")) {
+ FilePermission fp = new FilePermission("<<ALL FILES>>", "read");
+ grantedPermissions.add(fp);
+ } else if (privilege.equals("UniversalFileWrite")) {
+ FilePermission fp = new FilePermission("<<ALL FILES>>", "write");
+ grantedPermissions.add(fp);
+ } else if (privilege.equals("UniversalFdRead")) {
+ RuntimePermission rtp = new RuntimePermission("readFileDescriptor");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalFdWrite")) {
+ RuntimePermission rtp = new RuntimePermission("writeFileDescriptor");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalLinkAccess")) {
+ RuntimePermission rtp = new RuntimePermission("loadLibrary.*");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalListen")) {
+ SocketPermission sp = new SocketPermission("*", "listen");
+ grantedPermissions.add(sp);
+ } else if (privilege.equals("UniversalMulticast")) {
+ SocketPermission sp = new SocketPermission("*", "accept,connect,resolve");
+ grantedPermissions.add(sp);
+ } else if (privilege.equals("UniversalPackageAccess")) {
+ RuntimePermission rtp = new RuntimePermission("defineClassInPackage.*");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalPackageDefinition")) {
+ RuntimePermission rtp = new RuntimePermission("accessClassInPackage.*");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalPrintJobAccess")) {
+ RuntimePermission rtp = new RuntimePermission("queuePrintJob");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalPropertyRead")) {
+ PropertyPermission pp = new PropertyPermission("*", "read");
+ grantedPermissions.add(pp);
+ } else if (privilege.equals("UniversalPropertyWrite")) {
+ PropertyPermission pp = new PropertyPermission("*", "write");
+ grantedPermissions.add(pp);
+ } else if (privilege.equals("UniversalSetFactory")) {
+ RuntimePermission rtp = new RuntimePermission("setFactory");
+ grantedPermissions.add(rtp);
+ } else if (privilege.equals("UniversalSystemClipboardAccess")) {
+ AWTPermission awtp = new AWTPermission("accessClipboard");
+ grantedPermissions.add(awtp);
+ } else if (privilege.equals("UniversalThreadAccess")) {
+ RuntimePermission rtp1 = new RuntimePermission("modifyThread");
+ RuntimePermission rtp2 = new RuntimePermission("stopThread");
+ grantedPermissions.add(rtp1);
+ grantedPermissions.add(rtp2);
+ } else if (privilege.equals("UniversalThreadGroupAccess")) {
+ RuntimePermission rtp1 = new RuntimePermission("modifyThreadGroup");
+ RuntimePermission rtp2 = new RuntimePermission("modifyThread");
+ RuntimePermission rtp3 = new RuntimePermission("stopThread");
+ grantedPermissions.add(rtp1);
+ grantedPermissions.add(rtp2);
+ grantedPermissions.add(rtp3);
+ } else if (privilege.equals("UniversalTopLevelWindow")) {
+ AWTPermission awtp = new AWTPermission("topLevelWindow");
+ grantedPermissions.add(awtp);
+ } else if (privilege.equals("UniversalBrowserRead")) {
+ BrowserReadPermission bp = new BrowserReadPermission();
+ grantedPermissions.add(bp);
+ } else if (privilege.equals("UniversalJavaPermissions")) {
+ AllPermission ap = new AllPermission();
+ grantedPermissions.add(ap);
+ }
}
- }
- // what to do with these is unknown: UniversalConnectWithRedirect, UniversalDialogModality, UniversalSendMail, LimitedInstall, FullInstall, SilentInstall
-*/
+ // what to do with these is unknown: UniversalConnectWithRedirect, UniversalDialogModality, UniversalSendMail, LimitedInstall, FullInstall, SilentInstall
+ */
- Permissions grantedPermissions = new Permissions();
+ Permissions grantedPermissions = new Permissions();
- for (int i=0; i < nsPrivilegeList.length; i++) {
- String privilege = nsPrivilegeList[i];
+ for (int i = 0; i < nsPrivilegeList.length; i++) {
+ String privilege = nsPrivilegeList[i];
- if (privilege.equals("UniversalBrowserRead")) {
- BrowserReadPermission bp = new BrowserReadPermission();
- grantedPermissions.add(bp);
- } else if (privilege.equals("UniversalJavaPermission")) {
- AllPermission ap = new AllPermission();
- grantedPermissions.add(ap);
- }
- }
+ if (privilege.equals("UniversalBrowserRead")) {
+ BrowserReadPermission bp = new BrowserReadPermission();
+ grantedPermissions.add(bp);
+ } else if (privilege.equals("UniversalJavaPermission")) {
+ AllPermission ap = new AllPermission();
+ grantedPermissions.add(ap);
+ }
+ }
- CodeSource cs = new CodeSource((URL) null, (java.security.cert.Certificate [])null);
+ CodeSource cs = new CodeSource((URL) null, (java.security.cert.Certificate[]) null);
- if (src != null && src.length() > 0) {
- try {
- cs = new CodeSource(new URL(src + "/"), (java.security.cert.Certificate[]) null);
- } catch (MalformedURLException mfue) {
- // do nothing
- }
+ if (src != null && src.length() > 0) {
+ try {
+ cs = new CodeSource(new URL(src + "/"), (java.security.cert.Certificate[]) null);
+ } catch (MalformedURLException mfue) {
+ // do nothing
+ }
- if (src.equals("[System]"))
- grantedPermissions.add(new JSObjectCreatePermission());
+ if (src.equals("[System]"))
+ grantedPermissions.add(new JSObjectCreatePermission());
- } else {
- JSObjectCreatePermission perm = new JSObjectCreatePermission();
- grantedPermissions.add(perm);
- }
+ } else {
+ JSObjectCreatePermission perm = new JSObjectCreatePermission();
+ grantedPermissions.add(perm);
+ }
- ProtectionDomain pd = new ProtectionDomain(cs, grantedPermissions, null, null);
+ ProtectionDomain pd = new ProtectionDomain(cs, grantedPermissions, null, null);
- // Add to hashmap
- return new AccessControlContext(new ProtectionDomain[] {pd});
- }
+ // Add to hashmap
+ return new AccessControlContext(new ProtectionDomain[] { pd });
+ }
// private static final == inline
private static final boolean isInt(Object o) {
@@ -1491,10 +1487,10 @@ public class PluginAppletSecurityContext {
return isInt;
}
- class BrowserReadPermission extends BasicPermission {
- public BrowserReadPermission() {
- super("browserRead");
- }
+ class BrowserReadPermission extends BasicPermission {
+ public BrowserReadPermission() {
+ super("browserRead");
}
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
index 29a3103..ca90b70 100644
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
@@ -60,9 +60,9 @@ exception statement from your version. */
* have any questions.
*/
- package sun.applet;
+package sun.applet;
- import java.applet.Applet;
+import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.awt.Dimension;
@@ -115,368 +115,362 @@ import sun.misc.Ref;
import com.sun.jndi.toolkit.url.UrlUtil;
- /**
- * Lets us construct one using unix-style one shot behaviors
- */
+/**
+ * Lets us construct one using unix-style one shot behaviors
+ */
- class PluginAppletPanelFactory
- {
+class PluginAppletPanelFactory {
- public AppletPanel createPanel(PluginStreamHandler streamhandler,
+ public AppletPanel createPanel(PluginStreamHandler streamhandler,
int identifier,
long handle, int x, int y,
final URL doc,
- final Hashtable<String,String> atts) {
- AppletViewerPanel panel = AccessController.doPrivileged(new PrivilegedAction<AppletViewerPanel>() {
- public AppletViewerPanel run() {
- try {
- AppletViewerPanel panel = new NetxPanel(doc, atts, false);
- AppletViewerPanel.debug("Using NetX panel");
- PluginDebug.debug(atts.toString());
- return panel;
- } catch (Exception ex) {
- AppletViewerPanel.debug("Unable to start NetX applet - defaulting to Sun applet", ex);
- return new AppletViewerPanel(doc, atts);
- }
- }
- });
+ final Hashtable<String, String> atts) {
+ AppletViewerPanel panel = AccessController.doPrivileged(new PrivilegedAction<AppletViewerPanel>() {
+ public AppletViewerPanel run() {
+ try {
+ AppletViewerPanel panel = new NetxPanel(doc, atts, false);
+ AppletViewerPanel.debug("Using NetX panel");
+ PluginDebug.debug(atts.toString());
+ return panel;
+ } catch (Exception ex) {
+ AppletViewerPanel.debug("Unable to start NetX applet - defaulting to Sun applet", ex);
+ return new AppletViewerPanel(doc, atts);
+ }
+ }
+ });
- // create the frame.
- PluginAppletViewer.framePanel(identifier, System.out, handle, panel);
+ // create the frame.
+ PluginAppletViewer.framePanel(identifier, System.out, handle, panel);
- panel.init();
+ panel.init();
- // Start the applet
- initEventQueue(panel);
+ // Start the applet
+ initEventQueue(panel);
- // Applet initialized. Find out it's classloader and add it to the list
- String portComponent = doc.getPort() != -1 ? ":" + doc.getPort() : "";
- String codeBase = doc.getProtocol() + "://" + doc.getHost() + portComponent;
+ // Applet initialized. Find out it's classloader and add it to the list
+ String portComponent = doc.getPort() != -1 ? ":" + doc.getPort() : "";
+ String codeBase = doc.getProtocol() + "://" + doc.getHost() + portComponent;
- if (atts.get("codebase") != null) {
- try {
- URL appletSrcURL = new URL(codeBase + atts.get("codebase"));
- codeBase = appletSrcURL.getProtocol() + "://" + appletSrcURL.getHost();
- } catch (MalformedURLException mfue) {
- // do nothing
- }
- }
-
-
- // Wait for the panel to initialize
- // (happens in a separate thread)
- Applet a;
-
- // Wait for panel to come alive
- int maxWait = PluginAppletViewer.APPLET_TIMEOUT; // wait for panel to come alive
- int wait = 0;
- while ((panel == null) || (!((NetxPanel) panel).isAlive() && wait < maxWait)) {
- try {
- Thread.sleep(50);
- wait += 50;
- } catch (InterruptedException ie) {
- // just wait
- }
- }
-
- // Wait for the panel to initialize
- // (happens in a separate thread)
- PluginAppletViewer.waitForAppletInit((NetxPanel) panel);
-
- a = panel.getApplet();
-
- // Still null?
- if (panel.getApplet() == null) {
- streamhandler.write("instance " + identifier + " reference " + -1 + " fatalError " + "Initialization failed");
- return null;
- }
-
- PluginDebug.debug("Applet " + a.getClass() + " initialized");
- streamhandler.write("instance " + identifier + " reference 0 initialized");
-
- AppletSecurityContextManager.getSecurityContext(0).associateSrc(((NetxPanel) panel).getAppletClassLoader(), doc);
- AppletSecurityContextManager.getSecurityContext(0).associateInstance(identifier, ((NetxPanel) panel).getAppletClassLoader());
-
- return panel;
- }
-
- public boolean isStandalone()
- {
- return false;
- }
-
- /**
- * Send the initial set of events to the appletviewer event queue.
- * On start-up the current behaviour is to load the applet and call
- * Applet.init() and Applet.start().
- */
- private void initEventQueue(AppletPanel panel) {
- // appletviewer.send.event is an undocumented and unsupported system
- // property which is used exclusively for testing purposes.
- PrivilegedAction<String> pa = new PrivilegedAction<String>() {
- public String run() {
- return System.getProperty("appletviewer.send.event");
- }
- };
- String eventList = AccessController.doPrivileged(pa);
-
- if (eventList == null) {
- // Add the standard events onto the event queue.
- panel.sendEvent(AppletPanel.APPLET_LOAD);
- panel.sendEvent(AppletPanel.APPLET_INIT);
- panel.sendEvent(AppletPanel.APPLET_START);
- } else {
- // We're testing AppletViewer. Force the specified set of events
- // onto the event queue, wait for the events to be processed, and
- // exit.
-
- // The list of events that will be executed is provided as a
- // ","-separated list. No error-checking will be done on the list.
- String [] events = splitSeparator(",", eventList);
-
- for (int i = 0; i < events.length; i++) {
- PluginDebug.debug("Adding event to queue: " + events[i]);
- if (events[i].equals("dispose"))
- panel.sendEvent(AppletPanel.APPLET_DISPOSE);
- else if (events[i].equals("load"))
- panel.sendEvent(AppletPanel.APPLET_LOAD);
- else if (events[i].equals("init"))
- panel.sendEvent(AppletPanel.APPLET_INIT);
- else if (events[i].equals("start"))
- panel.sendEvent(AppletPanel.APPLET_START);
- else if (events[i].equals("stop"))
- panel.sendEvent(AppletPanel.APPLET_STOP);
- else if (events[i].equals("destroy"))
- panel.sendEvent(AppletPanel.APPLET_DESTROY);
- else if (events[i].equals("quit"))
- panel.sendEvent(AppletPanel.APPLET_QUIT);
- else if (events[i].equals("error"))
- panel.sendEvent(AppletPanel.APPLET_ERROR);
- else
- // non-fatal error if we get an unrecognized event
- PluginDebug.debug("Unrecognized event name: " + events[i]);
- }
+ if (atts.get("codebase") != null) {
+ try {
+ URL appletSrcURL = new URL(codeBase + atts.get("codebase"));
+ codeBase = appletSrcURL.getProtocol() + "://" + appletSrcURL.getHost();
+ } catch (MalformedURLException mfue) {
+ // do nothing
+ }
+ }
- while (!panel.emptyEventQueue()) ;
- }
- }
-
-
- /**
- * Split a string based on the presence of a specified separator. Returns
- * an array of arbitrary length. The end of each element in the array is
- * indicated by the separator of the end of the string. If there is a
- * separator immediately before the end of the string, the final element
- * will be empty. None of the strings will contain the separator. Useful
- * when separating strings such as "foo/bar/bas" using separator "/".
- *
- * @param sep The separator.
- * @param s The string to split.
- * @return An array of strings. Each string in the array is determined
- * by the location of the provided sep in the original string,
- * s. Whitespace not stripped.
- */
- private String [] splitSeparator(String sep, String s) {
- List<String> l = new ArrayList<String>();
- int tokenStart = 0;
- int tokenEnd = 0;
-
- while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
- l.add(s.substring(tokenStart, tokenEnd));
- tokenStart = tokenEnd+1;
- }
- // Add the final element.
- l.add(s.substring(tokenStart));
-
- return l.toArray(new String[l.size()]);
- }
- }
-
- class PluginParseRequest
- {
- long handle;
- String tag;
- String documentbase;
- }
-
- /*
- */
- // FIXME: declare JSProxy implementation
- public class PluginAppletViewer extends XEmbeddedFrame
- implements AppletContext, Printable {
- /**
- * Some constants...
- */
- private static String defaultSaveFile = "Applet.ser";
+ // Wait for the panel to initialize
+ // (happens in a separate thread)
+ Applet a;
+
+ // Wait for panel to come alive
+ int maxWait = PluginAppletViewer.APPLET_TIMEOUT; // wait for panel to come alive
+ int wait = 0;
+ while ((panel == null) || (!((NetxPanel) panel).isAlive() && wait < maxWait)) {
+ try {
+ Thread.sleep(50);
+ wait += 50;
+ } catch (InterruptedException ie) {
+ // just wait
+ }
+ }
+
+ // Wait for the panel to initialize
+ // (happens in a separate thread)
+ PluginAppletViewer.waitForAppletInit((NetxPanel) panel);
+
+ a = panel.getApplet();
+
+ // Still null?
+ if (panel.getApplet() == null) {
+ streamhandler.write("instance " + identifier + " reference " + -1 + " fatalError " + "Initialization failed");
+ return null;
+ }
+
+ PluginDebug.debug("Applet " + a.getClass() + " initialized");
+ streamhandler.write("instance " + identifier + " reference 0 initialized");
+
+ AppletSecurityContextManager.getSecurityContext(0).associateSrc(((NetxPanel) panel).getAppletClassLoader(), doc);
+ AppletSecurityContextManager.getSecurityContext(0).associateInstance(identifier, ((NetxPanel) panel).getAppletClassLoader());
+
+ return panel;
+ }
+
+ public boolean isStandalone() {
+ return false;
+ }
+
+ /**
+ * Send the initial set of events to the appletviewer event queue.
+ * On start-up the current behaviour is to load the applet and call
+ * Applet.init() and Applet.start().
+ */
+ private void initEventQueue(AppletPanel panel) {
+ // appletviewer.send.event is an undocumented and unsupported system
+ // property which is used exclusively for testing purposes.
+ PrivilegedAction<String> pa = new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("appletviewer.send.event");
+ }
+ };
+ String eventList = AccessController.doPrivileged(pa);
+
+ if (eventList == null) {
+ // Add the standard events onto the event queue.
+ panel.sendEvent(AppletPanel.APPLET_LOAD);
+ panel.sendEvent(AppletPanel.APPLET_INIT);
+ panel.sendEvent(AppletPanel.APPLET_START);
+ } else {
+ // We're testing AppletViewer. Force the specified set of events
+ // onto the event queue, wait for the events to be processed, and
+ // exit.
+
+ // The list of events that will be executed is provided as a
+ // ","-separated list. No error-checking will be done on the list.
+ String[] events = splitSeparator(",", eventList);
+
+ for (int i = 0; i < events.length; i++) {
+ PluginDebug.debug("Adding event to queue: " + events[i]);
+ if (events[i].equals("dispose"))
+ panel.sendEvent(AppletPanel.APPLET_DISPOSE);
+ else if (events[i].equals("load"))
+ panel.sendEvent(AppletPanel.APPLET_LOAD);
+ else if (events[i].equals("init"))
+ panel.sendEvent(AppletPanel.APPLET_INIT);
+ else if (events[i].equals("start"))
+ panel.sendEvent(AppletPanel.APPLET_START);
+ else if (events[i].equals("stop"))
+ panel.sendEvent(AppletPanel.APPLET_STOP);
+ else if (events[i].equals("destroy"))
+ panel.sendEvent(AppletPanel.APPLET_DESTROY);
+ else if (events[i].equals("quit"))
+ panel.sendEvent(AppletPanel.APPLET_QUIT);
+ else if (events[i].equals("error"))
+ panel.sendEvent(AppletPanel.APPLET_ERROR);
+ else
+ // non-fatal error if we get an unrecognized event
+ PluginDebug.debug("Unrecognized event name: " + events[i]);
+ }
+
+ while (!panel.emptyEventQueue())
+ ;
+ }
+ }
+ /**
+ * Split a string based on the presence of a specified separator. Returns
+ * an array of arbitrary length. The end of each element in the array is
+ * indicated by the separator of the end of the string. If there is a
+ * separator immediately before the end of the string, the final element
+ * will be empty. None of the strings will contain the separator. Useful
+ * when separating strings such as "foo/bar/bas" using separator "/".
+ *
+ * @param sep The separator.
+ * @param s The string to split.
+ * @return An array of strings. Each string in the array is determined
+ * by the location of the provided sep in the original string,
+ * s. Whitespace not stripped.
+ */
+ private String[] splitSeparator(String sep, String s) {
+ List<String> l = new ArrayList<String>();
+ int tokenStart = 0;
+ int tokenEnd = 0;
+
+ while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
+ l.add(s.substring(tokenStart, tokenEnd));
+ tokenStart = tokenEnd + 1;
+ }
+ // Add the final element.
+ l.add(s.substring(tokenStart));
+
+ return l.toArray(new String[l.size()]);
+ }
+}
+
+class PluginParseRequest {
+ long handle;
+ String tag;
+ String documentbase;
+}
+
+/*
+ */
+// FIXME: declare JSProxy implementation
+public class PluginAppletViewer extends XEmbeddedFrame
+ implements AppletContext, Printable {
+ /**
+ * Some constants...
+ */
+ private static String defaultSaveFile = "Applet.ser";
- /**
- * Enumerates the current status of an applet
- *
- * PRE_INIT -> Parsing and initialization phase
- * INIT_COMPLETE -> Initialization complete, reframe pending
- * REFRAME_COMPLETE -> Reframe complete, applet is initialized and usable by the user
- * INACTIVE -> Browser has directed that the applet be destroyed (this state is non-overridable except by DESTROYED)
- * DESTROYED -> Applet has been destroyed
- */
- private static enum PAV_INIT_STATUS {PRE_INIT, INIT_COMPLETE, REFRAME_COMPLETE, INACTIVE, DESTROYED};
+ /**
+ * Enumerates the current status of an applet
+ *
+ * PRE_INIT -> Parsing and initialization phase
+ * INIT_COMPLETE -> Initialization complete, reframe pending
+ * REFRAME_COMPLETE -> Reframe complete, applet is initialized and usable by the user
+ * INACTIVE -> Browser has directed that the applet be destroyed (this state is non-overridable except by DESTROYED)
+ * DESTROYED -> Applet has been destroyed
+ */
+ private static enum PAV_INIT_STATUS {
+ PRE_INIT, INIT_COMPLETE, REFRAME_COMPLETE, INACTIVE, DESTROYED
+ };
- /**
- * The panel in which the applet is being displayed.
- */
- AppletViewerPanel panel;
+ /**
+ * The panel in which the applet is being displayed.
+ */
+ AppletViewerPanel panel;
- /**
- * The status line.
- */
- Label label;
+ /**
+ * The status line.
+ */
+ Label label;
- /**
- * output status messages to this stream
- */
+ /**
+ * output status messages to this stream
+ */
- PrintStream statusMsgStream;
+ PrintStream statusMsgStream;
- int identifier;
+ int identifier;
- private static HashMap<Integer, PluginParseRequest> requests =
- new HashMap<Integer,PluginParseRequest>();
+ private static HashMap<Integer, PluginParseRequest> requests =
+ new HashMap<Integer, PluginParseRequest>();
- // Instance identifier -> PluginAppletViewer object.
- private static HashMap<Integer, PluginAppletViewer> applets =
- new HashMap<Integer,PluginAppletViewer>();
+ // Instance identifier -> PluginAppletViewer object.
+ private static HashMap<Integer, PluginAppletViewer> applets =
+ new HashMap<Integer, PluginAppletViewer>();
- private static PluginStreamHandler streamhandler;
+ private static PluginStreamHandler streamhandler;
- private static PluginCallRequestFactory requestFactory;
+ private static PluginCallRequestFactory requestFactory;
- private static HashMap<Integer, PAV_INIT_STATUS> status =
- new HashMap<Integer,PAV_INIT_STATUS>();
+ private static HashMap<Integer, PAV_INIT_STATUS> status =
+ new HashMap<Integer, PAV_INIT_STATUS>();
- private long handle = 0;
- private WindowListener windowEventListener = null;
- private AppletEventListener appletEventListener = null;
+ private long handle = 0;
+ private WindowListener windowEventListener = null;
+ private AppletEventListener appletEventListener = null;
- public static final int APPLET_TIMEOUT = 180000;
+ public static final int APPLET_TIMEOUT = 180000;
- private static Long requestIdentityCounter = 0L;
+ private static Long requestIdentityCounter = 0L;
- private Image bufFrameImg;
- private Graphics bufFrameImgGraphics;
+ private Image bufFrameImg;
+ private Graphics bufFrameImgGraphics;
- /**
- * Null constructor to allow instantiation via newInstance()
- */
- public PluginAppletViewer() {
- }
+ /**
+ * Null constructor to allow instantiation via newInstance()
+ */
+ public PluginAppletViewer() {
+ }
- public static void framePanel(int identifier, PrintStream statusMsgStream,
+ public static void framePanel(int identifier, PrintStream statusMsgStream,
long handle, AppletViewerPanel panel) {
- PluginDebug.debug("Framing " + panel);
+ PluginDebug.debug("Framing " + panel);
- // SecurityManager MUST be set, and only privileged code may call reFrame()
- System.getSecurityManager().checkPermission(new AllPermission());
+ // SecurityManager MUST be set, and only privileged code may call reFrame()
+ System.getSecurityManager().checkPermission(new AllPermission());
- PluginAppletViewer appletFrame = new PluginAppletViewer(handle, identifier, statusMsgStream, panel);
+ PluginAppletViewer appletFrame = new PluginAppletViewer(handle, identifier, statusMsgStream, panel);
- appletFrame.add("Center", panel);
- appletFrame.pack();
+ appletFrame.add("Center", panel);
+ appletFrame.pack();
- appletFrame.appletEventListener = new AppletEventListener(appletFrame, appletFrame);
- panel.addAppletListener(appletFrame.appletEventListener);
+ appletFrame.appletEventListener = new AppletEventListener(appletFrame, appletFrame);
+ panel.addAppletListener(appletFrame.appletEventListener);
- applets.put(identifier, appletFrame);
+ applets.put(identifier, appletFrame);
- PluginDebug.debug(panel + " framed");
- }
+ PluginDebug.debug(panel + " framed");
+ }
- /**
- * Create new plugin appletviewer frame
- */
- private PluginAppletViewer(long handle, final int identifier,
+ /**
+ * Create new plugin appletviewer frame
+ */
+ private PluginAppletViewer(long handle, final int identifier,
PrintStream statusMsgStream,
AppletViewerPanel appletPanel) {
- super(handle, true);
- this.statusMsgStream = statusMsgStream;
- this.identifier = identifier;
- this.panel = appletPanel;
+ super(handle, true);
+ this.statusMsgStream = statusMsgStream;
+ this.identifier = identifier;
+ this.panel = appletPanel;
- if (!appletPanels.contains(panel))
- appletPanels.addElement(panel);
+ if (!appletPanels.contains(panel))
+ appletPanels.addElement(panel);
- windowEventListener = new WindowAdapter() {
+ windowEventListener = new WindowAdapter() {
- public void windowClosing(WindowEvent evt) {
- appletClose();
- }
+ public void windowClosing(WindowEvent evt) {
+ appletClose();
+ }
- public void windowIconified(WindowEvent evt) {
- appletStop();
- }
+ public void windowIconified(WindowEvent evt) {
+ appletStop();
+ }
- public void windowDeiconified(WindowEvent evt) {
- appletStart();
- }
- };
+ public void windowDeiconified(WindowEvent evt) {
+ appletStart();
+ }
+ };
- addWindowListener(windowEventListener);
+ addWindowListener(windowEventListener);
- }
+ }
- private static class AppletEventListener implements AppletListener
- {
- final Frame frame;
- final PluginAppletViewer appletViewer;
+ private static class AppletEventListener implements AppletListener {
+ final Frame frame;
+ final PluginAppletViewer appletViewer;
- public AppletEventListener(Frame frame, PluginAppletViewer appletViewer)
- {
- this.frame = frame;
- this.appletViewer = appletViewer;
- }
+ public AppletEventListener(Frame frame, PluginAppletViewer appletViewer) {
+ this.frame = frame;
+ this.appletViewer = appletViewer;
+ }
- public void appletStateChanged(AppletEvent evt)
- {
- AppletPanel src = (AppletPanel)evt.getSource();
+ public void appletStateChanged(AppletEvent evt) {
+ AppletPanel src = (AppletPanel) evt.getSource();
- switch (evt.getID()) {
- case AppletPanel.APPLET_RESIZE: {
- if(src != null) {
- appletViewer.setSize(appletViewer.getPreferredSize());
- appletViewer.validate();
- }
- break;
- }
- case AppletPanel.APPLET_LOADING_COMPLETED: {
- Applet a = src.getApplet(); // sun.applet.AppletPanel
-
- // Fixed #4754451: Applet can have methods running on main
- // thread event queue.
- //
- // The cause of this bug is that the frame of the applet
- // is created in main thread group. Thus, when certain
- // AWT/Swing events are generated, the events will be
- // dispatched through the wrong event dispatch thread.
- //
- // To fix this, we rearrange the AppContext with the frame,
- // so the proper event queue will be looked up.
- //
- // Swing also maintains a Frame list for the AppContext,
- // so we will have to rearrange it as well.
- //
- if (a != null)
- AppletPanel.changeFrameAppContext(frame, SunToolkit.targetToAppContext(a));
- else
- AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext());
-
- updateStatus(appletViewer.identifier, PAV_INIT_STATUS.INIT_COMPLETE);
-
- break;
- }
- }
- }
- }
+ switch (evt.getID()) {
+ case AppletPanel.APPLET_RESIZE: {
+ if (src != null) {
+ appletViewer.setSize(appletViewer.getPreferredSize());
+ appletViewer.validate();
+ }
+ break;
+ }
+ case AppletPanel.APPLET_LOADING_COMPLETED: {
+ Applet a = src.getApplet(); // sun.applet.AppletPanel
+
+ // Fixed #4754451: Applet can have methods running on main
+ // thread event queue.
+ //
+ // The cause of this bug is that the frame of the applet
+ // is created in main thread group. Thus, when certain
+ // AWT/Swing events are generated, the events will be
+ // dispatched through the wrong event dispatch thread.
+ //
+ // To fix this, we rearrange the AppContext with the frame,
+ // so the proper event queue will be looked up.
+ //
+ // Swing also maintains a Frame list for the AppContext,
+ // so we will have to rearrange it as well.
+ //
+ if (a != null)
+ AppletPanel.changeFrameAppContext(frame, SunToolkit.targetToAppContext(a));
+ else
+ AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext());
+
+ updateStatus(appletViewer.identifier, PAV_INIT_STATUS.INIT_COMPLETE);
+
+ break;
+ }
+ }
+ }
+ }
public static void setStreamhandler(PluginStreamHandler sh) {
streamhandler = sh;
@@ -486,288 +480,286 @@ import com.sun.jndi.toolkit.url.UrlUtil;
requestFactory = rf;
}
- /**
- * Handle an incoming message from the plugin.
- */
- public static void handleMessage(int identifier, int reference, String message)
- {
-
- PluginDebug.debug("PAV handling: " + message);
-
- try {
- if (message.startsWith("handle")) {
-
- // If there is a key for this status, it means it
- // was either initialized before, or destroy has been
- // processed. Stop moving further.
- if (updateStatus(identifier, PAV_INIT_STATUS.PRE_INIT) != null)
- return;
-
- // Extract the information from the message
- String[] msgParts = new String[4];
- for (int i=0; i < 3; i++) {
- int spaceLocation = message.indexOf(' ');
- int nextSpaceLocation = message.indexOf(' ', spaceLocation+1);
- msgParts[i] = message.substring(spaceLocation + 1, nextSpaceLocation);
- message = message.substring(nextSpaceLocation + 1);
- }
-
- long handle = Long.parseLong(msgParts[0]);
- String width = msgParts[1];
- String height = msgParts[2];
-
- int spaceLocation = message.indexOf(' ', "tag".length()+1);
- String documentBase =
- UrlUtil.decode(message.substring("tag".length() + 1, spaceLocation));
- String tag = message.substring(spaceLocation+1);
+ /**
+ * Handle an incoming message from the plugin.
+ */
+ public static void handleMessage(int identifier, int reference, String message) {
- // Decode the tag
- tag = tag.replace("&gt;", ">");
- tag = tag.replace("&lt;", "<");
- tag = tag.replace("&amp;", "&");
- tag = tag.replace("&#10;", "\n");
- tag = tag.replace("&#13;", "\r");
- tag = tag.replace("&quot;", "\"");
+ PluginDebug.debug("PAV handling: " + message);
- PluginDebug.debug ("Handle = " + handle + "\n" +
+ try {
+ if (message.startsWith("handle")) {
+
+ // If there is a key for this status, it means it
+ // was either initialized before, or destroy has been
+ // processed. Stop moving further.
+ if (updateStatus(identifier, PAV_INIT_STATUS.PRE_INIT) != null)
+ return;
+
+ // Extract the information from the message
+ String[] msgParts = new String[4];
+ for (int i = 0; i < 3; i++) {
+ int spaceLocation = message.indexOf(' ');
+ int nextSpaceLocation = message.indexOf(' ', spaceLocation + 1);
+ msgParts[i] = message.substring(spaceLocation + 1, nextSpaceLocation);
+ message = message.substring(nextSpaceLocation + 1);
+ }
+
+ long handle = Long.parseLong(msgParts[0]);
+ String width = msgParts[1];
+ String height = msgParts[2];
+
+ int spaceLocation = message.indexOf(' ', "tag".length() + 1);
+ String documentBase =
+ UrlUtil.decode(message.substring("tag".length() + 1, spaceLocation));
+ String tag = message.substring(spaceLocation + 1);
+
+ // Decode the tag
+ tag = tag.replace("&gt;", ">");
+ tag = tag.replace("&lt;", "<");
+ tag = tag.replace("&amp;", "&");
+ tag = tag.replace("&#10;", "\n");
+ tag = tag.replace("&#13;", "\r");
+ tag = tag.replace("&quot;", "\"");
+
+ PluginDebug.debug("Handle = " + handle + "\n" +
"Width = " + width + "\n" +
"Height = " + height + "\n" +
"DocumentBase = " + documentBase + "\n" +
"Tag = " + tag);
- PluginAppletViewer.parse
+ PluginAppletViewer.parse
(identifier, handle, width, height,
new StringReader(tag),
new URL(documentBase));
- int maxWait = APPLET_TIMEOUT; // wait for applet to fully load
- int wait = 0;
- while ( !applets.containsKey(identifier) && // Map is populated only by reFrame
- (wait < maxWait)) {
-
- try {
- Thread.sleep(50);
- wait += 50;
- } catch (InterruptedException ie) {
- // just wait
- }
- }
+ int maxWait = APPLET_TIMEOUT; // wait for applet to fully load
+ int wait = 0;
+ while (!applets.containsKey(identifier) && // Map is populated only by reFrame
+ (wait < maxWait)) {
- // If wait exceeded maxWait, we timed out. Throw an exception
- if (wait >= maxWait)
- throw new Exception("Applet initialization timeout");
+ try {
+ Thread.sleep(50);
+ wait += 50;
+ } catch (InterruptedException ie) {
+ // just wait
+ }
+ }
- PluginAppletViewer oldFrame = applets.get(identifier);
+ // If wait exceeded maxWait, we timed out. Throw an exception
+ if (wait >= maxWait)
+ throw new Exception("Applet initialization timeout");
- // We should not try to destroy an applet during
- // initialization. It may cause an inconsistent state,
- // which would bad if it's a trusted applet that
- // read/writes to files
- waitForAppletInit((NetxPanel) applets.get(identifier).panel);
+ PluginAppletViewer oldFrame = applets.get(identifier);
- // Should we proceed with reframing?
- if (updateStatus(identifier, PAV_INIT_STATUS.REFRAME_COMPLETE).equals(PAV_INIT_STATUS.INACTIVE)) {
- destroyApplet(identifier);
- return;
- }
+ // We should not try to destroy an applet during
+ // initialization. It may cause an inconsistent state,
+ // which would bad if it's a trusted applet that
+ // read/writes to files
+ waitForAppletInit((NetxPanel) applets.get(identifier).panel);
+
+ // Should we proceed with reframing?
+ if (updateStatus(identifier, PAV_INIT_STATUS.REFRAME_COMPLETE).equals(PAV_INIT_STATUS.INACTIVE)) {
+ destroyApplet(identifier);
+ return;
+ }
- } else if (message.startsWith("destroy")) {
+ } else if (message.startsWith("destroy")) {
- // Set it inactive, and try to do cleanup is applicable
- PAV_INIT_STATUS previousStatus = updateStatus(identifier, PAV_INIT_STATUS.INACTIVE);
- PluginDebug.debug("Destroy status set for " + identifier);
+ // Set it inactive, and try to do cleanup is applicable
+ PAV_INIT_STATUS previousStatus = updateStatus(identifier, PAV_INIT_STATUS.INACTIVE);
+ PluginDebug.debug("Destroy status set for " + identifier);
- if (previousStatus != null &&
+ if (previousStatus != null &&
previousStatus.equals(PAV_INIT_STATUS.REFRAME_COMPLETE)) {
- destroyApplet(identifier);
- }
+ destroyApplet(identifier);
+ }
- } else {
- PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread());
+ } else {
+ PluginDebug.debug("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread());
- // Wait till initialization finishes
- while (!applets.containsKey(identifier) &&
+ // Wait till initialization finishes
+ while (!applets.containsKey(identifier) &&
(
!status.containsKey(identifier) ||
status.get(identifier).equals(PAV_INIT_STATUS.PRE_INIT)
- )
- );
+ ))
+ ;
- // don't bother processing further for inactive applets
- if (status.get(identifier).equals(PAV_INIT_STATUS.INACTIVE))
- return;
+ // don't bother processing further for inactive applets
+ if (status.get(identifier).equals(PAV_INIT_STATUS.INACTIVE))
+ return;
- applets.get(identifier).handleMessage(reference, message);
- }
- } catch (Exception e) {
+ applets.get(identifier).handleMessage(reference, message);
+ }
+ } catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
- // If an exception happened during pre-init, we need to update status
- updateStatus(identifier, PAV_INIT_STATUS.INACTIVE);
+ // If an exception happened during pre-init, we need to update status
+ updateStatus(identifier, PAV_INIT_STATUS.INACTIVE);
- throw new RuntimeException("Failed to handle message: " +
+ throw new RuntimeException("Failed to handle message: " +
message + " for instance " + identifier, e);
- }
- }
-
- /**
- * Sets the status unless an overriding status is set (e.g. if
- * status is DESTROYED, it may not be overridden).
- *
- * @param identifier The identifier for which the status is to be set
- * @param status The status to switch to
- * @return The previous status
- */
- private static synchronized PAV_INIT_STATUS updateStatus(int identifier, PAV_INIT_STATUS newStatus) {
-
- PAV_INIT_STATUS prev = status.get(identifier);
-
- // If the status is set
- if (status.containsKey(identifier)) {
-
- // Nothing may override destroyed status
- if (status.get(identifier).equals(PAV_INIT_STATUS.DESTROYED)) {
- return prev;
- }
+ }
+ }
- // If status is inactive, only DESTROYED may override it
- if (status.get(identifier).equals(PAV_INIT_STATUS.INACTIVE)) {
- if (!newStatus.equals(PAV_INIT_STATUS.DESTROYED)) {
- return prev;
- }
- }
- }
+ /**
+ * Sets the status unless an overriding status is set (e.g. if
+ * status is DESTROYED, it may not be overridden).
+ *
+ * @param identifier The identifier for which the status is to be set
+ * @param status The status to switch to
+ * @return The previous status
+ */
+ private static synchronized PAV_INIT_STATUS updateStatus(int identifier, PAV_INIT_STATUS newStatus) {
+
+ PAV_INIT_STATUS prev = status.get(identifier);
+
+ // If the status is set
+ if (status.containsKey(identifier)) {
+
+ // Nothing may override destroyed status
+ if (status.get(identifier).equals(PAV_INIT_STATUS.DESTROYED)) {
+ return prev;
+ }
+
+ // If status is inactive, only DESTROYED may override it
+ if (status.get(identifier).equals(PAV_INIT_STATUS.INACTIVE)) {
+ if (!newStatus.equals(PAV_INIT_STATUS.DESTROYED)) {
+ return prev;
+ }
+ }
+ }
// Else set to given status
status.put(identifier, newStatus);
return prev;
- }
+ }
- /**
- * Destroys the given applet instance.
- *
- * This function may be called multiple times without problems.
- * It does a synchronized check on the status and will only
- * attempt to destroy the applet if not previously destroyed.
- *
- * @param identifier The instance which is to be destroyed
- */
+ /**
+ * Destroys the given applet instance.
+ *
+ * This function may be called multiple times without problems.
+ * It does a synchronized check on the status and will only
+ * attempt to destroy the applet if not previously destroyed.
+ *
+ * @param identifier The instance which is to be destroyed
+ */
- private static synchronized void destroyApplet(int identifier) {
+ private static synchronized void destroyApplet(int identifier) {
- PluginDebug.debug("DestroyApplet called for " + identifier);
+ PluginDebug.debug("DestroyApplet called for " + identifier);
- PAV_INIT_STATUS prev = updateStatus(identifier, PAV_INIT_STATUS.DESTROYED);
+ PAV_INIT_STATUS prev = updateStatus(identifier, PAV_INIT_STATUS.DESTROYED);
- // If already destroyed, return
- if (prev.equals(PAV_INIT_STATUS.DESTROYED)) {
- PluginDebug.debug(identifier + " already destroyed. Returning.");
- return;
- }
+ // If already destroyed, return
+ if (prev.equals(PAV_INIT_STATUS.DESTROYED)) {
+ PluginDebug.debug(identifier + " already destroyed. Returning.");
+ return;
+ }
- PluginDebug.debug("Attempting to destroy frame " + identifier);
+ PluginDebug.debug("Attempting to destroy frame " + identifier);
- // Try to dispose the panel right away
- if (applets.containsKey(identifier))
- applets.get(identifier).dispose();
+ // Try to dispose the panel right away
+ if (applets.containsKey(identifier))
+ applets.get(identifier).dispose();
- // If panel is already disposed, return
- if (applets.get(identifier).panel.applet == null) {
- PluginDebug.debug(identifier + " panel inactive. Returning.");
- return;
- }
+ // If panel is already disposed, return
+ if (applets.get(identifier).panel.applet == null) {
+ PluginDebug.debug(identifier + " panel inactive. Returning.");
+ return;
+ }
- PluginDebug.debug("Attempting to destroy panel " + identifier);
+ PluginDebug.debug("Attempting to destroy panel " + identifier);
- final int fIdentifier = identifier;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- applets.get(fIdentifier).appletClose();
- }
- });
+ final int fIdentifier = identifier;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ applets.get(fIdentifier).appletClose();
+ }
+ });
- PluginDebug.debug(identifier + " destroyed");
- }
+ PluginDebug.debug(identifier + " destroyed");
+ }
- /**
- * Function to block until applet initialization is complete
- *
- * @param identifier The instance to wait for
- */
- public static void waitForAppletInit(NetxPanel panel) {
+ /**
+ * Function to block until applet initialization is complete
+ *
+ * @param identifier The instance to wait for
+ */
+ public static void waitForAppletInit(NetxPanel panel) {
- int waitTime = 0;
+ int waitTime = 0;
- // Wait till initialization finishes
- while (panel.getApplet() == null &&
+ // Wait till initialization finishes
+ while (panel.getApplet() == null &&
panel.isAlive() &&
waitTime < APPLET_TIMEOUT) {
- try {
- if (waitTime%500 == 0)
- PluginDebug.debug("Waiting for applet panel " + panel + " to initialize...");
+ try {
+ if (waitTime % 500 == 0)
+ PluginDebug.debug("Waiting for applet panel " + panel + " to initialize...");
- Thread.sleep(waitTime += 50);
- } catch (InterruptedException ie) {
- // just wait
- }
- }
-
- PluginDebug.debug("Applet panel " + panel + " initialized");
- }
-
- public void handleMessage(int reference, String message)
- {
- if (message.startsWith("width")) {
-
- // Wait for panel to come alive
- int maxWait = APPLET_TIMEOUT; // wait for panel to come alive
- int wait = 0;
- while (!status.get(identifier).equals(PAV_INIT_STATUS.INIT_COMPLETE) && wait < maxWait) {
- try {
- Thread.sleep(50);
- wait += 50;
- } catch (InterruptedException ie) {
- // just wait
- }
- }
+ Thread.sleep(waitTime += 50);
+ } catch (InterruptedException ie) {
+ // just wait
+ }
+ }
- // 0 => width, 1=> width_value, 2 => height, 3=> height_value
- String[] dimMsg = message.split(" ");
+ PluginDebug.debug("Applet panel " + panel + " initialized");
+ }
- final int height = Integer.parseInt(dimMsg[3]);
- final int width = Integer.parseInt(dimMsg[1]);
+ public void handleMessage(int reference, String message) {
+ if (message.startsWith("width")) {
+
+ // Wait for panel to come alive
+ int maxWait = APPLET_TIMEOUT; // wait for panel to come alive
+ int wait = 0;
+ while (!status.get(identifier).equals(PAV_INIT_STATUS.INIT_COMPLETE) && wait < maxWait) {
+ try {
+ Thread.sleep(50);
+ wait += 50;
+ } catch (InterruptedException ie) {
+ // just wait
+ }
+ }
+
+ // 0 => width, 1=> width_value, 2 => height, 3=> height_value
+ String[] dimMsg = message.split(" ");
- if (panel instanceof NetxPanel)
- ((NetxPanel) panel).updateSizeInAtts(height, width);
+ final int height = Integer.parseInt(dimMsg[3]);
+ final int width = Integer.parseInt(dimMsg[1]);
- try {
+ if (panel instanceof NetxPanel)
+ ((NetxPanel) panel).updateSizeInAtts(height, width);
+
+ try {
SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
-
- setSize(width, height);
-
- // 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.setSize(1,1);
- panel.validate();
-
- panel.setSize(width, height);
- panel.validate();
-
- panel.applet.resize(width, height);
- panel.applet.validate();
- }
- });
+ public void run() {
+
+ setSize(width, height);
+
+ // 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.setSize(1, 1);
+ panel.validate();
+
+ panel.setSize(width, height);
+ panel.validate();
+
+ panel.applet.resize(width, height);
+ panel.applet.validate();
+ }
+ });
} catch (InterruptedException e) {
// do nothing
e.printStackTrace();
@@ -776,780 +768,771 @@ import com.sun.jndi.toolkit.url.UrlUtil;
e.printStackTrace();
}
- } else if (message.startsWith("GetJavaObject")) {
-
- // FIXME: how do we determine what security context this
- // object should belong to?
- Object o;
-
- // Wait for panel to come alive
- int maxWait = APPLET_TIMEOUT; // wait for panel to come alive
- int wait = 0;
- while ((panel == null) || (!((NetxPanel) panel).isAlive() && wait < maxWait)) {
- try {
- Thread.sleep(50);
- wait += 50;
- } catch (InterruptedException ie) {
- // just wait
- }
- }
+ } else if (message.startsWith("GetJavaObject")) {
+
+ // FIXME: how do we determine what security context this
+ // object should belong to?
+ Object o;
+
+ // Wait for panel to come alive
+ int maxWait = APPLET_TIMEOUT; // wait for panel to come alive
+ int wait = 0;
+ while ((panel == null) || (!((NetxPanel) panel).isAlive() && wait < maxWait)) {
+ try {
+ Thread.sleep(50);
+ wait += 50;
+ } catch (InterruptedException ie) {
+ // just wait
+ }
+ }
- // Wait for the panel to initialize
- // (happens in a separate thread)
- waitForAppletInit((NetxPanel) panel);
+ // Wait for the panel to initialize
+ // (happens in a separate thread)
+ waitForAppletInit((NetxPanel) panel);
- PluginDebug.debug(panel + " -- " + panel.getApplet() + " -- " + ((NetxPanel) panel).isAlive());
+ PluginDebug.debug(panel + " -- " + panel.getApplet() + " -- " + ((NetxPanel) panel).isAlive());
- // Still null?
- if (panel.getApplet() == null) {
- this.streamhandler.write("instance " + identifier + " reference " + -1 + " fatalError " + "Initialization failed");
- return;
- }
+ // Still null?
+ if (panel.getApplet() == null) {
+ this.streamhandler.write("instance " + identifier + " reference " + -1 + " fatalError " + "Initialization failed");
+ return;
+ }
- o = panel.getApplet();
- PluginDebug.debug ("Looking for object " + o + " panel is " + panel);
- AppletSecurityContextManager.getSecurityContext(0).store(o);
- PluginDebug.debug ("WRITING 1: " + "context 0 reference " + reference + " GetJavaObject "
+ o = panel.getApplet();
+ PluginDebug.debug("Looking for object " + o + " panel is " + panel);
+ AppletSecurityContextManager.getSecurityContext(0).store(o);
+ PluginDebug.debug("WRITING 1: " + "context 0 reference " + reference + " GetJavaObject "
+ AppletSecurityContextManager.getSecurityContext(0).getIdentifier(o));
- streamhandler.write("context 0 reference " + reference + " GetJavaObject "
+ streamhandler.write("context 0 reference " + reference + " GetJavaObject "
+ AppletSecurityContextManager.getSecurityContext(0).getIdentifier(o));
- PluginDebug.debug ("WRITING 1 DONE");
- }
- }
-
- // FIXME: Kind of hackish way to ensure synchronized re-drawing
- private synchronized void forceredraw() {
- doLayout();
- }
-
- /*
- * Methods for java.applet.AppletContext
- */
-
- private static Map<URL,AudioClip> audioClips = new HashMap<URL,AudioClip>();
-
- /**
- * Get an audio clip.
- */
- public AudioClip getAudioClip(URL url) {
- checkConnect(url);
- synchronized (audioClips) {
- AudioClip clip = audioClips.get(url);
- if (clip == null) {
- audioClips.put(url, clip = new AppletAudioClip(url));
- }
- return clip;
- }
- }
+ PluginDebug.debug("WRITING 1 DONE");
+ }
+ }
+
+ // FIXME: Kind of hackish way to ensure synchronized re-drawing
+ private synchronized void forceredraw() {
+ doLayout();
+ }
+
+ /*
+ * Methods for java.applet.AppletContext
+ */
+
+ private static Map<URL, AudioClip> audioClips = new HashMap<URL, AudioClip>();
+
+ /**
+ * Get an audio clip.
+ */
+ public AudioClip getAudioClip(URL url) {
+ checkConnect(url);
+ synchronized (audioClips) {
+ AudioClip clip = audioClips.get(url);
+ if (clip == null) {
+ audioClips.put(url, clip = new AppletAudioClip(url));
+ }
+ return clip;
+ }
+ }
- private static Map<URL,AppletImageRef> imageRefs = new HashMap<URL,AppletImageRef>();
+ private static Map<URL, AppletImageRef> imageRefs = new HashMap<URL, AppletImageRef>();
- /**
- * Get an image.
- */
- public Image getImage(URL url) {
- return getCachedImage(url);
- }
+ /**
+ * Get an image.
+ */
+ public Image getImage(URL url) {
+ return getCachedImage(url);
+ }
- private Image getCachedImage(URL url) {
- // System.getSecurityManager().checkConnection(url.getHost(), url.getPort());
- return (Image)getCachedImageRef(url).get();
- }
+ private Image getCachedImage(URL url) {
+ // System.getSecurityManager().checkConnection(url.getHost(), url.getPort());
+ return (Image) getCachedImageRef(url).get();
+ }
- /**
- * Get an image ref.
- */
- private synchronized Ref getCachedImageRef(URL url) {
- PluginDebug.debug("getCachedImageRef() searching for " + url);
+ /**
+ * Get an image ref.
+ */
+ private synchronized Ref getCachedImageRef(URL url) {
+ PluginDebug.debug("getCachedImageRef() searching for " + url);
- try {
+ try {
- String originalURL = url.toString();
- String codeBase = panel.getCodeBase().toString();
+ String originalURL = url.toString();
+ String codeBase = panel.getCodeBase().toString();
- if (originalURL.startsWith(codeBase)) {
+ if (originalURL.startsWith(codeBase)) {
- PluginDebug.debug("getCachedImageRef() got URL = " + url);
- PluginDebug.debug("getCachedImageRef() plugin codebase = " + codeBase);
+ PluginDebug.debug("getCachedImageRef() got URL = " + url);
+ PluginDebug.debug("getCachedImageRef() plugin codebase = " + codeBase);
- // try to fetch it locally
- if (panel instanceof NetxPanel) {
+ // try to fetch it locally
+ if (panel instanceof NetxPanel) {
- URL localURL = null;
+ URL localURL = null;
- String resourceName = originalURL.substring(codeBase.length());
- JNLPClassLoader loader = (JNLPClassLoader) ((NetxPanel) panel).getAppletClassLoader();
+ String resourceName = originalURL.substring(codeBase.length());
+ JNLPClassLoader loader = (JNLPClassLoader) ((NetxPanel) panel).getAppletClassLoader();
- if (loader.resourceAvailableLocally(resourceName))
- localURL = loader.getResource(resourceName);
+ if (loader.resourceAvailableLocally(resourceName))
+ localURL = loader.getResource(resourceName);
- url = localURL != null ? localURL : url;
- }
- }
+ url = localURL != null ? localURL : url;
+ }
+ }
- PluginDebug.debug("getCachedImageRef() getting img from URL = " + url);
+ PluginDebug.debug("getCachedImageRef() getting img from URL = " + url);
- synchronized (imageRefs) {
- AppletImageRef ref = imageRefs.get(url);
- if (ref == null) {
- ref = new AppletImageRef(url);
- imageRefs.put(url, ref);
- }
- return ref;
- }
- } catch (Exception e) {
- System.err.println("Error occurred when trying to fetch image:");
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * Flush the image cache.
- */
- static void flushImageCache() {
+ synchronized (imageRefs) {
+ AppletImageRef ref = imageRefs.get(url);
+ if (ref == null) {
+ ref = new AppletImageRef(url);
+ imageRefs.put(url, ref);
+ }
+ return ref;
+ }
+ } catch (Exception e) {
+ System.err.println("Error occurred when trying to fetch image:");
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Flush the image cache.
+ */
+ static void flushImageCache() {
imageRefs.clear();
- }
-
- static Vector<AppletPanel> appletPanels = new Vector<AppletPanel>();
-
- /**
- * Get an applet by name.
- */
- public Applet getApplet(String name) {
- name = name.toLowerCase();
- SocketPermission panelSp =
- new SocketPermission(panel.getCodeBase().getHost(), "connect");
- for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) {
- AppletPanel p = (AppletPanel)e.nextElement();
- String param = p.getParameter("name");
- if (param != null) {
- param = param.toLowerCase();
+ }
+
+ static Vector<AppletPanel> appletPanels = new Vector<AppletPanel>();
+
+ /**
+ * Get an applet by name.
+ */
+ public Applet getApplet(String name) {
+ name = name.toLowerCase();
+ SocketPermission panelSp =
+ new SocketPermission(panel.getCodeBase().getHost(), "connect");
+ for (Enumeration e = appletPanels.elements(); e.hasMoreElements();) {
+ AppletPanel p = (AppletPanel) e.nextElement();
+ String param = p.getParameter("name");
+ if (param != null) {
+ param = param.toLowerCase();
+ }
+ if (name.equals(param) &&
+ p.getDocumentBase().equals(panel.getDocumentBase())) {
+
+ SocketPermission sp =
+ new SocketPermission(p.getCodeBase().getHost(), "connect");
+
+ if (panelSp.implies(sp)) {
+ return p.applet;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return an enumeration of all the accessible
+ * applets on this page.
+ */
+ public Enumeration<Applet> getApplets() {
+ Vector<Applet> v = new Vector<Applet>();
+ SocketPermission panelSp =
+ new SocketPermission(panel.getCodeBase().getHost(), "connect");
+
+ for (Enumeration<AppletPanel> e = appletPanels.elements(); e.hasMoreElements();) {
+ AppletPanel p = e.nextElement();
+ if (p.getDocumentBase().equals(panel.getDocumentBase())) {
+
+ SocketPermission sp =
+ new SocketPermission(p.getCodeBase().getHost(), "connect");
+ if (panelSp.implies(sp)) {
+ v.addElement(p.applet);
+ }
+ }
}
- if (name.equals(param) &&
- p.getDocumentBase().equals(panel.getDocumentBase())) {
+ return v.elements();
+ }
- SocketPermission sp =
- new SocketPermission(p.getCodeBase().getHost(), "connect");
+ /**
+ * Ignore.
+ */
+ public void showDocument(URL url) {
+ PluginDebug.debug("Showing document...");
+ showDocument(url, "_self");
+ }
- if (panelSp.implies(sp)) {
- return p.applet;
+ /**
+ * Ignore.
+ */
+ public void showDocument(URL url, String target) {
+ try {
+ // FIXME: change to postCallRequest
+ write("url " + UrlUtil.encode(url.toString(), "UTF-8") + " " + target);
+ } catch (IOException exception) {
+ // Deliberately ignore IOException. showDocument may be
+ // called from threads other than the main thread after
+ // streamhandler.pluginOutputStream has been closed.
}
+ }
+
+ /**
+ * Show status.
+ */
+ public void showStatus(String status) {
+ try {
+ // FIXME: change to postCallRequest
+ // For statuses, we cannot have a newline
+ status = status.replace("\n", " ");
+ write("status " + status);
+ } catch (IOException exception) {
+ // Deliberately ignore IOException. showStatus may be
+ // called from threads other than the main thread after
+ // streamhandler.pluginOutputStream has been closed.
}
}
- return null;
- }
-
- /**
- * Return an enumeration of all the accessible
- * applets on this page.
- */
- public Enumeration<Applet> getApplets() {
- Vector<Applet> v = new Vector<Applet>();
- SocketPermission panelSp =
- new SocketPermission(panel.getCodeBase().getHost(), "connect");
-
- for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
- AppletPanel p = e.nextElement();
- if (p.getDocumentBase().equals(panel.getDocumentBase())) {
-
- SocketPermission sp =
- new SocketPermission(p.getCodeBase().getHost(), "connect");
- if (panelSp.implies(sp)) {
- v.addElement(p.applet);
- }
- }
- }
- return v.elements();
- }
-
- /**
- * Ignore.
- */
- public void showDocument(URL url) {
- PluginDebug.debug("Showing document...");
- showDocument(url, "_self");
- }
-
- /**
- * Ignore.
- */
- public void showDocument(URL url, String target) {
- try {
- // FIXME: change to postCallRequest
- write("url " + UrlUtil.encode(url.toString(), "UTF-8") + " " + target);
- } catch (IOException exception) {
- // Deliberately ignore IOException. showDocument may be
- // called from threads other than the main thread after
- // streamhandler.pluginOutputStream has been closed.
- }
- }
-
- /**
- * Show status.
- */
- public void showStatus(String status) {
- try {
- // FIXME: change to postCallRequest
- // For statuses, we cannot have a newline
- status = status.replace("\n", " ");
- write("status " + status);
- } catch (IOException exception) {
- // Deliberately ignore IOException. showStatus may be
- // called from threads other than the main thread after
- // streamhandler.pluginOutputStream has been closed.
- }
- }
-
- /**
- * Returns an incremental number (unique identifier) for a message.
- * If identifier hits Long.MAX_VALUE it loops back starting at 0.
- *
- * @return A unique Long identifier for the request
- */
- private static Long getRequestIdentifier() {
- synchronized (requestIdentityCounter) {
-
- if (requestIdentityCounter == Long.MAX_VALUE)
- requestIdentityCounter = 0L;
-
- return requestIdentityCounter++;
+
+ /**
+ * Returns an incremental number (unique identifier) for a message.
+ * If identifier hits Long.MAX_VALUE it loops back starting at 0.
+ *
+ * @return A unique Long identifier for the request
+ */
+ private static Long getRequestIdentifier() {
+ synchronized (requestIdentityCounter) {
+
+ if (requestIdentityCounter == Long.MAX_VALUE)
+ requestIdentityCounter = 0L;
+
+ return requestIdentityCounter++;
}
- }
-
- public long getWindow() {
- PluginDebug.debug ("STARTING getWindow");
- Long reference = getRequestIdentifier();
-
- PluginCallRequest request = requestFactory.getPluginCallRequest("window",
- "instance " + identifier + " reference " +
- + reference + " " + "GetWindow", reference);
-
- PluginDebug.debug ("STARTING postCallRequest");
- streamhandler.postCallRequest(request);
- PluginDebug.debug ("STARTING postCallRequest done");
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait request 1");
- synchronized(request) {
- PluginDebug.debug ("wait request 2");
- while ((Long) request.getObject() == 0)
- request.wait();
- PluginDebug.debug ("wait request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+
+ public long getWindow() {
+ PluginDebug.debug("STARTING getWindow");
+ Long reference = getRequestIdentifier();
+
+ PluginCallRequest request = requestFactory.getPluginCallRequest("window",
+ "instance " + identifier + " reference " +
+ +reference + " " + "GetWindow", reference);
+
+ PluginDebug.debug("STARTING postCallRequest");
+ streamhandler.postCallRequest(request);
+ PluginDebug.debug("STARTING postCallRequest done");
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait request 2");
+ while ((Long) request.getObject() == 0)
+ request.wait();
+ PluginDebug.debug("wait request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
-
- PluginDebug.debug ("STARTING getWindow DONE");
- return (Long) request.getObject();
- }
-
- // FIXME: make private, access via reflection.
- public static Object getMember(long internal, String name)
- {
- AppletSecurityContextManager.getSecurityContext(0).store(name);
- int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("member",
- "instance " + 0 + " reference " + reference + " GetMember " +
- internal + " " + nameID, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait getMEM request 1");
- synchronized(request) {
- PluginDebug.debug ("wait getMEM request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait getMEM request 3 GOT: " + request.getObject().getClass());
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+
+ PluginDebug.debug("STARTING getWindow DONE");
+ return (Long) request.getObject();
+ }
+
+ // FIXME: make private, access via reflection.
+ public static Object getMember(long internal, String name) {
+ AppletSecurityContextManager.getSecurityContext(0).store(name);
+ int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("member",
+ "instance " + 0 + " reference " + reference + " GetMember " +
+ internal + " " + nameID, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait getMEM request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait getMEM request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait getMEM request 3 GOT: " + request.getObject().getClass());
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" getMember DONE");
- return request.getObject();
- }
-
- public static void setMember(long internal, String name, Object value) {
- System.err.println("Setting to class " + value.getClass() + ":" + value.getClass().isPrimitive());
- AppletSecurityContextManager.getSecurityContext(0).store(name);
- int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
- Long reference = getRequestIdentifier();
-
- // work on a copy of value, as we don't want to be manipulating
- // complex objects
- String valueToSetTo;
- if (value instanceof java.lang.Byte ||
- value instanceof java.lang.Character ||
- value instanceof java.lang.Short ||
- value instanceof java.lang.Integer ||
- value instanceof java.lang.Long ||
- value instanceof java.lang.Float ||
- value instanceof java.lang.Double ||
- value instanceof java.lang.Boolean) {
-
- valueToSetTo = "literalreturn " + value.toString();
-
- // Character -> Str results in str value.. we need int value as
- // per specs.
- if (value instanceof java.lang.Character) {
- valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue();
- } else if (value instanceof Float ||
+ }
+ PluginDebug.debug(" getMember DONE");
+ return request.getObject();
+ }
+
+ public static void setMember(long internal, String name, Object value) {
+ System.err.println("Setting to class " + value.getClass() + ":" + value.getClass().isPrimitive());
+ AppletSecurityContextManager.getSecurityContext(0).store(name);
+ int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
+ Long reference = getRequestIdentifier();
+
+ // work on a copy of value, as we don't want to be manipulating
+ // complex objects
+ String valueToSetTo;
+ if (value instanceof java.lang.Byte ||
+ value instanceof java.lang.Character ||
+ value instanceof java.lang.Short ||
+ value instanceof java.lang.Integer ||
+ value instanceof java.lang.Long ||
+ value instanceof java.lang.Float ||
+ value instanceof java.lang.Double ||
+ value instanceof java.lang.Boolean) {
+
+ valueToSetTo = "literalreturn " + value.toString();
+
+ // Character -> Str results in str value.. we need int value as
+ // per specs.
+ if (value instanceof java.lang.Character) {
+ valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue();
+ } else if (value instanceof Float ||
value instanceof Double) {
- valueToSetTo = "literalreturn " + String.format("%308.308e", value);
- }
+ valueToSetTo = "literalreturn " + String.format("%308.308e", value);
+ }
- } else {
- AppletSecurityContextManager.getSecurityContext(0).store(value);
- valueToSetTo = Integer.toString(AppletSecurityContextManager.getSecurityContext(0).getIdentifier(value));
- }
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("void",
- "instance " + 0 + " reference " + reference + " SetMember " +
- internal + " " + nameID + " " + valueToSetTo, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait setMem request: " + request.getMessage());
- PluginDebug.debug ("wait setMem request 1");
- synchronized(request) {
- PluginDebug.debug ("wait setMem request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait setMem request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ } else {
+ AppletSecurityContextManager.getSecurityContext(0).store(value);
+ valueToSetTo = Integer.toString(AppletSecurityContextManager.getSecurityContext(0).getIdentifier(value));
+ }
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("void",
+ "instance " + 0 + " reference " + reference + " SetMember " +
+ internal + " " + nameID + " " + valueToSetTo, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait setMem request: " + request.getMessage());
+ PluginDebug.debug("wait setMem request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait setMem request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait setMem request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" setMember DONE");
- }
-
- // FIXME: handle long index as well.
- public static void setSlot(long internal, int index, Object value) {
- AppletSecurityContextManager.getSecurityContext(0).store(value);
- Long reference = getRequestIdentifier();
-
- // work on a copy of value, as we don't want to be manipulating
- // complex objects
- String valueToSetTo;
- if (value instanceof java.lang.Byte ||
- value instanceof java.lang.Character ||
- value instanceof java.lang.Short ||
- value instanceof java.lang.Integer ||
- value instanceof java.lang.Long ||
- value instanceof java.lang.Float ||
- value instanceof java.lang.Double ||
- value instanceof java.lang.Boolean) {
-
- valueToSetTo = "literalreturn " + value.toString();
-
- // Character -> Str results in str value.. we need int value as
- // per specs.
- if (value instanceof java.lang.Character) {
- valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue();
- } else if (value instanceof Float ||
+ }
+ PluginDebug.debug(" setMember DONE");
+ }
+
+ // FIXME: handle long index as well.
+ public static void setSlot(long internal, int index, Object value) {
+ AppletSecurityContextManager.getSecurityContext(0).store(value);
+ Long reference = getRequestIdentifier();
+
+ // work on a copy of value, as we don't want to be manipulating
+ // complex objects
+ String valueToSetTo;
+ if (value instanceof java.lang.Byte ||
+ value instanceof java.lang.Character ||
+ value instanceof java.lang.Short ||
+ value instanceof java.lang.Integer ||
+ value instanceof java.lang.Long ||
+ value instanceof java.lang.Float ||
+ value instanceof java.lang.Double ||
+ value instanceof java.lang.Boolean) {
+
+ valueToSetTo = "literalreturn " + value.toString();
+
+ // Character -> Str results in str value.. we need int value as
+ // per specs.
+ if (value instanceof java.lang.Character) {
+ valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue();
+ } else if (value instanceof Float ||
value instanceof Double) {
- valueToSetTo = "literalreturn " + String.format("%308.308e", value);
- }
+ valueToSetTo = "literalreturn " + String.format("%308.308e", value);
+ }
- } else {
- AppletSecurityContextManager.getSecurityContext(0).store(value);
- valueToSetTo = Integer.toString(AppletSecurityContextManager.getSecurityContext(0).getIdentifier(value));
- }
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("void",
- "instance " + 0 + " reference " + reference + " SetSlot " +
- internal + " " + index + " " + valueToSetTo, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait setSlot request 1");
- synchronized(request) {
- PluginDebug.debug ("wait setSlot request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait setSlot request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ } else {
+ AppletSecurityContextManager.getSecurityContext(0).store(value);
+ valueToSetTo = Integer.toString(AppletSecurityContextManager.getSecurityContext(0).getIdentifier(value));
+ }
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("void",
+ "instance " + 0 + " reference " + reference + " SetSlot " +
+ internal + " " + index + " " + valueToSetTo, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait setSlot request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait setSlot request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait setSlot request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" setSlot DONE");
- }
-
- public static Object getSlot(long internal, int index)
- {
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("member",
- "instance " + 0 + " reference " + reference + " GetSlot " +
- internal + " " + index, reference);
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait getSlot request 1");
- synchronized(request) {
- PluginDebug.debug ("wait getSlot request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait getSlot request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" setSlot DONE");
+ }
+
+ public static Object getSlot(long internal, int index) {
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("member",
+ "instance " + 0 + " reference " + reference + " GetSlot " +
+ internal + " " + index, reference);
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait getSlot request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait getSlot request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait getSlot request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" getSlot DONE");
- return request.getObject();
- }
-
- public static Object eval(long internal, String s)
- {
- AppletSecurityContextManager.getSecurityContext(0).store(s);
- int stringID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(s);
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- // FIXME: rename GetMemberPluginCallRequest ObjectPluginCallRequest.
- PluginCallRequest request = requestFactory.getPluginCallRequest("member",
- "instance " + 0 + " reference " + reference + " Eval " +
- internal + " " + stringID, reference);
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait eval request 1");
- synchronized(request) {
- PluginDebug.debug ("wait eval request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait eval request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" getSlot DONE");
+ return request.getObject();
+ }
+
+ public static Object eval(long internal, String s) {
+ AppletSecurityContextManager.getSecurityContext(0).store(s);
+ int stringID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(s);
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ // FIXME: rename GetMemberPluginCallRequest ObjectPluginCallRequest.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("member",
+ "instance " + 0 + " reference " + reference + " Eval " +
+ internal + " " + stringID, reference);
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait eval request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait eval request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait eval request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" getSlot DONE");
- return request.getObject();
- }
-
- public static void removeMember (long internal, String name) {
- AppletSecurityContextManager.getSecurityContext(0).store(name);
- int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("void",
- "instance " + 0 + " reference " + reference + " RemoveMember " +
- internal + " " + nameID, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait removeMember request 1");
- synchronized(request) {
- PluginDebug.debug ("wait removeMember request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait removeMember request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" getSlot DONE");
+ return request.getObject();
+ }
+
+ public static void removeMember(long internal, String name) {
+ AppletSecurityContextManager.getSecurityContext(0).store(name);
+ int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("void",
+ "instance " + 0 + " reference " + reference + " RemoveMember " +
+ internal + " " + nameID, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait removeMember request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait removeMember request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait removeMember request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" RemoveMember DONE");
- }
-
- public static Object call(long internal, String name, Object args[])
- {
- // FIXME: when is this removed from the object store?
- // FIXME: reference should return the ID.
- // FIXME: convenience method for this long line.
- AppletSecurityContextManager.getSecurityContext(0).store(name);
- int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
- Long reference = getRequestIdentifier();
-
- String argIDs = "";
- for (Object arg : args)
- {
- AppletSecurityContextManager.getSecurityContext(0).store(arg);
- argIDs += AppletSecurityContextManager.getSecurityContext(0).getIdentifier(arg) + " ";
- }
- argIDs = argIDs.trim();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("member",
- "instance " + 0 + " reference " + reference + " Call " +
- internal + " " + nameID + " " + argIDs, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait call request 1");
- synchronized(request) {
- PluginDebug.debug ("wait call request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait call request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" RemoveMember DONE");
+ }
+
+ public static Object call(long internal, String name, Object args[]) {
+ // FIXME: when is this removed from the object store?
+ // FIXME: reference should return the ID.
+ // FIXME: convenience method for this long line.
+ AppletSecurityContextManager.getSecurityContext(0).store(name);
+ int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name);
+ Long reference = getRequestIdentifier();
+
+ String argIDs = "";
+ for (Object arg : args) {
+ AppletSecurityContextManager.getSecurityContext(0).store(arg);
+ argIDs += AppletSecurityContextManager.getSecurityContext(0).getIdentifier(arg) + " ";
+ }
+ argIDs = argIDs.trim();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("member",
+ "instance " + 0 + " reference " + reference + " Call " +
+ internal + " " + nameID + " " + argIDs, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait call request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait call request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait call request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" Call DONE");
- return request.getObject();
- }
+ }
+ PluginDebug.debug(" Call DONE");
+ return request.getObject();
+ }
- public static Object requestPluginCookieInfo(URI uri) {
+ public static Object requestPluginCookieInfo(URI uri) {
- PluginCallRequest request;
- Long reference = getRequestIdentifier();
+ PluginCallRequest request;
+ Long reference = getRequestIdentifier();
- try
- {
- String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8");
- request = requestFactory.getPluginCallRequest("cookieinfo",
- "plugin PluginCookieInfo " + "reference " + reference +
- " " + encodedURI, reference);
+ try {
+ String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8");
+ request = requestFactory.getPluginCallRequest("cookieinfo",
+ "plugin PluginCookieInfo " + "reference " + reference +
+ " " + encodedURI, reference);
+
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return null;
+ }
- } catch (UnsupportedEncodingException e)
- {
- e.printStackTrace();
- return null;
- }
-
- PluginMessageConsumer.registerPriorityWait(reference);
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait cookieinfo request 1");
- synchronized(request) {
- PluginDebug.debug ("wait cookieinfo request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait cookieinfo request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for cookieinfo request.",
- e);
- }
- PluginDebug.debug (" Cookieinfo DONE");
- return request.getObject();
- }
-
- public static Object requestPluginProxyInfo(URI uri) {
-
- String requestURI = null;
- Long reference = getRequestIdentifier();
-
- try {
-
- // there is no easy way to get SOCKS proxy info. So, we tell mozilla that we want proxy for
- // an HTTP uri in case of non http/ftp protocols. If we get back a SOCKS proxy, we can
- // use that, if we get back an http proxy, we fallback to DIRECT connect
-
- String scheme = uri.getScheme();
- String port = uri.getPort() != -1 ? ":" + uri.getPort() : "";
- if (!uri.getScheme().startsWith("http") && !uri.getScheme().equals("ftp"))
- scheme = "http";
-
- requestURI = UrlUtil.encode(scheme + "://" + uri.getHost() + port + "/" + uri.getPath(), "UTF-8");
- } catch (Exception e) {
- PluginDebug.debug("Cannot construct URL from " + uri.toString() + " ... falling back to DIRECT proxy");
- e.printStackTrace();
- return null;
- }
-
- PluginCallRequest request = requestFactory.getPluginCallRequest("proxyinfo",
- "plugin PluginProxyInfo reference " + reference + " " +
- requestURI, reference);
-
- PluginMessageConsumer.registerPriorityWait(reference);
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait call request 1");
- synchronized(request) {
- PluginDebug.debug ("wait call request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait call request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ PluginMessageConsumer.registerPriorityWait(reference);
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait cookieinfo request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait cookieinfo request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait cookieinfo request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for cookieinfo request.",
e);
- }
- PluginDebug.debug (" Call DONE");
- return request.getObject();
- }
-
- public static void JavaScriptFinalize(long internal)
- {
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("void",
- "instance " + 0 + " reference " + reference + " Finalize " +
- internal, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait finalize request 1");
- synchronized(request) {
- PluginDebug.debug ("wait finalize request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait finalize request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" Cookieinfo DONE");
+ return request.getObject();
+ }
+
+ public static Object requestPluginProxyInfo(URI uri) {
+
+ String requestURI = null;
+ Long reference = getRequestIdentifier();
+
+ try {
+
+ // there is no easy way to get SOCKS proxy info. So, we tell mozilla that we want proxy for
+ // an HTTP uri in case of non http/ftp protocols. If we get back a SOCKS proxy, we can
+ // use that, if we get back an http proxy, we fallback to DIRECT connect
+
+ String scheme = uri.getScheme();
+ String port = uri.getPort() != -1 ? ":" + uri.getPort() : "";
+ if (!uri.getScheme().startsWith("http") && !uri.getScheme().equals("ftp"))
+ scheme = "http";
+
+ requestURI = UrlUtil.encode(scheme + "://" + uri.getHost() + port + "/" + uri.getPath(), "UTF-8");
+ } catch (Exception e) {
+ PluginDebug.debug("Cannot construct URL from " + uri.toString() + " ... falling back to DIRECT proxy");
+ e.printStackTrace();
+ return null;
+ }
+
+ PluginCallRequest request = requestFactory.getPluginCallRequest("proxyinfo",
+ "plugin PluginProxyInfo reference " + reference + " " +
+ requestURI, reference);
+
+ PluginMessageConsumer.registerPriorityWait(reference);
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait call request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait call request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait call request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" finalize DONE");
- }
-
- public static String javascriptToString(long internal)
- {
- Long reference = getRequestIdentifier();
-
- // Prefix with dummy instance for convenience.
- PluginCallRequest request = requestFactory.getPluginCallRequest("member",
- "instance " + 0 + " reference " + reference + " ToString " +
- internal, reference);
-
- streamhandler.postCallRequest(request);
- streamhandler.write(request.getMessage());
- try {
- PluginDebug.debug ("wait ToString request 1");
- synchronized(request) {
- PluginDebug.debug ("wait ToString request 2");
- while (request.isDone() == false)
- request.wait();
- PluginDebug.debug ("wait ToString request 3");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException("Interrupted waiting for call request.",
+ }
+ PluginDebug.debug(" Call DONE");
+ return request.getObject();
+ }
+
+ public static void JavaScriptFinalize(long internal) {
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("void",
+ "instance " + 0 + " reference " + reference + " Finalize " +
+ internal, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait finalize request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait finalize request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait finalize request 3");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
e);
- }
- PluginDebug.debug (" ToString DONE");
- return (String) request.getObject();
- }
-
- // FIXME: make this private and access it from JSObject using
- // reflection.
- private void write(String message) throws IOException {
- PluginDebug.debug ("WRITING 2: " + "instance " + identifier + " " + message);
- streamhandler.write("instance " + identifier + " " + message);
- PluginDebug.debug ("WRITING 2 DONE");
- }
-
- public void setStream(String key, InputStream stream)throws IOException{
- // We do nothing.
- }
-
- @Override
- public InputStream getStream(String key){
- // We do nothing.
- return null;
- }
-
- @Override
- public Iterator<String> getStreamKeys(){
- // We do nothing.
- return null;
- }
-
- /**
- * System parameters.
- */
- static Hashtable<String,String> systemParam = new Hashtable<String,String>();
-
- static {
- systemParam.put("codebase", "codebase");
- systemParam.put("code", "code");
- systemParam.put("alt", "alt");
- systemParam.put("width", "width");
- systemParam.put("height", "height");
- systemParam.put("align", "align");
- systemParam.put("vspace", "vspace");
- systemParam.put("hspace", "hspace");
- }
-
- /**
- * Print the HTML tag.
- */
- public static void printTag(PrintStream out, Hashtable<String,String> atts) {
- out.print("<applet");
-
- String v = atts.get("codebase");
- if (v != null) {
- out.print(" codebase=\"" + v + "\"");
- }
-
- v = atts.get("code");
- if (v == null) {
- v = "applet.class";
- }
- out.print(" code=\"" + v + "\"");
- v = atts.get("width");
- if (v == null) {
- v = "150";
- }
- out.print(" width=" + v);
-
- v = atts.get("height");
- if (v == null) {
- v = "100";
- }
- out.print(" height=" + v);
-
- v = atts.get("name");
- if (v != null) {
- out.print(" name=\"" + v + "\"");
- }
- out.println(">");
-
- // A very slow sorting algorithm
- int len = atts.size();
- String params[] = new String[len];
- len = 0;
- for (Enumeration<String> e = atts.keys() ; e.hasMoreElements() ;) {
- String param = e.nextElement();
- int i = 0;
- for (; i < len ; i++) {
- if (params[i].compareTo(param) >= 0) {
- break;
+ }
+ PluginDebug.debug(" finalize DONE");
+ }
+
+ public static String javascriptToString(long internal) {
+ Long reference = getRequestIdentifier();
+
+ // Prefix with dummy instance for convenience.
+ PluginCallRequest request = requestFactory.getPluginCallRequest("member",
+ "instance " + 0 + " reference " + reference + " ToString " +
+ internal, reference);
+
+ streamhandler.postCallRequest(request);
+ streamhandler.write(request.getMessage());
+ try {
+ PluginDebug.debug("wait ToString request 1");
+ synchronized (request) {
+ PluginDebug.debug("wait ToString request 2");
+ while (request.isDone() == false)
+ request.wait();
+ PluginDebug.debug("wait ToString request 3");
}
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted waiting for call request.",
+ e);
}
- System.arraycopy(params, i, params, i + 1, len - i);
- params[i] = param;
- len++;
+ PluginDebug.debug(" ToString DONE");
+ return (String) request.getObject();
+ }
+
+ // FIXME: make this private and access it from JSObject using
+ // reflection.
+ private void write(String message) throws IOException {
+ PluginDebug.debug("WRITING 2: " + "instance " + identifier + " " + message);
+ streamhandler.write("instance " + identifier + " " + message);
+ PluginDebug.debug("WRITING 2 DONE");
+ }
+
+ public void setStream(String key, InputStream stream) throws IOException {
+ // We do nothing.
+ }
+
+ @Override
+ public InputStream getStream(String key) {
+ // We do nothing.
+ return null;
+ }
+
+ @Override
+ public Iterator<String> getStreamKeys() {
+ // We do nothing.
+ return null;
}
- for (int i = 0 ; i < len ; i++) {
- String param = params[i];
- if (systemParam.get(param) == null) {
- out.println("<param name=" + param +
- " value=\"" + atts.get(param) + "\">");
+ /**
+ * System parameters.
+ */
+ static Hashtable<String, String> systemParam = new Hashtable<String, String>();
+
+ static {
+ systemParam.put("codebase", "codebase");
+ systemParam.put("code", "code");
+ systemParam.put("alt", "alt");
+ systemParam.put("width", "width");
+ systemParam.put("height", "height");
+ systemParam.put("align", "align");
+ systemParam.put("vspace", "vspace");
+ systemParam.put("hspace", "hspace");
+ }
+
+ /**
+ * Print the HTML tag.
+ */
+ public static void printTag(PrintStream out, Hashtable<String, String> atts) {
+ out.print("<applet");
+
+ String v = atts.get("codebase");
+ if (v != null) {
+ out.print(" codebase=\"" + v + "\"");
+ }
+
+ v = atts.get("code");
+ if (v == null) {
+ v = "applet.class";
+ }
+ out.print(" code=\"" + v + "\"");
+ v = atts.get("width");
+ if (v == null) {
+ v = "150";
+ }
+ out.print(" width=" + v);
+
+ v = atts.get("height");
+ if (v == null) {
+ v = "100";
+ }
+ out.print(" height=" + v);
+
+ v = atts.get("name");
+ if (v != null) {
+ out.print(" name=\"" + v + "\"");
+ }
+ out.println(">");
+
+ // A very slow sorting algorithm
+ int len = atts.size();
+ String params[] = new String[len];
+ len = 0;
+ for (Enumeration<String> e = atts.keys(); e.hasMoreElements();) {
+ String param = e.nextElement();
+ int i = 0;
+ for (; i < len; i++) {
+ if (params[i].compareTo(param) >= 0) {
+ break;
+ }
+ }
+ System.arraycopy(params, i, params, i + 1, len - i);
+ params[i] = param;
+ len++;
}
+
+ for (int i = 0; i < len; i++) {
+ String param = params[i];
+ if (systemParam.get(param) == null) {
+ out.println("<param name=" + param +
+ " value=\"" + atts.get(param) + "\">");
+ }
+ }
+ out.println("</applet>");
}
- out.println("</applet>");
- }
- /**
- * Make sure the atrributes are uptodate.
- */
+ /**
+ * Make sure the atrributes are uptodate.
+ */
public void updateAtts() {
Dimension d = panel.getSize();
Insets in = panel.getInsets();
@@ -1557,100 +1540,100 @@ import com.sun.jndi.toolkit.url.UrlUtil;
Integer.valueOf(d.width - (in.left + in.right)).toString());
panel.atts.put("height",
Integer.valueOf(d.height - (in.top + in.bottom)).toString());
- }
-
- /**
- * Restart the applet.
- */
- void appletRestart() {
- panel.sendEvent(AppletPanel.APPLET_STOP);
- panel.sendEvent(AppletPanel.APPLET_DESTROY);
- panel.sendEvent(AppletPanel.APPLET_INIT);
- panel.sendEvent(AppletPanel.APPLET_START);
- }
-
- /**
- * Reload the applet.
- */
- void appletReload() {
- panel.sendEvent(AppletPanel.APPLET_STOP);
- panel.sendEvent(AppletPanel.APPLET_DESTROY);
- panel.sendEvent(AppletPanel.APPLET_DISPOSE);
+ }
/**
- * Fixed #4501142: Classlaoder sharing policy doesn't
- * take "archive" into account. This will be overridden
- * by Java Plug-in. [stanleyh]
+ * Restart the applet.
*/
- AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey());
-
- /*
- * Make sure we don't have two threads running through the event queue
- * at the same time.
- */
- try {
- panel.joinAppletThread();
- panel.release();
- } catch (InterruptedException e) {
- return; // abort the reload
- }
-
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- public Void run() {
- panel.createAppletThread();
- return null;
- }
- });
-
- panel.sendEvent(AppletPanel.APPLET_LOAD);
- panel.sendEvent(AppletPanel.APPLET_INIT);
- panel.sendEvent(AppletPanel.APPLET_START);
- }
-
- public int print(Graphics graphics, PageFormat pf, int pageIndex) {
- return Printable.NO_SUCH_PAGE;
- }
-
- /**
- * Start the applet.
- */
- void appletStart() {
- panel.sendEvent(AppletPanel.APPLET_START);
- }
-
- /**
- * Stop the applet.
- */
- void appletStop() {
- panel.sendEvent(AppletPanel.APPLET_STOP);
- }
-
- /**
- * Shutdown a viewer.
- * Stop, Destroy, Dispose and Quit a viewer
- */
- private void appletShutdown(AppletPanel p) {
- p.sendEvent(AppletPanel.APPLET_STOP);
- p.sendEvent(AppletPanel.APPLET_DESTROY);
- p.sendEvent(AppletPanel.APPLET_DISPOSE);
- p.sendEvent(AppletPanel.APPLET_QUIT);
- }
-
- /**
- * Close this viewer.
- * Stop, Destroy, Dispose and Quit an AppletView, then
- * reclaim resources and exit the program if this is
- * the last applet.
- */
- void appletClose() {
-
- // The caller thread is event dispatch thread, so
- // spawn a new thread to avoid blocking the event queue
- // when calling appletShutdown.
- //
- final AppletPanel p = panel;
-
- new Thread(new Runnable()
+ void appletRestart() {
+ panel.sendEvent(AppletPanel.APPLET_STOP);
+ panel.sendEvent(AppletPanel.APPLET_DESTROY);
+ panel.sendEvent(AppletPanel.APPLET_INIT);
+ panel.sendEvent(AppletPanel.APPLET_START);
+ }
+
+ /**
+ * Reload the applet.
+ */
+ void appletReload() {
+ panel.sendEvent(AppletPanel.APPLET_STOP);
+ panel.sendEvent(AppletPanel.APPLET_DESTROY);
+ panel.sendEvent(AppletPanel.APPLET_DISPOSE);
+
+ /**
+ * Fixed #4501142: Classlaoder sharing policy doesn't
+ * take "archive" into account. This will be overridden
+ * by Java Plug-in. [stanleyh]
+ */
+ AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey());
+
+ /*
+ * Make sure we don't have two threads running through the event queue
+ * at the same time.
+ */
+ try {
+ panel.joinAppletThread();
+ panel.release();
+ } catch (InterruptedException e) {
+ return; // abort the reload
+ }
+
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ panel.createAppletThread();
+ return null;
+ }
+ });
+
+ panel.sendEvent(AppletPanel.APPLET_LOAD);
+ panel.sendEvent(AppletPanel.APPLET_INIT);
+ panel.sendEvent(AppletPanel.APPLET_START);
+ }
+
+ public int print(Graphics graphics, PageFormat pf, int pageIndex) {
+ return Printable.NO_SUCH_PAGE;
+ }
+
+ /**
+ * Start the applet.
+ */
+ void appletStart() {
+ panel.sendEvent(AppletPanel.APPLET_START);
+ }
+
+ /**
+ * Stop the applet.
+ */
+ void appletStop() {
+ panel.sendEvent(AppletPanel.APPLET_STOP);
+ }
+
+ /**
+ * Shutdown a viewer.
+ * Stop, Destroy, Dispose and Quit a viewer
+ */
+ private void appletShutdown(AppletPanel p) {
+ p.sendEvent(AppletPanel.APPLET_STOP);
+ p.sendEvent(AppletPanel.APPLET_DESTROY);
+ p.sendEvent(AppletPanel.APPLET_DISPOSE);
+ p.sendEvent(AppletPanel.APPLET_QUIT);
+ }
+
+ /**
+ * Close this viewer.
+ * Stop, Destroy, Dispose and Quit an AppletView, then
+ * reclaim resources and exit the program if this is
+ * the last applet.
+ */
+ void appletClose() {
+
+ // The caller thread is event dispatch thread, so
+ // spawn a new thread to avoid blocking the event queue
+ // when calling appletShutdown.
+ //
+ final AppletPanel p = panel;
+
+ new Thread(new Runnable()
{
public void run()
{
@@ -1661,7 +1644,7 @@ import com.sun.jndi.toolkit.url.UrlUtil;
dispose();
if (tg.activeCount() > 0)
- tg.stop();
+ tg.stop();
if (countApplets() == 0) {
appletSystemExit();
@@ -1671,497 +1654,490 @@ import com.sun.jndi.toolkit.url.UrlUtil;
}
}).start();
- }
-
- /**
- * Exit the program.
- * Exit from the program (if not stand alone) - do no clean-up
- */
- private void appletSystemExit() {
- // Do nothing. Exit is handled by another
- // block of code, called when _all_ applets are gone
- }
-
- /**
- * How many applets are running?
- */
-
- public static int countApplets() {
- return appletPanels.size();
- }
-
-
- /**
- * Scan spaces.
- */
- public static void skipSpace(int[] c, Reader in) throws IOException {
- while ((c[0] >= 0) &&
- ((c[0] == ' ') || (c[0] == '\t') || (c[0] == '\n') || (c[0] == '\r'))) {
- c[0] = in.read();
- }
- }
-
- /**
- * Scan identifier
- */
- public static String scanIdentifier(int[] c, Reader in) throws IOException {
- StringBuilder buf = new StringBuilder();
-
- if (c[0] == '!') {
- // Technically, we should be scanning for '!--' but we are reading
- // from a stream, and there is no way to peek ahead. That said,
- // a ! at this point can only mean comment here afaik, so we
- // should be okay
- skipComment(c, in);
- return "";
- }
-
- while (true) {
- if (((c[0] >= 'a') && (c[0] <= 'z')) ||
- ((c[0] >= 'A') && (c[0] <= 'Z')) ||
- ((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '_')) {
- buf.append((char)c[0]);
- c[0] = in.read();
- } else {
- return buf.toString();
- }
- }
- }
-
- public static void skipComment(int[] c, Reader in) throws IOException {
- StringBuilder buf = new StringBuilder();
- boolean commentHeaderPassed = false;
- c[0] = in.read();
- buf.append((char)c[0]);
-
- while (true) {
- if (c[0] == '-' && (c[0] = in.read()) == '-') {
- buf.append((char)c[0]);
- if (commentHeaderPassed) {
- // -- encountered ... is > next?
- if ((c[0] = in.read()) == '>') {
- buf.append((char)c[0]);
-
- PluginDebug.debug("Comment skipped: " + buf.toString());
-
- // comment skipped.
- return;
- }
- } else {
- // first -- is part of <!-- ... , just mark that we have passed it
- commentHeaderPassed = true;
- }
+ }
- } else if (commentHeaderPassed == false) {
- buf.append((char)c[0]);
- PluginDebug.debug("Warning: Attempted to skip comment, but this tag does not appear to be a comment: " + buf.toString());
- return;
- }
+ /**
+ * Exit the program.
+ * Exit from the program (if not stand alone) - do no clean-up
+ */
+ private void appletSystemExit() {
+ // Do nothing. Exit is handled by another
+ // block of code, called when _all_ applets are gone
+ }
- c[0] = in.read();
- buf.append((char)c[0]);
- }
- }
-
- /**
- * Scan tag
- */
- public static Hashtable<String,String> scanTag(int[] c, Reader in) throws IOException {
- Hashtable<String,String> atts = new Hashtable<String,String>();
- skipSpace(c, in);
- while (c[0] >= 0 && c[0] != '>') {
- String att = scanIdentifier(c, in);
- String val = "";
- skipSpace(c, in);
- if (c[0] == '=') {
- int quote = -1;
- c[0] = in.read();
- skipSpace(c, in);
- if ((c[0] == '\'') || (c[0] == '\"')) {
- quote = c[0];
- c[0] = in.read();
- }
- StringBuilder buf = new StringBuilder();
- while ((c[0] > 0) &&
+ /**
+ * How many applets are running?
+ */
+
+ public static int countApplets() {
+ return appletPanels.size();
+ }
+
+ /**
+ * Scan spaces.
+ */
+ public static void skipSpace(int[] c, Reader in) throws IOException {
+ while ((c[0] >= 0) &&
+ ((c[0] == ' ') || (c[0] == '\t') || (c[0] == '\n') || (c[0] == '\r'))) {
+ c[0] = in.read();
+ }
+ }
+
+ /**
+ * Scan identifier
+ */
+ public static String scanIdentifier(int[] c, Reader in) throws IOException {
+ StringBuilder buf = new StringBuilder();
+
+ if (c[0] == '!') {
+ // Technically, we should be scanning for '!--' but we are reading
+ // from a stream, and there is no way to peek ahead. That said,
+ // a ! at this point can only mean comment here afaik, so we
+ // should be okay
+ skipComment(c, in);
+ return "";
+ }
+
+ while (true) {
+ if (((c[0] >= 'a') && (c[0] <= 'z')) ||
+ ((c[0] >= 'A') && (c[0] <= 'Z')) ||
+ ((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '_')) {
+ buf.append((char) c[0]);
+ c[0] = in.read();
+ } else {
+ return buf.toString();
+ }
+ }
+ }
+
+ public static void skipComment(int[] c, Reader in) throws IOException {
+ StringBuilder buf = new StringBuilder();
+ boolean commentHeaderPassed = false;
+ c[0] = in.read();
+ buf.append((char) c[0]);
+
+ while (true) {
+ if (c[0] == '-' && (c[0] = in.read()) == '-') {
+ buf.append((char) c[0]);
+ if (commentHeaderPassed) {
+ // -- encountered ... is > next?
+ if ((c[0] = in.read()) == '>') {
+ buf.append((char) c[0]);
+
+ PluginDebug.debug("Comment skipped: " + buf.toString());
+
+ // comment skipped.
+ return;
+ }
+ } else {
+ // first -- is part of <!-- ... , just mark that we have passed it
+ commentHeaderPassed = true;
+ }
+
+ } else if (commentHeaderPassed == false) {
+ buf.append((char) c[0]);
+ PluginDebug.debug("Warning: Attempted to skip comment, but this tag does not appear to be a comment: " + buf.toString());
+ return;
+ }
+
+ c[0] = in.read();
+ buf.append((char) c[0]);
+ }
+ }
+
+ /**
+ * Scan tag
+ */
+ public static Hashtable<String, String> scanTag(int[] c, Reader in) throws IOException {
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ skipSpace(c, in);
+ while (c[0] >= 0 && c[0] != '>') {
+ String att = scanIdentifier(c, in);
+ String val = "";
+ skipSpace(c, in);
+ if (c[0] == '=') {
+ int quote = -1;
+ c[0] = in.read();
+ skipSpace(c, in);
+ if ((c[0] == '\'') || (c[0] == '\"')) {
+ quote = c[0];
+ c[0] = in.read();
+ }
+ StringBuilder buf = new StringBuilder();
+ while ((c[0] > 0) &&
(((quote < 0) && (c[0] != ' ') && (c[0] != '\t') &&
- (c[0] != '\n') && (c[0] != '\r') && (c[0] != '>'))
+ (c[0] != '\n') && (c[0] != '\r') && (c[0] != '>'))
|| ((quote >= 0) && (c[0] != quote)))) {
- buf.append((char)c[0]);
- c[0] = in.read();
- }
- if (c[0] == quote) {
- c[0] = in.read();
- }
- skipSpace(c, in);
- val = buf.toString();
- }
+ buf.append((char) c[0]);
+ c[0] = in.read();
+ }
+ if (c[0] == quote) {
+ c[0] = in.read();
+ }
+ skipSpace(c, in);
+ val = buf.toString();
+ }
- PluginDebug.debug("PUT " + att + " = '" + val + "'");
- atts.put(att.toLowerCase(java.util.Locale.ENGLISH), val);
+ PluginDebug.debug("PUT " + att + " = '" + val + "'");
+ atts.put(att.toLowerCase(java.util.Locale.ENGLISH), val);
- while (true) {
- if ((c[0] == '>') || (c[0] < 0) ||
- ((c[0] >= 'a') && (c[0] <= 'z')) ||
- ((c[0] >= 'A') && (c[0] <= 'Z')) ||
- ((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '_'))
- break;
- c[0] = in.read();
- }
- //skipSpace(in);
- }
- return atts;
- }
-
- // private static final == inline
- private static final boolean isInt(Object o) {
- boolean isInt = false;
- try {
- Integer.parseInt((String) o);
- isInt = true;
- } catch (Exception e) {
- // don't care
- }
-
- return isInt;
- }
-
- /* values used for placement of AppletViewer's frames */
- private static int x = 0;
- private static int y = 0;
- private static final int XDELTA = 30;
- private static final int YDELTA = XDELTA;
-
- static String encoding = null;
-
- static private Reader makeReader(InputStream is) {
- if (encoding != null) {
+ while (true) {
+ if ((c[0] == '>') || (c[0] < 0) ||
+ ((c[0] >= 'a') && (c[0] <= 'z')) ||
+ ((c[0] >= 'A') && (c[0] <= 'Z')) ||
+ ((c[0] >= '0') && (c[0] <= '9')) || (c[0] == '_'))
+ break;
+ c[0] = in.read();
+ }
+ //skipSpace(in);
+ }
+ return atts;
+ }
+
+ // private static final == inline
+ private static final boolean isInt(Object o) {
+ boolean isInt = false;
try {
- return new BufferedReader(new InputStreamReader(is, encoding));
- } catch (IOException x) { }
- }
- InputStreamReader r = new InputStreamReader(is);
- encoding = r.getEncoding();
- return new BufferedReader(r);
- }
-
- /**
- * Scan an html file for <applet> tags
- */
- public static void parse(int identifier, long handle, String width, String height, Reader in, URL url, String enc)
- throws IOException {
- encoding = enc;
- parse(identifier, handle, width, height, in, url, System.out, new PluginAppletPanelFactory());
- }
-
- public static void parse(int identifier, long handle, String width, String height, Reader in, URL url)
- throws PrivilegedActionException {
-
- final int fIdentifier = identifier;
- final long fHandle = handle;
- final String fWidth = width;
- final String fHeight = height;
- final Reader fIn = in;
- final URL fUrl = url;
- AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
- public Void run() throws IOException {
- parse(fIdentifier, fHandle, fWidth, fHeight, fIn, fUrl,
- System.out, new PluginAppletPanelFactory());
- return null;
- }
- });
- }
+ Integer.parseInt((String) o);
+ isInt = true;
+ } catch (Exception e) {
+ // don't care
+ }
+
+ return isInt;
+ }
+
+ /* values used for placement of AppletViewer's frames */
+ private static int x = 0;
+ private static int y = 0;
+ private static final int XDELTA = 30;
+ private static final int YDELTA = XDELTA;
- public static void parse(int identifier, long handle, String width,
+ static String encoding = null;
+
+ static private Reader makeReader(InputStream is) {
+ if (encoding != null) {
+ try {
+ return new BufferedReader(new InputStreamReader(is, encoding));
+ } catch (IOException x) {
+ }
+ }
+ InputStreamReader r = new InputStreamReader(is);
+ encoding = r.getEncoding();
+ return new BufferedReader(r);
+ }
+
+ /**
+ * Scan an html file for <applet> tags
+ */
+ public static void parse(int identifier, long handle, String width, String height, Reader in, URL url, String enc)
+ throws IOException {
+ encoding = enc;
+ parse(identifier, handle, width, height, in, url, System.out, new PluginAppletPanelFactory());
+ }
+
+ public static void parse(int identifier, long handle, String width, String height, Reader in, URL url)
+ throws PrivilegedActionException {
+
+ final int fIdentifier = identifier;
+ final long fHandle = handle;
+ final String fWidth = width;
+ final String fHeight = height;
+ final Reader fIn = in;
+ final URL fUrl = url;
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
+ public Void run() throws IOException {
+ parse(fIdentifier, fHandle, fWidth, fHeight, fIn, fUrl,
+ System.out, new PluginAppletPanelFactory());
+ return null;
+ }
+ });
+ }
+
+ public static void parse(int identifier, long handle, String width,
String height, Reader in, URL url,
PrintStream statusMsgStream,
PluginAppletPanelFactory factory)
- throws IOException
- {
- // <OBJECT> <EMBED> tag flags
- boolean isAppletTag = false;
- boolean isObjectTag = false;
- boolean isEmbedTag = false;
- boolean objectTagAlreadyParsed = false;
-
- // The current character
- // FIXME: This is an evil hack to force pass-by-reference.. the
- // parsing code needs to be rewritten from scratch to prevent such
- //a need
- int[] c = new int[1];
-
- // warning messages
- String requiresNameWarning = amh.getMessage("parse.warning.requiresname");
- String paramOutsideWarning = amh.getMessage("parse.warning.paramoutside");
- String appletRequiresCodeWarning = amh.getMessage("parse.warning.applet.requirescode");
- String appletRequiresHeightWarning = amh.getMessage("parse.warning.applet.requiresheight");
- String appletRequiresWidthWarning = amh.getMessage("parse.warning.applet.requireswidth");
- String objectRequiresCodeWarning = amh.getMessage("parse.warning.object.requirescode");
- String objectRequiresHeightWarning = amh.getMessage("parse.warning.object.requiresheight");
- String objectRequiresWidthWarning = amh.getMessage("parse.warning.object.requireswidth");
- String embedRequiresCodeWarning = amh.getMessage("parse.warning.embed.requirescode");
- String embedRequiresHeightWarning = amh.getMessage("parse.warning.embed.requiresheight");
- String embedRequiresWidthWarning = amh.getMessage("parse.warning.embed.requireswidth");
- String appNotLongerSupportedWarning = amh.getMessage("parse.warning.appnotLongersupported");
-
- java.net.URLConnection conn = url.openConnection();
- /* The original URL may have been redirected - this
- * sets it to whatever URL/codebase we ended up getting
- */
- url = conn.getURL();
-
- int ydisp = 1;
- Hashtable<String,String> atts = null;
-
- while(true) {
- c[0] = in.read();
- if (c[0] == -1)
- break;
-
- if (c[0] == '<') {
- c[0] = in.read();
- if (c[0] == '/') {
- c[0] = in.read();
- String nm = scanIdentifier(c, in);
- if (nm.equalsIgnoreCase("applet") ||
+ throws IOException {
+ // <OBJECT> <EMBED> tag flags
+ boolean isAppletTag = false;
+ boolean isObjectTag = false;
+ boolean isEmbedTag = false;
+ boolean objectTagAlreadyParsed = false;
+
+ // The current character
+ // FIXME: This is an evil hack to force pass-by-reference.. the
+ // parsing code needs to be rewritten from scratch to prevent such
+ //a need
+ int[] c = new int[1];
+
+ // warning messages
+ String requiresNameWarning = amh.getMessage("parse.warning.requiresname");
+ String paramOutsideWarning = amh.getMessage("parse.warning.paramoutside");
+ String appletRequiresCodeWarning = amh.getMessage("parse.warning.applet.requirescode");
+ String appletRequiresHeightWarning = amh.getMessage("parse.warning.applet.requiresheight");
+ String appletRequiresWidthWarning = amh.getMessage("parse.warning.applet.requireswidth");
+ String objectRequiresCodeWarning = amh.getMessage("parse.warning.object.requirescode");
+ String objectRequiresHeightWarning = amh.getMessage("parse.warning.object.requiresheight");
+ String objectRequiresWidthWarning = amh.getMessage("parse.warning.object.requireswidth");
+ String embedRequiresCodeWarning = amh.getMessage("parse.warning.embed.requirescode");
+ String embedRequiresHeightWarning = amh.getMessage("parse.warning.embed.requiresheight");
+ String embedRequiresWidthWarning = amh.getMessage("parse.warning.embed.requireswidth");
+ String appNotLongerSupportedWarning = amh.getMessage("parse.warning.appnotLongersupported");
+
+ java.net.URLConnection conn = url.openConnection();
+ /* The original URL may have been redirected - this
+ * sets it to whatever URL/codebase we ended up getting
+ */
+ url = conn.getURL();
+
+ int ydisp = 1;
+ Hashtable<String, String> atts = null;
+
+ while (true) {
+ c[0] = in.read();
+ if (c[0] == -1)
+ break;
+
+ if (c[0] == '<') {
+ c[0] = in.read();
+ if (c[0] == '/') {
+ c[0] = in.read();
+ String nm = scanIdentifier(c, in);
+ if (nm.equalsIgnoreCase("applet") ||
nm.equalsIgnoreCase("object") ||
nm.equalsIgnoreCase("embed")) {
- // We can't test for a code tag until </OBJECT>
- // because it is a parameter, not an attribute.
- if(isObjectTag) {
- if (atts.get("code") == null && atts.get("object") == null) {
- statusMsgStream.println(objectRequiresCodeWarning);
- atts = null;
- }
- }
-
- if (atts != null) {
- // XXX 5/18 In general this code just simply
- // shouldn't be part of parsing. It's presence
- // causes things to be a little too much of a
- // hack.
-
- // Let user know we are starting up
- streamhandler.write("instance " + identifier + " status " + amh.getMessage("status.start"));
- factory.createPanel(streamhandler, identifier, handle, x, y, url, atts);
-
- x += XDELTA;
- y += YDELTA;
- // make sure we don't go too far!
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- if ((x > d.width - 300) || (y > d.height - 300)) {
- x = 0;
- y = 2 * ydisp * YDELTA;
- ydisp++;
- }
- }
- atts = null;
- isAppletTag = false;
- isObjectTag = false;
- isEmbedTag = false;
- }
- }
- else {
- String nm = scanIdentifier(c, in);
- if (nm.equalsIgnoreCase("param")) {
- Hashtable<String,String> t = scanTag(c, in);
- String att = t.get("name");
-
- if (atts.containsKey(att))
- continue;
-
- if (att == null) {
- statusMsgStream.println(requiresNameWarning);
- } else {
- String val = t.get("value");
- if (val == null) {
- statusMsgStream.println(requiresNameWarning);
- } else if (atts != null) {
- PluginDebug.debug("PUT " + att + " = " + val);
- atts.put(att.toLowerCase(), val);
- } else {
- statusMsgStream.println(paramOutsideWarning);
- }
- }
- }
- else if (nm.equalsIgnoreCase("applet")) {
- isAppletTag = true;
- atts = scanTag(c, in);
-
- // If there is a classid and no code tag present, transform it to code tag
- if (atts.get("code") == null && atts.get("classid") != null
- && !(atts.get("classid")).startsWith("clsid:")) {
- atts.put("code", atts.get("classid"));
- }
-
- // remove java: from code tag
- if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
- atts.put("code", (atts.get("code")).substring(5));
- }
-
- if (atts.get("code") == null && atts.get("object") == null) {
- statusMsgStream.println(appletRequiresCodeWarning);
- atts = null;
- }
-
- if (atts.get("width") == null || !isInt(atts.get("width"))) {
- atts.put("width", width);
- }
-
- if (atts.get("height") == null || !isInt(atts.get("height"))) {
- atts.put("height", height);
- }
- }
- else if (nm.equalsIgnoreCase("object")) {
- isObjectTag = true;
-
- // Once code is set, additional nested objects are ignored
- if (!objectTagAlreadyParsed) {
- objectTagAlreadyParsed = true;
- atts = scanTag(c, in);
- }
-
- // If there is a classid and no code tag present, transform it to code tag
- if (atts.get("code") == null && atts.get("classid") != null
- && !(atts.get("classid")).startsWith("clsid:")) {
- atts.put("code", atts.get("classid"));
- }
-
- // remove java: from code tag
- if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
- atts.put("code", (atts.get("code")).substring(5));
- }
-
- // java_* aliases override older names:
- // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-ie
- if (atts.get("java_code") != null) {
- atts.put("code", (atts.get("java_code")));
- }
-
- if (atts.containsKey("code")) {
- objectTagAlreadyParsed = true;
- }
-
- if (atts.get("java_codebase") != null) {
- atts.put("codebase", (atts.get("java_codebase")));
- }
-
- if (atts.get("java_archive") != null) {
- atts.put("archive", (atts.get("java_archive")));
- }
-
- if (atts.get("java_object") != null) {
- atts.put("object", (atts.get("java_object")));
- }
-
- if (atts.get("java_type") != null) {
- atts.put("type", (atts.get("java_type")));
- }
-
- if (atts.get("width") == null || !isInt(atts.get("width"))) {
- atts.put("width", width);
- }
-
- if (atts.get("height") == null || !isInt(atts.get("height"))) {
- atts.put("height", height);
- }
- }
- else if (nm.equalsIgnoreCase("embed")) {
- isEmbedTag = true;
- atts = scanTag(c, in);
-
- // If there is a classid and no code tag present, transform it to code tag
- if (atts.get("code") == null && atts.get("classid") != null
- && !(atts.get("classid")).startsWith("clsid:")) {
- atts.put("code", atts.get("classid"));
- }
-
- // remove java: from code tag
- if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
- atts.put("code", (atts.get("code")).substring(5));
- }
-
- // java_* aliases override older names:
- // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-nav
- if (atts.get("java_code") != null) {
- atts.put("code", (atts.get("java_code")));
- }
-
- if (atts.get("java_codebase") != null) {
- atts.put("codebase", (atts.get("java_codebase")));
- }
-
- if (atts.get("java_archive") != null) {
- atts.put("archive", (atts.get("java_archive")));
- }
-
- if (atts.get("java_object") != null) {
- atts.put("object", (atts.get("java_object")));
- }
-
- if (atts.get("java_type") != null) {
- atts.put("type", (atts.get("java_type")));
- }
-
- if (atts.get("code") == null && atts.get("object") == null) {
- statusMsgStream.println(embedRequiresCodeWarning);
- atts = null;
- }
-
- if (atts.get("width") == null || !isInt(atts.get("width"))) {
- atts.put("width", width);
- }
-
- if (atts.get("height") == null || !isInt(atts.get("height"))) {
- atts.put("height", height);
- }
-
- }
- }
- }
- }
- in.close();
- }
-
+ // We can't test for a code tag until </OBJECT>
+ // because it is a parameter, not an attribute.
+ if (isObjectTag) {
+ if (atts.get("code") == null && atts.get("object") == null) {
+ statusMsgStream.println(objectRequiresCodeWarning);
+ atts = null;
+ }
+ }
- private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer");
+ if (atts != null) {
+ // XXX 5/18 In general this code just simply
+ // shouldn't be part of parsing. It's presence
+ // causes things to be a little too much of a
+ // hack.
+
+ // Let user know we are starting up
+ streamhandler.write("instance " + identifier + " status " + amh.getMessage("status.start"));
+ factory.createPanel(streamhandler, identifier, handle, x, y, url, atts);
+
+ x += XDELTA;
+ y += YDELTA;
+ // make sure we don't go too far!
+ Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+ if ((x > d.width - 300) || (y > d.height - 300)) {
+ x = 0;
+ y = 2 * ydisp * YDELTA;
+ ydisp++;
+ }
+ }
+ atts = null;
+ isAppletTag = false;
+ isObjectTag = false;
+ isEmbedTag = false;
+ }
+ } else {
+ String nm = scanIdentifier(c, in);
+ if (nm.equalsIgnoreCase("param")) {
+ Hashtable<String, String> t = scanTag(c, in);
+ String att = t.get("name");
+
+ if (atts.containsKey(att))
+ continue;
+
+ if (att == null) {
+ statusMsgStream.println(requiresNameWarning);
+ } else {
+ String val = t.get("value");
+ if (val == null) {
+ statusMsgStream.println(requiresNameWarning);
+ } else if (atts != null) {
+ PluginDebug.debug("PUT " + att + " = " + val);
+ atts.put(att.toLowerCase(), val);
+ } else {
+ statusMsgStream.println(paramOutsideWarning);
+ }
+ }
+ } else if (nm.equalsIgnoreCase("applet")) {
+ isAppletTag = true;
+ atts = scanTag(c, in);
+
+ // If there is a classid and no code tag present, transform it to code tag
+ if (atts.get("code") == null && atts.get("classid") != null
+ && !(atts.get("classid")).startsWith("clsid:")) {
+ atts.put("code", atts.get("classid"));
+ }
- private static void checkConnect(URL url)
- {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- try {
- java.security.Permission perm =
- url.openConnection().getPermission();
- if (perm != null)
- security.checkPermission(perm);
- else
- security.checkConnect(url.getHost(), url.getPort());
- } catch (java.io.IOException ioe) {
- security.checkConnect(url.getHost(), url.getPort());
+ // remove java: from code tag
+ if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
+ atts.put("code", (atts.get("code")).substring(5));
+ }
+
+ if (atts.get("code") == null && atts.get("object") == null) {
+ statusMsgStream.println(appletRequiresCodeWarning);
+ atts = null;
+ }
+
+ if (atts.get("width") == null || !isInt(atts.get("width"))) {
+ atts.put("width", width);
+ }
+
+ if (atts.get("height") == null || !isInt(atts.get("height"))) {
+ atts.put("height", height);
+ }
+ } else if (nm.equalsIgnoreCase("object")) {
+ isObjectTag = true;
+
+ // Once code is set, additional nested objects are ignored
+ if (!objectTagAlreadyParsed) {
+ objectTagAlreadyParsed = true;
+ atts = scanTag(c, in);
+ }
+
+ // If there is a classid and no code tag present, transform it to code tag
+ if (atts.get("code") == null && atts.get("classid") != null
+ && !(atts.get("classid")).startsWith("clsid:")) {
+ atts.put("code", atts.get("classid"));
+ }
+
+ // remove java: from code tag
+ if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
+ atts.put("code", (atts.get("code")).substring(5));
+ }
+
+ // java_* aliases override older names:
+ // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-ie
+ if (atts.get("java_code") != null) {
+ atts.put("code", (atts.get("java_code")));
+ }
+
+ if (atts.containsKey("code")) {
+ objectTagAlreadyParsed = true;
+ }
+
+ if (atts.get("java_codebase") != null) {
+ atts.put("codebase", (atts.get("java_codebase")));
+ }
+
+ if (atts.get("java_archive") != null) {
+ atts.put("archive", (atts.get("java_archive")));
+ }
+
+ if (atts.get("java_object") != null) {
+ atts.put("object", (atts.get("java_object")));
+ }
+
+ if (atts.get("java_type") != null) {
+ atts.put("type", (atts.get("java_type")));
+ }
+
+ if (atts.get("width") == null || !isInt(atts.get("width"))) {
+ atts.put("width", width);
+ }
+
+ if (atts.get("height") == null || !isInt(atts.get("height"))) {
+ atts.put("height", height);
+ }
+ } else if (nm.equalsIgnoreCase("embed")) {
+ isEmbedTag = true;
+ atts = scanTag(c, in);
+
+ // If there is a classid and no code tag present, transform it to code tag
+ if (atts.get("code") == null && atts.get("classid") != null
+ && !(atts.get("classid")).startsWith("clsid:")) {
+ atts.put("code", atts.get("classid"));
+ }
+
+ // remove java: from code tag
+ if (atts.get("code") != null && (atts.get("code")).startsWith("java:")) {
+ atts.put("code", (atts.get("code")).substring(5));
+ }
+
+ // java_* aliases override older names:
+ // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-nav
+ if (atts.get("java_code") != null) {
+ atts.put("code", (atts.get("java_code")));
+ }
+
+ if (atts.get("java_codebase") != null) {
+ atts.put("codebase", (atts.get("java_codebase")));
+ }
+
+ if (atts.get("java_archive") != null) {
+ atts.put("archive", (atts.get("java_archive")));
+ }
+
+ if (atts.get("java_object") != null) {
+ atts.put("object", (atts.get("java_object")));
+ }
+
+ if (atts.get("java_type") != null) {
+ atts.put("type", (atts.get("java_type")));
+ }
+
+ if (atts.get("code") == null && atts.get("object") == null) {
+ statusMsgStream.println(embedRequiresCodeWarning);
+ atts = null;
+ }
+
+ if (atts.get("width") == null || !isInt(atts.get("width"))) {
+ atts.put("width", width);
+ }
+
+ if (atts.get("height") == null || !isInt(atts.get("height"))) {
+ atts.put("height", height);
+ }
+
+ }
+ }
+ }
+ }
+ in.close();
+ }
+
+ private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer");
+
+ private static void checkConnect(URL url) {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ try {
+ java.security.Permission perm =
+ url.openConnection().getPermission();
+ if (perm != null)
+ security.checkPermission(perm);
+ else
+ security.checkConnect(url.getHost(), url.getPort());
+ } catch (java.io.IOException ioe) {
+ security.checkConnect(url.getHost(), url.getPort());
+ }
}
}
- }
-
- /**
- * {@inheritDoc}
- *
- * This method calls paint directly, rather than via super.update() since
- * the parent class's update() just does a couple of checks (both of
- * which are accounted for) and then calls paint anyway.
- */
- public void update(Graphics g) {
-
- // If the image or the graphics don't exist, create new ones
- if (bufFrameImg == null || bufFrameImgGraphics == null) {
- bufFrameImg = createImage(getWidth(), getHeight());
- bufFrameImgGraphics = bufFrameImg.getGraphics ();
- }
-
- // Paint off-screen
- paint(bufFrameImgGraphics);
-
- // Draw the painted image
- g.drawImage(bufFrameImg, 0, 0, this);
- }
- }
+
+ /**
+ * {@inheritDoc}
+ *
+ * This method calls paint directly, rather than via super.update() since
+ * the parent class's update() just does a couple of checks (both of
+ * which are accounted for) and then calls paint anyway.
+ */
+ public void update(Graphics g) {
+
+ // If the image or the graphics don't exist, create new ones
+ if (bufFrameImg == null || bufFrameImgGraphics == null) {
+ bufFrameImg = createImage(getWidth(), getHeight());
+ bufFrameImgGraphics = bufFrameImg.getGraphics();
+ }
+
+ // Paint off-screen
+ paint(bufFrameImgGraphics);
+
+ // Draw the painted image
+ g.drawImage(bufFrameImg, 0, 0, this);
+ }
+}
diff --git a/plugin/icedteanp/java/sun/applet/PluginCallRequest.java b/plugin/icedteanp/java/sun/applet/PluginCallRequest.java
index a4f01a7..b32ff8b 100644
--- a/plugin/icedteanp/java/sun/applet/PluginCallRequest.java
+++ b/plugin/icedteanp/java/sun/applet/PluginCallRequest.java
@@ -54,23 +54,23 @@ public abstract class PluginCallRequest {
}
public String getMessage() {
- return this.message;
+ return this.message;
}
-
+
public boolean isDone() {
- return this.done;
+ return this.done;
}
-
+
public boolean setDone(boolean done) {
- return this.done = done;
+ return this.done = done;
}
-
+
public void setNext(PluginCallRequest next) {
- this.next = next;
+ this.next = next;
}
-
+
public PluginCallRequest getNext() {
- return this.next;
+ return this.next;
}
/**
@@ -82,8 +82,8 @@ public abstract class PluginCallRequest {
public boolean serviceable(String message) {
return message.contains("reference " + reference);
}
-
+
public abstract void parseReturn(String message);
-
+
public abstract Object getObject();
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java b/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
index 69cec35..d5edc6f 100644
--- a/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
+++ b/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
@@ -35,27 +35,25 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
-
public class PluginCallRequestFactory {
-
- public PluginCallRequest getPluginCallRequest(String id, String message, Long reference) {
-
- if (id == "member") {
- return new GetMemberPluginCallRequest(message, reference);
- } else if (id == "void") {
- return new VoidPluginCallRequest(message, reference);
- } else if (id == "window") {
- return new GetWindowPluginCallRequest(message, reference);
- } else if (id == "proxyinfo") {
+
+ public PluginCallRequest getPluginCallRequest(String id, String message, Long reference) {
+
+ if (id == "member") {
+ return new GetMemberPluginCallRequest(message, reference);
+ } else if (id == "void") {
+ return new VoidPluginCallRequest(message, reference);
+ } else if (id == "window") {
+ return new GetWindowPluginCallRequest(message, reference);
+ } else if (id == "proxyinfo") {
return new PluginProxyInfoRequest(message, reference);
} else if (id == "cookieinfo") {
return new PluginCookieInfoRequest(message, reference);
} else {
- throw new RuntimeException ("Unknown plugin call request type requested from factory");
- }
- }
+ throw new RuntimeException("Unknown plugin call request type requested from factory");
+ }
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginClassLoader.java b/plugin/icedteanp/java/sun/applet/PluginClassLoader.java
index 5965d0d..0af80c2 100644
--- a/plugin/icedteanp/java/sun/applet/PluginClassLoader.java
+++ b/plugin/icedteanp/java/sun/applet/PluginClassLoader.java
@@ -35,17 +35,16 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
public class PluginClassLoader extends ClassLoader {
- public PluginClassLoader() {
- super();
- }
+ public PluginClassLoader() {
+ super();
+ }
+
+ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ return super.loadClass(name, resolve);
+ }
- public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- return super.loadClass(name, resolve);
- }
-
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java b/plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java
index c08d9f5..89ef98d 100644
--- a/plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java
+++ b/plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java
@@ -37,7 +37,6 @@ exception statement from your version. */
package sun.applet;
-
/**
* This class represents a request object for cookie information for a given URI
*/
@@ -55,20 +54,20 @@ public class PluginCookieInfoRequest extends PluginCallRequest {
// try to parse the proxy information. If things go wrong, do nothing ..
// this will keep internal = null which forces a direct connection
- PluginDebug.debug ("PluginCookieInfoRequest GOT: " + cookieInfo);
+ PluginDebug.debug("PluginCookieInfoRequest GOT: " + cookieInfo);
- // Skip the first 5 components. We are guaranteed 5 components,
- // so no index -1 to worry about
- cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1);
- cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1);
- cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1);
- cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1);
- cookieString = cookieInfo.substring(cookieInfo.indexOf(' ')+1);
+ // Skip the first 5 components. We are guaranteed 5 components,
+ // so no index -1 to worry about
+ cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ') + 1);
+ cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ') + 1);
+ cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ') + 1);
+ cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ') + 1);
+ cookieString = cookieInfo.substring(cookieInfo.indexOf(' ') + 1);
setDone(true);
}
public String getObject() {
- return this.cookieString;
+ return this.cookieString;
}
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginCookieManager.java b/plugin/icedteanp/java/sun/applet/PluginCookieManager.java
index 233cfa9..72a94dc 100644
--- a/plugin/icedteanp/java/sun/applet/PluginCookieManager.java
+++ b/plugin/icedteanp/java/sun/applet/PluginCookieManager.java
@@ -45,35 +45,34 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-public class PluginCookieManager extends CookieManager
-{
+public class PluginCookieManager extends CookieManager {
public Map<String, List<String>> get(URI uri,
- Map<String, List<String>> requestHeaders) throws IOException {
- // pre-condition check
- if (uri == null || requestHeaders == null) {
- throw new IllegalArgumentException("Argument is null");
- }
-
- Map<String, List<String>> cookieMap = new java.util.HashMap<String, List<String>>();
-
- String cookies = (String) PluginAppletViewer
- .requestPluginCookieInfo(uri);
- List<String> cookieHeader = new java.util.ArrayList<String>();
-
- if (cookies != null && cookies.length() > 0)
- cookieHeader.add(cookies);
-
- // Add anything else that mozilla didn't add
+ Map<String, List<String>> requestHeaders) throws IOException {
+ // pre-condition check
+ if (uri == null || requestHeaders == null) {
+ throw new IllegalArgumentException("Argument is null");
+ }
+
+ Map<String, List<String>> cookieMap = new java.util.HashMap<String, List<String>>();
+
+ String cookies = (String) PluginAppletViewer
+ .requestPluginCookieInfo(uri);
+ List<String> cookieHeader = new java.util.ArrayList<String>();
+
+ if (cookies != null && cookies.length() > 0)
+ cookieHeader.add(cookies);
+
+ // Add anything else that mozilla didn't add
for (HttpCookie cookie : getCookieStore().get(uri)) {
// apply path-matches rule (RFC 2965 sec. 3.3.4)
if (pathMatches(uri.getPath(), cookie.getPath())) {
- cookieHeader.add(cookie.toString());
+ cookieHeader.add(cookie.toString());
}
}
- cookieMap.put("Cookie", cookieHeader);
- return Collections.unmodifiableMap(cookieMap);
- }
+ cookieMap.put("Cookie", cookieHeader);
+ return Collections.unmodifiableMap(cookieMap);
+ }
private boolean pathMatches(String path, String pathToMatchWith) {
if (path == pathToMatchWith)
diff --git a/plugin/icedteanp/java/sun/applet/PluginDebug.java b/plugin/icedteanp/java/sun/applet/PluginDebug.java
index 60e2bd0..d96314c 100644
--- a/plugin/icedteanp/java/sun/applet/PluginDebug.java
+++ b/plugin/icedteanp/java/sun/applet/PluginDebug.java
@@ -35,17 +35,16 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
import java.io.*;
public class PluginDebug {
- static final boolean DEBUG = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG");
+ static final boolean DEBUG = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG");
public static void debug(String message) {
- if (DEBUG)
- System.err.println(message);
- }
+ if (DEBUG)
+ System.err.println(message);
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginException.java b/plugin/icedteanp/java/sun/applet/PluginException.java
index 0f6e660..4d42eff 100644
--- a/plugin/icedteanp/java/sun/applet/PluginException.java
+++ b/plugin/icedteanp/java/sun/applet/PluginException.java
@@ -35,19 +35,17 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
-
public class PluginException extends Exception {
- public PluginException (PluginStreamHandler sh, int instance, int reference, Throwable t) {
- t.printStackTrace();
- this.setStackTrace(t.getStackTrace());
-
- AppletSecurityContextManager.dumpStore(0);
+ public PluginException(PluginStreamHandler sh, int instance, int reference, Throwable t) {
+ t.printStackTrace();
+ this.setStackTrace(t.getStackTrace());
+
+ AppletSecurityContextManager.dumpStore(0);
- String message = "instance " + instance + " reference " + reference + " Error " + t.getMessage();
- sh.write(message);
- }
+ String message = "instance " + instance + " reference " + reference + " Error " + t.getMessage();
+ sh.write(message);
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java
index 6c4b1f4..283a452 100644
--- a/plugin/icedteanp/java/sun/applet/PluginMain.java
+++ b/plugin/icedteanp/java/sun/applet/PluginMain.java
@@ -82,14 +82,13 @@ import net.sourceforge.jnlp.security.JNLPAuthenticator;
/**
* The main entry point into PluginAppletViewer.
*/
-public class PluginMain
-{
+public class PluginMain {
// the files where stdout/stderr are sent to
public static final String PLUGIN_STDERR_FILE = "java.stderr";
public static final String PLUGIN_STDOUT_FILE = "java.stdout";
- final boolean redirectStreams = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG");
- static PluginStreamHandler streamHandler;
+ final boolean redirectStreams = System.getenv().containsKey("ICEDTEAPLUGIN_DEBUG");
+ static PluginStreamHandler streamHandler;
// This is used in init(). Getting rid of this is desirable but depends
// on whether the property that uses it is necessary/standard.
@@ -101,25 +100,23 @@ public class PluginMain
* The main entry point into AppletViewer.
*/
public static void main(String args[])
- throws IOException
- {
+ throws IOException {
if (args.length != 2 || !(new File(args[0]).exists()) || !(new File(args[1]).exists())) {
System.err.println("Invalid pipe names provided. Refusing to proceed.");
System.exit(1);
}
try {
- PluginMain pm = new PluginMain(args[0], args[1]);
+ PluginMain pm = new PluginMain(args[0], args[1]);
} catch (Exception e) {
- e.printStackTrace();
- System.err.println("Something very bad happened. I don't know what to do, so I am going to exit :(");
- System.exit(1);
+ e.printStackTrace();
+ System.err.println("Something very bad happened. I don't know what to do, so I am going to exit :(");
+ System.exit(1);
}
}
public PluginMain(String inPipe, String outPipe) {
-
connect(inPipe, outPipe);
// must be called before JNLPRuntime.initialize()
@@ -130,87 +127,87 @@ public class PluginMain
securityContext.setStreamhandler(streamHandler);
AppletSecurityContextManager.addContext(0, securityContext);
- PluginAppletViewer.setStreamhandler(streamHandler);
- PluginAppletViewer.setPluginCallRequestFactory(new PluginCallRequestFactory());
+ PluginAppletViewer.setStreamhandler(streamHandler);
+ PluginAppletViewer.setPluginCallRequestFactory(new PluginCallRequestFactory());
init();
- // Streams set. Start processing.
- streamHandler.startProcessing();
+ // Streams set. Start processing.
+ streamHandler.startProcessing();
+ }
+
+ public void connect(String inPipe, String outPipe) {
+ try {
+ streamHandler = new PluginStreamHandler(new FileInputStream(inPipe), new FileOutputStream(outPipe));
+ PluginDebug.debug("Streams initialized");
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
}
- public void connect(String inPipe, String outPipe) {
- try {
- streamHandler = new PluginStreamHandler(new FileInputStream(inPipe), new FileOutputStream(outPipe));
- PluginDebug.debug("Streams initialized");
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
+ private static void init() {
+ Properties avProps = new Properties();
+
+ // ADD OTHER RANDOM PROPERTIES
+ // XXX 5/18 need to revisit why these are here, is there some
+ // standard for what is available?
+
+ // Standard browser properties
+ avProps.put("browser", "sun.applet.AppletViewer");
+ avProps.put("browser.version", "1.06");
+ avProps.put("browser.vendor", "Sun Microsystems Inc.");
+ avProps.put("http.agent", "Java(tm) 2 SDK, Standard Edition v" + theVersion);
+
+ // Define which packages can be extended by applets
+ // XXX 5/19 probably not needed, not checked in AppletSecurity
+ avProps.put("package.restrict.definition.java", "true");
+ avProps.put("package.restrict.definition.sun", "true");
+
+ // Define which properties can be read by applets.
+ // A property named by "key" can be read only when its twin
+ // property "key.applet" is true. The following ten properties
+ // are open by default. Any other property can be explicitly
+ // opened up by the browser user by calling appletviewer with
+ // -J-Dkey.applet=true
+ avProps.put("java.version.applet", "true");
+ avProps.put("java.vendor.applet", "true");
+ avProps.put("java.vendor.url.applet", "true");
+ avProps.put("java.class.version.applet", "true");
+ avProps.put("os.name.applet", "true");
+ avProps.put("os.version.applet", "true");
+ avProps.put("os.arch.applet", "true");
+ avProps.put("file.separator.applet", "true");
+ avProps.put("path.separator.applet", "true");
+ avProps.put("line.separator.applet", "true");
+
+ avProps.put("javaplugin.nodotversion", "160_17");
+ avProps.put("javaplugin.version", "1.6.0_17");
+ avProps.put("javaplugin.vm.options", "");
+
+ // Read in the System properties. If something is going to be
+ // over-written, warn about it.
+ Properties sysProps = System.getProperties();
+ for (Enumeration<?> e = sysProps.propertyNames(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String val = sysProps.getProperty(key);
+ avProps.setProperty(key, val);
}
- private static void init() {
- Properties avProps = new Properties();
-
- // ADD OTHER RANDOM PROPERTIES
- // XXX 5/18 need to revisit why these are here, is there some
- // standard for what is available?
-
- // Standard browser properties
- avProps.put("browser", "sun.applet.AppletViewer");
- avProps.put("browser.version", "1.06");
- avProps.put("browser.vendor", "Sun Microsystems Inc.");
- avProps.put("http.agent", "Java(tm) 2 SDK, Standard Edition v" + theVersion);
-
- // Define which packages can be extended by applets
- // XXX 5/19 probably not needed, not checked in AppletSecurity
- avProps.put("package.restrict.definition.java", "true");
- avProps.put("package.restrict.definition.sun", "true");
-
- // Define which properties can be read by applets.
- // A property named by "key" can be read only when its twin
- // property "key.applet" is true. The following ten properties
- // are open by default. Any other property can be explicitly
- // opened up by the browser user by calling appletviewer with
- // -J-Dkey.applet=true
- avProps.put("java.version.applet", "true");
- avProps.put("java.vendor.applet", "true");
- avProps.put("java.vendor.url.applet", "true");
- avProps.put("java.class.version.applet", "true");
- avProps.put("os.name.applet", "true");
- avProps.put("os.version.applet", "true");
- avProps.put("os.arch.applet", "true");
- avProps.put("file.separator.applet", "true");
- avProps.put("path.separator.applet", "true");
- avProps.put("line.separator.applet", "true");
-
- avProps.put("javaplugin.nodotversion", "160_17");
- avProps.put("javaplugin.version", "1.6.0_17");
- avProps.put("javaplugin.vm.options", "");
-
- // Read in the System properties. If something is going to be
- // over-written, warn about it.
- Properties sysProps = System.getProperties();
- for (Enumeration<?> e = sysProps.propertyNames(); e.hasMoreElements(); ) {
- String key = (String) e.nextElement();
- String val = sysProps.getProperty(key);
- avProps.setProperty(key, val);
- }
-
- // INSTALL THE PROPERTY LIST
- System.setProperties(avProps);
-
- // plug in a custom authenticator and proxy selector
- boolean installAuthenticator = Boolean.valueOf(JNLPRuntime.getConfiguration()
+ // INSTALL THE PROPERTY LIST
+ System.setProperties(avProps);
+
+ // plug in a custom authenticator and proxy selector
+ boolean installAuthenticator = Boolean.valueOf(JNLPRuntime.getConfiguration()
.getProperty(DeploymentConfiguration.KEY_SECURITY_INSTALL_AUTHENTICATOR));
- if (installAuthenticator) {
- Authenticator.setDefault(new JNLPAuthenticator());
- }
+ if (installAuthenticator) {
+ Authenticator.setDefault(new JNLPAuthenticator());
+ }
// override the proxy selector set by JNLPRuntime
ProxySelector.setDefault(new PluginProxySelector());
CookieManager ckManager = new PluginCookieManager();
CookieHandler.setDefault(ckManager);
- }
+ }
static boolean messageAvailable() {
return streamHandler.messageAvailable();
diff --git a/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java b/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java
index 188155b..c30cdcb 100644
--- a/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java
+++ b/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java
@@ -45,36 +45,36 @@ import java.util.Set;
class PluginMessageConsumer {
- private static int MAX_PARALLEL_INITS = 1;
-
- // Each initialization requires 5 responses (tag, handle, width, proxy, cookie)
- // before the message stack unlocks/collapses. This works out well because we
- // want to allow upto 5 parallel tasks anyway
- private static int MAX_WORKERS = MAX_PARALLEL_INITS*4;
- private static int PRIORITY_WORKERS = MAX_PARALLEL_INITS*2;
-
- private static Hashtable<Integer, PluginMessageHandlerWorker> initWorkers = new Hashtable<Integer, PluginMessageHandlerWorker>(2);
-
- LinkedList<String> readQueue = new LinkedList<String>();
- private static LinkedList<String> priorityWaitQueue = new LinkedList<String>();
- ArrayList<PluginMessageHandlerWorker> workers = new ArrayList<PluginMessageHandlerWorker>();
- PluginStreamHandler streamHandler = null;
- AppletSecurity as;
- ConsumerThread consumerThread = new ConsumerThread();
- private static ArrayList<Integer> processedIds = new ArrayList<Integer>();
-
- /**
- * Registers a reference to wait for. Responses to registered priority
- * references get handled by priority worker if normal workers are busy.
- *
- * @param reference The reference to give priority to
- */
- public static void registerPriorityWait(Long reference) {
- PluginDebug.debug("Registering priority for reference " + reference);
- registerPriorityWait("reference " + reference.toString());
- }
-
- /**
+ private static int MAX_PARALLEL_INITS = 1;
+
+ // Each initialization requires 5 responses (tag, handle, width, proxy, cookie)
+ // before the message stack unlocks/collapses. This works out well because we
+ // want to allow upto 5 parallel tasks anyway
+ private static int MAX_WORKERS = MAX_PARALLEL_INITS * 4;
+ private static int PRIORITY_WORKERS = MAX_PARALLEL_INITS * 2;
+
+ private static Hashtable<Integer, PluginMessageHandlerWorker> initWorkers = new Hashtable<Integer, PluginMessageHandlerWorker>(2);
+
+ LinkedList<String> readQueue = new LinkedList<String>();
+ private static LinkedList<String> priorityWaitQueue = new LinkedList<String>();
+ ArrayList<PluginMessageHandlerWorker> workers = new ArrayList<PluginMessageHandlerWorker>();
+ PluginStreamHandler streamHandler = null;
+ AppletSecurity as;
+ ConsumerThread consumerThread = new ConsumerThread();
+ private static ArrayList<Integer> processedIds = new ArrayList<Integer>();
+
+ /**
+ * Registers a reference to wait for. Responses to registered priority
+ * references get handled by priority worker if normal workers are busy.
+ *
+ * @param reference The reference to give priority to
+ */
+ public static void registerPriorityWait(Long reference) {
+ PluginDebug.debug("Registering priority for reference " + reference);
+ registerPriorityWait("reference " + reference.toString());
+ }
+
+ /**
* Registers a string to wait for.
*
* @param searchString the string to look for in a response
@@ -87,7 +87,7 @@ class PluginMessageConsumer {
}
}
- /**
+ /**
* Unregisters a priority reference to wait for.
*
* @param reference The reference to remove
@@ -117,46 +117,46 @@ class PluginMessageConsumer {
private Long getReference(String[] msgParts) {
return Long.parseLong(msgParts[3]);
}
-
- public PluginMessageConsumer(PluginStreamHandler streamHandler) {
-
- as = new AppletSecurity();
- this.streamHandler = streamHandler;
- this.consumerThread.start();
- }
-
- private String getPriorityStrIfPriority(String message) {
-
- // Destroy messages are permanently high priority
- if (message.endsWith("destroy"))
+
+ public PluginMessageConsumer(PluginStreamHandler streamHandler) {
+
+ as = new AppletSecurity();
+ this.streamHandler = streamHandler;
+ this.consumerThread.start();
+ }
+
+ private String getPriorityStrIfPriority(String message) {
+
+ // Destroy messages are permanently high priority
+ if (message.endsWith("destroy"))
return "destroy";
- synchronized (priorityWaitQueue) {
- Iterator<String> it = priorityWaitQueue.iterator();
+ synchronized (priorityWaitQueue) {
+ Iterator<String> it = priorityWaitQueue.iterator();
- while (it.hasNext()) {
- String priorityStr = it.next();
- if (message.indexOf(priorityStr) > 0)
- return priorityStr;
- }
- }
+ while (it.hasNext()) {
+ String priorityStr = it.next();
+ if (message.indexOf(priorityStr) > 0)
+ return priorityStr;
+ }
+ }
- return null;
- }
+ return null;
+ }
- private boolean isInInit(Integer instanceNum) {
- return initWorkers.containsKey(instanceNum);
- }
+ private boolean isInInit(Integer instanceNum) {
+ return initWorkers.containsKey(instanceNum);
+ }
- private void addToInitWorkers(Integer instanceNum, PluginMessageHandlerWorker worker) {
- synchronized(initWorkers) {
+ private void addToInitWorkers(Integer instanceNum, PluginMessageHandlerWorker worker) {
+ synchronized (initWorkers) {
initWorkers.put(instanceNum, worker);
}
- }
+ }
- public void notifyWorkerIsFree(PluginMessageHandlerWorker worker) {
- synchronized (initWorkers) {
- Iterator<Integer> i = initWorkers.keySet().iterator();
+ public void notifyWorkerIsFree(PluginMessageHandlerWorker worker) {
+ synchronized (initWorkers) {
+ Iterator<Integer> i = initWorkers.keySet().iterator();
while (i.hasNext()) {
Integer key = i.next();
if (initWorkers.get(key).equals(worker)) {
@@ -164,136 +164,137 @@ class PluginMessageConsumer {
initWorkers.remove(key);
}
}
- }
-
- consumerThread.interrupt();
- }
-
- public void queue(String message) {
- synchronized(readQueue) {
- readQueue.addLast(message);
- }
-
- // Wake that lazy consumer thread
- consumerThread.interrupt();
- }
-
- protected class ConsumerThread extends Thread {
-
- /**
- * Scans the readQueue for priority messages and brings them to the front
- */
- private void bringPriorityMessagesToFront() {
- synchronized (readQueue) {
-
- // iterate through the list
- for (int i=0; i < readQueue.size(); i++) {
-
- // remove element at i to inspect it
- String message = readQueue.remove(i);
-
- // if element at i is a priority msg, bring it forward
- if (getPriorityStrIfPriority(message) != null) {
- readQueue.addFirst(message);
- } else { // else keep it where it was
- readQueue.add(i, message);
- }
-
- // by the end the queue size is the same, so the
- // position indicator (i) is still valid
- }
- }
- }
-
- public void run() {
-
- while (true) {
+ }
+
+ consumerThread.interrupt();
+ }
+
+ public void queue(String message) {
+ synchronized (readQueue) {
+ readQueue.addLast(message);
+ }
+
+ // Wake that lazy consumer thread
+ consumerThread.interrupt();
+ }
+
+ protected class ConsumerThread extends Thread {
+
+ /**
+ * Scans the readQueue for priority messages and brings them to the front
+ */
+ private void bringPriorityMessagesToFront() {
+ synchronized (readQueue) {
+
+ // iterate through the list
+ for (int i = 0; i < readQueue.size(); i++) {
+
+ // remove element at i to inspect it
+ String message = readQueue.remove(i);
+
+ // if element at i is a priority msg, bring it forward
+ if (getPriorityStrIfPriority(message) != null) {
+ readQueue.addFirst(message);
+ } else { // else keep it where it was
+ readQueue.add(i, message);
+ }
+
+ // by the end the queue size is the same, so the
+ // position indicator (i) is still valid
+ }
+ }
+ }
+
+ public void run() {
+
+ while (true) {
String message = null;
- synchronized(readQueue) {
- message = readQueue.poll();
- }
+ synchronized (readQueue) {
+ message = readQueue.poll();
+ }
+
+ if (message != null) {
- if (message != null) {
+ String[] msgParts = message.split(" ");
- String[] msgParts = message.split(" ");
+ String priorityStr = getPriorityStrIfPriority(message);
+ boolean isPriorityResponse = (priorityStr != null);
- String priorityStr = getPriorityStrIfPriority(message);
- boolean isPriorityResponse = (priorityStr != null);
-
- //PluginDebug.debug("Message " + message + " (priority=" + isPriorityResponse + ") ready to be processed. Looking for free worker...");
- final PluginMessageHandlerWorker worker = getFreeWorker(isPriorityResponse);
-
- if (worker == null) {
- synchronized(readQueue) {
+ //PluginDebug.debug("Message " + message + " (priority=" + isPriorityResponse + ") ready to be processed. Looking for free worker...");
+ final PluginMessageHandlerWorker worker = getFreeWorker(isPriorityResponse);
+
+ if (worker == null) {
+ synchronized (readQueue) {
readQueue.addFirst(message);
}
- // re-scan to see if any priority message came in
+ // re-scan to see if any priority message came in
bringPriorityMessagesToFront();
-
- continue; // re-loop to try next msg
- }
- if (msgParts[2].equals("tag"))
- addToInitWorkers((new Integer(msgParts[1])), worker);
+ continue; // re-loop to try next msg
+ }
+
+ if (msgParts[2].equals("tag"))
+ addToInitWorkers((new Integer(msgParts[1])), worker);
- if (isPriorityResponse) {
- unRegisterPriorityWait(priorityStr);
- }
+ if (isPriorityResponse) {
+ unRegisterPriorityWait(priorityStr);
+ }
worker.setmessage(message);
- worker.interrupt();
-
- } else {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ie) {}
- }
- }
- }
- }
-
- private PluginMessageHandlerWorker getFreeWorker(boolean prioritized) {
-
- for (PluginMessageHandlerWorker worker: workers) {
- if (worker.isFree(prioritized)) {
- PluginDebug.debug("Found free worker (" + worker.isPriority() + ") with id " + worker.getWorkerId());
- // mark it busy before returning
- worker.busy();
- return worker;
- }
- }
-
- // If we have less than MAX_WORKERS, create a new worker
- if (workers.size() <= MAX_WORKERS) {
- PluginMessageHandlerWorker worker = null;
-
- if (workers.size() < (MAX_WORKERS - PRIORITY_WORKERS)) {
- PluginDebug.debug("Cannot find free worker, creating worker " + workers.size());
- worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, false);
- } else if (prioritized) {
- PluginDebug.debug("Cannot find free worker, creating priority worker " + workers.size());
- worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, true);
- } else {
- return null;
- }
-
- worker.start();
- worker.busy();
- workers.add(worker);
- return worker;
-
- }
-
- // No workers available. Better luck next time!
- return null;
- }
-
- private void dumpWorkerStatus() {
- for (PluginMessageHandlerWorker worker: workers) {
- PluginDebug.debug(worker.toString());
- }
- }
+ worker.interrupt();
+
+ } else {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+ }
+ }
+
+ private PluginMessageHandlerWorker getFreeWorker(boolean prioritized) {
+
+ for (PluginMessageHandlerWorker worker : workers) {
+ if (worker.isFree(prioritized)) {
+ PluginDebug.debug("Found free worker (" + worker.isPriority() + ") with id " + worker.getWorkerId());
+ // mark it busy before returning
+ worker.busy();
+ return worker;
+ }
+ }
+
+ // If we have less than MAX_WORKERS, create a new worker
+ if (workers.size() <= MAX_WORKERS) {
+ PluginMessageHandlerWorker worker = null;
+
+ if (workers.size() < (MAX_WORKERS - PRIORITY_WORKERS)) {
+ PluginDebug.debug("Cannot find free worker, creating worker " + workers.size());
+ worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, false);
+ } else if (prioritized) {
+ PluginDebug.debug("Cannot find free worker, creating priority worker " + workers.size());
+ worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, true);
+ } else {
+ return null;
+ }
+
+ worker.start();
+ worker.busy();
+ workers.add(worker);
+ return worker;
+
+ }
+
+ // No workers available. Better luck next time!
+ return null;
+ }
+
+ private void dumpWorkerStatus() {
+ for (PluginMessageHandlerWorker worker : workers) {
+ PluginDebug.debug(worker.toString());
+ }
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java b/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java
index 30714c4..91e3746 100644
--- a/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java
+++ b/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java
@@ -35,113 +35,109 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
-
class PluginMessageHandlerWorker extends Thread {
- private boolean free = true;
- private boolean isPriorityWorker = false;
- private int id;
- private String message = null;
- private SecurityManager sm;
- PluginStreamHandler streamHandler = null;
- PluginMessageConsumer consumer = null;
-
- public PluginMessageHandlerWorker(
- PluginMessageConsumer consumer,
- PluginStreamHandler streamHandler, int id,
- SecurityManager sm, boolean isPriorityWorker) {
-
- this.id = id;
- this.streamHandler = streamHandler;
- this.sm = sm;
- this.isPriorityWorker = isPriorityWorker;
- this.consumer = consumer;
-
- PluginDebug.debug("Worker " + this.id + " (priority=" + isPriorityWorker + ") created.");
- }
-
- public void setmessage(String message) {
- this.message = message;
- }
-
- public void run() {
- while (true) {
-
- if (message != null) {
-
- PluginDebug.debug("Consumer (priority=" + isPriorityWorker + ") thread " + id + " consuming " + message);
-
- // ideally, whoever returns things object should mark it
- // busy first, but just in case..
- busy();
-
- try {
- streamHandler.handleMessage(message);
- } catch (PluginException pe) {
- /*
- catch the exception and DO NOTHING. The plugin should take over after
- this error and let the user know. We don't quit because otherwise the
- exception will spread to the rest of the applets which is a no-no
- */
- }
-
- this.message = null;
-
- PluginDebug.debug("Consumption (priority=" + isPriorityWorker + ") completed by consumer thread " + id);
-
- // mark ourselves free again
- free();
-
- } else {
-
- // Sleep when there is nothing to do
- try {
- Thread.sleep(Integer.MAX_VALUE);
- PluginDebug.debug("Consumer thread " + id + " sleeping...");
- } catch (InterruptedException ie) {
- PluginDebug.debug("Consumer thread " + id + " woken...");
- // nothing.. someone woke us up, see if there
- // is work to do
- }
- }
- }
- }
-
-
-
- public int getWorkerId() {
- return id;
- }
-
- public void busy() {
- synchronized (this) {
- this.free = false;
+ private boolean free = true;
+ private boolean isPriorityWorker = false;
+ private int id;
+ private String message = null;
+ private SecurityManager sm;
+ PluginStreamHandler streamHandler = null;
+ PluginMessageConsumer consumer = null;
+
+ public PluginMessageHandlerWorker(
+ PluginMessageConsumer consumer,
+ PluginStreamHandler streamHandler, int id,
+ SecurityManager sm, boolean isPriorityWorker) {
+
+ this.id = id;
+ this.streamHandler = streamHandler;
+ this.sm = sm;
+ this.isPriorityWorker = isPriorityWorker;
+ this.consumer = consumer;
+
+ PluginDebug.debug("Worker " + this.id + " (priority=" + isPriorityWorker + ") created.");
+ }
+
+ public void setmessage(String message) {
+ this.message = message;
+ }
+
+ public void run() {
+ while (true) {
+
+ if (message != null) {
+
+ PluginDebug.debug("Consumer (priority=" + isPriorityWorker + ") thread " + id + " consuming " + message);
+
+ // ideally, whoever returns things object should mark it
+ // busy first, but just in case..
+ busy();
+
+ try {
+ streamHandler.handleMessage(message);
+ } catch (PluginException pe) {
+ /*
+ catch the exception and DO NOTHING. The plugin should take over after
+ this error and let the user know. We don't quit because otherwise the
+ exception will spread to the rest of the applets which is a no-no
+ */
+ }
+
+ this.message = null;
+
+ PluginDebug.debug("Consumption (priority=" + isPriorityWorker + ") completed by consumer thread " + id);
+
+ // mark ourselves free again
+ free();
+
+ } else {
+
+ // Sleep when there is nothing to do
+ try {
+ Thread.sleep(Integer.MAX_VALUE);
+ PluginDebug.debug("Consumer thread " + id + " sleeping...");
+ } catch (InterruptedException ie) {
+ PluginDebug.debug("Consumer thread " + id + " woken...");
+ // nothing.. someone woke us up, see if there
+ // is work to do
+ }
+ }
+ }
+ }
+
+ public int getWorkerId() {
+ return id;
+ }
+
+ public void busy() {
+ synchronized (this) {
+ this.free = false;
+ }
+ }
+
+ public void free() {
+ synchronized (this) {
+ this.free = true;
+
+ // Signal the consumer that we are done in case it was waiting
+ consumer.notifyWorkerIsFree(this);
+ }
+ }
+
+ public boolean isPriority() {
+ return isPriorityWorker;
+ }
+
+ public boolean isFree(boolean prioritized) {
+ synchronized (this) {
+ return free && (prioritized == isPriorityWorker);
}
- }
-
- public void free() {
- synchronized (this) {
- this.free = true;
-
- // Signal the consumer that we are done in case it was waiting
- consumer.notifyWorkerIsFree(this);
- }
- }
-
- public boolean isPriority() {
- return isPriorityWorker;
- }
-
- public boolean isFree(boolean prioritized) {
- synchronized (this) {
- return free && (prioritized == isPriorityWorker);
- }
- }
-
- public String toString() {
- return "Worker #" + this.id + "/IsPriority=" + this.isPriorityWorker + "/IsFree=" + this.free + "/Message=" + message;
- }
+ }
+
+ public String toString() {
+ return "Worker #" + this.id + "/IsPriority=" + this.isPriorityWorker + "/IsFree=" + this.free + "/Message=" + message;
+ }
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java
index 9960211..a0c6f6e 100644
--- a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java
+++ b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java
@@ -41,11 +41,10 @@ import java.util.*;
import java.lang.reflect.*;
import java.io.*;
-public class PluginObjectStore
-{
- private static HashMap<Integer, Object> objects = new HashMap<Integer,Object>();
- private static HashMap<Integer, Integer> counts = new HashMap<Integer,Integer>();
- private static HashMap<Object, Integer> identifiers = new HashMap<Object,Integer>();
+public class PluginObjectStore {
+ private static HashMap<Integer, Object> objects = new HashMap<Integer, Object>();
+ private static HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
+ private static HashMap<Object, Integer> identifiers = new HashMap<Object, Integer>();
// FIXME:
//
// IF uniqueID == MAX_LONG, uniqueID =
@@ -73,13 +72,13 @@ public class PluginObjectStore
public boolean contains(Object object) {
if (object == null)
- return identifiers.containsKey(object);
+ return identifiers.containsKey(object);
return false;
}
public boolean contains(int identifier) {
- return objects.containsKey(identifier);
+ return objects.containsKey(identifier);
}
public void reference(Object object) {
@@ -122,11 +121,10 @@ public class PluginObjectStore
}
public void dump() {
- Iterator i = objects.keySet().iterator();
- while (i.hasNext()) {
- Object key = i.next();
- PluginDebug.debug(key + "::" + objects.get(key));
- }
+ Iterator i = objects.keySet().iterator();
+ while (i.hasNext()) {
+ Object key = i.next();
+ PluginDebug.debug(key + "::" + objects.get(key));
+ }
}
}
-
diff --git a/plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java b/plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java
index 674f11d..b6e12d4 100644
--- a/plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java
+++ b/plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java
@@ -45,37 +45,37 @@ import java.net.URI;
*/
public class PluginProxyInfoRequest extends PluginCallRequest {
-
+
URI internal = null;
public PluginProxyInfoRequest(String message, Long reference) {
super(message, reference);
}
-
+
public void parseReturn(String proxyInfo) {
// try to parse the proxy information. If things go wrong, do nothing ..
// this will keep internal = null which forces a direct connection
- PluginDebug.debug ("PluginProxyInfoRequest GOT: " + proxyInfo);
- String[] messageComponents = proxyInfo.split(" ");
+ PluginDebug.debug("PluginProxyInfoRequest GOT: " + proxyInfo);
+ String[] messageComponents = proxyInfo.split(" ");
- try {
- String protocol = messageComponents[4].equals("PROXY") ? "http" : "socks";
- String host = messageComponents[5].split(":")[0];
- int port = Integer.parseInt(messageComponents[5].split(":")[1]);
+ try {
+ String protocol = messageComponents[4].equals("PROXY") ? "http" : "socks";
+ String host = messageComponents[5].split(":")[0];
+ int port = Integer.parseInt(messageComponents[5].split(":")[1]);
- internal = new URI(protocol, null, host, port, null, null, null);
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- // Nothing.. this is expected if there is no proxy
- } catch (Exception e) {
- e.printStackTrace();
- }
+ internal = new URI(protocol, null, host, port, null, null, null);
+ } catch (ArrayIndexOutOfBoundsException aioobe) {
+ // Nothing.. this is expected if there is no proxy
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
setDone(true);
}
public URI getObject() {
- return this.internal;
+ return this.internal;
}
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java
index 36236ba..dc716f7 100644
--- a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java
+++ b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java
@@ -138,7 +138,7 @@ public class PluginProxySelector extends JNLPProxySelector {
* @param <V> The Object type
*/
- private class TimedHashMap<K,V> extends HashMap<K,V> {
+ private class TimedHashMap<K, V> extends HashMap<K, V> {
HashMap<K, Long> timeStamps = new HashMap<K, Long>();
Long expiry = 10000L;
@@ -176,7 +176,7 @@ public class PluginProxySelector extends JNLPProxySelector {
timeStamps.put((K) key, (new Date()).getTime());
return super.get(key);
} else {
- PluginDebug.debug("Proxy cache for " + key + " has expired (age=" + age/1000.0 + " seconds)");
+ PluginDebug.debug("Proxy cache for " + key + " has expired (age=" + age / 1000.0 + " seconds)");
}
}
diff --git a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java
index eb5b11a..bd95493 100644
--- a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java
+++ b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java
@@ -35,7 +35,6 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
import java.io.BufferedReader;
@@ -54,234 +53,232 @@ import java.util.LinkedList;
import javax.swing.SwingUtilities;
-
public class PluginStreamHandler {
private BufferedReader pluginInputReader;
private StreamTokenizer pluginInputTokenizer;
private BufferedWriter pluginOutputWriter;
-
+
private RequestQueue queue = new RequestQueue();
-
+
private JavaConsole console = new JavaConsole();
- LinkedList<String> writeQueue = new LinkedList<String>();
-
- PluginMessageConsumer consumer;
- Boolean shuttingDown = false;
-
- PluginAppletViewer pav;
-
- static Date d = new Date();
- static long startTime = d.getTime();
- static long totalWait = 0;
-
+ LinkedList<String> writeQueue = new LinkedList<String>();
+
+ PluginMessageConsumer consumer;
+ Boolean shuttingDown = false;
+
+ PluginAppletViewer pav;
+
+ static Date d = new Date();
+ static long startTime = d.getTime();
+ static long totalWait = 0;
+
public PluginStreamHandler(InputStream inputstream, OutputStream outputstream)
- throws MalformedURLException, IOException
- {
-
- PluginDebug.debug("Current context CL=" + Thread.currentThread().getContextClassLoader());
- try {
- pav = (PluginAppletViewer) ClassLoader.getSystemClassLoader().loadClass("sun.applet.PluginAppletViewer").newInstance();
- PluginDebug.debug("Loaded: " + pav + " CL=" + pav.getClass().getClassLoader());
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- PluginDebug.debug("Creating consumer...");
- consumer = new PluginMessageConsumer(this);
-
- // Set up input and output pipes. Use UTF-8 encoding.
- pluginInputReader =
- new BufferedReader(new InputStreamReader(inputstream,
- Charset.forName("UTF-8")));
- /*pluginInputTokenizer = new StreamTokenizer(pluginInputReader);
- pluginInputTokenizer.resetSyntax();
- pluginInputTokenizer.whitespaceChars('\u0000', '\u0000');
- pluginInputTokenizer.wordChars('\u0001', '\u00FF');*/
- pluginOutputWriter =
- new BufferedWriter(new OutputStreamWriter
- (outputstream, Charset.forName("UTF-8")));
-
- /*
- while(true) {
+ throws MalformedURLException, IOException {
+
+ PluginDebug.debug("Current context CL=" + Thread.currentThread().getContextClassLoader());
+ try {
+ pav = (PluginAppletViewer) ClassLoader.getSystemClassLoader().loadClass("sun.applet.PluginAppletViewer").newInstance();
+ PluginDebug.debug("Loaded: " + pav + " CL=" + pav.getClass().getClassLoader());
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ PluginDebug.debug("Creating consumer...");
+ consumer = new PluginMessageConsumer(this);
+
+ // Set up input and output pipes. Use UTF-8 encoding.
+ pluginInputReader =
+ new BufferedReader(new InputStreamReader(inputstream,
+ Charset.forName("UTF-8")));
+ /*pluginInputTokenizer = new StreamTokenizer(pluginInputReader);
+ pluginInputTokenizer.resetSyntax();
+ pluginInputTokenizer.whitespaceChars('\u0000', '\u0000');
+ pluginInputTokenizer.wordChars('\u0001', '\u00FF');*/
+ pluginOutputWriter =
+ new BufferedWriter(new OutputStreamWriter
+ (outputstream, Charset.forName("UTF-8")));
+
+ /*
+ while(true) {
String message = read();
PluginDebug.debug(message);
handleMessage(message);
// TODO:
// write(queue.peek());
- }
- */
+ }
+ */
}
public void startProcessing() {
- Thread listenerThread = new Thread() {
-
- public void run() {
-
- while (true) {
-
- PluginDebug.debug("Waiting for data...");
-
- long b4 = new Date().getTime();
-
- String s = read();
-
- long after = new Date().getTime();
-
- totalWait += (after - b4);
- //System.err.println("Total wait time: " + totalWait);
-
- if (s != null) {
- consumer.queue(s);
- } else {
- try {
- // Close input/output channels to plugin.
- pluginInputReader.close();
- pluginOutputWriter.close();
- } catch (IOException exception) {
- // Deliberately ignore IOException caused by broken
- // pipe since plugin may have already detached.
- }
- AppletSecurityContextManager.dumpStore(0);
- PluginDebug.debug("APPLETVIEWER: exiting appletviewer");
- System.exit(0);
- }
-
-/*
- int readChar = -1;
- // blocking read, discard first character
- try {
- readChar = pluginInputReader.read();
- } catch (IOException ioe) {
- // plugin may have detached
- }
-
- // if not disconnected
- if (readChar != -1) {
- String s = read();
- PluginDebug.debug("Got data, consuming " + s);
- consumer.consume(s);
- } else {
- try {
- // Close input/output channels to plugin.
- pluginInputReader.close();
- pluginOutputWriter.close();
- } catch (IOException exception) {
- // Deliberately ignore IOException caused by broken
- // pipe since plugin may have already detached.
- }
- AppletSecurityContextManager.dumpStore(0);
- PluginDebug.debug("APPLETVIEWER: exiting appletviewer");
- System.exit(0);
- }
-*/
- }
- }
- };
-
- listenerThread.start();
+ Thread listenerThread = new Thread() {
+
+ public void run() {
+
+ while (true) {
+
+ PluginDebug.debug("Waiting for data...");
+
+ long b4 = new Date().getTime();
+
+ String s = read();
+
+ long after = new Date().getTime();
+
+ totalWait += (after - b4);
+ //System.err.println("Total wait time: " + totalWait);
+
+ if (s != null) {
+ consumer.queue(s);
+ } else {
+ try {
+ // Close input/output channels to plugin.
+ pluginInputReader.close();
+ pluginOutputWriter.close();
+ } catch (IOException exception) {
+ // Deliberately ignore IOException caused by broken
+ // pipe since plugin may have already detached.
+ }
+ AppletSecurityContextManager.dumpStore(0);
+ PluginDebug.debug("APPLETVIEWER: exiting appletviewer");
+ System.exit(0);
+ }
+
+ /*
+ int readChar = -1;
+ // blocking read, discard first character
+ try {
+ readChar = pluginInputReader.read();
+ } catch (IOException ioe) {
+ // plugin may have detached
+ }
+
+ // if not disconnected
+ if (readChar != -1) {
+ String s = read();
+ PluginDebug.debug("Got data, consuming " + s);
+ consumer.consume(s);
+ } else {
+ try {
+ // Close input/output channels to plugin.
+ pluginInputReader.close();
+ pluginOutputWriter.close();
+ } catch (IOException exception) {
+ // Deliberately ignore IOException caused by broken
+ // pipe since plugin may have already detached.
+ }
+ AppletSecurityContextManager.dumpStore(0);
+ PluginDebug.debug("APPLETVIEWER: exiting appletviewer");
+ System.exit(0);
+ }
+ */
+ }
+ }
+ };
+
+ listenerThread.start();
}
-
+
public void handleMessage(String message) throws PluginException {
- int nextIndex = 0;
- int reference = -1;
- String src = null;
- String[] privileges = null;
- String rest = "";
+ int nextIndex = 0;
+ int reference = -1;
+ String src = null;
+ String[] privileges = null;
+ String rest = "";
+
+ String[] msgComponents = message.split(" ");
- String[] msgComponents = message.split(" ");
-
- if (msgComponents.length < 2)
- return;
+ if (msgComponents.length < 2)
+ return;
if (msgComponents[0].startsWith("plugin")) {
handlePluginMessage(message);
return;
}
- // type and identifier are guaranteed to be there
- String type = msgComponents[0];
- final int identifier = Integer.parseInt(msgComponents[1]);
- nextIndex = 2;
-
- // reference, src and privileges are optional components,
- // and are guaranteed to be in that order, if they occur
-
- // is there a reference ?
- if (msgComponents[nextIndex].equals("reference")) {
- reference = Integer.parseInt(msgComponents[nextIndex+1]);
- nextIndex += 2;
- }
-
- // is there a src?
- if (msgComponents[nextIndex].equals("src")) {
- src = msgComponents[nextIndex+1];
- nextIndex += 2;
- }
-
- // is there a privileges?
- if (msgComponents[nextIndex].equals("privileges")) {
- String privs = msgComponents[nextIndex+1];
- privileges = privs.split(",");
- nextIndex += 2;
- }
-
- // rest
- for (int i=nextIndex; i < msgComponents.length; i++) {
- rest += msgComponents[i];
- rest += " ";
- }
-
- rest = rest.trim();
-
- try {
-
- PluginDebug.debug("Breakdown -- type: " + type + " identifier: " + identifier + " reference: " + reference + " src: " + src + " privileges: " + privileges + " rest: \"" + rest + "\"");
-
- if (rest.contains("JavaScriptGetWindow")
- || rest.contains("JavaScriptGetMember")
- || rest.contains("JavaScriptSetMember")
- || rest.contains("JavaScriptGetSlot")
- || rest.contains("JavaScriptSetSlot")
- || rest.contains("JavaScriptEval")
- || rest.contains("JavaScriptRemoveMember")
- || rest.contains("JavaScriptCall")
- || rest.contains("JavaScriptFinalize")
- || rest.contains("JavaScriptToString")) {
-
- finishCallRequest("reference " + reference + " " + rest);
- return;
- }
-
- final int freference = reference;
- final String frest = rest;
-
- if (type.equals("instance")) {
- PluginAppletViewer.handleMessage(identifier, freference,frest);
- } else if (type.equals("context")) {
- PluginDebug.debug("Sending to PASC: " + identifier + "/" + reference + " and " + rest);
- AppletSecurityContextManager.handleMessage(identifier, reference, src, privileges, rest);
- }
- } catch (Exception e) {
- throw new PluginException(this, identifier, reference, e);
- }
+ // type and identifier are guaranteed to be there
+ String type = msgComponents[0];
+ final int identifier = Integer.parseInt(msgComponents[1]);
+ nextIndex = 2;
+
+ // reference, src and privileges are optional components,
+ // and are guaranteed to be in that order, if they occur
+
+ // is there a reference ?
+ if (msgComponents[nextIndex].equals("reference")) {
+ reference = Integer.parseInt(msgComponents[nextIndex + 1]);
+ nextIndex += 2;
+ }
+
+ // is there a src?
+ if (msgComponents[nextIndex].equals("src")) {
+ src = msgComponents[nextIndex + 1];
+ nextIndex += 2;
+ }
+
+ // is there a privileges?
+ if (msgComponents[nextIndex].equals("privileges")) {
+ String privs = msgComponents[nextIndex + 1];
+ privileges = privs.split(",");
+ nextIndex += 2;
+ }
+
+ // rest
+ for (int i = nextIndex; i < msgComponents.length; i++) {
+ rest += msgComponents[i];
+ rest += " ";
+ }
+
+ rest = rest.trim();
+
+ try {
+
+ PluginDebug.debug("Breakdown -- type: " + type + " identifier: " + identifier + " reference: " + reference + " src: " + src + " privileges: " + privileges + " rest: \"" + rest + "\"");
+
+ if (rest.contains("JavaScriptGetWindow")
+ || rest.contains("JavaScriptGetMember")
+ || rest.contains("JavaScriptSetMember")
+ || rest.contains("JavaScriptGetSlot")
+ || rest.contains("JavaScriptSetSlot")
+ || rest.contains("JavaScriptEval")
+ || rest.contains("JavaScriptRemoveMember")
+ || rest.contains("JavaScriptCall")
+ || rest.contains("JavaScriptFinalize")
+ || rest.contains("JavaScriptToString")) {
+
+ finishCallRequest("reference " + reference + " " + rest);
+ return;
+ }
+
+ final int freference = reference;
+ final String frest = rest;
+
+ if (type.equals("instance")) {
+ PluginAppletViewer.handleMessage(identifier, freference, frest);
+ } else if (type.equals("context")) {
+ PluginDebug.debug("Sending to PASC: " + identifier + "/" + reference + " and " + rest);
+ AppletSecurityContextManager.handleMessage(identifier, reference, src, privileges, rest);
+ }
+ } catch (Exception e) {
+ throw new PluginException(this, identifier, reference, e);
+ }
}
private void handlePluginMessage(String message) {
if (message.equals("plugin showconsole")) {
showConsole();
} else if (message.equals("plugin hideconsole")) {
- hideConsole();
+ hideConsole();
} else {
// else this is something that was specifically requested
finishCallRequest(message);
@@ -289,60 +286,60 @@ public class PluginStreamHandler {
}
public void postCallRequest(PluginCallRequest request) {
- synchronized(queue) {
- queue.post(request);
+ synchronized (queue) {
+ queue.post(request);
}
}
private void finishCallRequest(String message) {
- PluginDebug.debug ("DISPATCHCALLREQUESTS 1");
- synchronized(queue) {
- PluginDebug.debug ("DISPATCHCALLREQUESTS 2");
- PluginCallRequest request = queue.pop();
-
- // make sure we give the message to the right request
- // in the queue.. for the love of God, MAKE SURE!
-
- // first let's be efficient.. if there was only one
- // request in queue, we're already set
- if (queue.size() != 0) {
-
- int size = queue.size();
- int count = 0;
-
- while (!request.serviceable(message)) {
-
- PluginDebug.debug(request + " cannot service " + message);
-
- // something is very wrong.. we have a message to
- // process, but no one to service it
- if (count >= size) {
- throw new RuntimeException("Unable to find processor for message " + message);
- }
-
- // post request at the end of the queue
- queue.post(request);
-
- // Look at the next request
- request = queue.pop();
-
- count++;
- }
-
- }
-
- PluginDebug.debug ("DISPATCHCALLREQUESTS 3");
- if (request != null) {
- PluginDebug.debug ("DISPATCHCALLREQUESTS 5");
- synchronized(request) {
- request.parseReturn(message);
- request.notifyAll();
- }
- PluginDebug.debug ("DISPATCHCALLREQUESTS 6");
- PluginDebug.debug ("DISPATCHCALLREQUESTS 7");
- }
- }
- PluginDebug.debug ("DISPATCHCALLREQUESTS 8");
+ PluginDebug.debug("DISPATCHCALLREQUESTS 1");
+ synchronized (queue) {
+ PluginDebug.debug("DISPATCHCALLREQUESTS 2");
+ PluginCallRequest request = queue.pop();
+
+ // make sure we give the message to the right request
+ // in the queue.. for the love of God, MAKE SURE!
+
+ // first let's be efficient.. if there was only one
+ // request in queue, we're already set
+ if (queue.size() != 0) {
+
+ int size = queue.size();
+ int count = 0;
+
+ while (!request.serviceable(message)) {
+
+ PluginDebug.debug(request + " cannot service " + message);
+
+ // something is very wrong.. we have a message to
+ // process, but no one to service it
+ if (count >= size) {
+ throw new RuntimeException("Unable to find processor for message " + message);
+ }
+
+ // post request at the end of the queue
+ queue.post(request);
+
+ // Look at the next request
+ request = queue.pop();
+
+ count++;
+ }
+
+ }
+
+ PluginDebug.debug("DISPATCHCALLREQUESTS 3");
+ if (request != null) {
+ PluginDebug.debug("DISPATCHCALLREQUESTS 5");
+ synchronized (request) {
+ request.parseReturn(message);
+ request.notifyAll();
+ }
+ PluginDebug.debug("DISPATCHCALLREQUESTS 6");
+ PluginDebug.debug("DISPATCHCALLREQUESTS 7");
+ }
+ }
+ PluginDebug.debug("DISPATCHCALLREQUESTS 8");
}
/**
@@ -352,16 +349,15 @@ public class PluginStreamHandler {
*
* @exception IOException if an error occurs
*/
- private String read()
- {
- String message = null;
+ private String read() {
+ String message = null;
- try {
- message = pluginInputReader.readLine();
- PluginDebug.debug(" PIPE: appletviewer read: " + message);
+ try {
+ message = pluginInputReader.readLine();
+ PluginDebug.debug(" PIPE: appletviewer read: " + message);
if (message == null || message.equals("shutdown")) {
- synchronized(shuttingDown) {
+ synchronized (shuttingDown) {
shuttingDown = true;
}
try {
@@ -376,13 +372,13 @@ public class PluginStreamHandler {
PluginDebug.debug("APPLETVIEWER: exiting appletviewer");
System.exit(0);
}
- } catch (IOException e) {
- e.printStackTrace();
- }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- return message;
+ return message;
}
-
+
/**
* Write string to plugin.
*
@@ -390,52 +386,51 @@ public class PluginStreamHandler {
*
* @exception IOException if an error occurs
*/
- public void write(String message)
- {
-
- PluginDebug.debug(" PIPE: appletviewer wrote: " + message);
- synchronized(pluginOutputWriter) {
- try {
- pluginOutputWriter.write(message + "\n", 0, message.length());
- pluginOutputWriter.write(0);
- pluginOutputWriter.flush();
- } catch (IOException e) {
- // if we are shutting down, ignore write failures as
- // pipe may have closed
- synchronized(shuttingDown) {
- if (!shuttingDown) {
- e.printStackTrace();
- }
- }
-
- // either ways, if the pipe is broken, there is nothing
- // we can do anymore. Don't hang around.
- PluginDebug.debug("Unable to write to PIPE. APPLETVIEWER exiting");
- System.exit(1);
- }
- }
+ public void write(String message) {
+
+ PluginDebug.debug(" PIPE: appletviewer wrote: " + message);
+ synchronized (pluginOutputWriter) {
+ try {
+ pluginOutputWriter.write(message + "\n", 0, message.length());
+ pluginOutputWriter.write(0);
+ pluginOutputWriter.flush();
+ } catch (IOException e) {
+ // if we are shutting down, ignore write failures as
+ // pipe may have closed
+ synchronized (shuttingDown) {
+ if (!shuttingDown) {
+ e.printStackTrace();
+ }
+ }
+
+ // either ways, if the pipe is broken, there is nothing
+ // we can do anymore. Don't hang around.
+ PluginDebug.debug("Unable to write to PIPE. APPLETVIEWER exiting");
+ System.exit(1);
+ }
+ }
- return;
- /*
- synchronized(writeQueue) {
- writeQueue.add(message);
- PluginDebug.debug(" PIPE: appletviewer wrote: " + message);
- }
- */
+ return;
+ /*
+ synchronized(writeQueue) {
+ writeQueue.add(message);
+ PluginDebug.debug(" PIPE: appletviewer wrote: " + message);
+ }
+ */
}
public boolean messageAvailable() {
- return writeQueue.size() != 0;
+ return writeQueue.size() != 0;
}
public String getMessage() {
- synchronized(writeQueue) {
- String ret = writeQueue.size() > 0 ? writeQueue.poll() : "";
- return ret;
- }
+ synchronized (writeQueue) {
+ String ret = writeQueue.size() > 0 ? writeQueue.poll() : "";
+ return ret;
+ }
}
-
+
private void showConsole() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
@@ -443,7 +438,7 @@ public class PluginStreamHandler {
}
});
}
-
+
private void hideConsole() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
diff --git a/plugin/icedteanp/java/sun/applet/RequestQueue.java b/plugin/icedteanp/java/sun/applet/RequestQueue.java
index 87dc54f..17df673 100644
--- a/plugin/icedteanp/java/sun/applet/RequestQueue.java
+++ b/plugin/icedteanp/java/sun/applet/RequestQueue.java
@@ -35,17 +35,15 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package sun.applet;
-
public class RequestQueue {
PluginCallRequest head = null;
PluginCallRequest tail = null;
private int size = 0;
public void post(PluginCallRequest request) {
- PluginDebug.debug("Securitymanager=" + System.getSecurityManager());
+ PluginDebug.debug("Securitymanager=" + System.getSecurityManager());
if (head == null) {
head = tail = request;
tail.setNext(null);
@@ -54,7 +52,7 @@ public class RequestQueue {
tail = request;
tail.setNext(null);
}
-
+
size++;
}
@@ -67,11 +65,11 @@ public class RequestQueue {
ret.setNext(null);
size--;
-
+
return ret;
}
-
+
public int size() {
- return size;
+ return size;
}
}
diff --git a/plugin/icedteanp/java/sun/applet/TestEnv.java b/plugin/icedteanp/java/sun/applet/TestEnv.java
index 08b74ce..0e4ac3d 100644
--- a/plugin/icedteanp/java/sun/applet/TestEnv.java
+++ b/plugin/icedteanp/java/sun/applet/TestEnv.java
@@ -37,8 +37,7 @@ exception statement from your version. */
package sun.applet;
-public class TestEnv
-{
+public class TestEnv {
public static int intField = 103;
public int intInstanceField = 7822;
public String stringField = "hello";
@@ -92,20 +91,20 @@ public class TestEnv
public static void TestItIntArray(int[] arg) {
PluginDebug.debug("TestItIntArray: " + arg);
for (int i = 0; i < arg.length; i++)
- PluginDebug.debug ("ELEMENT: " + i + " " + arg[i]);
+ PluginDebug.debug("ELEMENT: " + i + " " + arg[i]);
}
public static void TestItObjectArray(String[] arg) {
PluginDebug.debug("TestItObjectArray: " + arg);
for (int i = 0; i < arg.length; i++)
- PluginDebug.debug ("ELEMENT: " + i + " " + arg[i]);
+ PluginDebug.debug("ELEMENT: " + i + " " + arg[i]);
}
public static void TestItObjectArrayMulti(String[][] arg) {
PluginDebug.debug("TestItObjectArrayMulti: " + arg);
for (int i = 0; i < arg.length; i++)
for (int j = 0; j < arg[i].length; j++)
- PluginDebug.debug ("ELEMENT: " + i + " " + j + " " + arg[i][j]);
+ PluginDebug.debug("ELEMENT: " + i + " " + j + " " + arg[i][j]);
}
public static boolean TestItBoolReturnTrue() {
@@ -161,8 +160,8 @@ public class TestEnv
}
public static String[][] TestItObjectArrayMultiReturn() {
- return new String[][] { {"Thomas", "Brigitte"},
- {"Lindsay", "Michael"} };
+ return new String[][] { { "Thomas", "Brigitte" },
+ { "Lindsay", "Michael" } };
}
public int TestItIntInstance(int arg) {
diff --git a/plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java b/plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java
index 0bacc6c..71687d2 100644
--- a/plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java
+++ b/plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java
@@ -37,18 +37,17 @@ exception statement from your version. */
package sun.applet;
-
public class VoidPluginCallRequest extends PluginCallRequest {
public VoidPluginCallRequest(String message, Long reference) {
super(message, reference);
- PluginDebug.debug ("VoidPluginCall " + message);
+ PluginDebug.debug("VoidPluginCall " + message);
}
public void parseReturn(String message) {
- setDone(true);
+ setDone(true);
}
-
+
public Object getObject() {
- return null;
+ return null;
}
}