Bug 1552059 - Port bug 1551657: Adapt to array changes of nsILoginManager.findLogins, C++ part. r=benc
authorJorg K <jorgk@jorgk.com>
Thu, 16 May 2019 02:00:14 +0200
changeset 26618 f2aa9a4e1426738e9c21363660bba4fa453e8f3e
parent 26617 5806b067a6a1277fb418ac27b88fbaf062de0a52
child 26619 f0afd7103595c78dae5ee9ec3ccb0c8d5dfeb610
push id15923
push usergeoff@darktrojan.net
push dateThu, 16 May 2019 01:22:28 +0000
treeherdercomm-central@f0afd7103595 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc
bugs1552059, 1551657
Bug 1552059 - Port bug 1551657: Adapt to array changes of nsILoginManager.findLogins, C++ part. r=benc
mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
mailnews/base/util/nsMsgIncomingServer.cpp
mailnews/compose/src/nsSmtpServer.cpp
mailnews/news/src/nsNewsFolder.cpp
--- a/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPListenerBase.cpp
@@ -303,34 +303,29 @@ nsresult nsAbLDAPListenerBase::OnLDAPMes
       nsCString spec;
       rv = mDirectoryUrl->GetSpec(spec);
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCString prePath;
       rv = mDirectoryUrl->GetPrePath(prePath);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      uint32_t count;
-      nsILoginInfo **logins;
-
-      rv = loginMgr->FindLogins(&count, NS_ConvertUTF8toUTF16(prePath),
-                                EmptyString(), NS_ConvertUTF8toUTF16(spec),
-                                &logins);
+      nsTArray<RefPtr<nsILoginInfo>> logins;
+      rv = loginMgr->FindLogins(NS_ConvertUTF8toUTF16(prePath), EmptyString(),
+                                NS_ConvertUTF8toUTF16(spec), logins);
       NS_ENSURE_SUCCESS(rv, rv);
 
       // Typically there should only be one-login stored for this url, however,
       // just in case there isn't.
-      for (uint32_t i = 0; i < count; ++i) {
+      for (uint32_t i = 0; i < logins.Length(); ++i) {
         rv = loginMgr->RemoveLogin(logins[i]);
         if (NS_FAILED(rv)) {
-          NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
           return rv;
         }
       }
-      NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
 
       // XXX We should probably pop up an error dialog telling
       // the user that the login failed here, rather than just bringing
       // up the password dialog again, which is what calling OnLDAPInit()
       // does.
       return OnLDAPInit(nullptr, NS_OK);
     }
 
--- a/mailnews/base/util/nsMsgIncomingServer.cpp
+++ b/mailnews/base/util/nsMsgIncomingServer.cpp
@@ -614,25 +614,24 @@ nsresult nsMsgIncomingServer::GetPasswor
   nsCString temp;
   rv = GetHostName(temp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   currServerUri.Append(temp);
 
   NS_ConvertUTF8toUTF16 currServer(currServerUri);
 
-  uint32_t numLogins = 0;
-  nsILoginInfo **logins = nullptr;
-  rv = loginMgr->FindLogins(&numLogins, currServer, EmptyString(), currServer,
-                            &logins);
+  nsTArray<RefPtr<nsILoginInfo>> logins;
+  rv = loginMgr->FindLogins(currServer, EmptyString(), currServer, logins);
 
   // Login manager can produce valid fails, e.g. NS_ERROR_ABORT when a user
   // cancels the master password dialog. Therefore handle that here, but don't
   // warn about it.
   if (NS_FAILED(rv)) return rv;
+  uint32_t numLogins = logins.Length();
 
   // Don't abort here, if we didn't find any or failed, then we'll just have
   // to prompt.
   if (numLogins > 0) {
     nsCString serverCUsername;
     rv = GetUsername(serverCUsername);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -647,17 +646,16 @@ nsresult nsMsgIncomingServer::GetPasswor
         nsString password;
         rv = logins[i]->GetPassword(password);
         NS_ENSURE_SUCCESS(rv, rv);
 
         m_password = password;
         break;
       }
     }
-    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::GetPasswordWithUI(const nsAString &aPromptMessage,
                                        const nsAString &aPromptTitle,
                                        nsIMsgWindow *aMsgWindow,
@@ -752,43 +750,39 @@ nsMsgIncomingServer::ForgetPassword() {
   currServerUri.AppendLiteral("://");
 
   nsCString temp;
   rv = GetHostName(temp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   currServerUri.Append(temp);
 
-  uint32_t count;
-  nsILoginInfo **logins;
-
   NS_ConvertUTF8toUTF16 currServer(currServerUri);
 
   nsCString serverCUsername;
   rv = GetUsername(serverCUsername);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF8toUTF16 serverUsername(serverCUsername);
 
-  rv = loginMgr->FindLogins(&count, currServer, EmptyString(), currServer,
-                            &logins);
+  nsTArray<RefPtr<nsILoginInfo>> logins;
+  rv = loginMgr->FindLogins(currServer, EmptyString(), currServer, logins);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // There should only be one-login stored for this url, however just in case
   // there isn't.
   nsString username;
-  for (uint32_t i = 0; i < count; ++i) {
+  for (uint32_t i = 0; i < logins.Length(); ++i) {
     if (NS_SUCCEEDED(logins[i]->GetUsername(username)) &&
         username.Equals(serverUsername)) {
       // If this fails, just continue, we'll still want to remove the password
       // from our local cache.
       loginMgr->RemoveLogin(logins[i]);
     }
   }
-  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
 
   return SetPassword(EmptyString());
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::ForgetSessionPassword() {
   m_password.Truncate();
   return NS_OK;
--- a/mailnews/compose/src/nsSmtpServer.cpp
+++ b/mailnews/compose/src/nsSmtpServer.cpp
@@ -385,24 +385,23 @@ nsSmtpServer::SetPassword(const nsAStrin
 nsresult nsSmtpServer::GetPasswordWithoutUI() {
   nsresult rv;
   nsCOMPtr<nsILoginManager> loginMgr(
       do_GetService(NS_LOGINMANAGER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertASCIItoUTF16 serverUri(GetServerURIInternal(false));
 
-  uint32_t numLogins = 0;
-  nsILoginInfo **logins = nullptr;
-  rv = loginMgr->FindLogins(&numLogins, serverUri, EmptyString(), serverUri,
-                            &logins);
+  nsTArray<RefPtr<nsILoginInfo>> logins;
+  rv = loginMgr->FindLogins(serverUri, EmptyString(), serverUri, logins);
   // Login manager can produce valid fails, e.g. NS_ERROR_ABORT when a user
   // cancels the master password dialog. Therefore handle that here, but don't
   // warn about it.
   if (NS_FAILED(rv)) return rv;
+  uint32_t numLogins = logins.Length();
 
   // Don't abort here, if we didn't find any or failed, then we'll just have
   // to prompt.
   if (numLogins > 0) {
     nsCString serverCUsername;
     rv = GetUsername(serverCUsername);
     NS_ConvertASCIItoUTF16 serverUsername(serverCUsername);
 
@@ -416,17 +415,16 @@ nsresult nsSmtpServer::GetPasswordWithou
         rv = logins[i]->GetPassword(password);
         NS_ENSURE_SUCCESS(rv, rv);
 
         m_password = password;
         break;
       }
     }
   }
-  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::GetPasswordWithUI(const char16_t *aPromptMessage,
                                 const char16_t *aPromptTitle,
                                 nsIAuthPrompt *aDialog, nsAString &aPassword) {
   if (!m_password.IsEmpty()) return GetPassword(aPassword);
@@ -531,43 +529,39 @@ nsSmtpServer::ForgetPassword() {
 
   if (NS_SUCCEEDED(rv) && !hostname.IsEmpty()) {
     nsCString escapedHostname;
     MsgEscapeString(hostname, nsINetUtil::ESCAPE_URL_PATH, escapedHostname);
     // not all servers have a hostname
     serverUri.Append(escapedHostname);
   }
 
-  uint32_t count;
-  nsILoginInfo **logins;
-
   NS_ConvertUTF8toUTF16 currServer(serverUri);
 
   nsCString serverCUsername;
   rv = GetUsername(serverCUsername);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF8toUTF16 serverUsername(serverCUsername);
 
-  rv = loginMgr->FindLogins(&count, currServer, EmptyString(), currServer,
-                            &logins);
+  nsTArray<RefPtr<nsILoginInfo>> logins;
+  rv = loginMgr->FindLogins(currServer, EmptyString(), currServer, logins);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // There should only be one-login stored for this url, however just in case
   // there isn't.
   nsString username;
-  for (uint32_t i = 0; i < count; ++i) {
+  for (uint32_t i = 0; i < logins.Length(); ++i) {
     if (NS_SUCCEEDED(logins[i]->GetUsername(username)) &&
         username.Equals(serverUsername)) {
       // If this fails, just continue, we'll still want to remove the password
       // from our local cache.
       loginMgr->RemoveLogin(logins[i]);
     }
   }
-  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
 
   rv = SetPassword(EmptyString());
   m_logonFailed = true;
   return rv;
 }
 
 NS_IMETHODIMP
 nsSmtpServer::GetServerURI(nsACString &aResult) {
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -1070,32 +1070,29 @@ nsMsgNewsFolder::GetAuthenticationCreden
 
   // If we don't have a username or password, try to load it via the login mgr.
   // Do this even if mustPrompt is true, to prefill the dialog.
   if (mGroupUsername.IsEmpty() || mGroupPassword.IsEmpty()) {
     nsCOMPtr<nsILoginManager> loginMgr =
         do_GetService(NS_LOGINMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    uint32_t numLogins = 0;
-    nsILoginInfo **logins = nullptr;
-    rv = loginMgr->FindLogins(&numLogins, signonUrl, EmptyString(), signonUrl,
-                              &logins);
+    nsTArray<RefPtr<nsILoginInfo>> logins;
+    rv = loginMgr->FindLogins(signonUrl, EmptyString(), signonUrl, logins);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (numLogins > 0) {
+    if (logins.Length() > 0) {
       nsString uniUsername, uniPassword;
       logins[0]->GetUsername(uniUsername);
       logins[0]->GetPassword(uniPassword);
       mGroupUsername = NS_LossyConvertUTF16toASCII(uniUsername);
       mGroupPassword = NS_LossyConvertUTF16toASCII(uniPassword);
 
       *validCredentials = true;
     }
-    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
   }
 
   // Show the prompt if we need to
   if (mustPrompt ||
       (mayPrompt && (mGroupUsername.IsEmpty() || mGroupPassword.IsEmpty()))) {
     nsCOMPtr<nsIAuthPrompt> dialog;
     if (aMsgWindow) {
       rv = aMsgWindow->GetAuthPrompt(getter_AddRefs(dialog));
@@ -1178,27 +1175,23 @@ NS_IMETHODIMP nsMsgNewsFolder::ForgetAut
   nsString signonUrl;
   nsresult rv = CreateNewsgroupUrlForSignon(nullptr, signonUrl);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoginManager> loginMgr =
       do_GetService(NS_LOGINMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  uint32_t count;
-  nsILoginInfo **logins;
-
-  rv = loginMgr->FindLogins(&count, signonUrl, EmptyString(), signonUrl,
-                            &logins);
+  nsTArray<RefPtr<nsILoginInfo>> logins;
+  rv = loginMgr->FindLogins(signonUrl, EmptyString(), signonUrl, logins);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // There should only be one-login stored for this url, however just in case
   // there isn't.
-  for (uint32_t i = 0; i < count; ++i) loginMgr->RemoveLogin(logins[i]);
-  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
+  for (uint32_t i = 0; i < logins.Length(); ++i) loginMgr->RemoveLogin(logins[i]);
 
   // Clear out the saved passwords for anyone else who tries to call.
   mGroupUsername.Truncate();
   mGroupPassword.Truncate();
 
   return NS_OK;
 }