summaryrefslogtreecommitdiffstats
path: root/core/java/android/webkit/CookieManager.java
diff options
context:
space:
mode:
authorGrace Kloba <klobag@google.com>2009-08-03 10:05:39 -0700
committerGrace Kloba <klobag@google.com>2009-08-03 10:05:39 -0700
commitf4046ba80369efb2d2b75df05dfdf41a07bc8710 (patch)
tree6442aa4d10243155471b637ab59a6383dbdd1e5d /core/java/android/webkit/CookieManager.java
parenta05f75d61aa4e779f2fdf466267b47e7df213566 (diff)
downloadframeworks_base-f4046ba80369efb2d2b75df05dfdf41a07bc8710.zip
frameworks_base-f4046ba80369efb2d2b75df05dfdf41a07bc8710.tar.gz
frameworks_base-f4046ba80369efb2d2b75df05dfdf41a07bc8710.tar.bz2
Fix the cookie order. If multiple cookies satisfy the criteria, the one with
more specfic Path precede thoese with less specific.
Diffstat (limited to 'core/java/android/webkit/CookieManager.java')
-rw-r--r--core/java/android/webkit/CookieManager.java40
1 files changed, 29 insertions, 11 deletions
diff --git a/core/java/android/webkit/CookieManager.java b/core/java/android/webkit/CookieManager.java
index 7b91724..c81c4b6 100644
--- a/core/java/android/webkit/CookieManager.java
+++ b/core/java/android/webkit/CookieManager.java
@@ -23,9 +23,12 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
/**
* CookieManager manages cookies according to RFC2109 spec.
@@ -190,6 +193,14 @@ public final class CookieManager {
}
}
+ private static final CookieComparator COMPARATOR = new CookieComparator();
+
+ private static final class CookieComparator implements Comparator<Cookie> {
+ public int compare(Cookie cookie1, Cookie cookie2) {
+ return cookie2.path.length() - cookie1.path.length();
+ }
+ }
+
private CookieManager() {
}
@@ -401,8 +412,8 @@ public final class CookieManager {
long now = System.currentTimeMillis();
boolean secure = HTTPS.equals(uri.mScheme);
Iterator<Cookie> iter = cookieList.iterator();
- StringBuilder ret = new StringBuilder(256);
+ SortedSet<Cookie> cookieSet = new TreeSet<Cookie>(COMPARATOR);
while (iter.hasNext()) {
Cookie cookie = iter.next();
if (cookie.domainMatch(hostAndPath[0]) &&
@@ -413,19 +424,26 @@ public final class CookieManager {
&& (!cookie.secure || secure)
&& cookie.mode != Cookie.MODE_DELETED) {
cookie.lastAcessTime = now;
+ cookieSet.add(cookie);
+ }
+ }
- if (ret.length() > 0) {
- ret.append(SEMICOLON);
- // according to RC2109, SEMICOLON is office separator,
- // but when log in yahoo.com, it needs WHITE_SPACE too.
- ret.append(WHITE_SPACE);
- }
-
- ret.append(cookie.name);
- ret.append(EQUAL);
- ret.append(cookie.value);
+ StringBuilder ret = new StringBuilder(256);
+ Iterator<Cookie> setIter = cookieSet.iterator();
+ while (setIter.hasNext()) {
+ Cookie cookie = setIter.next();
+ if (ret.length() > 0) {
+ ret.append(SEMICOLON);
+ // according to RC2109, SEMICOLON is official separator,
+ // but when log in yahoo.com, it needs WHITE_SPACE too.
+ ret.append(WHITE_SPACE);
}
+
+ ret.append(cookie.name);
+ ret.append(EQUAL);
+ ret.append(cookie.value);
}
+
if (ret.length() > 0) {
if (DebugFlags.COOKIE_MANAGER) {
Log.v(LOGTAG, "getCookie: uri: " + uri + " value: " + ret);