changeset in /hg/icedtea: - Added support for FindClass, GetClas...

Deepak Bhole dbhole at redhat.com
Tue Aug 4 09:07:41 PDT 2009


changeset e808c63fb3a3 in /hg/icedtea
details: http://icedtea.classpath.org/hg/icedtea?cmd=changeset;node=e808c63fb3a3
description:
	- Added support for FindClass, GetClassName, GetMethodID, GetToStringValue,
	  NewObject and  NewStringUTF.
	- Split the request wait code in Java processor into a generic function.
	- Centralized all debug output calls.
	- ICEDTEAPLUGIN_DEBUG flag now supported.
	- Dynamic cookie fetching support ported over from current plugin.
	- Added support for modifying JS objects via SetMember calls.
	- Message processing model made more robust by using dedicated processing
	  threads, rather than dynamically initialized threads.

	With this commit,
	http://www.apl.jhu.edu/~hall/CWP-Sources/CWP-Examples/Chapter19/Everest.html
	now works.

diffstat:

12 files changed, 1577 insertions(+), 552 deletions(-)
ChangeLog                                                         |   23 
plugin/icedteanp/IcedTeaJavaRequestProcessor.cc                   |  258 ++
plugin/icedteanp/IcedTeaJavaRequestProcessor.h                    |   34 
plugin/icedteanp/IcedTeaNPPlugin.cc                               |  371 ++--
plugin/icedteanp/IcedTeaNPPlugin.h                                |   15 
plugin/icedteanp/IcedTeaPluginRequestProcessor.cc                 |  866 ++++++----
plugin/icedteanp/IcedTeaPluginRequestProcessor.h                  |   47 
plugin/icedteanp/IcedTeaPluginUtils.cc                            |  145 +
plugin/icedteanp/IcedTeaPluginUtils.h                             |   15 
plugin/icedteanp/IcedTeaRunnable.cc                               |   74 
plugin/icedteanp/IcedTeaRunnable.h                                |  102 +
plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java |  179 +-

diffs (truncated from 3025 to 500 lines):

diff -r 358aefef4fb5 -r e808c63fb3a3 ChangeLog
--- a/ChangeLog	Tue Jul 14 13:12:50 2009 -0400
+++ b/ChangeLog	Thu Jul 23 11:39:18 2009 -0400
@@ -1,3 +1,26 @@ 2009-07-14  Deepak Bhole  <dbhole at redhat
+2009-07-23  Deepak Bhole  <dbhole at redhat.com>
+
+	* plugin/icedteanp/IcedTeaJavaRequestProcessor.c: Added support for
+	FindClass, GetClassName, GetMethodID, GetToStringValue, NewObject and 
+	NewStringUTF. Split the request wait code into a generic function.
+	* plugin/icedteanp/IcedTeaNPPlugin.cc: Centralize debug output calls. Obey
+	the ICEDTEAPLUGIN_DEBUG flag. Support dynamic cookie fetching.
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.c: Update multi-threaded
+	processing model. Support SetMember. Set up a dedicated message queue
+	processor (arbitrarily scalable).
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.h: Add function and
+	variable declerations as needed by the .cc file.
+	* plugin/icedteanp/IcedTeaPluginUtils.cc: Use only long and long long for
+	memory address translation. Add additional utility methods.
+	* plugin/icedteanp/IcedTeaPluginUtils.h: Update as needed by the .cc file.
+	* plugin/icedteanp/IcedTeaRunnable.h: New file. Represents a dispatchable
+	event, extends nsIRunnable.
+	* plugin/icedteanp/IcedTeaRunnable.h: New file. Header for
+	IcedTeaRunnable.cc.
+	* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java: Fix
+	signature handling to remove the need for return type. Add support for
+	GetToStringValue and GetClassName.
+
 2009-07-14  Deepak Bhole  <dbhole at redhat.com>
 
 	* Makefile.am: Fix npplugin build.
diff -r 358aefef4fb5 -r e808c63fb3a3 plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Tue Jul 14 13:12:50 2009 -0400
+++ b/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Thu Jul 23 11:39:18 2009 -0400
@@ -67,7 +67,8 @@ JavaRequestProcessor::newMessageOnBus(co
 			// Gather the results
 
 			// GetStringUTFChars
-			if (message_parts->at(4) == "GetStringUTFChars")
+			if (message_parts->at(4) == "GetStringUTFChars" ||
+				message_parts->at(4) == "GetToStringValue")
 			{
 				// first item is length, and it is radix 10
 				int length = strtol(message_parts->at(5).c_str(), NULL, 10);
@@ -81,6 +82,31 @@ JavaRequestProcessor::newMessageOnBus(co
 				int length = strtol(message_parts->at(5).c_str(), NULL, 10);
 
 				IcedTeaPluginUtilities::getUTF16LEString(length, 6 /* start at */, message_parts, result->return_wstring);
+				result_ready = true;
+			} else if (message_parts->at(4) == "FindClass")
+			{
+				result->return_identifier = atoi(message_parts->at(5).c_str());
+				result->return_string->append(message_parts->at(5)); // store it as a string as well, for easy access
+				result_ready = true;
+			} else if (message_parts->at(4) == "GetClassName")
+			{
+				result->return_identifier = atoi(message_parts->at(5).c_str());
+				result->return_string->append(message_parts->at(5));  // store it as a string as well, for easy access
+				result_ready = true;
+			} else if (message_parts->at(4) == "GetMethodID")
+			{
+				result->return_identifier = atoi(message_parts->at(5).c_str());
+				result->return_string->append(message_parts->at(5)); // store it as a string as well, for easy access
+				result_ready = true;
+			} else if (message_parts->at(4) == "NewObject")
+			{
+				result->return_identifier = atoi(message_parts->at(5).c_str());
+				result->return_string->append(message_parts->at(5)); // store it as a string as well, for easy access
+				result_ready = true;
+			} else if (message_parts->at(4) == "NewStringUTF")
+			{
+				result->return_identifier = atoi(message_parts->at(5).c_str());
+				result->return_string->append(message_parts->at(5));  // store it as a string as well, for easy access
 				result_ready = true;
 			}
 
@@ -119,6 +145,8 @@ JavaRequestProcessor::JavaRequestProcess
 
 JavaRequestProcessor::~JavaRequestProcessor()
 {
+    PLUGIN_DEBUG_0ARG("JavaRequestProcessor::~JavaRequestProcessor\n");
+
 	if (result)
 	{
 		if (result->error_msg)
@@ -134,32 +162,12 @@ JavaRequestProcessor::~JavaRequestProces
 	}
 }
 
-/**
- * Given a string id, fetches the actual string from Java side
- *
- * @param request_data The JavaRequest struct containing request relevant information
- * @return A JavaResultData struct containing the result of the request
- */
-
-JavaResultData*
-JavaRequestProcessor::getString(JavaRequest* request_data)
-{
-	std::string string_id;
-	std::string* message;
-
-	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
-	this->reference = IcedTeaPluginUtilities::getReference();
-
-	string_id = request_data->data->at(0);
-
-	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
-
-    message->append(" GetStringUTFChars "); // get it in UTF8
-    message->append(string_id);
-
+void
+JavaRequestProcessor::postAndWaitForResponse(std::string* message)
+{
     struct timespec t;
     clock_gettime(CLOCK_REALTIME, &t);
-    t.tv_sec += 60; // 1 minute timeout
+    t.tv_sec += REQUESTTIMEOUT; // 1 minute timeout
 
     result_ready = false;
     java_to_plugin_bus->subscribe(this);
@@ -174,7 +182,7 @@ JavaRequestProcessor::getString(JavaRequ
         bool timedout = false;
 
 		if (!result_ready && (curr_t.tv_sec < t.tv_sec))
-			sleep(1);
+			usleep(2000);
 		else
 			break;
 
@@ -187,9 +195,195 @@ JavaRequestProcessor::getString(JavaRequ
     }
 
     java_to_plugin_bus->unSubscribe(this);
-	IcedTeaPluginUtilities::releaseReference();
-
-    delete message;
-
-	return result;
-}
+}
+
+/**
+ * Given an object id, fetches the toString() value from Java
+ *
+ * @param object_id The ID of the object
+ * @return A JavaResultData struct containing the result of the request
+ */
+
+JavaResultData*
+JavaRequestProcessor::getToStringValue(std::string object_id)
+{
+	std::string* message;
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+
+    message->append(" GetToStringValue "); // get it in UTF8
+    message->append(object_id);
+
+    postAndWaitForResponse(message);
+
+	IcedTeaPluginUtilities::releaseReference();
+    delete message;
+
+	return result;
+}
+
+/**
+ * Given a string id, fetches the actual string from Java side
+ *
+ * @param string_id The ID of the string
+ * @return A JavaResultData struct containing the result of the request
+ */
+
+JavaResultData*
+JavaRequestProcessor::getString(std::string string_id)
+{
+	std::string* message;
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+
+    message->append(" GetStringUTFChars "); // get it in UTF8
+    message->append(string_id);
+
+    postAndWaitForResponse(message);
+
+	IcedTeaPluginUtilities::releaseReference();
+    delete message;
+
+	return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::findClass(std::string name)
+{
+	std::string* message;
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+
+    message->append(" FindClass ");
+    message->append(name);
+
+    postAndWaitForResponse(message);
+
+    delete message;
+
+	return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::getClassName(std::string ID)
+{
+	std::string* message;
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+
+    message->append(" GetClassName ");
+    message->append(ID);
+
+    postAndWaitForResponse(message);
+
+    delete message;
+
+	return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::getMethodID(std::string objectID, NPIdentifier methodName,
+                                  std::vector<std::string> args)
+{
+	JavaRequestProcessor* java_request;
+	std::string* message;
+    std::string* signature;
+
+    signature = new std::string();
+    *signature += "(";
+
+    // FIXME: Need to determine how to extract array types and complex java objects
+    for (int i=0; i < args.size(); i++)
+    {
+    	*signature += args[i];
+    }
+
+    *signature += ")";
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+	*message += " GetMethodID ";
+	*message += objectID;
+	*message += " ";
+	*message += browser_functions.utf8fromidentifier(methodName);
+	*message += " ";
+	*message += *signature;
+
+	postAndWaitForResponse(message);
+
+	IcedTeaPluginUtilities::releaseReference();
+	delete signature;
+	delete message;
+
+	return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::newObject(std::string objectID, std::string methodID,
+                                  std::vector<std::string> args)
+{
+	JavaRequestProcessor* java_request;
+	std::string* message;
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+	*message += " NewObject ";
+	*message += objectID;
+	*message += " ";
+	*message += methodID;
+	*message += " ";
+
+	for (int i=0; i < args.size(); i++)
+	{
+		*message += args[i];
+		*message += " ";
+	}
+
+	postAndWaitForResponse(message);
+
+	IcedTeaPluginUtilities::releaseReference();
+	delete message;
+
+	return result;
+}
+
+JavaResultData*
+JavaRequestProcessor::newString(std::string str)
+{
+	JavaRequestProcessor* java_request;
+	std::string* utf_string = new std::string();
+	std::string* message;
+
+	IcedTeaPluginUtilities::convertStringToUTF8(&str, utf_string);
+
+	this->instance = 0; // context is always 0 (needed for java-side backwards compat.)
+	this->reference = IcedTeaPluginUtilities::getReference();
+
+	message = IcedTeaPluginUtilities::constructMessagePrefix(0, reference);
+	message->append(" NewStringUTF ");
+	message->append(*utf_string);
+
+	postAndWaitForResponse(message);
+
+	IcedTeaPluginUtilities::releaseReference();
+	delete utf_string;
+	delete message;
+
+	return result;
+}
diff -r 358aefef4fb5 -r e808c63fb3a3 plugin/icedteanp/IcedTeaJavaRequestProcessor.h
--- a/plugin/icedteanp/IcedTeaJavaRequestProcessor.h	Tue Jul 14 13:12:50 2009 -0400
+++ b/plugin/icedteanp/IcedTeaJavaRequestProcessor.h	Thu Jul 23 11:39:18 2009 -0400
@@ -45,6 +45,8 @@ exception statement from your version. *
 
 #include "IcedTeaNPPlugin.h"
 #include "IcedTeaPluginUtils.h"
+
+#define REQUESTTIMEOUT 60
 
 /*
  * This struct holds data specific to a Java operation requested by the plugin
@@ -97,11 +99,41 @@ class JavaRequestProcessor : BusSubscrib
     	bool result_ready;
     	JavaResultData* result;
 
+    	/* Post message on bus and wait */
+    	void postAndWaitForResponse(std::string* message);
+
     public:
     	JavaRequestProcessor();
     	~JavaRequestProcessor();
     	virtual bool newMessageOnBus(const char* message);
-    	JavaResultData* getString(JavaRequest* request_data);
+
+    	/* Returns the toString() value, given an object identifier */
+    	JavaResultData* getToStringValue(std::string object_id);
+
+    	/* Returns the string, given the identifier */
+    	JavaResultData* getString(std::string string_id);
+
+    	/* Returns the method ID from Java side */
+    	JavaResultData* getMethodID1(NPObject* obj, NPIdentifier methodName,
+                        std::vector<NPVariant> args);
+
+    	/* Returns the method id */
+    	JavaResultData* getMethodID(std::string objectID, NPIdentifier methodName,
+                                    std::vector<std::string> args);
+
+    	/* Creates a new object */
+    	JavaResultData* newObject(std::string objectID, std::string methodID,
+                                    std::vector<std::string> args);
+
+    	/* Returns the class ID */
+    	JavaResultData* findClass(std::string name);
+
+    	/* Returns the type class name */
+    	JavaResultData* getClassName(std::string ID);
+
+    	/* Creates a new string in the Java store */
+    	JavaResultData* newString(std::string str);
+
 };
 
 #endif /* ICEDTEAJAVAREQUESTPROCESSOR_H_ */
diff -r 358aefef4fb5 -r e808c63fb3a3 plugin/icedteanp/IcedTeaNPPlugin.cc
--- a/plugin/icedteanp/IcedTeaNPPlugin.cc	Tue Jul 14 13:12:50 2009 -0400
+++ b/plugin/icedteanp/IcedTeaNPPlugin.cc	Thu Jul 23 11:39:18 2009 -0400
@@ -70,14 +70,6 @@ exception statement from your version. *
 // Liveconnect extension
  #include "IcedTeaScriptablePluginObject.h"
 #include "IcedTeaNPPlugin.h"
-
-// Debugging macros.
-#define PLUGIN_DEBUG(message)                                           \
-  g_print ("GCJ PLUGIN: thread %p: %s\n", g_thread_self (), message)
-
-#define PLUGIN_DEBUG_TWO(first, second)                                 \
-  g_print ("GCJ PLUGIN: thread %p: %s %s\n", g_thread_self (),          \
-           first, second)
 
 // Error reporting macros.
 #define PLUGIN_ERROR(message)                                       \
@@ -180,7 +172,7 @@ NPNetscapeFuncs browser_functions;
 // Various message buses carrying information to/from Java, and internally
 MessageBus* plugin_to_java_bus = new MessageBus();
 MessageBus* java_to_plugin_bus = new MessageBus();
-MessageBus* internal_bus = new MessageBus();
+//MessageBus* internal_bus = new MessageBus();
 
 // Processor for plugin requests
 PluginRequestProcessor* plugin_req_proc = new PluginRequestProcessor();
@@ -265,6 +257,8 @@ static GPid appletviewer_pid = -1;
 static GPid appletviewer_pid = -1;
 static guint appletviewer_watch_id = -1;
 
+int plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL;
+
 // Functions prefixed by GCJ_ are instance functions.  They are called
 // by the browser and operate on instances of GCJPluginData.
 // Functions prefixed by plugin_ are static helper functions.
@@ -289,7 +283,22 @@ GCJ_New (NPMIMEType pluginType, NPP inst
          int16 argc, char* argn[], char* argv[],
          NPSavedData* saved)
 {
-  PLUGIN_DEBUG ("GCJ_New");
+  PLUGIN_DEBUG_0ARG("GCJ_New\n");
+
+  static NPObject *window_ptr;
+  NPIdentifier identifier;
+  NPVariant member_ptr;
+  browser_functions.getvalue(instance, NPNVWindowNPObject, &window_ptr);
+  identifier = browser_functions.getstringidentifier("document");
+  printf("Looking for %p %p %p (%s)\n", instance, window_ptr, identifier, "document");
+  if (!browser_functions.hasproperty(instance, window_ptr, identifier))
+  {
+	printf("%s not found!\n", "document");
+  }
+  browser_functions.getproperty(instance, window_ptr, identifier, &member_ptr);
+
+  PLUGIN_DEBUG_1ARG("Got variant %p\n", &member_ptr);
+
 
   NPError np_error = NPERR_NO_ERROR;
   GCJPluginData* data = NULL;
@@ -389,9 +398,6 @@ GCJ_New (NPMIMEType pluginType, NPP inst
   data->scriptable_plugin_object = npPluginObj;
 
   instance->pdata = data;
-
-  java_to_plugin_bus->subscribe(plugin_req_proc);
-  plugin_to_java_bus->subscribe(java_req_proc);
 
   goto cleanup_done;
 
@@ -428,7 +434,7 @@ GCJ_New (NPMIMEType pluginType, NPP inst
   g_hash_table_insert(id_to_instance_map, GINT_TO_POINTER(instance_counter), instance);
   instance_counter++;
 
-  PLUGIN_DEBUG ("GCJ_New return");
+  PLUGIN_DEBUG_0ARG ("GCJ_New return\n");
 
   return np_error;
 }
@@ -475,14 +481,14 @@ void start_jvm_if_needed()
   // clean up any older pip
   unlink (in_pipe_name);
 
-  PLUGIN_DEBUG_TWO ("GCJ_New: creating input fifo:", in_pipe_name);
+  PLUGIN_DEBUG_1ARG ("GCJ_New: creating input fifo: %s", in_pipe_name);
   if (mkfifo (in_pipe_name, 0700) == -1 && errno != EEXIST)
     {
       PLUGIN_ERROR_TWO ("Failed to create input pipe", strerror (errno));
       np_error = NPERR_GENERIC_ERROR;
       goto cleanup_in_pipe_name;
     }
-  PLUGIN_DEBUG_TWO ("GCJ_New: created input fifo:", in_pipe_name);
+  PLUGIN_DEBUG_1ARG ("GCJ_New: created input fifo: %s\n", in_pipe_name);
 
   // Create plugin-to-appletviewer pipe which we refer to as the
   // output pipe.
@@ -501,14 +507,14 @@ void start_jvm_if_needed()
   // clean up any older pip
   unlink (out_pipe_name);
 
-  PLUGIN_DEBUG_TWO ("GCJ_New: creating output fifo:", out_pipe_name);
+  PLUGIN_DEBUG_1ARG ("GCJ_New: creating output fifo: %s\n", out_pipe_name);
   if (mkfifo (out_pipe_name, 0700) == -1 && errno != EEXIST)
     {
       PLUGIN_ERROR_TWO ("Failed to create output pipe", strerror (errno));
       np_error = NPERR_GENERIC_ERROR;
       goto cleanup_out_pipe_name;
     }
-  PLUGIN_DEBUG_TWO ("GCJ_New: created output fifo:", out_pipe_name);
+  PLUGIN_DEBUG_1ARG ("GCJ_New: created output fifo: %s\n", out_pipe_name);
 
   // Start a separate appletviewer process for each applet, even if
   // there are multiple applets in the same page.  We may need to



More information about the distro-pkg-dev mailing list