aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java')
-rw-r--r--plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java220
1 files changed, 135 insertions, 85 deletions
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
index 2fc42d8..3686419 100644
--- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
@@ -68,7 +68,7 @@ import netscape.javascript.JSUtil;
class Signature {
private String signature;
private int currentIndex;
- private List<Class> typeList;
+ private List<Class<?>> typeList;
private static final char ARRAY = '[';
private static final char OBJECT = 'L';
private static final char SIGNATURE_ENDCLASS = ';';
@@ -136,18 +136,20 @@ class Signature {
public Signature(String signature, ClassLoader cl) {
this.signature = signature;
currentIndex = 0;
- typeList = new ArrayList<Class>(10);
+ typeList = new ArrayList<Class<?>>(10);
String elem;
while (currentIndex < signature.length()) {
elem = nextTypeName();
- if (elem == null) // end of signature
+ if (elem == null) {
continue;
+ }
- Class primitive = primitiveNameToType(elem);
- if (primitive != null)
+ Class<?> primitive = primitiveNameToType(elem);
+ if (primitive != null) {
typeList.add(primitive);
+ }
else {
int dimsize = 0;
int n = elem.indexOf('[');
@@ -164,9 +166,10 @@ class Signature {
if (primitive != null) {
typeList.add(Array.newInstance(primitive, dims)
.getClass());
- } else
+ } else {
typeList.add(Array.newInstance(
getClass(arrayType, cl), dims).getClass());
+ }
} else {
typeList.add(getClass(elem, cl));
}
@@ -178,9 +181,9 @@ class Signature {
}
}
- public static Class getClass(String name, ClassLoader cl) {
+ public static Class<?> getClass(String name, ClassLoader cl) {
- Class c = null;
+ Class<?> c = null;
try {
c = Class.forName(name);
@@ -197,31 +200,41 @@ class Signature {
return c;
}
- public static Class primitiveNameToType(String name) {
- if (name.equals("void"))
+ public static Class<?> primitiveNameToType(String name) {
+ if (name.equals("void")) {
return Void.TYPE;
- else if (name.equals("boolean"))
+ }
+ else if (name.equals("boolean")) {
return Boolean.TYPE;
- else if (name.equals("byte"))
+ }
+ else if (name.equals("byte")) {
return Byte.TYPE;
- else if (name.equals("char"))
+ }
+ else if (name.equals("char")) {
return Character.TYPE;
- else if (name.equals("short"))
+ }
+ else if (name.equals("short")) {
return Short.TYPE;
- else if (name.equals("int"))
+ }
+ else if (name.equals("int")) {
return Integer.TYPE;
- else if (name.equals("long"))
+ }
+ else if (name.equals("long")) {
return Long.TYPE;
- else if (name.equals("float"))
+ }
+ else if (name.equals("float")) {
return Float.TYPE;
- else if (name.equals("double"))
+ }
+ else if (name.equals("double")) {
return Double.TYPE;
- else
+ }
+ else {
return null;
+ }
}
- public Class[] getClassArray() {
- return typeList.subList(0, typeList.size()).toArray(new Class[] {});
+ public Class<?>[] getClassArray() {
+ return typeList.subList(0, typeList.size()).toArray(new Class<?>[] {});
}
}
@@ -264,7 +277,7 @@ public class PluginAppletSecurityContext {
OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e);
}
- this.classLoaders.put(liveconnectLoader, u);
+ PluginAppletSecurityContext.classLoaders.put(liveconnectLoader, u);
}
public PluginAppletSecurityContext(int identifier) {
@@ -272,49 +285,61 @@ public class PluginAppletSecurityContext {
}
private static <V> V parseCall(String s, ClassLoader cl, Class<V> c) {
- if (c == Integer.class)
+ 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)
+ }
+ else if (c == String.class) {
+ return c.cast(s);
+ }
+ else if (c == Signature.class) {
return c.cast(new Signature(s, cl));
- else
+ }
+ else {
throw new RuntimeException("Unexpected call value.");
+ }
}
- 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)
+ private Object parseArgs(String s, Class<?> c) {
+ if (c == Boolean.TYPE || c == Boolean.class) {
+ return Boolean.valueOf(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)
+ } else if (c == Short.TYPE || c == Short.class) {
return new Short(s);
- else if (c == Integer.TYPE || c == Integer.class)
+ }
+ else if (c == Integer.TYPE || c == Integer.class) {
return new Integer(s);
- else if (c == Long.TYPE || c == Long.class)
+ }
+ else if (c == Long.TYPE || c == Long.class) {
return new Long(s);
- else if (c == Float.TYPE || c == Float.class)
+ }
+ else if (c == Float.TYPE || c == Float.class) {
return new Float(s);
- else if (c == Double.TYPE || c == Double.class)
+ }
+ else if (c == Double.TYPE || c == Double.class) {
return new Double(s);
- else
+ }
+ 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);
+ PluginAppletSecurityContext.classLoaders.put(cl, src);
}
public void associateInstance(Integer i, ClassLoader cl) {
PluginDebug.debug("Associating ", cl, " with instance ", i);
- this.instanceClassLoaders.put(i, cl);
+ PluginAppletSecurityContext.instanceClassLoaders.put(i, cl);
}
public static void setStreamhandler(PluginStreamHandler sh) {
@@ -337,6 +362,7 @@ public class PluginAppletSecurityContext {
private static long privilegedJSObjectUnbox(final JSObject js) {
return AccessController.doPrivileged(new PrivilegedAction<Long>() {
+ @Override
public Long run() {
return JSUtil.getJSObjectInternalReference(js);
}
@@ -418,8 +444,8 @@ public class PluginAppletSecurityContext {
try {
if (message.startsWith("FindClass")) {
- ClassLoader cl = null;
- Class c = null;
+ ClassLoader cl;
+ Class<?> c;
cl = liveconnectLoader;
String[] args = message.split(" ");
Integer instance = new Integer(args[1]);
@@ -432,7 +458,7 @@ public class PluginAppletSecurityContext {
write(reference, "FindClass " + store.getIdentifier(c));
} catch (ClassNotFoundException cnfe) {
- cl = this.instanceClassLoaders.get(instance);
+ cl = PluginAppletSecurityContext.instanceClassLoaders.get(instance);
PluginDebug.debug("Not found. Looking in ", cl);
if (instance != 0 && cl != null) {
@@ -460,14 +486,16 @@ public class PluginAppletSecurityContext {
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;
+ methodName.equals("<clinit>")) {
+ c = (Class<?>) store.getObject(classID);
+ }
+ else {
+ c = store.getObject(classID).getClass();
+ }
+
+ Method m;
+ Constructor<?> cs;
+ Object o;
if (methodName.equals("<init>")
|| methodName.equals("<clinit>")) {
o = cs = c.getConstructor(signature.getClassArray());
@@ -489,7 +517,7 @@ public class PluginAppletSecurityContext {
PluginDebug.debug("GetStaticFieldID/GetFieldID got class=", c.getName());
- Field f = null;
+ Field f;
f = c.getField(fieldName);
store.reference(f);
@@ -508,6 +536,7 @@ public class PluginAppletSecurityContext {
checkPermission(src, c, acc);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
return f.get(c);
@@ -517,8 +546,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
String objIDStr = toObjectIDString(ret, f.getType(), false /*do not unbox primitives*/);
write(reference, "GetStaticField " + objIDStr);
@@ -547,6 +577,7 @@ public class PluginAppletSecurityContext {
checkPermission(src, message.startsWith("SetStaticField") ? (Class) o : o.getClass(), acc);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
f.set(o, fValue);
@@ -558,8 +589,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
write(reference, "SetField");
} else if (message.startsWith("GetObjectArrayElement")) {
@@ -610,6 +642,7 @@ public class PluginAppletSecurityContext {
checkPermission(src, o.getClass(), acc);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
return f.get(o);
@@ -619,8 +652,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
String objIDStr = toObjectIDString(ret, f.getType(), false /*do not unbox primitives*/);
write(reference, "GetField " + objIDStr);
@@ -676,6 +710,7 @@ public class PluginAppletSecurityContext {
// http://forums.sun.com/thread.jspa?threadID=332001&start=15&tstart=0
m.setAccessible(true);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
return m.invoke(callableObject, fArguments);
@@ -685,8 +720,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
String retO;
if (ret == null) {
@@ -704,8 +740,8 @@ public class PluginAppletSecurityContext {
} else if (message.startsWith("GetSuperclass")) {
String[] args = message.split(" ");
Integer classID = parseCall(args[1], null, Integer.class);
- Class<?> c = null;
- Class<?> ret = null;
+ Class<?> c;
+ Class<?> ret;
c = (Class) store.getObject(classID);
ret = c.getSuperclass();
@@ -740,7 +776,7 @@ public class PluginAppletSecurityContext {
String[] args = message.split(" ");
Integer stringID = parseCall(args[1], null, Integer.class);
- String o = null;
+ String o;
byte[] b = null;
o = (String) store.getObject(stringID);
b = o.getBytes("UTF-8");
@@ -750,7 +786,7 @@ public class PluginAppletSecurityContext {
String[] args = message.split(" ");
Integer stringID = parseCall(args[1], null, Integer.class);
- String o = null;
+ String o;
byte[] b = null;
o = (String) store.getObject(stringID);
b = o.getBytes("UTF-16LE");
@@ -760,22 +796,23 @@ public class PluginAppletSecurityContext {
String[] args = message.split(" ");
Integer stringID = parseCall(args[1], null, Integer.class);
- String o = null;
+ String o;
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++)
+ for (int i = 0; i < b.length; i++) {
buf.append(" " + Integer.toString(((int) b[i]) & 0x0ff, 16));
+ }
write(reference, "GetStringUTFChars " + buf);
} else if (message.startsWith("GetStringChars")) {
String[] args = message.split(" ");
Integer stringID = parseCall(args[1], null, Integer.class);
- String o = null;
+ String o;
byte[] b = null;
StringBuffer buf = null;
o = (String) store.getObject(stringID);
@@ -783,8 +820,9 @@ public class PluginAppletSecurityContext {
b = o.getBytes("UTF-16LE");
buf = new StringBuffer(b.length * 2);
buf.append(b.length);
- for (int i = 0; i < b.length; i++)
+ 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);
@@ -793,15 +831,16 @@ public class PluginAppletSecurityContext {
String[] args = message.split(" ");
Integer objectID = parseCall(args[1], null, Integer.class);
- String o = null;
+ String o;
byte[] b = null;
StringBuffer buf = null;
o = store.getObject(objectID).toString();
b = o.getBytes("UTF-8");
buf = new StringBuffer(b.length * 2);
buf.append(b.length);
- for (int i = 0; i < b.length; i++)
+ for (int i = 0; i < b.length; i++) {
buf.append(" " + Integer.toString(((int) b[i]) & 0x0ff, 16));
+ }
write(reference, "GetToStringValue " + buf);
} else if (message.startsWith("NewArray")) {
@@ -809,9 +848,9 @@ public class PluginAppletSecurityContext {
String type = parseCall(args[1], null, String.class);
Integer length = parseCall(args[2], null, Integer.class);
- Object newArray = null;
+ Object newArray;
- Class c;
+ Class<?> c;
if (type.equals("bool")) {
c = Boolean.class;
} else if (type.equals("double")) {
@@ -826,10 +865,12 @@ public class PluginAppletSecurityContext {
c = JSObject.class;
}
- if (args.length > 3)
+ if (args.length > 3) {
newArray = Array.newInstance(c, new int[] { length, parseCall(args[3], null, Integer.class) });
- else
+ }
+ else {
newArray = Array.newInstance(c, length);
+ }
store.reference(newArray);
write(reference, "NewArray " + store.getIdentifier(newArray));
@@ -838,7 +879,7 @@ public class PluginAppletSecurityContext {
Integer classNameID = parseCall(args[1], null, Integer.class);
Integer methodNameID = parseCall(args[2], null, Integer.class);
- Class c = (Class<?>) store.getObject(classNameID);
+ Class<?> c = (Class<?>) store.getObject(classNameID);
String methodName = (String) store.getObject(methodNameID);
Method method = null;
@@ -869,7 +910,7 @@ public class PluginAppletSecurityContext {
Integer classNameID = parseCall(args[1], null, Integer.class);
Integer fieldNameID = parseCall(args[2], null, Integer.class);
- Class c = (Class) store.getObject(classNameID);
+ Class<?> c = (Class<?>) store.getObject(classNameID);
String fieldName = (String) store.getObject(fieldNameID);
Field field = null;
@@ -890,13 +931,14 @@ public class PluginAppletSecurityContext {
Integer classID = parseCall(args[2], null, Integer.class);
Integer objectID = parseCall(args[3], null, Integer.class);
- Object newArray = null;
+ Object newArray;
newArray = Array.newInstance((Class) store.getObject(classID),
length);
Object[] array = (Object[]) newArray;
- for (int i = 0; i < array.length; i++)
+ for (int i = 0; i < array.length; i++) {
array[i] = store.getObject(objectID);
+ }
store.reference(newArray);
write(reference, "NewObjectArray "
+ store.getIdentifier(newArray));
@@ -906,7 +948,7 @@ public class PluginAppletSecurityContext {
Integer classID = parseCall(args[1], null, Integer.class);
Integer methodID = parseCall(args[2], null, Integer.class);
- final Constructor m = (Constructor) store.getObject(methodID);
+ final Constructor<?> m = (Constructor<?>) store.getObject(methodID);
Class[] argTypes = m.getParameterTypes();
Object[] arguments = new Object[argTypes.length];
@@ -917,10 +959,11 @@ public class PluginAppletSecurityContext {
final Object[] fArguments = arguments;
AccessControlContext acc = callContext != null ? callContext : getClosedAccessControlContext();
- Class c = (Class) store.getObject(classID);
+ Class<?> c = (Class<?>) store.getObject(classID);
checkPermission(src, c, acc);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
return m.newInstance(fArguments);
@@ -930,8 +973,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
store.reference(ret);
@@ -969,6 +1013,7 @@ public class PluginAppletSecurityContext {
checkPermission(src, c, acc);
Object ret = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
try {
return cons.newInstance(castedArgs);
@@ -978,8 +1023,9 @@ public class PluginAppletSecurityContext {
}
}, acc);
- if (ret instanceof Throwable)
+ if (ret instanceof Throwable) {
throw (Throwable) ret;
+ }
store.reference(ret);
@@ -1010,7 +1056,7 @@ public class PluginAppletSecurityContext {
Integer strlength = parseCall(args[1], null, Integer.class);
int bytelength = 2 * strlength;
byte[] byteArray = new byte[bytelength];
- String ret = null;
+ String ret;
for (int i = 0; i < strlength; i++) {
int c = parseCall(args[2 + i], null, Integer.class);
PluginDebug.debug("char ", i, " ", c);
@@ -1027,13 +1073,15 @@ public class PluginAppletSecurityContext {
} else if (message.startsWith("ExceptionOccurred")) {
PluginDebug.debug("EXCEPTION: ", throwable);
- if (throwable != null)
+ if (throwable != null) {
store.reference(throwable);
+ }
write(reference, "ExceptionOccurred "
+ store.getIdentifier(throwable));
} else if (message.startsWith("ExceptionClear")) {
- if (throwable != null && store.contains(throwable))
+ if (throwable != null && store.contains(throwable)) {
store.unreference(store.getIdentifier(throwable));
+ }
throwable = null;
write(reference, "ExceptionClear");
} else if (message.startsWith("DeleteGlobalRef")) {
@@ -1083,8 +1131,9 @@ public class PluginAppletSecurityContext {
// 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"))
+ if (message.startsWith("CallMethod") || message.startsWith("CallStaticMethod")) {
throwable = t.getCause();
+ }
}
}
@@ -1097,7 +1146,7 @@ public class PluginAppletSecurityContext {
* @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 {
+ 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;
@@ -1180,7 +1229,7 @@ public class PluginAppletSecurityContext {
private int prepopulateClass(String name) {
name = name.replace('/', '.');
ClassLoader cl = liveconnectLoader;
- Class c = null;
+ Class<?> c = null;
try {
c = cl.loadClass(name);
@@ -1199,7 +1248,7 @@ public class PluginAppletSecurityContext {
Class<?> c = (Class<?>) store.getObject(classID);
Method m = null;
- Constructor cs = null;
+ Constructor<?> cs = null;
try {
if (methodName.equals("<init>")
@@ -1285,8 +1334,9 @@ public class PluginAppletSecurityContext {
// do nothing
}
- if (src.equals("[System]"))
+ if (src.equals("[System]")) {
grantedPermissions.add(new JSObjectCreatePermission());
+ }
} else {
JSObjectCreatePermission perm = new JSObjectCreatePermission();