1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/nsCertTree.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,147 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef _NS_CERTTREE_H_ 1.9 +#define _NS_CERTTREE_H_ 1.10 + 1.11 +#include "nsCOMPtr.h" 1.12 +#include "nsIServiceManager.h" 1.13 +#include "nsICertTree.h" 1.14 +#include "nsITreeView.h" 1.15 +#include "nsITreeBoxObject.h" 1.16 +#include "nsITreeSelection.h" 1.17 +#include "nsIMutableArray.h" 1.18 +#include "nsNSSComponent.h" 1.19 +#include "nsTArray.h" 1.20 +#include "pldhash.h" 1.21 +#include "nsIX509CertDB.h" 1.22 +#include "nsCertOverrideService.h" 1.23 +#include "mozilla/Attributes.h" 1.24 + 1.25 +typedef struct treeArrayElStr treeArrayEl; 1.26 + 1.27 +struct CompareCacheHashEntry { 1.28 + enum { max_criterions = 3 }; 1.29 + CompareCacheHashEntry(); 1.30 + 1.31 + void *key; // no ownership 1.32 + bool mCritInit[max_criterions]; 1.33 + nsXPIDLString mCrit[max_criterions]; 1.34 +}; 1.35 + 1.36 +struct CompareCacheHashEntryPtr : PLDHashEntryHdr { 1.37 + CompareCacheHashEntryPtr(); 1.38 + ~CompareCacheHashEntryPtr(); 1.39 + CompareCacheHashEntry *entry; 1.40 +}; 1.41 + 1.42 +class nsCertAddonInfo MOZ_FINAL : public nsISupports 1.43 +{ 1.44 +public: 1.45 + NS_DECL_ISUPPORTS 1.46 + 1.47 + nsCertAddonInfo() : mUsageCount(0) {} 1.48 + 1.49 + mozilla::RefPtr<nsIX509Cert> mCert; 1.50 + // how many display entries reference this? 1.51 + // (and therefore depend on the underlying cert) 1.52 + int32_t mUsageCount; 1.53 +}; 1.54 + 1.55 +class nsCertTreeDispInfo : public nsICertTreeItem 1.56 +{ 1.57 +public: 1.58 + NS_DECL_ISUPPORTS 1.59 + NS_DECL_NSICERTTREEITEM 1.60 + 1.61 + nsCertTreeDispInfo(); 1.62 + nsCertTreeDispInfo(nsCertTreeDispInfo &other); 1.63 + virtual ~nsCertTreeDispInfo(); 1.64 + 1.65 + mozilla::RefPtr<nsCertAddonInfo> mAddonInfo; 1.66 + enum { 1.67 + direct_db, host_port_override 1.68 + } mTypeOfEntry; 1.69 + nsCString mAsciiHost; 1.70 + int32_t mPort; 1.71 + nsCertOverride::OverrideBits mOverrideBits; 1.72 + bool mIsTemporary; 1.73 + nsCOMPtr<nsIX509Cert> mCert; 1.74 +}; 1.75 + 1.76 +class nsCertTree : public nsICertTree 1.77 +{ 1.78 +public: 1.79 + NS_DECL_ISUPPORTS 1.80 + NS_DECL_NSICERTTREE 1.81 + NS_DECL_NSITREEVIEW 1.82 + 1.83 + nsCertTree(); 1.84 + virtual ~nsCertTree(); 1.85 + 1.86 + enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token, 1.87 + sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None }; 1.88 + 1.89 +protected: 1.90 + nsresult InitCompareHash(); 1.91 + void ClearCompareHash(); 1.92 + void RemoveCacheEntry(void *key); 1.93 + 1.94 + typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b); 1.95 + 1.96 + static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert); 1.97 + static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry, 1.98 + sortCriterion crit, int32_t level); 1.99 + static int32_t CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace, 1.100 + nsIX509Cert *b, CompareCacheHashEntry *bce, 1.101 + sortCriterion crit, int32_t level); 1.102 + static int32_t CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b, 1.103 + sortCriterion c0, sortCriterion c1, sortCriterion c2); 1.104 + static int32_t CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b); 1.105 + static int32_t CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); 1.106 + static int32_t CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); 1.107 + static int32_t CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); 1.108 + nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType); 1.109 + int32_t CountOrganizations(); 1.110 + 1.111 + nsresult GetCertsByType(uint32_t aType, nsCertCompareFunc aCertCmpFn, 1.112 + void *aCertCmpFnArg); 1.113 + 1.114 + nsresult GetCertsByTypeFromCache(nsINSSCertCache *aCache, uint32_t aType, 1.115 + nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg); 1.116 +private: 1.117 + nsTArray< mozilla::RefPtr<nsCertTreeDispInfo> > mDispInfo; 1.118 + nsCOMPtr<nsITreeBoxObject> mTree; 1.119 + nsCOMPtr<nsITreeSelection> mSelection; 1.120 + treeArrayEl *mTreeArray; 1.121 + int32_t mNumOrgs; 1.122 + int32_t mNumRows; 1.123 + PLDHashTable mCompareCache; 1.124 + nsCOMPtr<nsINSSComponent> mNSSComponent; 1.125 + nsCOMPtr<nsICertOverrideService> mOverrideService; 1.126 + mozilla::RefPtr<nsCertOverrideService> mOriginalOverrideService; 1.127 + 1.128 + treeArrayEl *GetThreadDescAtIndex(int32_t _index); 1.129 + already_AddRefed<nsIX509Cert> 1.130 + GetCertAtIndex(int32_t _index, int32_t *outAbsoluteCertOffset = nullptr); 1.131 + mozilla::TemporaryRef<nsCertTreeDispInfo> 1.132 + GetDispInfoAtIndex(int32_t index, int32_t *outAbsoluteCertOffset = nullptr); 1.133 + void FreeCertArray(); 1.134 + nsresult UpdateUIContents(); 1.135 + 1.136 + nsresult GetCertsByTypeFromCertList(CERTCertList *aCertList, 1.137 + uint32_t aType, 1.138 + nsCertCompareFunc aCertCmpFn, 1.139 + void *aCertCmpFnArg); 1.140 + 1.141 + nsCOMPtr<nsIMutableArray> mCellText; 1.142 + 1.143 +#ifdef DEBUG_CERT_TREE 1.144 + /* for debugging purposes */ 1.145 + void dumpMap(); 1.146 +#endif 1.147 +}; 1.148 + 1.149 +#endif /* _NS_CERTTREE_H_ */ 1.150 +