changeset 1050:30567fe7d579

- Update makefile to properly include plugin's sun.applet classes in rt.jar - Update .cc file to call new plugin main call (different hierarchy) - Added a couple of functions to the .cc file to properly recognize context
author Deepak Bhole <dbhole@redhat.com>
date Wed, 24 Sep 2008 11:35:01 -0400
parents abdb5c94757d
children f9d81fd1466d
files ChangeLog IcedTeaPlugin.cc Makefile.am
diffstat 3 files changed, 100 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 23 16:52:24 2008 -0400
+++ b/ChangeLog	Wed Sep 24 11:35:01 2008 -0400
@@ -1,4 +1,6 @@
 2008-09-23  Deepak Bhole  <dbhole@redhat.com>
+	* IcedTeaPlugin.cc: Updated to call new plugin main class. Add function to
+	correctly recognize JS context.
 	* Makefile.am: Update to create new IcedTeaPlugin.jar
 	* patches/icedtea-liveconnect.patch: Update patch and remove all new .java
 	files
--- a/IcedTeaPlugin.cc	Tue Sep 23 16:52:24 2008 -0400
+++ b/IcedTeaPlugin.cc	Wed Sep 24 11:35:01 2008 -0400
@@ -244,6 +244,7 @@
 static GError* channel_error = NULL;
 // Fully-qualified appletviewer executable.
 static char* appletviewer_executable = NULL;
+static char* extra_jars = NULL;
 static char* libjvm_so = NULL;
 
 class IcedTeaPluginFactory;
@@ -313,7 +314,10 @@
 // FIXME: create index from security context.
 #define MESSAGE_CREATE(reference)                            \
   const char* addr; \
+  char context[16]; \
   GetCurrentPageAddress(&addr); \
+  GetCurrentContextAddr(context); \
+  printf("Addr: %s , Context: %s\n", addr, context);\
 \
   nsCString message ("context ");                            \
   message.AppendInt (0);                                     \
@@ -1149,7 +1153,8 @@
 
   int IncrementContextCounter();
   void DecrementContextCounter();
-  void GetCurrentPageAddress(const char **addr);
+  nsresult GetCurrentContextAddr(char *addr);
+  nsresult GetCurrentPageAddress(const char **addr);
   int contextCounter;
 };
 
@@ -3184,9 +3189,9 @@
   PLUGIN_CHECK_RETURN ("init process", result);
 
   // FIXME: hard-coded port number.
-  char const* args[5] = { "-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n", "sun.applet.PluginMain", "50007" };
+  char const* args[8] = { "-classpath", extra_jars, "-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n", "org.classpath.icedtea.plugin.PluginMain", "50007" };
 //  char const* args[2] = { "sun.applet.PluginMain", "50007" };
-  result = applet_viewer_process->Run (PR_FALSE, args, 5, nsnull);
+  result = applet_viewer_process->Run (PR_FALSE, args, 8, nsnull);
   PLUGIN_CHECK_RETURN ("run process", result);
 
   // start processing thread
@@ -3763,6 +3768,7 @@
 #include <nsIPrincipal.h>
 #include <nsIScriptSecurityManager.h>
 #include <nsIURI.h>
+#include <xpcjsid.h>
 
 IcedTeaJNIEnv::IcedTeaJNIEnv (IcedTeaPluginFactory* factory)
 : factory (factory)
@@ -3801,17 +3807,69 @@
     PR_ExitMonitor(contextCounterPRMonitor);
 }
 
-void
+#include <nsIJSContextStack.h>
+
+nsresult
+IcedTeaJNIEnv::GetCurrentContextAddr(char *addr)
+{
+    PLUGIN_TRACE_JNIENV ();
+
+    // Get JSContext from stack.
+    nsCOMPtr<nsIJSContextStack> mJSContextStack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
+    if (mJSContextStack) {
+        JSContext *cx;
+        if (NS_FAILED(mJSContextStack->Peek(&cx)))
+            return NS_ERROR_FAILURE;
+
+        printf("Context1: %p\n", cx);
+
+        // address cannot be more than 8 bytes (8 bytes = 64 bits)
+		sprintf(addr, "%p", cx);
+
+        printf("Context2: %s\n", addr);
+	}
+
+	return NS_OK;
+}
+
+nsresult
 IcedTeaJNIEnv::GetCurrentPageAddress(const char **addr)
 {
+
+    PLUGIN_TRACE_JNIENV ();
+
     nsIPrincipal *prin;
 	nsCOMPtr<nsIScriptSecurityManager> sec_man(do_GetService("@mozilla.org/scriptsecuritymanager;1"));
 
-    sec_man->GetSubjectPrincipal(&prin);
+    if (sec_man) {
+    
+		PRBool isEnabled = PR_FALSE;
+    	sec_man->IsCapabilityEnabled("UniversalBrowserRead", &isEnabled);
+
+		if (isEnabled == PR_FALSE) {
+			printf("UniversalBrowserRead is NOT enabled\n");
+		} else {
+			printf("UniversalBrowserRead IS enabled\n");
+		}
+
+    	sec_man->IsCapabilityEnabled("UniversalBrowserWrite", &isEnabled);
+
+		if (isEnabled == PR_FALSE) {
+			printf("UniversalBrowserWrite is NOT enabled\n");
+		} else {
+			printf("UniversalBrowserWrite IS enabled\n");
+		}
+	}
+
+    if (sec_man)
+	{
+    	sec_man->GetSubjectPrincipal(&prin);
+	} else {
+		return NS_ERROR_FAILURE;
+	}
 
    if (prin)
    {
-
        nsIURI *uri;
        prin->GetURI(&uri);
 
@@ -3820,8 +3878,19 @@
            nsCAutoString str;
            uri->GetSpec(str);
            NS_CStringGetData(str, addr);
+	   } else {
+		   return NS_ERROR_FAILURE;
 	   }
+   } else {
+	   return NS_ERROR_FAILURE;
    }
+
+
+	nsCOMPtr<nsIJSID> js_id(do_GetService("@mozilla.org/js/xpc/ID;1"));
+	printf("JS ID is: %s\n", js_id->GetID()->ToString());
+
+    return NS_OK;
+
 }
 
 NS_IMETHODIMP
@@ -4846,15 +4915,24 @@
       return NS_ERROR_OUT_OF_MEMORY;
     }
   nsCString executable (dirname (filename));
+  nsCString jar(dirname (filename));
+  nsCString extrajars("");
   free (filename);
   filename = NULL;
 
   //executableString += nsCString ("/../../bin/pluginappletviewer");
   executable += nsCString ("/../../bin/java");
+  extrajars += jar;
+  extrajars += nsCString("/IcedTeaPlugin.jar");
+  extrajars += ":";
+  extrajars += jar;
+  extrajars += nsCString("/rt.jar");
+
   //executable += nsCString ("/client/libjvm.so");
 
   // Never freed.
   appletviewer_executable = strdup (executable.get ());
+  extra_jars = strdup (extrajars.get ());
   //libjvm_so = strdup (executable.get ());
   if (!appletviewer_executable)
     {
@@ -4862,6 +4940,12 @@
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
+  if (!extra_jars)
+    {
+      PLUGIN_ERROR ("Failed to create plugin jar name.");
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
+
   if (factory_created == PR_TRUE)
   {
 	  // wait for factory to initialize
--- a/Makefile.am	Tue Sep 23 16:52:24 2008 -0400
+++ b/Makefile.am	Wed Sep 24 11:35:01 2008 -0400
@@ -9,8 +9,6 @@
 NETBEANS_PROFILER_MD5SUM = ff8e8abc42df6c6749e6b02bcf7bb0a5
 VISUALVM_MD5SUM = 4b55bc623418818793392bb233da2927
 
-EXCLUDE_LIVECONNECT = | grep -vE "netscape/javascript|org/classpath/icedtea/plugin"
-
 if ENABLE_LIVECONNECT
 ICEDTEAPLUGIN_CLEAN = clean-IcedTeaPlugin
 ICEDTEAPLUGIN_TARGET = IcedTeaPlugin.so
@@ -587,6 +585,9 @@
 	  echo WARNING make clean-patch before retrying a fix ; \
 	  false; \
 	fi
+if ENABLE_LIVECONNECT
+	cp -a plugin/icedtea/sun/applet/*java openjdk/jdk/src/share/classes/sun/applet/
+endif
 
 clean-patch:
 	rm -f stamps/patch.stamp
@@ -605,6 +606,10 @@
 	if ! test x$${all_patches_ok} = "xyes" ; then \
 	  echo "WARNING Not all patches reverted cleanly" ; \
 	fi
+	for file in plugin/icedtea/sun/applet/*java ; \
+	do \
+		rm -f openjdk/jdk/src/share/classes/sun/applet/`basename $file` ; \
+	done ;
 
 stamps/patch-fsg.stamp: stamps/extract.stamp
 	mkdir -p stamps ; \
@@ -1198,7 +1203,6 @@
 # rt-closed.jar class files.
 rt-source-files.txt: stamps/extract.stamp stamps/copy-source-files.stamp
 	find $(abs_top_srcdir)/rt $(abs_top_builddir)/rt $(LIVECONNECT) -name '*.java' \
-	$(EXCLUDE_LIVECONNECT) \
 	  | sort -u > $@
 
 stamps/rt-class-files.stamp: rt-source-files.txt
@@ -1325,7 +1329,7 @@
 	mkdir -p $(BUILD_OUTPUT_DIR)/plugin/icedtea/classes
 	(cd plugin/icedtea/; \
 	  $(ICEDTEA_BOOT_DIR)/bin/javac -g \
-	  -d ../../../../../$(BUILD_OUTPUT_DIR)/plugin/icedtea/classes \
+	  -d ../../$(BUILD_OUTPUT_DIR)/plugin/icedtea/classes \
 	  -bootclasspath $(ICEDTEA_BOOT_DIR)/jre/lib/rt.jar \
 	  netscape/javascript/*.java org/classpath/icedtea/plugin/*.java \
 	)