michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _NS_CERTTREE_H_ michael@0: #define _NS_CERTTREE_H_ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsICertTree.h" michael@0: #include "nsITreeView.h" michael@0: #include "nsITreeBoxObject.h" michael@0: #include "nsITreeSelection.h" michael@0: #include "nsIMutableArray.h" michael@0: #include "nsNSSComponent.h" michael@0: #include "nsTArray.h" michael@0: #include "pldhash.h" michael@0: #include "nsIX509CertDB.h" michael@0: #include "nsCertOverrideService.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: typedef struct treeArrayElStr treeArrayEl; michael@0: michael@0: struct CompareCacheHashEntry { michael@0: enum { max_criterions = 3 }; michael@0: CompareCacheHashEntry(); michael@0: michael@0: void *key; // no ownership michael@0: bool mCritInit[max_criterions]; michael@0: nsXPIDLString mCrit[max_criterions]; michael@0: }; michael@0: michael@0: struct CompareCacheHashEntryPtr : PLDHashEntryHdr { michael@0: CompareCacheHashEntryPtr(); michael@0: ~CompareCacheHashEntryPtr(); michael@0: CompareCacheHashEntry *entry; michael@0: }; michael@0: michael@0: class nsCertAddonInfo MOZ_FINAL : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: nsCertAddonInfo() : mUsageCount(0) {} michael@0: michael@0: mozilla::RefPtr mCert; michael@0: // how many display entries reference this? michael@0: // (and therefore depend on the underlying cert) michael@0: int32_t mUsageCount; michael@0: }; michael@0: michael@0: class nsCertTreeDispInfo : public nsICertTreeItem michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSICERTTREEITEM michael@0: michael@0: nsCertTreeDispInfo(); michael@0: nsCertTreeDispInfo(nsCertTreeDispInfo &other); michael@0: virtual ~nsCertTreeDispInfo(); michael@0: michael@0: mozilla::RefPtr mAddonInfo; michael@0: enum { michael@0: direct_db, host_port_override michael@0: } mTypeOfEntry; michael@0: nsCString mAsciiHost; michael@0: int32_t mPort; michael@0: nsCertOverride::OverrideBits mOverrideBits; michael@0: bool mIsTemporary; michael@0: nsCOMPtr mCert; michael@0: }; michael@0: michael@0: class nsCertTree : public nsICertTree michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSICERTTREE michael@0: NS_DECL_NSITREEVIEW michael@0: michael@0: nsCertTree(); michael@0: virtual ~nsCertTree(); michael@0: michael@0: enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token, michael@0: sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None }; michael@0: michael@0: protected: michael@0: nsresult InitCompareHash(); michael@0: void ClearCompareHash(); michael@0: void RemoveCacheEntry(void *key); michael@0: michael@0: typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b); michael@0: michael@0: static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert); michael@0: static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry, michael@0: sortCriterion crit, int32_t level); michael@0: static int32_t CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace, michael@0: nsIX509Cert *b, CompareCacheHashEntry *bce, michael@0: sortCriterion crit, int32_t level); michael@0: static int32_t CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b, michael@0: sortCriterion c0, sortCriterion c1, sortCriterion c2); michael@0: static int32_t CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b); michael@0: static int32_t CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); michael@0: static int32_t CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); michael@0: static int32_t CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); michael@0: nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType); michael@0: int32_t CountOrganizations(); michael@0: michael@0: nsresult GetCertsByType(uint32_t aType, nsCertCompareFunc aCertCmpFn, michael@0: void *aCertCmpFnArg); michael@0: michael@0: nsresult GetCertsByTypeFromCache(nsINSSCertCache *aCache, uint32_t aType, michael@0: nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg); michael@0: private: michael@0: nsTArray< mozilla::RefPtr > mDispInfo; michael@0: nsCOMPtr mTree; michael@0: nsCOMPtr mSelection; michael@0: treeArrayEl *mTreeArray; michael@0: int32_t mNumOrgs; michael@0: int32_t mNumRows; michael@0: PLDHashTable mCompareCache; michael@0: nsCOMPtr mNSSComponent; michael@0: nsCOMPtr mOverrideService; michael@0: mozilla::RefPtr mOriginalOverrideService; michael@0: michael@0: treeArrayEl *GetThreadDescAtIndex(int32_t _index); michael@0: already_AddRefed michael@0: GetCertAtIndex(int32_t _index, int32_t *outAbsoluteCertOffset = nullptr); michael@0: mozilla::TemporaryRef michael@0: GetDispInfoAtIndex(int32_t index, int32_t *outAbsoluteCertOffset = nullptr); michael@0: void FreeCertArray(); michael@0: nsresult UpdateUIContents(); michael@0: michael@0: nsresult GetCertsByTypeFromCertList(CERTCertList *aCertList, michael@0: uint32_t aType, michael@0: nsCertCompareFunc aCertCmpFn, michael@0: void *aCertCmpFnArg); michael@0: michael@0: nsCOMPtr mCellText; michael@0: michael@0: #ifdef DEBUG_CERT_TREE michael@0: /* for debugging purposes */ michael@0: void dumpMap(); michael@0: #endif michael@0: }; michael@0: michael@0: #endif /* _NS_CERTTREE_H_ */ michael@0: