# HG changeset patch # User Adam Domurad # Date 1345218418 14400 # Node ID ae0cbdc9008a84899abf67f97610e4450a980d17 # Parent 5586c774341b39e1f29acfaffc0da17f89484681 Fixes PR588, Icedtea-web now saves cookies set in java cookie jar diff -r 5586c774341b -r ae0cbdc9008a ChangeLog --- a/ChangeLog Fri Aug 17 11:40:49 2012 -0400 +++ b/ChangeLog Fri Aug 17 11:46:58 2012 -0400 @@ -1,3 +1,16 @@ +2012-08-17 Adam Domurad + + Fixes PR588, cookies set in the java cookie jar are now stored properly + * plugin/icedteanp/IcedTeaNPPlugin.cc + (set_cookie_info): New, uses setvalueforurl + (consume_plugin_message): Additional message added allowing + set_cookie_info to be used from the java side. + * plugin/icedteanp/java/sun/applet/PluginCookieManager.java: Now + overrides put method, results in set_cookie_info calls in C++ + * plugin/icedteanp/java/sun/applet/PluginMain.java: Passes + PluginStreamHandler to PluginCookieManager to allow C++ side + communication + 2012-08-17 Adam Domurad * plugin/icedteanp/IcedTeaNPPlugin.cc diff -r 5586c774341b -r ae0cbdc9008a NEWS --- a/NEWS Fri Aug 17 11:40:49 2012 -0400 +++ b/NEWS Fri Aug 17 11:46:58 2012 -0400 @@ -26,6 +26,7 @@ - PR1011: Folders treated as jar files in archive tag - PR1106: Buffer overflow in plugin table - PR975: Plugin should not include classpaths specified in jar manifests when using jnlp_href + - PR588: Cookies not written from cookie jar to browser cookies * Common - PR918: java applet windows uses a low resulution black/white icon - RH838417: Disambiguate signed applet security prompt from certificate warning diff -r 5586c774341b -r ae0cbdc9008a plugin/icedteanp/IcedTeaNPPlugin.cc --- a/plugin/icedteanp/IcedTeaNPPlugin.cc Fri Aug 17 11:40:49 2012 -0400 +++ b/plugin/icedteanp/IcedTeaNPPlugin.cc Fri Aug 17 11:46:58 2012 -0400 @@ -985,6 +985,21 @@ return NPERR_NO_ERROR; } +static NPError +set_cookie_info(const char* siteAddr, const char* cookieString, uint32_t len) +{ + // Only attempt to perform this operation if there is a valid plugin instance + if (g_hash_table_size(instance_to_id_map) > 0 && browser_functions.getvalueforurl) + { + // We arbitrarily use the first valid instance we can grab + // For an explanation of the logic behind this, see get_cookie_info + gpointer instance = getFirstInTableInstance(instance_to_id_map); + return browser_functions.setvalueforurl((NPP) instance, NPNURLVCookie, siteAddr, cookieString, len); + } + + return NPERR_GENERIC_ERROR;; +} + // HELPER FUNCTIONS static void @@ -1247,7 +1262,37 @@ decoded_url = NULL; g_free(cookie_info); cookie_info = NULL; + } else if (g_str_has_prefix(parts[1], "PluginSetCookie")) + { + // Message structure: plugin PluginSetCookie reference -1 + gchar** cookie_parts = g_strsplit (message, " ", 6); + + if (g_strv_length(cookie_parts) < 6) + { + g_strfreev (parts); + g_strfreev (cookie_parts); + return; // Defensive, message _should_ be properly formatted + } + + gchar* decoded_url = (gchar*) calloc(strlen(cookie_parts[4])+1, sizeof(gchar)); + IcedTeaPluginUtilities::decodeURL(cookie_parts[4], &decoded_url); + + gchar* cookie_string = cookie_parts[5]; + uint32_t len = strlen(cookie_string); + if (set_cookie_info(decoded_url, cookie_string, len) == NPERR_NO_ERROR) + { + PLUGIN_DEBUG("Setting cookie for URL %s to %s\n", decoded_url, cookie_string); + } else + { + PLUGIN_DEBUG("Not able to set cookie for URL %s to %s\n", decoded_url, cookie_string); + } + + free(decoded_url); + decoded_url = NULL; + g_strfreev (cookie_parts); + cookie_parts = NULL; } + g_strfreev (parts); parts = NULL; } diff -r 5586c774341b -r ae0cbdc9008a plugin/icedteanp/java/sun/applet/PluginCookieManager.java --- a/plugin/icedteanp/java/sun/applet/PluginCookieManager.java Fri Aug 17 11:40:49 2012 -0400 +++ b/plugin/icedteanp/java/sun/applet/PluginCookieManager.java Fri Aug 17 11:46:58 2012 -0400 @@ -45,7 +45,16 @@ import java.util.List; import java.util.Map; +import com.sun.jndi.toolkit.url.UrlUtil; + public class PluginCookieManager extends CookieManager { + private PluginStreamHandler streamHandler; + + public PluginCookieManager(PluginStreamHandler streamHandler) { + this.streamHandler = streamHandler; + } + + @Override public Map> get(URI uri, Map> requestHeaders) throws IOException { // pre-condition check @@ -84,4 +93,21 @@ return false; } + + @Override + public void put(URI uri, + Map> responseHeaders) throws IOException { + super.put(uri, responseHeaders); + + for (Map.Entry> headerEntry : responseHeaders.entrySet()) { + String type = headerEntry.getKey(); + if ("Set-Cookie".equalsIgnoreCase(type) || "Set-Cookie2".equalsIgnoreCase(type)) { + List cookies = headerEntry.getValue(); + for (String cookie : cookies) { + streamHandler.write("plugin PluginSetCookie reference -1 " + UrlUtil.encode(uri.toString(), "UTF-8") + " " + cookie); + } + } + + } + } } diff -r 5586c774341b -r ae0cbdc9008a plugin/icedteanp/java/sun/applet/PluginMain.java --- a/plugin/icedteanp/java/sun/applet/PluginMain.java Fri Aug 17 11:40:49 2012 -0400 +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java Fri Aug 17 11:46:58 2012 -0400 @@ -118,6 +118,9 @@ // Streams set. Start processing. streamHandler.startProcessing(); + + setCookieHandler(streamHandler); + } catch (Exception e) { e.printStackTrace(); System.err.println("Something very bad happened. I don't know what to do, so I am going to exit :("); @@ -199,8 +202,10 @@ } // override the proxy selector set by JNLPRuntime ProxySelector.setDefault(new PluginProxySelector()); + } - CookieManager ckManager = new PluginCookieManager(); + private static void setCookieHandler(PluginStreamHandler streamHandler) { + CookieManager ckManager = new PluginCookieManager(streamHandler); CookieHandler.setDefault(ckManager); } }