1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef _NS_CERTTREE_H_
6 #define _NS_CERTTREE_H_
9 #include "nsICertTree.h"
10 #include "nsITreeSelection.h"
11 #include "nsIMutableArray.h"
12 #include "nsNSSComponent.h"
14 #include "PLDHashTable.h"
15 #include "mozilla/Attributes.h"
17 /* Disable the "base class XXX should be explicitly initialized
18 in the copy constructor" warning. */
19 #if defined(__clang__)
20 # pragma clang diagnostic push
21 # pragma clang diagnostic ignored "-Wextra"
22 #elif defined(__GNUC__)
23 # pragma GCC diagnostic push
24 # pragma GCC diagnostic ignored "-Wextra"
25 #endif // __clang__ || __GNUC__
27 #include "mozilla/dom/XULTreeElement.h"
29 #if defined(__clang__)
30 # pragma clang diagnostic pop
31 #elif defined(__GNUC__)
32 # pragma GCC diagnostic pop
33 #endif // __clang__ || __GNUC__
35 typedef struct treeArrayElStr treeArrayEl
;
37 struct CompareCacheHashEntry
{
38 enum { max_criterions
= 3 };
39 CompareCacheHashEntry();
41 void* key
; // no ownership
42 bool mCritInit
[max_criterions
];
43 nsString mCrit
[max_criterions
];
46 struct CompareCacheHashEntryPtr
: PLDHashEntryHdr
{
47 CompareCacheHashEntryPtr();
48 ~CompareCacheHashEntryPtr();
49 CompareCacheHashEntry
* entry
;
52 class nsCertTreeDispInfo
: public nsICertTreeItem
{
54 virtual ~nsCertTreeDispInfo();
57 explicit nsCertTreeDispInfo(nsIX509Cert
* aCert
) : mCert(aCert
) {}
60 NS_DECL_NSICERTTREEITEM
62 nsCOMPtr
<nsIX509Cert
> mCert
;
65 class nsCertTree
: public nsICertTree
{
78 sort_IssuedDateDescending
,
84 virtual ~nsCertTree();
86 void ClearCompareHash();
87 void RemoveCacheEntry(void* key
);
89 typedef int (*nsCertCompareFunc
)(void*, nsIX509Cert
* a
, nsIX509Cert
* b
);
91 static CompareCacheHashEntry
* getCacheEntry(void* cache
, void* aCert
);
92 static void CmpInitCriterion(nsIX509Cert
* cert
, CompareCacheHashEntry
* entry
,
93 sortCriterion crit
, int32_t level
);
94 static int32_t CmpByCrit(nsIX509Cert
* a
, CompareCacheHashEntry
* ace
,
95 nsIX509Cert
* b
, CompareCacheHashEntry
* bce
,
96 sortCriterion crit
, int32_t level
);
97 static int32_t CmpBy(void* cache
, nsIX509Cert
* a
, nsIX509Cert
* b
,
98 sortCriterion c0
, sortCriterion c1
, sortCriterion c2
);
99 static int32_t CmpCACert(void* cache
, nsIX509Cert
* a
, nsIX509Cert
* b
);
100 static int32_t CmpUserCert(void* cache
, nsIX509Cert
* a
, nsIX509Cert
* b
);
101 static int32_t CmpEmailCert(void* cache
, nsIX509Cert
* a
, nsIX509Cert
* b
);
102 nsCertCompareFunc
GetCompareFuncFromCertType(uint32_t aType
);
103 int32_t CountOrganizations();
106 static const uint32_t kInitialCacheLength
= 64;
108 nsTArray
<RefPtr
<nsCertTreeDispInfo
>> mDispInfo
;
109 RefPtr
<mozilla::dom::XULTreeElement
> mTree
;
110 nsCOMPtr
<nsITreeSelection
> mSelection
;
111 treeArrayEl
* mTreeArray
;
114 PLDHashTable mCompareCache
;
116 treeArrayEl
* GetThreadDescAtIndex(int32_t _index
);
117 already_AddRefed
<nsIX509Cert
> GetCertAtIndex(
118 int32_t _index
, int32_t* outAbsoluteCertOffset
= nullptr);
119 already_AddRefed
<nsCertTreeDispInfo
> GetDispInfoAtIndex(
120 int32_t index
, int32_t* outAbsoluteCertOffset
= nullptr);
121 void FreeCertArray();
122 nsresult
UpdateUIContents();
124 nsresult
GetCertsByTypeFromCertList(
125 const nsTArray
<RefPtr
<nsIX509Cert
>>& aCertList
, uint32_t aWantedType
,
126 nsCertCompareFunc aCertCmpFn
, void* aCertCmpFnArg
);
128 nsCOMPtr
<nsIMutableArray
> mCellText
;
131 #endif /* _NS_CERTTREE_H_ */