Bug 1356605 - Part 1: Add an enumerator for getting session cookies only. r=valentin

This commit is contained in:
Will Wang 2017-05-10 09:50:17 +08:00
parent c745ceee90
commit 6523b5834f
2 changed files with 31 additions and 0 deletions

View File

@ -2361,6 +2361,31 @@ nsCookieService::GetEnumerator(nsISimpleEnumerator **aEnumerator)
return NS_NewArrayEnumerator(aEnumerator, cookieList);
}
NS_IMETHODIMP
nsCookieService::GetSessionEnumerator(nsISimpleEnumerator **aEnumerator)
{
if (!mDBState) {
NS_WARNING("No DBState! Profile already closed?");
return NS_ERROR_NOT_AVAILABLE;
}
EnsureReadComplete();
nsCOMArray<nsICookie> cookieList(mDBState->cookieCount);
for (auto iter = mDBState->hostTable.Iter(); !iter.Done(); iter.Next()) {
const nsCookieEntry::ArrayType& cookies = iter.Get()->GetCookies();
for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ++i) {
nsCookie* cookie = cookies[i];
// Filter out non-session cookies.
if (cookie->IsSession()) {
cookieList.AppendObject(cookie);
}
}
}
return NS_NewArrayEnumerator(aEnumerator, cookieList);
}
static nsresult
InitializeOriginAttributes(OriginAttributes* aAttrs,
JS::HandleValue aOriginAttributes,

View File

@ -41,6 +41,12 @@ interface nsICookieManager : nsISupports
*/
readonly attribute nsISimpleEnumerator enumerator;
/**
* Called to enumerate through each session cookie in the cookie list.
* The objects enumerated over are of type nsICookie
*/
readonly attribute nsISimpleEnumerator sessionEnumerator;
/**
* Called to remove an individual cookie from the cookie list, specified
* by host, name, and path. If the cookie cannot be found, no exception