mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1610373
- Introduce nsICookieManager::getCookieSince(), r=ewright
Differential Revision: https://phabricator.services.mozilla.com/D70055 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b64dfbe64c
commit
4937793ee0
@ -2064,6 +2064,42 @@ CookieService::RemoveAllSince(int64_t aSinceWhen, JSContext* aCx,
|
||||
return runMe->Run();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class CompareCookiesCreationTime {
|
||||
public:
|
||||
static bool Equals(const nsICookie* aCookie1, const nsICookie* aCookie2) {
|
||||
return static_cast<const Cookie*>(aCookie1)->CreationTime() ==
|
||||
static_cast<const Cookie*>(aCookie2)->CreationTime();
|
||||
}
|
||||
|
||||
static bool LessThan(const nsICookie* aCookie1, const nsICookie* aCookie2) {
|
||||
return static_cast<const Cookie*>(aCookie1)->CreationTime() <
|
||||
static_cast<const Cookie*>(aCookie2)->CreationTime();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieService::GetCookiesSince(int64_t aSinceWhen,
|
||||
nsTArray<RefPtr<nsICookie>>& aResult) {
|
||||
mPersistentStorage->EnsureReadComplete();
|
||||
|
||||
// We expose only non-private cookies.
|
||||
nsTArray<RefPtr<nsICookie>> cookieList;
|
||||
mPersistentStorage->GetAll(cookieList);
|
||||
|
||||
for (RefPtr<nsICookie>& cookie : cookieList) {
|
||||
if (static_cast<Cookie*>(cookie.get())->CreationTime() >= aSinceWhen) {
|
||||
aResult.AppendElement(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
aResult.Sort(CompareCookiesCreationTime());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
size_t CookieService::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
||||
size_t n = aMallocSizeOf(this);
|
||||
|
||||
|
@ -247,4 +247,9 @@ interface nsICookieManager : nsISupports
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
Promise removeAllSince(in int64_t aSinceWhen);
|
||||
|
||||
/**
|
||||
* Retrieves all the cookies that were created on or after aSinceWhen, order
|
||||
* by creation time */
|
||||
Array<nsICookie> getCookiesSince(in int64_t aSinceWhen);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user