|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
RFC: Rewrite of cookie support in pluginThis patch rewrites cookie support in the plugin. The old way was
static, set at initialization time. Additionally, it did not support cookie provision for connection requests made by the applet internally. This patch fixes all of that. Cookie information is now supplied to Java in real-time from Mozilla side, as it should be. Thanks to Omair for the initial error trace. This patch fixes rhbz 506730: https://bugzilla.redhat.com/show_bug.cgi?id=506730 http://www.sbm.no/ will now load correctly with this patch. ChangeLog: * IcedTeaPlugin.cc: Add suppport for cookie info requests from applets. * plugin/icedtea/sun/applet/PluginAppletViewer.java: Rework cookie support to make it dynamic. * plugin/icedtea/sun/applet/PluginMain.java: Wire in custom cookie store that dynamically requests cookie information from C++ side. * rt/net/sourceforge/jnlp/JNLPFile.java: Remove old cookie handling code. * rt/net/sourceforge/jnlp/Launcher.java: Same. * rt/net/sourceforge/jnlp/NetxPanel.java: Same. * rt/net/sourceforge/jnlp/PluginBridge.java: Same. * rt/net/sourceforge/jnlp/cache/CacheUtil.java: Same. * rt/net/sourceforge/jnlp/cache/Resource.java: Same. * rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Same. * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Same. Comments? Deepak diff -r 308c172cd230 IcedTeaPlugin.cc --- a/IcedTeaPlugin.cc Fri Jul 03 11:52:45 2009 +0100 +++ b/IcedTeaPlugin.cc Fri Jul 03 17:40:05 2009 -0400 @@ -1012,6 +1012,7 @@ void ProcessMessage(); void ConsumeMsgFromJVM(); nsresult GetProxyInfo(const char* siteAddr, char** proxyScheme, char** proxyHost, char** proxyPort); + nsresult GetCookieInfo(const char* siteAddr, char** cookieString); nsCOMPtr<IcedTeaEventSink> sink; nsCOMPtr<nsISocketTransport> transport; nsCOMPtr<nsIProcess> applet_viewer_process; @@ -1070,7 +1071,6 @@ IcedTeaPluginFactory* factory; PRUint32 instance_identifier; nsCString instanceIdentifierPrefix; - nsresult GetCookie(const char* siteAddr, char** cookieString); }; @@ -2380,16 +2380,6 @@ encodedAppletTag += tagMessage.get()[i]; } - nsCString cookieInfo(instanceIdentifierPrefix); - cookieInfo += "cookie "; - - char* cookieString; - if (GetCookie(documentbase, &cookieString) == NS_OK) - { - cookieInfo += cookieString; - } - - factory->SendMessageToAppletViewer (cookieInfo); factory->SendMessageToAppletViewer (encodedAppletTag); // Set back-pointer to peer instance. @@ -2760,8 +2750,15 @@ return NS_OK; } -NS_IMETHODIMP -IcedTeaPluginInstance::GetCookie(const char* siteAddr, char** cookieString) +/** + * Returns the cookie information for the given url + * + * @param siteAddr The URI to check (must be decoded) + * @return cookieString The cookie string for the given URI + */ + +NS_IMETHODIMP +IcedTeaPluginFactory::GetCookieInfo(const char* siteAddr, char** cookieString) { nsresult rv; @@ -3497,6 +3494,35 @@ // free allocated memory delete proxyScheme, proxyHost, proxyPort; + + } else if (command == "PluginCookieInfo") + { + + nsresult rv; + nsCOMPtr<nsINetUtil> net_util = do_GetService(NS_NETUTIL_CONTRACTID, &rv); + + if (!net_util) + printf("Error instantiating NetUtil service.\n"); + + // decode the url + nsDependentCSubstring url; + net_util->UnescapeString(rest, 0, url); + + nsCString cookieInfo("plugin PluginCookieInfo "); + cookieInfo += rest; + cookieInfo += " "; + + char* cookieString; + if (GetCookieInfo(((nsCString) url).get(), &cookieString) == NS_OK) + { + cookieInfo += cookieString; + PLUGIN_DEBUG_2ARG("Cookie for %s is %s\n", ((nsCString) url).get(), cookieString); + } else { + PLUGIN_DEBUG_1ARG("No cookie found for %s\n", ((nsCString) url).get()); + } + + // send back what we found + SendMessageToAppletViewer (cookieInfo); } } diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginAppletViewer.java --- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Fri Jul 03 17:40:05 2009 -0400 @@ -84,6 +84,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketPermission; @@ -180,9 +181,6 @@ private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - - private static HashMap<Integer, String> siteCookies = - new HashMap<Integer,String>(); private static HashMap<Integer, PAV_INIT_STATUS> status = new HashMap<Integer,PAV_INIT_STATUS>(); @@ -226,7 +224,7 @@ AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { - panel = new NetxPanel(doc, siteCookies.get(identifier), atts, false); + panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); } catch (Exception ex) { @@ -483,16 +481,6 @@ PluginDebug.debug ("REQUEST TAG NOT SET: " + request.tag + ". BYPASSING"); } } - } else if (message.startsWith("cookie")) { - - int cookieStrIndex = message.indexOf(" "); - String cookieStr = null; - - if (cookieStrIndex > 0) - cookieStr = message.substring(cookieStrIndex); - - // Always set the cookie -- even if it is null - siteCookies.put(identifier, cookieStr); } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); @@ -842,7 +830,6 @@ * applets on this page. */ public Enumeration getApplets() { - AppletSecurity security = (AppletSecurity)System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); @@ -896,7 +883,7 @@ // streamhandler.pluginOutputStream has been closed. } } - + public long getWindow() { PluginDebug.debug ("STARTING getWindow"); PluginCallRequest request = requestFactory.getPluginCallRequest("window", @@ -1113,6 +1100,40 @@ return request.getObject(); } + public static Object requestPluginCookieInfo(URI uri) { + + PluginCallRequest request; + try + { + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + request = requestFactory.getPluginCallRequest("cookieinfo", + "plugin PluginCookieInfo " + encodedURI, + "plugin PluginCookieInfo " + encodedURI); + + } catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + return null; + } + + streamhandler.postCallRequest(request); + streamhandler.write(request.getMessage()); + try { + PluginDebug.debug ("wait cookieinfo request 1"); + synchronized(request) { + PluginDebug.debug ("wait cookieinfo request 2"); + while (request.isDone() == false) + request.wait(); + PluginDebug.debug ("wait cookieinfo request 3"); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted waiting for cookieinfo request.", + e); + } + PluginDebug.debug (" Cookieinfo DONE"); + return request.getObject(); + } + public static Object requestPluginProxyInfo(URI uri) { String requestURI = null; @@ -1623,10 +1644,6 @@ public static void parse(int identifier, long handle, Reader in, URL url) throws IOException { - // wait until cookie is set (even if cookie is null, it needs to be - // "set" to that first - while (!siteCookies.containsKey(identifier)); - final int fIdentifier = identifier; final long fHandle = handle; final Reader fIn = in; diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginCallRequestFactory.java --- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Fri Jul 03 17:40:05 2009 -0400 @@ -51,6 +51,8 @@ return new GetWindowPluginCallRequest(message, returnString); } else if (id == "proxyinfo") { return new PluginProxyInfoRequest(message, returnString); + } else if (id == "cookieinfo") { + return new PluginCookieInfoRequest(message, returnString); } else { throw new RuntimeException ("Unknown plugin call request type requested from factory"); } diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginMain.java --- a/plugin/icedtea/sun/applet/PluginMain.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginMain.java Fri Jul 03 17:40:05 2009 -0400 @@ -68,10 +68,11 @@ import java.io.IOException; import java.io.PrintStream; import java.net.Authenticator; +import java.net.CookieHandler; +import java.net.CookieManager; import java.net.PasswordAuthentication; import java.net.ProxySelector; import java.util.Enumeration; -import java.util.HashMap; import java.util.Properties; import javax.net.ssl.HttpsURLConnection; @@ -218,6 +219,9 @@ // plug in a custom authenticator and proxy selector Authenticator.setDefault(new CustomAuthenticator()); ProxySelector.setDefault(new PluginProxySelector()); + + CookieManager ckManager = new CookieManager(new PluginCookieStore(), null); + CookieHandler.setDefault(ckManager); } static boolean messageAvailable() { diff -r 308c172cd230 rt/net/sourceforge/jnlp/JNLPFile.java --- a/rt/net/sourceforge/jnlp/JNLPFile.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Fri Jul 03 17:40:05 2009 -0400 @@ -69,9 +69,6 @@ /** the URL used to resolve relative URLs in the file */ protected URL codeBase; - - /** cookie string to send alongwith resource requests */ - protected String cookieStr; /** file version */ protected Version fileVersion; @@ -159,7 +156,6 @@ parse(root, strict, location); this.fileLocation = location; - this.cookieStr = cookieStr; } /** @@ -196,7 +192,7 @@ try { ResourceTracker tracker = new ResourceTracker(false); // no prefetch - tracker.addResource(location, cookieStr, null/*version*/, policy); + tracker.addResource(location, null/*version*/, policy); return tracker.getInputStream(location); } @@ -255,13 +251,6 @@ */ public URL getCodeBase() { return codeBase; - } - - /** - * Returns the cookie string that will be send when resources for this file are requested - */ - public String getCookieStr() { - return cookieStr; } /** diff -r 308c172cd230 rt/net/sourceforge/jnlp/Launcher.java --- a/rt/net/sourceforge/jnlp/Launcher.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/Launcher.java Fri Jul 03 17:40:06 2009 -0400 @@ -389,7 +389,7 @@ IconDesc.SPLASH, preferredWidth, preferredHeight); if (splashImageURL != null) { ResourceTracker resourceTracker = new ResourceTracker(true); - resourceTracker.addResource(splashImageURL, "SPLASH", file.getFileVersion(), updatePolicy); + resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy); splashScreen = new JNLPSplashScreen(resourceTracker, null, null); splashScreen.setSplashImageURL(splashImageURL); if (splashScreen.isSplashScreenValid()) { diff -r 308c172cd230 rt/net/sourceforge/jnlp/NetxPanel.java --- a/rt/net/sourceforge/jnlp/NetxPanel.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/NetxPanel.java Fri Jul 03 17:40:06 2009 -0400 @@ -41,7 +41,6 @@ private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; - private String cookieStr; private boolean appletAlive; public NetxPanel(URL documentURL, Hashtable atts) @@ -50,11 +49,10 @@ } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, String cookieStr, Hashtable atts, boolean exitOnFailure) + public NetxPanel(URL documentURL, Hashtable atts, boolean exitOnFailure) { this(documentURL, atts); this.exitOnFailure = exitOnFailure; - this.cookieStr = cookieStr; this.appletAlive = true; } @@ -64,7 +62,6 @@ try { bridge = new PluginBridge(baseURL, - cookieStr, getDocumentBase(), getJarFiles(), getCode(), diff -r 308c172cd230 rt/net/sourceforge/jnlp/PluginBridge.java --- a/rt/net/sourceforge/jnlp/PluginBridge.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Fri Jul 03 17:40:06 2009 -0400 @@ -43,7 +43,7 @@ String[] cache_ex_jars = new String[0]; Hashtable atts; - public PluginBridge(URL codebase, String cookieStr, URL documentBase, String jar, String main, + public PluginBridge(URL codebase, URL documentBase, String jar, String main, int width, int height, Hashtable atts) throws Exception { @@ -104,7 +104,6 @@ else security = null; - this.cookieStr = cookieStr; } public String getTitle() diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/CacheUtil.java --- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Fri Jul 03 17:40:06 2009 -0400 @@ -75,9 +75,9 @@ * @param version the version, or null * @return either the location in the cache or the original location */ - public static URL getCachedResource(URL location, String cookieStr, Version version, UpdatePolicy policy) { + public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) { ResourceTracker rt = new ResourceTracker(); - rt.addResource(location, cookieStr, version, policy); + rt.addResource(location, version, policy); try { File f = rt.getCacheFile(location); return f.toURL(); diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/Resource.java --- a/rt/net/sourceforge/jnlp/cache/Resource.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/Resource.java Fri Jul 03 17:40:06 2009 -0400 @@ -68,9 +68,6 @@ /** the remote location of the resource */ URL location; - /** cookie string to send with the resource request */ - String cookieStr; - /** the local file downloaded to */ File localFile; @@ -98,20 +95,19 @@ /** * Create a resource. */ - private Resource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + private Resource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { this.location = location; this.requestVersion = requestVersion; this.updatePolicy = updatePolicy; - this.cookieStr = cookieStr; } /** * Return a shared Resource object representing the given * location and version. */ - public static Resource getResource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + public static Resource getResource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { synchronized (resources) { - Resource resource = new Resource(location, cookieStr, updatePolicy, requestVersion); + Resource resource = new Resource(location, updatePolicy, requestVersion); int index = resources.indexOf(resource); if (index >= 0) { // return existing object @@ -132,13 +128,6 @@ */ public URL getLocation() { return location; - } - - /** - * Returns the cookie string associated with this resource - */ - public String getCookieStr() { - return cookieStr; } /** diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/ResourceTracker.java --- a/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Fri Jul 03 17:40:06 2009 -0400 @@ -148,11 +148,11 @@ * @param version the resource version * @param updatePolicy whether to check for updates if already in cache */ - public void addResource(URL location, String cookieStr, Version version, UpdatePolicy updatePolicy) { + public void addResource(URL location, Version version, UpdatePolicy updatePolicy) { if (location == null) throw new IllegalArgumentException("location==null"); - Resource resource = Resource.getResource(location, cookieStr, updatePolicy, version); + Resource resource = Resource.getResource(location, updatePolicy, version); boolean downloaded = false; synchronized (resources) { @@ -606,9 +606,6 @@ try { // create out second in case in does not exist URLConnection con = getVersionedResourceURL(resource).openConnection(); - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - con.setRequestProperty("Cookie", resource.getCookieStr()); InputStream in = new BufferedInputStream(con.getInputStream()); OutputStream out = CacheUtil.getOutputStream(resource.location, resource.downloadVersion); @@ -657,9 +654,6 @@ // connect URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - connection.setRequestProperty("Cookie", resource.getCookieStr()); int size = connection.getContentLength(); boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE; diff -r 308c172cd230 rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Fri Jul 03 17:40:06 2009 -0400 @@ -314,7 +314,6 @@ initialJars.add(jars[i]); // regardless of part tracker.addResource(jars[i].getLocation(), - file.getCookieStr(), jars[i].getVersion(), jars[i].isCacheable() ? JNLPRuntime.getDefaultUpdatePolicy() : UpdatePolicy.FORCE ); @@ -776,8 +775,7 @@ available.add(desc); - tracker.addResource(desc.getLocation(), - file.getCookieStr(), + tracker.addResource(desc.getLocation(), desc.getVersion(), JNLPRuntime.getDefaultUpdatePolicy() ); |
|
|
Re: RFC: Rewrite of cookie support in pluginOops. Original message is missing 2 new files from the patch. Sorry
about that. New patch attached. Deepak * Deepak Bhole <dbhole@...> [2009-07-03 17:48]: > This patch rewrites cookie support in the plugin. The old way was > static, set at initialization time. Additionally, it did not support > cookie provision for connection requests made by the applet internally. > > This patch fixes all of that. Cookie information is now supplied to Java > in real-time from Mozilla side, as it should be. > > Thanks to Omair for the initial error trace. > > This patch fixes rhbz 506730: > https://bugzilla.redhat.com/show_bug.cgi?id=506730 > > http://www.sbm.no/ will now load correctly with this patch. > > ChangeLog: > * IcedTeaPlugin.cc: Add suppport for cookie info requests from applets. > * plugin/icedtea/sun/applet/PluginAppletViewer.java: Rework cookie support > to make it dynamic. > * plugin/icedtea/sun/applet/PluginMain.java: Wire in custom cookie store > that dynamically requests cookie information from C++ side. > * rt/net/sourceforge/jnlp/JNLPFile.java: Remove old cookie handling code. > * rt/net/sourceforge/jnlp/Launcher.java: Same. > * rt/net/sourceforge/jnlp/NetxPanel.java: Same. > * rt/net/sourceforge/jnlp/PluginBridge.java: Same. > * rt/net/sourceforge/jnlp/cache/CacheUtil.java: Same. > * rt/net/sourceforge/jnlp/cache/Resource.java: Same. > * rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Same. > * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Same. > > Comments? > > Deepak diff -r 308c172cd230 IcedTeaPlugin.cc --- a/IcedTeaPlugin.cc Fri Jul 03 11:52:45 2009 +0100 +++ b/IcedTeaPlugin.cc Fri Jul 03 18:28:13 2009 -0400 @@ -1012,6 +1012,7 @@ void ProcessMessage(); void ConsumeMsgFromJVM(); nsresult GetProxyInfo(const char* siteAddr, char** proxyScheme, char** proxyHost, char** proxyPort); + nsresult GetCookieInfo(const char* siteAddr, char** cookieString); nsCOMPtr<IcedTeaEventSink> sink; nsCOMPtr<nsISocketTransport> transport; nsCOMPtr<nsIProcess> applet_viewer_process; @@ -1070,7 +1071,6 @@ IcedTeaPluginFactory* factory; PRUint32 instance_identifier; nsCString instanceIdentifierPrefix; - nsresult GetCookie(const char* siteAddr, char** cookieString); }; @@ -2380,16 +2380,6 @@ encodedAppletTag += tagMessage.get()[i]; } - nsCString cookieInfo(instanceIdentifierPrefix); - cookieInfo += "cookie "; - - char* cookieString; - if (GetCookie(documentbase, &cookieString) == NS_OK) - { - cookieInfo += cookieString; - } - - factory->SendMessageToAppletViewer (cookieInfo); factory->SendMessageToAppletViewer (encodedAppletTag); // Set back-pointer to peer instance. @@ -2760,8 +2750,15 @@ return NS_OK; } -NS_IMETHODIMP -IcedTeaPluginInstance::GetCookie(const char* siteAddr, char** cookieString) +/** + * Returns the cookie information for the given url + * + * @param siteAddr The URI to check (must be decoded) + * @return cookieString The cookie string for the given URI + */ + +NS_IMETHODIMP +IcedTeaPluginFactory::GetCookieInfo(const char* siteAddr, char** cookieString) { nsresult rv; @@ -3497,6 +3494,35 @@ // free allocated memory delete proxyScheme, proxyHost, proxyPort; + + } else if (command == "PluginCookieInfo") + { + + nsresult rv; + nsCOMPtr<nsINetUtil> net_util = do_GetService(NS_NETUTIL_CONTRACTID, &rv); + + if (!net_util) + printf("Error instantiating NetUtil service.\n"); + + // decode the url + nsDependentCSubstring url; + net_util->UnescapeString(rest, 0, url); + + nsCString cookieInfo("plugin PluginCookieInfo "); + cookieInfo += rest; + cookieInfo += " "; + + char* cookieString; + if (GetCookieInfo(((nsCString) url).get(), &cookieString) == NS_OK) + { + cookieInfo += cookieString; + PLUGIN_DEBUG_2ARG("Cookie for %s is %s\n", ((nsCString) url).get(), cookieString); + } else { + PLUGIN_DEBUG_1ARG("No cookie found for %s\n", ((nsCString) url).get()); + } + + // send back what we found + SendMessageToAppletViewer (cookieInfo); } } diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginAppletViewer.java --- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Fri Jul 03 18:28:13 2009 -0400 @@ -84,6 +84,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketPermission; @@ -180,9 +181,6 @@ private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - - private static HashMap<Integer, String> siteCookies = - new HashMap<Integer,String>(); private static HashMap<Integer, PAV_INIT_STATUS> status = new HashMap<Integer,PAV_INIT_STATUS>(); @@ -226,7 +224,7 @@ AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { - panel = new NetxPanel(doc, siteCookies.get(identifier), atts, false); + panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); } catch (Exception ex) { @@ -483,16 +481,6 @@ PluginDebug.debug ("REQUEST TAG NOT SET: " + request.tag + ". BYPASSING"); } } - } else if (message.startsWith("cookie")) { - - int cookieStrIndex = message.indexOf(" "); - String cookieStr = null; - - if (cookieStrIndex > 0) - cookieStr = message.substring(cookieStrIndex); - - // Always set the cookie -- even if it is null - siteCookies.put(identifier, cookieStr); } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); @@ -842,7 +830,6 @@ * applets on this page. */ public Enumeration getApplets() { - AppletSecurity security = (AppletSecurity)System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); @@ -896,7 +883,7 @@ // streamhandler.pluginOutputStream has been closed. } } - + public long getWindow() { PluginDebug.debug ("STARTING getWindow"); PluginCallRequest request = requestFactory.getPluginCallRequest("window", @@ -1113,6 +1100,40 @@ return request.getObject(); } + public static Object requestPluginCookieInfo(URI uri) { + + PluginCallRequest request; + try + { + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + request = requestFactory.getPluginCallRequest("cookieinfo", + "plugin PluginCookieInfo " + encodedURI, + "plugin PluginCookieInfo " + encodedURI); + + } catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + return null; + } + + streamhandler.postCallRequest(request); + streamhandler.write(request.getMessage()); + try { + PluginDebug.debug ("wait cookieinfo request 1"); + synchronized(request) { + PluginDebug.debug ("wait cookieinfo request 2"); + while (request.isDone() == false) + request.wait(); + PluginDebug.debug ("wait cookieinfo request 3"); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted waiting for cookieinfo request.", + e); + } + PluginDebug.debug (" Cookieinfo DONE"); + return request.getObject(); + } + public static Object requestPluginProxyInfo(URI uri) { String requestURI = null; @@ -1623,10 +1644,6 @@ public static void parse(int identifier, long handle, Reader in, URL url) throws IOException { - // wait until cookie is set (even if cookie is null, it needs to be - // "set" to that first - while (!siteCookies.containsKey(identifier)); - final int fIdentifier = identifier; final long fHandle = handle; final Reader fIn = in; diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginCallRequestFactory.java --- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Fri Jul 03 18:28:13 2009 -0400 @@ -51,6 +51,8 @@ return new GetWindowPluginCallRequest(message, returnString); } else if (id == "proxyinfo") { return new PluginProxyInfoRequest(message, returnString); + } else if (id == "cookieinfo") { + return new PluginCookieInfoRequest(message, returnString); } else { throw new RuntimeException ("Unknown plugin call request type requested from factory"); } diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginCookieInfoRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieInfoRequest.java Fri Jul 03 18:28:13 2009 -0400 @@ -0,0 +1,122 @@ +/* PluginCookieInfoRequest -- Object representing a request for cookie information from the browser + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import com.sun.jndi.toolkit.url.UrlUtil; + +/** + * This class represents a request object for cookie information for a given URI + */ + +public class PluginCookieInfoRequest extends PluginCallRequest { + + List<HttpCookie> cookieObjects = new ArrayList<HttpCookie>(); + + public PluginCookieInfoRequest(String message, String returnString) { + super(message, returnString); + } + + public void parseReturn(String cookieInfo) { + + // try to parse the proxy information. If things go wrong, do nothing .. + // this will keep internal = null which forces a direct connection + + PluginDebug.debug ("PluginCookieInfoRequest GOT: " + cookieInfo); + + String encodedURI = cookieInfo.split(" ")[2]; + + // Skip the first 3 components. We are guaranteed 3 components, + // so no index -1 to worry about + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + + URI siteURI; + try + { + siteURI = new URI(UrlUtil.decode(encodedURI, "UTF-8")); + } catch (Exception e) + { + e.printStackTrace(); + return; + } + + if (cookieInfo != null && cookieInfo.length() > 0) + { + String[] cookies = cookieInfo.split(";"); + + for (int i = 0; i < cookies.length; i++) + { + ArrayList l = new ArrayList(); + + String cookie = cookies[i]; + cookie = cookie.trim(); + String cookieName = cookie.substring(0, cookie.indexOf("=")); + String cookieValue = cookie.substring(cookie.indexOf("=")+1); + + HttpCookie httpCookieObj = new HttpCookie(cookieName, cookieValue); + httpCookieObj.setPath(siteURI.getPath()); + httpCookieObj.setVersion(0); // force v0 + + PluginDebug.debug("Adding cookie info COOKIEN=" + cookieName + " and COOKIEV=" + cookieValue); + cookieObjects.add(httpCookieObj); + } + } + + setDone(true); + } + + /** + * Returns whether the given message is serviceable by this object + * + * @param message The message to service + * @return boolean indicating if message is serviceable + */ + public boolean serviceable(String message) { + return message.startsWith(returnString); + } + + public List<HttpCookie> getObject() { + return this.cookieObjects; + } +} diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginCookieStore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieStore.java Fri Jul 03 18:28:13 2009 -0400 @@ -0,0 +1,73 @@ +/* PluginCookieStore -- Storage for cookie information + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.List; + +import sun.net.www.protocol.http.InMemoryCookieStore; + +public class PluginCookieStore extends InMemoryCookieStore +{ + public List<HttpCookie> get(URI uri) + { + List<HttpCookie> cookies; + + // Try to fetch it from the plugin, but if something goes + // wrong, fall back. Don't crash! + try + { + cookies = (List<HttpCookie>) PluginAppletViewer.requestPluginCookieInfo(uri); + + // If cookies is null, something went wrong. Fall back. + if (cookies == null) throw new NullPointerException("Null cookie"); + + } catch (Exception e) + { + PluginDebug.debug("Unable to fetch cookie information from plugin. " + + "Falling back to default."); + e.printStackTrace(); + cookies = super.get(uri); + } + + PluginDebug.debug("Returning cookies " + cookies + " for site: " + uri); + + return cookies; + } +} diff -r 308c172cd230 plugin/icedtea/sun/applet/PluginMain.java --- a/plugin/icedtea/sun/applet/PluginMain.java Fri Jul 03 11:52:45 2009 +0100 +++ b/plugin/icedtea/sun/applet/PluginMain.java Fri Jul 03 18:28:13 2009 -0400 @@ -68,10 +68,11 @@ import java.io.IOException; import java.io.PrintStream; import java.net.Authenticator; +import java.net.CookieHandler; +import java.net.CookieManager; import java.net.PasswordAuthentication; import java.net.ProxySelector; import java.util.Enumeration; -import java.util.HashMap; import java.util.Properties; import javax.net.ssl.HttpsURLConnection; @@ -218,6 +219,9 @@ // plug in a custom authenticator and proxy selector Authenticator.setDefault(new CustomAuthenticator()); ProxySelector.setDefault(new PluginProxySelector()); + + CookieManager ckManager = new CookieManager(new PluginCookieStore(), null); + CookieHandler.setDefault(ckManager); } static boolean messageAvailable() { diff -r 308c172cd230 rt/net/sourceforge/jnlp/JNLPFile.java --- a/rt/net/sourceforge/jnlp/JNLPFile.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Fri Jul 03 18:28:13 2009 -0400 @@ -69,9 +69,6 @@ /** the URL used to resolve relative URLs in the file */ protected URL codeBase; - - /** cookie string to send alongwith resource requests */ - protected String cookieStr; /** file version */ protected Version fileVersion; @@ -159,7 +156,6 @@ parse(root, strict, location); this.fileLocation = location; - this.cookieStr = cookieStr; } /** @@ -196,7 +192,7 @@ try { ResourceTracker tracker = new ResourceTracker(false); // no prefetch - tracker.addResource(location, cookieStr, null/*version*/, policy); + tracker.addResource(location, null/*version*/, policy); return tracker.getInputStream(location); } @@ -255,13 +251,6 @@ */ public URL getCodeBase() { return codeBase; - } - - /** - * Returns the cookie string that will be send when resources for this file are requested - */ - public String getCookieStr() { - return cookieStr; } /** diff -r 308c172cd230 rt/net/sourceforge/jnlp/Launcher.java --- a/rt/net/sourceforge/jnlp/Launcher.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/Launcher.java Fri Jul 03 18:28:13 2009 -0400 @@ -389,7 +389,7 @@ IconDesc.SPLASH, preferredWidth, preferredHeight); if (splashImageURL != null) { ResourceTracker resourceTracker = new ResourceTracker(true); - resourceTracker.addResource(splashImageURL, "SPLASH", file.getFileVersion(), updatePolicy); + resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy); splashScreen = new JNLPSplashScreen(resourceTracker, null, null); splashScreen.setSplashImageURL(splashImageURL); if (splashScreen.isSplashScreenValid()) { diff -r 308c172cd230 rt/net/sourceforge/jnlp/NetxPanel.java --- a/rt/net/sourceforge/jnlp/NetxPanel.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/NetxPanel.java Fri Jul 03 18:28:13 2009 -0400 @@ -41,7 +41,6 @@ private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; - private String cookieStr; private boolean appletAlive; public NetxPanel(URL documentURL, Hashtable atts) @@ -50,11 +49,10 @@ } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, String cookieStr, Hashtable atts, boolean exitOnFailure) + public NetxPanel(URL documentURL, Hashtable atts, boolean exitOnFailure) { this(documentURL, atts); this.exitOnFailure = exitOnFailure; - this.cookieStr = cookieStr; this.appletAlive = true; } @@ -64,7 +62,6 @@ try { bridge = new PluginBridge(baseURL, - cookieStr, getDocumentBase(), getJarFiles(), getCode(), diff -r 308c172cd230 rt/net/sourceforge/jnlp/PluginBridge.java --- a/rt/net/sourceforge/jnlp/PluginBridge.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Fri Jul 03 18:28:13 2009 -0400 @@ -43,7 +43,7 @@ String[] cache_ex_jars = new String[0]; Hashtable atts; - public PluginBridge(URL codebase, String cookieStr, URL documentBase, String jar, String main, + public PluginBridge(URL codebase, URL documentBase, String jar, String main, int width, int height, Hashtable atts) throws Exception { @@ -104,7 +104,6 @@ else security = null; - this.cookieStr = cookieStr; } public String getTitle() diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/CacheUtil.java --- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Fri Jul 03 18:28:13 2009 -0400 @@ -75,9 +75,9 @@ * @param version the version, or null * @return either the location in the cache or the original location */ - public static URL getCachedResource(URL location, String cookieStr, Version version, UpdatePolicy policy) { + public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) { ResourceTracker rt = new ResourceTracker(); - rt.addResource(location, cookieStr, version, policy); + rt.addResource(location, version, policy); try { File f = rt.getCacheFile(location); return f.toURL(); diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/Resource.java --- a/rt/net/sourceforge/jnlp/cache/Resource.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/Resource.java Fri Jul 03 18:28:13 2009 -0400 @@ -68,9 +68,6 @@ /** the remote location of the resource */ URL location; - /** cookie string to send with the resource request */ - String cookieStr; - /** the local file downloaded to */ File localFile; @@ -98,20 +95,19 @@ /** * Create a resource. */ - private Resource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + private Resource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { this.location = location; this.requestVersion = requestVersion; this.updatePolicy = updatePolicy; - this.cookieStr = cookieStr; } /** * Return a shared Resource object representing the given * location and version. */ - public static Resource getResource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + public static Resource getResource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { synchronized (resources) { - Resource resource = new Resource(location, cookieStr, updatePolicy, requestVersion); + Resource resource = new Resource(location, updatePolicy, requestVersion); int index = resources.indexOf(resource); if (index >= 0) { // return existing object @@ -132,13 +128,6 @@ */ public URL getLocation() { return location; - } - - /** - * Returns the cookie string associated with this resource - */ - public String getCookieStr() { - return cookieStr; } /** diff -r 308c172cd230 rt/net/sourceforge/jnlp/cache/ResourceTracker.java --- a/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Fri Jul 03 18:28:13 2009 -0400 @@ -148,11 +148,11 @@ * @param version the resource version * @param updatePolicy whether to check for updates if already in cache */ - public void addResource(URL location, String cookieStr, Version version, UpdatePolicy updatePolicy) { + public void addResource(URL location, Version version, UpdatePolicy updatePolicy) { if (location == null) throw new IllegalArgumentException("location==null"); - Resource resource = Resource.getResource(location, cookieStr, updatePolicy, version); + Resource resource = Resource.getResource(location, updatePolicy, version); boolean downloaded = false; synchronized (resources) { @@ -606,9 +606,6 @@ try { // create out second in case in does not exist URLConnection con = getVersionedResourceURL(resource).openConnection(); - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - con.setRequestProperty("Cookie", resource.getCookieStr()); InputStream in = new BufferedInputStream(con.getInputStream()); OutputStream out = CacheUtil.getOutputStream(resource.location, resource.downloadVersion); @@ -657,9 +654,6 @@ // connect URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - connection.setRequestProperty("Cookie", resource.getCookieStr()); int size = connection.getContentLength(); boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE; diff -r 308c172cd230 rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Fri Jul 03 11:52:45 2009 +0100 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Fri Jul 03 18:28:13 2009 -0400 @@ -314,7 +314,6 @@ initialJars.add(jars[i]); // regardless of part tracker.addResource(jars[i].getLocation(), - file.getCookieStr(), jars[i].getVersion(), jars[i].isCacheable() ? JNLPRuntime.getDefaultUpdatePolicy() : UpdatePolicy.FORCE ); @@ -776,8 +775,7 @@ available.add(desc); - tracker.addResource(desc.getLocation(), - file.getCookieStr(), + tracker.addResource(desc.getLocation(), desc.getVersion(), JNLPRuntime.getDefaultUpdatePolicy() ); |
|
|
Re: RFC: Rewrite of cookie support in pluginHi,
Deepak Bhole wrote: > Oops. Original message is missing 2 new files from the patch. Sorry > about that. New patch attached. > > Deepak > > * Deepak Bhole <dbhole@...> [2009-07-03 17:48]: >> This patch rewrites cookie support in the plugin. The old way was >> static, set at initialization time. Additionally, it did not support >> cookie provision for connection requests made by the applet internally. >> >> This patch fixes all of that. Cookie information is now supplied to Java >> in real-time from Mozilla side, as it should be. >> >> Thanks to Omair for the initial error trace. >> >> This patch fixes rhbz 506730: >> https://bugzilla.redhat.com/show_bug.cgi?id=506730 >> >> http://www.sbm.no/ will now load correctly with this patch. >> >> ChangeLog: >> * IcedTeaPlugin.cc: Add suppport for cookie info requests from applets. >> * plugin/icedtea/sun/applet/PluginAppletViewer.java: Rework cookie support >> to make it dynamic. >> * plugin/icedtea/sun/applet/PluginMain.java: Wire in custom cookie store >> that dynamically requests cookie information from C++ side. >> * rt/net/sourceforge/jnlp/JNLPFile.java: Remove old cookie handling code. >> * rt/net/sourceforge/jnlp/Launcher.java: Same. >> * rt/net/sourceforge/jnlp/NetxPanel.java: Same. >> * rt/net/sourceforge/jnlp/PluginBridge.java: Same. >> * rt/net/sourceforge/jnlp/cache/CacheUtil.java: Same. >> * rt/net/sourceforge/jnlp/cache/Resource.java: Same. >> * rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Same. >> * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Same. >> >> Comments? >> >> Deepak > I am assuming that aside from the classes that manage cookies, nothing should be storing or passing them around. However, there are still many references to cookies. For example,net.sourceforge.jnlp.ExtensionDesc contains: public ExtensionDesc(String name, Version version, URL location, String cookieStr) Please remove all unused references to cookies. Thanks, Omair |
|
|
Re: RFC: Rewrite of cookie support in plugin* Omair Majid <omajid@...> [2009-07-07 15:48]:
> Hi, > > Deepak Bhole wrote: >> Oops. Original message is missing 2 new files from the patch. Sorry >> about that. New patch attached. >> >> Deepak >> >> * Deepak Bhole <dbhole@...> [2009-07-03 17:48]: >>> This patch rewrites cookie support in the plugin. The old way was >>> static, set at initialization time. Additionally, it did not support >>> cookie provision for connection requests made by the applet internally. >>> >>> This patch fixes all of that. Cookie information is now supplied to Java >>> in real-time from Mozilla side, as it should be. >>> >>> Thanks to Omair for the initial error trace. >>> >>> This patch fixes rhbz 506730: >>> https://bugzilla.redhat.com/show_bug.cgi?id=506730 >>> >>> http://www.sbm.no/ will now load correctly with this patch. >>> >>> ChangeLog: >>> * IcedTeaPlugin.cc: Add suppport for cookie info requests from applets. >>> * plugin/icedtea/sun/applet/PluginAppletViewer.java: Rework cookie support >>> to make it dynamic. >>> * plugin/icedtea/sun/applet/PluginMain.java: Wire in custom cookie store >>> that dynamically requests cookie information from C++ side. >>> * rt/net/sourceforge/jnlp/JNLPFile.java: Remove old cookie handling code. >>> * rt/net/sourceforge/jnlp/Launcher.java: Same. >>> * rt/net/sourceforge/jnlp/NetxPanel.java: Same. >>> * rt/net/sourceforge/jnlp/PluginBridge.java: Same. >>> * rt/net/sourceforge/jnlp/cache/CacheUtil.java: Same. >>> * rt/net/sourceforge/jnlp/cache/Resource.java: Same. >>> * rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Same. >>> * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Same. >>> >>> Comments? >>> >>> Deepak >> > > I am assuming that aside from the classes that manage cookies, nothing > should be storing or passing them around. However, there are still many > references to cookies. For example,net.sourceforge.jnlp.ExtensionDesc > contains: > public ExtensionDesc(String name, Version version, URL location, String > cookieStr) > > Please remove all unused references to cookies. > Cheers, Deepak diff -r b4bb02c70835 IcedTeaPlugin.cc --- a/IcedTeaPlugin.cc Tue Jul 07 13:44:35 2009 -0400 +++ b/IcedTeaPlugin.cc Tue Jul 07 16:17:17 2009 -0400 @@ -1012,6 +1012,7 @@ void ProcessMessage(); void ConsumeMsgFromJVM(); nsresult GetProxyInfo(const char* siteAddr, char** proxyScheme, char** proxyHost, char** proxyPort); + nsresult GetCookieInfo(const char* siteAddr, char** cookieString); nsCOMPtr<IcedTeaEventSink> sink; nsCOMPtr<nsISocketTransport> transport; nsCOMPtr<nsIProcess> applet_viewer_process; @@ -1070,7 +1071,6 @@ IcedTeaPluginFactory* factory; PRUint32 instance_identifier; nsCString instanceIdentifierPrefix; - nsresult GetCookie(const char* siteAddr, char** cookieString); }; @@ -2380,16 +2380,6 @@ encodedAppletTag += tagMessage.get()[i]; } - nsCString cookieInfo(instanceIdentifierPrefix); - cookieInfo += "cookie "; - - char* cookieString; - if (GetCookie(documentbase, &cookieString) == NS_OK) - { - cookieInfo += cookieString; - } - - factory->SendMessageToAppletViewer (cookieInfo); factory->SendMessageToAppletViewer (encodedAppletTag); // Set back-pointer to peer instance. @@ -2760,8 +2750,15 @@ return NS_OK; } -NS_IMETHODIMP -IcedTeaPluginInstance::GetCookie(const char* siteAddr, char** cookieString) +/** + * Returns the cookie information for the given url + * + * @param siteAddr The URI to check (must be decoded) + * @return cookieString The cookie string for the given URI + */ + +NS_IMETHODIMP +IcedTeaPluginFactory::GetCookieInfo(const char* siteAddr, char** cookieString) { nsresult rv; @@ -3497,6 +3494,35 @@ // free allocated memory delete proxyScheme, proxyHost, proxyPort; + + } else if (command == "PluginCookieInfo") + { + + nsresult rv; + nsCOMPtr<nsINetUtil> net_util = do_GetService(NS_NETUTIL_CONTRACTID, &rv); + + if (!net_util) + printf("Error instantiating NetUtil service.\n"); + + // decode the url + nsDependentCSubstring url; + net_util->UnescapeString(rest, 0, url); + + nsCString cookieInfo("plugin PluginCookieInfo "); + cookieInfo += rest; + cookieInfo += " "; + + char* cookieString; + if (GetCookieInfo(((nsCString) url).get(), &cookieString) == NS_OK) + { + cookieInfo += cookieString; + PLUGIN_DEBUG_2ARG("Cookie for %s is %s\n", ((nsCString) url).get(), cookieString); + } else { + PLUGIN_DEBUG_1ARG("No cookie found for %s\n", ((nsCString) url).get()); + } + + // send back what we found + SendMessageToAppletViewer (cookieInfo); } } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginAppletViewer.java --- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 16:17:17 2009 -0400 @@ -84,6 +84,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketPermission; @@ -180,9 +181,6 @@ private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - - private static HashMap<Integer, String> siteCookies = - new HashMap<Integer,String>(); private static HashMap<Integer, PAV_INIT_STATUS> status = new HashMap<Integer,PAV_INIT_STATUS>(); @@ -226,7 +224,7 @@ AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { - panel = new NetxPanel(doc, siteCookies.get(identifier), atts, false); + panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); } catch (Exception ex) { @@ -483,16 +481,6 @@ PluginDebug.debug ("REQUEST TAG NOT SET: " + request.tag + ". BYPASSING"); } } - } else if (message.startsWith("cookie")) { - - int cookieStrIndex = message.indexOf(" "); - String cookieStr = null; - - if (cookieStrIndex > 0) - cookieStr = message.substring(cookieStrIndex); - - // Always set the cookie -- even if it is null - siteCookies.put(identifier, cookieStr); } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); @@ -842,7 +830,6 @@ * applets on this page. */ public Enumeration getApplets() { - AppletSecurity security = (AppletSecurity)System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); @@ -896,7 +883,7 @@ // streamhandler.pluginOutputStream has been closed. } } - + public long getWindow() { PluginDebug.debug ("STARTING getWindow"); PluginCallRequest request = requestFactory.getPluginCallRequest("window", @@ -1113,6 +1100,40 @@ return request.getObject(); } + public static Object requestPluginCookieInfo(URI uri) { + + PluginCallRequest request; + try + { + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + request = requestFactory.getPluginCallRequest("cookieinfo", + "plugin PluginCookieInfo " + encodedURI, + "plugin PluginCookieInfo " + encodedURI); + + } catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + return null; + } + + streamhandler.postCallRequest(request); + streamhandler.write(request.getMessage()); + try { + PluginDebug.debug ("wait cookieinfo request 1"); + synchronized(request) { + PluginDebug.debug ("wait cookieinfo request 2"); + while (request.isDone() == false) + request.wait(); + PluginDebug.debug ("wait cookieinfo request 3"); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted waiting for cookieinfo request.", + e); + } + PluginDebug.debug (" Cookieinfo DONE"); + return request.getObject(); + } + public static Object requestPluginProxyInfo(URI uri) { String requestURI = null; @@ -1623,10 +1644,6 @@ public static void parse(int identifier, long handle, Reader in, URL url) throws IOException { - // wait until cookie is set (even if cookie is null, it needs to be - // "set" to that first - while (!siteCookies.containsKey(identifier)); - final int fIdentifier = identifier; final long fHandle = handle; final Reader fIn = in; diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCallRequestFactory.java --- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 16:17:17 2009 -0400 @@ -51,6 +51,8 @@ return new GetWindowPluginCallRequest(message, returnString); } else if (id == "proxyinfo") { return new PluginProxyInfoRequest(message, returnString); + } else if (id == "cookieinfo") { + return new PluginCookieInfoRequest(message, returnString); } else { throw new RuntimeException ("Unknown plugin call request type requested from factory"); } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCookieInfoRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieInfoRequest.java Tue Jul 07 16:17:17 2009 -0400 @@ -0,0 +1,122 @@ +/* PluginCookieInfoRequest -- Object representing a request for cookie information from the browser + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import com.sun.jndi.toolkit.url.UrlUtil; + +/** + * This class represents a request object for cookie information for a given URI + */ + +public class PluginCookieInfoRequest extends PluginCallRequest { + + List<HttpCookie> cookieObjects = new ArrayList<HttpCookie>(); + + public PluginCookieInfoRequest(String message, String returnString) { + super(message, returnString); + } + + public void parseReturn(String cookieInfo) { + + // try to parse the proxy information. If things go wrong, do nothing .. + // this will keep internal = null which forces a direct connection + + PluginDebug.debug ("PluginCookieInfoRequest GOT: " + cookieInfo); + + String encodedURI = cookieInfo.split(" ")[2]; + + // Skip the first 3 components. We are guaranteed 3 components, + // so no index -1 to worry about + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + + URI siteURI; + try + { + siteURI = new URI(UrlUtil.decode(encodedURI, "UTF-8")); + } catch (Exception e) + { + e.printStackTrace(); + return; + } + + if (cookieInfo != null && cookieInfo.length() > 0) + { + String[] cookies = cookieInfo.split(";"); + + for (int i = 0; i < cookies.length; i++) + { + ArrayList l = new ArrayList(); + + String cookie = cookies[i]; + cookie = cookie.trim(); + String cookieName = cookie.substring(0, cookie.indexOf("=")); + String cookieValue = cookie.substring(cookie.indexOf("=")+1); + + HttpCookie httpCookieObj = new HttpCookie(cookieName, cookieValue); + httpCookieObj.setPath(siteURI.getPath()); + httpCookieObj.setVersion(0); // force v0 + + PluginDebug.debug("Adding cookie info COOKIEN=" + cookieName + " and COOKIEV=" + cookieValue); + cookieObjects.add(httpCookieObj); + } + } + + setDone(true); + } + + /** + * Returns whether the given message is serviceable by this object + * + * @param message The message to service + * @return boolean indicating if message is serviceable + */ + public boolean serviceable(String message) { + return message.startsWith(returnString); + } + + public List<HttpCookie> getObject() { + return this.cookieObjects; + } +} diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCookieStore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieStore.java Tue Jul 07 16:17:17 2009 -0400 @@ -0,0 +1,73 @@ +/* PluginCookieStore -- Storage for cookie information + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.List; + +import sun.net.www.protocol.http.InMemoryCookieStore; + +public class PluginCookieStore extends InMemoryCookieStore +{ + public List<HttpCookie> get(URI uri) + { + List<HttpCookie> cookies; + + // Try to fetch it from the plugin, but if something goes + // wrong, fall back. Don't crash! + try + { + cookies = (List<HttpCookie>) PluginAppletViewer.requestPluginCookieInfo(uri); + + // If cookies is null, something went wrong. Fall back. + if (cookies == null) throw new NullPointerException("Null cookie"); + + } catch (Exception e) + { + PluginDebug.debug("Unable to fetch cookie information from plugin. " + + "Falling back to default."); + e.printStackTrace(); + cookies = super.get(uri); + } + + PluginDebug.debug("Returning cookies " + cookies + " for site: " + uri); + + return cookies; + } +} diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginMain.java --- a/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 16:17:17 2009 -0400 @@ -68,10 +68,11 @@ import java.io.IOException; import java.io.PrintStream; import java.net.Authenticator; +import java.net.CookieHandler; +import java.net.CookieManager; import java.net.PasswordAuthentication; import java.net.ProxySelector; import java.util.Enumeration; -import java.util.HashMap; import java.util.Properties; import javax.net.ssl.HttpsURLConnection; @@ -218,6 +219,9 @@ // plug in a custom authenticator and proxy selector Authenticator.setDefault(new CustomAuthenticator()); ProxySelector.setDefault(new PluginProxySelector()); + + CookieManager ckManager = new CookieManager(new PluginCookieStore(), null); + CookieHandler.setDefault(ckManager); } static boolean messageAvailable() { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/ExtensionDesc.java --- a/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 16:17:17 2009 -0400 @@ -40,9 +40,6 @@ /** the location of the extension JNLP file */ private URL location; - - /** the cookie string sent with resource requests */ - private String cookieStr; /** the JNLPFile the extension refers to */ private JNLPFile file; @@ -61,11 +58,10 @@ * @param version the required version of the extention JNLPFile * @param location the location of the extention JNLP file */ - public ExtensionDesc(String name, Version version, URL location, String cookieStr) { + public ExtensionDesc(String name, Version version, URL location) { this.name = name; this.version = version; this.location = location; - this.cookieStr = cookieStr; } /** @@ -125,7 +121,7 @@ */ public void resolve() throws ParseException, IOException { if (file == null) { - file = new JNLPFile(location, cookieStr); + file = new JNLPFile(location); if (JNLPRuntime.isDebug()) System.out.println("Resolve: "+file.getInformation().getTitle()); @@ -144,14 +140,6 @@ public JNLPFile getJNLPFile() { return file; } - - /** - * Returns the cookie associated with this instance - */ - public String getCookieStr() { - return cookieStr; - } - } diff -r b4bb02c70835 rt/net/sourceforge/jnlp/JNLPFile.java --- a/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 16:17:17 2009 -0400 @@ -69,9 +69,6 @@ /** the URL used to resolve relative URLs in the file */ protected URL codeBase; - - /** cookie string to send alongwith resource requests */ - protected String cookieStr; /** file version */ protected Version fileVersion; @@ -127,8 +124,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr) throws IOException, ParseException { - this(location, cookieStr, false); // not strict + public JNLPFile(URL location) throws IOException, ParseException { + this(location, false); // not strict } /** @@ -140,8 +137,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict) throws IOException, ParseException { - this(location, cookieStr, strict, JNLPRuntime.getDefaultUpdatePolicy()); + public JNLPFile(URL location, boolean strict) throws IOException, ParseException { + this(location, strict, JNLPRuntime.getDefaultUpdatePolicy()); } /** @@ -154,12 +151,11 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - Node root = Parser.getRootNode(openURL(location, cookieStr, policy)); + public JNLPFile(URL location, boolean strict, UpdatePolicy policy) throws IOException, ParseException { + Node root = Parser.getRootNode(openURL(location, policy)); parse(root, strict, location); this.fileLocation = location; - this.cookieStr = cookieStr; } /** @@ -190,13 +186,13 @@ * Open the jnlp file URL from the cache if there, otherwise * download to the cache. Called from constructor. */ - private static InputStream openURL(URL location, String cookieStr, UpdatePolicy policy) throws IOException { + private static InputStream openURL(URL location, UpdatePolicy policy) throws IOException { if (location == null || policy == null) throw new IllegalArgumentException(R("NullParameter")); try { ResourceTracker tracker = new ResourceTracker(false); // no prefetch - tracker.addResource(location, cookieStr, null/*version*/, policy); + tracker.addResource(location, null/*version*/, policy); return tracker.getInputStream(location); } @@ -255,13 +251,6 @@ */ public URL getCodeBase() { return codeBase; - } - - /** - * Returns the cookie string that will be send when resources for this file are requested - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Launcher.java --- a/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 16:17:17 2009 -0400 @@ -389,7 +389,7 @@ IconDesc.SPLASH, preferredWidth, preferredHeight); if (splashImageURL != null) { ResourceTracker resourceTracker = new ResourceTracker(true); - resourceTracker.addResource(splashImageURL, "SPLASH", file.getFileVersion(), updatePolicy); + resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy); splashScreen = new JNLPSplashScreen(resourceTracker, null, null); splashScreen.setSplashImageURL(splashImageURL); if (splashScreen.isSplashScreenValid()) { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/NetxPanel.java --- a/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 16:17:17 2009 -0400 @@ -41,7 +41,6 @@ private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; - private String cookieStr; private boolean appletAlive; public NetxPanel(URL documentURL, Hashtable atts) @@ -50,11 +49,10 @@ } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, String cookieStr, Hashtable atts, boolean exitOnFailure) + public NetxPanel(URL documentURL, Hashtable atts, boolean exitOnFailure) { this(documentURL, atts); this.exitOnFailure = exitOnFailure; - this.cookieStr = cookieStr; this.appletAlive = true; } @@ -64,7 +62,6 @@ try { bridge = new PluginBridge(baseURL, - cookieStr, getDocumentBase(), getJarFiles(), getCode(), diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Parser.java --- a/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 16:17:17 2009 -0400 @@ -336,10 +336,10 @@ Node dload[] = getChildNodes(node, "ext-download"); for (int i=0; i < dload.length; i++) { - boolean lazy = "lazy".equals(getAttribute(dload[i], "download", "eager")); + boolean lazy = "lazy".equals(getAttribute(node, "download", "eager")); - ext.addPart(getRequiredAttribute(dload[i], "ext-part", null), - getAttribute(dload[i], "part", null), + ext.addPart(getRequiredAttribute(node, "ext-part", null), + getAttribute(node, "part", null), lazy); } diff -r b4bb02c70835 rt/net/sourceforge/jnlp/PluginBridge.java --- a/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 16:17:17 2009 -0400 @@ -43,7 +43,7 @@ String[] cache_ex_jars = new String[0]; Hashtable atts; - public PluginBridge(URL codebase, String cookieStr, URL documentBase, String jar, String main, + public PluginBridge(URL codebase, URL documentBase, String jar, String main, int width, int height, Hashtable atts) throws Exception { @@ -104,7 +104,6 @@ else security = null; - this.cookieStr = cookieStr; } public String getTitle() diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/CacheUtil.java --- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 16:17:17 2009 -0400 @@ -75,9 +75,9 @@ * @param version the version, or null * @return either the location in the cache or the original location */ - public static URL getCachedResource(URL location, String cookieStr, Version version, UpdatePolicy policy) { + public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) { ResourceTracker rt = new ResourceTracker(); - rt.addResource(location, cookieStr, version, policy); + rt.addResource(location, version, policy); try { File f = rt.getCacheFile(location); return f.toURL(); diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/Resource.java --- a/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 16:17:17 2009 -0400 @@ -68,9 +68,6 @@ /** the remote location of the resource */ URL location; - /** cookie string to send with the resource request */ - String cookieStr; - /** the local file downloaded to */ File localFile; @@ -98,20 +95,19 @@ /** * Create a resource. */ - private Resource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + private Resource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { this.location = location; this.requestVersion = requestVersion; this.updatePolicy = updatePolicy; - this.cookieStr = cookieStr; } /** * Return a shared Resource object representing the given * location and version. */ - public static Resource getResource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + public static Resource getResource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { synchronized (resources) { - Resource resource = new Resource(location, cookieStr, updatePolicy, requestVersion); + Resource resource = new Resource(location, updatePolicy, requestVersion); int index = resources.indexOf(resource); if (index >= 0) { // return existing object @@ -132,13 +128,6 @@ */ public URL getLocation() { return location; - } - - /** - * Returns the cookie string associated with this resource - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/ResourceTracker.java --- a/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 16:17:17 2009 -0400 @@ -148,11 +148,11 @@ * @param version the resource version * @param updatePolicy whether to check for updates if already in cache */ - public void addResource(URL location, String cookieStr, Version version, UpdatePolicy updatePolicy) { + public void addResource(URL location, Version version, UpdatePolicy updatePolicy) { if (location == null) throw new IllegalArgumentException("location==null"); - Resource resource = Resource.getResource(location, cookieStr, updatePolicy, version); + Resource resource = Resource.getResource(location, updatePolicy, version); boolean downloaded = false; synchronized (resources) { @@ -606,9 +606,6 @@ try { // create out second in case in does not exist URLConnection con = getVersionedResourceURL(resource).openConnection(); - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - con.setRequestProperty("Cookie", resource.getCookieStr()); InputStream in = new BufferedInputStream(con.getInputStream()); OutputStream out = CacheUtil.getOutputStream(resource.location, resource.downloadVersion); @@ -657,9 +654,6 @@ // connect URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - connection.setRequestProperty("Cookie", resource.getCookieStr()); int size = connection.getContentLength(); boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE; diff -r b4bb02c70835 rt/net/sourceforge/jnlp/resources/Messages.properties --- a/rt/net/sourceforge/jnlp/resources/Messages.properties Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/resources/Messages.properties Tue Jul 07 16:17:17 2009 -0400 @@ -111,7 +111,6 @@ RDenyStopped=Stopped applications have no permissions. RExitNoApp=Can not exit the JVM because the current application cannot be determined. RNoLockDir=Unable to create locks directory ({0}) -RNestedJarExtration=Unable to extract nested jar. RUnexpected=Unexpected {0} at {1} # Boot options, message should be shorter than this ----------------> diff -r b4bb02c70835 rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 16:17:17 2009 -0400 @@ -234,11 +234,11 @@ * @param location the file's location * @param policy the update policy to use when downloading resources */ - public static JNLPClassLoader getInstance(URL location, String cookieStr, UpdatePolicy policy) throws IOException, ParseException, LaunchException { + public static JNLPClassLoader getInstance(URL location, UpdatePolicy policy) throws IOException, ParseException, LaunchException { JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(location); if (loader == null) - loader = getInstance(new JNLPFile(location, cookieStr, false, policy), policy); + loader = getInstance(new JNLPFile(location, false, policy), policy); return loader; } @@ -256,7 +256,7 @@ //if (ext != null) { for (int i=0; i < ext.length; i++) { try { - JNLPClassLoader loader = getInstance(ext[i].getLocation(), ext[i].getCookieStr(), updatePolicy); + JNLPClassLoader loader = getInstance(ext[i].getLocation(), updatePolicy); loaderList.add(loader); } catch (Exception ex) { @@ -314,7 +314,6 @@ initialJars.add(jars[i]); // regardless of part tracker.addResource(jars[i].getLocation(), - file.getCookieStr(), jars[i].getVersion(), jars[i].isCacheable() ? JNLPRuntime.getDefaultUpdatePolicy() : UpdatePolicy.FORCE ); @@ -521,10 +520,6 @@ // with standard classloader methods) String extractedJarLocation = localFile.getParent() + "/" + je.getName(); - File parentDir = new File(extractedJarLocation).getParentFile(); - if (!parentDir.isDirectory() && !parentDir.mkdirs()) { - throw new RuntimeException(R("RNestedJarExtration")); - } FileOutputStream extractedJar = new FileOutputStream(extractedJarLocation); InputStream is = jarFile.getInputStream(je); @@ -780,8 +775,7 @@ available.add(desc); - tracker.addResource(desc.getLocation(), - file.getCookieStr(), + tracker.addResource(desc.getLocation(), desc.getVersion(), JNLPRuntime.getDefaultUpdatePolicy() ); |
|
|
Re: RFC: Rewrite of cookie support in plugin* Deepak Bhole <dbhole@...> [2009-07-07 16:25]:
> * Omair Majid <omajid@...> [2009-07-07 15:48]: > > Hi, > > > > Deepak Bhole wrote: > >> Oops. Original message is missing 2 new files from the patch. Sorry > >> about that. New patch attached. > >> > >> Deepak > >> > >> * Deepak Bhole <dbhole@...> [2009-07-03 17:48]: > >>> This patch rewrites cookie support in the plugin. The old way was > >>> static, set at initialization time. Additionally, it did not support > >>> cookie provision for connection requests made by the applet internally. > >>> > >>> This patch fixes all of that. Cookie information is now supplied to Java > >>> in real-time from Mozilla side, as it should be. > >>> > >>> Thanks to Omair for the initial error trace. > >>> > >>> This patch fixes rhbz 506730: > >>> https://bugzilla.redhat.com/show_bug.cgi?id=506730 > >>> > >>> http://www.sbm.no/ will now load correctly with this patch. > >>> > >>> ChangeLog: > >>> * IcedTeaPlugin.cc: Add suppport for cookie info requests from applets. > >>> * plugin/icedtea/sun/applet/PluginAppletViewer.java: Rework cookie support > >>> to make it dynamic. > >>> * plugin/icedtea/sun/applet/PluginMain.java: Wire in custom cookie store > >>> that dynamically requests cookie information from C++ side. > >>> * rt/net/sourceforge/jnlp/JNLPFile.java: Remove old cookie handling code. > >>> * rt/net/sourceforge/jnlp/Launcher.java: Same. > >>> * rt/net/sourceforge/jnlp/NetxPanel.java: Same. > >>> * rt/net/sourceforge/jnlp/PluginBridge.java: Same. > >>> * rt/net/sourceforge/jnlp/cache/CacheUtil.java: Same. > >>> * rt/net/sourceforge/jnlp/cache/Resource.java: Same. > >>> * rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Same. > >>> * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Same. > >>> > >>> Comments? > >>> > >>> Deepak > >> > > > > I am assuming that aside from the classes that manage cookies, nothing > > should be storing or passing them around. However, there are still many > > references to cookies. For example,net.sourceforge.jnlp.ExtensionDesc > > contains: > > public ExtensionDesc(String name, Version version, URL location, String > > cookieStr) > > > > Please remove all unused references to cookies. > > > > Good catch! New patch attached. > first place when I tested it :/). Anyways, THIS one should work. The previous one was missing a change to the JNLPFile constructor call in Boot.java Deepak diff -r b4bb02c70835 IcedTeaPlugin.cc --- a/IcedTeaPlugin.cc Tue Jul 07 13:44:35 2009 -0400 +++ b/IcedTeaPlugin.cc Tue Jul 07 16:35:59 2009 -0400 @@ -1012,6 +1012,7 @@ void ProcessMessage(); void ConsumeMsgFromJVM(); nsresult GetProxyInfo(const char* siteAddr, char** proxyScheme, char** proxyHost, char** proxyPort); + nsresult GetCookieInfo(const char* siteAddr, char** cookieString); nsCOMPtr<IcedTeaEventSink> sink; nsCOMPtr<nsISocketTransport> transport; nsCOMPtr<nsIProcess> applet_viewer_process; @@ -1070,7 +1071,6 @@ IcedTeaPluginFactory* factory; PRUint32 instance_identifier; nsCString instanceIdentifierPrefix; - nsresult GetCookie(const char* siteAddr, char** cookieString); }; @@ -2380,16 +2380,6 @@ encodedAppletTag += tagMessage.get()[i]; } - nsCString cookieInfo(instanceIdentifierPrefix); - cookieInfo += "cookie "; - - char* cookieString; - if (GetCookie(documentbase, &cookieString) == NS_OK) - { - cookieInfo += cookieString; - } - - factory->SendMessageToAppletViewer (cookieInfo); factory->SendMessageToAppletViewer (encodedAppletTag); // Set back-pointer to peer instance. @@ -2760,8 +2750,15 @@ return NS_OK; } -NS_IMETHODIMP -IcedTeaPluginInstance::GetCookie(const char* siteAddr, char** cookieString) +/** + * Returns the cookie information for the given url + * + * @param siteAddr The URI to check (must be decoded) + * @return cookieString The cookie string for the given URI + */ + +NS_IMETHODIMP +IcedTeaPluginFactory::GetCookieInfo(const char* siteAddr, char** cookieString) { nsresult rv; @@ -3497,6 +3494,35 @@ // free allocated memory delete proxyScheme, proxyHost, proxyPort; + + } else if (command == "PluginCookieInfo") + { + + nsresult rv; + nsCOMPtr<nsINetUtil> net_util = do_GetService(NS_NETUTIL_CONTRACTID, &rv); + + if (!net_util) + printf("Error instantiating NetUtil service.\n"); + + // decode the url + nsDependentCSubstring url; + net_util->UnescapeString(rest, 0, url); + + nsCString cookieInfo("plugin PluginCookieInfo "); + cookieInfo += rest; + cookieInfo += " "; + + char* cookieString; + if (GetCookieInfo(((nsCString) url).get(), &cookieString) == NS_OK) + { + cookieInfo += cookieString; + PLUGIN_DEBUG_2ARG("Cookie for %s is %s\n", ((nsCString) url).get(), cookieString); + } else { + PLUGIN_DEBUG_1ARG("No cookie found for %s\n", ((nsCString) url).get()); + } + + // send back what we found + SendMessageToAppletViewer (cookieInfo); } } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginAppletViewer.java --- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 16:35:59 2009 -0400 @@ -84,6 +84,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketPermission; @@ -180,9 +181,6 @@ private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - - private static HashMap<Integer, String> siteCookies = - new HashMap<Integer,String>(); private static HashMap<Integer, PAV_INIT_STATUS> status = new HashMap<Integer,PAV_INIT_STATUS>(); @@ -226,7 +224,7 @@ AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { - panel = new NetxPanel(doc, siteCookies.get(identifier), atts, false); + panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); } catch (Exception ex) { @@ -483,16 +481,6 @@ PluginDebug.debug ("REQUEST TAG NOT SET: " + request.tag + ". BYPASSING"); } } - } else if (message.startsWith("cookie")) { - - int cookieStrIndex = message.indexOf(" "); - String cookieStr = null; - - if (cookieStrIndex > 0) - cookieStr = message.substring(cookieStrIndex); - - // Always set the cookie -- even if it is null - siteCookies.put(identifier, cookieStr); } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); @@ -842,7 +830,6 @@ * applets on this page. */ public Enumeration getApplets() { - AppletSecurity security = (AppletSecurity)System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); @@ -896,7 +883,7 @@ // streamhandler.pluginOutputStream has been closed. } } - + public long getWindow() { PluginDebug.debug ("STARTING getWindow"); PluginCallRequest request = requestFactory.getPluginCallRequest("window", @@ -1113,6 +1100,40 @@ return request.getObject(); } + public static Object requestPluginCookieInfo(URI uri) { + + PluginCallRequest request; + try + { + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + request = requestFactory.getPluginCallRequest("cookieinfo", + "plugin PluginCookieInfo " + encodedURI, + "plugin PluginCookieInfo " + encodedURI); + + } catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + return null; + } + + streamhandler.postCallRequest(request); + streamhandler.write(request.getMessage()); + try { + PluginDebug.debug ("wait cookieinfo request 1"); + synchronized(request) { + PluginDebug.debug ("wait cookieinfo request 2"); + while (request.isDone() == false) + request.wait(); + PluginDebug.debug ("wait cookieinfo request 3"); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted waiting for cookieinfo request.", + e); + } + PluginDebug.debug (" Cookieinfo DONE"); + return request.getObject(); + } + public static Object requestPluginProxyInfo(URI uri) { String requestURI = null; @@ -1623,10 +1644,6 @@ public static void parse(int identifier, long handle, Reader in, URL url) throws IOException { - // wait until cookie is set (even if cookie is null, it needs to be - // "set" to that first - while (!siteCookies.containsKey(identifier)); - final int fIdentifier = identifier; final long fHandle = handle; final Reader fIn = in; diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCallRequestFactory.java --- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 16:35:59 2009 -0400 @@ -51,6 +51,8 @@ return new GetWindowPluginCallRequest(message, returnString); } else if (id == "proxyinfo") { return new PluginProxyInfoRequest(message, returnString); + } else if (id == "cookieinfo") { + return new PluginCookieInfoRequest(message, returnString); } else { throw new RuntimeException ("Unknown plugin call request type requested from factory"); } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCookieInfoRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieInfoRequest.java Tue Jul 07 16:35:59 2009 -0400 @@ -0,0 +1,122 @@ +/* PluginCookieInfoRequest -- Object representing a request for cookie information from the browser + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import com.sun.jndi.toolkit.url.UrlUtil; + +/** + * This class represents a request object for cookie information for a given URI + */ + +public class PluginCookieInfoRequest extends PluginCallRequest { + + List<HttpCookie> cookieObjects = new ArrayList<HttpCookie>(); + + public PluginCookieInfoRequest(String message, String returnString) { + super(message, returnString); + } + + public void parseReturn(String cookieInfo) { + + // try to parse the proxy information. If things go wrong, do nothing .. + // this will keep internal = null which forces a direct connection + + PluginDebug.debug ("PluginCookieInfoRequest GOT: " + cookieInfo); + + String encodedURI = cookieInfo.split(" ")[2]; + + // Skip the first 3 components. We are guaranteed 3 components, + // so no index -1 to worry about + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + cookieInfo = cookieInfo.substring(cookieInfo.indexOf(' ')+1); + + URI siteURI; + try + { + siteURI = new URI(UrlUtil.decode(encodedURI, "UTF-8")); + } catch (Exception e) + { + e.printStackTrace(); + return; + } + + if (cookieInfo != null && cookieInfo.length() > 0) + { + String[] cookies = cookieInfo.split(";"); + + for (int i = 0; i < cookies.length; i++) + { + ArrayList l = new ArrayList(); + + String cookie = cookies[i]; + cookie = cookie.trim(); + String cookieName = cookie.substring(0, cookie.indexOf("=")); + String cookieValue = cookie.substring(cookie.indexOf("=")+1); + + HttpCookie httpCookieObj = new HttpCookie(cookieName, cookieValue); + httpCookieObj.setPath(siteURI.getPath()); + httpCookieObj.setVersion(0); // force v0 + + PluginDebug.debug("Adding cookie info COOKIEN=" + cookieName + " and COOKIEV=" + cookieValue); + cookieObjects.add(httpCookieObj); + } + } + + setDone(true); + } + + /** + * Returns whether the given message is serviceable by this object + * + * @param message The message to service + * @return boolean indicating if message is serviceable + */ + public boolean serviceable(String message) { + return message.startsWith(returnString); + } + + public List<HttpCookie> getObject() { + return this.cookieObjects; + } +} diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCookieStore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/icedtea/sun/applet/PluginCookieStore.java Tue Jul 07 16:35:59 2009 -0400 @@ -0,0 +1,73 @@ +/* PluginCookieStore -- Storage for cookie information + Copyright (C) 2009 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package sun.applet; + +import java.net.HttpCookie; +import java.net.URI; +import java.util.List; + +import sun.net.www.protocol.http.InMemoryCookieStore; + +public class PluginCookieStore extends InMemoryCookieStore +{ + public List<HttpCookie> get(URI uri) + { + List<HttpCookie> cookies; + + // Try to fetch it from the plugin, but if something goes + // wrong, fall back. Don't crash! + try + { + cookies = (List<HttpCookie>) PluginAppletViewer.requestPluginCookieInfo(uri); + + // If cookies is null, something went wrong. Fall back. + if (cookies == null) throw new NullPointerException("Null cookie"); + + } catch (Exception e) + { + PluginDebug.debug("Unable to fetch cookie information from plugin. " + + "Falling back to default."); + e.printStackTrace(); + cookies = super.get(uri); + } + + PluginDebug.debug("Returning cookies " + cookies + " for site: " + uri); + + return cookies; + } +} diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginMain.java --- a/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 16:35:59 2009 -0400 @@ -68,10 +68,11 @@ import java.io.IOException; import java.io.PrintStream; import java.net.Authenticator; +import java.net.CookieHandler; +import java.net.CookieManager; import java.net.PasswordAuthentication; import java.net.ProxySelector; import java.util.Enumeration; -import java.util.HashMap; import java.util.Properties; import javax.net.ssl.HttpsURLConnection; @@ -218,6 +219,9 @@ // plug in a custom authenticator and proxy selector Authenticator.setDefault(new CustomAuthenticator()); ProxySelector.setDefault(new PluginProxySelector()); + + CookieManager ckManager = new CookieManager(new PluginCookieStore(), null); + CookieHandler.setDefault(ckManager); } static boolean messageAvailable() { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/ExtensionDesc.java --- a/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 16:35:59 2009 -0400 @@ -40,9 +40,6 @@ /** the location of the extension JNLP file */ private URL location; - - /** the cookie string sent with resource requests */ - private String cookieStr; /** the JNLPFile the extension refers to */ private JNLPFile file; @@ -61,11 +58,10 @@ * @param version the required version of the extention JNLPFile * @param location the location of the extention JNLP file */ - public ExtensionDesc(String name, Version version, URL location, String cookieStr) { + public ExtensionDesc(String name, Version version, URL location) { this.name = name; this.version = version; this.location = location; - this.cookieStr = cookieStr; } /** @@ -125,7 +121,7 @@ */ public void resolve() throws ParseException, IOException { if (file == null) { - file = new JNLPFile(location, cookieStr); + file = new JNLPFile(location); if (JNLPRuntime.isDebug()) System.out.println("Resolve: "+file.getInformation().getTitle()); @@ -144,14 +140,6 @@ public JNLPFile getJNLPFile() { return file; } - - /** - * Returns the cookie associated with this instance - */ - public String getCookieStr() { - return cookieStr; - } - } diff -r b4bb02c70835 rt/net/sourceforge/jnlp/JNLPFile.java --- a/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 16:35:59 2009 -0400 @@ -69,9 +69,6 @@ /** the URL used to resolve relative URLs in the file */ protected URL codeBase; - - /** cookie string to send alongwith resource requests */ - protected String cookieStr; /** file version */ protected Version fileVersion; @@ -127,8 +124,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr) throws IOException, ParseException { - this(location, cookieStr, false); // not strict + public JNLPFile(URL location) throws IOException, ParseException { + this(location, false); // not strict } /** @@ -140,8 +137,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict) throws IOException, ParseException { - this(location, cookieStr, strict, JNLPRuntime.getDefaultUpdatePolicy()); + public JNLPFile(URL location, boolean strict) throws IOException, ParseException { + this(location, strict, JNLPRuntime.getDefaultUpdatePolicy()); } /** @@ -154,12 +151,11 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - Node root = Parser.getRootNode(openURL(location, cookieStr, policy)); + public JNLPFile(URL location, boolean strict, UpdatePolicy policy) throws IOException, ParseException { + Node root = Parser.getRootNode(openURL(location, policy)); parse(root, strict, location); this.fileLocation = location; - this.cookieStr = cookieStr; } /** @@ -190,13 +186,13 @@ * Open the jnlp file URL from the cache if there, otherwise * download to the cache. Called from constructor. */ - private static InputStream openURL(URL location, String cookieStr, UpdatePolicy policy) throws IOException { + private static InputStream openURL(URL location, UpdatePolicy policy) throws IOException { if (location == null || policy == null) throw new IllegalArgumentException(R("NullParameter")); try { ResourceTracker tracker = new ResourceTracker(false); // no prefetch - tracker.addResource(location, cookieStr, null/*version*/, policy); + tracker.addResource(location, null/*version*/, policy); return tracker.getInputStream(location); } @@ -255,13 +251,6 @@ */ public URL getCodeBase() { return codeBase; - } - - /** - * Returns the cookie string that will be send when resources for this file are requested - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Launcher.java --- a/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 16:35:59 2009 -0400 @@ -389,7 +389,7 @@ IconDesc.SPLASH, preferredWidth, preferredHeight); if (splashImageURL != null) { ResourceTracker resourceTracker = new ResourceTracker(true); - resourceTracker.addResource(splashImageURL, "SPLASH", file.getFileVersion(), updatePolicy); + resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy); splashScreen = new JNLPSplashScreen(resourceTracker, null, null); splashScreen.setSplashImageURL(splashImageURL); if (splashScreen.isSplashScreenValid()) { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/NetxPanel.java --- a/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 16:35:59 2009 -0400 @@ -41,7 +41,6 @@ private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; - private String cookieStr; private boolean appletAlive; public NetxPanel(URL documentURL, Hashtable atts) @@ -50,11 +49,10 @@ } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, String cookieStr, Hashtable atts, boolean exitOnFailure) + public NetxPanel(URL documentURL, Hashtable atts, boolean exitOnFailure) { this(documentURL, atts); this.exitOnFailure = exitOnFailure; - this.cookieStr = cookieStr; this.appletAlive = true; } @@ -64,7 +62,6 @@ try { bridge = new PluginBridge(baseURL, - cookieStr, getDocumentBase(), getJarFiles(), getCode(), diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Parser.java --- a/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 16:35:59 2009 -0400 @@ -336,10 +336,10 @@ Node dload[] = getChildNodes(node, "ext-download"); for (int i=0; i < dload.length; i++) { - boolean lazy = "lazy".equals(getAttribute(dload[i], "download", "eager")); + boolean lazy = "lazy".equals(getAttribute(node, "download", "eager")); - ext.addPart(getRequiredAttribute(dload[i], "ext-part", null), - getAttribute(dload[i], "part", null), + ext.addPart(getRequiredAttribute(node, "ext-part", null), + getAttribute(node, "part", null), lazy); } diff -r b4bb02c70835 rt/net/sourceforge/jnlp/PluginBridge.java --- a/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 16:35:59 2009 -0400 @@ -43,7 +43,7 @@ String[] cache_ex_jars = new String[0]; Hashtable atts; - public PluginBridge(URL codebase, String cookieStr, URL documentBase, String jar, String main, + public PluginBridge(URL codebase, URL documentBase, String jar, String main, int width, int height, Hashtable atts) throws Exception { @@ -104,7 +104,6 @@ else security = null; - this.cookieStr = cookieStr; } public String getTitle() diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/CacheUtil.java --- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 16:35:59 2009 -0400 @@ -75,9 +75,9 @@ * @param version the version, or null * @return either the location in the cache or the original location */ - public static URL getCachedResource(URL location, String cookieStr, Version version, UpdatePolicy policy) { + public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) { ResourceTracker rt = new ResourceTracker(); - rt.addResource(location, cookieStr, version, policy); + rt.addResource(location, version, policy); try { File f = rt.getCacheFile(location); return f.toURL(); diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/Resource.java --- a/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 16:35:59 2009 -0400 @@ -68,9 +68,6 @@ /** the remote location of the resource */ URL location; - /** cookie string to send with the resource request */ - String cookieStr; - /** the local file downloaded to */ File localFile; @@ -98,20 +95,19 @@ /** * Create a resource. */ - private Resource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + private Resource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { this.location = location; this.requestVersion = requestVersion; this.updatePolicy = updatePolicy; - this.cookieStr = cookieStr; } /** * Return a shared Resource object representing the given * location and version. */ - public static Resource getResource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + public static Resource getResource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { synchronized (resources) { - Resource resource = new Resource(location, cookieStr, updatePolicy, requestVersion); + Resource resource = new Resource(location, updatePolicy, requestVersion); int index = resources.indexOf(resource); if (index >= 0) { // return existing object @@ -132,13 +128,6 @@ */ public URL getLocation() { return location; - } - - /** - * Returns the cookie string associated with this resource - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/ResourceTracker.java --- a/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 16:35:59 2009 -0400 @@ -148,11 +148,11 @@ * @param version the resource version * @param updatePolicy whether to check for updates if already in cache */ - public void addResource(URL location, String cookieStr, Version version, UpdatePolicy updatePolicy) { + public void addResource(URL location, Version version, UpdatePolicy updatePolicy) { if (location == null) throw new IllegalArgumentException("location==null"); - Resource resource = Resource.getResource(location, cookieStr, updatePolicy, version); + Resource resource = Resource.getResource(location, updatePolicy, version); boolean downloaded = false; synchronized (resources) { @@ -606,9 +606,6 @@ try { // create out second in case in does not exist URLConnection con = getVersionedResourceURL(resource).openConnection(); - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - con.setRequestProperty("Cookie", resource.getCookieStr()); InputStream in = new BufferedInputStream(con.getInputStream()); OutputStream out = CacheUtil.getOutputStream(resource.location, resource.downloadVersion); @@ -657,9 +654,6 @@ // connect URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - connection.setRequestProperty("Cookie", resource.getCookieStr()); int size = connection.getContentLength(); boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE; diff -r b4bb02c70835 rt/net/sourceforge/jnlp/resources/Messages.properties --- a/rt/net/sourceforge/jnlp/resources/Messages.properties Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/resources/Messages.properties Tue Jul 07 16:35:59 2009 -0400 @@ -111,7 +111,6 @@ RDenyStopped=Stopped applications have no permissions. RExitNoApp=Can not exit the JVM because the current application cannot be determined. RNoLockDir=Unable to create locks directory ({0}) -RNestedJarExtration=Unable to extract nested jar. RUnexpected=Unexpected {0} at {1} # Boot options, message should be shorter than this ----------------> diff -r b4bb02c70835 rt/net/sourceforge/jnlp/runtime/Boot.java --- a/rt/net/sourceforge/jnlp/runtime/Boot.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/runtime/Boot.java Tue Jul 07 16:35:59 2009 -0400 @@ -276,7 +276,7 @@ boolean strict = (null != getOption("-strict")); - JNLPFile file = new JNLPFile(url, null, strict); + JNLPFile file = new JNLPFile(url, strict); // add in extra params from command line addProperties(file); diff -r b4bb02c70835 rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 16:35:59 2009 -0400 @@ -234,11 +234,11 @@ * @param location the file's location * @param policy the update policy to use when downloading resources */ - public static JNLPClassLoader getInstance(URL location, String cookieStr, UpdatePolicy policy) throws IOException, ParseException, LaunchException { + public static JNLPClassLoader getInstance(URL location, UpdatePolicy policy) throws IOException, ParseException, LaunchException { JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(location); if (loader == null) - loader = getInstance(new JNLPFile(location, cookieStr, false, policy), policy); + loader = getInstance(new JNLPFile(location, false, policy), policy); return loader; } @@ -256,7 +256,7 @@ //if (ext != null) { for (int i=0; i < ext.length; i++) { try { - JNLPClassLoader loader = getInstance(ext[i].getLocation(), ext[i].getCookieStr(), updatePolicy); + JNLPClassLoader loader = getInstance(ext[i].getLocation(), updatePolicy); loaderList.add(loader); } catch (Exception ex) { @@ -314,7 +314,6 @@ initialJars.add(jars[i]); // regardless of part tracker.addResource(jars[i].getLocation(), - file.getCookieStr(), jars[i].getVersion(), jars[i].isCacheable() ? JNLPRuntime.getDefaultUpdatePolicy() : UpdatePolicy.FORCE ); @@ -521,10 +520,6 @@ // with standard classloader methods) String extractedJarLocation = localFile.getParent() + "/" + je.getName(); - File parentDir = new File(extractedJarLocation).getParentFile(); - if (!parentDir.isDirectory() && !parentDir.mkdirs()) { - throw new RuntimeException(R("RNestedJarExtration")); - } FileOutputStream extractedJar = new FileOutputStream(extractedJarLocation); InputStream is = jarFile.getInputStream(je); @@ -780,8 +775,7 @@ available.add(desc); - tracker.addResource(desc.getLocation(), - file.getCookieStr(), + tracker.addResource(desc.getLocation(), desc.getVersion(), JNLPRuntime.getDefaultUpdatePolicy() ); |
|
|
Re: RFC: Rewrite of cookie support in plugin* Deepak Bhole <dbhole@...> [2009-07-07 16:37]:
> * Deepak Bhole <dbhole@...> [2009-07-07 16:25]: > > * Omair Majid <omajid@...> [2009-07-07 15:48]: > > > Hi, > > > > > > Deepak Bhole wrote: > > >> Oops. Original message is missing 2 new files from the patch. Sorry > > >> about that. New patch attached. > > >> Patch has been approved by Omair. Posting final version for reference. Deepak diff -r b4bb02c70835 IcedTeaPlugin.cc --- a/IcedTeaPlugin.cc Tue Jul 07 13:44:35 2009 -0400 +++ b/IcedTeaPlugin.cc Tue Jul 07 17:17:32 2009 -0400 @@ -1012,6 +1012,7 @@ void ProcessMessage(); void ConsumeMsgFromJVM(); nsresult GetProxyInfo(const char* siteAddr, char** proxyScheme, char** proxyHost, char** proxyPort); + nsresult GetCookieInfo(const char* siteAddr, char** cookieString); nsCOMPtr<IcedTeaEventSink> sink; nsCOMPtr<nsISocketTransport> transport; nsCOMPtr<nsIProcess> applet_viewer_process; @@ -1070,7 +1071,6 @@ IcedTeaPluginFactory* factory; PRUint32 instance_identifier; nsCString instanceIdentifierPrefix; - nsresult GetCookie(const char* siteAddr, char** cookieString); }; @@ -2380,16 +2380,6 @@ encodedAppletTag += tagMessage.get()[i]; } - nsCString cookieInfo(instanceIdentifierPrefix); - cookieInfo += "cookie "; - - char* cookieString; - if (GetCookie(documentbase, &cookieString) == NS_OK) - { - cookieInfo += cookieString; - } - - factory->SendMessageToAppletViewer (cookieInfo); factory->SendMessageToAppletViewer (encodedAppletTag); // Set back-pointer to peer instance. @@ -2760,8 +2750,15 @@ return NS_OK; } -NS_IMETHODIMP -IcedTeaPluginInstance::GetCookie(const char* siteAddr, char** cookieString) +/** + * Returns the cookie information for the given url + * + * @param siteAddr The URI to check (must be decoded) + * @return cookieString The cookie string for the given URI + */ + +NS_IMETHODIMP +IcedTeaPluginFactory::GetCookieInfo(const char* siteAddr, char** cookieString) { nsresult rv; @@ -3497,6 +3494,35 @@ // free allocated memory delete proxyScheme, proxyHost, proxyPort; + + } else if (command == "PluginCookieInfo") + { + + nsresult rv; + nsCOMPtr<nsINetUtil> net_util = do_GetService(NS_NETUTIL_CONTRACTID, &rv); + + if (!net_util) + printf("Error instantiating NetUtil service.\n"); + + // decode the url + nsDependentCSubstring url; + net_util->UnescapeString(rest, 0, url); + + nsCString cookieInfo("plugin PluginCookieInfo "); + cookieInfo += rest; + cookieInfo += " "; + + char* cookieString; + if (GetCookieInfo(((nsCString) url).get(), &cookieString) == NS_OK) + { + cookieInfo += cookieString; + PLUGIN_DEBUG_2ARG("Cookie for %s is %s\n", ((nsCString) url).get(), cookieString); + } else { + PLUGIN_DEBUG_1ARG("No cookie found for %s\n", ((nsCString) url).get()); + } + + // send back what we found + SendMessageToAppletViewer (cookieInfo); } } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginAppletViewer.java --- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Tue Jul 07 17:17:32 2009 -0400 @@ -84,6 +84,7 @@ import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketPermission; @@ -180,9 +181,6 @@ private static PluginStreamHandler streamhandler; private static PluginCallRequestFactory requestFactory; - - private static HashMap<Integer, String> siteCookies = - new HashMap<Integer,String>(); private static HashMap<Integer, PAV_INIT_STATUS> status = new HashMap<Integer,PAV_INIT_STATUS>(); @@ -226,7 +224,7 @@ AccessController.doPrivileged(new PrivilegedAction() { public Object run() { try { - panel = new NetxPanel(doc, siteCookies.get(identifier), atts, false); + panel = new NetxPanel(doc, atts, false); AppletViewerPanel.debug("Using NetX panel"); PluginDebug.debug(atts.toString()); } catch (Exception ex) { @@ -483,16 +481,6 @@ PluginDebug.debug ("REQUEST TAG NOT SET: " + request.tag + ". BYPASSING"); } } - } else if (message.startsWith("cookie")) { - - int cookieStrIndex = message.indexOf(" "); - String cookieStr = null; - - if (cookieStrIndex > 0) - cookieStr = message.substring(cookieStrIndex); - - // Always set the cookie -- even if it is null - siteCookies.put(identifier, cookieStr); } else { PluginDebug.debug ("Handling message: " + message + " instance " + identifier + " " + Thread.currentThread()); @@ -842,7 +830,6 @@ * applets on this page. */ public Enumeration getApplets() { - AppletSecurity security = (AppletSecurity)System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); @@ -896,7 +883,7 @@ // streamhandler.pluginOutputStream has been closed. } } - + public long getWindow() { PluginDebug.debug ("STARTING getWindow"); PluginCallRequest request = requestFactory.getPluginCallRequest("window", @@ -1113,6 +1100,40 @@ return request.getObject(); } + public static Object requestPluginCookieInfo(URI uri) { + + PluginCallRequest request; + try + { + String encodedURI = UrlUtil.encode(uri.toString(), "UTF-8"); + request = requestFactory.getPluginCallRequest("cookieinfo", + "plugin PluginCookieInfo " + encodedURI, + "plugin PluginCookieInfo " + encodedURI); + + } catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + return null; + } + + streamhandler.postCallRequest(request); + streamhandler.write(request.getMessage()); + try { + PluginDebug.debug ("wait cookieinfo request 1"); + synchronized(request) { + PluginDebug.debug ("wait cookieinfo request 2"); + while (request.isDone() == false) + request.wait(); + PluginDebug.debug ("wait cookieinfo request 3"); + } + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted waiting for cookieinfo request.", + e); + } + PluginDebug.debug (" Cookieinfo DONE"); + return request.getObject(); + } + public static Object requestPluginProxyInfo(URI uri) { String requestURI = null; @@ -1623,10 +1644,6 @@ public static void parse(int identifier, long handle, Reader in, URL url) throws IOException { - // wait until cookie is set (even if cookie is null, it needs to be - // "set" to that first - while (!siteCookies.containsKey(identifier)); - final int fIdentifier = identifier; final long fHandle = handle; final Reader fIn = in; diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginCallRequestFactory.java --- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Tue Jul 07 17:17:32 2009 -0400 @@ -51,6 +51,8 @@ return new GetWindowPluginCallRequest(message, returnString); } else if (id == "proxyinfo") { return new PluginProxyInfoRequest(message, returnString); + } else if (id == "cookieinfo") { + return new PluginCookieInfoRequest(message, returnString); } else { throw new RuntimeException ("Unknown plugin call request type requested from factory"); } diff -r b4bb02c70835 plugin/icedtea/sun/applet/PluginMain.java --- a/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 13:44:35 2009 -0400 +++ b/plugin/icedtea/sun/applet/PluginMain.java Tue Jul 07 17:17:32 2009 -0400 @@ -68,10 +68,11 @@ import java.io.IOException; import java.io.PrintStream; import java.net.Authenticator; +import java.net.CookieHandler; +import java.net.CookieManager; import java.net.PasswordAuthentication; import java.net.ProxySelector; import java.util.Enumeration; -import java.util.HashMap; import java.util.Properties; import javax.net.ssl.HttpsURLConnection; @@ -218,6 +219,9 @@ // plug in a custom authenticator and proxy selector Authenticator.setDefault(new CustomAuthenticator()); ProxySelector.setDefault(new PluginProxySelector()); + + CookieManager ckManager = new CookieManager(new PluginCookieStore(), null); + CookieHandler.setDefault(ckManager); } static boolean messageAvailable() { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/ExtensionDesc.java --- a/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/ExtensionDesc.java Tue Jul 07 17:17:32 2009 -0400 @@ -40,9 +40,6 @@ /** the location of the extension JNLP file */ private URL location; - - /** the cookie string sent with resource requests */ - private String cookieStr; /** the JNLPFile the extension refers to */ private JNLPFile file; @@ -61,11 +58,10 @@ * @param version the required version of the extention JNLPFile * @param location the location of the extention JNLP file */ - public ExtensionDesc(String name, Version version, URL location, String cookieStr) { + public ExtensionDesc(String name, Version version, URL location) { this.name = name; this.version = version; this.location = location; - this.cookieStr = cookieStr; } /** @@ -125,7 +121,7 @@ */ public void resolve() throws ParseException, IOException { if (file == null) { - file = new JNLPFile(location, cookieStr); + file = new JNLPFile(location); if (JNLPRuntime.isDebug()) System.out.println("Resolve: "+file.getInformation().getTitle()); @@ -144,14 +140,6 @@ public JNLPFile getJNLPFile() { return file; } - - /** - * Returns the cookie associated with this instance - */ - public String getCookieStr() { - return cookieStr; - } - } diff -r b4bb02c70835 rt/net/sourceforge/jnlp/JNLPFile.java --- a/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Tue Jul 07 17:17:32 2009 -0400 @@ -69,9 +69,6 @@ /** the URL used to resolve relative URLs in the file */ protected URL codeBase; - - /** cookie string to send alongwith resource requests */ - protected String cookieStr; /** file version */ protected Version fileVersion; @@ -127,8 +124,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr) throws IOException, ParseException { - this(location, cookieStr, false); // not strict + public JNLPFile(URL location) throws IOException, ParseException { + this(location, false); // not strict } /** @@ -140,8 +137,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict) throws IOException, ParseException { - this(location, cookieStr, strict, JNLPRuntime.getDefaultUpdatePolicy()); + public JNLPFile(URL location, boolean strict) throws IOException, ParseException { + this(location, strict, JNLPRuntime.getDefaultUpdatePolicy()); } /** @@ -154,12 +151,11 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String cookieStr, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - Node root = Parser.getRootNode(openURL(location, cookieStr, policy)); + public JNLPFile(URL location, boolean strict, UpdatePolicy policy) throws IOException, ParseException { + Node root = Parser.getRootNode(openURL(location, policy)); parse(root, strict, location); this.fileLocation = location; - this.cookieStr = cookieStr; } /** @@ -190,13 +186,13 @@ * Open the jnlp file URL from the cache if there, otherwise * download to the cache. Called from constructor. */ - private static InputStream openURL(URL location, String cookieStr, UpdatePolicy policy) throws IOException { + private static InputStream openURL(URL location, UpdatePolicy policy) throws IOException { if (location == null || policy == null) throw new IllegalArgumentException(R("NullParameter")); try { ResourceTracker tracker = new ResourceTracker(false); // no prefetch - tracker.addResource(location, cookieStr, null/*version*/, policy); + tracker.addResource(location, null/*version*/, policy); return tracker.getInputStream(location); } @@ -255,13 +251,6 @@ */ public URL getCodeBase() { return codeBase; - } - - /** - * Returns the cookie string that will be send when resources for this file are requested - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Launcher.java --- a/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Launcher.java Tue Jul 07 17:17:32 2009 -0400 @@ -335,10 +335,10 @@ JNLPFile file = null; try { - file = new JNLPFile(location, null, true, updatePolicy); // strict + file = new JNLPFile(location, true, updatePolicy); // strict } catch (ParseException ex) { - file = new JNLPFile(location, null, false, updatePolicy); + file = new JNLPFile(location, false, updatePolicy); // only here if strict failed but lax did not fail LaunchException lex = @@ -389,7 +389,7 @@ IconDesc.SPLASH, preferredWidth, preferredHeight); if (splashImageURL != null) { ResourceTracker resourceTracker = new ResourceTracker(true); - resourceTracker.addResource(splashImageURL, "SPLASH", file.getFileVersion(), updatePolicy); + resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy); splashScreen = new JNLPSplashScreen(resourceTracker, null, null); splashScreen.setSplashImageURL(splashImageURL); if (splashScreen.isSplashScreenValid()) { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/NetxPanel.java --- a/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/NetxPanel.java Tue Jul 07 17:17:32 2009 -0400 @@ -41,7 +41,6 @@ private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; - private String cookieStr; private boolean appletAlive; public NetxPanel(URL documentURL, Hashtable atts) @@ -50,11 +49,10 @@ } // overloaded constructor, called when initialized via plugin - public NetxPanel(URL documentURL, String cookieStr, Hashtable atts, boolean exitOnFailure) + public NetxPanel(URL documentURL, Hashtable atts, boolean exitOnFailure) { this(documentURL, atts); this.exitOnFailure = exitOnFailure; - this.cookieStr = cookieStr; this.appletAlive = true; } @@ -64,7 +62,6 @@ try { bridge = new PluginBridge(baseURL, - cookieStr, getDocumentBase(), getJarFiles(), getCode(), diff -r b4bb02c70835 rt/net/sourceforge/jnlp/Parser.java --- a/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/Parser.java Tue Jul 07 17:17:32 2009 -0400 @@ -332,7 +332,7 @@ Version version = getVersion(node, "version", null); URL location = getRequiredURL(node, "href", base); - ExtensionDesc ext = new ExtensionDesc(name, version, location, null); + ExtensionDesc ext = new ExtensionDesc(name, version, location); Node dload[] = getChildNodes(node, "ext-download"); for (int i=0; i < dload.length; i++) { diff -r b4bb02c70835 rt/net/sourceforge/jnlp/PluginBridge.java --- a/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Tue Jul 07 17:17:32 2009 -0400 @@ -43,7 +43,7 @@ String[] cache_ex_jars = new String[0]; Hashtable atts; - public PluginBridge(URL codebase, String cookieStr, URL documentBase, String jar, String main, + public PluginBridge(URL codebase, URL documentBase, String jar, String main, int width, int height, Hashtable atts) throws Exception { @@ -104,7 +104,6 @@ else security = null; - this.cookieStr = cookieStr; } public String getTitle() diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/CacheUtil.java --- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Tue Jul 07 17:17:32 2009 -0400 @@ -75,9 +75,9 @@ * @param version the version, or null * @return either the location in the cache or the original location */ - public static URL getCachedResource(URL location, String cookieStr, Version version, UpdatePolicy policy) { + public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) { ResourceTracker rt = new ResourceTracker(); - rt.addResource(location, cookieStr, version, policy); + rt.addResource(location, version, policy); try { File f = rt.getCacheFile(location); return f.toURL(); diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/Resource.java --- a/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/Resource.java Tue Jul 07 17:17:32 2009 -0400 @@ -68,9 +68,6 @@ /** the remote location of the resource */ URL location; - /** cookie string to send with the resource request */ - String cookieStr; - /** the local file downloaded to */ File localFile; @@ -98,20 +95,19 @@ /** * Create a resource. */ - private Resource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + private Resource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { this.location = location; this.requestVersion = requestVersion; this.updatePolicy = updatePolicy; - this.cookieStr = cookieStr; } /** * Return a shared Resource object representing the given * location and version. */ - public static Resource getResource(URL location, String cookieStr, UpdatePolicy updatePolicy, Version requestVersion) { + public static Resource getResource(URL location, UpdatePolicy updatePolicy, Version requestVersion) { synchronized (resources) { - Resource resource = new Resource(location, cookieStr, updatePolicy, requestVersion); + Resource resource = new Resource(location, updatePolicy, requestVersion); int index = resources.indexOf(resource); if (index >= 0) { // return existing object @@ -132,13 +128,6 @@ */ public URL getLocation() { return location; - } - - /** - * Returns the cookie string associated with this resource - */ - public String getCookieStr() { - return cookieStr; } /** diff -r b4bb02c70835 rt/net/sourceforge/jnlp/cache/ResourceTracker.java --- a/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/cache/ResourceTracker.java Tue Jul 07 17:17:32 2009 -0400 @@ -148,11 +148,11 @@ * @param version the resource version * @param updatePolicy whether to check for updates if already in cache */ - public void addResource(URL location, String cookieStr, Version version, UpdatePolicy updatePolicy) { + public void addResource(URL location, Version version, UpdatePolicy updatePolicy) { if (location == null) throw new IllegalArgumentException("location==null"); - Resource resource = Resource.getResource(location, cookieStr, updatePolicy, version); + Resource resource = Resource.getResource(location, updatePolicy, version); boolean downloaded = false; synchronized (resources) { @@ -606,9 +606,6 @@ try { // create out second in case in does not exist URLConnection con = getVersionedResourceURL(resource).openConnection(); - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - con.setRequestProperty("Cookie", resource.getCookieStr()); InputStream in = new BufferedInputStream(con.getInputStream()); OutputStream out = CacheUtil.getOutputStream(resource.location, resource.downloadVersion); @@ -657,9 +654,6 @@ // connect URLConnection connection = getVersionedResourceURL(resource).openConnection(); // this won't change so should be okay unsynchronized - - if (resource.getCookieStr() != null && resource.getCookieStr().length() > 0) - connection.setRequestProperty("Cookie", resource.getCookieStr()); int size = connection.getContentLength(); boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE; diff -r b4bb02c70835 rt/net/sourceforge/jnlp/runtime/Boot.java --- a/rt/net/sourceforge/jnlp/runtime/Boot.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/runtime/Boot.java Tue Jul 07 17:17:32 2009 -0400 @@ -276,7 +276,7 @@ boolean strict = (null != getOption("-strict")); - JNLPFile file = new JNLPFile(url, null, strict); + JNLPFile file = new JNLPFile(url, strict); // add in extra params from command line addProperties(file); diff -r b4bb02c70835 rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 13:44:35 2009 -0400 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Jul 07 17:17:32 2009 -0400 @@ -234,11 +234,11 @@ * @param location the file's location * @param policy the update policy to use when downloading resources */ - public static JNLPClassLoader getInstance(URL location, String cookieStr, UpdatePolicy policy) throws IOException, ParseException, LaunchException { + public static JNLPClassLoader getInstance(URL location, UpdatePolicy policy) throws IOException, ParseException, LaunchException { JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(location); if (loader == null) - loader = getInstance(new JNLPFile(location, cookieStr, false, policy), policy); + loader = getInstance(new JNLPFile(location, false, policy), policy); return loader; } @@ -256,7 +256,7 @@ //if (ext != null) { for (int i=0; i < ext.length; i++) { try { - JNLPClassLoader loader = getInstance(ext[i].getLocation(), ext[i].getCookieStr(), updatePolicy); + JNLPClassLoader loader = getInstance(ext[i].getLocation(), updatePolicy); loaderList.add(loader); } catch (Exception ex) { @@ -314,7 +314,6 @@ initialJars.add(jars[i]); // regardless of part tracker.addResource(jars[i].getLocation(), - file.getCookieStr(), jars[i].getVersion(), jars[i].isCacheable() ? JNLPRuntime.getDefaultUpdatePolicy() : UpdatePolicy.FORCE ); @@ -780,8 +779,7 @@ available.add(desc); - tracker.addResource(desc.getLocation(), - file.getCookieStr(), + tracker.addResource(desc.getLocation(), desc.getVersion(), JNLPRuntime.getDefaultUpdatePolicy() ); |
| Free embeddable forum powered by Nabble | Forum Help |