diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-03 10:23:58 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-08-03 10:23:58 -0700 |
commit | 8050220374e67e0ffa9d92551f422c02cacadd9d (patch) | |
tree | fd68df1c6f29310246d5257d1f8b04c870c86fb1 /core | |
parent | f2beab58f34fc593fff583bfcd8143ce09fcdecd (diff) | |
parent | f4046ba80369efb2d2b75df05dfdf41a07bc8710 (diff) | |
download | frameworks_base-8050220374e67e0ffa9d92551f422c02cacadd9d.zip frameworks_base-8050220374e67e0ffa9d92551f422c02cacadd9d.tar.gz frameworks_base-8050220374e67e0ffa9d92551f422c02cacadd9d.tar.bz2 |
Merge change 9259
* changes:
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')
-rw-r--r-- | core/java/android/webkit/CookieManager.java | 40 |
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); |