changeset 508:ca8b00cca4c3

PR1217: Add command line arguments for plugins
author Saad Mohammad <smohammad@redhat.com>
date Thu, 04 Apr 2013 12:52:57 -0400
parents f63bdf513e9d
children 6883b7d0a2fc
files ChangeLog netx/net/sourceforge/jnlp/config/Defaults.java netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java netx/net/sourceforge/jnlp/resources/Messages.properties plugin/icedteanp/IcedTeaNPPlugin.cc plugin/icedteanp/IcedTeaPluginUtils.cc plugin/icedteanp/IcedTeaPluginUtils.h
diffstat 9 files changed, 241 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 01 13:12:21 2013 -0500
+++ b/ChangeLog	Thu Apr 04 12:52:57 2013 -0400
@@ -1,3 +1,29 @@
+2013-04-04  Saad Mohammad  <smohammad@redhat.com>
+
+	Added new option in itw-settings which allows users to set JVM
+	arguments when plugin is initialized.
+	* netx/net/sourceforge/jnlp/config/Defaults.java (getDefaults):
+	Added defaults for DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS.
+	* netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java:
+	Added new property (KEY_PLUGIN_JVM_ARGUMENTS) which stores the value of
+	JVM plugin arguments.
+	* netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java:
+	(createMainSettingsPanel): Added JVM settings to the list of tabs.
+	(createJVMSettingsPanel): Returns a new JVMPanel object.
+	* netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java:
+	JVM settings panel.
+	* netx/net/sourceforge/jnlp/resources/Messages.properties:
+	Added a new items (CPJVMPluginArguments, CPHeadJVMSettings,
+	CPTabJVMSettings).
+	* plugin/icedteanp/IcedTeaNPPlugin.cc:
+	(plugin_start_appletviewer): Adds JVM arguments to the commands line list.
+	(get_jvm_args): Returns JVM arguments set in itw-settings.
+	* plugin/icedteanp/IcedTeaPluginUtils.cc:
+	(IcedTeaPluginUtilities::vectorStringToVectorGchar): New helper method
+	which returns a vector of gchar* from the vector of strings passed.
+	* plugin/icedteanp/IcedTeaPluginUtils.h:
+	Declaration of IcedTeaPluginUtilities::vectorStringToVectorGchar.
+
 2013-03-01 Adam Domurad  <adomurad@redhat.com>
 
 	Fix PR1157: Applets can hang browser after fatal exception
--- a/netx/net/sourceforge/jnlp/config/Defaults.java	Fri Mar 01 13:12:21 2013 -0500
+++ b/netx/net/sourceforge/jnlp/config/Defaults.java	Thu Apr 04 12:52:57 2013 -0400
@@ -378,6 +378,12 @@
                         DeploymentConfiguration.KEY_UPDATE_TIMEOUT,
                         BasicValueValidators.getRangedIntegerValidator(0, 10000),
                         String.valueOf(500)
+                },
+                //JVM arguments for plugin
+                {
+                        DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS,
+                        null,
+                        null
                 }
         };
 
--- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java	Fri Mar 01 13:12:21 2013 -0500
+++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java	Thu Apr 04 12:52:57 2013 -0400
@@ -158,6 +158,11 @@
     public static final String KEY_BROWSER_PATH = "deployment.browser.path";
     public static final String KEY_UPDATE_TIMEOUT = "deployment.javaws.update.timeout";
 
+    /*
+     * JVM arguments for plugin
+     */
+    public static final String KEY_PLUGIN_JVM_ARGUMENTS= "deployment.plugin.jvm.arguments";
+
     public enum ConfigType {
         System, User
     }
--- a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java	Fri Mar 01 13:12:21 2013 -0500
+++ b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java	Thu Apr 04 12:52:57 2013 -0400
@@ -226,6 +226,7 @@
                 // new SettingsPanel(Translator.R("CPTabClassLoader"), createClassLoaderSettingsPanel()),
                 new SettingsPanel(Translator.R("CPTabDebugging"), createDebugSettingsPanel()),
                 new SettingsPanel(Translator.R("CPTabDesktopIntegration"), createDesktopSettingsPanel()),
+                new SettingsPanel(Translator.R("CPTabJVMSettings"), createJVMSettingsPanel()),
                 new SettingsPanel(Translator.R("CPTabNetwork"), createNetworkSettingsPanel()),
                 // TODO: This is commented out since this is not implemented yet
                 // new SettingsPanel(Translator.R("CPTabRuntimes"), createRuntimesSettingsPanel()),
@@ -319,6 +320,10 @@
         return new SecuritySettingsPanel(this.config);
     }
 
+    private JPanel createJVMSettingsPanel() {
+        return new JVMPanel(this.config);
+    }
+
     /**
      * This is a placeholder panel.
      * 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java	Thu Apr 04 12:52:57 2013 -0400
@@ -0,0 +1,85 @@
+/* PluginPanel.java
+Copyright (C) 2012, Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+*/
+package net.sourceforge.jnlp.controlpanel;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.Box;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
+import net.sourceforge.jnlp.runtime.Translator;
+
+@SuppressWarnings("serial")
+public class JVMPanel extends NamedBorderPanel {
+    private DeploymentConfiguration config;
+
+    JVMPanel(DeploymentConfiguration config) {
+        super(Translator.R("CPHeadJVMSettings"), new GridBagLayout());
+        this.config = config;
+        addComponents();
+    }
+
+    private void addComponents() {
+        JLabel description = new JLabel("<html>" + Translator.R("CPJVMPluginArguments") + "<hr /></html>");
+        JTextField testFieldArguments = new JTextField(25);
+
+        testFieldArguments.getDocument().addDocumentListener(new DocumentAdapter(config, DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS));
+        testFieldArguments.setText(config.getProperty(DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS));
+
+        // Filler to pack the bottom of the panel.
+        GridBagConstraints c = new GridBagConstraints();
+        c.fill = GridBagConstraints.BOTH;
+        c.weightx = 1;
+        c.gridx = 0;
+        c.gridy = 0;
+
+        this.add(description, c);
+        c.gridy++;
+        this.add(testFieldArguments, c);
+
+        // This is to keep it from expanding vertically if resized.
+        Component filler = Box.createRigidArea(new Dimension(1, 1));
+        c.gridy++;
+        c.weighty++;
+        this.add(filler, c);
+    }
+}
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties	Fri Mar 01 13:12:21 2013 -0500
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties	Thu Apr 04 12:52:57 2013 -0400
@@ -298,6 +298,7 @@
 CPSecurityDescription=Use this to configure security settings.
 CPDebuggingDescription=Enable options here to help with debugging
 CPDesktopIntegrationDescription=Set whether or not to allow creation of desktop shortcut.
+CPJVMPluginArguments=Set JVM arguments for plugin.
 
 # Control Panel - Buttons
 CPButAbout=About...
@@ -316,6 +317,7 @@
 CPHeadDebugging=Debugging Settings
 CPHeadDesktopIntegration=Desktop Integrations
 CPHeadSecurity=Security Settings
+CPHeadJVMSettings=JVM Settings
 
 # Control Panel - Tabs
 CPTabAbout=About IcedTea-Web
@@ -327,6 +329,7 @@
 CPTabNetwork=Network
 CPTabRuntimes=Runtimes
 CPTabSecurity=Security
+CPTabJVMSettings=JVM Settings
 
 # Control Panel - AboutPanel
 CPAboutInfo=This is the control panel for setting deployments.properties.<br/>Not all options will take effect until implemented.<br/>The use of multiple JREs is currently unsupported.<br/>
--- a/plugin/icedteanp/IcedTeaNPPlugin.cc	Fri Mar 01 13:12:21 2013 -0500
+++ b/plugin/icedteanp/IcedTeaNPPlugin.cc	Thu Apr 04 12:52:57 2013 -0400
@@ -241,6 +241,8 @@
 void plugin_send_initialization_message(char* instance, gulong handle,
                                                int width, int height,
                                                char* url);
+/* Returns JVM options set in itw-settings */
+static std::vector<std::string*>* get_jvm_args();
 
 // Global instance counter.
 // Mutex to protect plugin_instance_counter.
@@ -1591,48 +1593,48 @@
   PLUGIN_DEBUG ("plugin_start_appletviewer\n");
   NPError error = NPERR_NO_ERROR;
 
-  gchar** command_line;
-  gchar** environment;
-
-  int cmd_num = 0;
+  std::vector<std::string> command_line;
+  gchar** environment = NULL;
+  std::vector<std::string*>* jvm_args = get_jvm_args();
+
+  // Construct command line parameters
+
+  command_line.push_back(appletviewer_executable);
+
+  //Add JVM args to command_line
+  for (int i = 0; i < jvm_args->size(); i++)
+  {
+    command_line.push_back(*jvm_args->at(i));
+  }
+
+  command_line.push_back(PLUGIN_BOOTCLASSPATH);
+  // set the classpath to avoid using the default (cwd).
+  command_line.push_back("-classpath");
+  command_line.push_back(ICEDTEA_WEB_JRE "/lib/rt.jar");
+
   if (plugin_debug)
   {
-      command_line = (gchar**) malloc(sizeof(gchar*)*11);
-      command_line[cmd_num++] = g_strdup(appletviewer_executable);
-      command_line[cmd_num++] = g_strdup(PLUGIN_BOOTCLASSPATH);
-      // set the classpath to avoid using the default (cwd).
-      command_line[cmd_num++] = g_strdup("-classpath");
-      command_line[cmd_num++] = g_strdup_printf("%s/lib/rt.jar", ICEDTEA_WEB_JRE);
-      command_line[cmd_num++] = g_strdup("-Xdebug");
-      command_line[cmd_num++] = g_strdup("-Xnoagent");
-      if (plugin_debug_suspend)
-      {
-          command_line[cmd_num++] = g_strdup("-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y");
-      } else
-      {
-          command_line[cmd_num++] = g_strdup("-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n");
-      }
-      command_line[cmd_num++] = g_strdup("sun.applet.PluginMain");
-      command_line[cmd_num++] = g_strdup(out_pipe_name);
-      command_line[cmd_num++] = g_strdup(in_pipe_name);
-      command_line[cmd_num] = NULL;
-  } else
-  {
-      command_line = (gchar**) malloc(sizeof(gchar*)*8);
-      command_line[cmd_num++] = g_strdup(appletviewer_executable);
-      command_line[cmd_num++] = g_strdup(PLUGIN_BOOTCLASSPATH);
-      command_line[cmd_num++] = g_strdup("-classpath");
-      command_line[cmd_num++] = g_strdup_printf("%s/lib/rt.jar", ICEDTEA_WEB_JRE);
-      command_line[cmd_num++] = g_strdup("sun.applet.PluginMain");
-      command_line[cmd_num++] = g_strdup(out_pipe_name);
-      command_line[cmd_num++] = g_strdup(in_pipe_name);
-      command_line[cmd_num] = NULL;
+    command_line.push_back("-Xdebug");
+    command_line.push_back("-Xnoagent");
+
+    //Debug flags
+    std::string debug_flags = "-Xrunjdwp:transport=dt_socket,address=8787,server=y,";
+    debug_flags += plugin_debug_suspend ? "suspend=y" : "suspend=n";
+    command_line.push_back(debug_flags);
   }
 
+  command_line.push_back("sun.applet.PluginMain");
+  command_line.push_back(out_pipe_name);
+  command_line.push_back(in_pipe_name);
+
+  // Finished command line parameters
+
   environment = plugin_filter_environment();
-
-  if (!g_spawn_async (NULL, command_line, environment,
-		      (GSpawnFlags) G_SPAWN_DO_NOT_REAP_CHILD,
+  std::vector<gchar*> vector_gchar = IcedTeaPluginUtilities::vectorStringToVectorGchar(&command_line);
+  gchar **command_line_args = &vector_gchar[0];
+
+  if (!g_spawn_async (NULL, command_line_args, environment,
+                     (GSpawnFlags) G_SPAWN_DO_NOT_REAP_CHILD,
                       NULL, NULL, &appletviewer_pid, &channel_error))
     {
       if (channel_error)
@@ -1647,15 +1649,11 @@
       error = NPERR_GENERIC_ERROR;
     }
 
-  g_strfreev (environment);
-
-  for (int i = 0; i < cmd_num; i++) {
-    g_free (command_line[i]);
-    command_line[i] = NULL;
-  }
-
-  g_free(command_line);
-  command_line = NULL;
+  //Free memory
+  g_strfreev(environment);
+  IcedTeaPluginUtilities::freeStringPtrVector(jvm_args);
+  jvm_args = NULL;
+  command_line_args = NULL;
 
   if (appletviewer_pid)
     {
@@ -1669,6 +1667,52 @@
 }
 
 /*
+ * Returns JVM options set in itw-settings
+ */
+static std::vector<std::string*>*
+get_jvm_args()
+{
+  std::vector < std::string> commands;
+  gchar *output = NULL;
+  std::vector<std::string*>* tokenOutput = NULL;
+
+  commands.push_back(appletviewer_executable);
+  commands.push_back(PLUGIN_BOOTCLASSPATH);
+  commands.push_back("-classpath");
+  commands.push_back(ICEDTEA_WEB_JRE "/lib/rt.jar");
+  commands.push_back("net.sourceforge.jnlp.controlpanel.CommandLine");
+  commands.push_back("get");
+  commands.push_back("deployment.plugin.jvm.arguments");
+
+  std::vector<gchar*> vector_gchar = IcedTeaPluginUtilities::vectorStringToVectorGchar(&commands);
+  gchar **command_line_args = &vector_gchar[0];
+
+  if (!g_spawn_sync(NULL, command_line_args, NULL,
+      (GSpawnFlags) G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, &output, NULL, NULL,
+      &channel_error))
+  {
+    PLUGIN_ERROR("Failed to get JVM arguments set for plugin.");
+    output = NULL;
+  }
+
+  tokenOutput = IcedTeaPluginUtilities::strSplit(output, " \n");
+
+  if (!tokenOutput->empty() && *tokenOutput->at(0) =="null")
+  {
+    delete tokenOutput->at(0);
+    tokenOutput->erase(tokenOutput->begin());
+  }
+
+  //Free memory
+  g_free(output);
+  output = NULL;
+  command_line_args = NULL;
+
+  return tokenOutput;
+}
+
+
+/*
  * Replaces certain characters (\r, \n, etc) with HTML escape equivalents.
  *
  * Return string is allocated on the heap. Caller assumes responsibility 
--- a/plugin/icedteanp/IcedTeaPluginUtils.cc	Fri Mar 01 13:12:21 2013 -0500
+++ b/plugin/icedteanp/IcedTeaPluginUtils.cc	Thu Apr 04 12:52:57 2013 -0400
@@ -978,6 +978,24 @@
 }
 
 /**
+ * Returns a vector of gchar* pointing to the elements of the vector string passed in.
+ * @param stringVec The vector of strings reference.
+ */
+std::vector<gchar*>
+IcedTeaPluginUtilities::vectorStringToVectorGchar(const std::vector<std::string>* stringVec)
+{
+  std::vector<gchar*> charVec;
+
+  for (int i = 0; i < stringVec->size(); i++)
+  {
+    gchar* element = (gchar*) stringVec->at(i).c_str(); //cast from const char
+    charVec.push_back(element);
+  }
+  charVec.push_back(NULL);
+  return charVec;
+}
+
+/**
  * Runs through the async call wait queue and executes all calls
  *
  * @param param Ignored -- required to conform to NPN_PluginThreadAsynCall API
--- a/plugin/icedteanp/IcedTeaPluginUtils.h	Fri Mar 01 13:12:21 2013 -0500
+++ b/plugin/icedteanp/IcedTeaPluginUtils.h	Thu Apr 04 12:52:57 2013 -0400
@@ -269,6 +269,9 @@
 
     	static void decodeURL(const char* url, char** decoded_url);
 
+    	/* Returns a vector of gchar* pointing to the elements of the vector string passed in*/
+    	static std::vector<gchar*> vectorStringToVectorGchar(const std::vector<std::string>* stringVec);
+
     	/* Posts call in async queue and waits till execution completes */
     	static void callAndWaitForResult(NPP instance, void (*func) (void *), AsyncCallThreadData* data);
 };