diff options
author | Adam Domurad <[email protected]> | 2012-08-17 10:40:22 -0400 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2012-08-17 10:40:22 -0400 |
commit | e6dfb0a5fab464a93c7c38e3cb72cefc0c4e84ea (patch) | |
tree | cb7899e65c15491feb348a1701280bd8f1262e13 /plugin | |
parent | 43ee427be2697090f2f6b0686bdfb3bac1c4964d (diff) |
Fixes PR588, Icedtea-web now saves cookies set in java cookie jar
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/icedteanp/IcedTeaNPPlugin.cc | 45 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginCookieManager.java | 26 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginMain.java | 7 |
3 files changed, 77 insertions, 1 deletions
diff --git a/plugin/icedteanp/IcedTeaNPPlugin.cc b/plugin/icedteanp/IcedTeaNPPlugin.cc index b9fb2c4..645bf11 100644 --- a/plugin/icedteanp/IcedTeaNPPlugin.cc +++ b/plugin/icedteanp/IcedTeaNPPlugin.cc @@ -985,6 +985,21 @@ get_cookie_info(const char* siteAddr, char** cookieString, uint32_t* len) 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 @@ void consume_plugin_message(gchar* message) { 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 <url> <cookie> + 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 --git a/plugin/icedteanp/java/sun/applet/PluginCookieManager.java b/plugin/icedteanp/java/sun/applet/PluginCookieManager.java index 72a94dc..21bdbc0 100644 --- a/plugin/icedteanp/java/sun/applet/PluginCookieManager.java +++ b/plugin/icedteanp/java/sun/applet/PluginCookieManager.java @@ -45,7 +45,16 @@ import java.util.Collections; 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<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException { // pre-condition check @@ -84,4 +93,21 @@ public class PluginCookieManager extends CookieManager { return false; } + + @Override + public void put(URI uri, + Map<String, List<String>> responseHeaders) throws IOException { + super.put(uri, responseHeaders); + + for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) { + String type = headerEntry.getKey(); + if ("Set-Cookie".equalsIgnoreCase(type) || "Set-Cookie2".equalsIgnoreCase(type)) { + List<String> cookies = headerEntry.getValue(); + for (String cookie : cookies) { + streamHandler.write("plugin PluginSetCookie reference -1 " + UrlUtil.encode(uri.toString(), "UTF-8") + " " + cookie); + } + } + + } + } } diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java index 09fce18..fa2de4b 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMain.java +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java @@ -118,6 +118,9 @@ public class PluginMain { // 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 @@ public class PluginMain { } // 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); } } |