Bug 666516. Stop casting things gotten by contract to concrete classes. r=kaie
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 23 Aug 2011 17:03:02 -0400
changeset 75778 9c84cf6b4d2c63c67ca581cd7bde68ebcb567e29
parent 75777 5afcb349cb1cda0c930b94a8f47c5a652d931647
child 75779 a0d3c755b289e02fe4c7cc90fbae3a60efca6341
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerskaie
bugs666516
milestone9.0a1
Bug 666516. Stop casting things gotten by contract to concrete classes. r=kaie
security/manager/ssl/src/nsCertTree.cpp
security/manager/ssl/src/nsCertTree.h
--- a/security/manager/ssl/src/nsCertTree.cpp
+++ b/security/manager/ssl/src/nsCertTree.cpp
@@ -60,16 +60,17 @@
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gPIPNSSLog;
 #endif
 
 #include "nsNSSCleaner.h"
 NSSCleanupAutoPtrClass(CERTCertificate, CERT_DestroyCertificate)
 
 static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
+static NS_DEFINE_CID(kCertOverrideCID, NS_CERTOVERRIDE_CID);
 
 // treeArrayElStr
 //
 // structure used to hold map of tree.  Each thread (an organization
 // field from a cert) has an element in the array.  The numChildren field
 // stores the number of certs corresponding to that thread.
 struct treeArrayElStr {
   nsString   orgName;     /* heading for thread                   */
@@ -193,16 +194,21 @@ nsCertTreeDispInfo::GetHostPort(nsAStrin
 
 NS_IMPL_ISUPPORTS2(nsCertTree, nsICertTree, nsITreeView)
 
 nsCertTree::nsCertTree() : mTreeArray(NULL)
 {
   mCompareCache.ops = nsnull;
   mNSSComponent = do_GetService(kNSSComponentCID);
   mOverrideService = do_GetService("@mozilla.org/security/certoverride;1");
+  // Might be a different service if someone is overriding the contract
+  nsCOMPtr<nsICertOverrideService> origCertOverride =
+    do_GetService(kCertOverrideCID);
+  mOriginalOverrideService =
+    static_cast<nsCertOverrideService*>(origCertOverride.get());
   mCellText = nsnull;
 }
 
 void nsCertTree::ClearCompareHash()
 {
   if (mCompareCache.ops) {
     PL_DHashTableFinish(&mCompareCache);
     mCompareCache.ops = nsnull;
@@ -480,29 +486,28 @@ nsCertTree::GetCertsByTypeFromCertList(C
                                        PRUint32 aWantedType,
                                        nsCertCompareFunc  aCertCmpFn,
                                        void *aCertCmpFnArg)
 {
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("GetCertsByTypeFromCertList"));
   if (!aCertList)
     return NS_ERROR_FAILURE;
 
-  nsCertOverrideService *cos = 
-    reinterpret_cast<nsCertOverrideService*>(mOverrideService.get());
-  if (!cos)
+  if (!mOriginalOverrideService)
     return NS_ERROR_FAILURE;
 
   nsTHashtable<nsCStringHashKey> allHostPortOverrideKeys;
   if (!allHostPortOverrideKeys.Init())
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (aWantedType == nsIX509Cert::SERVER_CERT) {
-    cos->EnumerateCertOverrides(nsnull, 
-                                CollectAllHostPortOverridesCallback, 
-                                &allHostPortOverrideKeys);
+    mOriginalOverrideService->
+      EnumerateCertOverrides(nsnull, 
+                             CollectAllHostPortOverridesCallback, 
+                             &allHostPortOverrideKeys);
   }
 
   CERTCertListNode *node;
   int count = 0;
   for (node = CERT_LIST_HEAD(aCertList);
        !CERT_LIST_END(node, aCertList);
        node = CERT_LIST_NEXT(node)) {
 
@@ -632,37 +637,39 @@ nsCertTree::GetCertsByTypeFromCertList(C
         certdi->mTypeOfEntry = nsCertTreeDispInfo::direct_db;
         // not necessary: certdi->mAsciiHost.Clear(); certdi->mPort = -1;
         certdi->mOverrideBits = nsCertOverride::ob_None;
         certdi->mIsTemporary = PR_FALSE;
         mDispInfo.InsertElementAt(InsertPosition, certdi);
         ++count;
         ++InsertPosition;
       }
-      if (addOverrides && cos) {
+      if (addOverrides) {
         nsCertAndArrayAndPositionAndCounterAndTracker cap;
         cap.certai = certai;
         cap.array = &mDispInfo;
         cap.position = InsertPosition;
         cap.counter = 0;
         cap.tracker = &allHostPortOverrideKeys;
 
-        cos->EnumerateCertOverrides(pipCert, MatchingCertOverridesCallback, &cap);
+        mOriginalOverrideService->
+          EnumerateCertOverrides(pipCert, MatchingCertOverridesCallback, &cap);
         count += cap.counter;
       }
     }
   }
 
   if (aWantedType == nsIX509Cert::SERVER_CERT) {
     nsArrayAndPositionAndCounterAndTracker cap;
     cap.array = &mDispInfo;
     cap.position = 0;
     cap.counter = 0;
     cap.tracker = &allHostPortOverrideKeys;
-    cos->EnumerateCertOverrides(nsnull, AddRemaningHostPortOverridesCallback, &cap);
+    mOriginalOverrideService->
+      EnumerateCertOverrides(nsnull, AddRemaningHostPortOverridesCallback, &cap);
   }
 
   return NS_OK;
 }
 
 nsresult 
 nsCertTree::GetCertsByType(PRUint32           aType,
                            nsCertCompareFunc  aCertCmpFn,
--- a/security/manager/ssl/src/nsCertTree.h
+++ b/security/manager/ssl/src/nsCertTree.h
@@ -150,16 +150,17 @@ private:
   nsCOMPtr<nsITreeBoxObject>  mTree;
   nsCOMPtr<nsITreeSelection>  mSelection;
   treeArrayEl                *mTreeArray;
   PRInt32                         mNumOrgs;
   PRInt32                         mNumRows;
   PLDHashTable mCompareCache;
   nsCOMPtr<nsINSSComponent> mNSSComponent;
   nsCOMPtr<nsICertOverrideService> mOverrideService;
+  nsRefPtr<nsCertOverrideService> mOriginalOverrideService;
 
   treeArrayEl *GetThreadDescAtIndex(PRInt32 _index);
   already_AddRefed<nsIX509Cert> 
     GetCertAtIndex(PRInt32 _index, PRInt32 *outAbsoluteCertOffset = nsnull);
   already_AddRefed<nsCertTreeDispInfo> 
     GetDispInfoAtIndex(PRInt32 index, PRInt32 *outAbsoluteCertOffset = nsnull);
   void FreeCertArray();
   nsresult UpdateUIContents();