diff options
author | Andrew John Hughes <[email protected]> | 2010-12-03 00:30:45 +0000 |
---|---|---|
committer | Andrew John Hughes <[email protected]> | 2010-12-03 00:30:45 +0000 |
commit | 8ddaf6d039146a442d35a7a31bfd48b061d456ff (patch) | |
tree | 023d91ea69877ae494e83bc01711c26c2ba41245 /plugin/icedteanp/java/sun/applet | |
parent | cad9500675e6a5dd9600a55fbe6dcb9523d23609 (diff) |
Fix warnings produced by NetX and the plugin (both Java and C++).
2010-12-01 Andrew John Hughes <[email protected]>
* netx/net/sourceforge/jnlp/cache/CacheUtil.java:
(getCachedResource(URL,Version,UpdatePolicy)): Use
toURI().toURL() to avoid broken escaping.
* netx/net/sourceforge/jnlp/cache/ResourceTracker.java:
(getCacheURL(URL)): Likewise.
* netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java:
(destroy()): Suppress deprecated warning from use of thread.stop().
Only use when interrupt() has already been tried.
* netx/net/sourceforge/jnlp/runtime/Boot.java:
(getFile()): Use toURI.toURL() to avoid broken escaping.
* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java:
(initializeResources()): Likewise.
* netx/net/sourceforge/jnlp/security/PasswordAuthenticationDialog.java:
(askUser(String,int,String,String)): Use getPassword() to retrieve
a character array directly. Fix overrunning line.
* netx/net/sourceforge/jnlp/tools/JarSigner.java:
Remove unused IdentityScope variable, scope.
* netx/net/sourceforge/nanoxml/XMLElement.java:
(scanWhitespace(StringBuffer)): Don't fallthrough.
* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc:
Fix warnings where std::string is used in printf
rather than char* by invoking c_str on these strings.
* plugin/icedteanp/java/netscape/javascript/JSException.java:
(JSException()): Mark with @Deprecated annotation.
(JSException(String)): Likewise.
(JSException(String,String,int,String,int)): Likewise.
* plugin/icedteanp/java/netscape/javascript/JSObject.java:
(JSObject(String)): Remove redundant cast.
(getWindow(Applet)): Likewise.
* plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java:
(contexts): Initialise properly with generic typing.
* plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java:
(getMatchingMethod(Object[]): Add missing generic type to Class
instances.
(getMatchingConstructor(Object[])): Likewise.
(getCostAndCastedObject(Object,Class<?>)): Likewise.
(getMatchingMethods(Class<?>,String,int)): Likewise.
(getMatchingConstructors(Class<?>,int)): Likewise.
(getNum(String,Class<?>)): Likewise.
* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java:
(parseCall(String,ClassLoader,Class<V>)): Use c.cast rather than (V).
(handleMessage(int,String,AccessControlContext,String)): Add
missing generic type to Class instances. Remove redundant casts.
(prepopulateField(int,String)): Add missing generic type to Class instance.
* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java:
(createPanel(PluginStreamHandler,int,long,URL,Hashtable<String,String>)):
Add missing generic types on Hashtable and PrivilegedAction.
(initEventQueue(AppletPanel)): Add missing generic type to PrivilegedAction.
(splitSeparator(String,String)): Use an ArrayList rather than Vector
to avoid locking and use generic types.
(requests): Initialise properly with generic typing.
(applets): Likewise.
(appletStateChanged(AppletEvent)): Use setSize and getPreferredSize.
(handleMessage(int,String)): Remove redundant casts.
(audioClips): Add generic types.
(getAudioClip): Remove redundant cast.
(imageRefs): Add generic types.
(getCachedImageRef(URL)): Remove redundant cast.
(appletPanels): Add generic types.
(getApplets()): Likewise.
(getStream(String)): Mark with @Override.
(getStreamKeys()): Likewise.
(systemParam): Add generic types.
(printTag(PrintStream,Hashtable<String,String>)): Likewise.
Remove redundant casts.
(updateAtts()): Use getSize() and getInsets(). Use Integer.valueOf().
(appletReload()): Add generic types to PrivilegedAction.
(scanIdentifier(int[],Reader)): Use StringBuilder to avoid unnecessary
locking.
(skipComment(int[],Reader)): Likewise.
(scanTag(int[],Reader)): Likewise. Add generic types.
(parse(int,long,String,String,Reader,URL)): Use PrivilegedExceptionAction
to avoid catching and rethrowing the exception manually. Add generic types.
(parse(int,long,String,String,Reader,URL,PrintStream,PluginAppletPanelFactory)):
Add generic types. Remove unnecessary casts. Fix overlong lines.
* plugin/icedteanp/java/sun/applet/PluginMain.java:
(init()): Add generic types. Remove unnecessary cast.
* plugin/icedteanp/java/sun/applet/PluginObjectStore.java:
(objects): Initialise properly with generic typing.
(counts): Likewise.
(identifiers): Likewise.
* plugin/icedteanp/java/sun/applet/PluginProxySelector.java:
(get(Object)): Suppress unchecked warning arising from cast to K.
Diffstat (limited to 'plugin/icedteanp/java/sun/applet')
7 files changed, 1878 insertions, 1877 deletions
diff --git a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java index 3820aa4..6e0defd 100644 --- a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java +++ b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java @@ -43,29 +43,30 @@ import java.util.HashMap; public class AppletSecurityContextManager { - // Context identifier -> PluginAppletSecurityContext object. - // FIXME: make private - private static HashMap<Integer, PluginAppletSecurityContext> contexts = new HashMap(); - - public static void addContext(int identifier, PluginAppletSecurityContext context) { - contexts.put(identifier, context); - } - - public static PluginAppletSecurityContext getSecurityContext(int identifier) { - return contexts.get(identifier); - } - - 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; - - privileges = privileges != null ? privileges : new String[0]; - callContext = contexts.get(identifier).getAccessControlContext(privileges, src); - - contexts.get(identifier).handleMessage(reference, src, callContext, message); - } + // 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 PluginAppletSecurityContext getSecurityContext(int identifier) { + return contexts.get(identifier); + } + + 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; + + privileges = privileges != null ? privileges : new String[0]; + callContext = contexts.get(identifier).getAccessControlContext(privileges, src); + + contexts.get(identifier).handleMessage(reference, src, callContext, message); + } } diff --git a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java index bb41e27..a1b3147 100644 --- a/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java +++ b/plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java @@ -1,5 +1,5 @@ /* MethodOverloadResolver -- Resolves overloaded methods - Copyright (C) 2009 Red Hat + Copyright (C) 2009 Red Hat This file is part of IcedTea. @@ -42,8 +42,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; -/* - * This class resolved overloaded methods in Java objects using a cost +/* + * This class resolved overloaded methods in Java objects using a cost * based-approach as described here: * * http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/#OVERLOADED_METHODS @@ -52,7 +52,7 @@ import java.util.ArrayList; public class MethodOverloadResolver { private static boolean debugging = false; - + public static void main(String[] args) { testMethodResolver(); } @@ -62,7 +62,7 @@ public class MethodOverloadResolver { ArrayList<Object[]> list = new ArrayList<Object[]>(20); FooClass fc = new FooClass(); - + // Numeric to java primitive // foo_i has Integer and int params String s1 = "foo_string_int(S,I)"; @@ -71,13 +71,13 @@ public class MethodOverloadResolver { list.add(o1); Object[] o1a = { fc.getClass(), "foo_string_int", "blah", "42.42" }; list.add(o1a); - + // Null to non-primitive type - // foo_i is overloaded with Integer and int + // foo_i is overloaded with Integer and int String s2 = "foo_string_int(N)"; Object[] o2 = { fc.getClass(), "foo_string_int", "blah", null }; list.add(o2); - + // foo_jsobj is overloaded with JSObject and String params String s3 = "foo_jsobj(LLowCostSignatureComputer/JSObject;)"; Object[] o3 = { fc.getClass(), "foo_jsobj", new JSObject() }; @@ -87,19 +87,19 @@ public class MethodOverloadResolver { String s4 = "foo_classtype(Ljava/lang/Integer;)"; Object[] o4 = { fc.getClass(), "foo_classtype", 42 }; list.add(o4); - + // foo_multiprim is overloaded with int, long and float types String s5 = "foo_multiprim(I)"; String s6 = "foo_multiprim(F)"; String s6a = "foo_multiprim(D)"; - + Object[] o5 = { fc.getClass(), "foo_multiprim", new Integer(42) }; Object[] o6 = { fc.getClass(), "foo_multiprim", new Float(42.42) }; Object[] o6a = { fc.getClass(), "foo_multiprim", new Double(42.42) }; list.add(o5); list.add(o6); list.add(o6a); - + // foo_float has float, String and JSObject type String s7 = "foo_float(I)"; Object[] o7 = { fc.getClass(), "foo_float", new Integer(42) }; @@ -109,7 +109,7 @@ public class MethodOverloadResolver { String s8 = "foo_float(S)"; Object[] o8 = { fc.getClass(), "foo_float", "42" }; list.add(o8); - + // foo_class is overloaded with BarClass 2 and 3 String s9 = "foo_class(LLowCostSignatureComputer/BarClass3;)"; Object[] o9 = { fc.getClass(), "foo_class", new BarClass3() }; @@ -129,17 +129,17 @@ public class MethodOverloadResolver { String s12 = "foo_str_and_float(S,I)"; Object[] o12 = { fc.getClass(), "foo_str_and_float", new JSObject(), new Integer(42) }; list.add(o12); - + // call for which no match will be found String s13 = "foo_int_only(JSObject)"; Object[] o13 = { fc.getClass(), "foo_int_only", new JSObject() }; list.add(o13); - + // method with no args String s14 = "foo_noargs()"; Object[] o14 = { fc.getClass(), "foo_noargs" }; list.add(o14); - + // method which takes a primitive bool, given a Boolean String s15 = "foo_boolonly()"; Object[] o15 = { fc.getClass(), "foo_boolonly", new Boolean(true) }; @@ -152,24 +152,24 @@ public class MethodOverloadResolver { System.out.println("Best match: " + methodAndArgs[0] + "\n"); else System.out.println("No match found.\n"); - + } - + } - /* + /* * Cost based overload resolution algorithm based on cost rules specified here: - * + * * http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/#OVERLOADED_METHODS */ public static Object[] getMatchingMethod(Object[] callList) { Object[] ret = null; - Class c = (Class) callList[0]; + Class<?> c = (Class<?>) callList[0]; String methodName = (String) callList[1]; Method[] matchingMethods = getMatchingMethods(c, methodName, callList.length - 2); - + if (debugging) System.out.println("getMatchingMethod called with: " + printList(callList)); @@ -187,23 +187,23 @@ public class MethodOverloadResolver { // Figure out which of the matched methods best represents what we // want for (int i = 0; i < paramTypes.length; i++) { - Class paramTypeClass = paramTypes[i]; + Class<?> paramTypeClass = paramTypes[i]; Object suppliedParam = callList[i + 2]; - Class suppliedParamClass = suppliedParam != null ? suppliedParam + Class<?> suppliedParamClass = suppliedParam != null ? suppliedParam .getClass() : null; Object[] costAndCastedObj = getCostAndCastedObject( suppliedParam, paramTypeClass); methodCost += (Integer) costAndCastedObj[0]; - + if ((Integer) costAndCastedObj[0] < 0) break; - + Object castedObj = paramTypeClass.isPrimitive() ? costAndCastedObj[1] : paramTypeClass.cast(costAndCastedObj[1]); methodAndArgs[i + 1] = castedObj; - Class castedObjClass = castedObj == null ? null : castedObj + Class<?> castedObjClass = castedObj == null ? null : castedObj .getClass(); Boolean castedObjIsPrim = castedObj == null ? null : castedObj .getClass().isPrimitive(); @@ -217,7 +217,7 @@ public class MethodOverloadResolver { + castedObjIsPrim + " value " + castedObj); } - if ((methodCost > 0 && methodCost < lowestCost) || + if ((methodCost > 0 && methodCost < lowestCost) || paramTypes.length == 0) { ret = methodAndArgs; lowestCost = methodCost; @@ -230,10 +230,10 @@ public class MethodOverloadResolver { public static Object[] getMatchingConstructor(Object[] callList) { Object[] ret = null; - Class c = (Class) callList[0]; + Class<?> c = (Class<?>) callList[0]; Constructor[] matchingConstructors = getMatchingConstructors(c, callList.length - 1); - + if (debugging) System.out.println("getMatchingConstructor called with: " + printList(callList)); @@ -244,14 +244,14 @@ public class MethodOverloadResolver { for (Constructor matchingConstructor : matchingConstructors) { int constructorCost = 0; - Class[] paramTypes = matchingConstructor.getParameterTypes(); + Class<?>[] paramTypes = matchingConstructor.getParameterTypes(); Object[] constructorAndArgs = new Object[paramTypes.length + 1]; constructorAndArgs[0] = matchingConstructor; // Figure out which of the matched methods best represents what we // want for (int i = 0; i < paramTypes.length; i++) { - Class paramTypeClass = paramTypes[i]; + Class<?> paramTypeClass = paramTypes[i]; Object suppliedParam = callList[i + 1]; Class suppliedParamClass = suppliedParam != null ? suppliedParam .getClass() @@ -260,14 +260,14 @@ public class MethodOverloadResolver { Object[] costAndCastedObj = getCostAndCastedObject( suppliedParam, paramTypeClass); constructorCost += (Integer) costAndCastedObj[0]; - + if ((Integer) costAndCastedObj[0] < 0) break; - + Object castedObj = paramTypeClass.isPrimitive() ? costAndCastedObj[1] : paramTypeClass.cast(costAndCastedObj[1]); constructorAndArgs[i + 1] = castedObj; - Class castedObjClass = castedObj == null ? null : castedObj + Class<?> castedObjClass = castedObj == null ? null : castedObj .getClass(); Boolean castedObjIsPrim = castedObj == null ? null : castedObj .getClass().isPrimitive(); @@ -281,7 +281,7 @@ public class MethodOverloadResolver { + castedObjIsPrim + " value " + castedObj); } - if ((constructorCost > 0 && constructorCost < lowestCost) || + if ((constructorCost > 0 && constructorCost < lowestCost) || paramTypes.length == 0) { ret = constructorAndArgs; lowestCost = constructorCost; @@ -291,20 +291,20 @@ public class MethodOverloadResolver { return ret; } - public static Object[] getCostAndCastedObject(Object suppliedParam, Class paramTypeClass) { - + public static Object[] getCostAndCastedObject(Object suppliedParam, Class<?> paramTypeClass) { + Object[] ret = new Object[2]; 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 && + if (paramTypeClass.isArray() != suppliedParamIsArray && !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; } @@ -315,37 +315,37 @@ public class MethodOverloadResolver { // If it is a string, we need to convert according to the JS engine rules if (paramTypeClass.isArray()) { - + Object newArray = Array.newInstance(paramTypeClass.getComponentType(), Array.getLength(suppliedParam)); for (int i=0; i < Array.getLength(suppliedParam); i++) { - Object original = Array.get(suppliedParam, i); - - // When dealing with arrays, we represent empty slots with - // null. We need to convert this to 0 before recursive - // calling, since normal transformation does not allow - // null -> primitive - - if (original == null && paramTypeClass.getComponentType().isPrimitive()) - original = 0; - - Object[] costAndCastedObject = getCostAndCastedObject(original, paramTypeClass.getComponentType()); - - if ((Integer) costAndCastedObject[0] < 0) { - ret[0] = Integer.MIN_VALUE; // Not allowed + Object original = Array.get(suppliedParam, i); + + // When dealing with arrays, we represent empty slots with + // null. We need to convert this to 0 before recursive + // calling, since normal transformation does not allow + // null -> primitive + + if (original == null && paramTypeClass.getComponentType().isPrimitive()) + original = 0; + + Object[] costAndCastedObject = getCostAndCastedObject(original, paramTypeClass.getComponentType()); + + if ((Integer) costAndCastedObject[0] < 0) { + ret[0] = Integer.MIN_VALUE; // Not allowed ret[1] = suppliedParam; return ret; - } + } - Array.set(newArray, i, costAndCastedObject[1]); + Array.set(newArray, i, costAndCastedObject[1]); } - + ret[0] = 9; ret[1] = newArray; return ret; } - + if (suppliedParamIsArray && paramTypeClass.equals(String.class)) { - + ret[0] = 9; ret[1] = getArrayAsString(suppliedParam); return ret; @@ -366,7 +366,7 @@ public class MethodOverloadResolver { } else if (suppliedParamClass.equals(paramTypeClass)) { cost += 3; // Class type to Class type where the types are equal castedObj = suppliedParam; - } else if (isNum(suppliedParam) && + } else if (isNum(suppliedParam) && (paramTypeClass.isPrimitive() || java.lang.Number.class.isAssignableFrom(paramTypeClass) || java.lang.Character.class.isAssignableFrom(paramTypeClass) || @@ -379,7 +379,7 @@ public class MethodOverloadResolver { suppliedParam = "1"; else if (suppliedParam.toString().equals("false")) suppliedParam = "0"; - + if (paramTypeClass.equals(Boolean.TYPE)) castedObj = getNum(suppliedParam.toString(), paramTypeClass).doubleValue() != 0D; else if (paramTypeClass.equals(Character.TYPE)) @@ -394,12 +394,12 @@ public class MethodOverloadResolver { paramTypeClass.isPrimitive()) ) { cost += 5; // String to numeric type - + if (suppliedParam.toString().equals("true")) suppliedParam = "1"; else if (suppliedParam.toString().equals("false")) suppliedParam = "0"; - + if (paramTypeClass.equals(Character.TYPE)) castedObj = (char) Short.decode(suppliedParam.toString()).shortValue(); else @@ -419,24 +419,24 @@ public class MethodOverloadResolver { castedObj = suppliedParam.toString(); } else if (suppliedParam instanceof JSObject && paramTypeClass.isArray()) { - cost += 8; // JSObject to Java array + cost += 8; // JSObject to Java array castedObj = (JSObject) suppliedParam; } else { cost = Integer.MIN_VALUE; // Not allowed castedObj = suppliedParam; } - + ret[0] = cost; ret[1] = castedObj; return ret; } - - private static Method[] getMatchingMethods(Class c, String name, int paramCount) { + + private static Method[] getMatchingMethods(Class<?> c, String name, int paramCount) { Method[] allMethods = c.getMethods(); - ArrayList<Method> matchingMethods = new ArrayList(5); - + ArrayList<Method> matchingMethods = new ArrayList<Method>(5); + for (Method m: allMethods) { if (m.getName().equals(name) && m.getParameterTypes().length == paramCount) matchingMethods.add(m); @@ -444,11 +444,11 @@ public class MethodOverloadResolver { return matchingMethods.toArray(new Method[0]); } - - private static Constructor[] getMatchingConstructors(Class c, int paramCount) { + + private static Constructor[] getMatchingConstructors(Class<?> c, int paramCount) { Constructor[] allConstructors = c.getConstructors(); ArrayList<Constructor> matchingConstructors = new ArrayList<Constructor>(5); - + for (Constructor cs: allConstructors) { if (cs.getParameterTypes().length == paramCount) matchingConstructors.add(cs); @@ -458,7 +458,7 @@ public class MethodOverloadResolver { } private static Class getPrimitive(Object o) { - + if (o instanceof java.lang.Byte) { return java.lang.Byte.TYPE; } else if (o instanceof java.lang.Character) { @@ -481,15 +481,15 @@ public class MethodOverloadResolver { } private static boolean isNum (Object o) { - + if (o instanceof java.lang.Number) return true; - + // Boolean is changeable to number as well if (o instanceof java.lang.Boolean) return true; - // At this point, it _has_ to be a string else automatically + // At this point, it _has_ to be a string else automatically // return false if (!(o instanceof java.lang.String)) return false; @@ -498,24 +498,24 @@ public class MethodOverloadResolver { Long.parseLong((String) o); // whole number test return true; } catch (NumberFormatException nfe) {} - + try { Float.parseFloat((String) o); // decimal return true; } 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(".")) n = new Double(s); else n = new Long(s); - + // See if we need to collapse first if (c.equals(java.lang.Integer.class) || c.equals(java.lang.Integer.TYPE)) { @@ -531,12 +531,12 @@ public class MethodOverloadResolver { c.equals(java.lang.Short.TYPE)) { return n.shortValue(); } - + if (c.equals(java.lang.Float.class) || c.equals(java.lang.Float.TYPE)) { return n.floatValue(); } - + if (c.equals(java.lang.Double.class) || c.equals(java.lang.Double.TYPE)) { return n.doubleValue(); @@ -551,14 +551,14 @@ public class MethodOverloadResolver { } private static String printList (Object[] oList) { - + String ret = ""; - + ret += "{ "; for (Object o : oList) { - + String oStr = o != null ? o.toString() + " [" + o.getClass() + "]" : "null"; - + ret += oStr; ret += ", "; } @@ -567,15 +567,15 @@ public class MethodOverloadResolver { return ret; } - + private static String getArrayAsString(Object array) { // We are guaranteed that supplied object is a String - + String ret = new String(); - + for (int i=0; i < Array.getLength(array); i++) { Object element = Array.get(array, i); - + if (element != null) { if (element.getClass().isArray()) { ret += getArrayAsString(element); @@ -583,7 +583,7 @@ public class MethodOverloadResolver { ret += element; } } - + ret += ","; } @@ -591,7 +591,7 @@ public class MethodOverloadResolver { if (ret.length() > 0) { ret = ret.substring(0, ret.length() - 1); } - + return ret; } } @@ -601,7 +601,7 @@ public class MethodOverloadResolver { class FooClass { public FooClass() {} - + public FooClass(Boolean b, int i) {} public FooClass(Boolean b, Integer i) {} @@ -621,7 +621,7 @@ class FooClass { public FooClass(double d) {} public FooClass(float f) {} - + public FooClass(JSObject j) {} public FooClass(BarClass1 b) {} @@ -629,18 +629,18 @@ class FooClass { public FooClass(BarClass2 b) {} public FooClass(String s) {} - + public FooClass(byte b) {} - + public FooClass(String s, Float f) {} - + public FooClass (int i) {} public void FooClass() {} public void FooClass(boolean b) {} - + public void foo(Boolean b, int i) {} public void foo(Boolean b, Integer i) {} @@ -664,13 +664,13 @@ class FooClass { public void foo_multiprim(long l) {} public void foo_multiprim(float f) {} - + public void foo_multiprim(double d) {} public void foo_float(float f) {} - + public void foo_float(String s) {} - + public void foo_float(JSObject j) {} public void foo_class(BarClass1 b) {} @@ -678,13 +678,13 @@ class FooClass { public void foo_class(BarClass2 b) {} public void foo_strandbyteonly(String s) {} - + public void foo_strandbyteonly(byte b) {} - + public void foo_str_and_float(String s, Float f) {} - + public void foo_int_only (int i) {} - + public void foo_noargs() {} public void foo_boolonly(boolean b) {} diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java index eb68371..e2db130 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java @@ -1,5 +1,5 @@ /* PluginAppletSecurityContext -- execute plugin JNI messages - Copyright (C) 2008 Red Hat + Copyright (C) 2008, 2010 Red Hat This file is part of IcedTea. @@ -67,377 +67,377 @@ 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( - "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) - .getClass()); - // System.out.println ("HERE4"); - } else - typeList.add(Array.newInstance( - getClass(arrayType, cl), dims).getClass()); - } else { - typeList.add(getClass(elem, cl)); - } - } - } - if (signature.length() < 2) { - throw new IllegalArgumentException("Invalid JNI signature '" - + signature + "'"); - } - } - - public static Class getClass(String name, ClassLoader cl) { - - Class c = null; - - 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))); - } - } - - return c; - } - - 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[] {}); - } + 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) + .getClass()); + // System.out.println ("HERE4"); + } else + typeList.add(Array.newInstance( + getClass(arrayType, cl), dims).getClass()); + } else { + typeList.add(getClass(elem, cl)); + } + } + } + if (signature.length() < 2) { + throw new IllegalArgumentException("Invalid JNI signature '" + + signature + "'"); + } + } + + public static Class getClass(String name, ClassLoader cl) { + + Class c = null; + + 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))); + } + } + + return c; + } + + 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>(); - - // FIXME: make private - public PluginObjectStore store = new PluginObjectStore(); - private Throwable throwable = null; - private ClassLoader liveconnectLoader = ClassLoader.getSystemClassLoader(); - int identifier = 0; - - public static PluginStreamHandler streamhandler; - - 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); - } - - JNLPRuntime.disableExit(); - - URL u = null; - try { - u = new URL("file://"); - } catch (Exception e) { - e.printStackTrace(); - } - - - this.classLoaders.put(liveconnectLoader, u); - } - - private static <V> V parseCall(String s, ClassLoader cl, Class<V> c) { - if (c == Integer.class) - return (V) new Integer(s); - else if (c == String.class) - return (V) new String(s); - else if (c == Signature.class) - return (V) new Signature(s, cl); - 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) - 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); - } - + + 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; + + public static PluginStreamHandler streamhandler; + + 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); + } + + JNLPRuntime.disableExit(); + + URL u = null; + try { + u = new URL("file://"); + } catch (Exception e) { + e.printStackTrace(); + } + + + this.classLoaders.put(liveconnectLoader, u); + } + + 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."); + } + + 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>(); - - for (ClassLoader loader : PluginAppletSecurityContext.classLoaders.keySet()) { - map.put(loader.getClass().getName(), classLoaders.get(loader).toString()); - } - - return map; - } - - public void handleMessage(int reference, String src, AccessControlContext callContext, String message) { - - 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 { - 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"); - } - } - - } 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(); - - Class c; - - 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>") - || 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") - || 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); - - Class c = (Class) store.getObject(classID); - - PluginDebug.debug("GetStaticFieldID/GetFieldID got class=" + c.getName()); - - Field f = null; - f = c.getField(fieldName); - - 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); - - final Class c = (Class) store.getObject(classID); - final Field f = (Field) store.getObject(fieldID); - - 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); - - if (ret instanceof Throwable) - throw (Throwable) ret; + public static void setStreamhandler(PluginStreamHandler sh) { + streamhandler = sh; + } + + public static Map<String, String> getLoaderInfo() { + Hashtable<String, String> map = new Hashtable<String, String>(); + + for (ClassLoader loader : PluginAppletSecurityContext.classLoaders.keySet()) { + map.put(loader.getClass().getName(), classLoaders.get(loader).toString()); + } + + return map; + } + + public void handleMessage(int reference, String src, AccessControlContext callContext, String message) { + + 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 { + 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"); + } + } + + } 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(); + + Class<?> c; + + 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>") + || 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") + || 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); + + Class<?> c = (Class<?>) store.getObject(classID); + + PluginDebug.debug("GetStaticFieldID/GetFieldID got class=" + c.getName()); + + Field f = null; + f = c.getField(fieldName); + + 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); + + final Class<?> c = (Class<?>) store.getObject(classID); + final Field f = (Field) store.getObject(fieldID); + + 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); + + if (ret instanceof Throwable) + throw (Throwable) ret; if (ret == null) { write(reference, "GetStaticField literalreturn null"); @@ -448,8 +448,8 @@ public class PluginAppletSecurityContext { || f.getType() == Long.TYPE) { write(reference, "GetStaticField literalreturn " + ret); } else if (f.getType() == Float.TYPE - || f.getType() == Double.TYPE) { - write(reference, "GetStaticField literalreturn " + String.format("%308.308e", ret)); + || f.getType() == Double.TYPE) { + write(reference, "GetStaticField literalreturn " + String.format("%308.308e", ret)); } else if (f.getType() == Character.TYPE) { write(reference, "GetStaticField literalreturn " + (int) (Character) ret); } else { @@ -457,10 +457,10 @@ 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); - + Object ret = store.getObject(index); if (ret == null) { @@ -490,46 +490,46 @@ public class PluginAppletSecurityContext { write(reference, "GetValue " + store.getIdentifier(ret)); } } 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)); - - final Object o = store.getObject(classOrObjectID); - final Field f = (Field) store.getObject(fieldID); - - final Object fValue = MethodOverloadResolver.getCostAndCastedObject(value, f.getType())[1]; - - 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; - } - - return null; - } - }, acc); - - 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); - - Object ret = Array.get(store.getObject(arrayID), index); - Class retClass = store.getObject(arrayID).getClass().getComponentType(); // prevent auto-boxing influence - + 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)); + + final Object o = store.getObject(classOrObjectID); + final Field f = (Field) store.getObject(fieldID); + + final Object fValue = MethodOverloadResolver.getCostAndCastedObject(value, f.getType())[1]; + + 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; + } + + return null; + } + }, acc); + + 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); + + 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 @@ -539,71 +539,71 @@ public class PluginAppletSecurityContext { || 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)); + || retClass == Double.TYPE) { + write(reference, "GetObjectArrayElement literalreturn " + String.format("%308.308e", ret)); } else if (retClass == Character.TYPE) { write(reference, "GetObjectArrayElement literalreturn " + (int) (Character) ret); } else { // Track returned object. store.reference(ret); 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 = (Object) 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 = (Object) 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"); @@ -614,8 +614,8 @@ public class PluginAppletSecurityContext { || f.getType() == Long.TYPE) { write(reference, "GetField literalreturn " + ret); } else if (f.getType() == Float.TYPE - || f.getType() == Double.TYPE) { - write(reference, "GetField literalreturn " + String.format("%308.308e", ret)); + || f.getType() == Double.TYPE) { + write(reference, "GetField literalreturn " + String.format("%308.308e", ret)); } else if (f.getType() == Character.TYPE) { write(reference, "GetField literalreturn " + (int) (Character) ret); } else { @@ -624,217 +624,217 @@ public class PluginAppletSecurityContext { write(reference, "GetField " + store.getIdentifier(ret)); } - } 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") || - 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 = (Object) 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; + } 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") || + 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); + } + + // 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]); } Object[] matchingMethodAndArgs = MethodOverloadResolver.getMatchingMethod(arguments); - + if (matchingMethodAndArgs == null) { write(reference, "Error: No suitable method named " + methodName + " with matching args found"); 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]; - } - - String collapsedArgs = ""; - for (Object arg : castedArgs) { - collapsedArgs += " " + arg; - } - - 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(); - } - - PluginDebug.debug("Calling " + m + " on " + o + " with " - + collapsedArgs + " and that returned: " + ret - + " of type " + retO); - - if (m.getReturnType().equals(java.lang.Void.class) || - m.getReturnType().equals(java.lang.Void.TYPE)) { + 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; + } + + 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(); + } + + PluginDebug.debug("Calling " + m + " on " + o + " with " + + collapsedArgs + " and that returned: " + ret + + " of type " + retO); + + 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 - || 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 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); } 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 = (Object) 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 - .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")) { + || 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 + .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 + .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")) { String[] args = message.split(" "); Integer objectID = parseCall(args[1], null, Integer.class); @@ -853,56 +853,56 @@ 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)) { - c = (Class) store.getObject(Integer.parseInt(type)); + c = (Class<?>) store.getObject(Integer.parseInt(type)); } else { 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); - - Class c = (Class) store.getObject(classNameID); + + Class c = (Class<?>) store.getObject(classNameID); String methodName = (String) store.getObject(methodNameID); Method method = null; Method[] classMethods = c.getMethods(); for (Method m: classMethods) { - if (m.getName().equals(methodName)) { - method = m; - break; - } + if (m.getName().equals(methodName)) { + method = m; + break; + } } - - int hasMethod = (method != null) ? 1 : 0; + + int hasMethod = (method != null) ? 1 : 0; write(reference, "HasMethod " + hasMethod); } else if (message.startsWith("HasPackage")) { @@ -912,7 +912,7 @@ public class PluginAppletSecurityContext { String pkgName = (String) store.getObject(nameID); Package pkg = Package.getPackage(pkgName); - int hasPkg = (pkg != null) ? 1 : 0; + int hasPkg = (pkg != null) ? 1 : 0; write(reference, "HasPackage " + hasPkg); @@ -920,43 +920,43 @@ public class PluginAppletSecurityContext { String[] args = message.split(" "); Integer classNameID = parseCall(args[1], null, Integer.class); Integer fieldNameID = parseCall(args[2], null, Integer.class); - + Class c = (Class) store.getObject(classNameID); String fieldName = (String) store.getObject(fieldNameID); Field field = null; Field[] classFields = c.getFields(); for (Field f: classFields) { - if (f.getName().equals(fieldName)) { - field = f; - break; - } + if (f.getName().equals(fieldName)) { + field = f; + break; + } } - int hasField = (field != null) ? 1 : 0; + 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); - - // System.out.println ("CALLING: NewObjectArray: " + - // classID + " " + length + " " - // + objectID); - - 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 " - + store.getIdentifier(newArray)); - } else if (message.startsWith("NewObjectWithConstructor")) { + 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); + + 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 " + + store.getIdentifier(newArray)); + } else if (message.startsWith("NewObjectWithConstructor")) { String[] args = message.split(" "); Integer classID = parseCall(args[1], null, Integer.class); @@ -997,9 +997,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; @@ -1033,30 +1033,30 @@ public class PluginAppletSecurityContext { collapsedArgs += " " + arg.toString(); } - PluginDebug.debug("Calling constructor on class " + c + + PluginDebug.debug("Calling constructor on class " + c + " 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]); @@ -1068,14 +1068,14 @@ public class PluginAppletSecurityContext { while (i < length) { c = Integer.parseInt(args[j++], 16); byteArray[i++] = (byte) c; - } + } ret = new String(byteArray, "UTF-8"); PluginDebug.debug("NEWSTRINGUTF: " + ret); 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 +1099,383 @@ 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 " - + 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 = (Object) store.getObject(objectID); - write(reference, "GetClassName " + o.getClass().getName()); - } else if (message.startsWith("GetClassID")) { + } 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")) { 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); - - // 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); - } - - 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 int prepopulateClass(String name) { - name = name.replace('/', '.'); - ClassLoader cl = liveconnectLoader; - Class c = null; - - try { - c = cl.loadClass(name); - store.reference(c); - } catch (ClassNotFoundException cnfe) { - // do nothing ... this should never happen - cnfe.printStackTrace(); - } - - return store.getIdentifier(c); - } - - private int prepopulateMethod(int classID, String methodName, String signatureStr) { - Signature signature = parseCall(signatureStr, ((Class) store.getObject(classID)).getClassLoader(), Signature.class); - Object[] a = signature.getClassArray(); - - Class c = (Class) store.getObject(classID); - Method m = null; - Constructor cs = null; - Object o = null; - - 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(); - } - - return store.getIdentifier(m); - } - - private int prepopulateField(int classID, String fieldName) { - - 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(); - } - - store.reference(f); - return store.getIdentifier(f); - } - - public void dumpStore() { - store.dump(); - } - - public Object getObject(int identifier) { - return store.getObject(identifier); - } - - public int getIdentifier(Object o) { - return store.getIdentifier(o); - } - - 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) { + } 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); + + // 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); + } + + 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 int prepopulateClass(String name) { + name = name.replace('/', '.'); + ClassLoader cl = liveconnectLoader; + Class c = null; + + try { + c = cl.loadClass(name); + store.reference(c); + } catch (ClassNotFoundException cnfe) { + // do nothing ... this should never happen + cnfe.printStackTrace(); + } + + return store.getIdentifier(c); + } + + private int prepopulateMethod(int classID, String methodName, String signatureStr) { + Signature signature = parseCall(signatureStr, ((Class) store.getObject(classID)).getClassLoader(), Signature.class); + Object[] a = signature.getClassArray(); + + Class<?> c = (Class<?>) store.getObject(classID); + Method m = null; + Constructor cs = null; + Object o = null; + + 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(); + } + + return store.getIdentifier(m); + } + + private int prepopulateField(int classID, String fieldName) { + + 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(); + } + + store.reference(f); + return store.getIdentifier(f); + } + + public void dumpStore() { + store.dump(); + } + + public Object getObject(int identifier) { + return store.getObject(identifier); + } + + public int getIdentifier(Object o) { + return store.getIdentifier(o); + } + + 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); - } - } - - // what to do with these is unknown: UniversalConnectWithRedirect, UniversalDialogModality, UniversalSendMail, LimitedInstall, FullInstall, SilentInstall + 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 */ - Permissions grantedPermissions = new Permissions(); - - 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); - } - } - - 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.equals("[System]")) - grantedPermissions.add(new JSObjectCreatePermission()); - - } else { - JSObjectCreatePermission perm = new JSObjectCreatePermission(); - grantedPermissions.add(perm); - } - - ProtectionDomain pd = new ProtectionDomain(cs, grantedPermissions, null, null); - - // Add to hashmap - return new AccessControlContext(new ProtectionDomain[] {pd}); - } + Permissions grantedPermissions = new Permissions(); + + 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); + } + } + + 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.equals("[System]")) + grantedPermissions.add(new JSObjectCreatePermission()); + + } else { + JSObjectCreatePermission perm = new JSObjectCreatePermission(); + grantedPermissions.add(perm); + } + + ProtectionDomain pd = new ProtectionDomain(cs, grantedPermissions, null, null); + + // Add to hashmap + return new AccessControlContext(new ProtectionDomain[] {pd}); + } // private static final == inline private static final boolean isInt(Object o) { @@ -1490,11 +1490,11 @@ 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 27246b0..29a3103 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -1,5 +1,5 @@ /* PluginAppletViewer -- Handles embedding of the applet panel - Copyright (C) 2008 Red Hat + Copyright (C) 2008 Red Hat This file is part of IcedTea. @@ -59,9 +59,9 @@ exception statement from your version. */ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ - + package sun.applet; - + import java.applet.Applet; import java.applet.AppletContext; import java.applet.AudioClip; @@ -93,10 +93,14 @@ import java.net.URL; import java.security.AccessController; import java.security.AllPermission; import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Vector; @@ -110,23 +114,23 @@ import sun.awt.X11.XEmbeddedFrame; import sun.misc.Ref; import com.sun.jndi.toolkit.url.UrlUtil; - + /** * Lets us construct one using unix-style one shot behaviors */ - + 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 atts) { - - AppletViewerPanel panel = (AppletViewerPanel) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + final URL doc, + final Hashtable<String,String> atts) { + AppletViewerPanel panel = AccessController.doPrivileged(new PrivilegedAction<AppletViewerPanel>() { + public AppletViewerPanel run() { try { - AppletPanel panel = new NetxPanel(doc, atts, false); + AppletViewerPanel panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); return panel; @@ -136,7 +140,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; } } }); - + // create the frame. PluginAppletViewer.framePanel(identifier, System.out, handle, panel); @@ -151,7 +155,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; if (atts.get("codebase") != null) { try { - URL appletSrcURL = new URL(codeBase + (String) atts.get("codebase")); + URL appletSrcURL = new URL(codeBase + atts.get("codebase")); codeBase = appletSrcURL.getProtocol() + "://" + appletSrcURL.getHost(); } catch (MalformedURLException mfue) { // do nothing @@ -162,7 +166,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; // 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; @@ -174,7 +178,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; // just wait } } - + // Wait for the panel to initialize // (happens in a separate thread) PluginAppletViewer.waitForAppletInit((NetxPanel) panel); @@ -189,18 +193,18 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 @@ -209,12 +213,12 @@ import com.sun.jndi.toolkit.url.UrlUtil; private void initEventQueue(AppletPanel panel) { // appletviewer.send.event is an undocumented and unsupported system // property which is used exclusively for testing purposes. - PrivilegedAction pa = new PrivilegedAction() { - public Object run() { + PrivilegedAction<String> pa = new PrivilegedAction<String>() { + public String run() { return System.getProperty("appletviewer.send.event"); } }; - String eventList = (String) AccessController.doPrivileged(pa); + String eventList = AccessController.doPrivileged(pa); if (eventList == null) { // Add the standard events onto the event queue. @@ -256,8 +260,8 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 @@ -273,30 +277,28 @@ import com.sun.jndi.toolkit.url.UrlUtil; * s. Whitespace not stripped. */ private String [] splitSeparator(String sep, String s) { - Vector v = new Vector(); + List<String> l = new ArrayList<String>(); int tokenStart = 0; int tokenEnd = 0; while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) { - v.addElement(s.substring(tokenStart, tokenEnd)); + l.add(s.substring(tokenStart, tokenEnd)); tokenStart = tokenEnd+1; } // Add the final element. - v.addElement(s.substring(tokenStart)); + l.add(s.substring(tokenStart)); - String [] retVal = new String[v.size()]; - v.copyInto(retVal); - return retVal; + return l.toArray(new String[l.size()]); } } - + class PluginParseRequest { long handle; String tag; String documentbase; } - + /* */ // FIXME: declare JSProxy implementation @@ -306,11 +308,11 @@ import com.sun.jndi.toolkit.url.UrlUtil; * 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 @@ -323,61 +325,61 @@ import com.sun.jndi.toolkit.url.UrlUtil; * The panel in which the applet is being displayed. */ AppletViewerPanel panel; - + /** * The status line. */ Label label; - + /** * output status messages to this stream */ - + PrintStream statusMsgStream; - + int identifier; - - private static HashMap<Integer, PluginParseRequest> requests = - new HashMap(); - + + private static HashMap<Integer, PluginParseRequest> requests = + new HashMap<Integer,PluginParseRequest>(); + // Instance identifier -> PluginAppletViewer object. - private static HashMap<Integer, PluginAppletViewer> applets = - new HashMap(); - + private static HashMap<Integer, PluginAppletViewer> applets = + new HashMap<Integer,PluginAppletViewer>(); + private static PluginStreamHandler streamhandler; - + private static PluginCallRequestFactory requestFactory; - private static HashMap<Integer, PAV_INIT_STATUS> 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; - + public static final int APPLET_TIMEOUT = 180000; private static Long requestIdentityCounter = 0L; - + private Image bufFrameImg; private Graphics bufFrameImgGraphics; - + /** * Null constructor to allow instantiation via newInstance() */ public PluginAppletViewer() { } - public static void framePanel(int identifier, PrintStream statusMsgStream, - long handle, AppletViewerPanel panel) { + public static void framePanel(int identifier, PrintStream statusMsgStream, + long handle, AppletViewerPanel panel) { PluginDebug.debug("Framing " + panel); - + // SecurityManager MUST be set, and only privileged code may call reFrame() System.getSecurityManager().checkPermission(new AllPermission()); PluginAppletViewer appletFrame = new PluginAppletViewer(handle, identifier, statusMsgStream, panel); - + appletFrame.add("Center", panel); appletFrame.pack(); @@ -392,10 +394,10 @@ import com.sun.jndi.toolkit.url.UrlUtil; /** * Create new plugin appletviewer frame */ - private PluginAppletViewer(long handle, final int identifier, - PrintStream statusMsgStream, + private PluginAppletViewer(long handle, final int identifier, + PrintStream statusMsgStream, AppletViewerPanel appletPanel) { - + super(handle, true); this.statusMsgStream = statusMsgStream; this.identifier = identifier; @@ -423,37 +425,37 @@ import com.sun.jndi.toolkit.url.UrlUtil; } - private static class AppletEventListener implements AppletListener + 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 void appletStateChanged(AppletEvent evt) + + public void appletStateChanged(AppletEvent evt) { AppletPanel src = (AppletPanel)evt.getSource(); - + switch (evt.getID()) { case AppletPanel.APPLET_RESIZE: { if(src != null) { - appletViewer.resize(appletViewer.preferredSize()); + 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 + // 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. // @@ -468,14 +470,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; else AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext()); - updateStatus(appletViewer.identifier, PAV_INIT_STATUS.INIT_COMPLETE); + updateStatus(appletViewer.identifier, PAV_INIT_STATUS.INIT_COMPLETE); break; } } } } - + public static void setStreamhandler(PluginStreamHandler sh) { streamhandler = sh; } @@ -491,35 +493,35 @@ import com.sun.jndi.toolkit.url.UrlUtil; { 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 = + // 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 + String tag = message.substring(spaceLocation+1); + + // Decode the tag tag = tag.replace(">", ">"); tag = tag.replace("<", "<"); tag = tag.replace("&", "&"); @@ -527,16 +529,16 @@ import com.sun.jndi.toolkit.url.UrlUtil; tag = tag.replace(" ", "\r"); tag = tag.replace(""", "\""); - PluginDebug.debug ("Handle = " + handle + "\n" + - "Width = " + width + "\n" + - "Height = " + height + "\n" + - "DocumentBase = " + documentBase + "\n" + - "Tag = " + tag); - - PluginAppletViewer.parse - (identifier, handle, width, height, - new StringReader(tag), - new URL(documentBase)); + PluginDebug.debug ("Handle = " + handle + "\n" + + "Width = " + width + "\n" + + "Height = " + height + "\n" + + "DocumentBase = " + documentBase + "\n" + + "Tag = " + tag); + + 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; @@ -554,13 +556,13 @@ import com.sun.jndi.toolkit.url.UrlUtil; // If wait exceeded maxWait, we timed out. Throw an exception if (wait >= maxWait) throw new Exception("Applet initialization timeout"); - + PluginAppletViewer oldFrame = applets.get(identifier); - // 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 + // 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? @@ -571,22 +573,22 @@ import com.sun.jndi.toolkit.url.UrlUtil; } 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 && - previousStatus.equals(PAV_INIT_STATUS.REFRAME_COMPLETE)) { - destroyApplet(identifier); - } + if (previousStatus != null && + previousStatus.equals(PAV_INIT_STATUS.REFRAME_COMPLETE)) { + destroyApplet(identifier); + } } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); // Wait till initialization finishes - while (!applets.containsKey(identifier) && + while (!applets.containsKey(identifier) && ( - !status.containsKey(identifier) || + !status.containsKey(identifier) || status.get(identifier).equals(PAV_INIT_STATUS.PRE_INIT) ) ); @@ -600,118 +602,118 @@ import com.sun.jndi.toolkit.url.UrlUtil; } catch (Exception e) { e.printStackTrace(); - + // 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 + * 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; + + 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 + * + * 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) { - PluginDebug.debug("DestroyApplet called for " + identifier); - - PAV_INIT_STATUS prev = updateStatus(identifier, PAV_INIT_STATUS.DESTROYED); + PluginDebug.debug("DestroyApplet called for " + identifier); - // If already destroyed, return - if (prev.equals(PAV_INIT_STATUS.DESTROYED)) { - PluginDebug.debug(identifier + " already destroyed. Returning."); - return; - } + PAV_INIT_STATUS prev = updateStatus(identifier, PAV_INIT_STATUS.DESTROYED); - PluginDebug.debug("Attempting to destroy frame " + identifier); - - // Try to dispose the panel right away - if (applets.containsKey(identifier)) - applets.get(identifier).dispose(); + // If already destroyed, return + if (prev.equals(PAV_INIT_STATUS.DESTROYED)) { + PluginDebug.debug(identifier + " already destroyed. 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 frame " + identifier); - PluginDebug.debug("Attempting to destroy panel " + identifier); + // Try to dispose the panel right away + if (applets.containsKey(identifier)) + applets.get(identifier).dispose(); - final int fIdentifier = identifier; - SwingUtilities.invokeLater(new Runnable() { - public void run() { - applets.get(fIdentifier).appletClose(); - } - }); + // 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(identifier + " destroyed"); + final int fIdentifier = identifier; + SwingUtilities.invokeLater(new Runnable() { + public void run() { + applets.get(fIdentifier).appletClose(); + } + }); + + 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) { - - int waitTime = 0; - + + int waitTime = 0; + // 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..."); + PluginDebug.debug("Waiting for applet panel " + panel + " to initialize..."); Thread.sleep(waitTime += 50); } catch (InterruptedException ie) { // just wait } } - + PluginDebug.debug("Applet panel " + panel + " initialized"); } @@ -730,12 +732,12 @@ import com.sun.jndi.toolkit.url.UrlUtil; // just wait } } - + // 0 => width, 1=> width_value, 2 => height, 3=> height_value String[] dimMsg = message.split(" "); - - final int height = (int) (Integer.parseInt(dimMsg[3])); - final int width = (int) (Integer.parseInt(dimMsg[1])); + + final int height = Integer.parseInt(dimMsg[3]); + final int width = Integer.parseInt(dimMsg[1]); if (panel instanceof NetxPanel) ((NetxPanel) panel).updateSizeInAtts(height, width); @@ -745,15 +747,15 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 + + // 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); @@ -761,7 +763,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; panel.setSize(width, height); panel.validate(); - + panel.applet.resize(width, height); panel.applet.validate(); } @@ -791,7 +793,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; // just wait } } - + // Wait for the panel to initialize // (happens in a separate thread) waitForAppletInit((NetxPanel) panel); @@ -815,7 +817,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; } } - // FIXME: Kind of hackish way to ensure synchronized re-drawing + // FIXME: Kind of hackish way to ensure synchronized re-drawing private synchronized void forceredraw() { doLayout(); } @@ -823,43 +825,43 @@ import com.sun.jndi.toolkit.url.UrlUtil; /* * Methods for java.applet.AppletContext */ - - private static Map audioClips = new HashMap(); - + + 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 = (AudioClip)audioClips.get(url); - if (clip == null) { - audioClips.put(url, clip = new AppletAudioClip(url)); - } - return clip; - } + checkConnect(url); + synchronized (audioClips) { + AudioClip clip = audioClips.get(url); + if (clip == null) { + audioClips.put(url, clip = new AppletAudioClip(url)); + } + return clip; + } } - - private static Map imageRefs = new HashMap(); - + + private static Map<URL,AppletImageRef> imageRefs = new HashMap<URL,AppletImageRef>(); + /** * Get an image. */ public Image getImage(URL url) { - return getCachedImage(url); + return getCachedImage(url); } - + 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); - + try { String originalURL = url.toString(); @@ -874,9 +876,9 @@ import com.sun.jndi.toolkit.url.UrlUtil; if (panel instanceof NetxPanel) { 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); @@ -888,7 +890,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; PluginDebug.debug("getCachedImageRef() getting img from URL = " + url); synchronized (imageRefs) { - AppletImageRef ref = (AppletImageRef)imageRefs.get(url); + AppletImageRef ref = imageRefs.get(url); if (ref == null) { ref = new AppletImageRef(url); imageRefs.put(url, ref); @@ -901,16 +903,16 @@ import com.sun.jndi.toolkit.url.UrlUtil; return null; } } - + /** * Flush the image cache. */ static void flushImageCache() { - imageRefs.clear(); + imageRefs.clear(); } - - static Vector appletPanels = new Vector(); - + + static Vector<AppletPanel> appletPanels = new Vector<AppletPanel>(); + /** * Get an applet by name. */ @@ -926,10 +928,10 @@ import com.sun.jndi.toolkit.url.UrlUtil; } if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) { - + SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect"); - + if (panelSp.implies(sp)) { return p.applet; } @@ -937,30 +939,30 @@ import com.sun.jndi.toolkit.url.UrlUtil; } return null; } - + /** * Return an enumeration of all the accessible * applets on this page. */ - public Enumeration getApplets() { - Vector v = new Vector(); - SocketPermission panelSp = - new SocketPermission(panel.getCodeBase().getHost(), "connect"); - - for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { - AppletPanel p = (AppletPanel)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(); + 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. */ @@ -968,7 +970,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; PluginDebug.debug("Showing document..."); showDocument(url, "_self"); } - + /** * Ignore. */ @@ -982,7 +984,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; // streamhandler.pluginOutputStream has been closed. } } - + /** * Show status. */ @@ -998,11 +1000,11 @@ import com.sun.jndi.toolkit.url.UrlUtil; // streamhandler.pluginOutputStream has been closed. } } - + /** - * Returns an incremental number (unique identifier) for a message. + * 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() { @@ -1010,7 +1012,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; if (requestIdentityCounter == Long.MAX_VALUE) requestIdentityCounter = 0L; - + return requestIdentityCounter++; } } @@ -1020,7 +1022,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; Long reference = getRequestIdentifier(); PluginCallRequest request = requestFactory.getPluginCallRequest("window", - "instance " + identifier + " reference " + + "instance " + identifier + " reference " + + reference + " " + "GetWindow", reference); PluginDebug.debug ("STARTING postCallRequest"); @@ -1043,17 +1045,17 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 " + + PluginCallRequest request = requestFactory.getPluginCallRequest("member", + "instance " + 0 + " reference " + reference + " GetMember " + internal + " " + nameID, reference); streamhandler.postCallRequest(request); @@ -1073,14 +1075,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 + // work on a copy of value, as we don't want to be manipulating // complex objects String valueToSetTo; if (value instanceof java.lang.Byte || @@ -1094,23 +1096,23 @@ import com.sun.jndi.toolkit.url.UrlUtil; valueToSetTo = "literalreturn " + value.toString(); - // Character -> Str results in str value.. we need int value as + // 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(); + valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue(); } else if (value instanceof Float || value instanceof Double) { 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 " + + "instance " + 0 + " reference " + reference + " SetMember " + internal + " " + nameID + " " + valueToSetTo, reference); streamhandler.postCallRequest(request); @@ -1130,13 +1132,13 @@ import com.sun.jndi.toolkit.url.UrlUtil; } 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 + + // work on a copy of value, as we don't want to be manipulating // complex objects String valueToSetTo; if (value instanceof java.lang.Byte || @@ -1150,23 +1152,23 @@ import com.sun.jndi.toolkit.url.UrlUtil; valueToSetTo = "literalreturn " + value.toString(); - // Character -> Str results in str value.. we need int value as + // 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(); + valueToSetTo = "literalreturn " + (int) ((java.lang.Character) value).charValue(); } else if (value instanceof Float || value instanceof Double) { 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 " + + "instance " + 0 + " reference " + reference + " SetSlot " + internal + " " + index + " " + valueToSetTo, reference); streamhandler.postCallRequest(request); @@ -1185,14 +1187,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; } 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 " + + PluginCallRequest request = requestFactory.getPluginCallRequest("member", + "instance " + 0 + " reference " + reference + " GetSlot " + internal + " " + index, reference); streamhandler.postCallRequest(request); streamhandler.write(request.getMessage()); @@ -1211,7 +1213,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; PluginDebug.debug (" getSlot DONE"); return request.getObject(); } - + public static Object eval(long internal, String s) { AppletSecurityContextManager.getSecurityContext(0).store(s); @@ -1220,8 +1222,8 @@ import com.sun.jndi.toolkit.url.UrlUtil; // Prefix with dummy instance for convenience. // FIXME: rename GetMemberPluginCallRequest ObjectPluginCallRequest. - PluginCallRequest request = requestFactory.getPluginCallRequest("member", - "instance " + 0 + " reference " + reference + " Eval " + + PluginCallRequest request = requestFactory.getPluginCallRequest("member", + "instance " + 0 + " reference " + reference + " Eval " + internal + " " + stringID, reference); streamhandler.postCallRequest(request); streamhandler.write(request.getMessage()); @@ -1240,15 +1242,15 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 " + + "instance " + 0 + " reference " + reference + " RemoveMember " + internal + " " + nameID, reference); streamhandler.postCallRequest(request); @@ -1267,7 +1269,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; } PluginDebug.debug (" RemoveMember DONE"); } - + public static Object call(long internal, String name, Object args[]) { // FIXME: when is this removed from the object store? @@ -1276,7 +1278,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; AppletSecurityContextManager.getSecurityContext(0).store(name); int nameID = AppletSecurityContextManager.getSecurityContext(0).getIdentifier(name); Long reference = getRequestIdentifier(); - + String argIDs = ""; for (Object arg : args) { @@ -1284,10 +1286,10 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 " + + "instance " + 0 + " reference " + reference + " Call " + internal + " " + nameID + " " + argIDs, reference); streamhandler.postCallRequest(request); @@ -1307,7 +1309,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; PluginDebug.debug (" Call DONE"); return request.getObject(); } - + public static Object requestPluginCookieInfo(URI uri) { PluginCallRequest request; @@ -1315,9 +1317,9 @@ import com.sun.jndi.toolkit.url.UrlUtil; try { - String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); request = requestFactory.getPluginCallRequest("cookieinfo", - "plugin PluginCookieInfo " + "reference " + reference + + "plugin PluginCookieInfo " + "reference " + reference + " " + encodedURI, reference); } catch (UnsupportedEncodingException e) @@ -1352,12 +1354,12 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 + // 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() : ""; + String port = uri.getPort() != -1 ? ":" + uri.getPort() : ""; if (!uri.getScheme().startsWith("http") && !uri.getScheme().equals("ftp")) scheme = "http"; @@ -1369,7 +1371,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; } PluginCallRequest request = requestFactory.getPluginCallRequest("proxyinfo", - "plugin PluginProxyInfo reference " + reference + " " + + "plugin PluginProxyInfo reference " + reference + " " + requestURI, reference); PluginMessageConsumer.registerPriorityWait(reference); @@ -1390,14 +1392,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 " + + "instance " + 0 + " reference " + reference + " Finalize " + internal, reference); streamhandler.postCallRequest(request); @@ -1416,14 +1418,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; } 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 " + + "instance " + 0 + " reference " + reference + " ToString " + internal, reference); streamhandler.postCallRequest(request); @@ -1443,7 +1445,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 { @@ -1455,22 +1457,24 @@ import com.sun.jndi.toolkit.url.UrlUtil; public void setStream(String key, InputStream stream)throws IOException{ // We do nothing. } - + + @Override public InputStream getStream(String key){ - // We do nothing. - return null; + // We do nothing. + return null; } - - public Iterator getStreamKeys(){ - // We do nothing. - return null; + + @Override + public Iterator<String> getStreamKeys(){ + // We do nothing. + return null; } - + /** * System parameters. */ - static Hashtable systemParam = new Hashtable(); - + static Hashtable<String,String> systemParam = new Hashtable<String,String>(); + static { systemParam.put("codebase", "codebase"); systemParam.put("code", "code"); @@ -1481,58 +1485,58 @@ import com.sun.jndi.toolkit.url.UrlUtil; systemParam.put("vspace", "vspace"); systemParam.put("hspace", "hspace"); } - + /** * Print the HTML tag. */ - public static void printTag(PrintStream out, Hashtable atts) { + public static void printTag(PrintStream out, Hashtable<String,String> atts) { out.print("<applet"); - - String v = (String)atts.get("codebase"); + + String v = atts.get("codebase"); if (v != null) { out.print(" codebase=\"" + v + "\""); } - - v = (String)atts.get("code"); + + v = atts.get("code"); if (v == null) { v = "applet.class"; } out.print(" code=\"" + v + "\""); - v = (String)atts.get("width"); + v = atts.get("width"); if (v == null) { v = "150"; } out.print(" width=" + v); - - v = (String)atts.get("height"); + + v = atts.get("height"); if (v == null) { v = "100"; } out.print(" height=" + v); - - v = (String)atts.get("name"); + + 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 e = atts.keys() ; e.hasMoreElements() ;) { - String param = (String)e.nextElement(); + 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; - } + 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) { @@ -1542,19 +1546,19 @@ import com.sun.jndi.toolkit.url.UrlUtil; } out.println("</applet>"); } - + /** * Make sure the atrributes are uptodate. */ - public void updateAtts() { - Dimension d = panel.size(); - Insets in = panel.insets(); - panel.atts.put("width", - new Integer(d.width - (in.left + in.right)).toString()); - panel.atts.put("height", - new Integer(d.height - (in.top + in.bottom)).toString()); - } - + public void updateAtts() { + Dimension d = panel.getSize(); + Insets in = panel.getInsets(); + panel.atts.put("width", + 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. */ @@ -1564,7 +1568,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; panel.sendEvent(AppletPanel.APPLET_INIT); panel.sendEvent(AppletPanel.APPLET_START); } - + /** * Reload the applet. */ @@ -1572,14 +1576,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; panel.sendEvent(AppletPanel.APPLET_STOP); panel.sendEvent(AppletPanel.APPLET_DESTROY); panel.sendEvent(AppletPanel.APPLET_DISPOSE); - + /** - * Fixed #4501142: Classlaoder sharing policy doesn't + * 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. @@ -1590,37 +1594,37 @@ import com.sun.jndi.toolkit.url.UrlUtil; } catch (InterruptedException e) { return; // abort the reload } - - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + + 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 @@ -1631,7 +1635,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; p.sendEvent(AppletPanel.APPLET_DISPOSE); p.sendEvent(AppletPanel.APPLET_QUIT); } - + /** * Close this viewer. * Stop, Destroy, Dispose and Quit an AppletView, then @@ -1657,7 +1661,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; dispose(); if (tg.activeCount() > 0) - tg.stop(); + tg.stop(); if (countApplets() == 0) { appletSystemExit(); @@ -1668,24 +1672,24 @@ 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 + // 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. @@ -1693,39 +1697,39 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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(); + c[0] = in.read(); } } - + /** * Scan identifier */ public static String scanIdentifier(int[] c, Reader in) throws IOException { - StringBuffer buf = new StringBuffer(); - - 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(); - } - } + 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 { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); boolean commentHeaderPassed = false; c[0] = in.read(); buf.append((char)c[0]); @@ -1758,42 +1762,42 @@ import com.sun.jndi.toolkit.url.UrlUtil; buf.append((char)c[0]); } } - + /** * Scan tag */ - public static Hashtable scanTag(int[] c, Reader in) throws IOException { - Hashtable atts = new Hashtable(); - skipSpace(c, in); + 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(); - } - StringBuffer buf = new StringBuffer(); + 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') && + (((quote < 0) && (c[0] != ' ') && (c[0] != '\t') && (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(); - } + || ((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(); + } - 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) || @@ -1804,10 +1808,10 @@ import com.sun.jndi.toolkit.url.UrlUtil; c[0] = in.read(); } //skipSpace(in); - } - return atts; + } + return atts; } - + // private static final == inline private static final boolean isInt(Object o) { boolean isInt = false; @@ -1820,15 +1824,15 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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) { try { @@ -1839,7 +1843,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; encoding = r.getEncoding(); return new BufferedReader(r); } - + /** * Scan an html file for <applet> tags */ @@ -1848,35 +1852,27 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 IOException { - + 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; - PrivilegedAction pa = new PrivilegedAction() { - public Object run() { - try { - parse(fIdentifier, fHandle, fWidth, fHeight, fIn, fUrl, System.out, new PluginAppletPanelFactory()); - } catch (IOException ioe) { - return ioe; - } + AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { + public Void run() throws IOException { + parse(fIdentifier, fHandle, fWidth, fHeight, fIn, fUrl, + System.out, new PluginAppletPanelFactory()); return null; } - }; - - Object ret = AccessController.doPrivileged(pa); - if (ret instanceof IOException) { - throw (IOException) ret; - } + }); } - - public static void parse(int identifier, long handle, String width, - String height, Reader in, URL url, + + public static void parse(int identifier, long handle, String width, + String height, Reader in, URL url, PrintStream statusMsgStream, PluginAppletPanelFactory factory) throws IOException @@ -1888,8 +1884,8 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 + // 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]; @@ -1914,7 +1910,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; url = conn.getURL(); int ydisp = 1; - Hashtable atts = null; + Hashtable<String,String> atts = null; while(true) { c[0] = in.read(); @@ -1944,11 +1940,11 @@ import com.sun.jndi.toolkit.url.UrlUtil; // 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! @@ -1968,8 +1964,8 @@ import com.sun.jndi.toolkit.url.UrlUtil; else { String nm = scanIdentifier(c, in); if (nm.equalsIgnoreCase("param")) { - Hashtable t = scanTag(c, in); - String att = (String)t.get("name"); + Hashtable<String,String> t = scanTag(c, in); + String att = t.get("name"); if (atts.containsKey(att)) continue; @@ -1977,7 +1973,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; if (att == null) { statusMsgStream.println(requiresNameWarning); } else { - String val = (String)t.get("value"); + String val = t.get("value"); if (val == null) { statusMsgStream.println(requiresNameWarning); } else if (atts != null) { @@ -1993,13 +1989,14 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 && !((String) atts.get("classid")).startsWith("clsid:")) { + 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 && ((String) atts.get("code")).startsWith("java:")) { - atts.put("code", ((String) atts.get("code")).substring(5)); + 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) { @@ -2010,7 +2007,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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); } @@ -2025,19 +2022,20 @@ import com.sun.jndi.toolkit.url.UrlUtil; } // If there is a classid and no code tag present, transform it to code tag - if (atts.get("code") == null && atts.get("classid") != null && !((String) atts.get("classid")).startsWith("clsid:")) { + 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 && ((String) atts.get("code")).startsWith("java:")) { - atts.put("code", ((String) atts.get("code")).substring(5)); + 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", ((String) atts.get("java_code"))); + atts.put("code", (atts.get("java_code"))); } if (atts.containsKey("code")) { @@ -2045,25 +2043,25 @@ import com.sun.jndi.toolkit.url.UrlUtil; } if (atts.get("java_codebase") != null) { - atts.put("codebase", ((String) atts.get("java_codebase"))); + atts.put("codebase", (atts.get("java_codebase"))); } if (atts.get("java_archive") != null) { - atts.put("archive", ((String) atts.get("java_archive"))); + atts.put("archive", (atts.get("java_archive"))); } if (atts.get("java_object") != null) { - atts.put("object", ((String) atts.get("java_object"))); + atts.put("object", (atts.get("java_object"))); } if (atts.get("java_type") != null) { - atts.put("type", ((String) atts.get("java_type"))); + 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); } @@ -2073,46 +2071,47 @@ import com.sun.jndi.toolkit.url.UrlUtil; 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 && !((String) atts.get("classid")).startsWith("clsid:")) { + 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 && ((String) atts.get("code")).startsWith("java:")) { - atts.put("code", ((String) atts.get("code")).substring(5)); + 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", ((String) atts.get("java_code"))); + atts.put("code", (atts.get("java_code"))); } - + if (atts.get("java_codebase") != null) { - atts.put("codebase", ((String) atts.get("java_codebase"))); + atts.put("codebase", (atts.get("java_codebase"))); } - + if (atts.get("java_archive") != null) { - atts.put("archive", ((String) atts.get("java_archive"))); + atts.put("archive", (atts.get("java_archive"))); } - + if (atts.get("java_object") != null) { - atts.put("object", ((String) atts.get("java_object"))); + atts.put("object", (atts.get("java_object"))); } - + if (atts.get("java_type") != null) { - atts.put("type", ((String) atts.get("java_type"))); + 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); } @@ -2126,7 +2125,7 @@ import com.sun.jndi.toolkit.url.UrlUtil; private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer"); - + private static void checkConnect(URL url) { SecurityManager security = System.getSecurityManager(); @@ -2148,21 +2147,21 @@ import com.sun.jndi.toolkit.url.UrlUtil; * {@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 + * 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 (); - } + // 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); + // Paint off-screen + paint(bufFrameImgGraphics); - // Draw the painted image - g.drawImage(bufFrameImg, 0, 0, this); + // Draw the painted image + g.drawImage(bufFrameImg, 0, 0, this); } } diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java index 6c83ffd..6c4b1f4 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMain.java +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java @@ -88,136 +88,136 @@ public class PluginMain 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; - - // This is used in init(). Getting rid of this is desirable but depends + 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. public static final String theVersion = System.getProperty("java.version"); - + private PluginAppletSecurityContext securityContext; /** * 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]); - } 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); - } + try { + 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); + } } public PluginMain(String inPipe, String outPipe) { - - connect(inPipe, outPipe); + + connect(inPipe, outPipe); // must be called before JNLPRuntime.initialize() JNLPRuntime.setRedirectStreams(redirectStreams); - securityContext = new PluginAppletSecurityContext(0); - securityContext.prePopulateLCClasses(); - securityContext.setStreamhandler(streamHandler); - AppletSecurityContextManager.addContext(0, securityContext); + securityContext = new PluginAppletSecurityContext(0); + securityContext.prePopulateLCClasses(); + securityContext.setStreamhandler(streamHandler); + AppletSecurityContextManager.addContext(0, securityContext); - PluginAppletViewer.setStreamhandler(streamHandler); - PluginAppletViewer.setPluginCallRequestFactory(new PluginCallRequestFactory()); + PluginAppletViewer.setStreamhandler(streamHandler); + PluginAppletViewer.setPluginCallRequestFactory(new PluginCallRequestFactory()); - init(); + 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(); - } - } - - 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 = (String) 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() - .getProperty(DeploymentConfiguration.KEY_SECURITY_INSTALL_AUTHENTICATOR)); - if (installAuthenticator) { - Authenticator.setDefault(new JNLPAuthenticator()); - } + 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); + } + + // 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()); + } // override the proxy selector set by JNLPRuntime ProxySelector.setDefault(new PluginProxySelector()); - + CookieManager ckManager = new PluginCookieManager(); CookieHandler.setDefault(ckManager); - } + } static boolean messageAvailable() { - return streamHandler.messageAvailable(); + return streamHandler.messageAvailable(); } static String getMessage() { - return streamHandler.getMessage(); + return streamHandler.getMessage(); } - + } diff --git a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java index b744744..9960211 100644 --- a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java +++ b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java @@ -43,9 +43,9 @@ import java.io.*; public class PluginObjectStore { - private static HashMap<Integer, Object> objects = new HashMap(); - private static HashMap<Integer, Integer> counts = new HashMap(); - private static HashMap<Object, Integer> identifiers = new HashMap(); + 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 = @@ -70,16 +70,16 @@ public class PluginObjectStore return 0; return identifiers.get(object); } - + public boolean contains(Object object) { - if (object == null) - return identifiers.containsKey(object); + if (object == null) + return identifiers.containsKey(object); - return false; + return false; } - + public boolean contains(int identifier) { - return objects.containsKey(identifier); + return objects.containsKey(identifier); } public void reference(Object object) { @@ -122,11 +122,11 @@ 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/PluginProxySelector.java b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java index f6a096f..36236ba 100644 --- a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java +++ b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java @@ -49,20 +49,20 @@ import net.sourceforge.jnlp.runtime.JNLPProxySelector; /** * Proxy selector implementation for plugin network functions. - * - * This class fetches proxy information from the web browser and - * uses that information in the context of all network connection + * + * This class fetches proxy information from the web browser and + * uses that information in the context of all network connection * (plugin specific and applet connections) as applicable - * + * */ public class PluginProxySelector extends JNLPProxySelector { - private TimedHashMap<String, Proxy> proxyCache = new TimedHashMap<String, Proxy>(); + private TimedHashMap<String, Proxy> proxyCache = new TimedHashMap<String, Proxy>(); /** * Selects the appropriate proxy (or DIRECT connection method) for the given URI - * + * * @param uri The URI being accessed * @return A list of Proxy objects that are usable for this URI */ @@ -87,11 +87,11 @@ public class PluginProxySelector extends JNLPProxySelector { if (o != null) { PluginDebug.debug("Proxy URI = " + o); URI proxyURI = (URI) o; - + // If origin uri is http/ftp, we're good. If origin uri is not that, the proxy _must_ be socks, else we fallback to direct if (uri.getScheme().startsWith("http") || uri.getScheme().equals("ftp") || proxyURI.getScheme().startsWith("socks")) { - Proxy.Type type = proxyURI.getScheme().equals("http") ? Proxy.Type.HTTP : Proxy.Type.SOCKS; + Proxy.Type type = proxyURI.getScheme().equals("http") ? Proxy.Type.HTTP : Proxy.Type.SOCKS; InetSocketAddress socketAddr = new InetSocketAddress(proxyURI.getHost(), proxyURI.getPort()); proxy = new Proxy(type, socketAddr); @@ -113,14 +113,14 @@ public class PluginProxySelector extends JNLPProxySelector { return proxyList; } - /** - * Checks to see if proxy information is already cached. - * + /** + * Checks to see if proxy information is already cached. + * * @param uri The URI to check - * @return The cached Proxy. null if there is no suitable cached proxy. + * @return The cached Proxy. null if there is no suitable cached proxy. */ private Proxy checkCache(URI uri) { - + String uriKey = uri.getScheme() + "://" + uri.getHost(); if (proxyCache.get(uriKey) != null) { return proxyCache.get(uriKey); @@ -128,10 +128,10 @@ public class PluginProxySelector extends JNLPProxySelector { return null; } - + /** * Simple utility class that extends HashMap by adding an expiry to the entries. - * + * * This map stores entries, and returns them only if the entries were last accessed within time t=10 seconds * * @param <K> The key type @@ -142,10 +142,10 @@ public class PluginProxySelector extends JNLPProxySelector { HashMap<K, Long> timeStamps = new HashMap<K, Long>(); Long expiry = 10000L; - + /** * Store the item in the map and associate a timestamp with it - * + * * @param key The key * @param value The value to store */ @@ -156,12 +156,13 @@ public class PluginProxySelector extends JNLPProxySelector { /** * Return cached item if it has not already expired. - * - * Before returning, this method also resets the "last accessed" + * + * Before returning, this method also resets the "last accessed" * time for this entry, so it is good for another 10 seconds - * + * * @param key The key */ + @SuppressWarnings("unchecked") public V get(Object key) { Long now = new Date().getTime(); @@ -169,7 +170,7 @@ public class PluginProxySelector extends JNLPProxySelector { if (super.containsKey(key)) { Long age = now - timeStamps.get(key); - // Item exists. If it has not expired, renew its access time and return it + // Item exists. If it has not expired, renew its access time and return it if (age <= expiry) { PluginDebug.debug("Returning proxy " + super.get(key) + " from cache for " + key); timeStamps.put((K) key, (new Date()).getTime()); @@ -177,10 +178,10 @@ public class PluginProxySelector extends JNLPProxySelector { } else { PluginDebug.debug("Proxy cache for " + key + " has expired (age=" + age/1000.0 + " seconds)"); } - } + } return null; } } - + } |