/hg/icedtea6: Updates to the new NP plugin:

dbhole at icedtea.classpath.org dbhole at icedtea.classpath.org
Tue Sep 15 09:43:00 PDT 2009


changeset 260b65087a73 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=260b65087a73
author: Deepak Bhole <dbhole at redhat.com>
date: Tue Sep 15 12:47:59 2009 -0400

	Updates to the new NP plugin:

	- Added preliminary array support (get/set from JS->Java)
	- Fixed some timing issues to make plugin faster
	- Implemented object resuse so that comparison of Java objects on JS
	side works

	 * plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
	(newMessageOnBus): Handle certain callbacks in a more uniform
	manner. (postAndWaitForResponse): Lower poll time to 200 us for
	more responsiveness. (findClass): Accept instance ID which
	is used for searching classes in specific applet instance
	classloaders. (getArrayLength): New function. Returns length of
	an array on Java side. (getSlot): New function. Returns element
	at requested index in an array. (setSlot): New function. Sets
	requested index in array to supplied value. (getField): Accept
	object id. (getStaticField): Fix parameter ordering for
	consistency. (set): New function. Sets Java side fields to given
	value. (setStaticField): New function. Sets value of a static
	field in a Java object. (setField): New function. Sets value
	of a static field in a class. (createJavaObjectFromVariant):
	Handle void and null variants. Handle case where object is
	already created. (call): Use a string to store object id.
	(newObject): Same. (hasPackage): Accept instance id and pass it
	on.
	    * plugin/icedteanp/IcedTeaJavaRequestProcessor.h: Relevant changes as
	needed by the updates to the .cc file.
	    * plugin/icedteanp/IcedTeaNPPlugin.cc (get_scriptable_object):
	Pass false for the new isArray arg to
	get_scriptable_java_object.
	    * plugin/icedteanp/IcedTeaPluginRequestProcessor.cc: Pass 0 as the
	instance id to all findClass calls.
	    * plugin/icedteanp/IcedTeaScriptablePluginObject.cc: Reuse Java object
	pointers. (IcedTeaScriptableJavaPackageObject::hasProperty):
	Pass the instance id to findClass.
	(get_scriptable_java_object): Update code so that Java object
	pointers can be reused.
	(IcedTeaScriptableJavaObject::setIsArray): New function. Sets if
	this object represents an array.
	(IcedTeaScriptableJavaObject::getIsArray): New function. Returns if
	this object represents an array.
	(IcedTeaScriptableJavaObject::hasMethod): Bypass "array indexes"
	passed to the method.
	(IcedTeaScriptableJavaObject::javaResultToNPVariant): Handle void
	and null values correctly. Handle array objects.
	(IcedTeaScriptableJavaObject::invoke): Set exceptions in JS engine
	if one occurred on Java side.
	(IcedTeaScriptableJavaObject::hasProperty): Handle array length and
	index properties.
	(IcedTeaScriptableJavaObject::getProperty): Same.
	(IcedTeaScriptableJavaObject::setProperty): Add support for setting
	array index values.
	    * plugin/icedteanp/IcedTeaScriptablePluginObject.h: Changes as
	necessitated by changes to the .cc file.
	    * plugin/icedteanp/java/sun/applet/JavaConsole.java: Handle changed
	API in PluginAppletSecurityContext.
	    * plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
	(getMatchingMethod): Handle un-castable/deferred casts.
	(getMatchingConstructor): Same. (getNum): Fix handling for
	characters.
	    * plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
	(associateInstance): New function. Associated a loader with an
	instance. (getLoaderInfo): New function. Returns loader info in
	a map. (handleMessage): Look for class in instance specific
	loaders as well. Handle float/double precision upto 308 (E308 is
	max for double).
	    * plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
	(AppletEventListener::appletStateChanged): Fix race condition during
	initialization. (handleMessage): Fix race condition to handle
	GetJavaObject calls when panel is still being initialized.


diffstat:

11 files changed, 893 insertions(+), 360 deletions(-)
ChangeLog                                                         |   69 +
plugin/icedteanp/IcedTeaJavaRequestProcessor.cc                   |  250 ++++-
plugin/icedteanp/IcedTeaJavaRequestProcessor.h                    |   42 
plugin/icedteanp/IcedTeaNPPlugin.cc                               |   10 
plugin/icedteanp/IcedTeaPluginRequestProcessor.cc                 |   24 
plugin/icedteanp/IcedTeaScriptablePluginObject.cc                 |  457 +++++++---
plugin/icedteanp/IcedTeaScriptablePluginObject.h                  |   20 
plugin/icedteanp/java/sun/applet/JavaConsole.java                 |    8 
plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java      |   14 
plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java |  287 +++---
plugin/icedteanp/java/sun/applet/PluginAppletViewer.java          |   72 +

diffs (truncated from 2062 to 500 lines):

diff -r 419024238732 -r 260b65087a73 ChangeLog
--- a/ChangeLog	Tue Sep 15 07:54:59 2009 -0400
+++ b/ChangeLog	Tue Sep 15 12:47:59 2009 -0400
@@ -1,3 +1,72 @@ 2009-09-15  Gary Benson  <gbenson at redhat
+2009-09-15  Deepak Bhole  <dbhole at redhat.com>
+
+	* plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
+	(newMessageOnBus): Handle certain callbacks in a more uniform manner.
+	(postAndWaitForResponse): Lower poll time to 200 us for more
+	responsiveness.
+	(findClass): Accept instance ID which is used for searching classes in
+	specific applet instance classloaders.
+	(getArrayLength): New function. Returns length of an array on Java side.
+	(getSlot): New function. Returns element at requested index in an array.
+	(setSlot): New function. Sets requested index in array to supplied value.
+	(getField): Accept object id.
+	(getStaticField): Fix parameter ordering for consistency.
+	(set): New function. Sets Java side fields to given value.
+	(setStaticField): New function. Sets value of a static field in a Java
+	object.
+	(setField): New function. Sets value of a static field in a class.
+	(createJavaObjectFromVariant): Handle void and null variants. Handle case
+	where object is already created.
+	(call): Use a string to store object id.
+	(newObject): Same.
+	(hasPackage): Accept instance id and pass it on.
+	* plugin/icedteanp/IcedTeaJavaRequestProcessor.h: Relevant changes as
+	needed by the updates to the .cc file.
+	* plugin/icedteanp/IcedTeaNPPlugin.cc
+	(get_scriptable_object): Pass false for the new isArray arg to
+	get_scriptable_java_object.
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc: Pass 0 as the
+	instance id to all findClass calls.
+	* plugin/icedteanp/IcedTeaScriptablePluginObject.cc: Reuse Java object
+	pointers.
+	(IcedTeaScriptableJavaPackageObject::hasProperty): Pass the instance id to
+	findClass.
+	(get_scriptable_java_object): Update code so that Java object pointers can
+	be reused.
+	(IcedTeaScriptableJavaObject::setIsArray): New function. Sets if this object 
+	represents an array.
+	(IcedTeaScriptableJavaObject::getIsArray): New function. Returns if this
+	object represents an array.
+	(IcedTeaScriptableJavaObject::hasMethod): Bypass "array indexes" passed to
+	the method.
+	(IcedTeaScriptableJavaObject::javaResultToNPVariant): Handle void and null
+	values correctly. Handle array objects.
+	(IcedTeaScriptableJavaObject::invoke): Set exceptions in JS engine if one
+	occurred on Java side.
+	(IcedTeaScriptableJavaObject::hasProperty): Handle array length and index
+	properties.
+	(IcedTeaScriptableJavaObject::getProperty): Same.
+	(IcedTeaScriptableJavaObject::setProperty): Add support for setting array
+	index values.
+	* plugin/icedteanp/IcedTeaScriptablePluginObject.h: Changes as
+	necessitated by changes to the .cc file.
+	* plugin/icedteanp/java/sun/applet/JavaConsole.java: Handle changed API in
+	PluginAppletSecurityContext.
+	* plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java
+	(getMatchingMethod): Handle un-castable/deferred casts.
+	(getMatchingConstructor): Same.
+	(getNum): Fix handling for characters.
+	* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
+	(associateInstance): New function. Associated a loader with an instance.
+	(getLoaderInfo): New function. Returns loader info in a map.
+	(handleMessage): Look for class in instance specific loaders as well.
+	Handle float/double precision upto 308 (E308 is max for double).
+	* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+	(AppletEventListener::appletStateChanged): Fix race condition during
+	initialization.
+	(handleMessage): Fix race condition to handle GetJavaObject calls when
+	panel is still being initialized.
+
 2009-09-15  Gary Benson  <gbenson at redhat.com>
 
 	* ports/hotspot/src/cpu/zero/vm/jni_zero.h
diff -r 419024238732 -r 260b65087a73 plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Tue Sep 15 07:54:59 2009 -0400
+++ b/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Tue Sep 15 12:47:59 2009 -0400
@@ -37,6 +37,7 @@ exception statement from your version. *
 exception statement from your version. */
 
 #include "IcedTeaJavaRequestProcessor.h"
+#include "IcedTeaScriptablePluginObject.h"
 
 /*
  * This class processes LiveConnect requests from JavaScript to Java.
@@ -109,8 +110,6 @@ JavaRequestProcessor::newMessageOnBus(co
                     (message_parts->at(4) == "HasField") ||
                     (message_parts->at(4) == "GetStaticFieldID") ||
                     (message_parts->at(4) == "GetFieldID") ||
-                    (message_parts->at(4) == "GetField") ||
-                    (message_parts->at(4) == "GetStaticField") ||
                     (message_parts->at(4) == "GetJavaObject") ||
                     (message_parts->at(4) == "IsInstanceOf"))
 			{
@@ -122,7 +121,10 @@ JavaRequestProcessor::newMessageOnBus(co
 			{
 			    result_ready = true; // nothing else to do
 			} else if ((message_parts->at(4) == "CallMethod") ||
-					   (message_parts->at(4) == "CallStaticMethod"))
+					   (message_parts->at(4) == "CallStaticMethod") ||
+					   (message_parts->at(4) == "GetField") ||
+					   (message_parts->at(4) == "GetStaticField") ||
+	                   (message_parts->at(4) == "GetObjectArrayElement"))
 			{
 
 			    if (message_parts->at(5) == "literalreturn")
@@ -140,7 +142,20 @@ JavaRequestProcessor::newMessageOnBus(co
 			    }
 
 				result_ready = true;
-			}
+			} else if ((message_parts->at(4) == "GetArrayLength"))
+            {
+			    result->return_identifier = 0; // length is not an "identifier"
+			    result->return_string->append(message_parts->at(5));
+			    result_ready = true;
+            } else if ((message_parts->at(4) == "SetField") ||
+                       (message_parts->at(4) == "SetObjectArrayElement"))
+            {
+
+                // nothing to do
+
+                result->return_identifier = 0;
+                result_ready = true;
+            }
 
 			delete message_parts;
 			return true;
@@ -238,7 +253,7 @@ JavaRequestProcessor::postAndWaitForResp
 			if (g_main_context_pending(NULL))
 				g_main_context_iteration(NULL, false);
 			else
-				usleep(2000);
+				usleep(200);
 		}
 		else
 			break;
@@ -361,9 +376,13 @@ JavaRequestProcessor::addReference(std::
 }
 
 JavaResultData*
-JavaRequestProcessor::findClass(std::string name)
-{
-    std::string message = std::string();
+JavaRequestProcessor::findClass(int plugin_instance_id,
+                                std::string name)
+{
+    std::string message = std::string();
+    std::string plugin_instance_id_str = std::string();
+
+    IcedTeaPluginUtilities::itoa(plugin_instance_id, &plugin_instance_id_str);
 
 	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
 	this->reference = IcedTeaPluginUtilities::getReference();
@@ -371,6 +390,8 @@ JavaRequestProcessor::findClass(std::str
 	IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &message);
 
     message.append(" FindClass ");
+    message.append(plugin_instance_id_str);
+    message.append(" ");
     message.append(name);
 
     postAndWaitForResponse(message);
@@ -410,6 +431,72 @@ JavaRequestProcessor::getClassID(std::st
     message.append(objectID);
 
     postAndWaitForResponse(message);
+
+    return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::getArrayLength(std::string objectID)
+{
+    std::string message = std::string();
+
+    this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+    this->reference = IcedTeaPluginUtilities::getReference();
+
+    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &message);
+
+    message.append(" GetArrayLength ");
+    message.append(objectID);
+
+    postAndWaitForResponse(message);
+
+    return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::getSlot(std::string objectID, std::string index)
+{
+    std::string message = std::string();
+    this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+    this->reference = IcedTeaPluginUtilities::getReference();
+
+    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &message);
+
+    message.append(" GetObjectArrayElement ");
+    message.append(objectID);
+    message.append(" ");
+    message.append(index);
+
+    postAndWaitForResponse(message);
+
+    return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::setSlot(std::string objectID,
+                              std::string index,
+                              NPVariant value)
+{
+    std::string id = std::string();
+    std::string message = std::string();
+
+    createJavaObjectFromVariant(value, &id);
+
+    this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+    this->reference = IcedTeaPluginUtilities::getReference();
+
+    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &message);
+
+    message.append(" SetObjectArrayElement ");
+    message.append(objectID);
+    message.append(" ");
+    message.append(index);
+    message.append(" ");
+    message.append(id);
+
+    postAndWaitForResponse(message);
+
+    IcedTeaPluginUtilities::releaseReference();
 
     return result;
 }
@@ -471,6 +558,7 @@ JavaResultData*
 JavaResultData*
 JavaRequestProcessor::getField(std::string source,
                                std::string classID,
+                               std::string objectID,
                                std::string fieldName)
 {
     JavaResultData* java_result;
@@ -484,7 +572,7 @@ JavaRequestProcessor::getField(std::stri
 
     IcedTeaPluginUtilities::constructMessagePrefix(0, reference, source, &message);
     message.append(" GetField ");
-    message.append(classID);
+    message.append(objectID);
     message.append(" ");
     message.append(java_result->return_string->c_str());
 
@@ -498,7 +586,7 @@ JavaRequestProcessor::getField(std::stri
 }
 
 JavaResultData*
-JavaRequestProcessor::getStaticField(std::string classID, std::string source,
+JavaRequestProcessor::getStaticField(std::string source, std::string classID,
                                      std::string fieldName)
 {
     JavaResultData* java_result;
@@ -523,6 +611,70 @@ JavaRequestProcessor::getStaticField(std
     delete java_request;
 
     return result;
+}
+
+
+JavaResultData*
+JavaRequestProcessor::set(std::string source,
+                          bool isStatic,
+                          std::string classID,
+                          std::string objectID,
+                          std::string fieldName,
+                          NPVariant value)
+{
+    JavaResultData* java_result;
+    JavaRequestProcessor java_request = JavaRequestProcessor();
+    std::string id = std::string();
+    std::string message = std::string();
+
+    createJavaObjectFromVariant(value, &id);
+
+    java_result = java_request.getFieldID(classID, fieldName);
+
+    this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+    this->reference = IcedTeaPluginUtilities::getReference();
+
+    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, source, &message);
+
+    if (isStatic)
+    {
+        message.append(" SetStaticField ");
+        message.append(classID);
+    } else
+    {
+        message.append(" SetField ");
+        message.append(objectID);
+    }
+
+    message.append(" ");
+    message.append(java_result->return_string->c_str());
+    message.append(" ");
+    message.append(id);
+
+    postAndWaitForResponse(message);
+
+    IcedTeaPluginUtilities::releaseReference();
+
+    return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::setStaticField(std::string source,
+                                     std::string classID,
+                                     std::string fieldName,
+                                     NPVariant value)
+{
+    return set(source, true, classID, "", fieldName, value);
+}
+
+JavaResultData*
+JavaRequestProcessor::setField(std::string source,
+                               std::string classID,
+                               std::string objectID,
+                               std::string fieldName,
+                               NPVariant value)
+{
+    return set(source, false, classID, objectID, fieldName, value);
 }
 
 JavaResultData*
@@ -601,8 +753,8 @@ JavaRequestProcessor::getStaticMethodID(
     return result;
 }
 
-int
-JavaRequestProcessor::createJavaObjectFromVariant(NPVariant variant)
+void
+JavaRequestProcessor::createJavaObjectFromVariant(NPVariant variant, std::string* id)
 {
 	JavaResultData* java_result;
 
@@ -619,10 +771,14 @@ JavaRequestProcessor::createJavaObjectFr
     if (NPVARIANT_IS_VOID(variant))
     {
     	PLUGIN_DEBUG_1ARG("VOID %d\n", variant);
+    	id->append("0");
+    	return; // no need to go further
     }
     else if (NPVARIANT_IS_NULL(variant))
     {
     	PLUGIN_DEBUG_1ARG("NULL\n", variant);
+    	id->append("0");
+    	return; // no need to go further
     }
     else if (NPVARIANT_IS_BOOLEAN(variant))
     {
@@ -648,7 +804,7 @@ JavaRequestProcessor::createJavaObjectFr
     	className = "java.lang.Double";
 
     	char* valueStr = (char*) malloc(sizeof(char)*1024);
-    	sprintf(valueStr, "%d", NPVARIANT_TO_DOUBLE(variant));
+    	sprintf(valueStr, "%f", NPVARIANT_TO_DOUBLE(variant));
     	stringArg += valueStr;
     	free(valueStr);
     }
@@ -660,17 +816,24 @@ JavaRequestProcessor::createJavaObjectFr
 #else
     	stringArg += NPVARIANT_TO_STRING(variant).UTF8Characters;
 #endif
-    } else {
+    }
+    else if (browser_functions.getproperty())
+    {
+
+    }
+    else
+    {
     	alreadyCreated = true;
     }
 
     if (!alreadyCreated) {
-		java_result = java_request.findClass(className.c_str());
+		java_result = java_request.findClass(0, className.c_str());
 
 		// the result we want is in result_string (assuming there was no error)
 		if (java_result->error_occurred) {
 			printf("Unable to find classid for %s\n", className.c_str());
-			return 0;
+			id->append("0");
+			return;
 		}
 
 		jsObjectClassID.append(*(java_result->return_string));
@@ -685,7 +848,8 @@ JavaRequestProcessor::createJavaObjectFr
 		// the result we want is in result_string (assuming there was no error)
 		if (java_result->error_occurred) {
 			printf("Unable to find string constructor for %s\n", className.c_str());
-			return 0;
+			id->append("0");
+            return;
 		}
 
 		jsObjectConstructorID.append(*(java_result->return_string));
@@ -697,7 +861,8 @@ JavaRequestProcessor::createJavaObjectFr
 
 		if (java_result->error_occurred) {
 			printf("Unable to create requested object\n");
-			return 0;
+			id->append("0");
+            return;
 		}
 
 		// Create the object
@@ -709,21 +874,25 @@ JavaRequestProcessor::createJavaObjectFr
 
         if (java_result->error_occurred) {
             printf("Unable to create requested object\n");
-            return 0;
+            id->append("0");
+            return;
         }
 
 
-		return java_result->return_identifier;
-
+		id->append(*(java_result->return_string));
+
+	} else {
+	    // Else already created
+
+	    std::string classId = std::string(((IcedTeaScriptableJavaObject*) NPVARIANT_TO_OBJECT(variant))->getClassID());
+	    std::string instanceId = std::string(((IcedTeaScriptableJavaObject*) NPVARIANT_TO_OBJECT(variant))->getInstanceID());
+
+	    if (instanceId.length() == 0)
+	        id->append(classId.c_str());
+	    else
+	        id->append(instanceId.c_str());
 	}
 
-    std::string classId = std::string(((IcedTeaScriptableJavaObject*) NPVARIANT_TO_OBJECT(variant))->getClassID());
-    std::string instanceId = std::string(((IcedTeaScriptableJavaObject*) NPVARIANT_TO_OBJECT(variant))->getInstanceID());
-
-    if (instanceId.length() == 0)
-    	return atoi(classId.c_str());
-    else
-    	return atoi(instanceId.c_str());
 }
 
 JavaResultData*
@@ -766,20 +935,19 @@ JavaRequestProcessor::call(std::string s
     message += " ";
 
 	// First, we need to load the arguments into the java-side table
+    std::string id = std::string();
 	for (int i=0; i < numArgs; i++) {
-		int objectID = createJavaObjectFromVariant(args[i]);
-		if (objectID == 0)
+	    id.clear();
+		createJavaObjectFromVariant(args[i], &id);
+		if (id == "0")
 		{
 			result->error_occurred = true;
 			result->error_msg->append("Unable to create arguments");
 			return result;
 		}
 
-		char* id = (char*) malloc(sizeof(char)*32);
-		sprintf(id, "%d", objectID);
 		message += id;
 		message += " ";
-		free(id);
 	}
 
 	postAndWaitForResponse(message);
@@ -825,20 +993,19 @@ JavaRequestProcessor::newObject(std::str
     message += " ";
 
     // First, we need to load the arguments into the java-side table
+    std::string id = std::string();
     for (int i=0; i < argCount; i++) {
-        int objectID = createJavaObjectFromVariant(args[i]);
-        if (objectID == 0)
+        id.clear();
+        createJavaObjectFromVariant(args[i], &id);
+        if (id == "0")
         {
             result->error_occurred = true;
             result->error_msg->append("Unable to create arguments");
             return result;
         }
 
-        char* id = (char*) malloc(sizeof(char)*32);
-        sprintf(id, "%d", objectID);
         message += id;
         message += " ";



More information about the distro-pkg-dev mailing list