1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_PrincipalHashKey_h
8 #define mozilla_PrincipalHashKey_h
10 #include "BasePrincipal.h"
11 #include "PLDHashTable.h"
12 #include "mozilla/Unused.h"
14 #include "nsHashKeys.h"
18 class PrincipalHashKey
: public PLDHashEntryHdr
{
20 using KeyType
= nsIPrincipal
*;
21 using KeyTypePointer
= const nsIPrincipal
*;
23 explicit PrincipalHashKey(const nsIPrincipal
* aKey
)
24 : mPrincipal(const_cast<nsIPrincipal
*>(aKey
)) {
26 MOZ_COUNT_CTOR(PrincipalHashKey
);
28 PrincipalHashKey(PrincipalHashKey
&& aKey
)
29 : mPrincipal(std::move(aKey
.mPrincipal
)) {
30 MOZ_COUNT_CTOR(PrincipalHashKey
);
33 MOZ_COUNTED_DTOR(PrincipalHashKey
)
35 nsIPrincipal
* GetKey() const { return mPrincipal
; }
37 bool KeyEquals(const nsIPrincipal
* aKey
) const {
38 return BasePrincipal::Cast(mPrincipal
)
39 ->FastEquals(const_cast<nsIPrincipal
*>(aKey
));
42 static const nsIPrincipal
* KeyToPointer(const nsIPrincipal
* aKey
) {
45 static PLDHashNumber
HashKey(const nsIPrincipal
* aKey
) {
46 auto* bp
= BasePrincipal::Cast(aKey
);
47 return HashGeneric(bp
->GetOriginNoSuffixHash(), bp
->GetOriginSuffixHash());
50 enum { ALLOW_MEMMOVE
= true };
53 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
56 } // namespace mozilla