1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_net_nsCookieKey_h
7 #define mozilla_net_nsCookieKey_h
8 #include "nsHashKeys.h"
9 #include "nsTHashtable.h"
13 class nsCookieKey
: public PLDHashEntryHdr
16 typedef const nsCookieKey
& KeyType
;
17 typedef const nsCookieKey
* KeyTypePointer
;
19 nsCookieKey() = default;
21 nsCookieKey(const nsCString
&baseDomain
, const OriginAttributes
&attrs
)
22 : mBaseDomain(baseDomain
)
23 , mOriginAttributes(attrs
)
26 explicit nsCookieKey(KeyTypePointer other
)
27 : mBaseDomain(other
->mBaseDomain
)
28 , mOriginAttributes(other
->mOriginAttributes
)
31 nsCookieKey(nsCookieKey
&& other
) = default;
32 nsCookieKey
& operator=(nsCookieKey
&&) = default;
34 bool KeyEquals(KeyTypePointer other
) const
36 return mBaseDomain
== other
->mBaseDomain
&&
37 mOriginAttributes
== other
->mOriginAttributes
;
40 static KeyTypePointer
KeyToPointer(KeyType aKey
)
45 static PLDHashNumber
HashKey(KeyTypePointer aKey
)
47 nsAutoCString
temp(aKey
->mBaseDomain
);
50 aKey
->mOriginAttributes
.CreateSuffix(suffix
);
52 return mozilla::HashString(temp
);
55 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const
57 return mBaseDomain
.SizeOfExcludingThisIfUnshared(aMallocSizeOf
);
60 enum { ALLOW_MEMMOVE
= true };
62 nsCString mBaseDomain
;
63 OriginAttributes mOriginAttributes
;
68 #endif // mozilla_net_nsCookieKey_h