1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 __NSCLIENTAUTHREMEMBER_H__
8 #define __NSCLIENTAUTHREMEMBER_H__
12 #include "mozilla/Attributes.h"
13 #include "mozilla/DataMutex.h"
14 #include "mozilla/HashFunctions.h"
15 #include "mozilla/ReentrantMonitor.h"
16 #include "nsIClientAuthRememberService.h"
17 #include "nsIDataStorage.h"
18 #include "nsIObserver.h"
19 #include "nsNSSCertificate.h"
21 #include "nsTHashtable.h"
22 #include "nsWeakReference.h"
25 class OriginAttributes
;
28 using mozilla::OriginAttributes
;
30 class nsClientAuthRemember final
: public nsIClientAuthRememberRecord
{
32 NS_DECL_THREADSAFE_ISUPPORTS
33 NS_DECL_NSICLIENTAUTHREMEMBERRECORD
35 nsClientAuthRemember(const nsACString
& aHostName
,
36 const OriginAttributes
& aOriginAttributes
) {
37 mAsciiHost
.Assign(aHostName
);
38 aOriginAttributes
.CreateSuffix(mOriginAttributesSuffix
);
41 nsClientAuthRemember(const nsCString
& aEntryKey
, const nsCString
& aDBKey
) {
42 if (!aDBKey
.Equals(nsClientAuthRemember::SentinelValue
)) {
46 size_t field_index
= 0;
47 for (const auto& field
: aEntryKey
.Split(',')) {
48 switch (field_index
) {
50 mAsciiHost
.Assign(field
);
55 mOriginAttributesSuffix
.Assign(field
);
65 nsCString mOriginAttributesSuffix
;
67 static constexpr nsLiteralCString SentinelValue
= "no client certificate"_ns
;
70 ~nsClientAuthRemember() = default;
73 class nsClientAuthRememberService final
: public nsIClientAuthRememberService
{
75 NS_DECL_THREADSAFE_ISUPPORTS
76 NS_DECL_NSICLIENTAUTHREMEMBERSERVICE
78 nsClientAuthRememberService()
79 : mMigrated(false, "nsClientAuthRememberService::mMigrated") {}
83 static bool IsPrivateBrowsingKey(const nsCString
& entryKey
);
86 ~nsClientAuthRememberService() = default;
88 static nsIDataStorage::DataType
GetDataStorageType(
89 const OriginAttributes
& aOriginAttributes
);
91 nsCOMPtr
<nsIDataStorage
> mClientAuthRememberList
;
93 nsresult
AddEntryToList(const nsACString
& aHost
,
94 const OriginAttributes
& aOriginAttributes
,
95 const nsACString
& aDBKey
);
97 mozilla::DataMutex
<bool> mMigrated
;