Bug 1495101 - remove interface nsISubscribeDataSource and related RDF code. r=jorgk
authoraceman <acelists@atlas.sk>
Fri, 28 Sep 2018 17:22:00 +0200
changeset 33268 d945c1cb9d917bfaa6d4d8bfacecde30889567cc
parent 33267 2131ecd0173c88f2a080af5c8ce46ecbb36dd272
child 33269 17f0a541d7acf332ba8c503025277932d3b9936b
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1495101
Bug 1495101 - remove interface nsISubscribeDataSource and related RDF code. r=jorgk
mailnews/base/public/nsISubscribableServer.idl
mailnews/base/public/nsMsgBaseCID.h
mailnews/base/src/moz.build
mailnews/base/src/nsSubscribableServer.cpp
mailnews/base/src/nsSubscribableServer.h
mailnews/base/src/nsSubscribeDataSource.cpp
mailnews/base/src/nsSubscribeDataSource.h
mailnews/build/nsMailModule.cpp
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/news/src/nsNntpIncomingServer.cpp
mailnews/news/test/unit/test_internalUris.js
--- a/mailnews/base/public/nsISubscribableServer.idl
+++ b/mailnews/base/public/nsISubscribableServer.idl
@@ -2,26 +2,18 @@
 /* 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 "nsISupports.idl"
 
 interface nsIMsgWindow;
 interface nsIMsgIncomingServer;
-interface nsIRDFResource;
-interface nsIRDFNode;
-interface nsISimpleEnumerator;
 interface nsITreeView;
-
-[scriptable, uuid(61a08c3a-1dd2-11b2-b64f-c4b2de1cf129)]
-interface nsISubscribeDataSource : nsISupports {
-    readonly attribute boolean hasObservers;
-    void NotifyObservers(in nsIRDFResource subject, in nsIRDFResource property, in nsIRDFNode object, in boolean isAssert, in boolean isChange);
-};
+interface nsIUTF8StringEnumerator;
 
 /**
  * A listener to receive notification of the subscribable folders of a server.
  */
 [scriptable, uuid(f337b84a-1dd1-11b2-97c7-fb8b2e3f2280)]
 interface nsISubscribeListener : nsISupports {
   /**
    * The server has finished finding all folders to subscribe to.
@@ -61,23 +53,22 @@ interface nsISubscribableServer : nsISup
   // if path is null, use the root
   boolean isSubscribed(in AUTF8String path);
   // if path is null, use the root
   boolean isSubscribable(in AUTF8String path);
   // if path is null, use the root
   AString getLeafName(in AUTF8String path);
 
   /**
-   * Returns the children underneath the specified uri (path).
+   * Returns the children uris underneath the specified uri (path).
    *
    * @param  aPath  The server's uri; If this is null or empty, then the
    *                root server uri will be used.
-   * @return        Enumerator containing the children.
    */
-  nsISimpleEnumerator getChildren(in AUTF8String aPath);
+  nsIUTF8StringEnumerator getChildURIs(in AUTF8String aPath);
   // if path is null, use the root
   AUTF8String getFirstChildURI(in AUTF8String path);
 
   // for searching
   void setSearchValue(in AString searchValue);
   readonly attribute boolean supportsSubscribeSearch;
   readonly attribute nsITreeView folderView;
 };
--- a/mailnews/base/public/nsMsgBaseCID.h
+++ b/mailnews/base/public/nsMsgBaseCID.h
@@ -241,26 +241,16 @@
 //
 #define NS_SUBSCRIBABLESERVER_CONTRACTID \
  "@mozilla.org/messenger/subscribableserver;1"
 
 #define NS_SUBSCRIBABLESERVER_CID \
 { 0x8510876a, 0x1dd2, 0x11b2,     \
 { 0x82, 0x53, 0x91, 0xf7, 0x1b, 0x34, 0x8a, 0x25 }}
 
-//
-// nsSubscribeDataSource
-//
-#define NS_SUBSCRIBEDATASOURCE_CONTRACTID \
-  NS_RDF_DATASOURCE_CONTRACTID_PREFIX "subscribe"
-
-#define NS_SUBSCRIBEDATASOURCE_CID \
-{ 0x00e89c82, 0x1dd2, 0x11b2,      \
-{ 0x9a, 0x1c, 0xe7, 0x59, 0x95, 0xd7, 0xd5, 0x95 }}
-
 #define NS_MSGLOCALFOLDERCOMPACTOR_CONTRACTID \
   "@mozilla.org/messenger/localfoldercompactor;1"
 
 #define NS_MSGLOCALFOLDERCOMPACTOR_CID \
 { 0x7d1d315c, 0xe5c6, 0x11d4,          \
 { 0xa5, 0xb7, 0x00,0x60, 0xb0, 0xfc, 0x04, 0xb7 }}
 
 #define NS_MSGOFFLINESTORECOMPACTOR_CONTRACTID \
--- a/mailnews/base/src/moz.build
+++ b/mailnews/base/src/moz.build
@@ -43,18 +43,17 @@ SOURCES += [
     'nsMsgStatusFeedback.cpp',
     'nsMsgTagService.cpp',
     'nsMsgThreadedDBView.cpp',
     'nsMsgWindow.cpp',
     'nsMsgXFViewThread.cpp',
     'nsMsgXFVirtualFolderDBView.cpp',
     'nsSpamSettings.cpp',
     'nsStatusBarBiffManager.cpp',
-    'nsSubscribableServer.cpp',
-    'nsSubscribeDataSource.cpp',
+    'nsSubscribableServer.cpp'
 ]
 
 if CONFIG['NS_PRINTING']:
     SOURCES += ['nsMsgPrintEngine.cpp']
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += ['nsMessengerWinIntegration.cpp']
 
--- a/mailnews/base/src/nsSubscribableServer.cpp
+++ b/mailnews/base/src/nsSubscribableServer.cpp
@@ -1,59 +1,39 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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 "nsSubscribableServer.h"
 #include "nsIMsgIncomingServer.h"
 #include "prmem.h"
-#include "rdf.h"
-#include "nsRDFCID.h"
 #include "nsIServiceManager.h"
 #include "nsMsgI18N.h"
 #include "nsMsgUtils.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
+#include "nsStringEnumerator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTreeColumns.h"
 #include "mozilla/dom/DataTransfer.h"
 
-static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
 
 nsSubscribableServer::nsSubscribableServer(void)
 {
     mDelimiter = '.';
     mShowFullName = true;
     mTreeRoot = nullptr;
     mStopped = false;
 }
 
 nsresult
 nsSubscribableServer::Init()
 {
-    nsresult rv;
-
-    rv = EnsureRDFService();
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
-                                  getter_AddRefs(kNC_Child));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Subscribed"),
-                                  getter_AddRefs(kNC_Subscribed));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetLiteral(u"true", getter_AddRefs(kTrueLiteral));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetLiteral(u"false", getter_AddRefs(kFalseLiteral));
-    NS_ENSURE_SUCCESS(rv,rv);
-    return NS_OK;
+  return NS_OK;
 }
 
 nsSubscribableServer::~nsSubscribableServer(void)
 {
   mozilla::DebugOnly<nsresult> rv = FreeRows();
   NS_ASSERTION(NS_SUCCEEDED(rv), "failed to free tree rows");
   rv = FreeSubtree(mTreeRoot);
   NS_ASSERTION(NS_SUCCEEDED(rv),"failed to free tree");
@@ -103,19 +83,16 @@ nsSubscribableServer::SetAsSubscribed(co
     rv = FindAndCreateNode(path, &node);
     NS_ENSURE_SUCCESS(rv,rv);
 
     NS_ASSERTION(node,"didn't find the node");
     if (!node) return NS_ERROR_FAILURE;
     node->isSubscribable = true;
     node->isSubscribed = true;
 
-    rv = NotifyChange(node, kNC_Subscribed, node->isSubscribed);
-    NS_ENSURE_SUCCESS(rv,rv);
-
     return rv;
 }
 
 NS_IMETHODIMP
 nsSubscribableServer::AddTo(const nsACString& aName, bool aAddAsSubscribed,
                             bool aSubscribable, bool aChangeIfExists)
 {
     nsresult rv = NS_OK;
@@ -130,18 +107,16 @@ nsSubscribableServer::AddTo(const nsACSt
     // default value if we create it?
     rv = FindAndCreateNode(aName, &node);
     NS_ENSURE_SUCCESS(rv,rv);
     NS_ASSERTION(node,"didn't find the node");
     if (!node) return NS_ERROR_FAILURE;
 
     if (aChangeIfExists) {
         node->isSubscribed = aAddAsSubscribed;
-        rv = NotifyChange(node, kNC_Subscribed, node->isSubscribed);
-        NS_ENSURE_SUCCESS(rv,rv);
     }
 
     node->isSubscribable = aSubscribable;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -169,171 +144,28 @@ nsSubscribableServer::SetState(const nsA
     }
 
     if (node->isSubscribed == aState) {
         return NS_OK;
     }
     else {
         node->isSubscribed = aState;
         *aStateChanged = true;
-        rv = NotifyChange(node, kNC_Subscribed, node->isSubscribed);
-        NS_ENSURE_SUCCESS(rv,rv);
 
         // Repaint the tree row to show/clear the check mark.
         if (mTree) {
           bool dummy;
           int32_t index = GetRow(node, &dummy);
           if (index >= 0)
             mTree->InvalidateRow(index);
         }
     }
     return NS_OK;
 }
 
-void
-nsSubscribableServer::BuildURIFromNode(SubscribeTreeNode *node, nsACString &uri)
-{
-    if (node->parent) {
-        BuildURIFromNode(node->parent, uri);
-        if (node->parent == mTreeRoot) {
-            uri += "/";
-        }
-        else {
-            uri += mDelimiter;
-        }
-    }
-
-    uri += node->name;
-    return;
-}
-
-nsresult
-nsSubscribableServer::NotifyAssert(SubscribeTreeNode *subjectNode, nsIRDFResource *property, SubscribeTreeNode *objectNode)
-{
-    nsresult rv;
-
-    bool hasObservers = true;
-    rv = EnsureSubscribeDS();
-    NS_ENSURE_SUCCESS(rv,rv);
-    rv = mSubscribeDS->GetHasObservers(&hasObservers);
-    NS_ENSURE_SUCCESS(rv,rv);
-    // no need to do all this work, there are no observers
-    if (!hasObservers) {
-        return NS_OK;
-    }
-
-    nsAutoCString subjectUri;
-    BuildURIFromNode(subjectNode, subjectUri);
-
-    // we could optimize this, since we know that objectUri == subjectUri + mDelimiter + object->name
-    // is it worth it?
-    nsAutoCString objectUri;
-    BuildURIFromNode(objectNode, objectUri);
-
-    nsCOMPtr <nsIRDFResource> subject;
-    nsCOMPtr <nsIRDFResource> object;
-
-    rv = EnsureRDFService();
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(subjectUri, getter_AddRefs(subject));
-    NS_ENSURE_SUCCESS(rv,rv);
-    rv = mRDFService->GetResource(objectUri, getter_AddRefs(object));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = Notify(subject, property, object, true, false);
-    NS_ENSURE_SUCCESS(rv,rv);
-    return NS_OK;
-}
-
-nsresult
-nsSubscribableServer::EnsureRDFService()
-{
-    nsresult rv;
-
-    if (!mRDFService) {
-        mRDFService = do_GetService(kRDFServiceCID, &rv);
-        NS_ASSERTION(NS_SUCCEEDED(rv) && mRDFService, "failed to get rdf service");
-        NS_ENSURE_SUCCESS(rv,rv);
-        if (!mRDFService) return NS_ERROR_FAILURE;
-    }
-    return NS_OK;
-}
-
-nsresult
-nsSubscribableServer::NotifyChange(SubscribeTreeNode *subjectNode, nsIRDFResource *property, bool value)
-{
-    nsresult rv;
-    nsCOMPtr <nsIRDFResource> subject;
-
-    bool hasObservers = true;
-    rv = EnsureSubscribeDS();
-    NS_ENSURE_SUCCESS(rv,rv);
-    rv = mSubscribeDS->GetHasObservers(&hasObservers);
-    NS_ENSURE_SUCCESS(rv,rv);
-    // no need to do all this work, there are no observers
-    if (!hasObservers) {
-        return NS_OK;
-    }
-
-    nsAutoCString subjectUri;
-    BuildURIFromNode(subjectNode, subjectUri);
-
-    rv = EnsureRDFService();
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(subjectUri, getter_AddRefs(subject));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    if (value) {
-        rv = Notify(subject,property,kTrueLiteral,false,true);
-    }
-    else {
-        rv = Notify(subject,property,kFalseLiteral,false,true);
-    }
-
-    NS_ENSURE_SUCCESS(rv,rv);
-    return NS_OK;
-}
-
-nsresult
-nsSubscribableServer::EnsureSubscribeDS()
-{
-    nsresult rv = NS_OK;
-
-    if (!mSubscribeDS) {
-        nsCOMPtr<nsIRDFDataSource> ds;
-
-        rv = EnsureRDFService();
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        rv = mRDFService->GetDataSource("rdf:subscribe", getter_AddRefs(ds));
-        NS_ENSURE_SUCCESS(rv,rv);
-        if (!ds) return NS_ERROR_FAILURE;
-
-        mSubscribeDS = do_QueryInterface(ds, &rv);
-        NS_ENSURE_SUCCESS(rv,rv);
-        if (!mSubscribeDS) return NS_ERROR_FAILURE;
-    }
-    return NS_OK;
-}
-
-nsresult
-nsSubscribableServer::Notify(nsIRDFResource *subject, nsIRDFResource *property, nsIRDFNode *object, bool isAssert, bool isChange)
-{
-    nsresult rv = NS_OK;
-
-    rv = EnsureSubscribeDS();
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mSubscribeDS->NotifyObservers(subject, property, object, isAssert, isChange);
-    NS_ENSURE_SUCCESS(rv,rv);
-    return rv;
-}
-
 NS_IMETHODIMP
 nsSubscribableServer::SetSubscribeListener(nsISubscribeListener *aListener)
 {
   mSubscribeListener = aListener;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -538,19 +370,16 @@ nsSubscribableServer::AddChildNode(Subsc
     if (!parent->firstChild) {
         // CreateNode will set the parent->cachedChild
         rv = CreateNode(parent, name, aPath, child);
         NS_ENSURE_SUCCESS(rv,rv);
 
         parent->firstChild = *child;
         parent->lastChild = *child;
 
-        rv = NotifyAssert(parent, kNC_Child, *child);
-        NS_ENSURE_SUCCESS(rv,rv);
-
         return NS_OK;
     }
 
     if (parent->cachedChild) {
         if (strcmp(parent->cachedChild->name,name) == 0) {
             *child = parent->cachedChild;
             return NS_OK;
         }
@@ -584,18 +413,16 @@ nsSubscribableServer::AddChildNode(Subsc
             current->prevSibling = (*child);
             if (!(*child)->prevSibling) {
                 parent->firstChild = (*child);
             }
             else {
                 (*child)->prevSibling->nextSibling = (*child);
             }
 
-            rv = NotifyAssert(parent, kNC_Child, *child);
-            NS_ENSURE_SUCCESS(rv,rv);
             return NS_OK;
         }
         current = current->nextSibling;
         if (current) {
             NS_ASSERTION(current->name, "no name!");
             compare = strcmp(current->name,name);
         }
         else {
@@ -616,18 +443,16 @@ nsSubscribableServer::AddChildNode(Subsc
     rv = CreateNode(parent, name, aPath, child);
     NS_ENSURE_SUCCESS(rv,rv);
 
     (*child)->prevSibling = parent->lastChild;
     (*child)->nextSibling = nullptr;
     parent->lastChild->nextSibling = *child;
     parent->lastChild = *child;
 
-    rv = NotifyAssert(parent, kNC_Child, *child);
-    NS_ENSURE_SUCCESS(rv,rv);
     return NS_OK;
 }
 
 nsresult
 nsSubscribableServer::FindAndCreateNode(const nsACString &aPath,
                                         SubscribeTreeNode **aResult)
 {
   nsresult rv = NS_OK;
@@ -766,76 +591,62 @@ nsSubscribableServer::GetFirstChildURI(c
     NS_ENSURE_SUCCESS(rv,rv);
 
     NS_ASSERTION(node,"didn't find the node");
     if (!node) return NS_ERROR_FAILURE;
 
     // no children
     if (!node->firstChild) return NS_ERROR_FAILURE;
 
-    BuildURIFromNode(node->firstChild, aResult);
+    aResult.Assign(node->firstChild->path);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsSubscribableServer::GetChildren(const nsACString &aPath,
-                                  nsISimpleEnumerator **aResult)
+nsSubscribableServer::GetChildURIs(const nsACString &aPath,
+                                   nsIUTF8StringEnumerator **aResult)
 {
     SubscribeTreeNode *node = nullptr;
     nsresult rv = FindAndCreateNode(aPath, &node);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ASSERTION(node,"didn't find the node");
     if (!node)
       return NS_ERROR_FAILURE;
 
-    nsAutoCString uriPrefix;
     NS_ASSERTION(mTreeRoot, "no tree root!");
     if (!mTreeRoot)
       return NS_ERROR_UNEXPECTED;
 
-    uriPrefix = mTreeRoot->name; // the root's name is the server uri
-    uriPrefix += "/";
-    if (!aPath.IsEmpty()) {
-        uriPrefix += aPath;
-        uriPrefix += mDelimiter;
-    }
-
-    // we inserted them in reverse alphabetical order.
-    // so pull them out in reverse to get the right order
-    // in the subscribe dialog
+    // We inserted them in reverse alphabetical order.
+    // So pull them out in reverse to get the right order
+    // in the subscribe dialog.
     SubscribeTreeNode *current = node->lastChild;
     // return failure if there are no children.
     if (!current)
       return NS_ERROR_FAILURE;
 
-    nsCOMArray<nsIRDFResource> result;
+    nsTArray<nsCString> *result = new nsTArray<nsCString>;
 
     while (current) {
-        nsAutoCString uri;
-        uri = uriPrefix;
         NS_ASSERTION(current->name, "no name");
         if (!current->name)
           return NS_ERROR_FAILURE;
 
-        uri += current->name;
-
-        nsCOMPtr <nsIRDFResource> res;
-        rv = EnsureRDFService();
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        // todo, is this creating nsMsgFolders?
-        mRDFService->GetResource(uri, getter_AddRefs(res));
-        result.AppendObject(res);
+        result->AppendElement(current->path);
 
         current = current->prevSibling;
     }
 
-    return NS_NewArrayEnumerator(aResult, result, NS_GET_IID(nsIRDFResource));
+    rv = NS_NewAdoptingUTF8StringEnumerator(aResult, result);
+    if (NS_FAILED(rv))
+      delete result;
+
+    return rv;
 }
 
 NS_IMETHODIMP
 nsSubscribableServer::CommitSubscribeChanges()
 {
     NS_ASSERTION(false,"override this.");
     return NS_ERROR_FAILURE;
 }
--- a/mailnews/base/src/nsSubscribableServer.h
+++ b/mailnews/base/src/nsSubscribableServer.h
@@ -8,19 +8,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIMsgIncomingServer.h"
 #include "nsITreeBoxObject.h"
 #include "nsITreeSelection.h"
 #include "nsITreeView.h"
 #include "nsISubscribableServer.h"
-#include "nsIRDFService.h"
-#include "nsSubscribeDataSource.h"
-#include "nsIRDFResource.h"
 #include "nsTArray.h"
 
 /**
  * The basic structure for the tree of the implementation.
  *
  * These elements are stored in reverse alphabetical order.
  */
 typedef struct _subscribeTreeNode {
@@ -57,42 +54,28 @@ public:
   NS_DECL_NSITREEVIEW
 
 private:
   virtual ~nsSubscribableServer();
 
   nsresult ConvertNameToUnichar(const char *inStr, char16_t **outStr);
   nsCOMPtr <nsISubscribeListener> mSubscribeListener;
   nsCString mIncomingServerUri;
-  nsCOMPtr <nsISubscribeDataSource> mSubscribeDS;
   char mDelimiter;
   bool mShowFullName;
   bool mStopped;
   nsCString mServerType;
 
-  nsCOMPtr <nsIRDFResource>      kNC_Child;
-  nsCOMPtr <nsIRDFResource>      kNC_Subscribed;
-  nsCOMPtr <nsIRDFLiteral>       kTrueLiteral;
-  nsCOMPtr <nsIRDFLiteral>       kFalseLiteral;
-
-  nsCOMPtr <nsIRDFService>       mRDFService;
-
   SubscribeTreeNode *mTreeRoot;          // root of the folder tree while items are discovered on the server
   nsTArray<SubscribeTreeNode*> mRowMap;  // array of nodes representing the rows for the tree element
   nsCOMPtr<nsITreeSelection> mSelection;
   nsCOMPtr<nsITreeBoxObject> mTree;
   nsresult FreeSubtree(SubscribeTreeNode *node);
   nsresult FreeRows();
   nsresult CreateNode(SubscribeTreeNode *parent, const char *name, const nsACString &aPath, SubscribeTreeNode **result);
   nsresult AddChildNode(SubscribeTreeNode *parent, const char *name, const nsACString &aPath, SubscribeTreeNode **child);
   nsresult FindAndCreateNode(const nsACString &aPath, SubscribeTreeNode **aResult);
-  nsresult NotifyAssert(SubscribeTreeNode *subjectNode, nsIRDFResource *property, SubscribeTreeNode *objectNode);
-  nsresult NotifyChange(SubscribeTreeNode *subjectNode, nsIRDFResource *property, bool value);
-  nsresult Notify(nsIRDFResource *subject, nsIRDFResource *property, nsIRDFNode *object, bool isAssert, bool isChange);
-  void BuildURIFromNode(SubscribeTreeNode *node, nsACString &uri);
-  nsresult EnsureSubscribeDS();
-  nsresult EnsureRDFService();
 
   int32_t GetRow(SubscribeTreeNode *node, bool *open);
   int32_t AddSubtree(SubscribeTreeNode *node, int32_t index);
 };
 
 #endif // nsSubscribableServer_h__
deleted file mode 100644
--- a/mailnews/base/src/nsSubscribeDataSource.cpp
+++ /dev/null
@@ -1,671 +0,0 @@
-/* -*- 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 "nsSubscribeDataSource.h"
-
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
-#include "nsIComponentManager.h"
-#include "rdf.h"
-#include "nsIServiceManager.h"
-#include "nsEnumeratorUtils.h"
-#include "nsString.h"
-#include "nsCOMPtr.h"
-#include "nsIMsgFolder.h"
-#include "nsIMsgIncomingServer.h"
-#include "nsCOMArray.h"
-#include "nsArrayEnumerator.h"
-#include "nsServiceManagerUtils.h"
-#include "nsComponentManagerUtils.h"
-#include "nsMsgUtils.h"
-
-static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
-
-nsSubscribeDataSource::nsSubscribeDataSource()
-{
-}
-
-nsSubscribeDataSource::~nsSubscribeDataSource()
-{
-}
-
-NS_IMPL_ISUPPORTS(nsSubscribeDataSource, nsIRDFDataSource, nsISubscribeDataSource)
-
-nsresult
-nsSubscribeDataSource::Init()
-{
-    nsresult rv;
-
-    mRDFService = do_GetService(kRDFServiceCID, &rv);
-    NS_ASSERTION(NS_SUCCEEDED(rv) && mRDFService, "failed to get rdf service");
-    NS_ENSURE_SUCCESS(rv,rv);
-    if (!mRDFService) return NS_ERROR_FAILURE;
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
-                                  getter_AddRefs(kNC_Child));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
-                                  getter_AddRefs(kNC_Name));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "LeafName"),
-                                  getter_AddRefs(kNC_LeafName));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Subscribed"),
-                                  getter_AddRefs(kNC_Subscribed));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Subscribable"),
-                                  getter_AddRefs(kNC_Subscribable));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ServerType"),
-                                  getter_AddRefs(kNC_ServerType));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetLiteral(u"true", getter_AddRefs(kTrueLiteral));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = mRDFService->GetLiteral(u"false", getter_AddRefs(kFalseLiteral));
-    NS_ENSURE_SUCCESS(rv,rv);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetURI(nsACString& aURI)
-{
-  aURI.AssignLiteral("rdf:subscribe");
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetSource(nsIRDFResource *property, nsIRDFNode *target, bool tv, nsIRDFResource **source)
-{
-    NS_ASSERTION(property != nullptr, "null ptr");
-    if (! property)
-        return NS_ERROR_NULL_POINTER;
-
-    NS_ASSERTION(target != nullptr, "null ptr");
-    if (! target)
-        return NS_ERROR_NULL_POINTER;
-
-    NS_ASSERTION(source != nullptr, "null ptr");
-    if (! source)
-        return NS_ERROR_NULL_POINTER;
-
-    *source = nullptr;
-    return NS_RDF_NO_VALUE;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetTarget(nsIRDFResource *source,
-                                nsIRDFResource *property,
-                                bool tv,
-                                nsIRDFNode **target /* out */)
-{
-  nsresult rv = NS_RDF_NO_VALUE;
-
-  NS_ASSERTION(source != nullptr, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(property != nullptr, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(target != nullptr, "null ptr");
-  if (! target)
-    return NS_ERROR_NULL_POINTER;
-
-  *target = nullptr;
-
-  // we only have positive assertions in the subscribe data source.
-  if (! tv) return NS_RDF_NO_VALUE;
-
-    nsCOMPtr<nsISubscribableServer> server;
-    nsCString relativePath;
-    rv = GetServerAndRelativePathFromResource(source, getter_AddRefs(server), getter_Copies(relativePath));
-    if (NS_FAILED(rv) || !server)
-        return NS_RDF_NO_VALUE;
-
-    if (property == kNC_Name.get()) {
-        nsCOMPtr<nsIRDFLiteral> name;
-        rv = mRDFService->GetLiteral(NS_ConvertUTF8toUTF16(relativePath).get(),
-                                     getter_AddRefs(name));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        if (!name) rv = NS_RDF_NO_VALUE;
-        if (rv == NS_RDF_NO_VALUE) return(rv);
-        return name->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
-    }
-    else if (property == kNC_Child.get()) {
-        nsCString childUri;
-        rv = server->GetFirstChildURI(relativePath, childUri);
-        if (NS_FAILED(rv)) return NS_RDF_NO_VALUE;
-        if (childUri.IsEmpty()) return NS_RDF_NO_VALUE;
-
-        nsCOMPtr <nsIRDFResource> childResource;
-        rv = mRDFService->GetResource(childUri, getter_AddRefs(childResource));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return childResource->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
-    }
-    else if (property == kNC_Subscribed.get()) {
-        bool isSubscribed;
-        rv = server->IsSubscribed(relativePath, &isSubscribed);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        NS_IF_ADDREF(*target = isSubscribed ? kTrueLiteral : kFalseLiteral);
-        return NS_OK;
-    }
-    else if (property == kNC_Subscribable.get()) {
-        bool isSubscribable;
-        rv = server->IsSubscribable(relativePath, &isSubscribable);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        NS_IF_ADDREF(*target = isSubscribable ? kTrueLiteral : kFalseLiteral);
-        return NS_OK;
-    }
-    else if (property == kNC_ServerType.get()) {
-        nsCString serverTypeStr;
-        rv = GetServerType(server, serverTypeStr);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        nsCOMPtr<nsIRDFLiteral> serverType;
-        rv = mRDFService->GetLiteral(NS_ConvertASCIItoUTF16(serverTypeStr).get(),
-                                     getter_AddRefs(serverType));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        if (!serverType)
-          rv = NS_RDF_NO_VALUE;
-        if (rv == NS_RDF_NO_VALUE)
-          return rv;
-        return serverType->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
-    }
-    else if (property == kNC_LeafName.get()) {
-        nsString leafNameStr;
-        rv = server->GetLeafName(relativePath, leafNameStr);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        nsCOMPtr<nsIRDFLiteral> leafName;
-        rv = mRDFService->GetLiteral(leafNameStr.get(), getter_AddRefs(leafName));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        if (!leafName)
-          rv = NS_RDF_NO_VALUE;
-        if (rv == NS_RDF_NO_VALUE)
-          return rv;
-        return leafName->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
-    }
-    else {
-        // do nothing
-    }
-
-  return(NS_RDF_NO_VALUE);
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetTargets(nsIRDFResource *source,
-        nsIRDFResource *property,
-        bool tv,
-        nsISimpleEnumerator **targets /* out */)
-{
-  nsresult rv = NS_OK;
-
-  NS_ASSERTION(source != nullptr, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(property != nullptr, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(targets != nullptr, "null ptr");
-  if (! targets)
-    return NS_ERROR_NULL_POINTER;
-
-  *targets = nullptr;
-
-  // we only have positive assertions in the subscribe data source.
-  if (!tv) return NS_RDF_NO_VALUE;
-
-    nsCOMPtr<nsISubscribableServer> server;
-    nsCString relativePath;  // UTF-8
-
-    rv = GetServerAndRelativePathFromResource(source, getter_AddRefs(server), getter_Copies(relativePath));
-    if (NS_FAILED(rv) || !server) {
-      return NS_NewEmptyEnumerator(targets);
-    }
-
-    if (property == kNC_Child.get()) {
-        rv = server->GetChildren(relativePath, targets);
-        if (NS_FAILED(rv)) {
-            return NS_NewEmptyEnumerator(targets);
-        }
-        return rv;
-    }
-    else if (property == kNC_LeafName.get()) {
-        nsString leafNameStr;
-        rv = server->GetLeafName(relativePath, leafNameStr);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        nsCOMPtr<nsIRDFLiteral> leafName;
-        rv = mRDFService->GetLiteral(leafNameStr.get(), getter_AddRefs(leafName));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return NS_NewSingletonEnumerator(targets, leafName);
-    }
-    else if (property == kNC_Subscribed.get()) {
-        bool isSubscribed;
-        rv = server->IsSubscribed(relativePath, &isSubscribed);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return NS_NewSingletonEnumerator(targets,
-                 isSubscribed ? kTrueLiteral : kFalseLiteral);
-    }
-    else if (property == kNC_Subscribable.get()) {
-        bool isSubscribable;
-        rv = server->IsSubscribable(relativePath, &isSubscribable);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return NS_NewSingletonEnumerator(targets,
-                 isSubscribable ? kTrueLiteral : kFalseLiteral);
-    }
-    else if (property == kNC_Name.get()) {
-        nsCOMPtr<nsIRDFLiteral> name;
-        rv = mRDFService->GetLiteral(NS_ConvertUTF8toUTF16(relativePath).get(),
-                                     getter_AddRefs(name));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return NS_NewSingletonEnumerator(targets, name);
-    }
-    else if (property == kNC_ServerType.get()) {
-        nsCString serverTypeStr;
-        rv = GetServerType(server, serverTypeStr);
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        nsCOMPtr<nsIRDFLiteral> serverType;
-        rv = mRDFService->GetLiteral(NS_ConvertASCIItoUTF16(serverTypeStr).get(),
-                                     getter_AddRefs(serverType));
-        NS_ENSURE_SUCCESS(rv,rv);
-
-        return NS_NewSingletonEnumerator(targets, serverType);
-    }
-    else {
-        // do nothing
-    }
-
-  return NS_NewEmptyEnumerator(targets);
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::Assert(nsIRDFResource *source,
-                       nsIRDFResource *property,
-                       nsIRDFNode *target,
-                       bool tv)
-{
-  return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::Unassert(nsIRDFResource *source,
-                         nsIRDFResource *property,
-                         nsIRDFNode *target)
-{
-  return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::Change(nsIRDFResource* aSource,
-                              nsIRDFResource* aProperty,
-                              nsIRDFNode* aOldTarget,
-                              nsIRDFNode* aNewTarget)
-{
-  return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::Move(nsIRDFResource* aOldSource,
-                            nsIRDFResource* aNewSource,
-                            nsIRDFResource* aProperty,
-                            nsIRDFNode* aTarget)
-{
-  return NS_RDF_ASSERTION_REJECTED;
-}
-
-nsresult
-nsSubscribeDataSource::GetServerType(nsISubscribableServer *server, nsACString& serverType)
-{
-  NS_ENSURE_ARG_POINTER(server);
-  nsresult rv;
-  nsCOMPtr<nsIMsgIncomingServer> incomingServer(do_QueryInterface(server, &rv));
-  NS_ENSURE_SUCCESS(rv,rv);
-  return incomingServer->GetType(serverType);
-}
-
-nsresult
-nsSubscribeDataSource::GetServerAndRelativePathFromResource(nsIRDFResource *source, nsISubscribableServer **server, char **relativePath)
-{
-    nsresult rv = NS_OK;
-
-    const char *sourceURI = nullptr;
-    rv = source->GetValueConst(&sourceURI);
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    nsCOMPtr<nsIMsgFolder> folder(do_QueryInterface(source, &rv));
-    // we expect this to fail sometimes, so don't assert
-    if (NS_FAILED(rv))
-      return rv;
-
-    nsCOMPtr<nsIMsgIncomingServer> incomingServer;
-    rv = folder->GetServer(getter_AddRefs(incomingServer));
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    rv = incomingServer->QueryInterface(NS_GET_IID(nsISubscribableServer), (void**)server);
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    nsCString serverURI;
-    rv = incomingServer->GetServerURI(serverURI);
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    uint32_t serverURILen = serverURI.Length();
-    if (serverURILen == strlen(sourceURI))
-      *relativePath = nullptr;
-    else {
-      // XXX : perhaps, have to unescape before returning
-      *relativePath = strdup(sourceURI + serverURILen + 1);
-      if (!*relativePath)
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::HasAssertion(nsIRDFResource *source,
-                             nsIRDFResource *property,
-                             nsIRDFNode *target,
-                             bool tv,
-                             bool *hasAssertion /* out */)
-{
-  nsresult rv = NS_OK;
-
-  NS_ASSERTION(source != nullptr, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(property != nullptr, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(target != nullptr, "null ptr");
-  if (! target)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_ASSERTION(hasAssertion != nullptr, "null ptr");
-  if (! hasAssertion)
-    return NS_ERROR_NULL_POINTER;
-
-  *hasAssertion = false;
-
-  // we only have positive assertions in the subscribe data source.
-  if (!tv) return NS_OK;
-
-  if (property == kNC_Child.get()) {
-    nsCOMPtr<nsISubscribableServer> server;
-    nsCString relativePath;
-
-    rv = GetServerAndRelativePathFromResource(source, getter_AddRefs(server), getter_Copies(relativePath));
-    if (NS_FAILED(rv) || !server) {
-        *hasAssertion = false;
-        return NS_OK;
-    }
-
-        // not everything has children
-        rv = server->HasChildren(relativePath, hasAssertion);
-        NS_ENSURE_SUCCESS(rv,rv);
-    }
-    else if (property == kNC_Name.get()) {
-        // everything has a name
-        *hasAssertion = true;
-    }
-    else if (property == kNC_LeafName.get()) {
-        // everything has a leaf name
-        *hasAssertion = true;
-    }
-    else if (property == kNC_Subscribed.get()) {
-        // everything is subscribed or not
-        *hasAssertion = true;
-    }
-    else if (property == kNC_Subscribable.get()) {
-        // everything is subscribable or not
-        *hasAssertion = true;
-    }
-    else if (property == kNC_ServerType.get()) {
-        // everything has a server type
-        *hasAssertion = true;
-    }
-    else {
-        // do nothing
-    }
-
-  return NS_OK;
-}
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, bool *result)
-{
-    return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, bool *result)
-{
-    nsresult rv = NS_OK;
-
-    nsCOMPtr<nsISubscribableServer> server;
-    nsCString relativePath;
-
-    if (aArc == kNC_Child.get()) {
-    rv = GetServerAndRelativePathFromResource(source, getter_AddRefs(server), getter_Copies(relativePath));
-        if (NS_FAILED(rv) || !server) {
-          *result = false;
-            return NS_OK;
-        }
-
-        bool hasChildren = false;
-        rv = server->HasChildren(relativePath, &hasChildren);
-        NS_ENSURE_SUCCESS(rv,rv);
-        *result = hasChildren;
-        return NS_OK;
-    }
-    else if ((aArc == kNC_Subscribed.get()) ||
-             (aArc == kNC_Subscribable.get()) ||
-             (aArc == kNC_LeafName.get()) ||
-             (aArc == kNC_ServerType.get()) ||
-             (aArc == kNC_Name.get())) {
-        *result = true;
-        return NS_OK;
-    }
-
-    *result = false;
-    return NS_OK;
-}
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::ArcLabelsIn(nsIRDFNode *node,
-                            nsISimpleEnumerator ** labels /* out */)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::ArcLabelsOut(nsIRDFResource *source,
-           nsISimpleEnumerator **labels /* out */)
-{
-    nsresult rv = NS_OK;
-
-    NS_ASSERTION(source != nullptr, "null ptr");
-    if (! source)
-      return NS_ERROR_NULL_POINTER;
-
-    NS_ASSERTION(labels != nullptr, "null ptr");
-    if (! labels)
-      return NS_ERROR_NULL_POINTER;
-
-    nsCOMPtr<nsISubscribableServer> server;
-    nsCString relativePath;
-
-    rv = GetServerAndRelativePathFromResource(source, getter_AddRefs(server), getter_Copies(relativePath));
-    if (NS_FAILED(rv) || !server) {
-        return NS_NewEmptyEnumerator(labels);
-    }
-
-    bool hasChildren = false;
-    rv = server->HasChildren(relativePath, &hasChildren);
-    NS_ENSURE_SUCCESS(rv,rv);
-
-    // Initialise with the number of items below, to save reallocating on each
-    // addition.
-    nsCOMArray<nsIRDFResource> array(hasChildren ? 6 : 5);
-
-    array.AppendObject(kNC_Subscribed);
-    array.AppendObject(kNC_Subscribable);
-    array.AppendObject(kNC_Name);
-    array.AppendObject(kNC_ServerType);
-    array.AppendObject(kNC_LeafName);
-
-    if (hasChildren) {
-        array.AppendObject(kNC_Child);
-    }
-
-    return NS_NewArrayEnumerator(labels, array, NS_GET_IID(nsIRDFResource));
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
-{
-  MOZ_ASSERT_UNREACHABLE("sorry!");
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::AddObserver(nsIRDFObserver *n)
-{
-  NS_ENSURE_ARG_POINTER(n);
-  mObservers.AppendElement(n);
-  return NS_OK;
-}
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::RemoveObserver(nsIRDFObserver *n)
-{
-  NS_ENSURE_ARG_POINTER(n);
-  mObservers.RemoveElement(n);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetHasObservers(bool *hasObservers)
-{
-  NS_ENSURE_ARG_POINTER(hasObservers);
-  *hasObservers = !mObservers.IsEmpty();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetAllCmds(nsIRDFResource* source,
-                                     nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
-{
-  return(NS_NewEmptyEnumerator(commands));
-}
-
-NS_IMETHODIMP
-nsSubscribeDataSource::IsCommandEnabled(nsISupports/*nsISupportsArray<nsIRDFResource>*/* aSources,
-                                        nsIRDFResource*   aCommand,
-                                        nsISupports/*nsISupportsArray<nsIRDFResource>*/* aArguments,
-                                        bool* aResult)
-{
-  return(NS_ERROR_NOT_IMPLEMENTED);
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::DoCommand(nsISupports/*nsISupportsArray<nsIRDFResource>*/* aSources,
-                                 nsIRDFResource*   aCommand,
-                                 nsISupports/*nsISupportsArray<nsIRDFResource>*/* aArguments)
-{
-  return(NS_ERROR_NOT_IMPLEMENTED);
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::BeginUpdateBatch()
-{
-        return NS_OK;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::EndUpdateBatch()
-{
-        return NS_OK;
-}
-
-
-
-NS_IMETHODIMP
-nsSubscribeDataSource::GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, bool aTruthValue, nsISimpleEnumerator **_retval)
-{
-  NS_ASSERTION(false, "Not implemented");
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-#define NOTIFY_SUBSCRIBE_LISTENERS(propertyfunc_, params_) \
-  PR_BEGIN_MACRO \
-  { \
-    nsTObserverArray<nsCOMPtr<nsIRDFObserver> >::ForwardIterator iter(mObservers); \
-    while (iter.HasMore()) \
-    { \
-      iter.GetNext()->propertyfunc_ params_; \
-    } \
-  } \
-  PR_END_MACRO
-
-NS_IMETHODIMP
-nsSubscribeDataSource::NotifyObservers(nsIRDFResource *subject,
-                                                nsIRDFResource *property,
-                                                nsIRDFNode *object,
-                                                bool assert, bool change)
-{
-  NS_ASSERTION(!(change && assert),
-               "Can't change and assert at the same time!\n");
-
-  if (change)
-    NOTIFY_SUBSCRIBE_LISTENERS(OnChange, (this, subject, property, nullptr, object));
-  else if (assert)
-    NOTIFY_SUBSCRIBE_LISTENERS(OnAssert, (this, subject, property, object));
-  else
-    NOTIFY_SUBSCRIBE_LISTENERS(OnUnassert, (this, subject, property, object));
-  return NS_OK;
-}
deleted file mode 100644
--- a/mailnews/base/src/nsSubscribeDataSource.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- 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/. */
-
-#ifndef nsSubscribeDataSource_h__
-#define nsSubscribeDataSource_h__
-
-#include "nsIRDFService.h"
-#include "nsIRDFDataSource.h"
-#include "nsIRDFResource.h"
-#include "nsIRDFLiteral.h"
-#include "nsCOMPtr.h"
-#include "nsISubscribableServer.h"
-#include "nsTObserverArray.h"
-
-/**
- * The subscribe data source.
- */
-class nsSubscribeDataSource : public nsIRDFDataSource, public nsISubscribeDataSource
-{
-
-public:
-  nsSubscribeDataSource();
-
-  nsresult Init();
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSIRDFDATASOURCE
-  NS_DECL_NSISUBSCRIBEDATASOURCE
-
-private:
-  virtual ~nsSubscribeDataSource();
-  nsCOMPtr <nsIRDFResource>      kNC_Child;
-  nsCOMPtr <nsIRDFResource>      kNC_Name;
-  nsCOMPtr <nsIRDFResource>      kNC_LeafName;
-  nsCOMPtr <nsIRDFResource>      kNC_Subscribed;
-  nsCOMPtr <nsIRDFResource>      kNC_Subscribable;
-  nsCOMPtr <nsIRDFResource>      kNC_ServerType;
-  nsCOMPtr <nsIRDFLiteral>       kTrueLiteral;
-  nsCOMPtr <nsIRDFLiteral>       kFalseLiteral;
-
-  nsCOMPtr <nsIRDFService>       mRDFService;
-  nsTObserverArray<nsCOMPtr<nsIRDFObserver> >  mObservers;
-
-  nsresult GetServerAndRelativePathFromResource(nsIRDFResource *source, nsISubscribableServer **server, char **relativePath);
-  nsresult GetServerType(nsISubscribableServer *server, nsACString& serverType);
-};
-
-#endif /* nsSubscribedDataSource_h__ */
--- a/mailnews/build/nsMailModule.cpp
+++ b/mailnews/build/nsMailModule.cpp
@@ -65,17 +65,16 @@
 #include "nsMsgKeyArray.h"
 #include "nsCopyMessageStreamListener.h"
 #include "nsMsgCopyService.h"
 #include "nsMsgFolderCache.h"
 #include "nsMsgStatusFeedback.h"
 #include "nsMsgFilterService.h"
 #include "nsMsgWindow.h"
 #include "nsMsgServiceProvider.h"
-#include "nsSubscribeDataSource.h"
 #include "nsSubscribableServer.h"
 #ifdef NS_PRINTING
 #include "nsMsgPrintEngine.h"
 #endif
 #include "nsMsgSearchSession.h"
 #include "nsMsgSearchTerm.h"
 #include "nsMsgSearchAdapter.h"
 #include "nsMsgFolderCompactor.h"
@@ -336,17 +335,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgPurg
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStatusBarBiffManager, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCopyMessageStreamListener)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgCopyService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgFolderCache)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgStatusFeedback)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgKeyArray)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgWindow,Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgServiceProviderService, Init)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSubscribeDataSource, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSubscribableServer, Init)
 #ifdef NS_PRINTING
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgPrintEngine)
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFolderCompactState)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsOfflineStoreCompactState)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgThreadedDBView)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgThreadsWithUnreadDBView)
@@ -396,17 +394,16 @@ NS_DEFINE_NAMED_CID(NS_MSGCOPYSERVICE_CI
 NS_DEFINE_NAMED_CID(NS_MSGFOLDERCACHE_CID);
 NS_DEFINE_NAMED_CID(NS_MSGSTATUSFEEDBACK_CID);
 NS_DEFINE_NAMED_CID(NS_MSGWINDOW_CID);
 NS_DEFINE_NAMED_CID(NS_MSGKEYARRAY_CID);
 #ifdef NS_PRINTING
 NS_DEFINE_NAMED_CID(NS_MSG_PRINTENGINE_CID);
 #endif
 NS_DEFINE_NAMED_CID(NS_MSGSERVICEPROVIDERSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_SUBSCRIBEDATASOURCE_CID);
 NS_DEFINE_NAMED_CID(NS_SUBSCRIBABLESERVER_CID);
 NS_DEFINE_NAMED_CID(NS_MSGLOCALFOLDERCOMPACTOR_CID);
 NS_DEFINE_NAMED_CID(NS_MSG_OFFLINESTORECOMPACTOR_CID);
 NS_DEFINE_NAMED_CID(NS_MSGTHREADEDDBVIEW_CID);
 NS_DEFINE_NAMED_CID(NS_MSGTHREADSWITHUNREADDBVIEW_CID);
 NS_DEFINE_NAMED_CID(NS_MSGWATCHEDTHREADSWITHUNREADDBVIEW_CID);
 NS_DEFINE_NAMED_CID(NS_MSGSEARCHDBVIEW_CID);
 NS_DEFINE_NAMED_CID(NS_MSGQUICKSEARCHDBVIEW_CID);
@@ -860,17 +857,16 @@ const mozilla::Module::CIDEntry kMailNew
   { &kNS_MSGFOLDERCACHE_CID, false, NULL, nsMsgFolderCacheConstructor},
   { &kNS_MSGSTATUSFEEDBACK_CID, false, NULL, nsMsgStatusFeedbackConstructor},
   { &kNS_MSGKEYARRAY_CID, false, NULL, nsMsgKeyArrayConstructor},
   { &kNS_MSGWINDOW_CID, false, NULL, nsMsgWindowConstructor},
 #ifdef NS_PRINTING
   { &kNS_MSG_PRINTENGINE_CID, false, NULL, nsMsgPrintEngineConstructor},
 #endif
   { &kNS_MSGSERVICEPROVIDERSERVICE_CID, false, NULL, nsMsgServiceProviderServiceConstructor},
-  { &kNS_SUBSCRIBEDATASOURCE_CID, false, NULL, nsSubscribeDataSourceConstructor},
   { &kNS_SUBSCRIBABLESERVER_CID, false, NULL, nsSubscribableServerConstructor},
   { &kNS_MSGLOCALFOLDERCOMPACTOR_CID, false, NULL, nsFolderCompactStateConstructor},
   { &kNS_MSG_OFFLINESTORECOMPACTOR_CID, false, NULL, nsOfflineStoreCompactStateConstructor},
   { &kNS_MSGTHREADEDDBVIEW_CID, false, NULL, nsMsgThreadedDBViewConstructor},
   { &kNS_MSGTHREADSWITHUNREADDBVIEW_CID, false, NULL, nsMsgThreadsWithUnreadDBViewConstructor},
   { &kNS_MSGWATCHEDTHREADSWITHUNREADDBVIEW_CID, false, NULL, nsMsgWatchedThreadsWithUnreadDBViewConstructor
 },
   { &kNS_MSGSEARCHDBVIEW_CID, false, NULL, nsMsgSearchDBViewConstructor},
@@ -1069,17 +1065,16 @@ const mozilla::Module::ContractIDEntry k
   { NS_MSGFOLDERCACHE_CONTRACTID, &kNS_MSGFOLDERCACHE_CID },
   { NS_MSGSTATUSFEEDBACK_CONTRACTID, &kNS_MSGSTATUSFEEDBACK_CID },
   { NS_MSGKEYARRAY_CONTRACTID, &kNS_MSGKEYARRAY_CID },
   { NS_MSGWINDOW_CONTRACTID, &kNS_MSGWINDOW_CID },
 #ifdef NS_PRINTING
   { NS_MSGPRINTENGINE_CONTRACTID, &kNS_MSG_PRINTENGINE_CID },
 #endif
   { NS_MSGSERVICEPROVIDERSERVICE_CONTRACTID, &kNS_MSGSERVICEPROVIDERSERVICE_CID },
-  { NS_SUBSCRIBEDATASOURCE_CONTRACTID, &kNS_SUBSCRIBEDATASOURCE_CID },
   { NS_SUBSCRIBABLESERVER_CONTRACTID, &kNS_SUBSCRIBABLESERVER_CID },
   { NS_MSGLOCALFOLDERCOMPACTOR_CONTRACTID, &kNS_MSGLOCALFOLDERCOMPACTOR_CID },
   { NS_MSGOFFLINESTORECOMPACTOR_CONTRACTID, &kNS_MSG_OFFLINESTORECOMPACTOR_CID },
   { NS_MSGTHREADEDDBVIEW_CONTRACTID, &kNS_MSGTHREADEDDBVIEW_CID },
   { NS_MSGTHREADSWITHUNREADDBVIEW_CONTRACTID, &kNS_MSGTHREADSWITHUNREADDBVIEW_CID },
   { NS_MSGWATCHEDTHREADSWITHUNREADDBVIEW_CONTRACTID, &kNS_MSGWATCHEDTHREADSWITHUNREADDBVIEW_CID },
   { NS_MSGSEARCHDBVIEW_CONTRACTID, &kNS_MSGSEARCHDBVIEW_CID },
   { NS_MSGQUICKSEARCHDBVIEW_CONTRACTID, &kNS_MSGQUICKSEARCHDBVIEW_CID },
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -2644,22 +2644,22 @@ nsImapIncomingServer::GetFirstChildURI(c
 {
   nsresult rv = EnsureInner();
   NS_ENSURE_SUCCESS(rv,rv);
   return mInner->GetFirstChildURI(path, aResult);
 }
 
 
 NS_IMETHODIMP
-nsImapIncomingServer::GetChildren(const nsACString &aPath,
-                                  nsISimpleEnumerator **aResult)
+nsImapIncomingServer::GetChildURIs(const nsACString &aPath,
+                                   nsIUTF8StringEnumerator **aResult)
 {
   nsresult rv = EnsureInner();
   NS_ENSURE_SUCCESS(rv,rv);
-  return mInner->GetChildren(aPath, aResult);
+  return mInner->GetChildURIs(aPath, aResult);
 }
 
 nsresult
 nsImapIncomingServer::EnsureInner()
 {
   nsresult rv = NS_OK;
 
   if (mInner)
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -1325,22 +1325,22 @@ NS_IMETHODIMP
 nsNntpIncomingServer::GetFirstChildURI(const nsACString &path, nsACString &aResult)
 {
   nsresult rv = EnsureInner();
   NS_ENSURE_SUCCESS(rv,rv);
   return mInner->GetFirstChildURI(path, aResult);
 }
 
 NS_IMETHODIMP
-nsNntpIncomingServer::GetChildren(const nsACString &aPath,
-                                  nsISimpleEnumerator **aResult)
+nsNntpIncomingServer::GetChildURIs(const nsACString &aPath,
+                                   nsIUTF8StringEnumerator **aResult)
 {
   nsresult rv = EnsureInner();
   NS_ENSURE_SUCCESS(rv,rv);
-  return mInner->GetChildren(aPath, aResult);
+  return mInner->GetChildURIs(aPath, aResult);
 }
 
 NS_IMETHODIMP
 nsNntpIncomingServer::CommitSubscribeChanges()
 {
   // we force the newrc to be dirty, so it will get written out when
   // we call WriteNewsrcFile()
   nsresult rv = SetNewsrcHasChanged(true);
--- a/mailnews/news/test/unit/test_internalUris.js
+++ b/mailnews/news/test/unit/test_internalUris.js
@@ -149,36 +149,39 @@ function* test_grouplist() {
   // This tests nsNntpService::GetListOfGroupsOnServer
   let subserver = localserver.QueryInterface(Ci.nsISubscribableServer);
   let subscribeListener = {
     OnDonePopulating: function () { async_driver(); }
   };
   subserver.subscribeListener = subscribeListener;
 
   function enumGroups(rootUri) {
-    let hierarchy = subserver.getChildren(rootUri);
+    let hierarchy = subserver.getChildURIs(rootUri);
     let groups = [];
-    while (hierarchy.hasMoreElements()) {
-      let element = hierarchy.getNext().QueryInterface(Ci.nsIRDFResource);
-      let name = element.ValueUTF8;
-      name = name.slice(name.lastIndexOf("/") + 1);
+    for (let name of hierarchy) {
       if (subserver.isSubscribable(name))
         groups.push(name);
       if (subserver.hasChildren(name))
         groups = groups.concat(enumGroups(name));
     }
     return groups;
   }
 
   MailServices.nntp.getListOfGroupsOnServer(localserver, null, false);
   yield false;
 
   let groups = enumGroups("");
-  for (let group in daemon._groups)
-    Assert.ok(groups.indexOf(group) >= 0);
+  Assert.equal(groups.length, Object.keys(daemon._groups).length);
+  for (let group in daemon._groups) {
+    Assert.ok(groups.includes(group));
+  }
+
+  // First node in the group list, even though it is not subscribable,
+  // parent of "test.empty" group.
+  Assert.equal(subserver.getFirstChildURI(""), "test");
 
   // Release reference, somehow impedes GC of 'subserver'.
   subserver.subscribeListener = null;
   yield true;
 }
 
 function* test_postMessage() {
   // This tests nsNntpService::SetUpNntpUrlForPosting via PostMessage