changeset in /hg/icedtea6: Rewrote cookie support for the plugin...
Deepak Bhole
dbhole at redhat.com
Thu Jul 9 11:38:21 PDT 2009
changeset a50daec5fab4 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=a50daec5fab4
description:
Rewrote cookie support for the plugin so that cookies are aquired dynamically
from Mozilla for each http/https connection.
diffstat:
16 files changed, 127 insertions(+), 108 deletions(-)
ChangeLog | 16 ++++
IcedTeaPlugin.cc | 52 ++++++++++---
plugin/icedtea/sun/applet/PluginAppletViewer.java | 57 +++++++++------
plugin/icedtea/sun/applet/PluginCallRequestFactory.java | 2
plugin/icedtea/sun/applet/PluginMain.java | 6 +
rt/net/sourceforge/jnlp/ExtensionDesc.java | 16 ----
rt/net/sourceforge/jnlp/JNLPFile.java | 27 ++-----
rt/net/sourceforge/jnlp/Launcher.java | 6 -
rt/net/sourceforge/jnlp/NetxPanel.java | 5 -
rt/net/sourceforge/jnlp/Parser.java | 2
rt/net/sourceforge/jnlp/PluginBridge.java | 3
rt/net/sourceforge/jnlp/cache/CacheUtil.java | 4 -
rt/net/sourceforge/jnlp/cache/Resource.java | 17 ----
rt/net/sourceforge/jnlp/cache/ResourceTracker.java | 10 --
rt/net/sourceforge/jnlp/runtime/Boot.java | 2
rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 10 +-
diffs (truncated from 645 to 500 lines):
diff -r bb7ad7d43804 -r a50daec5fab4 ChangeLog
--- a/ChangeLog Thu Jul 09 12:49:11 2009 +0200
+++ b/ChangeLog Thu Jul 09 14:42:44 2009 -0400
@@ -1,3 +1,19 @@ 2009-07-09 Xerxes RÃ¥nby <xerxes at zafen
+2009-07-09 Deepak Bhole <dbhole at redhat.com>
+
+ * 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.
+
2009-07-09 Xerxes RÃ¥nby <xerxes at zafena.se>
* ports/hotspot/src/share/vm/shark/sharkBuilder.cpp
diff -r bb7ad7d43804 -r a50daec5fab4 IcedTeaPlugin.cc
--- a/IcedTeaPlugin.cc Thu Jul 09 12:49:11 2009 +0200
+++ b/IcedTeaPlugin.cc Thu Jul 09 14:42:44 2009 -0400
@@ -1012,6 +1012,7 @@ private:
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 @@ private:
IcedTeaPluginFactory* factory;
PRUint32 instance_identifier;
nsCString instanceIdentifierPrefix;
- nsresult GetCookie(const char* siteAddr, char** cookieString);
};
@@ -2380,16 +2380,6 @@ IcedTeaPluginInstance::Initialize (nsIPl
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 @@ IcedTeaPluginFactory::GetProxyInfo(const
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 @@ IcedTeaPluginFactory::HandleMessage (nsC
// 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 bb7ad7d43804 -r a50daec5fab4 plugin/icedtea/sun/applet/PluginAppletViewer.java
--- a/plugin/icedtea/sun/applet/PluginAppletViewer.java Thu Jul 09 12:49:11 2009 +0200
+++ b/plugin/icedtea/sun/applet/PluginAppletViewer.java Thu Jul 09 14:42:44 2009 -0400
@@ -84,6 +84,7 @@ import java.io.PrintStream;
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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
* 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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
// streamhandler.pluginOutputStream has been closed.
}
}
-
+
public long getWindow() {
PluginDebug.debug ("STARTING getWindow");
PluginCallRequest request = requestFactory.getPluginCallRequest("window",
@@ -1113,6 +1100,40 @@ import com.sun.jndi.toolkit.url.UrlUtil;
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 @@ import com.sun.jndi.toolkit.url.UrlUtil;
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 bb7ad7d43804 -r a50daec5fab4 plugin/icedtea/sun/applet/PluginCallRequestFactory.java
--- a/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Thu Jul 09 12:49:11 2009 +0200
+++ b/plugin/icedtea/sun/applet/PluginCallRequestFactory.java Thu Jul 09 14:42:44 2009 -0400
@@ -51,6 +51,8 @@ public class PluginCallRequestFactory {
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 bb7ad7d43804 -r a50daec5fab4 plugin/icedtea/sun/applet/PluginMain.java
--- a/plugin/icedtea/sun/applet/PluginMain.java Thu Jul 09 12:49:11 2009 +0200
+++ b/plugin/icedtea/sun/applet/PluginMain.java Thu Jul 09 14:42:44 2009 -0400
@@ -68,10 +68,11 @@ import java.io.IOException;
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 @@ public class PluginMain
// 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 bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/ExtensionDesc.java
--- a/rt/net/sourceforge/jnlp/ExtensionDesc.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/ExtensionDesc.java Thu Jul 09 14:42:44 2009 -0400
@@ -40,9 +40,6 @@ public class ExtensionDesc {
/** 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 @@ public class ExtensionDesc {
* @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 class ExtensionDesc {
*/
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 class ExtensionDesc {
public JNLPFile getJNLPFile() {
return file;
}
-
- /**
- * Returns the cookie associated with this instance
- */
- public String getCookieStr() {
- return cookieStr;
- }
-
}
diff -r bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/JNLPFile.java
--- a/rt/net/sourceforge/jnlp/JNLPFile.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/JNLPFile.java Thu Jul 09 14:42:44 2009 -0400
@@ -69,9 +69,6 @@ public class JNLPFile {
/** 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 @@ public class JNLPFile {
* @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 @@ public class JNLPFile {
* @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 @@ public class JNLPFile {
* @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 @@ public class JNLPFile {
* 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 class JNLPFile {
*/
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 bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/Launcher.java
--- a/rt/net/sourceforge/jnlp/Launcher.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/Launcher.java Thu Jul 09 14:42:44 2009 -0400
@@ -335,10 +335,10 @@ public class Launcher {
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 @@ public class Launcher {
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 bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/NetxPanel.java
--- a/rt/net/sourceforge/jnlp/NetxPanel.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/NetxPanel.java Thu Jul 09 14:42:44 2009 -0400
@@ -41,7 +41,6 @@ public class NetxPanel extends AppletVie
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 @@ public class NetxPanel extends AppletVie
}
// 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 @@ public class NetxPanel extends AppletVie
try {
bridge = new PluginBridge(baseURL,
- cookieStr,
getDocumentBase(),
getJarFiles(),
getCode(),
diff -r bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/Parser.java
--- a/rt/net/sourceforge/jnlp/Parser.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/Parser.java Thu Jul 09 14:42:44 2009 -0400
@@ -332,7 +332,7 @@ class Parser {
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 bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/PluginBridge.java
--- a/rt/net/sourceforge/jnlp/PluginBridge.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/PluginBridge.java Thu Jul 09 14:42:44 2009 -0400
@@ -43,7 +43,7 @@ public class PluginBridge extends JNLPFi
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 @@ public class PluginBridge extends JNLPFi
else
security = null;
- this.cookieStr = cookieStr;
}
public String getTitle()
diff -r bb7ad7d43804 -r a50daec5fab4 rt/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java Thu Jul 09 12:49:11 2009 +0200
+++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java Thu Jul 09 14:42:44 2009 -0400
@@ -75,9 +75,9 @@ public class CacheUtil {
* @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);
More information about the distro-pkg-dev
mailing list