Bug 1432204 - replace SetSpecInteral() on stardard URL. r=aceman
authorJorg K <jorgk@jorgk.com>
Tue, 23 Jan 2018 09:19:43 +0100
changeset 30938 941a1c2bda737375f1c3040e99d1a59531c4129f
parent 30937 68c02fba54d279de77b2a35db77522f9f5b381a0
child 30939 459b4030d2c9ee173f386e9b1bc2b1b68a8efbb8
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersaceman
bugs1432204
Bug 1432204 - replace SetSpecInteral() on stardard URL. r=aceman
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsMsgCopy.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsLocalUtils.cpp
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -66,16 +66,17 @@
 #include "nsIMsgFilterService.h"
 #include "nsDirectoryServiceUtils.h"
 #include "mozilla/Services.h"
 #include "nsMimeTypes.h"
 #include "nsIMsgFilter.h"
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "mozilla/intl/LocaleService.h"
+#include "nsIURIMutator.h"
 
 static PRTime gtimeOfLastPurgeCheck;    //variable to know when to check for purge_threshhold
 
 #define PREF_MAIL_PROMPT_PURGE_THRESHOLD "mail.prompt_purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD "mail.purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD_MB "mail.purge_threshhold_mb"
 #define PREF_MAIL_PURGE_MIGRATED "mail.purge_threshold_migrated"
 #define PREF_MAIL_PURGE_ASK "mail.purge.ask"
@@ -3124,22 +3125,19 @@ NS_IMETHODIMP nsMsgDBFolder::GetServer(n
   return *aServer ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsMsgDBFolder::parseURI(bool needServer)
 {
   nsresult rv;
   nsCOMPtr<nsIURL> url;
-
-  url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
+  rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(mURI).Finalize(url);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = url->SetSpecInternal(mURI);
-  NS_ENSURE_SUCCESS(rv, rv);
   // empty path tells us it's a server.
   if (!mIsServerIsValid)
   {
     nsAutoCString path;
     rv = url->GetPathQueryRef(path);
     if (NS_SUCCEEDED(rv))
       mIsServer = path.EqualsLiteral("/");
     mIsServerIsValid = true;
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -194,55 +194,53 @@ nsresult nsMsgMailNewsUrl::UnRegisterLis
 NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServer)
 {
   // mscott --> we could cache a copy of the server here....but if we did, we run
   // the risk of leaking the server if any single url gets leaked....of course that
   // shouldn't happen...but it could. so i'm going to look it up every time and
   // we can look at caching it later.
 
   nsresult rv;
+
   nsAutoCString urlstr;
-  nsAutoCString scheme;
-
-  nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) return rv;
-
   rv = m_baseURL->GetSpec(urlstr);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = url->SetSpecInternal(urlstr);
-  if (NS_FAILED(rv)) return rv;
-  rv = GetScheme(scheme);
-    if (NS_SUCCEEDED(rv))
-    {
-        if (scheme.EqualsLiteral("pop"))
-          scheme.AssignLiteral("pop3");
-        // we use "nntp" in the server list so translate it here.
-        if (scheme.EqualsLiteral("news"))
-          scheme.AssignLiteral("nntp");
-        url->SetScheme(scheme);
-        nsCOMPtr<nsIMsgAccountManager> accountManager =
-                 do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
-        if (NS_FAILED(rv)) return rv;
+
+  nsCOMPtr<nsIURL> url;
+  rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(urlstr).Finalize(url);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-        nsCOMPtr<nsIMsgIncomingServer> server;
-        rv = accountManager->FindServerByURI(url, false,
-                                        aIncomingServer);
-        if (!*aIncomingServer && scheme.EqualsLiteral("imap"))
-        {
-          // look for any imap server with this host name so clicking on
-          // other users folder urls will work. We could override this method
-          // for imap urls, or we could make caching of servers work and
-          // just set the server in the imap code for this case.
-          url->SetUserPass(EmptyCString());
-          rv = accountManager->FindServerByURI(url, false,
-                                          aIncomingServer);
-        }
+  nsAutoCString scheme;
+  rv = GetScheme(scheme);
+  if (NS_SUCCEEDED(rv))
+  {
+    if (scheme.EqualsLiteral("pop"))
+      scheme.AssignLiteral("pop3");
+    // we use "nntp" in the server list so translate it here.
+    if (scheme.EqualsLiteral("news"))
+      scheme.AssignLiteral("nntp");
+    url->SetScheme(scheme);
+    nsCOMPtr<nsIMsgAccountManager> accountManager =
+      do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
+    if (NS_FAILED(rv)) return rv;
+
+    nsCOMPtr<nsIMsgIncomingServer> server;
+    rv = accountManager->FindServerByURI(url, false, aIncomingServer);
+    if (!*aIncomingServer && scheme.EqualsLiteral("imap"))
+    {
+      // look for any imap server with this host name so clicking on
+      // other users folder urls will work. We could override this method
+      // for imap urls, or we could make caching of servers work and
+      // just set the server in the imap code for this case.
+      url->SetUserPass(EmptyCString());
+      rv = accountManager->FindServerByURI(url, false, aIncomingServer);
     }
+  }
 
-    return rv;
+  return rv;
 }
 
 NS_IMETHODIMP nsMsgMailNewsUrl::GetMsgWindow(nsIMsgWindow **aMsgWindow)
 {
   NS_ENSURE_ARG_POINTER(aMsgWindow);
   *aMsgWindow = nullptr;
 
   nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -30,16 +30,17 @@
 #include "nsNetUtil.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsComposeStrings.h"
 #include "nsIZipWriter.h"
 #include "nsIDirectoryEnumerator.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeEncoder.h"
 #include "nsIPrincipal.h"
+#include "nsIURIMutator.h"
 
 ///////////////////////////////////////////////////////////////////////////
 // Mac Specific Attachment Handling for AppleDouble Encoded Files
 ///////////////////////////////////////////////////////////////////////////
 #ifdef XP_MACOSX
 
 #define AD_WORKING_BUFF_SIZE FILE_IO_BUFFER_SIZE
 
@@ -848,39 +849,36 @@ nsMsgAttachmentHandler::ConvertToAppleEn
 
   FSRef fsRef;
   aSourceFile->GetFSRef(&fsRef);
   bool sendResourceFork = HasResourceFork(&fsRef);
 
   // if we have a resource fork, check the filename extension, maybe we don't need the resource fork!
   if (sendResourceFork)
   {
-    nsCOMPtr<nsIURL> fileUrl(do_CreateInstance(NS_STANDARDURL_CONTRACTID));
-    if (fileUrl)
+    nsCOMPtr<nsIURL> fileUrl;
+    rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(aFileURI).Finalize(fileUrl);
+    if (NS_SUCCEEDED(rv))
     {
-      rv = fileUrl->SetSpecInternal(aFileURI);
-      if (NS_SUCCEEDED(rv))
+      nsAutoCString ext;
+      rv = fileUrl->GetFileExtension(ext);
+      if (NS_SUCCEEDED(rv) && !ext.IsEmpty())
       {
-        nsAutoCString ext;
-        rv = fileUrl->GetFileExtension(ext);
-        if (NS_SUCCEEDED(rv) && !ext.IsEmpty())
-        {
-          sendResourceFork =
-          PL_strcasecmp(ext.get(), "TXT") &&
-          PL_strcasecmp(ext.get(), "JPG") &&
-          PL_strcasecmp(ext.get(), "GIF") &&
-          PL_strcasecmp(ext.get(), "TIF") &&
-          PL_strcasecmp(ext.get(), "HTM") &&
-          PL_strcasecmp(ext.get(), "HTML") &&
-          PL_strcasecmp(ext.get(), "ART") &&
-          PL_strcasecmp(ext.get(), "XUL") &&
-          PL_strcasecmp(ext.get(), "XML") &&
-          PL_strcasecmp(ext.get(), "CSS") &&
-          PL_strcasecmp(ext.get(), "JS");
-        }
+        sendResourceFork =
+        PL_strcasecmp(ext.get(), "TXT") &&
+        PL_strcasecmp(ext.get(), "JPG") &&
+        PL_strcasecmp(ext.get(), "GIF") &&
+        PL_strcasecmp(ext.get(), "TIF") &&
+        PL_strcasecmp(ext.get(), "HTM") &&
+        PL_strcasecmp(ext.get(), "HTML") &&
+        PL_strcasecmp(ext.get(), "ART") &&
+        PL_strcasecmp(ext.get(), "XUL") &&
+        PL_strcasecmp(ext.get(), "XML") &&
+        PL_strcasecmp(ext.get(), "CSS") &&
+        PL_strcasecmp(ext.get(), "JS");
       }
     }
   }
 
   // Only use appledouble if we aren't uuencoding.
   if( sendResourceFork )
   {
     char *separator;
--- a/mailnews/compose/src/nsMsgCopy.cpp
+++ b/mailnews/compose/src/nsMsgCopy.cpp
@@ -25,16 +25,17 @@
 #include "nsIMsgWindow.h"
 #include "nsIMsgProgress.h"
 #include "nsComposeStrings.h"
 #include "prmem.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMsgUtils.h"
 #include "nsArrayUtils.h"
+#include "nsIURIMutator.h"
 
 static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
 
 ////////////////////////////////////////////////////////////////////////////////////
 // This is the listener class for the copy operation. We have to create this class
 // to listen for message copy completion and eventually notify the caller
 ////////////////////////////////////////////////////////////////////////////////////
 NS_IMPL_ISUPPORTS(CopyListener, nsIMsgCopyServiceListener)
@@ -534,20 +535,19 @@ MessageFolderIsLocal(nsIMsgIdentity   *u
                      nsMsgDeliverMode aFolderType,
                      const char       *aFolderURI,
 		     bool 	      *aResult)
 {
   nsresult rv;
 
   if (!aFolderURI) return NS_ERROR_NULL_POINTER;
 
-  nsCOMPtr <nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) return rv;
-
-  rv = url->SetSpecInternal(nsDependentCString(aFolderURI));
+  nsCOMPtr <nsIURL> url;
+  rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(nsDependentCString(aFolderURI))
+                                                     .Finalize(url);
   if (NS_FAILED(rv)) return rv;
 
   /* mailbox:/ means its local (on disk) */
   rv = url->SchemeIs("mailbox", aResult);
   if (NS_FAILED(rv)) return rv;
   return NS_OK;
 }
 
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -78,16 +78,17 @@
 #include "mozilla/dom/HTMLBodyElement.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/HTMLLinkElement.h"
 #include "nsIMutableArray.h"
 #include "nsIMsgFilterService.h"
 #include "nsIMsgProtocolInfo.h"
 #include "mozIDOMWindow.h"
 #include "mozilla/Preferences.h"
+#include "nsIURIMutator.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::mailnews;
 
 static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
 
 #define PREF_MAIL_SEND_STRUCT "mail.send_struct"
@@ -2194,19 +2195,20 @@ nsMsgComposeAndSend::AddCompFieldRemoteA
       attachment->GetUrl(url);
       if (!url.IsEmpty())
       {
         // Just look for files that are NOT local file attachments and do
         // the right thing.
         if (! nsMsgIsLocalFile(url.get()))
         {
           // Check for message attachment, see nsMsgMailNewsUrl::GetIsMessageUri.
-          nsCOMPtr<nsIURI> nsiuri = do_CreateInstance(NS_STANDARDURL_CONTRACTID);
-          NS_ENSURE_STATE(nsiuri);
-          nsiuri->SetSpecInternal(url);
+          nsCOMPtr<nsIURI> nsiuri;
+          rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(url).Finalize(nsiuri);
+          NS_ENSURE_SUCCESS(rv, rv);
+
           nsAutoCString scheme;
           nsiuri->GetScheme(scheme);
           bool isAMessageAttachment =
             StringEndsWith(scheme, NS_LITERAL_CSTRING("-message"));
 
           m_attachments[newLoc]->mDeleteFile = true;
           m_attachments[newLoc]->m_done = false;
           m_attachments[newLoc]->SetMimeDeliveryState(this);
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -2522,22 +2522,21 @@ nsresult nsImapService::GetServerFromUrl
   rv = accountManager->FindServerByURI(mailnewsUrl, false, aServer);
   
   // look for server with any user name, in case we're trying to subscribe
   // to a folder with some one else's user name like the following
   // "IMAP://userSharingFolder@server1/SharedFolderName"
   if (NS_FAILED(rv) || !aServer)
   {
     nsAutoCString turl;
-    nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
     rv = mailnewsUrl->GetSpec(turl);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = url->SetSpecInternal(turl);
+
+    nsCOMPtr<nsIURL> url;
+    rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(turl).Finalize(url);
     NS_ENSURE_SUCCESS(rv, rv);
 
     url->SetUserPass(EmptyCString());
     rv = accountManager->FindServerByURI(url, false, aServer);
     if (*aServer)
       aImapUrl->SetExternalLinkUrl(true);
   }
   
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -61,16 +61,17 @@
 #include "nsIRssIncomingServer.h"
 #include "nsNetUtil.h"
 #include "nsIMsgFolderNotificationService.h"
 #include "nsReadLine.h"
 #include "nsArrayUtils.h"
 #include "nsIMsgTraitService.h"
 #include "nsIStringEnumerator.h"
 #include "mozilla/Services.h"
+#include "nsIURIMutator.h"
 
 //////////////////////////////////////////////////////////////////////////////
 // nsLocal
 /////////////////////////////////////////////////////////////////////////////
 
 nsLocalMailCopyState::nsLocalMailCopyState() :
   m_flags(0),
   m_lastProgressTime(PR_IntervalToMilliseconds(PR_IntervalNow())),
@@ -3103,21 +3104,18 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Noti
 // sometimes this gets called when we don't have the server yet, so
 // that's why we're not calling GetServer()
 NS_IMETHODIMP
 nsMsgLocalMailFolder::GetIncomingServerType(nsACString& aServerType)
 {
   nsresult rv;
   if (mType.IsEmpty())
   {
-    nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-    if (NS_FAILED(rv))
-      return rv;
-
-    rv = url->SetSpecInternal(mURI);
+    nsCOMPtr<nsIURL> url;
+    rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(mURI).Finalize(url);
     if (NS_FAILED(rv))
       return rv;
 
     nsCOMPtr<nsIMsgAccountManager> accountManager =
              do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
     if (NS_FAILED(rv))
       return rv;
 
--- a/mailnews/local/src/nsLocalUtils.cpp
+++ b/mailnews/local/src/nsLocalUtils.cpp
@@ -15,96 +15,96 @@
 #include "nsIPop3IncomingServer.h"
 #include "nsINoIncomingServer.h"
 #include "nsMsgBaseCID.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 
 #include "nsMsgUtils.h"
 #include "nsNetCID.h"
+#include "nsIURIMutator.h"
 
 // it would be really cool to:
 // - cache the last hostname->path match
 // - if no such server exists, behave like an old-style mailbox URL
 // (i.e. return the mail.directory preference or something)
 static nsresult
 nsGetMailboxServer(const char *uriStr, nsIMsgIncomingServer** aResult)
 {
   nsresult rv = NS_OK;
 
-  nsCOMPtr<nsIURL> aUrl = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) return rv;
-
-  rv = aUrl->SetSpecInternal(nsDependentCString(uriStr));
+  nsCOMPtr<nsIURL> url;
+  rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(nsDependentCString(uriStr))
+                                                     .Finalize(url);
   if (NS_FAILED(rv)) return rv;
 
   // retrieve the AccountManager
   nsCOMPtr<nsIMsgAccountManager> accountManager =
     do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
   // find all local mail "no servers" matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> none_server;
-  aUrl->SetScheme(NS_LITERAL_CSTRING("none"));
+  url->SetScheme(NS_LITERAL_CSTRING("none"));
   // No unescaping of username or hostname done here.
   // The unescaping is done inside of FindServerByURI
-  rv = accountManager->FindServerByURI(aUrl, false,
+  rv = accountManager->FindServerByURI(url, false,
                                   getter_AddRefs(none_server));
   if (NS_SUCCEEDED(rv)) {
     none_server.forget(aResult);
     return rv;
   }
 
   // if that fails, look for the rss hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> rss_server;
-  aUrl->SetScheme(NS_LITERAL_CSTRING("rss"));
-  rv = accountManager->FindServerByURI(aUrl, false,
+  url->SetScheme(NS_LITERAL_CSTRING("rss"));
+  rv = accountManager->FindServerByURI(url, false,
                                   getter_AddRefs(rss_server));
   if (NS_SUCCEEDED(rv))
   {
      rss_server.forget(aResult);
      return rv;
   }
 #ifdef HAVE_MOVEMAIL
   // find all movemail "servers" matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> movemail_server;
-  aUrl->SetScheme(NS_LITERAL_CSTRING("movemail"));
-  rv = accountManager->FindServerByURI(aUrl, false,
+  url->SetScheme(NS_LITERAL_CSTRING("movemail"));
+  rv = accountManager->FindServerByURI(url, false,
                                   getter_AddRefs(movemail_server));
   if (NS_SUCCEEDED(rv)) {
     movemail_server.forget(aResult);
     return rv;
   }
 #endif /* HAVE_MOVEMAIL */
 
   // if that fails, look for the pop hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> server;
   if (NS_FAILED(rv))
   {
-    aUrl->SetScheme(NS_LITERAL_CSTRING("pop3"));
-    rv = accountManager->FindServerByURI(aUrl, false,
+    url->SetScheme(NS_LITERAL_CSTRING("pop3"));
+    rv = accountManager->FindServerByURI(url, false,
                                     getter_AddRefs(server));
 
     // if we can't find a pop server, maybe it's a local message
     // in an imap hierarchy. look for an imap server.
     if (NS_FAILED(rv))
     {
-      aUrl->SetScheme(NS_LITERAL_CSTRING("imap"));
-      rv = accountManager->FindServerByURI(aUrl, false,
+      url->SetScheme(NS_LITERAL_CSTRING("imap"));
+      rv = accountManager->FindServerByURI(url, false,
                                     getter_AddRefs(server));
     }
   }
   if (NS_SUCCEEDED(rv))
   {
     server.forget(aResult);
     return rv;
   }
 
-// if you fail after looking at all "pop3", "movemail" and "none" servers, you fail.
-return rv;
+  // if you fail after looking at all "pop3", "movemail" and "none" servers, you fail.
+ return rv;
 }
 
 static nsresult
 nsLocalURI2Server(const char* uriStr,
                   nsIMsgIncomingServer ** aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIMsgIncomingServer> server;