nsCertTree.h (3847B)
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/. */ 4 5 #ifndef _NS_CERTTREE_H_ 6 #define _NS_CERTTREE_H_ 7 8 #include "nsCOMPtr.h" 9 #include "nsICertTree.h" 10 #include "nsITreeSelection.h" 11 #include "nsIMutableArray.h" 12 #include "nsNSSComponent.h" 13 #include "nsTArray.h" 14 #include "PLDHashTable.h" 15 16 /* Disable the "base class XXX should be explicitly initialized 17 in the copy constructor" warning. */ 18 #if defined(__clang__) 19 # pragma clang diagnostic push 20 # pragma clang diagnostic ignored "-Wextra" 21 #elif defined(__GNUC__) 22 # pragma GCC diagnostic push 23 # pragma GCC diagnostic ignored "-Wextra" 24 #endif // __clang__ || __GNUC__ 25 26 #include "mozilla/dom/XULTreeElement.h" 27 28 #if defined(__clang__) 29 # pragma clang diagnostic pop 30 #elif defined(__GNUC__) 31 # pragma GCC diagnostic pop 32 #endif // __clang__ || __GNUC__ 33 34 typedef struct treeArrayElStr treeArrayEl; 35 36 struct CompareCacheHashEntry { 37 enum { max_criterions = 3 }; 38 CompareCacheHashEntry(); 39 40 void* key; // no ownership 41 bool mCritInit[max_criterions]; 42 nsString mCrit[max_criterions]; 43 }; 44 45 struct CompareCacheHashEntryPtr : PLDHashEntryHdr { 46 CompareCacheHashEntryPtr(); 47 ~CompareCacheHashEntryPtr(); 48 CompareCacheHashEntry* entry; 49 }; 50 51 class nsCertTreeDispInfo : public nsICertTreeItem { 52 protected: 53 virtual ~nsCertTreeDispInfo(); 54 55 public: 56 explicit nsCertTreeDispInfo(nsIX509Cert* aCert) : mCert(aCert) {} 57 58 NS_DECL_ISUPPORTS 59 NS_DECL_NSICERTTREEITEM 60 61 nsCOMPtr<nsIX509Cert> mCert; 62 }; 63 64 class nsCertTree : public nsICertTree { 65 public: 66 NS_DECL_ISUPPORTS 67 NS_DECL_NSICERTTREE 68 NS_DECL_NSITREEVIEW 69 70 nsCertTree(); 71 72 enum sortCriterion { 73 sort_IssuerOrg, 74 sort_Org, 75 sort_Token, 76 sort_CommonName, 77 sort_IssuedDateDescending, 78 sort_Email, 79 sort_None 80 }; 81 82 protected: 83 virtual ~nsCertTree(); 84 85 void ClearCompareHash(); 86 void RemoveCacheEntry(void* key); 87 88 typedef int (*nsCertCompareFunc)(void*, nsIX509Cert* a, nsIX509Cert* b); 89 90 static CompareCacheHashEntry* getCacheEntry(void* cache, void* aCert); 91 static void CmpInitCriterion(nsIX509Cert* cert, CompareCacheHashEntry* entry, 92 sortCriterion crit, int32_t level); 93 static int32_t CmpByCrit(nsIX509Cert* a, CompareCacheHashEntry* ace, 94 nsIX509Cert* b, CompareCacheHashEntry* bce, 95 sortCriterion crit, int32_t level); 96 static int32_t CmpBy(void* cache, nsIX509Cert* a, nsIX509Cert* b, 97 sortCriterion c0, sortCriterion c1, sortCriterion c2); 98 static int32_t CmpCACert(void* cache, nsIX509Cert* a, nsIX509Cert* b); 99 static int32_t CmpUserCert(void* cache, nsIX509Cert* a, nsIX509Cert* b); 100 static int32_t CmpEmailCert(void* cache, nsIX509Cert* a, nsIX509Cert* b); 101 nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType); 102 int32_t CountOrganizations(); 103 104 private: 105 static const uint32_t kInitialCacheLength = 64; 106 107 nsTArray<RefPtr<nsCertTreeDispInfo>> mDispInfo; 108 RefPtr<mozilla::dom::XULTreeElement> mTree; 109 nsCOMPtr<nsITreeSelection> mSelection; 110 treeArrayEl* mTreeArray; 111 int32_t mNumOrgs; 112 int32_t mNumRows; 113 PLDHashTable mCompareCache; 114 115 treeArrayEl* GetThreadDescAtIndex(int32_t _index); 116 already_AddRefed<nsIX509Cert> GetCertAtIndex( 117 int32_t _index, int32_t* outAbsoluteCertOffset = nullptr); 118 already_AddRefed<nsCertTreeDispInfo> GetDispInfoAtIndex( 119 int32_t index, int32_t* outAbsoluteCertOffset = nullptr); 120 void FreeCertArray(); 121 nsresult UpdateUIContents(); 122 123 nsresult GetCertsByTypeFromCertList( 124 const nsTArray<RefPtr<nsIX509Cert>>& aCertList, uint32_t aWantedType, 125 nsCertCompareFunc aCertCmpFn, void* aCertCmpFnArg); 126 127 nsCOMPtr<nsIMutableArray> mCellText; 128 }; 129 130 #endif /* _NS_CERTTREE_H_ */