Bug 374862 Port xpfe/components/search/src to frozen linkage. Original patch by Mook, one minor fixup by me,r=Neil,sr=biesi

This commit is contained in:
bugzilla@standard8.plus.com 2007-08-27 01:05:44 -07:00
parent bf7810b7de
commit 7a32f6e43f
6 changed files with 263 additions and 301 deletions

View File

@ -52,14 +52,14 @@ interface nsILocalSearchService : nsISupports
{ {
}; };
[scriptable, uuid(6bd1d803-1c67-11d3-9820-ed1b357eb3c4)] [scriptable, uuid(a0d28a88-702e-49bd-bee2-929562688ae1)]
interface nsIInternetSearchService : nsISupports interface nsIInternetSearchService : nsISupports
{ {
// constants set in the whichButtons out param of GetInternetSearchURL() // constants set in the whichButtons out param of GetInternetSearchURL()
const unsigned short kHaveNext = 1; const unsigned short kHaveNext = 1;
const unsigned short kHavePrev = 2; const unsigned short kHavePrev = 2;
string GetInternetSearchURL(in string searchEngineURI, in wstring searchStr, in short direction, in unsigned short pageNumber, out unsigned short whichButtons); wstring GetInternetSearchURL(in string searchEngineURI, in wstring searchStr, in short direction, in unsigned short pageNumber, out unsigned short whichButtons);
void RememberLastSearchText(in wstring escapedSearchStr); void RememberLastSearchText(in wstring escapedSearchStr);
boolean FindInternetSearchResults(in string url); boolean FindInternetSearchResults(in string url);
void Stop(); void Stop();

View File

@ -46,9 +46,8 @@ MODULE = appcomps
LIBRARY_NAME = searchservice LIBRARY_NAME = searchservice
SHORT_LIBNAME = srchsvc SHORT_LIBNAME = srchsvc
IS_COMPONENT = 1 IS_COMPONENT = 1
EXPORT_LIBRARY = 1
MODULE_NAME = SearchServiceModule MODULE_NAME = SearchServiceModule
MOZILLA_INTERNAL_API = 1 FORCE_SHARED_LIB = 1
REQUIRES = xpcom \ REQUIRES = xpcom \
string \ string \
@ -73,6 +72,7 @@ endif
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += \ EXTRA_DSO_LDOPTS += \
$(MOZ_UNICHARUTIL_LIBS) \ $(call EXPAND_LIBNAME_PATH,unicharutil_external_s,$(LIBXUL_DIST)/lib) \
$(XPCOM_GLUE_LDOPTS) \
$(MOZ_COMPONENT_LIBS) \ $(MOZ_COMPONENT_LIBS) \
$(NULL) $(NULL)

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@
#define nsinternetsearchdatasource__h____ #define nsinternetsearchdatasource__h____
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsString.h" #include "nsStringAPI.h"
#include "nsISearchService.h" #include "nsISearchService.h"
#include "nsIRDFDataSource.h" #include "nsIRDFDataSource.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
@ -143,7 +143,6 @@ protected:
PRBool isSearchURI(nsIRDFResource* aResource); PRBool isSearchURI(nsIRDFResource* aResource);
PRBool isSearchCategoryURI(nsIRDFResource* aResource); PRBool isSearchCategoryURI(nsIRDFResource* aResource);
PRBool isSearchCategoryEngineURI(nsIRDFResource* aResource); PRBool isSearchCategoryEngineURI(nsIRDFResource* aResource);
PRBool isSearchCategoryEngineBasenameURI(nsIRDFNode *aResource);
PRBool isSearchCommand(nsIRDFResource* aResource); PRBool isSearchCommand(nsIRDFResource* aResource);
nsresult resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine); nsresult resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine);
nsresult BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest); nsresult BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest);

View File

@ -44,10 +44,11 @@
#include "nsLocalSearchService.h" #include "nsLocalSearchService.h"
#include "nscore.h" #include "nscore.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsIRDFContainerUtils.h" #include "nsIRDFContainerUtils.h"
#include "nsEnumeratorUtils.h" #include "nsEnumeratorUtils.h"
#include "nsXPIDLString.h" #include "nsArrayEnumerator.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "plhash.h" #include "plhash.h"
#include "plstr.h" #include "plstr.h"
@ -59,7 +60,7 @@
#include "nsIRDFObserver.h" #include "nsIRDFObserver.h"
#include "nsRDFCID.h" #include "nsRDFCID.h"
#include "rdf.h" #include "rdf.h"
#include "nsCRT.h" #include "nsCRTGlue.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kTextToSubURICID, NS_TEXTTOSUBURI_CID); static NS_DEFINE_CID(kTextToSubURICID, NS_TEXTTOSUBURI_CID);
@ -166,7 +167,8 @@ LocalSearchDataSource::GetURI(char **uri)
if (! uri) if (! uri)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
if ((*uri = nsCRT::strdup("rdf:localsearch")) == nsnull) *uri = ToNewCString(NS_LITERAL_CSTRING("rdf:localsearch"));
if (! *uri)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
@ -305,7 +307,8 @@ LocalSearchDataSource::parseResourceIntoFindTokens(nsIRDFResource *u, findTokenP
return(NS_ERROR_OUT_OF_MEMORY); return(NS_ERROR_OUT_OF_MEMORY);
/* parse ID, build up token list */ /* parse ID, build up token list */
if ((token = nsCRT::strtok(id, "&", &newstr)) != NULL) newstr = id;
if ((token = NS_strtok("&", &newstr)) != NULL)
{ {
while (token != NULL) while (token != NULL)
{ {
@ -332,12 +335,12 @@ LocalSearchDataSource::parseResourceIntoFindTokens(nsIRDFResource *u, findTokenP
} }
else else
{ {
CopyASCIItoUTF16(value, tokens[loop].value); CopyASCIItoUTF16(nsDependentCString(value), tokens[loop].value);
} }
break; break;
} }
} }
token = nsCRT::strtok(newstr, "&", &newstr); token = NS_strtok("&", &newstr);
} }
} }
PL_strfree(id); PL_strfree(id);
@ -365,50 +368,32 @@ LocalSearchDataSource::doMatch(nsIRDFLiteral *literal,
if (matchMethod.EqualsLiteral("contains")) if (matchMethod.EqualsLiteral("contains"))
{ {
if (FindInReadable(matchText, value, if (-1 != value.Find(matchText, CaseInsensitiveCompare))
nsCaseInsensitiveStringComparator()))
found = PR_TRUE; found = PR_TRUE;
} }
else if (matchMethod.EqualsLiteral("startswith")) else if (matchMethod.EqualsLiteral("startswith"))
{ {
nsAString::const_iterator start, realstart, end; if (StringBeginsWith(value, matchText, CaseInsensitiveCompare))
value.BeginReading(start);
value.EndReading(end);
realstart = start;
if (FindInReadable(matchText, start, end,
nsCaseInsensitiveStringComparator()) &&
start == realstart)
found = PR_TRUE; found = PR_TRUE;
} }
else if (matchMethod.EqualsLiteral("endswith")) else if (matchMethod.EqualsLiteral("endswith"))
{ {
nsAString::const_iterator start, end, realend; if (StringEndsWith(value, matchText, CaseInsensitiveCompare))
value.BeginReading(start);
value.EndReading(end);
realend = end;
if (RFindInReadable(matchText, start, end,
nsCaseInsensitiveStringComparator()) &&
end == realend)
found = PR_TRUE; found = PR_TRUE;
} }
else if (matchMethod.EqualsLiteral("is")) else if (matchMethod.EqualsLiteral("is"))
{ {
if (value.Equals(matchText, nsCaseInsensitiveStringComparator())) if (value.Equals(matchText, CaseInsensitiveCompare))
found = PR_TRUE; found = PR_TRUE;
} }
else if (matchMethod.EqualsLiteral("isnot")) else if (matchMethod.EqualsLiteral("isnot"))
{ {
if (!value.Equals(matchText, nsCaseInsensitiveStringComparator())) if (!value.Equals(matchText, CaseInsensitiveCompare))
found = PR_TRUE; found = PR_TRUE;
} }
else if (matchMethod.EqualsLiteral("doesntcontain")) else if (matchMethod.EqualsLiteral("doesntcontain"))
{ {
if (!FindInReadable(matchText, value, if (-1 == value.Find(matchText, CaseInsensitiveCompare))
nsCaseInsensitiveStringComparator()))
found = PR_TRUE; found = PR_TRUE;
} }
return(found); return(found);
@ -445,9 +430,8 @@ LocalSearchDataSource::doIntMatch(nsIRDFInt *aInt,
rv = aInt->GetValue(&val); rv = aInt->GetValue(&val);
if (NS_FAILED(rv)) return PR_FALSE; if (NS_FAILED(rv)) return PR_FALSE;
PRInt32 error=0; PRInt32 matchVal = matchText.ToInteger(&rv);
PRInt32 matchVal = matchText.ToInteger(&error); if (NS_FAILED(rv)) return PR_FALSE;
if (error != 0) return PR_FALSE;
if (matchMethod.EqualsLiteral("is")) if (matchMethod.EqualsLiteral("is"))
found = (val == matchVal); found = (val == matchVal);
@ -499,7 +483,7 @@ LocalSearchDataSource::dateMatches(nsIRDFDate *aDate,
NS_METHOD NS_METHOD
LocalSearchDataSource::parseFindURL(nsIRDFResource *u, nsISupportsArray *array) LocalSearchDataSource::parseFindURL(nsIRDFResource *u, nsIMutableArray *array)
{ {
findTokenStruct tokens[5]; findTokenStruct tokens[5];
nsresult rv; nsresult rv;
@ -590,7 +574,7 @@ LocalSearchDataSource::parseFindURL(nsIRDFResource *u, nsISupportsArray *array)
found = matchNode(value, tokens[2].value, tokens[3].value); found = matchNode(value, tokens[2].value, tokens[3].value);
if (found) if (found)
array->AppendElement(source); array->AppendElement(source, PR_FALSE);
} }
if (rv == NS_RDF_CURSOR_EMPTY) if (rv == NS_RDF_CURSOR_EMPTY)
@ -626,8 +610,8 @@ NS_METHOD
LocalSearchDataSource::getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult) LocalSearchDataSource::getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsISupportsArray> nameArray; nsCOMPtr<nsIMutableArray> nameArray;
rv = NS_NewISupportsArray( getter_AddRefs(nameArray) ); nameArray = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = parseFindURL(source, nameArray); rv = parseFindURL(source, nameArray);
@ -854,12 +838,12 @@ LocalSearchDataSource::ArcLabelsOut(nsIRDFResource *source,
if (isFindURI(source)) if (isFindURI(source))
{ {
nsCOMPtr<nsISupportsArray> array; nsCOMPtr<nsIMutableArray> array;
rv = NS_NewISupportsArray( getter_AddRefs(array) ); array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
array->AppendElement(kNC_Child); array->AppendElement(kNC_Child, PR_FALSE);
array->AppendElement(kNC_pulse); array->AppendElement(kNC_pulse, PR_FALSE);
return NS_NewArrayEnumerator(labels, array); return NS_NewArrayEnumerator(labels, array);
} }

View File

@ -38,10 +38,10 @@
#ifndef localsearchdb___h_____ #ifndef localsearchdb___h_____
#define localsearchdb___h_____ #define localsearchdb___h_____
#include "nsISupportsArray.h" #include "nsIMutableArray.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIRDFDataSource.h" #include "nsIRDFDataSource.h"
#include "nsString.h" #include "nsStringAPI.h"
#include "nsIRDFNode.h" #include "nsIRDFNode.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
#include "nsISearchService.h" #include "nsISearchService.h"
@ -94,7 +94,7 @@ protected:
NS_METHOD parseDate(const nsAString& aDate, PRInt64* aResult); NS_METHOD parseDate(const nsAString& aDate, PRInt64* aResult);
NS_METHOD parseFindURL(nsIRDFResource *u, nsISupportsArray *array); NS_METHOD parseFindURL(nsIRDFResource *u, nsIMutableArray *array);
public: public:
LocalSearchDataSource(void); LocalSearchDataSource(void);