modules/web/src/main/java/com/sun/webkit/network/URLs.java
Print this page
@@ -26,10 +26,12 @@
package com.sun.webkit.network;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLStreamHandler;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
@@ -79,26 +81,39 @@
* @param context the context in which to parse the specification.
* @param spec the {@code String} to parse as a {@code URL}.
* @throws MalformedURLException if no protocol is specified, or an
* unknown protocol is found.
*/
- public static URL newURL(URL context, String spec)
+ public static URL newURL(final URL context, final String spec)
throws MalformedURLException
{
try {
// Try the standard protocol handler selection procedure
return new URL(context, spec);
} catch (MalformedURLException ex) {
// Try WebPane-specific protocol handler, if any
- URLStreamHandler handler = null;
int colonPosition = spec.indexOf(':');
if (colonPosition != -1) {
- handler = handlerMap.get(
+ final URLStreamHandler handler = handlerMap.get(
spec.substring(0, colonPosition).toLowerCase());
+
+ try {
+ // We should be able to specify one of our stream handlers for the URL
+ // when running as an applet or a web start app.
+ return AccessController.doPrivileged((PrivilegedAction<URL>) () -> {
+ try {
+ return new URL(context, spec, handler);
+ } catch (MalformedURLException muex) {
+ throw new RuntimeException(muex);
}
- if (handler == null) {
- throw ex;
+ });
+ } catch (RuntimeException re) {
+ if (re.getCause() instanceof MalformedURLException) {
+ throw (MalformedURLException)re.getCause();
}
- return new URL(context, spec, handler);
+ throw re;
+ }
+ }
+ throw ex;
}
}
}