Ignore:
Timestamp:
Feb 11, 2013, 8:53:47 PM (13 years ago)
Author:
dmik
Message:

Merge icedtea-web v1.3 to trunk.

Location:
trunk/icedtea-web
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/icedtea-web

  • trunk/icedtea-web/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc

    r358 r418  
    921921    {
    922922        className = "java.lang.String";
    923 #if MOZILLA_VERSION_COLLAPSED < 1090200
    924         stringArg += NPVARIANT_TO_STRING(variant).utf8characters;
    925 #else
    926         stringArg += NPVARIANT_TO_STRING(variant).UTF8Characters;
    927 #endif
     923        stringArg = IcedTeaPluginUtilities::NPVariantAsString(variant);
    928924    } else if (NPVARIANT_IS_OBJECT(variant))
    929925    {
     
    938934            PLUGIN_DEBUG("NPObject is not a Java object\n");
    939935            NPIdentifier length_id = browser_functions.getstringidentifier("length");
     936            bool isJSObjectArray = false;
    940937
    941938            // FIXME: We currently only handle <= 2 dim arrays. Do we really need more though?
     
    953950                IcedTeaPluginUtilities::itoa(NPVARIANT_TO_INT32(length), &length_str);
    954951
    955                 if (NPVARIANT_TO_INT32(length) > 0)
     952                if (NPVARIANT_TO_INT32(length) >= 0)
    956953                {
    957954                    NPIdentifier id_0 = browser_functions.getintidentifier(0);
     
    973970                        getArrayTypeForJava(instance, first_element, &java_array_type);
    974971                    }
    975                 } else
    976                     java_array_type.append("jsobject");
     972                }
     973
     974                // For JSObject arrays, we create a regular object (accessible via JSObject.getSlot())
     975                if (NPVARIANT_TO_INT32(length) < 0 || !java_array_type.compare("jsobject"))
     976                {
     977                    isJSObjectArray = true;
     978                    goto createRegularObject;
     979                }
    977980
    978981                java_result = java_request.newArray(java_array_type, length_str);
     
    10121015                // Got here => no errors above. We're good to return!
    10131016                return;
    1014             } else // Else it is not an array
     1017            }
     1018
     1019            createRegularObject:
     1020            if (!IcedTeaPluginUtilities::isObjectJSArray(instance, obj) || isJSObjectArray) // Else it is not an array
    10151021            {
    10161022
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc

    r394 r418  
    108108#define PLUGIN_FULL_NAME PLUGIN_NAME " (using " PLUGIN_VERSION ")"
    109109#define PLUGIN_DESC "The <a href=\"" PACKAGE_URL "\">" PLUGIN_NAME "</a> executes Java applets."
     110
     111#ifdef HAVE_JAVA7
     112 #define JPI_VERSION "1.7.0_" JDK_UPDATE_VERSION
     113 #define PLUGIN_APPLET_MIME_DESC7 \
     114  "application/x-java-applet;version=1.7:class,jar:IcedTea;"
     115 #define PLUGIN_BEAN_MIME_DESC7 \
     116  "application/x-java-bean;version=1.7:class,jar:IcedTea;"
     117#else
     118 #define JPI_VERSION "1.6.0_" JDK_UPDATE_VERSION
     119 #define PLUGIN_APPLET_MIME_DESC7
     120 #define PLUGIN_BEAN_MIME_DESC7
     121#endif
    110122
    111123#define PLUGIN_MIME_DESC                                               \
     
    126138  "application/x-java-applet;version=1.5:class,jar:IcedTea;"           \
    127139  "application/x-java-applet;version=1.6:class,jar:IcedTea;"           \
    128   "application/x-java-applet;jpi-version=1.6.0_" JDK_UPDATE_VERSION ":class,jar:IcedTea;"  \
     140  PLUGIN_APPLET_MIME_DESC7 \
     141  "application/x-java-applet;jpi-version=" JPI_VERSION ":class,jar:IcedTea;"  \
    129142  "application/x-java-bean:class,jar:IcedTea;"                         \
    130143  "application/x-java-bean;version=1.1:class,jar:IcedTea;"             \
     
    142155  "application/x-java-bean;version=1.5:class,jar:IcedTea;"             \
    143156  "application/x-java-bean;version=1.6:class,jar:IcedTea;"             \
    144   "application/x-java-bean;jpi-version=1.6.0_" JDK_UPDATE_VERSION ":class,jar:IcedTea;"    \
     157  PLUGIN_BEAN_MIME_DESC7 \
     158  "application/x-java-bean;jpi-version=" JPI_VERSION ":class,jar:IcedTea;"    \
    145159  "application/x-java-vm-npruntime::IcedTea;"
    146160
     
    280294pthread_cond_t cond_message_available = PTHREAD_COND_INITIALIZER;
    281295
     296
     297#ifdef LEGACY_GLIB
     298// Returns key from first item stored in hashtable
     299gboolean
     300find_first_item_in_hash_table(gpointer key, gpointer value, gpointer user_data)
     301{
     302    user_data = key;
     303    return (gboolean)TRUE;
     304}
     305
     306int
     307g_strcmp0(char *str1, char *str2)
     308{
     309   if (str1 != NULL)
     310     return str2 != NULL ? strcmp(str1, str2) : 1;
     311   else // str1 == NULL
     312     return str2 != NULL ? 1 : 0;
     313}
     314
     315
     316#endif
     317
     318
     319/*
     320 * Find first member in GHashTable* depending on version of glib
     321 */
     322gpointer getFirstInTableInstance(GHashTable* table)
     323{
     324      gpointer id, instance;
     325      #ifndef LEGACY_GLIB
     326        GHashTableIter iter;
     327        g_hash_table_iter_init (&iter, table);
     328        g_hash_table_iter_next (&iter, &instance, &id);
     329      #else
     330        g_hash_table_find(table, (GHRFunc)find_first_item_in_hash_table, &instance);
     331      #endif
     332        return instance;
     333}
     334
    282335// Functions prefixed by ITNP_ are instance functions.  They are called
    283336// by the browser and operate on instances of ITNPPluginData.
     
    405458
    406459 cleanup_appletviewer_mutex:
    407   g_free (data->appletviewer_mutex);
     460  g_mutex_free (data->appletviewer_mutex);
    408461  data->appletviewer_mutex = NULL;
    409462
     
    9651018get_cookie_info(const char* siteAddr, char** cookieString, uint32_t* len)
    9661019{
     1020  // Only attempt to perform this operation if there is a valid plugin instance
     1021  if (g_hash_table_size(instance_to_id_map) <= 0)
     1022  {
     1023    return NPERR_GENERIC_ERROR;
     1024  }
    9671025#if MOZILLA_VERSION_COLLAPSED < 1090100
    9681026  nsresult rv;
     
    10081066  if (browser_functions.getvalueforurl)
    10091067  {
    1010       GHashTableIter iter;
    1011       gpointer id, instance;
    1012 
    1013       g_hash_table_iter_init (&iter, instance_to_id_map);
    1014       g_hash_table_iter_next (&iter, &instance, &id);
    1015 
     1068      gpointer instance=getFirstInTableInstance(instance_to_id_map);
    10161069      return browser_functions.getvalueforurl((NPP) instance, NPNURLVCookie, siteAddr, cookieString, len);
    10171070  } else
     
    10231076
    10241077  return NPERR_NO_ERROR;
     1078}
     1079
     1080static NPError
     1081set_cookie_info(const char* siteAddr, const char* cookieString, uint32_t len)
     1082{
     1083  // Only attempt to perform this operation if there is a valid plugin instance
     1084  if (g_hash_table_size(instance_to_id_map) > 0 && browser_functions.getvalueforurl)
     1085  {
     1086      // We arbitrarily use the first valid instance we can grab
     1087      // For an explanation of the logic behind this, see get_cookie_info
     1088      gpointer instance = getFirstInTableInstance(instance_to_id_map);
     1089      return browser_functions.setvalueforurl((NPP) instance, NPNURLVCookie, siteAddr, cookieString, len);
     1090  }
     1091
     1092  return NPERR_GENERIC_ERROR;;
    10251093}
    10261094
     
    11381206                               href_id, &href);
    11391207
    1140   // Strip everything after the last "/"
    1141 #if MOZILLA_VERSION_COLLAPSED < 1090200
    1142   gchar** parts = g_strsplit (NPVARIANT_TO_STRING(href).utf8characters, "/", -1);
    1143 #else
    1144   gchar** parts = g_strsplit (NPVARIANT_TO_STRING(href).UTF8Characters, "/", -1);
    1145 #endif
    1146   guint parts_sz = g_strv_length (parts);
    1147 
    1148   std::string location_str;
    1149   for (int i=0; i < parts_sz - 1; i++)
    1150   {
    1151       location_str += parts[i];
    1152       location_str += "/";
    1153   }
    1154 
    1155   documentbase_copy = g_strdup (location_str.c_str());
     1208  std::string href_str = IcedTeaPluginUtilities::NPVariantAsString(href);
     1209  documentbase_copy = g_strdup (href_str.c_str());
    11561210
    11571211  // Release references.
     
    12581312}
    12591313
     1314static
     1315void consume_plugin_message(gchar* message) {
     1316  // internal plugin related message
     1317  gchar** parts = g_strsplit (message, " ", 5);
     1318  if (g_str_has_prefix(parts[1], "PluginProxyInfo"))
     1319  {
     1320    gchar* proxy;
     1321    uint32_t len;
     1322
     1323    gchar* decoded_url = (gchar*) calloc(strlen(parts[4]) + 1, sizeof(gchar));
     1324    IcedTeaPluginUtilities::decodeURL(parts[4], &decoded_url);
     1325    PLUGIN_DEBUG("parts[0]=%s, parts[1]=%s, reference, parts[3]=%s, parts[4]=%s -- decoded_url=%s\n", parts[0], parts[1], parts[3], parts[4], decoded_url);
     1326
     1327    gchar* proxy_info;
     1328
     1329#if MOZILLA_VERSION_COLLAPSED < 1090100
     1330        proxy = (char*) malloc(sizeof(char)*2048);
     1331#endif
     1332
     1333    proxy_info = g_strconcat ("plugin PluginProxyInfo reference ", parts[3], " ", NULL);
     1334    if (get_proxy_info(decoded_url, &proxy, &len) == NPERR_NO_ERROR)
     1335      {
     1336        proxy_info = g_strconcat (proxy_info, proxy, NULL);
     1337      }
     1338
     1339    PLUGIN_DEBUG("Proxy info: %s\n", proxy_info);
     1340    plugin_send_message_to_appletviewer(proxy_info);
     1341
     1342    free(decoded_url);
     1343    decoded_url = NULL;
     1344    g_free(proxy_info);
     1345    proxy_info = NULL;
     1346
     1347#if MOZILLA_VERSION_COLLAPSED < 1090100
     1348        g_free(proxy);
     1349        proxy = NULL;
     1350#endif
     1351
     1352  } else if (g_str_has_prefix(parts[1], "PluginCookieInfo"))
     1353  {
     1354    gchar* decoded_url = (gchar*) calloc(strlen(parts[4])+1, sizeof(gchar));
     1355    IcedTeaPluginUtilities::decodeURL(parts[4], &decoded_url);
     1356
     1357    gchar* cookie_info = g_strconcat ("plugin PluginCookieInfo reference ", parts[3], " ", NULL);
     1358    gchar* cookie_string;
     1359    uint32_t len;
     1360    if (get_cookie_info(decoded_url, &cookie_string, &len) == NPERR_NO_ERROR)
     1361    {
     1362        cookie_info = g_strconcat (cookie_info, cookie_string, NULL);
     1363    }
     1364
     1365    PLUGIN_DEBUG("Cookie info: %s\n", cookie_info);
     1366    plugin_send_message_to_appletviewer(cookie_info);
     1367
     1368    free(decoded_url);
     1369    decoded_url = NULL;
     1370    g_free(cookie_info);
     1371    cookie_info = NULL;
     1372  } else if (g_str_has_prefix(parts[1], "PluginSetCookie"))
     1373  {
     1374    // Message structure: plugin PluginSetCookie reference -1 <url> <cookie>
     1375    gchar** cookie_parts = g_strsplit (message, " ", 6);
     1376
     1377    if (g_strv_length(cookie_parts) < 6)
     1378    {
     1379       g_strfreev (parts);
     1380       g_strfreev (cookie_parts);
     1381       return; // Defensive, message _should_ be properly formatted
     1382    }
     1383
     1384    gchar* decoded_url = (gchar*) calloc(strlen(cookie_parts[4])+1, sizeof(gchar));
     1385    IcedTeaPluginUtilities::decodeURL(cookie_parts[4], &decoded_url);
     1386
     1387    gchar* cookie_string = cookie_parts[5];
     1388    uint32_t len = strlen(cookie_string);
     1389    if (set_cookie_info(decoded_url, cookie_string, len) == NPERR_NO_ERROR)
     1390    {
     1391          PLUGIN_DEBUG("Setting cookie for URL %s to %s\n", decoded_url, cookie_string);
     1392    } else
     1393    {
     1394          PLUGIN_DEBUG("Not able to set cookie for URL %s to %s\n", decoded_url, cookie_string);
     1395    }
     1396
     1397    free(decoded_url);
     1398    decoded_url = NULL;
     1399    g_strfreev (cookie_parts);
     1400    cookie_parts = NULL;
     1401  }
     1402
     1403  g_strfreev (parts);
     1404  parts = NULL;
     1405}
     1406
    12601407void consume_message(gchar* message) {
    12611408
     
    12871434
    12881435          // clear the "instance X status" parts
    1289           sprintf(parts[0], "");
    1290           sprintf(parts[1], "");
    1291           sprintf(parts[2], "");
     1436          strcpy(parts[0], "");
     1437          strcpy(parts[1], "");
     1438          strcpy(parts[2], "");
    12921439
    12931440          // join the rest
     
    13201467  else if (g_str_has_prefix (message, "plugin "))
    13211468    {
    1322       // internal plugin related message
    1323       gchar** parts = g_strsplit (message, " ", 5);
    1324       if (g_str_has_prefix(parts[1], "PluginProxyInfo"))
    1325       {
    1326         gchar* proxy;
    1327         uint32_t len;
    1328 
    1329         gchar* decoded_url = (gchar*) calloc(strlen(parts[4]) + 1, sizeof(gchar));
    1330         IcedTeaPluginUtilities::decodeURL(parts[4], &decoded_url);
    1331         PLUGIN_DEBUG("parts[0]=%s, parts[1]=%s, reference, parts[3]=%s, parts[4]=%s -- decoded_url=%s\n", parts[0], parts[1], parts[3], parts[4], decoded_url);
    1332 
    1333         gchar* proxy_info;
    1334 
    1335 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1336         proxy = (char*) malloc(sizeof(char)*2048);
    1337 #endif
    1338 
    1339         proxy_info = g_strconcat ("plugin PluginProxyInfo reference ", parts[3], " ", NULL);
    1340         if (get_proxy_info(decoded_url, &proxy, &len) == NPERR_NO_ERROR)
    1341           {
    1342             proxy_info = g_strconcat (proxy_info, proxy, NULL);
    1343           }
    1344 
    1345         PLUGIN_DEBUG("Proxy info: %s\n", proxy_info);
    1346         plugin_send_message_to_appletviewer(proxy_info);
    1347 
    1348         g_free(decoded_url);
    1349         decoded_url = NULL;
    1350         g_free(proxy_info);
    1351         proxy_info = NULL;
    1352 
    1353 #if MOZILLA_VERSION_COLLAPSED < 1090100
    1354         g_free(proxy);
    1355         proxy = NULL;
    1356 #endif
    1357 
    1358       } else if (g_str_has_prefix(parts[1], "PluginCookieInfo"))
    1359       {
    1360         gchar* decoded_url = (gchar*) calloc(strlen(parts[4])+1, sizeof(gchar));
    1361         IcedTeaPluginUtilities::decodeURL(parts[4], &decoded_url);
    1362 
    1363         gchar* cookie_info = g_strconcat ("plugin PluginCookieInfo reference ", parts[3], " ", NULL);
    1364         gchar* cookie_string;
    1365         uint32_t len;
    1366         if (get_cookie_info(decoded_url, &cookie_string, &len) == NPERR_NO_ERROR)
    1367         {
    1368             cookie_info = g_strconcat (cookie_info, cookie_string, NULL);
    1369         }
    1370 
    1371         PLUGIN_DEBUG("Cookie info: %s\n", cookie_info);
    1372         plugin_send_message_to_appletviewer(cookie_info);
    1373 
    1374         g_free(decoded_url);
    1375         decoded_url = NULL;
    1376         g_free(cookie_info);
    1377         cookie_info = NULL;
    1378       }
     1469        consume_plugin_message(message);
    13791470    }
    13801471  else
     
    13821473        g_print ("  Unable to handle message: %s\n", message);
    13831474    }
     1475
    13841476}
    13851477
     
    14011493get_proxy_info(const char* siteAddr, char** proxy, uint32_t* len)
    14021494{
     1495  // Only attempt to perform this operation if there is a valid plugin instance
     1496  if (g_hash_table_size(instance_to_id_map) <= 0)
     1497  {
     1498          return NPERR_GENERIC_ERROR;
     1499  }
    14031500#if MOZILLA_VERSION_COLLAPSED < 1090100
    14041501  nsresult rv;
     
    14751572
    14761573      // As in get_cookie_info, we use the first active instance
    1477       GHashTableIter iter;
    1478       gpointer id, instance;
    1479 
    1480       g_hash_table_iter_init (&iter, instance_to_id_map);
    1481       g_hash_table_iter_next (&iter, &instance, &id);
    1482 
     1574      gpointer instance=getFirstInTableInstance(instance_to_id_map);
    14831575      browser_functions.getvalueforurl((NPP) instance, NPNURLVProxy, siteAddr, proxy, len);
    14841576  } else
     
    20862178
    20872179  // cleanup_appletviewer_mutex:
    2088   g_free (tofree->appletviewer_mutex);
     2180  g_mutex_free (tofree->appletviewer_mutex);
    20892181  tofree->appletviewer_mutex = NULL;
    20902182
     
    21092201}
    21102202
    2111 static NPError
    2112 plugin_get_entry_points (NPPluginFuncs* pluginTable)
    2113 {
    2114   // Ensure that the plugin function table we've received is large
    2115   // enough to store the number of functions that we may provide.
    2116   if (pluginTable->size < sizeof (NPPluginFuncs))
    2117     {
    2118       PLUGIN_ERROR ("Invalid plugin function table.");
    2119 
    2120       return NPERR_INVALID_FUNCTABLE_ERROR;
    2121     }
    2122 
    2123   // Return to the browser the plugin functions that we implement.
     2203static bool
     2204initialize_browser_functions(const NPNetscapeFuncs* browserTable)
     2205{
     2206#if MOZILLA_VERSION_COLLAPSED < 1090100
     2207#define NPNETSCAPEFUNCS_LAST_FIELD_USED (browserTable->pluginthreadasynccall)
     2208#else
     2209#define NPNETSCAPEFUNCS_LAST_FIELD_USED (browserTable->setvalueforurl)
     2210#endif
     2211
     2212  //Determine the size in bytes, as a difference of the address past the last used field
     2213  //And the browser table address
     2214  size_t usedSize = (char*)(1 + &NPNETSCAPEFUNCS_LAST_FIELD_USED) - (char*)browserTable;
     2215
     2216  // compare the reported size versus the size we required
     2217  if (browserTable->size < usedSize)
     2218  {
     2219    return false;
     2220  }
     2221
     2222  //Ensure any unused fields are NULL
     2223  memset(&browser_functions, 0, sizeof(NPNetscapeFuncs));
     2224
     2225  //browserTable->size can be larger than sizeof(NPNetscapeFuncs) (PR1106)
     2226  size_t copySize = browserTable->size < sizeof(NPNetscapeFuncs) ?
     2227                    browserTable->size : sizeof(NPNetscapeFuncs);
     2228
     2229  //Copy fields according to given size
     2230  memcpy(&browser_functions, browserTable, copySize);
     2231
     2232  return true;
     2233}
     2234
     2235/* Set the plugin table to the correct contents, taking care not to write past
     2236 * the provided object space */
     2237static bool
     2238initialize_plugin_table(NPPluginFuncs* pluginTable)
     2239{
     2240#define NPPLUGINFUNCS_LAST_FIELD_USED (pluginTable->getvalue)
     2241
     2242  //Determine the size in bytes, as a difference of the address past the last used field
     2243  //And the browser table address
     2244  size_t usedSize = (char*)(1 + &NPPLUGINFUNCS_LAST_FIELD_USED) - (char*)pluginTable;
     2245
     2246  // compare the reported size versus the size we required
     2247  if (pluginTable->size < usedSize)
     2248    return false;
     2249
    21242250  pluginTable->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
    21252251  pluginTable->size = sizeof (NPPluginFuncs);
     
    21512277#endif
    21522278
    2153   return NPERR_NO_ERROR;
     2279  return true;
    21542280}
    21552281
     
    22002326    }
    22012327
    2202   // Ensure that the browser function table is large enough to store
    2203   // the number of browser functions that we may use.
    2204   if (browserTable->size < sizeof (NPNetscapeFuncs))
    2205     {
    2206       fprintf (stderr, "ERROR: Invalid browser function table. Some functionality may be restricted.\n");
    2207     }
    2208 
    2209   // Store in a local table the browser functions that we may use.
    2210   browser_functions.size                    = browserTable->size;
    2211   browser_functions.version                 = browserTable->version;
    2212   browser_functions.geturlnotify            = browserTable->geturlnotify;
    2213   browser_functions.geturl                  = browserTable->geturl;
    2214   browser_functions.posturlnotify           = browserTable->posturlnotify;
    2215   browser_functions.posturl                 = browserTable->posturl;
    2216   browser_functions.requestread             = browserTable->requestread;
    2217   browser_functions.newstream               = browserTable->newstream;
    2218   browser_functions.write                   = browserTable->write;
    2219   browser_functions.destroystream           = browserTable->destroystream;
    2220   browser_functions.status                  = browserTable->status;
    2221   browser_functions.uagent                  = browserTable->uagent;
    2222   browser_functions.memalloc                = browserTable->memalloc;
    2223   browser_functions.memfree                 = browserTable->memfree;
    2224   browser_functions.memflush                = browserTable->memflush;
    2225   browser_functions.reloadplugins           = browserTable->reloadplugins;
    2226   browser_functions.getJavaEnv              = browserTable->getJavaEnv;
    2227   browser_functions.getJavaPeer             = browserTable->getJavaPeer;
    2228   browser_functions.getvalue                = browserTable->getvalue;
    2229   browser_functions.setvalue                = browserTable->setvalue;
    2230   browser_functions.invalidaterect          = browserTable->invalidaterect;
    2231   browser_functions.invalidateregion        = browserTable->invalidateregion;
    2232   browser_functions.forceredraw             = browserTable->forceredraw;
    2233   browser_functions.getstringidentifier     = browserTable->getstringidentifier;
    2234   browser_functions.getstringidentifiers    = browserTable->getstringidentifiers;
    2235   browser_functions.getintidentifier        = browserTable->getintidentifier;
    2236   browser_functions.identifierisstring      = browserTable->identifierisstring;
    2237   browser_functions.utf8fromidentifier      = browserTable->utf8fromidentifier;
    2238   browser_functions.intfromidentifier       = browserTable->intfromidentifier;
    2239   browser_functions.createobject            = browserTable->createobject;
    2240   browser_functions.retainobject            = browserTable->retainobject;
    2241   browser_functions.releaseobject           = browserTable->releaseobject;
    2242   browser_functions.invoke                  = browserTable->invoke;
    2243   browser_functions.invokeDefault           = browserTable->invokeDefault;
    2244   browser_functions.evaluate                = browserTable->evaluate;
    2245   browser_functions.getproperty             = browserTable->getproperty;
    2246   browser_functions.setproperty             = browserTable->setproperty;
    2247   browser_functions.removeproperty          = browserTable->removeproperty;
    2248   browser_functions.hasproperty             = browserTable->hasproperty;
    2249   browser_functions.hasmethod               = browserTable->hasmethod;
    2250   browser_functions.releasevariantvalue     = browserTable->releasevariantvalue;
    2251   browser_functions.setexception            = browserTable->setexception;
    2252   browser_functions.pluginthreadasynccall   = browserTable->pluginthreadasynccall;
    2253 #if MOZILLA_VERSION_COLLAPSED >= 1090100
    2254   browser_functions.getvalueforurl          = browserTable->getvalueforurl;
    2255   browser_functions.setvalueforurl          = browserTable->setvalueforurl;
    2256 #endif
    2257 
    2258   NPError np_error = NPERR_NO_ERROR;
     2328  // Copy into a global table (browser_functions) the browser functions that we may use.
     2329  // If the browser functions needed change, update NPNETSCAPEFUNCS_LAST_FIELD_USED
     2330  // within this function
     2331  bool browser_functions_supported = initialize_browser_functions(browserTable);
     2332
     2333  // Check if everything we rely on is supported
     2334  if ( !browser_functions_supported )
     2335  {
     2336        PLUGIN_ERROR ("Invalid browser function table.");
     2337
     2338        return NPERR_INVALID_FUNCTABLE_ERROR;
     2339  }
     2340
    22592341#if !defined(_WIN32) && !defined (__OS2__)
    2260   np_error = plugin_get_entry_points (pluginTable);
    2261   if (np_error != NPERR_NO_ERROR)
    2262     return np_error;
     2342  // Return to the browser the plugin functions that we implement.
     2343  // If the plugin functions needed change, update NPPLUGINFUNCS_LAST_FIELD_USED
     2344  // within this function
     2345  bool plugin_functions_supported = initialize_plugin_table(pluginTable);
     2346
     2347  // Check if everything we rely on is supported
     2348  if ( !plugin_functions_supported )
     2349  {
     2350    PLUGIN_ERROR ("Invalid plugin function table.");
     2351
     2352    return NPERR_INVALID_FUNCTABLE_ERROR;
     2353  }
    22632354#endif
    22642355
     
    22872378      return NPERR_OUT_OF_MEMORY_ERROR;
    22882379    }
     2380  NPError np_error = NPERR_NO_ERROR;
     2381  gchar* filename = NULL;
    22892382
    22902383  // If P_tmpdir does not exist, try /tmp directly
     
    22932386                    (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
    22942387    {
     2388      int file_error = 0;
     2389
    22952390      data_directory = g_strconcat ("/tmp", NULL);
    22962391        if (!data_directory)
     
    24532548  }
    24542549
    2455   return plugin_get_entry_points (pluginTable);
     2550  // Return to the browser the plugin functions that we implement.
     2551  // If the plugin functions needed change, update NPPLUGINFUNCS_LAST_FIELD_USED
     2552  // within this function
     2553  bool plugin_functions_supported = initialize_plugin_table(pluginTable);
     2554
     2555  // Check if everything we rely on is supported
     2556  if ( !plugin_functions_supported )
     2557  {
     2558    PLUGIN_ERROR ("Invalid plugin function table.");
     2559
     2560    return NPERR_INVALID_FUNCTABLE_ERROR;
     2561  }
     2562
     2563  return NPERR_NO_ERROR;
    24562564}
    24572565#endif
     
    24592567// Returns a string describing the MIME type that this plugin
    24602568// handles.
    2461 const char*
     2569#ifdef LEGACY_XULRUNNERAPI
     2570  char*
     2571#else
     2572  const char*
     2573#endif
    24622574OSCALL NP_GetMIMEDescription ()
    24632575{
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc

    r369 r418  
    124124            this->sendWindow(message_parts);
    125125            return true;
     126        } else if (!command->find("Finalize"))
     127        {
     128            // Object can be finalized from the main thread only. And this
     129                // call returns immediately, so we do it in the same thread.
     130            this->finalize(message_parts);
     131            return true;
    126132        } else if (!command->find("GetMember") ||
    127133                   !command->find("SetMember") ||
     
    131137                   !command->find("SetSlot") ||
    132138                   !command->find("Eval") ||
    133                    !command->find("Finalize") ||
    134139                   !command->find("LoadURL"))
    135140        {
     
    242247    IcedTeaPluginUtilities::callAndWaitForResult(instance, &_eval, &thread_data);
    243248
    244     NPVariant* result_variant = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(thread_data.result);
    245     std::string result_variant_jniid = std::string();
    246     createJavaObjectFromVariant(instance, *result_variant, &result_variant_jniid);
    247 
    248249    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &response);
    249250    response += " JavaScriptEval ";
    250     response += result_variant_jniid;
     251    response += thread_data.result;
    251252
    252253    plugin_to_java_bus->post(response.c_str());
     
    275276    NPVariant* result_variant;
    276277    std::string result_variant_jniid = std::string();
    277     NPVariant* args_array;
     278    NPVariant* args_array = NULL;
    278279    AsyncCallThreadData thread_data = AsyncCallThreadData();
    279280
     
    331332    IcedTeaPluginUtilities::callAndWaitForResult(instance, &_call, &thread_data);
    332333
    333     result_variant = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(thread_data.result);
    334 
    335     if (result_variant)
    336     {
    337         createJavaObjectFromVariant(instance, *result_variant, &result_variant_jniid);
    338     } else
    339     {
    340         result_variant_jniid = "0";
    341     }
    342 
    343334    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &response);
    344335    response += " JavaScriptCall ";
    345     response += result_variant_jniid;
     336    response += thread_data.result;
    346337
    347338    plugin_to_java_bus->post(response.c_str());
     
    410401    NPP instance;
    411402    NPVariant* member;
    412     NPIdentifier property_identifier;
     403    std::string property_id = std::string();
     404    bool int_identifier;
    413405
    414406    JavaRequestProcessor java_request = JavaRequestProcessor();
     
    440432    if (*(message_parts->at(4)) == "SetSlot")
    441433    {
    442         property_identifier = browser_functions.getintidentifier(atoi(message_parts->at(6)->c_str()));
     434        property_id.append(*(message_parts->at(6)));
     435        int_identifier = true;
    443436    } else
    444437    {
     
    452445        }
    453446
    454         property_identifier = browser_functions.getstringidentifier(java_result->return_string->c_str());
     447        property_id.append(*(java_result->return_string));
     448        int_identifier = false;
    455449    }
    456450
     
    462456    thread_data.parameters.push_back(instance);
    463457    thread_data.parameters.push_back(NPVARIANT_TO_OBJECT(*member));
    464     thread_data.parameters.push_back(&property_identifier);
     458    thread_data.parameters.push_back(&property_id);
    465459    thread_data.parameters.push_back(&value);
     460    thread_data.parameters.push_back(&int_identifier);
    466461
    467462    IcedTeaPluginUtilities::callAndWaitForResult(instance, &_setMember, &thread_data);
     
    478473 * can only be requested from the main thread in Mozilla, this function
    479474 * does whatever it can seperately, and then makes an internal request that
    480  * causes _sendMember to do the rest of the work.
     475 * causes _getMember to do the rest of the work.
    481476 *
    482477 * @param message_parts The request message
     
    491486    JavaResultData* java_result;
    492487    NPVariant* parent_ptr;
     488    NPVariant* member_ptr;
    493489
    494490    //int reference;
    495491    std::string member_id = std::string();
    496     std::string jsObjectClassID = std::string();
    497     std::string jsObjectConstructorID = std::string();
    498492    std::string response = std::string();
     493    std::string result_id = std::string();
    499494
    500495    NPIdentifier member_identifier;
     
    503498    int instance_id;
    504499    int reference;
     500    bool int_identifier;
    505501
    506502    // debug printout of parent thread data
     
    517513    if (*(message_parts->at(4)) == "GetSlot")
    518514    {
    519         member_identifier = browser_functions.getintidentifier(atoi(member_id.c_str()));
     515        int_identifier=true;
    520516    } else
    521517    {
     
    530526        }
    531527
    532         member_identifier = browser_functions.getstringidentifier(java_result->return_string->c_str());
     528        member_id.assign(*(java_result->return_string));
     529        int_identifier=false;
    533530    }
    534531
     
    546543    thread_data.parameters.push_back(instance);
    547544    thread_data.parameters.push_back(NPVARIANT_TO_OBJECT(*parent_ptr));
    548     thread_data.parameters.push_back(&member_identifier);
     545    thread_data.parameters.push_back(&member_id);
     546    thread_data.parameters.push_back(&int_identifier);
    549547
    550548    IcedTeaPluginUtilities::callAndWaitForResult(instance, &_getMember, &thread_data);
    551549
    552     PLUGIN_DEBUG("Member PTR after internal request: %s\n", thread_data.result.c_str());
    553 
    554     java_result = java_request.findClass(0, "netscape.javascript.JSObject");
    555 
    556     // the result we want is in result_string (assuming there was no error)
    557     if (java_result->error_occurred)
    558     {
    559         printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg->c_str());
    560         //goto cleanup;
    561     }
    562 
    563     jsObjectClassID.append(*(java_result->return_string));
    564 
    565     args = std::vector<std::string>();
    566     std::string longArg = "J";
    567     args.push_back(longArg);
    568 
    569     java_result = java_request.getMethodID(jsObjectClassID,
    570                                            browser_functions.getstringidentifier("<init>"),
    571                                            args);
    572 
    573     // the result we want is in result_string (assuming there was no error)
    574     if (java_result->error_occurred)
    575     {
    576         printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg->c_str());
    577         //goto cleanup;
    578     }
    579 
    580     jsObjectConstructorID.append(*(java_result->return_string));
    581 
    582     // We have the method id. Now create a new object.
    583 
    584     args.clear();
    585     args.push_back(thread_data.result);
    586     java_result = java_request.newObjectWithConstructor("",
    587                                          jsObjectClassID,
    588                                          jsObjectConstructorID,
    589                                          args);
    590 
    591     // the result we want is in result_string (assuming there was no error)
    592     if (java_result->error_occurred)
    593     {
    594         printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg->c_str());
    595         //goto cleanup;
    596     }
    597 
    598 
    599550    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &response);
    600     if (*(message_parts->at(2)) == "GetSlot")
    601     {
     551    if (*(message_parts->at(4)) == "GetSlot")
     552    {
     553        response.append(" JavaScriptGetSlot ");
     554    } else {
    602555        response.append(" JavaScriptGetMember ");
    603     } else {
    604         response.append(" JavaScriptGetSlot ");
    605     }
    606     response.append(java_result->return_string->c_str());
     556    }
     557    response.append(thread_data.result);
    607558    plugin_to_java_bus->post(response.c_str());
    608559}
     
    764715                processor->setMember(message_parts);
    765716                pthread_mutex_unlock(&syn_write_mutex);
    766             } else if (command == "Finalize")
    767             {
    768                 // write methods are synchronized
    769                 pthread_mutex_lock(&syn_write_mutex);
    770                 processor->finalize(message_parts);
    771                 pthread_mutex_unlock(&syn_write_mutex);
    772717            } else if (command == "LoadURL") // For instance X url <url> <target>
    773718            {
     
    821766    NPVariant value_variant = NPVariant();
    822767    NPObject* member;
    823     NPIdentifier* property;
     768    NPIdentifier property_identifier;
     769
    824770
    825771    std::vector<void*> parameters = ((AsyncCallThreadData*) data)->parameters;
    826772    instance = (NPP) parameters.at(0);
    827773    member = (NPObject*) parameters.at(1);
    828     property = (NPIdentifier*) parameters.at(2);
     774    std::string*  property_id = (std::string*) parameters.at(2);
    829775    value = (std::string*) parameters.at(3);
    830 
    831     PLUGIN_DEBUG("Setting %s on instance %p, object %p to value %s\n", browser_functions.utf8fromidentifier(*property), instance, member, value->c_str());
     776    bool* int_identifier = (bool*) parameters.at(4);
     777
     778    if(*int_identifier==true)
     779        property_identifier = browser_functions.getintidentifier(atoi(property_id->c_str()));
     780    else
     781        property_identifier = browser_functions.getstringidentifier(property_id->c_str());
     782
     783    PLUGIN_DEBUG("Setting %s on instance %p, object %p to value %s\n", browser_functions.utf8fromidentifier(property_identifier), instance, member, value->c_str());
    832784
    833785    IcedTeaPluginUtilities::javaResultToNPVariant(instance, value, &value_variant);
    834786
    835     ((AsyncCallThreadData*) data)->call_successful = browser_functions.setproperty(instance, member, *property, &value_variant);
     787    ((AsyncCallThreadData*) data)->call_successful = browser_functions.setproperty(instance, member, property_identifier, &value_variant);
    836788
    837789    ((AsyncCallThreadData*) data)->result_ready = true;
     
    850802    instance = (NPP) parameters.at(0);
    851803    parent_ptr = (NPObject*) parameters.at(1);
    852     NPIdentifier* member_identifier = (NPIdentifier*) parameters.at(2);
     804    std::string*  member_id = (std::string*) parameters.at(2);
     805    NPIdentifier member_identifier;
     806
     807    bool* int_identifier = (bool*) parameters.at(3);
     808
     809    if(*int_identifier==true)
     810        member_identifier = browser_functions.getintidentifier(atoi(member_id->c_str()));
     811    else
     812        member_identifier = browser_functions.getstringidentifier(member_id->c_str());
    853813
    854814    // Get the NPVariant corresponding to this member
    855     PLUGIN_DEBUG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier, browser_functions.utf8fromidentifier(*member_identifier));
    856 
    857     if (!browser_functions.hasproperty(instance, parent_ptr, *member_identifier))
    858     {
    859         printf("%s not found!\n", browser_functions.utf8fromidentifier(*member_identifier));
    860     }
    861     ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, *member_identifier, member_ptr);
     815    PLUGIN_DEBUG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier, browser_functions.utf8fromidentifier(member_identifier));
     816
     817    if (!browser_functions.hasproperty(instance, parent_ptr, member_identifier))
     818    {
     819        printf("%s not found!\n", browser_functions.utf8fromidentifier(member_identifier));
     820    }
     821    ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, member_identifier, member_ptr);
    862822
    863823    IcedTeaPluginUtilities::printNPVariant(*member_ptr);
     
    865825    if (((AsyncCallThreadData*) data)->call_successful)
    866826    {
    867         IcedTeaPluginUtilities::JSIDToString(member_ptr, &member_ptr_str);
     827        createJavaObjectFromVariant(instance, *member_ptr, &member_ptr_str);
    868828        ((AsyncCallThreadData*) data)->result.append(member_ptr_str);
     829
    869830    }
    870831    ((AsyncCallThreadData*) data)->result_ready = true;
     
    884845    NPIdentifier script_identifier;
    885846    NPString script = NPString();
    886     NPVariant* eval_result = new NPVariant();
    887     std::string eval_result_ptr_str = std::string();
     847    NPVariant* eval_variant = new NPVariant();
     848    std::string eval_variant_str = std::string();
    888849
    889850    PLUGIN_DEBUG("_eval called\n");
     
    899860    script.utf8length = script_str->size();
    900861
    901     PLUGIN_DEBUG("Evaluating: %s\n", script.utf8characters);
     862    PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str());
    902863#else
    903864    script.UTF8Characters = script_str->c_str();
    904865    script.UTF8Length = script_str->size();
    905866
    906     PLUGIN_DEBUG("Evaluating: %s\n", script.UTF8Characters);
     867    PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str());
    907868#endif
    908869
    909     ((AsyncCallThreadData*) data)->call_successful = browser_functions.evaluate(instance, window_ptr, &script, eval_result);
    910     IcedTeaPluginUtilities::printNPVariant(*eval_result);
     870    ((AsyncCallThreadData*) data)->call_successful = browser_functions.evaluate(instance, window_ptr, &script, eval_variant);
     871    IcedTeaPluginUtilities::printNPVariant(*eval_variant);
    911872
    912873    if (((AsyncCallThreadData*) data)->call_successful)
    913874    {
    914         IcedTeaPluginUtilities::JSIDToString(eval_result, &eval_result_ptr_str);
    915         ((AsyncCallThreadData*) data)->result.append(eval_result_ptr_str);
    916     }
     875        if (eval_variant)
     876        {
     877            createJavaObjectFromVariant(instance, *eval_variant, &eval_variant_str);
     878        } else
     879        {
     880            eval_variant_str = "0";
     881        }
     882    } else
     883    {
     884        eval_variant_str = "0";
     885    }
     886
     887    ((AsyncCallThreadData*) data)->result.append(eval_variant_str);
    917888    ((AsyncCallThreadData*) data)->result_ready = true;
    918889
     
    957928    if (((AsyncCallThreadData*) data)->call_successful)
    958929    {
    959         IcedTeaPluginUtilities::JSIDToString(call_result, &call_result_ptr_str);
    960         ((AsyncCallThreadData*) data)->result.append(call_result_ptr_str);
    961     }
    962 
     930
     931        if (call_result)
     932        {
     933            createJavaObjectFromVariant(instance, *call_result, &call_result_ptr_str);
     934        } else
     935        {
     936                call_result_ptr_str = "0";
     937        }
     938    } else
     939    {
     940        call_result_ptr_str = "0";
     941    }
     942
     943    ((AsyncCallThreadData*) data)->result.append(call_result_ptr_str);
    963944    ((AsyncCallThreadData*) data)->result_ready = true;
    964945
     
    10311012    ((AsyncCallThreadData*) data)->result_ready = true;
    10321013
    1033     g_free(decoded_url);
     1014    free(decoded_url);
    10341015    decoded_url = NULL;
    10351016
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginUtils.cc

    r375 r418  
    151151IcedTeaPluginUtilities::JSIDToString(void* id, std::string* result)
    152152{
    153 
    154         char* id_str = (char*) malloc(sizeof(char)*20); // max = long long = 8446744073709551615 == 19 chars
     153        char id_str[NUM_STR_BUFFER_SIZE];
    155154
    156155        if (sizeof(void*) == sizeof(long long))
    157156        {
    158                 sprintf(id_str, "%llu", id);
     157                snprintf(id_str, NUM_STR_BUFFER_SIZE, "%llu", id);
    159158        }
    160159        else
    161160        {
    162                 sprintf(id_str, "%lu", id); // else use long
     161                snprintf(id_str, NUM_STR_BUFFER_SIZE, "%lu", id); // else use long
    163162        }
    164163
     
    166165
    167166        PLUGIN_DEBUG("Converting pointer %p to %s\n", id, id_str);
    168         free(id_str);
    169167}
    170168
     
    262260IcedTeaPluginUtilities::itoa(int i, std::string* result)
    263261{
    264         // largest possible integer is 10 digits long
    265         char* int_str = (char*) malloc(sizeof(char)*11);
    266         sprintf(int_str, "%d", i);
     262        char int_str[NUM_STR_BUFFER_SIZE];
     263        snprintf(int_str, NUM_STR_BUFFER_SIZE, "%d", i);
    267264        result->append(int_str);
    268 
    269         free(int_str);
    270265}
    271266
     
    297292 * @param str The string to split
    298293 * @param The delimiters to split on
    299  * @return A string vector containing the aplit components
     294 * @return A string vector containing the split components
    300295 */
    301296
     
    307302        char* copy;
    308303
    309         // Tokening is done on a copy
     304        // Tokenization is done on a copy
    310305        copy = (char*) malloc (sizeof(char)*strlen(str) + 1);
    311306        strcpy(copy, str);
     
    318313            // Allocation on heap since caller has no way to knowing how much will
    319314            // be needed. Make sure caller cleans up!
    320                 std::string* s = new std::string();
    321                 s->append(tok_ptr);
    322                 v->push_back(s);
    323                 tok_ptr = strtok (NULL, " ");
     315            std::string* s = new std::string();
     316            s->append(tok_ptr);
     317            v->push_back(s);
     318            tok_ptr = strtok (NULL, delim);
    324319        }
     320        free(copy);
    325321
    326322        return v;
     
    376372        ostream << length;
    377373
    378         // UTF-8 characters are 4-bytes max + space + '\0'
    379         char* hex_value = (char*) malloc(sizeof(char)*10);
     374        char hex_value[NUM_STR_BUFFER_SIZE];
    380375
    381376        for (int i = 0; i < str->length(); i++)
    382377        {
    383                 sprintf(hex_value, " %hx", str->at(i));
     378                snprintf(hex_value, NUM_STR_BUFFER_SIZE," %hx", str->at(i));
    384379                ostream << hex_value;
    385380        }
     
    388383        *utf_str = ostream.str();
    389384
    390         free(hex_value);
    391385        PLUGIN_DEBUG("Converted %s to UTF-8 string %s\n", str->c_str(), utf_str->c_str());
    392386}
     
    673667    else if (NPVARIANT_IS_STRING(variant))
    674668    {
    675 #if MOZILLA_VERSION_COLLAPSED < 1090200
    676         PLUGIN_DEBUG("STRING: %s\n", NPVARIANT_TO_STRING(variant).utf8characters);
    677 #else
    678         PLUGIN_DEBUG("STRING: %s\n", NPVARIANT_TO_STRING(variant).UTF8Characters);
    679 #endif
     669        std::string str = IcedTeaPluginUtilities::NPVariantAsString(variant);
     670        PLUGIN_DEBUG("STRING: %s (length=%d)\n", str.c_str(), str.size());
    680671    }
    681672    else
     
    688679IcedTeaPluginUtilities::NPVariantToString(NPVariant variant, std::string* result)
    689680{
    690         char* str = (char*) malloc(sizeof(char)*32); // enough for everything except string
    691 
    692     if (NPVARIANT_IS_VOID(variant))
    693     {
    694         sprintf(str, "%p", variant);
    695     }
    696     else if (NPVARIANT_IS_NULL(variant))
    697     {
    698         sprintf(str, "NULL");
    699     }
    700     else if (NPVARIANT_IS_BOOLEAN(variant))
    701     {
    702         if (NPVARIANT_TO_BOOLEAN(variant))
    703                 sprintf(str, "true");
    704         else
    705                 sprintf(str, "false");
    706     }
    707     else if (NPVARIANT_IS_INT32(variant))
    708     {
    709         sprintf(str, "%d", NPVARIANT_TO_INT32(variant));
    710     }
    711     else if (NPVARIANT_IS_DOUBLE(variant))
    712     {
    713         sprintf(str, "%f", NPVARIANT_TO_DOUBLE(variant));;
    714     }
    715     else if (NPVARIANT_IS_STRING(variant))
    716     {
    717         free(str);
    718 #if MOZILLA_VERSION_COLLAPSED < 1090200
    719         str = (char*) malloc(sizeof(char)*NPVARIANT_TO_STRING(variant).utf8length);
    720         sprintf(str, "%s", NPVARIANT_TO_STRING(variant).utf8characters);
    721 #else
    722         str = (char*) malloc(sizeof(char)*NPVARIANT_TO_STRING(variant).UTF8Length);
    723         sprintf(str, "%s", NPVARIANT_TO_STRING(variant).UTF8Characters);
    724 #endif
    725     }
     681  char conv_str[NUM_STR_BUFFER_SIZE]; // conversion buffer
     682  bool was_string_already = false;
     683
     684  if (NPVARIANT_IS_STRING(variant))
     685  {
     686    result->append(IcedTeaPluginUtilities::NPVariantAsString(variant));
     687    was_string_already = true;
     688  }
     689  else if (NPVARIANT_IS_VOID(variant))
     690  {
     691    snprintf(conv_str, NUM_STR_BUFFER_SIZE, "%p", variant);
     692  }
     693  else if (NPVARIANT_IS_NULL(variant))
     694  {
     695    snprintf(conv_str, NUM_STR_BUFFER_SIZE, "NULL");
     696  }
     697  else if (NPVARIANT_IS_BOOLEAN(variant))
     698  {
     699    if (NPVARIANT_TO_BOOLEAN(variant))
     700      snprintf(conv_str, NUM_STR_BUFFER_SIZE, "true");
    726701    else
    727     {
    728         sprintf(str, "[Object %p]", variant);
    729     }
    730 
    731     result->append(str);
    732     free(str);
     702      snprintf(conv_str, NUM_STR_BUFFER_SIZE, "false");
     703  }
     704  else if (NPVARIANT_IS_INT32(variant))
     705  {
     706    snprintf(conv_str, NUM_STR_BUFFER_SIZE, "%d", NPVARIANT_TO_INT32(variant));
     707  }
     708  else if (NPVARIANT_IS_DOUBLE(variant))
     709  {
     710    snprintf(conv_str, NUM_STR_BUFFER_SIZE, "%f", NPVARIANT_TO_DOUBLE(variant));
     711  }
     712  else
     713  {
     714    snprintf(conv_str, NUM_STR_BUFFER_SIZE, "[Object %p]", variant);
     715  }
     716
     717  if (!was_string_already){
     718    result->append(conv_str);
     719  }
    733720}
    734721
     
    869856    IcedTeaPluginUtilities::printNPVariant(constructor_str);
    870857
    871     std::string constructor_name = std::string();
    872 
    873 #if MOZILLA_VERSION_COLLAPSED < 1090200
    874     constructor_name.append(NPVARIANT_TO_STRING(constructor_str).utf8characters);
    875 #else
    876     constructor_name.append(NPVARIANT_TO_STRING(constructor_str).UTF8Characters);
    877 #endif
     858    std::string constructor_name = IcedTeaPluginUtilities::NPVariantAsString(constructor_str);
    878859
    879860    PLUGIN_DEBUG("Constructor for NPObject is %s\n", constructor_name.c_str());
     
    918899}
    919900
     901/* Copies a variant data type into a C++ string */
     902std::string
     903IcedTeaPluginUtilities::NPVariantAsString(NPVariant variant)
     904{
     905#if MOZILLA_VERSION_COLLAPSED < 1090200
     906  return std::string(
     907    NPVARIANT_TO_STRING(variant).utf8characters,
     908    NPVARIANT_TO_STRING(variant).utf8length);
     909#else
     910  return std::string(
     911    NPVARIANT_TO_STRING(variant).UTF8Characters,
     912    NPVARIANT_TO_STRING(variant).UTF8Length);
     913#endif
     914}
    920915
    921916/**
     
    10811076                PLUGIN_DEBUG("Error: Unable to initialize message queue mutex: %d\n", ret);
    10821077
    1083         PLUGIN_DEBUG("Mutexs %p and %p initialized\n", &subscriber_mutex, &msg_queue_mutex);
     1078        PLUGIN_DEBUG("Mutexes %p and %p initialized\n", &subscriber_mutex, &msg_queue_mutex);
    10841079}
    10851080
     
    11451140MessageBus::post(const char* message)
    11461141{
    1147         char* msg = (char*) malloc(sizeof(char)*strlen(message) + 1);
    11481142        bool message_consumed = false;
    1149 
    1150         // consumer frees this memory
    1151         strcpy(msg, message);
    11521143
    11531144        PLUGIN_DEBUG("Trying to lock %p...\n", &msg_queue_mutex);
    11541145        pthread_mutex_lock(&subscriber_mutex);
    11551146
    1156     PLUGIN_DEBUG("Message %s received on bus. Notifying subscribers.\n", msg);
     1147    PLUGIN_DEBUG("Message %s received on bus. Notifying subscribers.\n", message);
    11571148
    11581149    std::list<BusSubscriber*>::const_iterator i;
    11591150    for( i = subscribers.begin(); i != subscribers.end() && !message_consumed; ++i ) {
    1160         PLUGIN_DEBUG("Notifying subscriber %p of %s\n", *i, msg);
    1161         message_consumed = ((BusSubscriber*) *i)->newMessageOnBus(msg);
     1151        PLUGIN_DEBUG("Notifying subscriber %p of %s\n", *i, message);
     1152        message_consumed = ((BusSubscriber*) *i)->newMessageOnBus(message);
    11621153    }
    11631154
     
    11651156
    11661157    if (!message_consumed)
    1167         PLUGIN_DEBUG("Warning: No consumer found for message %s\n", msg);
     1158        PLUGIN_DEBUG("Warning: No consumer found for message %s\n", message);
    11681159
    11691160    PLUGIN_DEBUG("%p unlocked...\n", &msg_queue_mutex);
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginUtils.h

    r375 r418  
    9797     (*c >= 'A' && *c <= 'F'))
    9898
     99//long long max ~ 19 chars + terminator
     100//leave some room for converting strings like "<var> = %d"
     101const size_t NUM_STR_BUFFER_SIZE = 32;
     102
    99103/*
    100104 * This struct holds data specific to a Java operation requested by the plugin
     
    206210        static void itoa(int i, std::string* result);
    207211
     212        /* Copies a variant data type into a C++ string */
     213        static std::string NPVariantAsString(NPVariant variant);
     214
    208215        /* Frees the given vector and the strings that its contents point to */
    209216        static void freeStringPtrVector(std::vector<std::string*>* v);
  • trunk/icedtea-web/plugin/icedteanp/java/netscape/javascript/JSObject.java

    r348 r418  
    131131            boolean mayProceed = false;
    132132
    133             for (int i = 0; i < stack.length; i++) {
    134                 if (stack[i].getClassName().equals("netscape.javascript.JSObject") &&
    135                         stack[i].getMethodName().equals("getWindow")) {
     133            for (StackTraceElement element : stack) {
     134                if (element.getClassName().equals("netscape.javascript.JSObject") &&
     135                        element.getMethodName().equals("getWindow")) {
    136136                    mayProceed = true;
    137137                }
     
    210210
    211211        PluginDebug.debug("JSObject.call ", methodName);
    212         for (int i = 0; i < args.length; i++)
    213             PluginDebug.debug(" ", args[i]);
     212        for (Object arg : args) {
     213            PluginDebug.debug(" ", arg);
     214        }
    214215        PluginDebug.debug("");
    215216        return PluginAppletViewer.call(internal, methodName, args);
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java

    r348 r418  
    1 /* VoidPluginCallRequest -- represent Java-to-JavaScript requests
     1/* AppletSecurityContextManager -- handles messages in an appropriate security
     2 context
     3
    24   Copyright (C) 2008  Red Hat
    35
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java

    r348 r418  
    5151        // FIXME: Is it even possible to distinguish between null and void
    5252        // here?
    53         if (args[3] != "null" && args[3] != "void")
     53        if (!"null".equals(args[3]) && !"void".equals(args[3]))
    5454            object = AppletSecurityContextManager.getSecurityContext(0).getObject(Integer.parseInt(args[3]));
    5555        setDone(true);
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/JavaConsole.java

    r348 r418  
    6666import net.sourceforge.jnlp.config.DeploymentConfiguration;
    6767import net.sourceforge.jnlp.runtime.JNLPRuntime;
     68import net.sourceforge.jnlp.util.ImageResources;
    6869
    6970/**
     
    9394
    9495        consoleWindow = new JFrame("Java Console");
     96        consoleWindow.setIconImages(ImageResources.INSTANCE.getApplicationImages());
    9597
    9698        JPanel contentPanel = new JPanel();
     
    307309        boolean toShowConsole = false;
    308310
    309         for (int i = 0; i < args.length; i++) {
    310             if (args[i] == "--show-console") {
     311        for (String arg : args) {
     312            if ("--show-console".equals(arg)) {
    311313                toShowConsole = true;
    312314            }
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java

    r348 r418  
    244244        if (System.getSecurityManager() == null) {
    245245            JNLPRuntime.initialize(/* isApplication */false);
    246             JNLPRuntime.setDefaultLaunchHandler(new DefaultLaunchHandler());
     246            JNLPRuntime.setDefaultLaunchHandler(new DefaultLaunchHandler(System.err));
    247247        }
    248248
     
    12961296        Permissions grantedPermissions = new Permissions();
    12971297
    1298         for (int i = 0; i < nsPrivilegeList.length; i++) {
    1299             String privilege = nsPrivilegeList[i];
    1300 
     1298        for (String privilege : nsPrivilegeList) {
    13011299            if (privilege.equals("UniversalBrowserRead")) {
    13021300                BrowserReadPermission bp = new BrowserReadPermission();
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java

    r362 r418  
    123123
    124124    public AppletPanel createPanel(PluginStreamHandler streamhandler,
    125                                     int identifier,
    126                                     long handle, int x, int y,
    127                                     final URL doc,
    128                                     final Hashtable<String, String> atts) {
     125                                   final int identifier,
     126                                   final long handle, int x, int y,
     127                                   final URL doc,
     128                                   final Hashtable<String, String> atts) {
    129129        final NetxPanel panel = AccessController.doPrivileged(new PrivilegedAction<NetxPanel>() {
    130130            public NetxPanel run() {
     
    136136        });
    137137
    138         // create the frame.
    139         PluginAppletViewer.framePanel(identifier, handle, panel);
    140 
    141         panel.init();
    142 
    143         // Start the applet
    144         initEventQueue(panel);
     138        // Framing the panel needs to happen in a thread whose thread group
     139        // is the same as the threadgroup of the applet thread. If this
     140        // isn't the case, the awt eventqueue thread's context classloader
     141        // won't be set to a JNLPClassLoader, and when an applet class needs
     142        // to be loaded from the awt eventqueue, it won't be found.
     143        Thread panelInit = new Thread(panel.getThreadGroup(), new Runnable() {
     144            @Override public void run() {
     145                panel.createNewAppContext();
     146                // create the frame.
     147                PluginAppletViewer.framePanel(identifier, handle, panel);
     148                panel.init();
     149                // Start the applet
     150                initEventQueue(panel);
     151            }
     152        }, "NetXPanel initializer");
     153
     154        panelInit.start();
     155        while(panelInit.isAlive()) {
     156            try {
     157                panelInit.join();
     158            } catch (InterruptedException e) {
     159            }
     160        }
    145161
    146162        // Wait for the panel to initialize
     
    221237            String[] events = eventList.split(",");
    222238
    223             for (int i = 0; i < events.length; i++) {
    224                 PluginDebug.debug("Adding event to queue: ", events[i]);
    225                 if (events[i].equals("dispose"))
     239            for (String event : events) {
     240                PluginDebug.debug("Adding event to queue: ", event);
     241                if ("dispose".equals(event))
    226242                    panel.sendEvent(AppletPanel.APPLET_DISPOSE);
    227                 else if (events[i].equals("load"))
     243                else if ("load".equals(event))
    228244                    panel.sendEvent(AppletPanel.APPLET_LOAD);
    229                 else if (events[i].equals("init"))
     245                else if ("init".equals(event))
    230246                    panel.sendEvent(AppletPanel.APPLET_INIT);
    231                 else if (events[i].equals("start"))
     247                else if ("start".equals(event))
    232248                    panel.sendEvent(AppletPanel.APPLET_START);
    233                 else if (events[i].equals("stop"))
     249                else if ("stop".equals(event))
    234250                    panel.sendEvent(AppletPanel.APPLET_STOP);
    235                 else if (events[i].equals("destroy"))
     251                else if ("destroy".equals(event))
    236252                    panel.sendEvent(AppletPanel.APPLET_DESTROY);
    237                 else if (events[i].equals("quit"))
     253                else if ("quit".equals(event))
    238254                    panel.sendEvent(AppletPanel.APPLET_QUIT);
    239                 else if (events[i].equals("error"))
     255                else if ("error".equals(event))
    240256                    panel.sendEvent(AppletPanel.APPLET_ERROR);
    241257                else
    242258                    // non-fatal error if we get an unrecognized event
    243                     PluginDebug.debug("Unrecognized event name: ", events[i]);
     259                    PluginDebug.debug("Unrecognized event name: ", event);
    244260            }
    245261
     
    16091625                appletShutdown(p);
    16101626                appletPanels.removeElement(p);
     1627               
     1628                // Mark classloader unusable
     1629                ((JNLPClassLoader) cl).decrementLoaderUseCount();
    16111630
    16121631                try {
     
    19041923                        String att = t.get("name");
    19051924
    1906                         if (atts.containsKey(att))
    1907                             continue;
    1908 
    19091925                        if (att == null) {
    19101926                            statusMsgStream.println(requiresNameWarning);
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginCallRequest.java

    r348 r418  
    3838package sun.applet;
    3939
    40 // FIXME: for each type of request extend a new (anonymous?)
    41 // PluginCallRequest.
    4240public abstract class PluginCallRequest {
    4341    private String message;
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java

    r348 r418  
    1 /* VoidPluginCallRequest -- represent Java-to-JavaScript requests
     1/* PluginCallRequestFactory -- contains factory methods for dispatching
     2 an appropriate PluginCallRequest.
    23   Copyright (C) 2008  Red Hat
    34
     
    4243    public PluginCallRequest getPluginCallRequest(String id, String message, Long reference) {
    4344
    44         if (id == "member") {
     45        if ("member".equals(id)) {
    4546            return new GetMemberPluginCallRequest(message, reference);
    46         } else if (id == "void") {
     47        } else if ("void".equals(id)) {
    4748            return new VoidPluginCallRequest(message, reference);
    48         } else if (id == "window") {
     49        } else if ("window".equals(id)) {
    4950            return new GetWindowPluginCallRequest(message, reference);
    50         } else if (id == "proxyinfo") {
     51        } else if ("proxyinfo".equals(id)) {
    5152            return new PluginProxyInfoRequest(message, reference);
    52         } else if (id == "cookieinfo") {
     53        } else if ("cookieinfo".equals(id)) {
    5354            return new PluginCookieInfoRequest(message, reference);
    5455        } else {
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginCookieManager.java

    r348 r418  
    4646import java.util.Map;
    4747
     48import com.sun.jndi.toolkit.url.UrlUtil;
     49
    4850public class PluginCookieManager extends CookieManager {
     51    private PluginStreamHandler streamHandler;
     52
     53    public PluginCookieManager(PluginStreamHandler streamHandler) {
     54        this.streamHandler = streamHandler;
     55    }
     56
     57    @Override
    4958    public Map<String, List<String>> get(URI uri,
    5059            Map<String, List<String>> requestHeaders) throws IOException {
     
    8594        return false;
    8695    }
     96
     97    @Override
     98    public void put(URI uri,
     99            Map<String, List<String>> responseHeaders) throws IOException {
     100        super.put(uri, responseHeaders);
     101
     102        for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
     103            String type = headerEntry.getKey();
     104            if ("Set-Cookie".equalsIgnoreCase(type) || "Set-Cookie2".equalsIgnoreCase(type)) {
     105                List<String> cookies = headerEntry.getValue();
     106                for (String cookie : cookies) {
     107                    streamHandler.write("plugin PluginSetCookie reference -1 " + UrlUtil.encode(uri.toString(), "UTF-8") + " " + cookie);
     108                }
     109            }
     110
     111        }
     112    }
    87113}
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginException.java

    r348 r418  
    1 /* VoidPluginCallRequest -- represent Java-to-JavaScript requests
     1/* PluginException -- represents an exception in handling a plugin message
    22   Copyright (C) 2008  Red Hat
    33
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginMain.java

    r368 r418  
    115115            // Streams set. Start processing.
    116116            streamHandler.startProcessing();
     117
     118            setCookieHandler(streamHandler);
     119
    117120        } catch (Exception e) {
    118121            e.printStackTrace();
     
    185188        // override the proxy selector set by JNLPRuntime
    186189        ProxySelector.setDefault(new PluginProxySelector());
     190    }
    187191
    188         CookieManager ckManager = new PluginCookieManager();
     192    private static void setCookieHandler(PluginStreamHandler streamHandler) {
     193        CookieManager ckManager = new PluginCookieManager(streamHandler);
    189194        CookieHandler.setDefault(ckManager);
    190195    }
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java

    r348 r418  
    1 /* VoidPluginCallRequest -- represent Java-to-JavaScript requests
     1/* PluginMessageHandlerWorker -- worker thread for handling messages
    22   Copyright (C) 2008  Red Hat
    33
  • trunk/icedtea-web/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java

    r348 r418  
    6060
    6161    private PluginMessageConsumer consumer;
    62     private Boolean shuttingDown = false;
     62    private volatile boolean shuttingDown = false;
    6363
    6464
     
    323323
    324324            if (message == null || message.equals("shutdown")) {
    325                 synchronized (shuttingDown) {
    326                     shuttingDown = true;
    327                 }
     325                shuttingDown = true;
    328326                try {
    329327                    // Close input/output channels to plugin.
     
    363361                // if we are shutting down, ignore write failures as
    364362                // pipe may have closed
    365                 synchronized (shuttingDown) {
    366                     if (!shuttingDown) {
    367                         e.printStackTrace();
    368                     }
     363                if (!shuttingDown) {
     364                    e.printStackTrace();
    369365                }
    370366
Note: See TracChangeset for help on using the changeset viewer.