nsCertTree.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #ifndef _NS_CERTTREE_H_
  5. #define _NS_CERTTREE_H_
  6. #include "nsCOMPtr.h"
  7. #include "nsIServiceManager.h"
  8. #include "nsICertTree.h"
  9. #include "nsITreeView.h"
  10. #include "nsITreeBoxObject.h"
  11. #include "nsITreeSelection.h"
  12. #include "nsIMutableArray.h"
  13. #include "nsNSSComponent.h"
  14. #include "nsTArray.h"
  15. #include "PLDHashTable.h"
  16. #include "nsIX509CertDB.h"
  17. #include "nsCertOverrideService.h"
  18. #include "mozilla/Attributes.h"
  19. typedef struct treeArrayElStr treeArrayEl;
  20. struct CompareCacheHashEntry {
  21. enum { max_criterions = 3 };
  22. CompareCacheHashEntry();
  23. void *key; // no ownership
  24. bool mCritInit[max_criterions];
  25. nsXPIDLString mCrit[max_criterions];
  26. };
  27. struct CompareCacheHashEntryPtr : PLDHashEntryHdr {
  28. CompareCacheHashEntryPtr();
  29. ~CompareCacheHashEntryPtr();
  30. CompareCacheHashEntry *entry;
  31. };
  32. class nsCertAddonInfo final : public nsISupports
  33. {
  34. private:
  35. ~nsCertAddonInfo() {}
  36. public:
  37. NS_DECL_ISUPPORTS
  38. nsCertAddonInfo() : mUsageCount(0) {}
  39. RefPtr<nsIX509Cert> mCert;
  40. // how many display entries reference this?
  41. // (and therefore depend on the underlying cert)
  42. int32_t mUsageCount;
  43. };
  44. class nsCertTreeDispInfo : public nsICertTreeItem
  45. {
  46. protected:
  47. virtual ~nsCertTreeDispInfo();
  48. public:
  49. NS_DECL_ISUPPORTS
  50. NS_DECL_NSICERTTREEITEM
  51. nsCertTreeDispInfo();
  52. nsCertTreeDispInfo(nsCertTreeDispInfo &other);
  53. RefPtr<nsCertAddonInfo> mAddonInfo;
  54. enum {
  55. direct_db, host_port_override
  56. } mTypeOfEntry;
  57. nsCString mAsciiHost;
  58. int32_t mPort;
  59. nsCertOverride::OverrideBits mOverrideBits;
  60. bool mIsTemporary;
  61. nsCOMPtr<nsIX509Cert> mCert;
  62. };
  63. class nsCertTree : public nsICertTree
  64. {
  65. public:
  66. NS_DECL_ISUPPORTS
  67. NS_DECL_NSICERTTREE
  68. NS_DECL_NSITREEVIEW
  69. nsCertTree();
  70. enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token,
  71. sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None };
  72. protected:
  73. virtual ~nsCertTree();
  74. void ClearCompareHash();
  75. void RemoveCacheEntry(void *key);
  76. typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b);
  77. static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert);
  78. static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry,
  79. sortCriterion crit, int32_t level);
  80. static int32_t CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace,
  81. nsIX509Cert *b, CompareCacheHashEntry *bce,
  82. sortCriterion crit, int32_t level);
  83. static int32_t CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b,
  84. sortCriterion c0, sortCriterion c1, sortCriterion c2);
  85. static int32_t CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
  86. static int32_t CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
  87. static int32_t CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
  88. static int32_t CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
  89. nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType);
  90. int32_t CountOrganizations();
  91. nsresult GetCertsByType(uint32_t aType, nsCertCompareFunc aCertCmpFn,
  92. void *aCertCmpFnArg);
  93. nsresult GetCertsByTypeFromCache(nsIX509CertList *aCache, uint32_t aType,
  94. nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg);
  95. private:
  96. static const uint32_t kInitialCacheLength = 64;
  97. nsTArray< RefPtr<nsCertTreeDispInfo> > mDispInfo;
  98. nsCOMPtr<nsITreeBoxObject> mTree;
  99. nsCOMPtr<nsITreeSelection> mSelection;
  100. treeArrayEl *mTreeArray;
  101. int32_t mNumOrgs;
  102. int32_t mNumRows;
  103. PLDHashTable mCompareCache;
  104. nsCOMPtr<nsINSSComponent> mNSSComponent;
  105. nsCOMPtr<nsICertOverrideService> mOverrideService;
  106. RefPtr<nsCertOverrideService> mOriginalOverrideService;
  107. treeArrayEl *GetThreadDescAtIndex(int32_t _index);
  108. already_AddRefed<nsIX509Cert>
  109. GetCertAtIndex(int32_t _index, int32_t *outAbsoluteCertOffset = nullptr);
  110. already_AddRefed<nsCertTreeDispInfo>
  111. GetDispInfoAtIndex(int32_t index, int32_t *outAbsoluteCertOffset = nullptr);
  112. void FreeCertArray();
  113. nsresult UpdateUIContents();
  114. nsresult GetCertsByTypeFromCertList(CERTCertList *aCertList,
  115. uint32_t aType,
  116. nsCertCompareFunc aCertCmpFn,
  117. void *aCertCmpFnArg);
  118. nsCOMPtr<nsIMutableArray> mCellText;
  119. #ifdef DEBUG_CERT_TREE
  120. /* for debugging purposes */
  121. void dumpMap();
  122. #endif
  123. };
  124. #endif /* _NS_CERTTREE_H_ */