diff options
author | Adam Domurad <[email protected]> | 2013-08-19 13:01:03 -0400 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2013-08-19 13:01:03 -0400 |
commit | 98d454b3141c131697b3a94eb4ec108ad1f108eb (patch) | |
tree | fd9a1137db620b4964942a9cf4fa8d674e3d8846 /plugin | |
parent | 40dbe8d01d9e6a9d2f99c772a0f5968102309808 (diff) |
Fix PR1271: icedtea-web does not handle javascript:-protocol URLs
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginAppletViewer.java | 14 | ||||
-rw-r--r-- | plugin/icedteanp/java/sun/applet/PluginMain.java | 25 |
2 files changed, 33 insertions, 6 deletions
diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java index 7742035..cfa3109 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java @@ -115,6 +115,7 @@ import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteUnsignedApple import net.sourceforge.jnlp.splashscreen.SplashController; import net.sourceforge.jnlp.splashscreen.SplashPanel; import net.sourceforge.jnlp.splashscreen.SplashUtils; +import netscape.javascript.JSObject; import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.awt.X11.XEmbeddedFrame; @@ -903,18 +904,19 @@ public class PluginAppletViewer extends XEmbeddedFrame return v.elements(); } - /** - * Ignore. - */ public void showDocument(URL url) { PluginDebug.debug("Showing document..."); showDocument(url, "_self"); } - /** - * Ignore. - */ public void showDocument(URL url, String target) { + // If it is a javascript document, eval on current page. + if ("javascript".equals(url.getProtocol())) { + // Snip protocol off string + String evalString = url.toString().substring("javascript:".length()); + eval(getWindow(), evalString); + return; + } try { Long reference = getRequestIdentifier(); write("reference " + reference + " LoadURL " + UrlUtil.encode(url.toString(), "UTF-8") + " " + target); diff --git a/plugin/icedteanp/java/sun/applet/PluginMain.java b/plugin/icedteanp/java/sun/applet/PluginMain.java index d43444e..3ceb119 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMain.java +++ b/plugin/icedteanp/java/sun/applet/PluginMain.java @@ -66,11 +66,15 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.reflect.Field; import java.net.Authenticator; import java.net.CookieHandler; import java.net.CookieManager; import java.net.ProxySelector; +import java.net.URL; +import java.net.URLStreamHandler; import java.util.Enumeration; +import java.util.Hashtable; import java.util.Properties; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -91,6 +95,25 @@ public class PluginMain { // on whether the property that uses it is necessary/standard. private static final String theVersion = System.getProperty("java.version"); + /* Install a handler directly using reflection. This ensures that java doesn't error-out + * when javascript is used in a URL. We can then handle these URLs correctly in eg PluginAppletViewer.showDocument(). + */ + static private void installDummyJavascriptProtocolHandler() { + try { + Field handlersField = URL.class.getDeclaredField("handlers"); + handlersField.setAccessible(true); + + @SuppressWarnings("unchecked") + Hashtable<String, URLStreamHandler> handlers = (Hashtable<String,URLStreamHandler>)handlersField.get(null); + + // Place an arbitrary handler, we only need the URL construction to not error-out + handlers.put("javascript", new sun.net.www.protocol.http.Handler()); + } catch (Exception e) { + System.err.println("Unable to install 'javascript:' URL protocol handler!"); + e.printStackTrace(); + } + } + /** * The main entry point into AppletViewer. */ @@ -99,6 +122,8 @@ public class PluginMain { if (AppContext.getAppContext() == null) { SunToolkit.createNewAppContext(); } + installDummyJavascriptProtocolHandler(); + if (args.length != 2 || !(new File(args[0]).exists()) || !(new File(args[1]).exists())) { System.err.println("Invalid pipe names provided. Refusing to proceed."); System.exit(1); |