bug 1424392 - remove unnecessary nsINSSComponent usage in nsNSSCallbacks r=mgoodwin
authorDavid Keeler <dkeeler@mozilla.com>
Fri, 08 Dec 2017 14:07:04 -0800
changeset 396405 f8d18d87288cbc3657b6a38d7449d4d36365e048
parent 396404 8cbcc8b4fa5736f170fffedd2f99f1aa63fb4f0f
child 396406 1e60dbbef9973cccdaabfec0b40ee27be873a9da
push id56986
push userdkeeler@mozilla.com
push dateThu, 14 Dec 2017 15:54:00 +0000
treeherderautoland@f8d18d87288c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgoodwin
bugs1424392
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1424392 - remove unnecessary nsINSSComponent usage in nsNSSCallbacks r=mgoodwin PK11PasswordPromptRunnable::RunOnTargetThread instantiates nsINSSComponent and calls GetPIPNSSBundleString/PIPBundleFormatStringFromName to get some localized strings. Since that runs on the main thread, we can call the helpers in nsNSSCertHelper instead. MozReview-Commit-ID: GsHoGDKBKdB
security/manager/ssl/nsNSSCallbacks.cpp
security/manager/ssl/nsNSSCertHelper.cpp
security/manager/ssl/nsNSSCertHelper.h
--- a/security/manager/ssl/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/nsNSSCallbacks.cpp
@@ -19,16 +19,17 @@
 #include "nsContentUtils.h"
 #include "nsICertOverrideService.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIPrompt.h"
 #include "nsISupportsPriority.h"
 #include "nsITokenDialogs.h"
 #include "nsIUploadChannel.h"
 #include "nsIWebProgressListener.h"
+#include "nsNSSCertHelper.h"
 #include "nsNSSCertificate.h"
 #include "nsNSSComponent.h"
 #include "nsNSSIOLayer.h"
 #include "nsNetUtil.h"
 #include "nsProtectedAuthThread.h"
 #include "nsProxyRelease.h"
 #include "nsStringStream.h"
 #include "pkix/pkixtypes.h"
@@ -758,18 +759,16 @@ PK11PasswordPromptRunnable::~PK11Passwor
   }
 
   shutdown(ShutdownCalledFrom::Object);
 }
 
 void
 PK11PasswordPromptRunnable::RunOnTargetThread()
 {
-  static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
-
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return;
   }
 
   nsresult rv;
   nsCOMPtr<nsIPrompt> prompt;
   if (!mIR) {
@@ -786,34 +785,27 @@ PK11PasswordPromptRunnable::RunOnTargetT
     return;
   }
 
   if (PK11_ProtectedAuthenticationPath(mSlot)) {
     mResult = ShowProtectedAuthPrompt(mSlot, mIR);
     return;
   }
 
-  nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID));
-  if (!nssComponent) {
-    return;
-  }
-
   nsAutoString promptString;
   if (PK11_IsInternal(mSlot)) {
-    rv = nssComponent->GetPIPNSSBundleString("CertPassPromptDefault",
-                                             promptString);
+    rv = GetPIPNSSBundleString("CertPassPromptDefault", promptString);
   } else {
     NS_ConvertUTF8toUTF16 tokenName(PK11_GetTokenName(mSlot));
     const char16_t* formatStrings[] = {
       tokenName.get(),
     };
-    rv = nssComponent->PIPBundleFormatStringFromName("CertPassPrompt",
-                                                     formatStrings,
-                                                     ArrayLength(formatStrings),
-                                                     promptString);
+    rv = PIPBundleFormatStringFromName("CertPassPrompt", formatStrings,
+                                       ArrayLength(formatStrings),
+                                       promptString);
   }
   if (NS_FAILED(rv)) {
     return;
   }
 
   nsString password;
   // |checkState| is unused because |checkMsg| (the argument just before it) is
   // null, but XPConnect requires it to point to a valid bool nonetheless.
--- a/security/manager/ssl/nsNSSCertHelper.cpp
+++ b/security/manager/ssl/nsNSSCertHelper.cpp
@@ -104,17 +104,17 @@ GetPIPNSSBundleString(const char* string
   nsresult rv = GetPIPNSSBundle(getter_AddRefs(pipnssBundle));
   if (NS_FAILED(rv)) {
     return rv;
   }
   result.Truncate();
   return pipnssBundle->GetStringFromName(stringName, result);
 }
 
-static nsresult
+nsresult
 PIPBundleFormatStringFromName(const char* stringName, const char16_t** params,
                               uint32_t numParams, nsAString& result)
 {
   MOZ_ASSERT(stringName);
   MOZ_ASSERT(params);
   if (!stringName || !params) {
     return NS_ERROR_INVALID_ARG;
   }
--- a/security/manager/ssl/nsNSSCertHelper.h
+++ b/security/manager/ssl/nsNSSCertHelper.h
@@ -17,10 +17,13 @@ getCertType(CERTCertificate* cert);
 
 nsresult
 GetCertFingerprintByOidTag(CERTCertificate* nsscert, SECOidTag aOidTag,
                            nsCString& fp);
 
 // Must be used on the main thread only.
 nsresult
 GetPIPNSSBundleString(const char* stringName, nsAString& result);
+nsresult
+PIPBundleFormatStringFromName(const char* stringName, const char16_t** params,
+                              uint32_t numParams, nsAString& result);
 
 #endif // nsNSSCertHelper_h