changeset 4038:5a92586a9a1b

RT-31072: Sending email with gmail doesn't work with webview
author Vasiliy Baranov <vasiliy.baranov@oracle.com>
date Mon, 24 Jun 2013 14:51:13 +0400
parents 7bf2396582c8
children 3822e5001c00
files webview/src/com/sun/webkit/network/CookieJar.java webview/src/com/sun/webkit/network/CookieManager.java webview/test/com/sun/webkit/network/CookieManagerTest.java
diffstat 3 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/webview/src/com/sun/webkit/network/CookieJar.java	Mon Jun 24 13:31:56 2013 +0300
+++ b/webview/src/com/sun/webkit/network/CookieJar.java	Mon Jun 24 14:51:13 2013 +0400
@@ -23,10 +23,7 @@
             URI uri = null;
             try {
                 uri = new URI(url);
-                // RT-12200: Rewrite the scheme to javascript to avoid
-                // modifying HttpOnly cookies
-                uri = new URI("javascript", uri.getRawSchemeSpecificPart(),
-                        uri.getRawFragment());
+                uri = rewriteToFilterOutHttpOnlyCookies(uri);
             } catch (URISyntaxException e) {
                 return;
             }
@@ -49,10 +46,7 @@
             try {
                 uri = new URI(url);
                 if (!includeHttpOnlyCookies) {
-                    // RT-12200: Rewrite the scheme to javascript to avoid
-                    // returning HttpOnly cookies
-                    uri = new URI("javascript", uri.getRawSchemeSpecificPart(),
-                            uri.getRawFragment());
+                    uri = rewriteToFilterOutHttpOnlyCookies(uri);
                 }
             } catch (URISyntaxException e) {
                 return null;
@@ -83,4 +77,19 @@
         }
         return null;
     }
+
+    private static URI rewriteToFilterOutHttpOnlyCookies(URI uri)
+        throws URISyntaxException
+    {
+        // RT-12200, RT-31072: Rewrite the 'https' scheme to
+        // 'javascripts' to filter out HttpOnly cookies but
+        // keep Secure cookies. Rewrite any other scheme
+        // to 'javascript' to filter out both HttpOnly and
+        // Secure cookies.
+        return new URI(
+                uri.getScheme().equalsIgnoreCase("https")
+                        ? "javascripts" : "javascript",
+                uri.getRawSchemeSpecificPart(),
+                uri.getRawFragment());
+    }
 }
--- a/webview/src/com/sun/webkit/network/CookieManager.java	Mon Jun 24 13:31:56 2013 +0300
+++ b/webview/src/com/sun/webkit/network/CookieManager.java	Mon Jun 24 14:51:13 2013 +0400
@@ -79,7 +79,8 @@
         host = canonicalize(host);
 
         String scheme = uri.getScheme();
-        boolean secureProtocol = "https".equalsIgnoreCase(scheme);
+        boolean secureProtocol = "https".equalsIgnoreCase(scheme)
+                || "javascripts".equalsIgnoreCase(scheme);
         boolean httpApi = "http".equalsIgnoreCase(scheme)
                 || "https".equalsIgnoreCase(scheme);
 
--- a/webview/test/com/sun/webkit/network/CookieManagerTest.java	Mon Jun 24 13:31:56 2013 +0300
+++ b/webview/test/com/sun/webkit/network/CookieManagerTest.java	Mon Jun 24 14:51:13 2013 +0400
@@ -141,24 +141,20 @@
     }
 
     /**
-     * Tests the get() method's handling of the secureOnly flag.
+     * Tests the get() method's handling of the secureOnly and httpOnly flags.
      */
     @Test
-    public void testGetSecureOnly() {
-        put("http://example.org/", "foo=bar", "baz=qux; Secure");
-        assertEquals("foo=bar", get("http://example.org/"));
-        assertEquals("foo=bar; baz=qux", get("https://example.org/"));
-    }
-
-    /**
-     * Tests the get() method's handling of the httpOnly flag.
-     */
-    @Test
-    public void testGetHttpOnly() {
-        put("http://example.org/", "foo=bar", "baz=qux; HttpOnly");
+    public void testGetSecureOnlyAndHttpOnly() {
+        put("http://example.org/",
+                "foo=bar",
+                "baz=qux; Secure",
+                "quux=courge; HttpOnly",
+                "grault=garply; Secure; HttpOnly");
+        assertEquals("foo=bar; quux=courge", get("http://example.org/"));
+        assertEquals("foo=bar; baz=qux; quux=courge; grault=garply",
+                get("https://example.org/"));
         assertEquals("foo=bar", get("javascript://example.org/"));
-        assertEquals("foo=bar; baz=qux", get("http://example.org/"));
-        assertEquals("foo=bar; baz=qux", get("https://example.org/"));
+        assertEquals("foo=bar; baz=qux", get("javascripts://example.org/"));
     }
 
     /**