Bug 123679 Exclude deleted bookmarks from search results r=IanN
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 06 Aug 2009 10:54:23 +0100
changeset 3245 29283536a63924d88734e2597f80ecb397e7d11a
parent 3244 690f3249cae2cb1d4057d266f440f939e0945d00
child 3246 4344cc9a28a79af2fa2ef41eafa97cb3ba840891
push idunknown
push userunknown
push dateunknown
reviewersIanN
bugs123679
Bug 123679 Exclude deleted bookmarks from search results r=IanN
suite/browser/src/nsLocalSearchService.cpp
suite/browser/src/nsLocalSearchService.h
--- a/suite/browser/src/nsLocalSearchService.cpp
+++ b/suite/browser/src/nsLocalSearchService.cpp
@@ -41,17 +41,16 @@
   Implementation for a find RDF data store.
  */
 
 #include "nsLocalSearchService.h"
 #include "nscore.h"
 #include "nsIServiceManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
-#include "nsIRDFContainerUtils.h"
 #include "nsEnumeratorUtils.h"
 #include "nsArrayEnumerator.h"
 #include "nsUnicharUtils.h"
 #include "plhash.h"
 #include "plstr.h"
 #include "prmem.h"
 #include "prprf.h"
 #include "prio.h"
@@ -552,16 +551,20 @@ LocalSearchDataSource::parseFindURL(nsIR
       cUtils->IsContainer(datasource, source, &isContainer);
     // Check to see if this source is a pseudo-container
     if (!isContainer)
       datasource->HasArcOut(source, kNC_Child, &isContainer);
 
     if (isContainer) 
       continue;
 
+    // Check to see if this source has a parent
+    if (!nodeHasParent(datasource, source, cUtils))
+      continue;
+
     nsCOMPtr<nsIRDFResource> property;
     rv = gRDFService->GetUnicodeResource(tokens[1].value,
     getter_AddRefs(property));
 
     if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE) || !property)
       continue;
 
     nsCOMPtr<nsIRDFNode>    value;
@@ -578,16 +581,42 @@ LocalSearchDataSource::parseFindURL(nsIR
    }
 
   if (rv == NS_RDF_CURSOR_EMPTY)
     rv = NS_OK;
 
   return rv;
 }
 
+PRBool
+LocalSearchDataSource::nodeHasParent(nsIRDFDataSource *aDataSource,
+                                     nsIRDFNode *aNode,
+                                     nsIRDFContainerUtils *aUtils)
+{
+  nsCOMPtr<nsISimpleEnumerator> cursor;
+  if (NS_FAILED(aDataSource->ArcLabelsIn(aNode, getter_AddRefs(cursor))))
+    return PR_FALSE;
+
+  PRBool hasMore;
+  while (NS_SUCCEEDED(cursor->HasMoreElements(&hasMore)) && hasMore) {
+    nsCOMPtr<nsISupports> isupports;
+    if (NS_FAILED(cursor->GetNext(getter_AddRefs(isupports))))
+      break;
+
+    nsCOMPtr<nsIRDFResource> arc(do_QueryInterface(isupports));
+    if (!arc)
+      continue;
+
+    PRBool result;
+    if (NS_SUCCEEDED(aUtils->IsOrdinalProperty(arc, &result)) && result)
+      return PR_TRUE;
+  }
+  return PR_FALSE;
+}
+
 // could speed up date/integer matching signifigantly by caching the
 // last successful match data type (i.e. string, date, int) and trying
 // to QI against that first
 PRBool
 LocalSearchDataSource::matchNode(nsIRDFNode *aValue,
                                  const nsAString& matchMethod,
                                  const nsString& matchText)
 {
--- a/suite/browser/src/nsLocalSearchService.h
+++ b/suite/browser/src/nsLocalSearchService.h
@@ -39,16 +39,17 @@
 #define localsearchdb___h_____
 
 #include "nsIMutableArray.h"
 #include "nsCOMPtr.h"
 #include "nsIRDFDataSource.h"
 #include "nsStringAPI.h"
 #include "nsIRDFNode.h"
 #include "nsIRDFService.h"
+#include "nsIRDFContainerUtils.h"
 #include "nsISearchService.h"
 
 typedef	struct	_findTokenStruct
 {
 	const char		*token;
 	nsString	    value;
 } findTokenStruct, *findTokenPtr;
 
@@ -68,16 +69,19 @@ private:
 	static nsIRDFResource	*kRDF_type;
 
 protected:
 
 	NS_METHOD	getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult);
 	NS_METHOD	getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult);
 	NS_METHOD	parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens);
 
+    PRBool nodeHasParent(nsIRDFDataSource *aDataSource,
+                         nsIRDFNode *aNode,
+                         nsIRDFContainerUtils *aUtils);
     // matching functions, based on type
 	PRBool doMatch(nsIRDFLiteral  *literal,
                    const nsAString& matchMethod,
                    const nsString& matchText);
     PRBool matchNode(nsIRDFNode *aNode,
                      const nsAString& matchMethod,
                      const nsString& matchText);