Bug 1550945 - Part 4: Flesh out NS_NewMailnewsURI(). rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Wed, 29 May 2019 19:53:26 +0200
changeset 35705 21ef273cf681ef9a38d3569fb89adeaf750bbdbe
parent 35704 05e4ae2b2c7c6c2ce4135a7535135ac344a17e84
child 35706 b2e2cb73dfce7ee1ae96ec0f4c42f6ccecf494b8
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersbustage-fix
bugs1550945
Bug 1550945 - Part 4: Flesh out NS_NewMailnewsURI(). rs=bustage-fix
calendar/lightning/components/calItipProtocolHandler.js
chat/components/src/smileProtocolHandler.js
ldap/xpcom/src/nsLDAPProtocolHandler.js
ldap/xpcom/src/nsLDAPURL.cpp
ldap/xpcom/src/nsLDAPURL.h
mailnews/addrbook/src/nsAddbookProtocolHandler.h
mailnews/base/src/nsCidProtocolHandler.h
mailnews/base/util/nsNewMailnewsURI.cpp
mailnews/compose/src/nsSMTPProtocolHandler.js
mailnews/compose/src/nsSmtpService.h
mailnews/imap/src/nsImapService.h
mailnews/local/src/nsMailboxService.h
mailnews/local/src/nsPop3Service.h
mailnews/news/src/nsNntpService.h
--- a/calendar/lightning/components/calItipProtocolHandler.js
+++ b/calendar/lightning/components/calItipProtocolHandler.js
@@ -51,23 +51,16 @@ function ItipProtocolHandler() {
 }
 ItipProtocolHandler.prototype = {
     QueryInterface: ChromeUtils.generateQI([Ci.nsIProtocolHandler]),
     classID: Components.ID("{6e957006-b4ce-11d9-b053-001124736B74}"),
 
     protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
     allowPort: () => false,
     isSecure: false,
-    newURI: function(spec, charSet, baseURI) {
-        dump("Creating new URI for " + spec + "\n");
-        return Cc["@mozilla.org/network/standard-url-mutator;1"]
-                 .createInstance(Ci.nsIStandardURLMutator)
-                 .init(Ci.nsIStandardURL.URLTYPE_STANDARD, 0, spec, charSet, baseURI)
-                 .finalize();
-    },
     newChannel: function(URI, aLoadInfo) {
         dump("Creating new ItipChannel for " + URI + "\n");
         return new ItipChannel(URI, aLoadInfo);
     },
 };
 
 function ItipContentHandler() {
     this.wrappedJSObject = this;
--- a/chat/components/src/smileProtocolHandler.js
+++ b/chat/components/src/smileProtocolHandler.js
@@ -18,21 +18,16 @@ function smileProtocolHandler() { }
 
 smileProtocolHandler.prototype = {
   scheme: "smile",
   defaultPort: -1,
   protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
                  Ci.nsIProtocolHandler.URI_NOAUTH |
                  Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE |
                  Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE,
-  newURI(aSpec, aOriginCharset, aBaseURI) {
-    let mutator = Cc["@mozilla.org/network/simple-uri-mutator;1"]
-                    .createInstance(Ci.nsIURIMutator);
-    return mutator.setSpec(aSpec).finalize();
-  },
   newChannel(aURI, aLoadInfo) {
     let smile = aURI.spec.replace(kSmileRegexp, "");
     let uri = Services.io.newURI(getSmileRealURI(smile));
     let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
     channel.originalURI = aURI;
     return channel;
   },
   allowPort(aPort, aScheme) { return false; },
--- a/ldap/xpcom/src/nsLDAPProtocolHandler.js
+++ b/ldap/xpcom/src/nsLDAPProtocolHandler.js
@@ -13,27 +13,16 @@ function makeProtocolHandler(aCID, aProt
     QueryInterface: ChromeUtils.generateQI([nsIProtocolHandler]),
 
     scheme: aProtocol,
     defaultPort: aDefaultPort,
     protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
                    nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
                    nsIProtocolHandler.ALLOWS_PROXY,
 
-    newURI(aSpec, aOriginCharset, aBaseURI) {
-      var url = Cc["@mozilla.org/network/ldap-url;1"]
-                  .createInstance(Ci.nsIURI);
-
-      if (url instanceof Ci.nsILDAPURL)
-        url.init(Ci.nsIStandardURL.URLTYPE_STANDARD,
-          aDefaultPort, aSpec, aOriginCharset, aBaseURI);
-
-      return url;
-    },
-
     newChannel(aURI, aLoadInfo) {
       if ("@mozilla.org/network/ldap-channel;1" in Cc) {
         var channel = Cc["@mozilla.org/network/ldap-channel;1"]
                         .createInstance(Ci.nsIChannel);
         channel.init(aURI);
         channel.loadInfo = aLoadInfo;
         return channel;
       }
--- a/ldap/xpcom/src/nsLDAPURL.cpp
+++ b/ldap/xpcom/src/nsLDAPURL.cpp
@@ -8,16 +8,18 @@
 #include "netCore.h"
 #include "plstr.h"
 #include "nsCOMPtr.h"
 #include "nsNetCID.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIStandardURL.h"
 #include "nsMsgUtils.h"
 #include "mozilla/Encoding.h"
+#include "ldap.h"
+
 
 // The two schemes we support, LDAP and LDAPS
 //
 NS_NAMED_LITERAL_CSTRING(LDAP_SCHEME, "ldap");
 NS_NAMED_LITERAL_CSTRING(LDAP_SSL_SCHEME, "ldaps");
 
 NS_IMPL_ISUPPORTS(nsLDAPURL, nsILDAPURL, nsIURI)
 
--- a/ldap/xpcom/src/nsLDAPURL.h
+++ b/ldap/xpcom/src/nsLDAPURL.h
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "ldap.h"
 #include "nsString.h"
 #include "nsILDAPURL.h"
 #include "nsCOMPtr.h"
 #include "nsIURIMutator.h"
 
 // cb7c67f8-0053-4072-89e9-501cbd1b35ab
 #define NS_LDAPURL_CID                               \
   {                                                  \
--- a/mailnews/addrbook/src/nsAddbookProtocolHandler.h
+++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.h
@@ -11,19 +11,19 @@
 #include "nsAddbookProtocolHandler.h"
 #include "nsIProtocolHandler.h"
 #include "nsIAddbookUrl.h"
 #include "nsIAbDirectory.h"
 
 class nsAddbookProtocolHandler : public nsIProtocolHandler {
  public:
   nsAddbookProtocolHandler();
-  nsresult NewURI(const nsACString &aSpec,
-                  const char *aOriginCharset,  // ignored
-                  nsIURI *aBaseURI, nsIURI **_retval);
+  static nsresult NewURI(const nsACString &aSpec,
+                         const char *aOriginCharset,  // ignored
+                         nsIURI *aBaseURI, nsIURI **_retval);
 
   NS_DECL_ISUPPORTS
 
   //////////////////////////////////////////////////////////////////////////
   // We support the nsIProtocolHandler interface.
   //////////////////////////////////////////////////////////////////////////
   NS_DECL_NSIPROTOCOLHANDLER
 
--- a/mailnews/base/src/nsCidProtocolHandler.h
+++ b/mailnews/base/src/nsCidProtocolHandler.h
@@ -7,19 +7,19 @@
 #define nsCidProtocolHandler_h__
 
 #include "nsCOMPtr.h"
 #include "nsIProtocolHandler.h"
 
 class nsCidProtocolHandler : public nsIProtocolHandler {
  public:
   nsCidProtocolHandler();
+  static nsresult NewURI(const nsACString &aSpec, const char *aOriginCharset,
+                         nsIURI *aBaseURI, nsIURI **_retval);
 
-  nsresult NewURI(const nsACString &aSpec, const char *aOriginCharset,
-                  nsIURI *aBaseURI, nsIURI **_retval);
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPROTOCOLHANDLER
 
  private:
   virtual ~nsCidProtocolHandler();
 };
 
 #endif /* nsCidProtocolHandler_h__ */
--- a/mailnews/base/util/nsNewMailnewsURI.cpp
+++ b/mailnews/base/util/nsNewMailnewsURI.cpp
@@ -1,13 +1,87 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsNewMailnewsURI.h"
+#include "nsURLHelper.h"
+#include "nsSimpleURI.h"
+#include "nsStandardURL.h"
+
+#include "../../local/src/nsPop3Service.h"
+#include "../../local/src/nsMailboxService.h"
+#include "../../compose/src/nsSmtpService.h"
+#include "../../compose/src/nsSmtpUrl.h"
+#include "../../../ldap/xpcom/src/nsLDAPURL.h"
+#include "../../imap/src/nsImapService.h"
+#include "../../news/src/nsNntpService.h"
+#include "../../addrbook/src/nsAddbookProtocolHandler.h"
+#include "../src/nsCidProtocolHandler.h"
 
 nsresult NS_NewMailnewsURI(nsIURI** aURI, const nsACString& aSpec,
                            const char* aCharset /* = nullptr */,
                            nsIURI* aBaseURI /* = nullptr */,
                            nsIIOService* aIOService /* = nullptr */) {
-  return NS_OK;
+  nsAutoCString scheme;
+  nsresult rv = net_ExtractURLScheme(aSpec, scheme);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (scheme.EqualsLiteral("mailbox") ||
+      scheme.EqualsLiteral("mailbox-message")) {
+    return nsMailboxService::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("imap") || scheme.EqualsLiteral("imap-message")) {
+    return nsImapService::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("smtp")) {
+    rv = NS_MutateURI(new nsSmtpUrl::Mutator()).SetSpec(aSpec).Finalize(aURI);
+    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsISmtpUrl> url(do_QueryInterface(*aURI));
+    NS_ENSURE_TRUE(url, NS_ERROR_UNEXPECTED);
+    return url->Init(aSpec);
+  }
+  if (scheme.EqualsLiteral("mailto")) {
+    return nsSmtpService::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("pop3")) {
+    return nsPop3Service::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("news") || scheme.EqualsLiteral("snews")) {
+    return nsNntpService::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("cid")) {
+    return nsCidProtocolHandler::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("addbook")) {
+    return nsAddbookProtocolHandler::NewURI(aSpec, aCharset, aBaseURI, aURI);
+  }
+  if (scheme.EqualsLiteral("ldap") || scheme.EqualsLiteral("ldaps")) {
+    rv = NS_MutateURI(new nsLDAPURL::Mutator()).SetSpec(aSpec).Finalize(aURI);
+    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsILDAPURL> url(do_QueryInterface(*aURI));
+    NS_ENSURE_TRUE(url, NS_ERROR_UNEXPECTED);
+    return url->Init(nsIStandardURL::URLTYPE_STANDARD,
+                     scheme.EqualsLiteral("ldap") ? 389 : 636, aSpec, aCharset,
+                     aBaseURI);
+  }
+  if (scheme.EqualsLiteral("smile")) {
+    ;  // Fall through.
+  }
+  if (scheme.EqualsLiteral("moz-cal-handle-itip")) {
+    return NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
+        .SetSpec(aSpec)
+        .Finalize(aURI);
+  }
+  if (scheme.EqualsLiteral("webcal") || scheme.EqualsLiteral("webcals")) {
+    return NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
+        .SetSpec(aSpec)
+        .Finalize(aURI);
+  }
+
+  // XXX TODO: What about JS Account?
+
+  // None of the above, let's fallback to the M-C fallback.
+  return NS_MutateURI(new mozilla::net::nsSimpleURI::Mutator())
+      .SetSpec(aSpec)
+      .Finalize(aURI);
 }
--- a/mailnews/compose/src/nsSMTPProtocolHandler.js
+++ b/mailnews/compose/src/nsSMTPProtocolHandler.js
@@ -15,24 +15,16 @@ function makeProtocolHandler(aProtocol, 
     scheme: aProtocol,
     defaultPort: aDefaultPort,
     protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
                    nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
       nsIProtocolHandler.URI_NON_PERSISTABLE |
       nsIProtocolHandler.ALLOWS_PROXY |
       nsIProtocolHandler.URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT,
 
-    newURI(aSpec, aOriginCharset, aBaseURI) {
-      var url = Cc["@mozilla.org/messengercompose/smtpurl;1"]
-                  .createInstance(Ci.nsIURI);
-      if (url instanceof Ci.nsISmtpUrl)
-        url.init(aSpec);
-      return url;
-    },
-
     newChannel(aURI, aLoadInfo) {
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
     },
 
     allowPort(port, scheme) {
       return port == aDefaultPort;
     },
   };
--- a/mailnews/compose/src/nsSmtpService.h
+++ b/mailnews/compose/src/nsSmtpService.h
@@ -18,19 +18,19 @@
 // to urls easier. I'm not sure if this service will go away when the new
 // networking model comes on line (as part of the N2 project). So I reserve the
 // right to change my mind and take this service away =).
 ////////////////////////////////////////////////////////////////////////////////////////
 
 class nsSmtpService : public nsISmtpService, public nsIProtocolHandler {
  public:
   nsSmtpService();
-  nsresult NewURI(const nsACString &aSpec,
-                  const char *aOriginCharset,  // ignored, always UTF-8.
-                  nsIURI *aBaseURI, nsIURI **_retval);
+  static nsresult NewURI(const nsACString &aSpec,
+                         const char *aOriginCharset,  // ignored, always UTF-8.
+                         nsIURI *aBaseURI, nsIURI **_retval);
   NS_DECL_ISUPPORTS
 
   ////////////////////////////////////////////////////////////////////////
   // we support the nsISmtpService interface
   ////////////////////////////////////////////////////////////////////////
   NS_DECL_NSISMTPSERVICE
 
   //////////////////////////////////////////////////////////////////////////
--- a/mailnews/imap/src/nsImapService.h
+++ b/mailnews/imap/src/nsImapService.h
@@ -23,19 +23,19 @@ class nsIMsgIncomingServer;
 class nsImapService : public nsIImapService,
                       public nsIMsgMessageService,
                       public nsIMsgMessageFetchPartService,
                       public nsIProtocolHandler,
                       public nsIMsgProtocolInfo,
                       public nsIContentHandler {
  public:
   nsImapService();
-  nsresult NewURI(const nsACString &aSpec,
-                  const char *aOriginCharset,  // ignored
-                  nsIURI *aBaseURI, nsIURI **aRetVal);
+  static nsresult NewURI(const nsACString &aSpec,
+                         const char *aOriginCharset,  // ignored
+                         nsIURI *aBaseURI, nsIURI **aRetVal);
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIMSGPROTOCOLINFO
   NS_DECL_NSIIMAPSERVICE
   NS_DECL_NSIMSGMESSAGESERVICE
   NS_DECL_NSIPROTOCOLHANDLER
   NS_DECL_NSIMSGMESSAGEFETCHPARTSERVICE
   NS_DECL_NSICONTENTHANDLER
@@ -59,17 +59,18 @@ class nsImapService : public nsIImapServ
           &aImapURI,  // a RDF URI for the current message/folder, can be empty
       nsIImapUrl **imapUrl, nsIMsgFolder *aImapFolder,
       nsIUrlListener *aUrlListener, nsACString &urlSpec,
       char &hierarchyDelimiter);
 
   nsresult GetImapConnectionAndLoadUrl(nsIImapUrl *aImapUrl,
                                        nsISupports *aConsumer, nsIURI **aURL);
 
-  nsresult SetImapUrlSink(nsIMsgFolder *aMsgFolder, nsIImapUrl *aImapUrl);
+  static nsresult SetImapUrlSink(nsIMsgFolder *aMsgFolder,
+                                 nsIImapUrl *aImapUrl);
 
   nsresult FetchMimePart(nsIImapUrl *aImapUrl, nsImapAction aImapAction,
                          nsIMsgFolder *aImapMailFolder,
                          nsIImapMessageSink *aImapMessage, nsIURI **aURL,
                          nsISupports *aDisplayConsumer,
                          const nsACString &messageIdentifierList,
                          const nsACString &mimePart);
 
@@ -91,18 +92,18 @@ class nsImapService : public nsIImapServ
 
   nsresult OfflineAppendFromFile(nsIFile *aFile, nsIURI *aUrl,
                                  nsIMsgFolder *aDstFolder,
                                  const nsACString &messageId,  // to be replaced
                                  bool inSelectedState,         // needs to be in
                                  nsIUrlListener *aListener, nsIURI **aURL,
                                  nsISupports *aCopyState);
 
-  nsresult GetServerFromUrl(nsIImapUrl *aImapUrl,
-                            nsIMsgIncomingServer **aServer);
+  static nsresult GetServerFromUrl(nsIImapUrl *aImapUrl,
+                                   nsIMsgIncomingServer **aServer);
 
   // just a little helper method...maybe it should be a macro? which helps break
   // down a imap message uri into the folder and message key equivalents
   nsresult DecomposeImapURI(const nsACString &aMessageURI,
                             nsIMsgFolder **aFolder, nsACString &msgKey);
   nsresult DecomposeImapURI(const nsACString &aMessageURI,
                             nsIMsgFolder **aFolder, nsMsgKey *msgKey);
 
--- a/mailnews/local/src/nsMailboxService.h
+++ b/mailnews/local/src/nsMailboxService.h
@@ -19,18 +19,18 @@
 #include "nsIProtocolHandler.h"
 
 class nsMailboxService : public nsIMailboxService,
                          public nsIMsgMessageService,
                          public nsIMsgMessageFetchPartService,
                          public nsIProtocolHandler {
  public:
   nsMailboxService();
-  nsresult NewURI(const nsACString &aSpec, const char *aOriginCharset,
-                  nsIURI *aBaseURI, nsIURI **_retval);
+  static nsresult NewURI(const nsACString &aSpec, const char *aOriginCharset,
+                         nsIURI *aBaseURI, nsIURI **_retval);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMAILBOXSERVICE
   NS_DECL_NSIMSGMESSAGESERVICE
   NS_DECL_NSIMSGMESSAGEFETCHPARTSERVICE
   NS_DECL_NSIPROTOCOLHANDLER
 
  protected:
--- a/mailnews/local/src/nsPop3Service.h
+++ b/mailnews/local/src/nsPop3Service.h
@@ -16,33 +16,34 @@
 
 class nsIMsgMailNewsUrl;
 
 class nsPop3Service : public nsIPop3Service,
                       public nsIProtocolHandler,
                       public nsIMsgProtocolInfo {
  public:
   nsPop3Service();
-  nsresult NewURI(const nsACString &aSpec,
-                  const char *aOriginCharset,  // ignored
-                  nsIURI *aBaseURI, nsIURI **_retval);
+  static nsresult NewURI(const nsACString &aSpec,
+                         const char *aOriginCharset,  // ignored
+                         nsIURI *aBaseURI, nsIURI **_retval);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPOP3SERVICE
   NS_DECL_NSIPROTOCOLHANDLER
   NS_DECL_NSIMSGPROTOCOLINFO
 
  protected:
   virtual ~nsPop3Service();
   nsresult GetMail(bool downloadNewMail, nsIMsgWindow *aMsgWindow,
                    nsIUrlListener *aUrlListener, nsIMsgFolder *inbox,
                    nsIPop3IncomingServer *popServer, nsIURI **aURL);
   // convenience function to make constructing of the pop3 url easier...
-  nsresult BuildPop3Url(const char *urlSpec, nsIMsgFolder *inbox,
-                        nsIPop3IncomingServer *, nsIUrlListener *aUrlListener,
-                        nsIURI **aUrl, nsIMsgWindow *aMsgWindow);
+  static nsresult BuildPop3Url(const char *urlSpec, nsIMsgFolder *inbox,
+                               nsIPop3IncomingServer *,
+                               nsIUrlListener *aUrlListener, nsIURI **aUrl,
+                               nsIMsgWindow *aMsgWindow);
 
   nsresult RunPopUrl(nsIMsgIncomingServer *aServer, nsIURI *aUrlToRun);
   void AlertServerBusy(nsIMsgMailNewsUrl *url);
   nsTObserverArray<nsCOMPtr<nsIPop3ServiceListener> > mListeners;
 };
 
 #endif /* nsPop3Service_h___ */
--- a/mailnews/news/src/nsNntpService.h
+++ b/mailnews/news/src/nsNntpService.h
@@ -37,19 +37,19 @@ class nsNntpService : public nsINntpServ
   NS_DECL_NSIPROTOCOLHANDLER
   NS_DECL_NSIMSGPROTOCOLINFO
   NS_DECL_NSICONTENTHANDLER
   NS_DECL_NSIMSGMESSAGEFETCHPARTSERVICE
   NS_DECL_NSICOMMANDLINEHANDLER
 
   // nsNntpService
   nsNntpService();
-  nsresult NewURI(const nsACString &aSpec,
-                  const char *aCharset,  // ignored
-                  nsIURI *aBaseURI, nsIURI **_retval);
+  static nsresult NewURI(const nsACString &aSpec,
+                         const char *aCharset,  // ignored
+                         nsIURI *aBaseURI, nsIURI **_retval);
 
  protected:
   virtual ~nsNntpService();
 
   nsresult GetNntpServerByAccount(const char *aAccountKey,
                                   nsIMsgIncomingServer **aNntpServer);
   nsresult SetUpNntpUrlForPosting(const char *aAccountKey, char **newsUrlSpec);
   nsresult FindHostFromGroup(nsCString &host, nsCString &groupName);