Ignore:
Timestamp:
Sep 24, 2014, 9:34:21 PM (11 years ago)
Author:
dmik
Message:

icedtea-web: Merge version 1.5.1 from vendor to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc

    r419 r429  
    4646#include <sys/socket.h>
    4747#include <fcntl.h>
     48#include <sstream>
    4849#include "OS_OS2.h"
    4950#endif
     
    5152// System includes.
    5253#include <dlfcn.h>
     54#include <unistd.h>
     55#include <fcntl.h>
     56#include <dirent.h>
    5357#include <errno.h>
    5458#include <libgen.h>
     
    5660#include <stdlib.h>
    5761#include <string.h>
     62#include <string>
    5863#include <sys/stat.h>
    5964#include <sys/types.h>
    6065#include <unistd.h>
    61 
     66#include <new>
     67
     68//IcedTea-plugin includes
     69#include "IcedTeaPluginUtils.h"
     70#include "IcedTeaParseProperties.h"
    6271// Liveconnect extension
    6372#include "IcedTeaScriptablePluginObject.h"
     
    6978#define DT_SOCKET_DLL "dt_socket"
    7079#endif
    71 
    72 #if MOZILLA_VERSION_COLLAPSED < 1090100
    73 // Documentbase retrieval includes.
    74 #include <nsIPluginInstance.h>
    75 #include <nsIPluginInstancePeer.h>
    76 #include <nsIPluginTagInfo2.h>
    77 
    78 // API's into Mozilla
    79 #include <nsCOMPtr.h>
    80 #include <nsICookieService.h>
    81 #include <nsIDNSRecord.h>
    82 #include <nsIDNSService.h>
    83 #include <nsINetUtil.h>
    84 #include <nsIProxyInfo.h>
    85 #include <nsIProtocolProxyService.h>
    86 #include <nsIScriptSecurityManager.h>
    87 #include <nsIIOService.h>
    88 #include <nsIURI.h>
    89 #include <nsNetCID.h>
    90 #include <nsStringAPI.h>
    91 #include <nsServiceManagerUtils.h>
    92 #endif
    93 
    94 // Error reporting macros.
    95 #define PLUGIN_ERROR(message)                                       \
    96   g_printerr ("%s:%d: thread %p: Error: %s\n", __FILE__, __LINE__,  \
    97               g_thread_self (), message)
    98 
    99 #define PLUGIN_ERROR_TWO(first, second)                                 \
    100   g_printerr ("%s:%d: thread %p: Error: %s: %s\n", __FILE__, __LINE__,  \
    101               g_thread_self (), first, second)
    102 
    103 #define PLUGIN_ERROR_THREE(first, second, third)                        \
    104   g_printerr ("%s:%d: thread %p: Error: %s: %s: %s\n", __FILE__,        \
    105               __LINE__, g_thread_self (), first, second, third)
    10680
    10781// Plugin information passed to about:plugins.
     
    167141  "  For more detail rerun \"firefox -g\" in a terminal window."
    168142
    169 #if MOZILLA_VERSION_COLLAPSED < 1090100
    170 // Documentbase retrieval required definition.
    171 static NS_DEFINE_IID (kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
    172 #endif
    173 
    174143// Data directory for plugin.
    175 static gchar* data_directory = NULL;
    176 
    177 // Fully-qualified appletviewer executable.
    178 static gchar* appletviewer_executable = NULL;
     144static std::string data_directory;
     145static DIR *data_directory_descriptor;
     146
     147// Fully-qualified appletviewer default  executable and rt.jar
     148static const char* appletviewer_default_executable = ICEDTEA_WEB_JRE "/bin/java";
     149static const char* appletviewer_default_rtjar = ICEDTEA_WEB_JRE "/lib/rt.jar";
    179150
    180151// Applet viewer input channel (needs to be static because it is used in plugin_in_pipe_callback)
     
    202173#endif
    203174
     175// Applet viewer debug pipe name.
     176gchar* debug_pipe_name = NULL;
     177
    204178// Applet viewer output watch source.
    205179gint out_watch_source;
     
    211185pthread_mutex_t pluginAsyncCallMutex;
    212186
     187/*to sync pipe to apletviewer console*/
     188pthread_mutex_t debug_pipe_lock = PTHREAD_MUTEX_INITIALIZER;
     189
    213190// Applet viewer output channel.
    214191GIOChannel* out_to_appletviewer;
     192
     193// Applet viewer debug channel.
     194GIOChannel* debug_to_appletviewer = NULL;
    215195
    216196// Tracks jvm status
     
    235215JavaMessageSender* java_req_proc;
    236216
    237 #if MOZILLA_VERSION_COLLAPSED < 1090100
    238 // Documentbase retrieval type-punning union.
    239 typedef union
    240 {
    241   void** void_field;
    242   nsIPluginTagInfo2** info_field;
    243 } info_union;
     217// Queue processing threads
     218static pthread_t plugin_request_processor_thread1;
     219static pthread_t plugin_request_processor_thread2;
     220static pthread_t plugin_request_processor_thread3;
     221
     222#ifdef __OS2__
     223struct QueueProcessorData
     224{
     225    PluginRequestProcessor *processor;
     226    bool stopRequested;
     227};
     228
     229static QueueProcessorData queue_processor_data1 = { NULL, false };
     230static QueueProcessorData queue_processor_data2 = { NULL, false };
     231static QueueProcessorData queue_processor_data3 = { NULL, false };
    244232#endif
    245233
    246234// Static instance helper functions.
    247 // Have the browser allocate a new ITNPPluginData structure.
    248 static void plugin_data_new (ITNPPluginData** data);
    249235// Retrieve the current document's documentbase.
    250 static gchar* plugin_get_documentbase (NPP instance);
    251 // Notify the user that the appletviewer is not installed correctly.
    252 static void plugin_display_failure_dialog ();
     236static std::string plugin_get_documentbase (NPP instance);
    253237// Callback used to monitor input pipe status.
    254238static gboolean plugin_in_pipe_callback (GIOChannel* source,
     
    259243                                          GIOCondition condition,
    260244                                          gpointer plugin_data);
    261 static NPError plugin_start_appletviewer (ITNPPluginData* data);
    262 static gchar* plugin_create_applet_tag (int16_t argc, char* argn[],
    263                                         char* argv[]);
     245std::string plugin_parameters_string (int argc, char* argn[], char* argv[]);
    264246static void plugin_stop_appletviewer ();
    265 // Uninitialize ITNPPluginData structure
    266 static void plugin_data_destroy (NPP instance);
    267247
    268248NPError get_cookie_info(const char* siteAddr, char** cookieString, uint32_t* len);
    269249NPError get_proxy_info(const char* siteAddr, char** proxy, uint32_t* len);
    270250void consume_message(gchar* message);
    271 void start_jvm_if_needed();
    272251static void appletviewer_monitor(GPid pid, gint status, gpointer data);
    273252void plugin_send_initialization_message(char* instance, gulong handle,
    274253                                               int width, int height,
    275254                                               char* url);
     255/* Returns JVM options set in itw-settings */
     256std::vector<std::string*>* get_jvm_args();
    276257
    277258// Global instance counter.
     
    288269static guint appletviewer_watch_id = -1;
    289270
     271bool debug_initiated = false;
    290272int plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL;
     273bool plugin_debug_headers = false;
     274bool plugin_debug_to_file = false ;
     275bool plugin_debug_to_streams = true ;
     276bool plugin_debug_to_system = false;
     277bool plugin_debug_to_console = true;
     278FILE *  plugin_file_log;
     279std::string plugin_file_log_name;
     280
    291281int plugin_debug_suspend = (getenv("ICEDTEAPLUGIN_DEBUG") != NULL) &&
    292282        (strcmp(getenv("ICEDTEAPLUGIN_DEBUG"), "suspend") == 0);
    293 
    294 pthread_cond_t cond_message_available = PTHREAD_COND_INITIALIZER;
    295283
    296284
     
    316304#endif
    317305
    318 
     306static std::string get_plugin_executable(){
     307      std::string custom_jre;
     308      bool custom_jre_defined = find_custom_jre(custom_jre);
     309      if (custom_jre_defined) {
     310            if (IcedTeaPluginUtilities::file_exists(custom_jre+"/bin/java")){
     311                  return custom_jre+"/bin/java";
     312            } else {
     313                 PLUGIN_ERROR("Your custom jre (/bin/java check) %s is not valid. Please fix %s in your %s. In attempt to run using default one. \n", custom_jre.c_str(), custom_jre_key.c_str(), default_file_ITW_deploy_props_name.c_str());
     314            }
     315      }
     316      return appletviewer_default_executable;     
     317}
     318
     319static std::string get_plugin_rt_jar(){
     320      std::string custom_jre;
     321      bool custom_jre_defined = find_custom_jre(custom_jre);
     322      if (custom_jre_defined) {
     323            if (IcedTeaPluginUtilities::file_exists(custom_jre+"/lib/rt.jar")){
     324                  return custom_jre+"/lib/rt.jar";
     325            } else {
     326                  PLUGIN_ERROR("Your custom jre (/lib/rt.jar check) %s is not valid. Please fix %s in your %s. In attempt to run using default one. \n", custom_jre.c_str(), custom_jre_key.c_str(), default_file_ITW_deploy_props_name.c_str());
     327            }
     328      }
     329      return appletviewer_default_rtjar;     
     330}
     331
     332static void cleanUpDir(){
     333  //free data_directory descriptor
     334  if (data_directory_descriptor != NULL) {
     335    closedir(data_directory_descriptor);
     336  }
     337  //clean up pipes directory
     338  PLUGIN_DEBUG ("Removing runtime directory %s \n", data_directory.c_str());
     339  int removed = rmdir(data_directory.c_str());
     340  if (removed != 0) {
     341    PLUGIN_ERROR ("Failed to remove runtime directory %s, because of  %s \n", data_directory.c_str(), strerror(errno));
     342  } else {
     343    PLUGIN_DEBUG ("Removed runtime directory %s \n", data_directory.c_str());
     344  }
     345  data_directory_descriptor = NULL;
     346}
    319347/*
    320348 * Find first member in GHashTable* depending on version of glib
     
    344372// Creates a new icedtea np plugin instance.  This function creates a
    345373// ITNPPluginData* and stores it in instance->pdata.  The following
    346 // ITNPPluginData fiels are initialized: instance_id, in_pipe_name,
     374// ITNPPluginData fields are initialized: instance_id, in_pipe_name,
    347375// in_from_appletviewer, in_watch_source, out_pipe_name,
    348376// out_to_appletviewer, out_watch_source, appletviewer_mutex, owner,
     
    366394  if (!browser_functions.hasproperty(instance, window_ptr, identifier))
    367395  {
    368         printf("%s not found!\n", "document");
     396        PLUGIN_ERROR("%s not found!\n", "document");
    369397  }
    370398  browser_functions.getproperty(instance, window_ptr, identifier, &member_ptr);
     
    372400  PLUGIN_DEBUG("Got variant %p\n", &member_ptr);
    373401
    374 
    375   NPError np_error = NPERR_NO_ERROR;
    376   ITNPPluginData* data = NULL;
    377 
    378   gchar* documentbase = NULL;
    379   gchar* read_message = NULL;
    380   gchar* applet_tag = NULL;
    381   gchar* cookie_info = NULL;
    382 
    383   NPObject* npPluginObj = NULL;
    384 
    385402  if (!instance)
    386     {
    387       PLUGIN_ERROR ("Browser-provided instance pointer is NULL.");
    388       np_error = NPERR_INVALID_INSTANCE_ERROR;
    389       goto cleanup_done;
    390     }
     403  {
     404      PLUGIN_ERROR ("Browser-provided instance pointer is NULL.\n");
     405      return NPERR_INVALID_INSTANCE_ERROR;
     406  }
    391407
    392408  // data
    393   plugin_data_new (&data);
     409  ITNPPluginData* data = plugin_data_new ();
    394410  if (data == NULL)
    395     {
    396       PLUGIN_ERROR ("Failed to allocate plugin data.");
    397       np_error = NPERR_OUT_OF_MEMORY_ERROR;
    398       goto cleanup_done;
     411  {
     412      PLUGIN_ERROR ("Failed to allocate plugin data.\n");
     413      return NPERR_OUT_OF_MEMORY_ERROR;
    399414    }
    400415
    401416  // start the jvm if needed
    402   start_jvm_if_needed();
     417   NPError startup_error = start_jvm_if_needed();
     418   if (startup_error != NPERR_NO_ERROR) {
     419           PLUGIN_ERROR ("Failed to start JVM\n");
     420           return startup_error;
     421   }
    403422
    404423  // Initialize data->instance_id.
     
    422441  g_mutex_lock (data->appletviewer_mutex);
    423442
     443  std::string documentbase = plugin_get_documentbase (instance);
    424444  // Documentbase retrieval.
    425   documentbase = plugin_get_documentbase (instance);
    426   if (documentbase && argc != 0)
    427     {
    428       // Send applet tag message to appletviewer.
    429       applet_tag = plugin_create_applet_tag (argc, argn, argv);
    430 
    431       data->applet_tag = (gchar*) malloc(strlen(applet_tag)*sizeof(gchar) + strlen(documentbase)*sizeof(gchar) + 32);
    432       g_sprintf(data->applet_tag, "tag %s %s", documentbase, applet_tag);
     445  if (argc != 0)
     446  {
     447      // Send parameters to appletviewer.
     448      std::string params_string = plugin_parameters_string(argc, argn, argv);
     449
     450      data->parameters_string =  g_strdup_printf("tag %s %s", documentbase.c_str(), params_string.c_str());
    433451
    434452      data->is_applet_instance = true;
    435     }
    436 
    437   if (argc == 0)
    438     {
     453  }
     454  else
     455  {
    439456      data->is_applet_instance = false;
    440     }
     457  }
    441458
    442459  g_mutex_unlock (data->appletviewer_mutex);
     
    454471
    455472  instance->pdata = data;
    456 
    457   goto cleanup_done;
    458 
    459  cleanup_appletviewer_mutex:
    460   g_mutex_free (data->appletviewer_mutex);
    461   data->appletviewer_mutex = NULL;
    462 
    463   // cleanup_instance_string:
    464   g_free (data->instance_id);
    465   data->instance_id = NULL;
    466 
    467   // cleanup applet tag:
    468   g_free (data->applet_tag);
    469   data->applet_tag = NULL;
    470 
    471   // cleanup_data:
    472   // Eliminate back-pointer to plugin instance.
    473   data->owner = NULL;
    474   (*browser_functions.memfree) (data);
    475   data = NULL;
    476 
    477   // Initialization failed so return a NULL pointer for the browser
    478   // data.
    479   instance->pdata = NULL;
    480 
    481  cleanup_done:
    482   g_free (applet_tag);
    483   applet_tag = NULL;
    484   g_free (read_message);
    485   read_message = NULL;
    486   g_free (documentbase);
    487   documentbase = NULL;
    488473
    489474  // store an identifier for this plugin
     
    495480  PLUGIN_DEBUG ("ITNP_New return\n");
    496481
    497   return np_error;
     482  return NPERR_NO_ERROR;
    498483}
    499484
    500485// Starts the JVM if it is not already running
    501 void start_jvm_if_needed()
     486NPError start_jvm_if_needed()
    502487{
    503488
     
    514499  {
    515500      PLUGIN_DEBUG("JVM is up. Returning.\n");
    516       return;
     501      return  NPERR_NO_ERROR;
    517502  }
    518503
     
    536521  // in_pipe_name
    537522  in_pipe_name = g_strdup_printf ("%s/%d-icedteanp-appletviewer-to-plugin",
    538                                          data_directory, getpid());
     523                                         data_directory.c_str(), getpid());
    539524  if (!in_pipe_name)
    540525    {
    541       PLUGIN_ERROR ("Failed to create input pipe name.");
     526      PLUGIN_ERROR ("Failed to create input pipe name.\n");
    542527      np_error = NPERR_OUT_OF_MEMORY_ERROR;
    543528      // If in_pipe_name is NULL then the g_free at
     
    552537  if (mkfifo (in_pipe_name, 0600) == -1 && errno != EEXIST)
    553538    {
    554       PLUGIN_ERROR_TWO ("Failed to create input pipe", strerror (errno));
     539      PLUGIN_ERROR ("Failed to create input pipe\n", strerror (errno));
    555540      np_error = NPERR_GENERIC_ERROR;
    556541      goto cleanup_in_pipe_name;
     
    573558  // out_pipe_name
    574559  out_pipe_name = g_strdup_printf ("%s/%d-icedteanp-plugin-to-appletviewer",
    575                                          data_directory, getpid());
     560                                         data_directory.c_str(), getpid());
    576561
    577562  if (!out_pipe_name)
    578563    {
    579       PLUGIN_ERROR ("Failed to create output pipe name.");
     564      PLUGIN_ERROR ("Failed to create output pipe name.\n");
    580565      np_error = NPERR_OUT_OF_MEMORY_ERROR;
    581566      goto cleanup_out_pipe_name;
     
    588573  if (mkfifo (out_pipe_name, 0600) == -1 && errno != EEXIST)
    589574    {
    590       PLUGIN_ERROR_TWO ("Failed to create output pipe", strerror (errno));
     575      PLUGIN_ERROR ("Failed to create output pipe\n", strerror (errno));
    591576      np_error = NPERR_GENERIC_ERROR;
    592577      goto cleanup_out_pipe_name;
     
    594579  PLUGIN_DEBUG ("ITNP_New: created output fifo: %s\n", out_pipe_name);
    595580#endif
     581
     582  // Create plugin-debug-to-appletviewer pipe which we refer to as the
     583  // debug pipe.
     584  initialize_debug();//should be already initialized, but...
     585  if (plugin_debug_to_console){
     586    // debug_pipe_name
     587    debug_pipe_name = g_strdup_printf ("%s/%d-icedteanp-plugin-debug-to-appletviewer",
     588                                         data_directory.c_str(), getpid());
     589
     590    if (!debug_pipe_name)
     591      {
     592        PLUGIN_ERROR ("Failed to create debug pipe name.\n");
     593        np_error = NPERR_OUT_OF_MEMORY_ERROR;
     594        goto cleanup_debug_pipe_name;
     595      }
     596
     597    // clean up any older pip
     598    unlink (debug_pipe_name);
     599
     600    PLUGIN_DEBUG ("ITNP_New: creating debug fifo: %s\n", debug_pipe_name);
     601    if (mkfifo (debug_pipe_name, 0600) == -1 && errno != EEXIST)
     602      {
     603        PLUGIN_ERROR ("Failed to create debug pipe\n", strerror (errno));
     604        np_error = NPERR_GENERIC_ERROR;
     605        goto cleanup_debug_pipe_name;
     606      }
     607    PLUGIN_DEBUG ("ITNP_New: created debug fifo: %s\n", debug_pipe_name);
     608  }
    596609
    597610  // Start a separate appletviewer process for each applet, even if
     
    628641      if (channel_error)
    629642        {
    630           PLUGIN_ERROR_TWO ("Failed to create output channel",
     643          PLUGIN_ERROR ("Failed to create output channel, '%s'\n",
    631644                            channel_error->message);
    632645          g_error_free (channel_error);
     
    634647        }
    635648      else
    636         PLUGIN_ERROR ("Failed to create output channel");
     649        PLUGIN_ERROR ("Failed to create output channel\n");
    637650
    638651      np_error = NPERR_GENERIC_ERROR;
     
    659672      if (channel_error)
    660673        {
    661           PLUGIN_ERROR_TWO ("Failed to create input channel",
     674          PLUGIN_ERROR ("Failed to create input channel, '%s'\n",
    662675                            channel_error->message);
    663676          g_error_free (channel_error);
     
    665678        }
    666679      else
    667         PLUGIN_ERROR ("Failed to create input channel");
     680        PLUGIN_ERROR ("Failed to create input channel\n");
    668681
    669682      np_error = NPERR_GENERIC_ERROR;
     
    676689                    (GIOCondition) (G_IO_IN | G_IO_ERR | G_IO_HUP),
    677690                    plugin_in_pipe_callback, (gpointer) in_from_appletviewer);
     691                   
     692  // Create plugin-to-appletviewer console debug channel.  The default encoding for
     693  // the file is UTF-8.
     694  // debug_to_appletviewer
     695  if (plugin_debug_to_console){
     696    debug_to_appletviewer = g_io_channel_new_file (debug_pipe_name,
     697                                                 "w", &channel_error);
     698    if (!debug_to_appletviewer)
     699      {
     700        if (channel_error)
     701          {
     702            PLUGIN_ERROR ("Failed to debug output channel, '%s'\n",
     703                              channel_error->message);
     704            g_error_free (channel_error);
     705            channel_error = NULL;
     706          }
     707        else
     708          PLUGIN_ERROR ("Failed to create debug channel\n");
     709
     710        np_error = NPERR_GENERIC_ERROR;
     711        goto cleanup_debug_to_appletviewer;
     712     }
     713  }
    678714
    679715  jvm_up = TRUE;
    680 
     716 
     717  if (plugin_debug_to_console){
     718    //jvm is up, we can start console producer thread
     719    pthread_t debug_to_console_consumer;
     720    pthread_create(&debug_to_console_consumer,NULL,&flush_pre_init_messages,NULL);
     721  }
    681722  goto done;
    682723
    683   // Free allocated data
     724  // Free allocated data in case of error
     725 cleanup_debug_to_appletviewer:
     726  if (plugin_debug_to_console){
     727    if (debug_to_appletviewer)
     728      g_io_channel_unref (debug_to_appletviewer);
     729    debug_to_appletviewer = NULL;
     730  }
    684731
    685732 cleanup_in_watch_source:
     
    702749    g_io_channel_unref (out_to_appletviewer);
    703750  out_to_appletviewer = NULL;
     751
     752  if (plugin_debug_to_console){
     753    // cleanup_debug_pipe:
     754    // Delete output pipe.
     755    PLUGIN_DEBUG ("ITNP_New: deleting debug fifo: %s\n", debug_pipe_name);
     756    unlink (debug_pipe_name);
     757    PLUGIN_DEBUG ("ITNP_New: deleted debug fifo: %s\n", debug_pipe_name);
     758  }
     759 cleanup_debug_pipe_name:
     760  if (plugin_debug_to_console){
     761    g_free (debug_pipe_name);
     762    debug_pipe_name = NULL;
     763  }
     764
     765
    704766
    705767  // cleanup_out_pipe:
     
    735797#endif
    736798
     799  cleanUpDir();
    737800 done:
    738801
     802  IcedTeaPluginUtilities::printDebugStatus();
    739803  // Now other threads may re-enter.. unlock the mutex
    740804  g_mutex_unlock(vm_start_mutex);
     805  return np_error;
    741806
    742807}
     
    765830      break;
    766831    default:
    767       PLUGIN_ERROR ("Unknown plugin value requested.");
     832      PLUGIN_ERROR ("Unknown plugin value requested.\n");
    768833      np_error = NPERR_GENERIC_ERROR;
    769834      break;
     
    814879  if (instance == NULL)
    815880    {
    816       PLUGIN_ERROR ("Invalid instance.");
     881      PLUGIN_ERROR ("Invalid instance.\n");
    817882
    818883      return NPERR_INVALID_INSTANCE_ERROR;
     
    927992      plugin_send_initialization_message(
    928993                  data->instance_id, (gulong) data->window_handle,
    929                   data->window_width, data->window_height, data->applet_tag);
     994                  data->window_width, data->window_height, data->parameters_string);
    930995
    931996      g_mutex_unlock (data->appletviewer_mutex);
     
    10231088    return NPERR_GENERIC_ERROR;
    10241089  }
    1025 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1026   nsresult rv;
    1027   nsCOMPtr<nsIScriptSecurityManager> sec_man =
    1028     do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    1029 
    1030   if (!sec_man) {
    1031     return NPERR_GENERIC_ERROR;
    1032   }
    1033 
    1034   nsCOMPtr<nsIIOService> io_svc = do_GetService("@mozilla.org/network/io-service;1", &rv);
    1035 
    1036   if (NS_FAILED(rv) || !io_svc) {
    1037     return NPERR_GENERIC_ERROR;
    1038   }
    1039 
    1040   nsCOMPtr<nsIURI> uri;
    1041   io_svc->NewURI(nsCString(siteAddr), NULL, NULL, getter_AddRefs(uri));
    1042 
    1043   nsCOMPtr<nsICookieService> cookie_svc = do_GetService("@mozilla.org/cookieService;1", &rv);
    1044 
    1045   if (NS_FAILED(rv) || !cookie_svc) {
    1046     return NPERR_GENERIC_ERROR;
    1047   }
    1048 
    1049   rv = cookie_svc->GetCookieString(uri, NULL, cookieString);
    1050 
    1051   if (NS_FAILED(rv) || !*cookieString) {
    1052     return NPERR_GENERIC_ERROR;
    1053   }
    1054 
    1055 #else
    1056 
    10571090  // getvalueforurl needs an NPP instance. Quite frankly, there is no easy way
    10581091  // to know which instance needs the information, as applets on Java side can
     
    10731106  }
    10741107
    1075 #endif
    1076 
    10771108  return NPERR_NO_ERROR;
    10781109}
     
    10951126// HELPER FUNCTIONS
    10961127
    1097 static void
    1098 plugin_data_new (ITNPPluginData** data)
     1128ITNPPluginData*
     1129plugin_data_new ()
    10991130{
    11001131  PLUGIN_DEBUG ("plugin_data_new\n");
    11011132
    1102   *data = (ITNPPluginData*)
    1103     (*browser_functions.memalloc) (sizeof (struct ITNPPluginData));
    1104 
    1105   // appletviewer_alive is false until the applet viewer is spawned.
    1106   if (*data)
    1107     memset (*data, 0, sizeof (struct ITNPPluginData));
    1108 
     1133  ITNPPluginData* data = (ITNPPluginData*)browser_functions.memalloc(sizeof (struct ITNPPluginData));
     1134
     1135  if (data)
     1136  {
     1137      // Call constructor on allocated data
     1138      new (data) ITNPPluginData();
     1139  }
    11091140  PLUGIN_DEBUG ("plugin_data_new return\n");
     1141
     1142  return data;
    11101143}
    11111144
     
    11151148// documentbase.  This function relies on browser-private data so it
    11161149// will only work when the plugin is loaded in a Mozilla-based
    1117 // browser.  We could not find a way to retrieve the documentbase
    1118 // using the original Netscape plugin API so we use the XPCOM API
    1119 // instead.
    1120 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1121 static gchar*
     1150// browser.
     1151static std::string
    11221152plugin_get_documentbase (NPP instance)
    11231153{
    11241154  PLUGIN_DEBUG ("plugin_get_documentbase\n");
    1125 
    1126   nsIPluginInstance* xpcom_instance = NULL;
    1127   nsIPluginInstancePeer* peer = NULL;
    1128   nsresult result = 0;
    1129   nsIPluginTagInfo2* pluginTagInfo2 = NULL;
    1130   info_union u = { NULL };
    1131   char const* documentbase = NULL;
    1132   gchar* documentbase_copy = NULL;
    1133 
    1134   xpcom_instance = (nsIPluginInstance*) (instance->ndata);
    1135   if (!xpcom_instance)
    1136     {
    1137       PLUGIN_ERROR ("xpcom_instance is NULL.");
    1138       goto cleanup_done;
    1139     }
    1140 
    1141   xpcom_instance->GetPeer (&peer);
    1142   if (!peer)
    1143     {
    1144       PLUGIN_ERROR ("peer is NULL.");
    1145       goto cleanup_done;
    1146     }
    1147 
    1148   u.info_field = &pluginTagInfo2;
    1149 
    1150   result = peer->QueryInterface (kIPluginTagInfo2IID,
    1151                                  u.void_field);
    1152   if (result || !pluginTagInfo2)
    1153     {
    1154       PLUGIN_ERROR ("pluginTagInfo2 retrieval failed.");
    1155       goto cleanup_peer;
    1156     }
    1157 
    1158   pluginTagInfo2->GetDocumentBase (&documentbase);
    1159 
    1160   if (!documentbase)
    1161     {
    1162       // NULL => dummy instantiation for LiveConnect
    1163       goto cleanup_plugintaginfo2;
    1164     }
    1165 
    1166   documentbase_copy = g_strdup (documentbase);
    1167 
    1168   // Release references.
    1169  cleanup_plugintaginfo2:
    1170   NS_RELEASE (pluginTagInfo2);
    1171 
    1172  cleanup_peer:
    1173   NS_RELEASE (peer);
    1174 
    1175  cleanup_done:
    1176   PLUGIN_DEBUG ("plugin_get_documentbase return\n");
    1177 
    1178   PLUGIN_DEBUG("plugin_get_documentbase returning: %s\n", documentbase_copy);
    1179   return documentbase_copy;
    1180 }
    1181 #else
    1182 static gchar*
    1183 plugin_get_documentbase (NPP instance)
    1184 {
    1185   PLUGIN_DEBUG ("plugin_get_documentbase\n");
    1186 
    1187   char const* documentbase = NULL;
    1188   gchar* documentbase_copy = NULL;
    11891155
    11901156  // FIXME: This method is not ideal, but there are no known NPAPI call
     
    12071173
    12081174  std::string href_str = IcedTeaPluginUtilities::NPVariantAsString(href);
    1209   documentbase_copy = g_strdup (href_str.c_str());
    12101175
    12111176  // Release references.
    12121177  browser_functions.releasevariantvalue(&href);
    12131178  browser_functions.releasevariantvalue(&location);
    1214  cleanup_done:
     1179
    12151180  PLUGIN_DEBUG ("plugin_get_documentbase return\n");
    1216   PLUGIN_DEBUG("plugin_get_documentbase returning: %s\n", documentbase_copy);
    1217 
    1218   return documentbase_copy;
    1219 }
    1220 #endif
    1221 
    1222 // This function displays an error message if the appletviewer has not
    1223 // been installed correctly.
    1224 static void
    1225 plugin_display_failure_dialog ()
    1226 {
    1227 #ifdef __OS2__
    1228   gchar *msg = NULL;
    1229 
    1230   PLUGIN_DEBUG ("plugin_display_failure_dialog\n");
    1231 
    1232   msg = g_strdup_printf (FAILURE_MESSAGE, appletviewer_executable);
    1233   WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
    1234                  msg, "Error", 0, MB_ERROR | MB_OK | MB_MOVEABLE);
    1235   g_free(msg);
    1236 #else
    1237   GtkWidget* dialog = NULL;
    1238 
    1239   PLUGIN_DEBUG ("plugin_display_failure_dialog\n");
    1240 
    1241   dialog = gtk_message_dialog_new (NULL,
    1242                                    GTK_DIALOG_DESTROY_WITH_PARENT,
    1243                                    GTK_MESSAGE_ERROR,
    1244                                    GTK_BUTTONS_CLOSE,
    1245                                    FAILURE_MESSAGE,
    1246                                    appletviewer_executable);
    1247   gtk_widget_show_all (dialog);
    1248   gtk_dialog_run (GTK_DIALOG (dialog));
    1249   gtk_widget_destroy (dialog);
    1250 #endif
    1251 
    1252   PLUGIN_DEBUG ("plugin_display_failure_dialog return\n");
    1253 }
    1254 
    1255 
     1181  PLUGIN_DEBUG("plugin_get_documentbase returning: %s\n", href_str.c_str());
     1182
     1183  return href_str;
     1184}
    12561185
    12571186// plugin_in_pipe_callback is called when data is available on the
     
    12791208          if (channel_error)
    12801209            {
    1281               PLUGIN_ERROR_TWO ("Failed to read line from input channel",
     1210              PLUGIN_ERROR ("Failed to read line from input channel, %s\n",
    12821211                                channel_error->message);
    12831212              g_error_free (channel_error);
     
    12851214            }
    12861215          else
    1287             PLUGIN_ERROR ("Failed to read line from input channel");
     1216            PLUGIN_ERROR ("Failed to read line from input channel\n");
    12881217#ifdef __OS2__
    12891218          // G_IO_ERR/HUP is not reported on file/pipe handles, simulate it
     
    13181247  if (g_str_has_prefix(parts[1], "PluginProxyInfo"))
    13191248  {
    1320     gchar* proxy;
     1249    gchar* proxy = NULL;
    13211250    uint32_t len;
    13221251
     
    13261255
    13271256    gchar* proxy_info;
    1328 
    1329 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1330         proxy = (char*) malloc(sizeof(char)*2048);
    1331 #endif
    13321257
    13331258    proxy_info = g_strconcat ("plugin PluginProxyInfo reference ", parts[3], " ", NULL);
     
    13451270    proxy_info = NULL;
    13461271
    1347 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1348         g_free(proxy);
    1349         proxy = NULL;
    1350 #endif
     1272    g_free(proxy);
     1273    proxy = NULL;
    13511274
    13521275  } else if (g_str_has_prefix(parts[1], "PluginCookieInfo"))
     
    13561279
    13571280    gchar* cookie_info = g_strconcat ("plugin PluginCookieInfo reference ", parts[3], " ", NULL);
    1358     gchar* cookie_string;
     1281    gchar* cookie_string = NULL;
    13591282    uint32_t len;
    13601283    if (get_cookie_info(decoded_url, &cookie_string, &len) == NPERR_NO_ERROR)
     
    13701293    g_free(cookie_info);
    13711294    cookie_info = NULL;
     1295    g_free(cookie_string);
     1296    cookie_string = NULL;
    13721297  } else if (g_str_has_prefix(parts[1], "PluginSetCookie"))
    13731298  {
     
    14981423          return NPERR_GENERIC_ERROR;
    14991424  }
    1500 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1501   nsresult rv;
    1502 
    1503   // Initialize service variables
    1504   nsCOMPtr<nsIProtocolProxyService> proxy_svc = do_GetService("@mozilla.org/network/protocol-proxy-service;1", &rv);
    1505 
    1506   if (!proxy_svc) {
    1507       printf("Cannot initialize proxy service\n");
    1508       return NPERR_GENERIC_ERROR;
    1509   }
    1510 
    1511   nsCOMPtr<nsIIOService> io_svc = do_GetService("@mozilla.org/network/io-service;1", &rv);
    1512 
    1513   if (NS_FAILED(rv) || !io_svc) {
    1514     printf("Cannot initialize io service\n");
    1515     return NPERR_GENERIC_ERROR;
    1516   }
    1517 
    1518   // uri which needs to be accessed
    1519   nsCOMPtr<nsIURI> uri;
    1520   io_svc->NewURI(nsCString(siteAddr), NULL, NULL, getter_AddRefs(uri));
    1521 
    1522   // find the proxy address if any
    1523   nsCOMPtr<nsIProxyInfo> info;
    1524   proxy_svc->Resolve(uri, 0, getter_AddRefs(info));
    1525 
    1526   // if there is no proxy found, return immediately
    1527   if (!info) {
    1528      PLUGIN_DEBUG("%s does not need a proxy\n", siteAddr);
    1529      return NPERR_GENERIC_ERROR;
    1530   }
    1531 
    1532   // if proxy info is available, extract it
    1533   nsCString phost;
    1534   PRInt32 pport;
    1535   nsCString ptype;
    1536 
    1537   info->GetHost(phost);
    1538   info->GetPort(&pport);
    1539   info->GetType(ptype);
    1540 
    1541   // resolve the proxy address to an IP
    1542   nsCOMPtr<nsIDNSService> dns_svc = do_GetService("@mozilla.org/network/dns-service;1", &rv);
    1543 
    1544   if (!dns_svc) {
    1545       printf("Cannot initialize DNS service\n");
    1546       return NPERR_GENERIC_ERROR;
    1547   }
    1548 
    1549   nsCOMPtr<nsIDNSRecord> record;
    1550   dns_svc->Resolve(phost, 0U, getter_AddRefs(record));
    1551 
    1552   // TODO: Add support for multiple ips
    1553   nsDependentCString ipAddr;
    1554   record->GetNextAddrAsString(ipAddr);
    1555 
    1556   if (!strcmp(ptype.get(), "http"))
    1557   {
    1558       snprintf(*proxy, sizeof(char)*1024, "%s %s:%d", "PROXY", ipAddr.get(), pport);
    1559   } else
    1560   {
    1561       snprintf(*proxy, sizeof(char)*1024, "%s %s:%d", "SOCKS", ipAddr.get(), pport);
    1562   }
    1563 
    1564   *len = strlen(*proxy);
    1565 
    1566   PLUGIN_DEBUG("Proxy info for %s: %s\n", siteAddr, *proxy);
    1567 
    1568 #else
    1569 
    15701425  if (browser_functions.getvalueforurl)
    15711426  {
     
    15781433      return NPERR_GENERIC_ERROR;
    15791434  }
    1580 #endif
    15811435
    15821436  return NPERR_NO_ERROR;
     
    16781532plugin_test_appletviewer ()
    16791533{
    1680   PLUGIN_DEBUG ("plugin_test_appletviewer: %s\n", appletviewer_executable);
     1534
     1535  PLUGIN_DEBUG ("plugin_test_appletviewer: %s\n", get_plugin_executable().c_str());
    16811536  NPError error = NPERR_NO_ERROR;
    16821537
     
    16841539  gchar** environment;
    16851540
    1686   command_line[0] = g_strdup (appletviewer_executable);
     1541  command_line[0] = g_strdup (get_plugin_executable().c_str());
    16871542  command_line[1] = g_strdup("-version");
    16881543  command_line[2] = NULL;
     
    16961551      if (channel_error)
    16971552        {
    1698           PLUGIN_ERROR_TWO ("Failed to spawn applet viewer",
     1553          PLUGIN_ERROR ("Failed to spawn applet viewer %s\n",
    16991554                            channel_error->message);
    17001555          g_error_free (channel_error);
     
    17021557        }
    17031558      else
    1704         PLUGIN_ERROR ("Failed to spawn applet viewer");
     1559        PLUGIN_ERROR ("Failed to spawn applet viewer\n");
    17051560      error = NPERR_GENERIC_ERROR;
    17061561    }
     
    17191574}
    17201575
    1721 static NPError
     1576NPError
    17221577plugin_start_appletviewer (ITNPPluginData* data)
    17231578{
     
    17251580  NPError error = NPERR_NO_ERROR;
    17261581
    1727   gchar** command_line;
    1728   gchar** environment;
    1729 
    1730   int cmd_num = 0;
     1582  std::vector<std::string> command_line;
     1583  gchar** environment = NULL;
     1584  std::vector<std::string*>* jvm_args = get_jvm_args();
     1585
     1586  // Construct command line parameters
     1587
     1588  command_line.push_back(get_plugin_executable());
     1589
     1590  //Add JVM args to command_line
     1591  for (int i = 0; i < jvm_args->size(); i++)
     1592  {
     1593    command_line.push_back(*jvm_args->at(i));
     1594  }
     1595
     1596  command_line.push_back(PLUGIN_BOOTCLASSPATH);
     1597  // set the classpath to avoid using the default (cwd).
     1598  command_line.push_back("-classpath");
     1599  command_line.push_back(get_plugin_rt_jar());
     1600
     1601  // Enable coverage agent if we are running instrumented plugin
     1602#ifdef COVERAGE_AGENT
     1603  command_line.push_back(COVERAGE_AGENT);
     1604#endif
     1605
    17311606  if (plugin_debug)
    17321607  {
    1733       command_line = (gchar**) malloc(sizeof(gchar*)*11);
    1734       command_line[cmd_num++] = g_strdup(appletviewer_executable);
    1735       command_line[cmd_num++] = g_strdup_printf(PLUGIN_BOOTCLASSPATH);
    1736       // set the classpath to avoid using the default (cwd).
    1737       command_line[cmd_num++] = g_strdup("-classpath");
    1738       command_line[cmd_num++] = g_strdup_printf("%s/lib/rt.jar", ICEDTEA_WEB_JRE);
    1739       command_line[cmd_num++] = g_strdup("-Xdebug");
    1740       command_line[cmd_num++] = g_strdup("-Xnoagent");
    1741       if (plugin_debug_suspend)
    1742       {
    1743           command_line[cmd_num++] = g_strdup("-Xrunjdwp:transport="DT_SOCKET_DLL",address=8787,server=y,suspend=y");
    1744       } else
    1745       {
    1746           command_line[cmd_num++] = g_strdup("-Xrunjdwp:transport="DT_SOCKET_DLL",address=8787,server=y,suspend=n");
    1747       }
    1748       command_line[cmd_num++] = g_strdup("sun.applet.PluginMain");
    1749 #ifdef __OS2__
    1750       command_line[cmd_num++] = g_strdup_printf("%d", out_pipe [1]);
    1751       command_line[cmd_num++] = g_strdup_printf("%d", in_pipe [1]);
     1608    command_line.push_back("-Xdebug");
     1609    command_line.push_back("-Xnoagent");
     1610
     1611    //Debug flags
     1612    std::string debug_flags = "-Xrunjdwp:transport="DT_SOCKET_DLL",address=8787,server=y,";
     1613    debug_flags += plugin_debug_suspend ? "suspend=y" : "suspend=n";
     1614    command_line.push_back(debug_flags);
     1615  }
     1616
     1617  command_line.push_back("sun.applet.PluginMain");
     1618#ifdef __OS2__
     1619  command_line.push_back((std::ostrstream() << out_pipe[1]).str());
     1620  command_line.push_back((std::ostrstream() << in_pipe[1]).str());
    17521621#else
    1753       command_line[cmd_num++] = g_strdup(out_pipe_name);
    1754       command_line[cmd_num++] = g_strdup(in_pipe_name);
    1755 #endif
    1756       command_line[cmd_num] = NULL;
    1757   } else
    1758   {
    1759       command_line = (gchar**) malloc(sizeof(gchar*)*8);
    1760       command_line[cmd_num++] = g_strdup(appletviewer_executable);
    1761       command_line[cmd_num++] = g_strdup_printf(PLUGIN_BOOTCLASSPATH);
    1762       command_line[cmd_num++] = g_strdup("-classpath");
    1763       command_line[cmd_num++] = g_strdup_printf("%s/lib/rt.jar", ICEDTEA_WEB_JRE);
    1764       command_line[cmd_num++] = g_strdup("sun.applet.PluginMain");
    1765 #ifdef __OS2__
    1766       command_line[cmd_num++] = g_strdup_printf("%d", out_pipe [1]);
    1767       command_line[cmd_num++] = g_strdup_printf("%d", in_pipe [1]);
     1622  command_line.push_back(out_pipe_name);
     1623  command_line.push_back(in_pipe_name);
     1624#endif
     1625  if (plugin_debug_to_console){
     1626      command_line.push_back(debug_pipe_name);
     1627  }
     1628
     1629  // Finished command line parameters
     1630
     1631  environment = plugin_filter_environment();
     1632  std::vector<gchar*> vector_gchar = IcedTeaPluginUtilities::vectorStringToVectorGchar(&command_line);
     1633  gchar **command_line_args = &vector_gchar[0];
     1634
     1635  if (!g_spawn_async (NULL, command_line_args, environment,
     1636#ifdef __OS2__
     1637                      (GSpawnFlags) (G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD),
    17681638#else
    1769       command_line[cmd_num++] = g_strdup(out_pipe_name);
    1770       command_line[cmd_num++] = g_strdup(in_pipe_name);
    1771 #endif
    1772       command_line[cmd_num] = NULL;
    1773   }
    1774 
    1775   environment = plugin_filter_environment();
    1776 
    1777 #ifdef __OS2__
    1778   int flags = G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD;
    1779 #else
    1780   int flags = G_SPAWN_DO_NOT_REAP_CHILD;
    1781 #endif
    1782 
    1783   if (!g_spawn_async (NULL, command_line, environment,
    1784                       (GSpawnFlags) flags,
     1639                      (GSpawnFlags) G_SPAWN_DO_NOT_REAP_CHILD,
     1640#endif
    17851641                      NULL, NULL, &appletviewer_pid, &channel_error))
    17861642    {
    17871643      if (channel_error)
    17881644        {
    1789           PLUGIN_ERROR_TWO ("Failed to spawn applet viewer",
     1645          PLUGIN_ERROR ("Failed to spawn applet viewer %s\n",
    17901646                            channel_error->message);
    17911647          g_error_free (channel_error);
     
    17931649        }
    17941650      else
    1795         PLUGIN_ERROR ("Failed to spawn applet viewer");
     1651        PLUGIN_ERROR ("Failed to spawn applet viewer\n");
    17961652      error = NPERR_GENERIC_ERROR;
    17971653    }
     
    18021658  signal (SIGPIPE, SIG_IGN);
    18031659
    1804   g_strfreev (environment);
    1805 
    1806   for (int i = 0; i < cmd_num; i++) {
    1807     g_free (command_line[i]);
    1808     command_line[i] = NULL;
    1809   }
    1810 
    1811   g_free(command_line);
    1812   command_line = NULL;
     1660  //Free memory
     1661  g_strfreev(environment);
     1662  IcedTeaPluginUtilities::freeStringPtrVector(jvm_args);
     1663  jvm_args = NULL;
     1664  command_line_args = NULL;
    18131665
    18141666  if (appletviewer_pid)
     
    18241676
    18251677/*
    1826  * Replaces certain characters (\r, \n, etc) with HTML escape equivalents.
    1827  *
    1828  * Return string is allocated on the heap. Caller assumes responsibility
    1829  * for freeing the memory via free()
     1678 * Returns JVM options set in itw-settings
    18301679 */
    1831 static char*
    1832 encode_string(char* to_encode)
    1833 {
    1834 
    1835   // Do nothing for an empty string
    1836   if (to_encode == '\0')
    1837       return to_encode;
    1838 
    1839   // worst case scenario -> all characters are newlines or
    1840   // returns, each of which translates to 5 substitutions
    1841   char* encoded = (char*) calloc(((strlen(to_encode)*5)+1), sizeof(char));
    1842 
    1843   strcpy(encoded, "");
    1844 
    1845   for (int i=0; i < strlen(to_encode); i++)
    1846   {
    1847       if (to_encode[i] == '\r')
    1848           encoded = strcat(encoded, "&#13;");
    1849       else if (to_encode[i] == '\n')
    1850           encoded = strcat(encoded, "&#10;");
    1851       else if (to_encode[i] == '>')
    1852           encoded = strcat(encoded, "&gt;");
    1853       else if (to_encode[i] == '<')
    1854           encoded = strcat(encoded, "&lt;");
    1855       else if (to_encode[i] == '&')
    1856           encoded = strcat(encoded, "&amp;");
    1857       else if (to_encode[i] == '"')
    1858           encoded = strcat(encoded, "&quot;");
     1680std::vector<std::string*>*
     1681get_jvm_args()
     1682{
     1683  std::string output;
     1684  std::vector<std::string*>* tokenOutput = NULL;
     1685  bool args_defined = read_deploy_property_value("deployment.plugin.jvm.arguments", output);
     1686  if (!args_defined){
     1687    return new std::vector<std::string*>();
     1688  }
     1689  tokenOutput = IcedTeaPluginUtilities::strSplit(output.c_str(), " \n");
     1690  return tokenOutput;
     1691}
     1692
     1693
     1694/*
     1695 * Escape characters for passing to Java.
     1696 * "\n" for new line, "\\" for "\", "\:" for ";"
     1697 */
     1698std::string
     1699escape_parameter_string(const char* to_encode) {
     1700  std::string encoded;
     1701
     1702  if (to_encode == NULL)
     1703  {
     1704      return encoded;
     1705  }
     1706
     1707  size_t length = strlen(to_encode);
     1708  for (int i = 0; i < length; i++)
     1709  {
     1710      if (to_encode[i] == '\n')
     1711          encoded += "\\n";
     1712      else if (to_encode[i] == '\\')
     1713          encoded += "\\\\";
     1714      else if (to_encode[i] == ';')
     1715          encoded += "\\:";
    18591716      else
    1860       {
    1861            char* orig_char = (char*) calloc(2, sizeof(char));
    1862            orig_char[0] = to_encode[i];
    1863            orig_char[1] = '\0';
    1864 
    1865            strcat(encoded, orig_char);
    1866 
    1867            free(orig_char);
    1868            orig_char = NULL;
    1869       }
     1717          encoded += to_encode[i];
    18701718  }
    18711719
     
    18731721}
    18741722
    1875 // Build up the applet tag string that we'll send to the applet
    1876 // viewer.
    1877 static gchar*
    1878 plugin_create_applet_tag (int16_t argc, char* argn[], char* argv[])
    1879 {
    1880   PLUGIN_DEBUG ("plugin_create_applet_tag\n");
    1881 
    1882   gchar* applet_tag = g_strdup ("<EMBED ");
    1883   gchar* parameters = g_strdup ("");
    1884 
    1885   for (int16_t i = 0; i < argc; i++)
    1886     {
    1887       gchar* argn_escaped = encode_string(argn[i]);
    1888       gchar* argv_escaped = encode_string(argv[i]);
    1889 
    1890       if (!g_ascii_strcasecmp (argn_escaped, "code"))
    1891         {
    1892           gchar* code = g_strdup_printf ("CODE=\"%s\" ", argv_escaped);
    1893           applet_tag = g_strconcat (applet_tag, code, NULL);
    1894           g_free (code);
    1895           code = NULL;
    1896     }
    1897       else if (!g_ascii_strcasecmp (argn_escaped, "java_code"))
    1898     {
    1899           gchar* java_code = g_strdup_printf ("JAVA_CODE=\"%s\" ", argv_escaped);
    1900           applet_tag = g_strconcat (applet_tag, java_code, NULL);
    1901           g_free (java_code);
    1902           java_code = NULL;
    1903     }
    1904       else if (!g_ascii_strcasecmp (argn_escaped, "codebase"))
    1905     {
    1906           gchar* codebase = g_strdup_printf ("CODEBASE=\"%s\" ", argv_escaped);
    1907           applet_tag = g_strconcat (applet_tag, codebase, NULL);
    1908           g_free (codebase);
    1909           codebase = NULL;
    1910     }
    1911       else if (!g_ascii_strcasecmp (argn_escaped, "java_codebase"))
    1912     {
    1913           gchar* java_codebase = g_strdup_printf ("JAVA_CODEBASE=\"%s\" ", argv_escaped);
    1914           applet_tag = g_strconcat (applet_tag, java_codebase, NULL);
    1915           g_free (java_codebase);
    1916           java_codebase = NULL;
    1917     }
    1918       else if (!g_ascii_strcasecmp (argn_escaped, "classid"))
    1919     {
    1920           gchar* classid = g_strdup_printf ("CLASSID=\"%s\" ", argv_escaped);
    1921           applet_tag = g_strconcat (applet_tag, classid, NULL);
    1922           g_free (classid);
    1923           classid = NULL;
    1924     }
    1925       else if (!g_ascii_strcasecmp (argn_escaped, "archive"))
    1926     {
    1927           gchar* archive = g_strdup_printf ("ARCHIVE=\"%s\" ", argv_escaped);
    1928           applet_tag = g_strconcat (applet_tag, archive, NULL);
    1929           g_free (archive);
    1930           archive = NULL;
    1931     }
    1932       else if (!g_ascii_strcasecmp (argn_escaped, "java_archive"))
    1933     {
    1934           gchar* java_archive = g_strdup_printf ("JAVA_ARCHIVE=\"%s\" ", argv_escaped);
    1935           applet_tag = g_strconcat (applet_tag, java_archive, NULL);
    1936           g_free (java_archive);
    1937           java_archive = NULL;
    1938     }
    1939       else if (!g_ascii_strcasecmp (argn_escaped, "width"))
    1940     {
    1941           gchar* width = g_strdup_printf ("width=\"%s\" ", argv_escaped);
    1942           applet_tag = g_strconcat (applet_tag, width, NULL);
    1943           g_free (width);
    1944           width = NULL;
    1945     }
    1946       else if (!g_ascii_strcasecmp (argn_escaped, "height"))
    1947     {
    1948           gchar* height = g_strdup_printf ("height=\"%s\" ", argv_escaped);
    1949           applet_tag = g_strconcat (applet_tag, height, NULL);
    1950           g_free (height);
    1951           height = NULL;
    1952     }
    1953       else
    1954         {
    1955 
    1956           if (argv_escaped != '\0')
    1957             {
    1958               parameters = g_strconcat (parameters, "<PARAM NAME=\"", argn_escaped,
    1959                                         "\" VALUE=\"", argv_escaped, "\">", NULL);
    1960             }
    1961         }
    1962 
    1963       free(argn_escaped);
    1964       free(argv_escaped);
    1965 
    1966       argn_escaped = NULL;
    1967       argv_escaped = NULL;
    1968     }
    1969 
    1970   applet_tag = g_strconcat (applet_tag, ">", parameters, "</EMBED>", NULL);
    1971 
    1972   g_free (parameters);
    1973   parameters = NULL;
    1974 
    1975   PLUGIN_DEBUG ("plugin_create_applet_tag return\n");
    1976 
    1977   return applet_tag;
     1723/*
     1724 * Build a string containing an encoded list of parameters to send to the applet viewer.
     1725 * The parameters are separated as 'key1;value1;key2;value2;'. As well, they are
     1726 * separated and escaped as:
     1727 * "\n" for new line, "\\" for "\", "\:" for ";"
     1728 */
     1729std::string
     1730plugin_parameters_string (int argc, char* argn[], char* argv[])
     1731{
     1732  PLUGIN_DEBUG ("plugin_parameters_string\n");
     1733
     1734  std::string parameters;
     1735
     1736  for (int i = 0; i < argc; i++)
     1737  {
     1738    if (argv[i] != NULL)
     1739    {
     1740        std::string name_escaped = escape_parameter_string(argn[i]);
     1741        std::string value_escaped = escape_parameter_string(argv[i]);
     1742
     1743        //Encode parameters and send as 'key1;value1;key2;value2;' etc
     1744        parameters += name_escaped;
     1745        parameters += ';';
     1746        parameters += value_escaped;
     1747        parameters += ';';
     1748    }
     1749  }
     1750
     1751  PLUGIN_DEBUG ("plugin_parameters_string return\n");
     1752
     1753  return parameters;
    19781754}
    19791755
     
    20031779          if (channel_error)
    20041780            {
    2005               PLUGIN_ERROR_TWO ("Failed to write bytes to output channel",
     1781              PLUGIN_ERROR ("Failed to write bytes to output channel '%s' \n",
    20061782                                channel_error->message);
    20071783              g_error_free (channel_error);
     
    20091785            }
    20101786          else
    2011             PLUGIN_ERROR ("Failed to write bytes to output channel");
     1787            PLUGIN_ERROR ("Failed to write bytes to output channel for %s", newline_message);
    20121788        }
    20131789
     
    20171793          if (channel_error)
    20181794            {
    2019               PLUGIN_ERROR_TWO ("Failed to flush bytes to output channel",
     1795              PLUGIN_ERROR ("Failed to flush bytes to output channel '%s'\n",
    20201796                                channel_error->message);
    20211797              g_error_free (channel_error);
     
    20231799            }
    20241800          else
    2025             PLUGIN_ERROR ("Failed to flush bytes to output channel");
     1801            PLUGIN_ERROR ("Failed to flush bytes to output channel for %s", newline_message);
    20261802        }
    20271803      g_free (newline_message);
    20281804      newline_message = NULL;
    20291805
    2030       PLUGIN_DEBUG ("  PIPE: plugin wrote: %s\n", message);
     1806      PLUGIN_DEBUG ("  PIPE: plugin wrote(?): %s\n", message);
    20311807    }
    20321808
    20331809  PLUGIN_DEBUG ("plugin_send_message_to_appletviewer return\n");
     1810}
     1811
     1812// unlike like  plugin_send_message_to_appletviewer
     1813// do not debug
     1814// do not error
     1815// do not have its own line end
     1816// is accesed by only one thread
     1817// have own pipe
     1818// jvm must be up
     1819void
     1820plugin_send_message_to_appletviewer_console (gchar const* newline_message)
     1821{
     1822  gsize bytes_written = 0;
     1823  if (g_io_channel_write_chars (debug_to_appletviewer,
     1824                                newline_message, -1, &bytes_written,
     1825                                &channel_error) != G_IO_STATUS_NORMAL)  {
     1826          if (channel_error) {
     1827              //error must be freed
     1828              g_error_free (channel_error);
     1829              channel_error = NULL;
     1830            }
     1831        }
     1832}
     1833//flush only when its full
     1834void flush_plugin_send_message_to_appletviewer_console (){
     1835  if (g_io_channel_flush (debug_to_appletviewer, &channel_error)
     1836                                                 != G_IO_STATUS_NORMAL) {
     1837          if (channel_error) {
     1838              g_error_free (channel_error);
     1839              channel_error = NULL;
     1840            }
     1841        }
    20341842}
    20351843
     
    20841892              if (channel_error)
    20851893                {
    2086                   PLUGIN_ERROR_TWO ("Failed to write shutdown message to"
    2087                                     " appletviewer", channel_error->message);
     1894                  PLUGIN_ERROR ("Failed to write shutdown message to "
     1895                                    " appletviewer, %s \n", channel_error->message);
    20881896                  g_error_free (channel_error);
    20891897                  channel_error = NULL;
    20901898                }
    20911899              else
    2092                 PLUGIN_ERROR ("Failed to write shutdown message to");
     1900                PLUGIN_ERROR ("Failed to write shutdown message to\n");
    20931901            }
    20941902
     
    20981906              if (channel_error)
    20991907                {
    2100                   PLUGIN_ERROR_TWO ("Failed to write shutdown message to"
    2101                                     " appletviewer", channel_error->message);
     1908                  PLUGIN_ERROR ("Failed to write shutdown message to"
     1909                                    " appletviewer %s \n", channel_error->message);
    21021910                  g_error_free (channel_error);
    21031911                  channel_error = NULL;
    21041912                }
    21051913              else
    2106                 PLUGIN_ERROR ("Failed to write shutdown message to");
     1914                PLUGIN_ERROR ("Failed to write shutdown message to\n");
    21071915            }
    21081916
     
    21131921              if (channel_error)
    21141922                {
    2115                   PLUGIN_ERROR_TWO ("Failed to shut down appletviewer"
    2116                                     " output channel", channel_error->message);
     1923                  PLUGIN_ERROR ("Failed to shut down appletviewer"
     1924                                    " output channel %s \n", channel_error->message);
    21171925                  g_error_free (channel_error);
    21181926                  channel_error = NULL;
    21191927                }
    21201928              else
    2121                 PLUGIN_ERROR ("Failed to shut down appletviewer");
     1929                PLUGIN_ERROR ("Failed to shut down appletviewer\n");
    21221930            }
    21231931        }
     
    21311939              if (channel_error)
    21321940                {
    2133                   PLUGIN_ERROR_TWO ("Failed to shut down appletviewer"
    2134                                     " input channel", channel_error->message);
     1941                  PLUGIN_ERROR ("Failed to shut down appletviewer"
     1942                                    " input channel %s \n", channel_error->message);
    21351943                  g_error_free (channel_error);
    21361944                  channel_error = NULL;
    21371945                }
    21381946              else
    2139                 PLUGIN_ERROR ("Failed to shut down appletviewer");
     1947                PLUGIN_ERROR ("Failed to shut down appletviewer\n");
    21401948            }
    21411949        }
     
    21561964}
    21571965
    2158 static void
     1966void
    21591967plugin_data_destroy (NPP instance)
    21601968{
     
    21731981    }
    21741982
    2175   tofree->window_handle = NULL;
    2176   tofree->window_height = 0;
    2177   tofree->window_width = 0;
    2178 
    2179   // cleanup_appletviewer_mutex:
    2180   g_mutex_free (tofree->appletviewer_mutex);
    2181   tofree->appletviewer_mutex = NULL;
    2182 
    2183   // cleanup_instance_string:
    2184   g_free (tofree->instance_id);
    2185   tofree->instance_id = NULL;
    2186 
    2187   // cleanup applet tag
    2188   g_free (tofree->applet_tag);
    2189   tofree->applet_tag = NULL;
    2190 
    2191   g_free(tofree->source);
    2192   tofree->source = NULL;
    2193 
    2194   // cleanup_data:
    2195   // Eliminate back-pointer to plugin instance.
    2196   tofree->owner = NULL;
     1983  /* Explicitly call destructor */
     1984  tofree->~ITNPPluginData();
     1985
    21971986  (*browser_functions.memfree) (tofree);
    2198   tofree = NULL;
    21991987
    22001988  PLUGIN_DEBUG ("plugin_data_destroy return\n");
     
    22041992initialize_browser_functions(const NPNetscapeFuncs* browserTable)
    22051993{
    2206 #if MOZILLA_VERSION_COLLAPSED < 1090100
    2207 #define NPNETSCAPEFUNCS_LAST_FIELD_USED (browserTable->pluginthreadasynccall)
    2208 #else
    22091994#define NPNETSCAPEFUNCS_LAST_FIELD_USED (browserTable->setvalueforurl)
    2210 #endif
    22111995
    22121996  //Determine the size in bytes, as a difference of the address past the last used field
     
    22502034  pluginTable->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
    22512035  pluginTable->size = sizeof (NPPluginFuncs);
    2252 
    2253 #if MOZILLA_VERSION_COLLAPSED < 1090100
    2254   pluginTable->newp = NewNPP_NewProc (ITNP_New);
    2255   pluginTable->destroy = NewNPP_DestroyProc (ITNP_Destroy);
    2256   pluginTable->setwindow = NewNPP_SetWindowProc (ITNP_SetWindow);
    2257   pluginTable->newstream = NewNPP_NewStreamProc (ITNP_NewStream);
    2258   pluginTable->destroystream = NewNPP_DestroyStreamProc (ITNP_DestroyStream);
    2259   pluginTable->asfile = NewNPP_StreamAsFileProc (ITNP_StreamAsFile);
    2260   pluginTable->writeready = NewNPP_WriteReadyProc (ITNP_WriteReady);
    2261   pluginTable->write = NewNPP_WriteProc (ITNP_Write);
    2262   pluginTable->print = NewNPP_PrintProc (ITNP_Print);
    2263   pluginTable->urlnotify = NewNPP_URLNotifyProc (ITNP_URLNotify);
    2264   pluginTable->getvalue = NewNPP_GetValueProc (ITNP_GetValue);
    2265 #else
    22662036  pluginTable->newp = NPP_NewProcPtr (ITNP_New);
    22672037  pluginTable->destroy = NPP_DestroyProcPtr (ITNP_Destroy);
     
    22752045  pluginTable->urlnotify = NPP_URLNotifyProcPtr (ITNP_URLNotify);
    22762046  pluginTable->getvalue = NPP_GetValueProcPtr (ITNP_GetValue);
    2277 #endif
    22782047
    22792048  return true;
     2049}
     2050
     2051// Make sure the plugin data directory exists, creating it if necessary.
     2052NPError
     2053initialize_data_directory()
     2054{
     2055
     2056  data_directory = IcedTeaPluginUtilities::getRuntimePath() + "/icedteaplugin-";
     2057  if (getenv("USER") != NULL) {
     2058    data_directory = data_directory + getenv("USER") + "-";
     2059  }
     2060  data_directory += "XXXXXX";
     2061  // Now create a icedteaplugin subdir
     2062  char fileNameX[data_directory.length()+1];
     2063  std::strcpy (fileNameX, data_directory.c_str());
     2064  char * fileName = mkdtemp(fileNameX);
     2065  if (fileName == NULL) {
     2066    PLUGIN_ERROR ("Failed to create data directory %s, %s\n",
     2067                        data_directory.c_str(),
     2068                        strerror (errno));
     2069    return NPERR_GENERIC_ERROR;
     2070  }
     2071  data_directory = std::string(fileName);
     2072
     2073  //open uniques icedteaplugin subdir for one single run 
     2074  data_directory_descriptor = opendir(data_directory.c_str());
     2075  if (data_directory_descriptor == NULL) {
     2076      PLUGIN_ERROR ("Failed to open data directory %s %s\n",
     2077                      data_directory.c_str(), strerror (errno));
     2078      return NPERR_GENERIC_ERROR;
     2079  }
     2080
     2081  return NPERR_NO_ERROR;
    22802082}
    22812083
     
    22912093// been called. There is no need to call this function more than once and
    22922094// this workaround avoids any duplicate calls.
     2095__attribute__ ((visibility ("default")))
    22932096NPError
    22942097#if defined(_WIN32) || defined (__OS2__)
     
    23102113  if ((browserTable == NULL) || (pluginTable == NULL))
    23112114  {
    2312     PLUGIN_ERROR ("Browser or plugin function table is NULL.");
     2115    PLUGIN_ERROR ("Browser or plugin function table is NULL.\n");
    23132116
    23142117    return NPERR_INVALID_FUNCTABLE_ERROR;
     
    23212124  if ((browserTable->version >> 8) > NP_VERSION_MAJOR)
    23222125    {
    2323       PLUGIN_ERROR ("Incompatible version.");
     2126      PLUGIN_ERROR ("Incompatible version.\n");
    23242127
    23252128      return NPERR_INCOMPATIBLE_VERSION_ERROR;
     
    23342137  if ( !browser_functions_supported )
    23352138  {
    2336         PLUGIN_ERROR ("Invalid browser function table.");
     2139        PLUGIN_ERROR ("Invalid browser function table.\n");
    23372140
    23382141        return NPERR_INVALID_FUNCTABLE_ERROR;
     
    23482151  if ( !plugin_functions_supported )
    23492152  {
    2350     PLUGIN_ERROR ("Invalid plugin function table.");
     2153    PLUGIN_ERROR ("Invalid plugin function table.\n");
    23512154
    23522155    return NPERR_INVALID_FUNCTABLE_ERROR;
     
    23712174  NPError np_error = NPERR_NO_ERROR;
    23722175#ifndef __OS2__
    2373   // Make sure the plugin data directory exists, creating it if
    2374   // necessary.
    2375   data_directory = g_strconcat (P_tmpdir, NULL);
    2376   if (!data_directory)
    2377     {
    2378       PLUGIN_ERROR ("Failed to create data directory name.");
    2379       return NPERR_OUT_OF_MEMORY_ERROR;
    2380     }
    2381 
    2382   // If P_tmpdir does not exist, try /tmp directly
    2383 
    2384   if (!g_file_test (data_directory,
    2385                     (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
    2386     {
    2387       int file_error = 0;
    2388 
    2389       data_directory = g_strconcat ("/tmp", NULL);
    2390         if (!data_directory)
    2391           {
    2392             PLUGIN_ERROR ("Failed to create data directory name.");
    2393             return NPERR_OUT_OF_MEMORY_ERROR;
    2394           }
    2395 
    2396     }
    2397 
    2398   data_directory = g_strconcat (data_directory, "/icedteaplugin-", getenv("USER"), NULL);
    2399 
    2400   if (!data_directory)
    2401   {
    2402       PLUGIN_ERROR ("Failed to create data directory name.");
    2403       return NPERR_OUT_OF_MEMORY_ERROR;
    2404   }
    2405 
    2406   // Now create a icedteaplugin subdir
    2407   if (!g_file_test (data_directory,
    2408                     (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
    2409     {
    2410       int file_error = 0;
    2411 
    2412       file_error = g_mkdir (data_directory, 0700);
    2413       if (file_error != 0)
    2414         {
    2415           PLUGIN_ERROR_THREE ("Failed to create data directory",
    2416                           data_directory,
    2417                           strerror (errno));
    2418           np_error = NPERR_GENERIC_ERROR;
    2419           goto cleanup_data_directory;
    2420         }
    2421     }
    2422 
    2423 
    2424   // If data directory doesn't exit by this point, bail
    2425   if (!g_file_test (data_directory,
    2426                     (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
    2427     {
    2428       PLUGIN_ERROR_THREE ("Temp directory does not exist: ",
    2429                           data_directory,
    2430                           strerror (errno));
    2431 
    2432       np_error = NPERR_GENERIC_ERROR;
    2433             goto cleanup_data_directory;
    2434 
     2176  // create directory for pipes
     2177  np_error =  initialize_data_directory();
     2178  if (np_error != NPERR_NO_ERROR)
     2179    {
     2180      PLUGIN_ERROR("Unable to create data directory %s\n", data_directory.c_str());
     2181      return np_error;
    24352182    }
    24362183#endif
    24372184
    24382185  // Set appletviewer_executable.
    2439   gchar* filename = g_strdup(ICEDTEA_WEB_JRE);
    2440   appletviewer_executable = g_strdup_printf ("%s/bin/java",
    2441                                              filename);
    2442   PLUGIN_DEBUG("Executing java at %s\n", appletviewer_executable);
    2443   if (!appletviewer_executable)
    2444     {
    2445       PLUGIN_ERROR ("Failed to create appletviewer executable name.");
    2446       np_error = NPERR_OUT_OF_MEMORY_ERROR;
    2447       goto cleanup_filename;
    2448     }
    2449 
     2186  PLUGIN_DEBUG("Executing java at %s\n", get_plugin_executable().c_str());
    24502187  np_error = plugin_test_appletviewer ();
    24512188  if (np_error != NPERR_NO_ERROR)
    24522189    {
    2453       plugin_display_failure_dialog ();
    2454       goto cleanup_appletviewer_executable;
    2455     }
    2456   g_free (filename);
     2190      PLUGIN_ERROR("Unable to find java executable %s\n", get_plugin_executable().c_str());
     2191      return np_error;
     2192    }
    24572193
    24582194  // Initialize threads (needed for mutexes).
     
    24642200  {
    24652201    PLUGIN_DEBUG ("Failed to integrate with PM");
    2466     np_error = NPERR_GENERIC_ERROR;
    2467     goto cleanup_appletviewer_executable;
     2202    return NPERR_GENERIC_ERROR;
    24682203  }
    24692204#endif
     
    24712206  plugin_instance_mutex = g_mutex_new ();
    24722207
    2473   PLUGIN_DEBUG ("NP_Initialize: using %s\n", appletviewer_executable);
     2208  PLUGIN_DEBUG ("NP_Initialize: using %s\n", get_plugin_executable().c_str());
    24742209
    24752210  plugin_req_proc = new PluginRequestProcessor();
     
    25082243
    25092244  return NPERR_NO_ERROR;
    2510 
    2511  cleanup_appletviewer_executable:
    2512   if (appletviewer_executable)
    2513     {
    2514       g_free (appletviewer_executable);
    2515       appletviewer_executable = NULL;
    2516     }
    2517 
    2518  cleanup_filename:
    2519   if (filename)
    2520     {
    2521       g_free (filename);
    2522       filename = NULL;
    2523     }
    2524 
    2525  cleanup_data_directory:
    2526   if (data_directory)
    2527     {
    2528       g_free (data_directory);
    2529       data_directory = NULL;
    2530     }
    2531 
    2532 
    2533   return np_error;
    25342245}
    25352246
     
    25662277// Returns a string describing the MIME type that this plugin
    25672278// handles.
     2279__attribute__ ((visibility ("default")))
    25682280#ifdef LEGACY_XULRUNNERAPI
    25692281  char*
     
    25732285OSCALL NP_GetMIMEDescription ()
    25742286{
     2287  //this function is called severaltimes between lunches
    25752288  PLUGIN_DEBUG ("NP_GetMIMEDescription\n");
    25762289
     
    25822295// Returns a value relevant to the plugin as a whole.  The browser
    25832296// calls this function to obtain information about the plugin.
     2297__attribute__ ((visibility ("default")))
    25842298NPError
    25852299OSCALL NP_GetValue (void* future, NPPVariable variable, void* value)
     
    26032317
    26042318    default:
    2605       PLUGIN_ERROR ("Unknown plugin value requested.");
     2319      PLUGIN_ERROR ("Unknown plugin value requested.\n");
    26062320      result = NPERR_GENERIC_ERROR;
    26072321      break;
     
    26152329// Shuts down the plugin.  Called after the last plugin instance is
    26162330// destroyed.
     2331__attribute__ ((visibility ("default")))
    26172332NPError
    26182333OSCALL NP_Shutdown (void)
     
    26292344      g_mutex_free (plugin_instance_mutex);
    26302345      plugin_instance_mutex = NULL;
    2631     }
    2632 
    2633   if (data_directory)
    2634     {
    2635       g_free (data_directory);
    2636       data_directory = NULL;
    2637     }
    2638 
    2639   if (appletviewer_executable)
    2640     {
    2641       g_free (appletviewer_executable);
    2642       appletviewer_executable = NULL;
    26432346    }
    26442347
     
    26992402#endif
    27002403
     2404  if (plugin_debug_to_console){
     2405    //jvm_up is now false
     2406    if (g_io_channel_shutdown (debug_to_appletviewer,
     2407                                     TRUE, &channel_error)
     2408              != G_IO_STATUS_NORMAL)
     2409            {
     2410              if (channel_error)
     2411                {
     2412                  PLUGIN_ERROR ("Failed to shut down appletviewer"
     2413                                    " debug channel\n", channel_error->message);
     2414                  g_error_free (channel_error);
     2415                  channel_error = NULL;
     2416                }
     2417              else
     2418                PLUGIN_ERROR ("Failed to shut down debug to appletviewer\n");
     2419            }
     2420    // cleanup_out_to_appletviewer:
     2421    if (debug_to_appletviewer)
     2422     g_io_channel_unref (debug_to_appletviewer);
     2423    out_to_appletviewer = NULL;
     2424    // cleanup_debug_pipe:
     2425    // Delete debug pipe.
     2426    PLUGIN_DEBUG ("NP_Shutdown: deleting debug fifo: %s\n", debug_pipe_name);
     2427    unlink (debug_pipe_name);
     2428    PLUGIN_DEBUG ("NP_Shutdown: deleted debug fifo: %s\n", debug_pipe_name);
     2429    // cleanup_out_pipe_name:
     2430    g_free (debug_pipe_name);
     2431    debug_pipe_name = NULL;
     2432  }
     2433 
    27012434  // Destroy the call queue mutex
    27022435  pthread_mutex_destroy(&pluginAsyncCallMutex);
     
    27362469  //delete internal_bus;
    27372470
     2471  cleanUpDir();
     2472 
    27382473  PLUGIN_DEBUG ("NP_Shutdown return\n");
     2474 
     2475  if (plugin_debug_to_file){
     2476    fflush (plugin_file_log);
     2477    //fclose (plugin_file_log);
     2478    //keep writing untill possible!
     2479  } 
    27392480
    27402481  return NPERR_NO_ERROR;
     
    27622503        if (!data->window_handle)
    27632504        {
    2764             plugin_send_initialization_message(data->instance_id, 0, 0, 0, data->applet_tag);
     2505            plugin_send_initialization_message(data->instance_id, 0, 0, 0, data->parameters_string);
    27652506        }
    27662507
     
    27712512        if (java_result->error_occurred)
    27722513        {
    2773             printf("Error: Unable to fetch applet instance id from Java side.\n");
     2514            PLUGIN_ERROR("Error: Unable to fetch applet instance id from Java side.\n");
    27742515            return NULL;
    27752516        }
     
    27812522        if (java_result->error_occurred)
    27822523        {
    2783             printf("Error: Unable to fetch applet instance id from Java side.\n");
     2524            PLUGIN_ERROR("Error: Unable to fetch applet instance id from Java side.\n");
    27842525            return NULL;
    27852526        }
     
    27872528        applet_class_id.append(*(java_result->return_string));
    27882529
    2789         obj = IcedTeaScriptableJavaPackageObject::get_scriptable_java_object(instance, applet_class_id, instance_id, false);
     2530        obj = IcedTeaScriptableJavaObject::get_scriptable_java_object(instance, applet_class_id, instance_id, false);
    27902531
    27912532    } else
    27922533    {
    2793         obj = IcedTeaScriptablePluginObject::get_scriptable_java_package_object(instance, "");
     2534        obj = IcedTeaScriptableJavaPackageObject::get_scriptable_java_package_object(instance, "");
    27942535    }
    27952536
Note: See TracChangeset for help on using the changeset viewer.