Skip to content

Commit e823842

Browse files
committed
Bug 1876579 - Add a hash key class for OriginAttributes. r=ckerschb
Differential Revision: https://phabricator.services.mozilla.com/D200817
1 parent 9958dc0 commit e823842

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

caps/OriginAttributesHashKey.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/. */
6+
7+
#ifndef mozilla_OriginAttributesHashKey_h
8+
#define mozilla_OriginAttributesHashKey_h
9+
10+
#include "OriginAttributes.h"
11+
#include "PLDHashTable.h"
12+
#include "nsHashKeys.h"
13+
14+
namespace mozilla {
15+
16+
class OriginAttributesHashKey : public PLDHashEntryHdr {
17+
public:
18+
using KeyType = OriginAttributes;
19+
using KeyTypeRef = const KeyType&;
20+
using KeyTypePointer = const KeyType*;
21+
22+
explicit OriginAttributesHashKey(KeyTypePointer aKey) {
23+
mOriginAttributes = *aKey;
24+
MOZ_COUNT_CTOR(OriginAttributesHashKey);
25+
}
26+
OriginAttributesHashKey(OriginAttributesHashKey&& aKey) noexcept {
27+
mOriginAttributes = std::move(aKey.mOriginAttributes);
28+
MOZ_COUNT_CTOR(OriginAttributesHashKey);
29+
}
30+
31+
MOZ_COUNTED_DTOR(OriginAttributesHashKey)
32+
33+
KeyTypeRef GetKey() const { return mOriginAttributes; }
34+
35+
bool KeyEquals(KeyTypePointer aKey) const {
36+
return mOriginAttributes == *aKey;
37+
}
38+
39+
static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
40+
41+
static PLDHashNumber HashKey(KeyTypePointer aKey) {
42+
nsAutoCString suffix;
43+
aKey->CreateSuffix(suffix);
44+
return mozilla::HashString(suffix);
45+
}
46+
47+
enum { ALLOW_MEMMOVE = true };
48+
49+
protected:
50+
OriginAttributes mOriginAttributes;
51+
};
52+
53+
} // namespace mozilla
54+
55+
#endif

caps/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ EXPORTS.mozilla = [
3434
"ExpandedPrincipal.h",
3535
"NullPrincipal.h",
3636
"OriginAttributes.h",
37+
"OriginAttributesHashKey.h",
3738
"PrincipalHashKey.h",
3839
"SystemPrincipal.h",
3940
]

0 commit comments

Comments
 (0)