changeset 1902:0424d3023049

Added support for JSObject.finalize() 2010-03-16 Deepak Bhole <dbhole@redhat.com> * plugin/icedteanp/IcedTeaPluginRequestProcessor.cc (newMessageOnBus): Added support for finalize. (finalize): New function. Decrements object reference count by one. (queue_processor): Added support for finalize. * plugin/icedteanp/IcedTeaPluginRequestProcessor.h: Removed unused function declerations. Added decleration for finalize.
author Deepak Bhole <dbhole@redhat.com>
date Tue, 16 Mar 2010 10:29:49 -0400
parents 0ebb8329d845
children 7f0427a81b5b
files ChangeLog plugin/icedteanp/IcedTeaPluginRequestProcessor.cc plugin/icedteanp/IcedTeaPluginRequestProcessor.h
diffstat 3 files changed, 66 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 15 13:35:18 2010 -0400
+++ b/ChangeLog	Tue Mar 16 10:29:49 2010 -0400
@@ -1,3 +1,12 @@
+2010-03-16  Deepak Bhole <dbhole@redhat.com>
+
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
+	(newMessageOnBus): Added support for finalize.
+	(finalize): New function. Decrements object reference count by one.
+	(queue_processor): Added support for finalize.
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.h: Removed unused
+	function declerations. Added decleration for finalize.
+
 2010-03-13  Deepak Bhole <dbhole@redhat.com>
 
 	* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
--- a/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Mon Mar 15 13:35:18 2010 -0400
+++ b/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Tue Mar 16 10:29:49 2010 -0400
@@ -119,7 +119,8 @@
                    command == "Call"      ||
                    command == "GetSlot"   ||
                    command == "SetSlot"   ||
-                   command == "Eval")
+                   command == "Eval"      ||
+                   command == "Finalize")
         {
 
             // Update queue synchronously
@@ -665,6 +666,53 @@
     pthread_mutex_unlock(&tc_mutex);
 }
 
+/**
+ * Decrements reference count to given object
+ *
+ * @param message_parts The request message.
+ */
+
+void
+PluginRequestProcessor::finalize(std::vector<std::string>* message_parts)
+{
+    std::string type;
+    std::string command;
+    int reference;
+    std::string response = std::string();
+    std::string variant_ptr_str = std::string();
+    NPVariant* variant_ptr;
+    NPObject* window_ptr;
+    int id;
+
+    type = message_parts->at(0);
+    id = atoi(message_parts->at(1).c_str());
+    reference = atoi(message_parts->at(3).c_str());
+    variant_ptr_str = message_parts->at(5);
+
+    NPP instance;
+    get_instance_from_id(id, instance);
+
+    variant_ptr = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(variant_ptr_str);
+    window_ptr = NPVARIANT_TO_OBJECT(*variant_ptr);
+    browser_functions.releaseobject(window_ptr);
+
+    // remove reference
+    IcedTeaPluginUtilities::removeInstanceID(variant_ptr);
+
+    // clear memory
+    free(variant_ptr);
+
+    // We need the context 0 for backwards compatibility with the Java side
+    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &response);
+    response += " JavaScriptFinalize";
+
+    plugin_to_java_bus->post(response.c_str());
+
+    delete message_parts;
+
+}
+
+
 void*
 queue_processor(void* data)
 {
@@ -726,6 +774,12 @@
                 pthread_mutex_lock(&syn_write_mutex);
                 processor->setMember(message_parts);
                 pthread_mutex_unlock(&syn_write_mutex);
+            } else if (command == "Finalize")
+            {
+                // write methods are synchronized
+                pthread_mutex_lock(&syn_write_mutex);
+                processor->finalize(message_parts);
+                pthread_mutex_unlock(&syn_write_mutex);
             } else
             {
                 // Nothing matched
--- a/plugin/icedteanp/IcedTeaPluginRequestProcessor.h	Mon Mar 15 13:35:18 2010 -0400
+++ b/plugin/icedteanp/IcedTeaPluginRequestProcessor.h	Tue Mar 16 10:29:49 2010 -0400
@@ -72,14 +72,6 @@
 /* Internal request reference counter */
 static long internal_req_ref_counter;
 
-// JS request processor methods
-static void* requestFromMainThread();
-static void* getSlot(void* tdata);
-static void* setSlot(void* tdata);
-static void* removeMember(void* tdata);
-static void* call(void* tdata);
-static void* finalize(void* tdata);
-
 /* Given a value and type, performs the appropriate Java->JS type
  * mapping and puts it in the given variant */
 
@@ -147,6 +139,8 @@
         /* Evaluate the given script */
         void call(std::vector<std::string>* message_parts);
 
+        /* Decrements reference count for given object */
+        void finalize(std::vector<std::string>* message_parts);
 };
 
 #endif // __ICEDTEAPLUGINREQUESTPROCESSOR_H__