# HG changeset patch # User Jaroslav Tulach # Date 1359744561 -3600 # Node ID a947e379f1614954df57a6a3aba5bd5c717eafc8 # Parent cfbd4eecb9415034b87f722e4138c6648e4e36c8 Infering the URL context from the browser's base URL, if any diff -r cfbd4eecb941 -r a947e379f161 emul/mini/src/main/java/java/net/URL.java --- a/emul/mini/src/main/java/java/net/URL.java Fri Feb 01 18:42:07 2013 +0100 +++ b/emul/mini/src/main/java/java/net/URL.java Fri Feb 01 19:49:21 2013 +0100 @@ -506,6 +506,17 @@ public URL(URL context, String spec, URLStreamHandler handler) throws MalformedURLException { + this(findContext(context), spec, handler != null); + } + + private URL(URL context, String spec, boolean ishandler) + throws MalformedURLException { + // Check for permission to specify a handler + if (ishandler) { + throw new SecurityException(); + } + URLStreamHandler handler = null; + String original = spec; int i, limit, c; int start = 0; @@ -513,10 +524,6 @@ boolean aRef=false; boolean isRelative = false; - // Check for permission to specify a handler - if (handler != null) { - throw new SecurityException(); - } try { limit = spec.length(); @@ -1035,6 +1042,23 @@ return universal; } + private static URL findContext(URL context) throws MalformedURLException { + if (context == null) { + String base = findBaseURL(); + if (base != null) { + context = new URL(null, base, false); + } + } + return context; + } + + @JavaScriptBody(args = {}, body = + "if (window && window.location && window.location.href) {\n" + + " return window.location.href;\n" + + "}\n" + + "return null;" + ) + private static native String findBaseURL(); } class Parts { String path, query, ref; diff -r cfbd4eecb941 -r a947e379f161 vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Fri Feb 01 18:42:07 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Fri Feb 01 19:49:21 2013 +0100 @@ -62,7 +62,7 @@ @HttpResource(path = "/readAnEntry.jar", mimeType = "x-application/zip", content = "", resource="readAnEntry.zip") @BrwsrTest public void canVmLoadResourceFromZip() throws IOException { - Object res = loadVMResource("/my/main/file.txt", "http:/readAnEntry.jar"); + Object res = loadVMResource("/my/main/file.txt", "/readAnEntry.jar"); assert res instanceof InputStream : "Got array of bytes: " + res; InputStream is = (InputStream)res;