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/. */ 5 6 #ifndef mozilla_net_CookieKey_h 7 #define mozilla_net_CookieKey_h 8 9 #include "mozilla/OriginAttributes.h" 10 #include "nsHashKeys.h" 11 12 namespace mozilla { 13 namespace net { 14 15 class CookieKey : public PLDHashEntryHdr { 16 public: 17 typedef const CookieKey& KeyType; 18 typedef const CookieKey* KeyTypePointer; 19 20 CookieKey() = default; 21 CookieKey(const nsACString & baseDomain,const OriginAttributes & attrs)22 CookieKey(const nsACString& baseDomain, const OriginAttributes& attrs) 23 : mBaseDomain(baseDomain), mOriginAttributes(attrs) {} 24 CookieKey(KeyTypePointer other)25 explicit CookieKey(KeyTypePointer other) 26 : mBaseDomain(other->mBaseDomain), 27 mOriginAttributes(other->mOriginAttributes) {} 28 29 CookieKey(CookieKey&& other) = default; 30 CookieKey& operator=(CookieKey&&) = default; 31 KeyEquals(KeyTypePointer other)32 bool KeyEquals(KeyTypePointer other) const { 33 return mBaseDomain == other->mBaseDomain && 34 mOriginAttributes == other->mOriginAttributes; 35 } 36 KeyToPointer(KeyType aKey)37 static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } 38 HashKey(KeyTypePointer aKey)39 static PLDHashNumber HashKey(KeyTypePointer aKey) { 40 nsAutoCString temp(aKey->mBaseDomain); 41 temp.Append('#'); 42 nsAutoCString suffix; 43 aKey->mOriginAttributes.CreateSuffix(suffix); 44 temp.Append(suffix); 45 return HashString(temp); 46 } 47 SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)48 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { 49 return mBaseDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf); 50 } 51 52 enum { ALLOW_MEMMOVE = true }; 53 54 nsCString mBaseDomain; 55 OriginAttributes mOriginAttributes; 56 }; 57 58 } // namespace net 59 } // namespace mozilla 60 61 #endif // mozilla_net_CookieKey_h 62