зеркало из https://github.com/mozilla/pjs.git
165955 - preventing phoenix from building history, autocomplete, urlbarhistory, r=bryner, sr=hyatt
This commit is contained in:
Родитель
f231c9ea08
Коммит
c9d70da9f2
|
@ -30,7 +30,7 @@ DIRS = \
|
|||
bookmarks \
|
||||
directory \
|
||||
filepicker \
|
||||
find history \
|
||||
find \
|
||||
search \
|
||||
sidebar \
|
||||
related \
|
||||
|
@ -39,9 +39,7 @@ DIRS = \
|
|||
shistory \
|
||||
timebomb \
|
||||
console \
|
||||
autocomplete \
|
||||
updates \
|
||||
urlbarhistory \
|
||||
intl \
|
||||
resetPref \
|
||||
killAll \
|
||||
|
@ -49,7 +47,7 @@ DIRS = \
|
|||
$(NULL)
|
||||
|
||||
ifndef MOZ_PHOENIX
|
||||
DIRS += download-manager
|
||||
DIRS += autocomplete history urlbarhistory download-manager
|
||||
endif
|
||||
|
||||
ifdef MOZ_ENABLE_XREMOTE
|
||||
|
|
|
@ -31,6 +31,7 @@ LIBRARY_NAME = appcomps
|
|||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
MODULE_NAME = application
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
content \
|
||||
|
@ -43,7 +44,6 @@ REQUIRES = xpcom \
|
|||
mork \
|
||||
widget \
|
||||
dom \
|
||||
downloadmanager \
|
||||
alerts\
|
||||
uriloader \
|
||||
mimetype \
|
||||
|
@ -53,10 +53,13 @@ REQUIRES = xpcom \
|
|||
docshell \
|
||||
webshell \
|
||||
appshell \
|
||||
history \
|
||||
browser \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_PHOENIX
|
||||
REQUIRES += history downloadmanager
|
||||
endif
|
||||
|
||||
CPPSRCS = nsModule.cpp
|
||||
|
||||
ifdef MOZ_LDAP_XPCOM
|
||||
|
@ -69,14 +72,11 @@ EXTRA_DSO_LIBS += mozutil_s
|
|||
endif
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)autocomplete_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)bookmarks_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)directory_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)appcompintl_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)related_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)search_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)urlbarhistory_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)timebomb_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)windowds_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)mozbrwsr_s.$(LIB_SUFFIX) \
|
||||
|
@ -85,31 +85,42 @@ SHARED_LIBRARY_LIBS = \
|
|||
ifndef MOZ_PHOENIX
|
||||
SHARED_LIBRARY_LIBS += \
|
||||
$(DIST)/lib/$(LIB_PREFIX)downloadmanager_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
$(DIST)/lib/$(LIB_PREFIX)autocomplete_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)urlbarhistory_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/../autocomplete/src \
|
||||
-I$(srcdir)/../bookmarks/src \
|
||||
-I$(srcdir)/../directory \
|
||||
-I$(srcdir)/../download-manager/src \
|
||||
-I$(srcdir)/../history/src \
|
||||
-I$(srcdir)/../related/src \
|
||||
-I$(srcdir)/../search/src \
|
||||
-I$(srcdir)/../timebomb \
|
||||
-I$(srcdir)/../urlbarhistory/src \
|
||||
-I$(srcdir)/../windowds \
|
||||
-I$(srcdir)/../../browser/src \
|
||||
$(NULL)
|
||||
|
||||
ifndef MOZ_PHOENIX
|
||||
LOCAL_INCLUDES += \
|
||||
-I$(srcdir)/../autocomplete/src \
|
||||
-I$(srcdir)/../history/src \
|
||||
-I$(srcdir)/../urlbarhistory/src \
|
||||
-I$(srcdir)/../download-manager/src \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
DEFINES += -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
SHARED_LIBRARY_LIBS += \
|
||||
$(DIST)/lib/$(LIB_PREFIX)urlwidgt_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)winhooks_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
OS_LIBS += ole32.lib shell32.lib
|
||||
|
||||
LOCAL_INCLUDES += \
|
||||
-I$(srcdir)/../urlwidget \
|
||||
-I$(srcdir)/../winhooks \
|
||||
|
@ -124,6 +135,4 @@ EXTRA_DSO_LDOPTS = \
|
|||
$(MOZ_JS_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -36,63 +36,64 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsAutoComplete.h"
|
||||
#include "nsBookmarksService.h"
|
||||
#include "nsDirectoryViewer.h"
|
||||
#ifndef MOZ_PHOENIX
|
||||
#include "nsDownloadManager.h"
|
||||
#include "nsDownloadProxy.h"
|
||||
#endif
|
||||
#include "nsGlobalHistory.h"
|
||||
#include "rdf.h"
|
||||
#include "nsTimeBomb.h"
|
||||
#include "nsLocalSearchService.h"
|
||||
#include "nsInternetSearchService.h"
|
||||
#include "nsRelatedLinksHandlerImpl.h"
|
||||
#include "nsUrlbarHistory.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsCharsetMenu.h"
|
||||
#include "nsFontPackageHandler.h"
|
||||
#include "nsWindowDataSource.h"
|
||||
#include "nsRDFCID.h"
|
||||
#ifndef MOZ_PHOENIX
|
||||
#include "nsAutoComplete.h"
|
||||
#include "nsGlobalHistory.h"
|
||||
#include "nsUrlbarHistory.h"
|
||||
#include "nsDownloadManager.h"
|
||||
#include "nsDownloadProxy.h"
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
#include "nsLDAPAutoCompleteSession.h"
|
||||
#endif
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
#include "nsAlertsService.h"
|
||||
#include "nsUrlWidget.h"
|
||||
#include "nsWindowsHooks.h"
|
||||
#endif // Windows
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
#include "nsLDAPAutoCompleteSession.h"
|
||||
#endif
|
||||
|
||||
#include "nsBrowserStatusFilter.h"
|
||||
#include "nsBrowserInstance.h"
|
||||
#include "nsCURILoader.h"
|
||||
|
||||
// Factory constructors
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteItem)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteResults)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsBookmarksService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPIndex, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDirectoryViewerFactory)
|
||||
#ifndef MOZ_PHOENIX
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDownloadManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(LocalSearchDataSource, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(InternetSearchDataSource, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(RelatedLinksHandlerImpl, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimeBomb)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlbarHistory)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontPackageHandler)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWindowDataSource, Init)
|
||||
#ifndef MOZ_PHOENIX
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteItem)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteResults)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlbarHistory)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDownloadManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy)
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession)
|
||||
#endif
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUrlWidget, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindowsHooks)
|
||||
#endif // Windows
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession)
|
||||
#endif
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsBrowserInstance, Init)
|
||||
|
@ -151,10 +152,6 @@ UnregisterProc(nsIComponentManager *aCompMgr,
|
|||
}
|
||||
|
||||
static const nsModuleComponentInfo components[] = {
|
||||
{ "AutoComplete Search Results", NS_AUTOCOMPLETERESULTS_CID, NS_AUTOCOMPLETERESULTS_CONTRACTID,
|
||||
nsAutoCompleteResultsConstructor},
|
||||
{ "AutoComplete Search Item", NS_AUTOCOMPLETEITEM_CID, NS_AUTOCOMPLETEITEM_CONTRACTID,
|
||||
nsAutoCompleteItemConstructor},
|
||||
{ "Bookmarks", NS_BOOKMARKS_SERVICE_CID, NS_BOOKMARKS_SERVICE_CONTRACTID,
|
||||
nsBookmarksServiceConstructor },
|
||||
{ "Bookmarks", NS_BOOKMARKS_SERVICE_CID, NS_BOOKMARKS_DATASOURCE_CONTRACTID,
|
||||
|
@ -174,13 +171,24 @@ static const nsModuleComponentInfo components[] = {
|
|||
nsDownloadManagerConstructor },
|
||||
{ "Download", NS_DOWNLOAD_CID, NS_DOWNLOAD_CONTRACTID,
|
||||
nsDownloadProxyConstructor },
|
||||
#endif
|
||||
{ "AutoComplete Search Results", NS_AUTOCOMPLETERESULTS_CID, NS_AUTOCOMPLETERESULTS_CONTRACTID,
|
||||
nsAutoCompleteResultsConstructor},
|
||||
{ "AutoComplete Search Item", NS_AUTOCOMPLETEITEM_CID, NS_AUTOCOMPLETEITEM_CONTRACTID,
|
||||
nsAutoCompleteItemConstructor},
|
||||
{ "nsUrlbarHistory", NS_URLBARHISTORY_CID,
|
||||
NS_URLBARHISTORY_CONTRACTID, nsUrlbarHistoryConstructor },
|
||||
{ "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_CONTRACTID,
|
||||
nsGlobalHistoryConstructor },
|
||||
{ "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_DATASOURCE_CONTRACTID,
|
||||
nsGlobalHistoryConstructor },
|
||||
{ "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID,
|
||||
nsGlobalHistoryConstructor },
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
{ "LDAP Autocomplete Session", NS_LDAPAUTOCOMPLETESESSION_CID,
|
||||
"@mozilla.org/autocompleteSession;1?type=ldap",
|
||||
nsLDAPAutoCompleteSessionConstructor },
|
||||
#endif
|
||||
#endif
|
||||
{ "Local Search", NS_RDFFINDDATASOURCE_CID,
|
||||
NS_LOCALSEARCH_SERVICE_CONTRACTID, LocalSearchDataSourceConstructor },
|
||||
{ "Local Search", NS_RDFFINDDATASOURCE_CID,
|
||||
|
@ -192,10 +200,6 @@ static const nsModuleComponentInfo components[] = {
|
|||
{ "Related Links Handler", NS_RELATEDLINKSHANDLER_CID, NS_RELATEDLINKSHANDLER_CONTRACTID,
|
||||
RelatedLinksHandlerImplConstructor},
|
||||
{ "Netscape TimeBomb", NS_TIMEBOMB_CID, NS_TIMEBOMB_CONTRACTID, nsTimeBombConstructor},
|
||||
{ "nsUrlbarHistory", NS_URLBARHISTORY_CID,
|
||||
NS_URLBARHISTORY_CONTRACTID, nsUrlbarHistoryConstructor },
|
||||
{ "nsUrlbarHistory", NS_URLBARHISTORY_CID,
|
||||
NS_URLBARAUTOCOMPLETE_CONTRACTID, nsUrlbarHistoryConstructor },
|
||||
{ "nsCharsetMenu", NS_CHARSETMENU_CID,
|
||||
NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CHARSETMENU_PID,
|
||||
NS_NewCharsetMenu },
|
||||
|
@ -213,11 +217,6 @@ static const nsModuleComponentInfo components[] = {
|
|||
{ NS_IWINDOWSHOOKS_CLASSNAME, NS_IWINDOWSHOOKS_CID, NS_IWINDOWSHOOKS_CONTRACTID,
|
||||
nsWindowsHooksConstructor },
|
||||
#endif // Windows
|
||||
#if defined(MOZ_LDAP_XPCOM)
|
||||
{ "LDAP Autocomplete Session", NS_LDAPAUTOCOMPLETESESSION_CID,
|
||||
"@mozilla.org/autocompleteSession;1?type=ldap",
|
||||
nsLDAPAutoCompleteSessionConstructor },
|
||||
#endif
|
||||
{ "nsBrowserInstance",
|
||||
NS_BROWSERINSTANCE_CID,
|
||||
NS_BROWSERINSTANCE_CONTRACTID,
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "nsXPIDLString.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIAutoCompleteResults.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -75,9 +74,6 @@ static nsIRDFService * gRDFService;
|
|||
static nsIRDFContainerUtils * gRDFCUtils;
|
||||
|
||||
static nsIPref * gPrefs;
|
||||
#define PREF_AUTOCOMPLETE_ENABLED "browser.urlbar.autocomplete.enabled"
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsUrlbarHistory: Object Management
|
||||
|
@ -151,7 +147,6 @@ NS_IMPL_RELEASE(nsUrlbarHistory)
|
|||
|
||||
NS_INTERFACE_MAP_BEGIN(nsUrlbarHistory)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIUrlbarHistory)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteSession)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIUrlbarHistory)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
@ -220,502 +215,3 @@ nsUrlbarHistory::PrintHistory()
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::OnStartLookup(const PRUnichar *uSearchString, nsIAutoCompleteResults *previousSearchResult, nsIAutoCompleteListener *listener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!listener)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool enabled = PR_FALSE;
|
||||
if (gPrefs) {
|
||||
rv = gPrefs->GetBoolPref(PREF_AUTOCOMPLETE_ENABLED, &enabled);
|
||||
}
|
||||
|
||||
if (!enabled) {// urlbar autocomplete is not enabled
|
||||
listener->OnAutoComplete(nsnull, nsIAutoCompleteStatus::ignored);
|
||||
return NS_OK;
|
||||
}
|
||||
// printf("Autocomplete is enabled\n");
|
||||
|
||||
if (uSearchString[0] == 0)
|
||||
{
|
||||
listener->OnAutoComplete(nsnull, nsIAutoCompleteStatus::ignored);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if it is one of the generic strings "http://, www., ftp:// etc..
|
||||
PRInt32 cnt = mIgnoreArray.Count();
|
||||
for(PRInt32 i=0; i<cnt; i++) {
|
||||
nsString * match = (nsString *)mIgnoreArray.ElementAt(i);
|
||||
|
||||
if (match) {
|
||||
nsDependentString searchString(uSearchString);
|
||||
if (searchString.Length() <= match->Length() &&
|
||||
searchString.Equals(Substring(*match, 0, searchString.Length()),
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
listener->OnAutoComplete(nsnull, nsIAutoCompleteStatus::ignored);
|
||||
return NS_OK;
|
||||
}
|
||||
} // match
|
||||
} //for
|
||||
|
||||
nsCOMPtr<nsIAutoCompleteResults> results;
|
||||
/* Don't call SearchPreviousResults. It is buggy
|
||||
if (NS_FAILED(SearchPreviousResults(uSearchString, previousSearchResult)))
|
||||
{
|
||||
results = do_CreateInstance(NS_AUTOCOMPLETERESULTS_CONTRACTID);
|
||||
NS_ENSURE_TRUE(results, NS_ERROR_FAILURE);
|
||||
rv = SearchCache(uSearchString, results);
|
||||
}
|
||||
else
|
||||
results = previousSearchResult;
|
||||
*/
|
||||
|
||||
results = do_CreateInstance(NS_AUTOCOMPLETERESULTS_CONTRACTID);
|
||||
NS_ENSURE_TRUE(results, NS_ERROR_FAILURE);
|
||||
rv = SearchCache(uSearchString, results);
|
||||
|
||||
AutoCompleteStatus status = nsIAutoCompleteStatus::failed;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool addedDefaultItem = PR_FALSE;
|
||||
|
||||
results->SetSearchString(uSearchString);
|
||||
results->SetDefaultItemIndex(-1);
|
||||
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = results->GetItems(getter_AddRefs(array));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUint32 nbrOfItems;
|
||||
rv = array->Count(&nbrOfItems);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (nbrOfItems > 1)
|
||||
{
|
||||
results->SetDefaultItemIndex(addedDefaultItem ? 1 : 0);
|
||||
status = nsIAutoCompleteStatus::matchFound;
|
||||
}
|
||||
else {
|
||||
if (nbrOfItems == 1)
|
||||
{
|
||||
results->SetDefaultItemIndex(0);
|
||||
status = nsIAutoCompleteStatus::matchFound;
|
||||
}
|
||||
else
|
||||
status = nsIAutoCompleteStatus::noMatch;
|
||||
}
|
||||
} // NS_SUCCEEDED(rv)
|
||||
}
|
||||
listener->OnAutoComplete(results, status);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::SearchPreviousResults(const PRUnichar *searchStr, nsIAutoCompleteResults *previousSearchResult)
|
||||
{
|
||||
if (!previousSearchResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsXPIDLString prevSearchString;
|
||||
PRUint32 searchStrLen = nsCRT::strlen(searchStr);
|
||||
nsresult rv;
|
||||
|
||||
rv = previousSearchResult->GetSearchString(getter_Copies(prevSearchString));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!(const PRUnichar*)prevSearchString)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint32 prevSearchStrLen = nsCRT::strlen(prevSearchString);
|
||||
// XXXldb This code used to be the line:
|
||||
// if (searchStrLen < prevSearchStrLen || nsCRT::strncasecmp(searchStr, prevSearchString, prevSearchStrLen != 0))
|
||||
// which doesn't make any sense (since the "!= 0" was inside the
|
||||
// parentheses)
|
||||
if (searchStrLen < prevSearchStrLen ||
|
||||
!Substring(searchStr,
|
||||
searchStr+prevSearchStrLen).Equals(nsDependentString(prevSearchString, prevSearchStrLen),
|
||||
nsCaseInsensitiveStringComparator()))
|
||||
return NS_ERROR_ABORT;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = previousSearchResult->GetItems(getter_AddRefs(array));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUint32 nbrOfItems;
|
||||
PRUint32 i;
|
||||
|
||||
rv = array->Count(&nbrOfItems);
|
||||
if (NS_FAILED(rv) || nbrOfItems <= 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISupports> item;
|
||||
nsCOMPtr<nsIAutoCompleteItem> resultItem;
|
||||
|
||||
|
||||
for (i = 0; i < nbrOfItems; i ++)
|
||||
{
|
||||
rv = array->QueryElementAt(i, nsIAutoCompleteItem::GetIID(), getter_AddRefs(resultItem));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString itemValue;
|
||||
resultItem->GetValue(itemValue);
|
||||
|
||||
if (itemValue.IsEmpty())
|
||||
continue;
|
||||
if (nsDependentString(searchStr,
|
||||
searchStrLen).Equals(Substring(itemValue, 0, searchStrLen),
|
||||
nsCaseInsensitiveStringComparator()))
|
||||
continue;
|
||||
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::SearchCache(const PRUnichar* searchStr, nsIAutoCompleteResults* results)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsISimpleEnumerator> entries;
|
||||
|
||||
//printf("******** In SearchCache *******\n");
|
||||
nsAutoString searchAutoStr(searchStr);
|
||||
|
||||
PRInt32 protocolIndex=-1;
|
||||
nsAutoString searchProtocol, searchPath, resultAutoStr;
|
||||
PRInt32 searchPathIndex, searchStrLength;
|
||||
|
||||
// Get the length of the search string
|
||||
searchStrLength = searchAutoStr.Length();
|
||||
// Check if there is any protocol present in the
|
||||
// search string.
|
||||
GetHostIndex(searchStr, &searchPathIndex);
|
||||
if (searchPathIndex > 0) {
|
||||
// There was a protocol in the search string. Strip off
|
||||
// the protocol from the rest of the url
|
||||
searchAutoStr.Left(searchProtocol, searchPathIndex);
|
||||
searchAutoStr.Mid(searchPath, searchPathIndex, searchStrLength);
|
||||
}
|
||||
else {
|
||||
// There was no protocol in the search string.
|
||||
searchPath = searchAutoStr;
|
||||
}
|
||||
//printf("Search String is %s path = %s protocol = %s \n",
|
||||
// NS_LossyConvertUCS2toASCII(searchAutoStr).get(),
|
||||
// NS_LossyConvertUCS2toASCII(searchPath).get(),
|
||||
// NS_LossyConvertUCS2toASCII(searchProtocol).get());
|
||||
|
||||
if (!gRDFCUtils || !kNC_URLBARHISTORY)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
/* Get the elements in the data source
|
||||
* through the container
|
||||
*/
|
||||
rv = gRDFCUtils->MakeSeq(mDataSource,
|
||||
kNC_URLBARHISTORY,
|
||||
getter_AddRefs(container));
|
||||
|
||||
NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
|
||||
|
||||
//Get the elements from the container
|
||||
container->GetElements(getter_AddRefs(entries));
|
||||
|
||||
NS_ENSURE_TRUE(entries, NS_ERROR_FAILURE);
|
||||
|
||||
PRBool moreElements = PR_FALSE;
|
||||
while (NS_SUCCEEDED(entries->HasMoreElements(&moreElements)) && moreElements) {
|
||||
nsCOMPtr<nsISupports> entry;
|
||||
nsCOMPtr<nsIRDFLiteral> literal;
|
||||
nsAutoString rdfAutoStr;
|
||||
nsAutoString rdfProtocol, rdfPath;
|
||||
PRInt32 rdfLength, rdfPathIndex, index = -1;
|
||||
const PRUnichar * match = nsnull;
|
||||
const PRUnichar * rdfValue = nsnull;
|
||||
|
||||
rv = entries->GetNext(getter_AddRefs(entry));
|
||||
if (entry) {
|
||||
literal = do_QueryInterface(entry);
|
||||
literal->GetValueConst(&rdfValue);
|
||||
}
|
||||
if (!rdfValue)
|
||||
continue;
|
||||
rdfAutoStr = rdfValue;
|
||||
rdfLength = rdfAutoStr.Length();
|
||||
|
||||
// Get the index of the hostname in the rdf string
|
||||
GetHostIndex (rdfValue, &rdfPathIndex);
|
||||
|
||||
if (rdfPathIndex > 0) {
|
||||
// RDf string has a protocol in it, Strip it off
|
||||
// from the rest of the url;
|
||||
rdfAutoStr.Left(rdfProtocol, rdfPathIndex);
|
||||
rdfAutoStr.Mid(rdfPath, rdfPathIndex, rdfLength);
|
||||
}
|
||||
else {
|
||||
// There was no protocol.
|
||||
rdfPath = rdfAutoStr;
|
||||
}
|
||||
//printf("RDFString is %s path = %s protocol = %s\n",
|
||||
// NS_LossyConvertUCS2toASCII(rdfAutoStr).get(),
|
||||
// NS_LossyConvertUCS2toASCII(rdfPath).get(),
|
||||
// NS_LossyConvertUCS2toASCII(rdfProtocol).get());
|
||||
// We have all the data we need. Let's do the comparison
|
||||
// We compare the path first and compare the protocol next
|
||||
|
||||
if (rdfPath.Length() >= searchPath.Length() &&
|
||||
searchPath.Equals(Substring(rdfPath, 0, searchPath.Length()),
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
// The paths match. Now let's compare protocols
|
||||
if (searchProtocol.Length() && rdfProtocol.Length()) {
|
||||
// Both the strings have a protocol part. Compare them.
|
||||
protocolIndex = rdfProtocol.Find(searchProtocol);
|
||||
if (protocolIndex == 0) {
|
||||
// Both protocols match. We found a result item
|
||||
match = rdfAutoStr.get();
|
||||
}
|
||||
}
|
||||
else if (searchProtocol.Length() && (rdfProtocol.Length() <= 0)) {
|
||||
/* The searchString has a protocol but the rdf string doesn't
|
||||
* Check if the searchprotocol is the default "http://". If so,
|
||||
* prepend the searchProtocol to the rdfPath and provide that as
|
||||
* the result. Otherwise we don't have a match
|
||||
*/
|
||||
// XXX I guess hard-coded "http://" is OK, since netlib considers
|
||||
// all urls to be char *
|
||||
if ((searchProtocol.Find("http://", PR_TRUE)) == 0) {
|
||||
resultAutoStr = searchProtocol + rdfPath;
|
||||
match = resultAutoStr.get();
|
||||
}
|
||||
}
|
||||
else if ((searchProtocol.Length() <=0) && rdfProtocol.Length() ||
|
||||
(searchProtocol.Length() <=0) && (rdfProtocol.Length() <= 0)) {
|
||||
/* Provide the rdfPath (no protocol, just the www.xyz.com/... part)
|
||||
* as the result for the following 2 cases.
|
||||
* a) searchString has no protocol but rdfString has protocol
|
||||
* b) Both searchString and rdfString don't have a protocol
|
||||
*/
|
||||
match = rdfPath.get();
|
||||
}
|
||||
} // (index == 0)
|
||||
|
||||
|
||||
|
||||
if (match) {
|
||||
/* We have a result item.
|
||||
* First make sure that the value is not already
|
||||
* present in the results array. If we have
|
||||
* www.mozilla.org and http://www.mozilla.org as unique addresses
|
||||
* in the history and due to the algorithm we follow above to find a match,
|
||||
* when the user user types, http://www.m, we would have 2 matches, both being,
|
||||
* http://www.mozilla.org. So, before adding an entry as a result,
|
||||
* make sure it is not already present in the resultarray
|
||||
*/
|
||||
PRBool itemPresent = PR_FALSE;
|
||||
rv = CheckItemAvailability(match, results, &itemPresent);
|
||||
if (itemPresent) {
|
||||
continue;
|
||||
}
|
||||
//Create an AutoComplete Item
|
||||
nsCOMPtr<nsIAutoCompleteItem> newItem(do_CreateInstance(NS_AUTOCOMPLETEITEM_CONTRACTID));
|
||||
NS_ENSURE_TRUE(newItem, NS_ERROR_FAILURE);
|
||||
|
||||
newItem->SetValue(nsDependentString(match));
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = results->GetItems(getter_AddRefs(array));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// printf("Appending element %s to the results array\n", ToNewCString(*item)); // leaks
|
||||
array->AppendElement((nsISupports*)newItem);
|
||||
}
|
||||
/* The result may be much more than what was asked for. For example
|
||||
* the user types http://www.moz and we had http://www.mozilla.org/sidebar
|
||||
* as an entry in the history. This will match our selection criteria above
|
||||
* above and will be provided as result. But the user may actually want to
|
||||
* go to http://www.mozilla.org. If we are such a situation, offer
|
||||
* http://www.mozilla.org (The first part of the result string http://www.mozilla.org/sidebar)
|
||||
* as a result option(probably the default result).
|
||||
*/
|
||||
rv = VerifyAndCreateEntry(searchStr, match, results);
|
||||
}
|
||||
|
||||
} // while
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::GetHostIndex(const PRUnichar * aPath, PRInt32 * aReturn)
|
||||
{
|
||||
if (!aPath || !aReturn)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 slashIndex=-1;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8(aPath));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> pathURL(do_QueryInterface(uri));
|
||||
|
||||
if (pathURL) {
|
||||
nsCAutoString host, filePath, userPass;
|
||||
pathURL->GetHost(host);
|
||||
pathURL->GetFilePath(filePath);
|
||||
pathURL->GetUserPass(userPass);
|
||||
nsCAutoString spec;
|
||||
pathURL->GetSpec(spec);
|
||||
if (!userPass.IsEmpty())
|
||||
slashIndex = spec.Find(userPass, PR_TRUE);
|
||||
else if (!host.IsEmpty())
|
||||
slashIndex = spec.Find(host,PR_TRUE);
|
||||
else if (!filePath.IsEmpty())
|
||||
slashIndex = spec.Find(filePath, PR_TRUE);
|
||||
else
|
||||
slashIndex = 0;
|
||||
|
||||
//printf("$$$$ Scheme for uri = %s, preHost = %s, filepath = %s, Host = %s HostIndex = %d\n", pathScheme, preHost, filePath, pathHost, *aReturn);
|
||||
}
|
||||
|
||||
*aReturn = slashIndex;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::CheckItemAvailability(const PRUnichar * aItem, nsIAutoCompleteResults * aArray, PRBool * aResult)
|
||||
{
|
||||
if (!aItem || !aArray)
|
||||
return PR_FALSE;
|
||||
|
||||
nsresult rv;
|
||||
*aResult = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = aArray->GetItems(getter_AddRefs(array));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUint32 nbrOfItems=0;
|
||||
PRUint32 i;
|
||||
|
||||
rv = array->Count(&nbrOfItems);
|
||||
// If there is no item found in the array, return false
|
||||
if (nbrOfItems <= 0)
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr <nsIAutoCompleteItem> resultItem;
|
||||
for (i = 0; i < nbrOfItems; i ++)
|
||||
{
|
||||
rv = array->QueryElementAt(i, NS_GET_IID(nsIAutoCompleteItem),
|
||||
getter_AddRefs(resultItem));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsAutoString itemValue;
|
||||
resultItem->GetValue(itemValue);
|
||||
// Using nsIURI to do comparisons didn't quite work out.
|
||||
// So use nsCRT methods
|
||||
if (itemValue.Equals(nsDependentString(aItem),
|
||||
nsCaseInsensitiveStringComparator()))
|
||||
{
|
||||
//printf("In CheckItemAvailability. Item already found\n");
|
||||
*aResult = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
} // for
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::VerifyAndCreateEntry(const PRUnichar * aSearchItem, const PRUnichar * aMatchStr, nsIAutoCompleteResults * aResultArray)
|
||||
{
|
||||
if (!aSearchItem || !aMatchStr || !aResultArray)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 searchStrLen = 0;
|
||||
|
||||
if (aSearchItem)
|
||||
searchStrLen = nsCRT::strlen(aSearchItem);
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8(aSearchItem));
|
||||
nsCAutoString filePath;
|
||||
if (uri) {
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
if (url)
|
||||
url->GetFilePath(filePath);
|
||||
}
|
||||
|
||||
// Don't bother checking for hostname if the search string
|
||||
// already has a filepath;
|
||||
if (filePath.Length() > 1) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8(aMatchStr));
|
||||
if (uri) {
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
if (url)
|
||||
url->GetFilePath(filePath);
|
||||
}
|
||||
|
||||
// If the match string doesn't have a filepath
|
||||
// we need to do nothing here, return.
|
||||
if (filePath.Length() <= 1)
|
||||
return NS_OK;
|
||||
|
||||
// Find the position of the filepath in the result string
|
||||
nsAutoString matchAutoStr(aMatchStr);
|
||||
PRInt32 slashIndex = matchAutoStr.Find("/", PR_FALSE, searchStrLen);
|
||||
// Extract the host name
|
||||
nsAutoString hostName;
|
||||
matchAutoStr.Left(hostName, slashIndex);
|
||||
//printf("#### Host Name is %s\n", NS_LossyConvertUCS2toASCII(hostName).get());
|
||||
// Check if this host is already present in the result array
|
||||
// If not add it to the result array
|
||||
PRBool itemAvailable = PR_TRUE;
|
||||
CheckItemAvailability(hostName.get(), aResultArray, &itemAvailable);
|
||||
if (!itemAvailable) {
|
||||
// Insert the host name to the result array at the top
|
||||
//Create an AutoComplete Item
|
||||
nsCOMPtr<nsIAutoCompleteItem> newItem(do_CreateInstance(NS_AUTOCOMPLETEITEM_CONTRACTID));
|
||||
NS_ENSURE_TRUE(newItem, NS_ERROR_FAILURE);
|
||||
newItem->SetValue(hostName);
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = aResultArray->GetItems(getter_AddRefs(array));
|
||||
// Always insert the host entry at the top of the array
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
array->InsertElementAt(newItem, 0);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::OnStopLookup()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlbarHistory::OnAutoComplete(const PRUnichar *searchString, nsIAutoCompleteResults *previousSearchResult, nsIAutoCompleteListener *listener)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -28,31 +28,22 @@
|
|||
|
||||
//Interfaces Needed
|
||||
#include "nsIUrlbarHistory.h"
|
||||
#include "nsIAutoCompleteSession.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
class nsUrlbarHistory: public nsIUrlbarHistory,
|
||||
public nsIAutoCompleteSession
|
||||
class nsUrlbarHistory: public nsIUrlbarHistory
|
||||
{
|
||||
public:
|
||||
nsUrlbarHistory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURLBARHISTORY
|
||||
NS_DECL_NSIAUTOCOMPLETESESSION
|
||||
|
||||
protected:
|
||||
virtual ~nsUrlbarHistory();
|
||||
|
||||
NS_IMETHOD SearchPreviousResults(const PRUnichar *, nsIAutoCompleteResults *);
|
||||
NS_IMETHOD SearchCache(const PRUnichar *, nsIAutoCompleteResults *);
|
||||
NS_IMETHOD GetHostIndex(const PRUnichar * aPath, PRInt32 * aReturn);
|
||||
NS_IMETHOD CheckItemAvailability(const PRUnichar * aItem, nsIAutoCompleteResults * aArray, PRBool * aResult);
|
||||
NS_IMETHOD VerifyAndCreateEntry(const PRUnichar * aItem, const PRUnichar * aMatchItem, nsIAutoCompleteResults * aArray);
|
||||
|
||||
private:
|
||||
nsVoidArray mArray;
|
||||
PRInt32 mLength;
|
||||
|
|
Загрузка…
Ссылка в новой задаче