mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1331680 - Part 0: Extract nsCookieKey. r=jdm
This commit is contained in:
parent
88efc0911a
commit
62553acf94
74
netwerk/cookie/nsCookieKey.h
Normal file
74
netwerk/cookie/nsCookieKey.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_net_nsCookieKey_h
|
||||
#define mozilla_net_nsCookieKey_h
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsTHashtable.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
class nsCookieKey : public PLDHashEntryHdr
|
||||
{
|
||||
public:
|
||||
typedef const nsCookieKey& KeyType;
|
||||
typedef const nsCookieKey* KeyTypePointer;
|
||||
|
||||
nsCookieKey()
|
||||
{}
|
||||
|
||||
nsCookieKey(const nsCString &baseDomain, const OriginAttributes &attrs)
|
||||
: mBaseDomain(baseDomain)
|
||||
, mOriginAttributes(attrs)
|
||||
{}
|
||||
|
||||
explicit nsCookieKey(KeyTypePointer other)
|
||||
: mBaseDomain(other->mBaseDomain)
|
||||
, mOriginAttributes(other->mOriginAttributes)
|
||||
{}
|
||||
|
||||
nsCookieKey(KeyType other)
|
||||
: mBaseDomain(other.mBaseDomain)
|
||||
, mOriginAttributes(other.mOriginAttributes)
|
||||
{}
|
||||
|
||||
~nsCookieKey()
|
||||
{}
|
||||
|
||||
bool KeyEquals(KeyTypePointer other) const
|
||||
{
|
||||
return mBaseDomain == other->mBaseDomain &&
|
||||
mOriginAttributes == other->mOriginAttributes;
|
||||
}
|
||||
|
||||
static KeyTypePointer KeyToPointer(KeyType aKey)
|
||||
{
|
||||
return &aKey;
|
||||
}
|
||||
|
||||
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||
{
|
||||
nsAutoCString temp(aKey->mBaseDomain);
|
||||
temp.Append('#');
|
||||
nsAutoCString suffix;
|
||||
aKey->mOriginAttributes.CreateSuffix(suffix);
|
||||
temp.Append(suffix);
|
||||
return mozilla::HashString(temp);
|
||||
}
|
||||
|
||||
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
return mBaseDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
nsCString mBaseDomain;
|
||||
OriginAttributes mOriginAttributes;
|
||||
};
|
||||
|
||||
} // net
|
||||
} // mozilla
|
||||
#endif // mozilla_net_nsCookieKey_h
|
@ -606,12 +606,6 @@ NS_IMPL_ISUPPORTS(AppClearDataObserver, nsIObserver)
|
||||
|
||||
} // namespace
|
||||
|
||||
size_t
|
||||
nsCookieKey::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
return mBaseDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
size_t
|
||||
nsCookieEntry::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
@ -3440,14 +3434,14 @@ nsCookieService::GetCookieStringInternal(nsIURI *aHostURI,
|
||||
// processes a single cookie, and returns true if there are more cookies
|
||||
// to be processed
|
||||
bool
|
||||
nsCookieService::SetCookieInternal(nsIURI *aHostURI,
|
||||
const nsCookieKey &aKey,
|
||||
bool aRequireHostMatch,
|
||||
CookieStatus aStatus,
|
||||
nsDependentCString &aCookieHeader,
|
||||
int64_t aServerTime,
|
||||
bool aFromHttp,
|
||||
nsIChannel *aChannel)
|
||||
nsCookieService::SetCookieInternal(nsIURI *aHostURI,
|
||||
const nsCookieKey &aKey,
|
||||
bool aRequireHostMatch,
|
||||
CookieStatus aStatus,
|
||||
nsDependentCString &aCookieHeader,
|
||||
int64_t aServerTime,
|
||||
bool aFromHttp,
|
||||
nsIChannel *aChannel)
|
||||
{
|
||||
NS_ASSERTION(aHostURI, "null host!");
|
||||
|
||||
@ -3591,12 +3585,12 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI,
|
||||
// and deletes a cookie (if maximum number of cookies has been
|
||||
// reached). also performs list maintenance by removing expired cookies.
|
||||
void
|
||||
nsCookieService::AddInternal(const nsCookieKey &aKey,
|
||||
nsCookie *aCookie,
|
||||
int64_t aCurrentTimeInUsec,
|
||||
nsIURI *aHostURI,
|
||||
const char *aCookieHeader,
|
||||
bool aFromHttp)
|
||||
nsCookieService::AddInternal(const nsCookieKey &aKey,
|
||||
nsCookie *aCookie,
|
||||
int64_t aCurrentTimeInUsec,
|
||||
nsIURI *aHostURI,
|
||||
const char *aCookieHeader,
|
||||
bool aFromHttp)
|
||||
{
|
||||
int64_t currentTime = aCurrentTimeInUsec / PR_USEC_PER_SEC;
|
||||
|
||||
@ -4998,8 +4992,8 @@ nsCookieService::RemoveCookiesWithOriginAttributes(
|
||||
|
||||
// find an secure cookie specified by host and name
|
||||
bool
|
||||
nsCookieService::FindSecureCookie(const nsCookieKey &aKey,
|
||||
nsCookie *aCookie)
|
||||
nsCookieService::FindSecureCookie(const nsCookieKey &aKey,
|
||||
nsCookie *aCookie)
|
||||
{
|
||||
EnsureReadDomain(aKey);
|
||||
|
||||
|
@ -31,8 +31,10 @@
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "nsCookieKey.h"
|
||||
|
||||
using mozilla::OriginAttributes;
|
||||
using mozilla::nsCookieKey;
|
||||
|
||||
class nsICookiePermission;
|
||||
class nsIEffectiveTLDService;
|
||||
@ -55,64 +57,6 @@ class CookieServiceParent;
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
// hash key class
|
||||
class nsCookieKey : public PLDHashEntryHdr
|
||||
{
|
||||
public:
|
||||
typedef const nsCookieKey& KeyType;
|
||||
typedef const nsCookieKey* KeyTypePointer;
|
||||
|
||||
nsCookieKey()
|
||||
{}
|
||||
|
||||
nsCookieKey(const nsCString &baseDomain, const OriginAttributes &attrs)
|
||||
: mBaseDomain(baseDomain)
|
||||
, mOriginAttributes(attrs)
|
||||
{}
|
||||
|
||||
explicit nsCookieKey(KeyTypePointer other)
|
||||
: mBaseDomain(other->mBaseDomain)
|
||||
, mOriginAttributes(other->mOriginAttributes)
|
||||
{}
|
||||
|
||||
nsCookieKey(KeyType other)
|
||||
: mBaseDomain(other.mBaseDomain)
|
||||
, mOriginAttributes(other.mOriginAttributes)
|
||||
{}
|
||||
|
||||
~nsCookieKey()
|
||||
{}
|
||||
|
||||
bool KeyEquals(KeyTypePointer other) const
|
||||
{
|
||||
return mBaseDomain == other->mBaseDomain &&
|
||||
mOriginAttributes == other->mOriginAttributes;
|
||||
}
|
||||
|
||||
static KeyTypePointer KeyToPointer(KeyType aKey)
|
||||
{
|
||||
return &aKey;
|
||||
}
|
||||
|
||||
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
||||
{
|
||||
// TODO: more efficient way to generate hash?
|
||||
nsAutoCString temp(aKey->mBaseDomain);
|
||||
temp.Append('#');
|
||||
nsAutoCString suffix;
|
||||
aKey->mOriginAttributes.CreateSuffix(suffix);
|
||||
temp.Append(suffix);
|
||||
return mozilla::HashString(temp);
|
||||
}
|
||||
|
||||
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
nsCString mBaseDomain;
|
||||
OriginAttributes mOriginAttributes;
|
||||
};
|
||||
|
||||
// Inherit from nsCookieKey so this can be stored in nsTHashTable
|
||||
// TODO: why aren't we using nsClassHashTable<nsCookieKey, ArrayType>?
|
||||
class nsCookieEntry : public nsCookieKey
|
||||
|
Loading…
Reference in New Issue
Block a user