Bug 296430 - Allow extensions to ship searchplugins, final patch to read searchplugins from a dirservice nsISimpleEnumerator key, r=mkaply a=asa

This commit is contained in:
bsmedberg%covad.net 2007-09-06 22:07:27 +00:00
Родитель 17fc855a98
Коммит 447b0cf25a
2 изменённых файлов: 53 добавлений и 115 удалений

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -86,12 +86,6 @@
#include "nsIPrefLocalizedString.h" #include "nsIPrefLocalizedString.h"
#include "nsIGenericFactory.h" #include "nsIGenericFactory.h"
#ifdef XP_MAC
#include <Files.h>
#include <Timer.h>
#include <Gestalt.h>
#endif
#ifdef XP_WIN #ifdef XP_WIN
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
@ -977,47 +971,51 @@ InternetSearchDataSource::Init()
return(rv); return(rv);
} }
void
NS_METHOD
InternetSearchDataSource::DeferredInit() InternetSearchDataSource::DeferredInit()
{ {
nsresult rv = NS_OK; if (gEngineListBuilt)
return;
if (!gEngineListBuilt) nsresult rv;
{
gEngineListBuilt = PR_TRUE;
// get available search engines nsCOMPtr<nsIProperties> dirSvc
nsCOMPtr<nsIFile> nativeDir; (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (NS_SUCCEEDED(rv = GetSearchFolder(getter_AddRefs(nativeDir)))) if (!dirSvc)
{ return;
rv = GetSearchEngineList(nativeDir, PR_FALSE, PR_FALSE);
// read in category list
rv = GetCategoryList();
}
#ifdef XP_MAC gEngineListBuilt = PR_TRUE;
// on Mac, use system's search files too
nsCOMPtr<nsIFile> macSearchDir;
rv = NS_GetSpecialDirectory(NS_MAC_INTERNET_SEARCH_DIR, getter_AddRefs(macSearchDir)); // get available search engines
if (NS_SUCCEEDED(rv)) nsCOMPtr<nsIFile> dir;
{ rv = dirSvc->Get(NS_APP_SEARCH_DIR,
// Mac OS X doesn't have file types set for search files, so don't check them NS_GET_IID(nsIFile), getter_AddRefs(dir));
long response; if (NS_SUCCEEDED(rv))
OSErr err = ::Gestalt(gestaltSystemVersion, &response); {
PRBool checkFileType = (!err) && (response >= 0x00001000) ? PR_FALSE : PR_TRUE; GetSearchEngineList(dir, PR_FALSE);
rv = GetSearchEngineList(macSearchDir, PR_TRUE, checkFileType); }
}
#endif nsCOMPtr<nsISimpleEnumerator> dirlist;
} rv = dirSvc->Get(NS_APP_SEARCH_DIR_LIST,
return(rv); NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(dirlist));
if (NS_SUCCEEDED(rv))
{
PRBool more;
while (NS_SUCCEEDED(dirlist->HasMoreElements(&more)) && more) {
nsCOMPtr<nsISupports> suppfile;
dirlist->GetNext(getter_AddRefs(suppfile));
dir = do_QueryInterface(suppfile);
if (dir)
{
GetSearchEngineList(dir, PR_FALSE);
}
}
}
// read in category list
GetCategoryList();
} }
NS_IMETHODIMP NS_IMETHODIMP
InternetSearchDataSource::GetURI(char **uri) InternetSearchDataSource::GetURI(char **uri)
{ {
@ -2564,7 +2562,9 @@ InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchCon
} }
nsCOMPtr<nsIFile> outFile; nsCOMPtr<nsIFile> outFile;
if (NS_FAILED(rv = GetSearchFolder(getter_AddRefs(outFile)))) return(rv); rv = NS_GetSpecialDirectory(NS_APP_SEARCH_DIR, getter_AddRefs(outFile));
if (NS_FAILED(rv))
return rv;
const PRUnichar *dataBuf = nsnull; const PRUnichar *dataBuf = nsnull;
if (NS_FAILED(rv = context->GetBufferConst(&dataBuf))) return(rv); if (NS_FAILED(rv = context->GetBufferConst(&dataBuf))) return(rv);
@ -2617,27 +2617,18 @@ InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchCon
if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT || if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT) contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT)
{ {
#ifdef XP_MAC
// set appropriate Mac file type/creator for search engine files
nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(outFile));
if (macFile) {
macFile->SetFileType('issp');
macFile->SetFileCreator('fndf');
}
#endif
// check suggested category hint // check suggested category hint
const PRUnichar *hintUni = nsnull; const PRUnichar *hintUni = nsnull;
rv = context->GetHintConst(&hintUni); rv = context->GetHintConst(&hintUni);
// update graph with various required info // update graph with various required info
SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE, PR_FALSE); SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE);
} }
else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT || else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT) contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT)
{ {
// update graph with icon info // update graph with icon info
SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE, PR_FALSE); SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE);
} }
// after we're all done with the data buffer, get rid of it // after we're all done with the data buffer, get rid of it
@ -4116,29 +4107,11 @@ InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engin
return(rv); return(rv);
} }
nsresult
InternetSearchDataSource::GetSearchFolder(nsIFile **searchDir)
{
NS_ENSURE_ARG_POINTER(searchDir);
*searchDir = nsnull;
nsCOMPtr<nsIFile> aDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_SEARCH_DIR, getter_AddRefs(aDir));
if (NS_FAILED(rv)) return rv;
*searchDir = aDir;
NS_ADDREF(*searchDir);
return NS_OK;
}
nsresult nsresult
InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon,
const PRUnichar *categoryHint, const PRUnichar *dataUni, PRBool isSystemSearchFile, const PRUnichar *categoryHint,
PRBool checkMacFileType) const PRUnichar *dataUni,
PRBool isSystemSearchFile)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -4225,16 +4198,6 @@ InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon,
return(rv); return(rv);
AppendUTF8toUTF16(iconFileURL, iconURL); AppendUTF8toUTF16(iconFileURL, iconURL);
} }
#ifdef XP_MAC
else if (file)
{
nsCAutoString fileURL;
if (NS_FAILED(rv = NS_GetURLSpecFromFile(file,fileURL)))
return(rv);
iconURL.AssignLiteral("moz-icon:");
AppendUTF8toUTF16(fileURL, iconURL);
}
#endif
// save icon url (if we have one) // save icon url (if we have one)
if (iconURL.Length() > 0) if (iconURL.Length() > 0)
@ -4335,7 +4298,7 @@ InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon,
nsresult nsresult
InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir, InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir,
PRBool isSystemSearchFile, PRBool checkMacFileType) PRBool isSystemSearchFile)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -4368,7 +4331,7 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir,
continue; continue;
if (isDirectory) if (isDirectory)
{ {
GetSearchEngineList(dirEntry, isSystemSearchFile, checkMacFileType); GetSearchEngineList(dirEntry, isSystemSearchFile);
continue; continue;
} }
@ -4391,22 +4354,6 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir,
continue; continue;
} }
#ifdef XP_MAC
if (checkMacFileType)
{
nsCOMPtr<nsILocalFileMac> macFile(do_QueryInterface(dirEntry));
if (!macFile)
continue;
OSType type, creator;
rv = macFile->GetFileType(&type);
if (NS_FAILED(rv) || type != 'issp')
continue;
rv = macFile->GetFileCreator(&creator); // Do we really care about creator?
if (NS_FAILED(rv) || creator != 'fndf')
continue;
}
#endif
// check the extension (must be ".src") // check the extension (must be ".src")
nsAutoString extension; nsAutoString extension;
if ((uri.Right(extension, 4) != 4) || (!extension.LowerCaseEqualsLiteral(".src"))) if ((uri.Right(extension, 4) != 4) || (!extension.LowerCaseEqualsLiteral(".src")))
@ -4445,7 +4392,7 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir,
} }
} }
SaveEngineInfoIntoGraph(dirEntry, iconFile, nsnull, nsnull, isSystemSearchFile, checkMacFileType); SaveEngineInfoIntoGraph(dirEntry, iconFile, nsnull, nsnull, isSystemSearchFile);
} }
#ifdef MOZ_PHOENIX #ifdef MOZ_PHOENIX
@ -5485,12 +5432,8 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent,
#ifdef DEBUG #ifdef DEBUG
PRTime now; PRTime now;
#ifdef XP_MAC
Microseconds((UnsignedWide *)&now);
#else
now = PR_Now(); now = PR_Now();
#endif printf("\nStart processing search results: %u bytes \n", htmlPageSize);
printf("\nStart processing search results: %u bytes \n", htmlPageSize);
#endif #endif
// need to handle multiple <interpret> sections, per spec // need to handle multiple <interpret> sections, per spec
@ -6243,11 +6186,7 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent,
#ifdef DEBUG #ifdef DEBUG
PRTime now2; PRTime now2;
#ifdef XP_MAC
Microseconds((UnsignedWide *)&now2);
#else
now2 = PR_Now(); now2 = PR_Now();
#endif
PRUint64 loadTime64; PRUint64 loadTime64;
LL_SUB(loadTime64, now2, now); LL_SUB(loadTime64, now2, now);
PRUint32 loadTime32; PRUint32 loadTime32;

Просмотреть файл

@ -154,10 +154,9 @@ friend int PR_CALLBACK searchModePrefCallback(const char *pref, void *aClosur
nsresult MapEncoding(const nsString &numericEncoding, nsresult MapEncoding(const nsString &numericEncoding,
nsString &stringEncoding); nsString &stringEncoding);
const char * const MapScriptCodeToCharsetName(PRUint32 aScriptCode); const char * const MapScriptCodeToCharsetName(PRUint32 aScriptCode);
nsresult SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile, PRBool checkMacFileType); nsresult SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile);
nsresult GetSearchEngineList(nsIFile *spec, PRBool isSystemSearchFile, PRBool checkMacFileType); nsresult GetSearchEngineList(nsIFile *spec, PRBool isSystemSearchFile);
nsresult GetCategoryList(); nsresult GetCategoryList();
nsresult GetSearchFolder(nsIFile **spec);
nsresult ReadFileContents(nsILocalFile *baseFilename, nsString & sourceContents); nsresult ReadFileContents(nsILocalFile *baseFilename, nsString & sourceContents);
nsresult DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString); nsresult DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString);
nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value); nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
@ -203,7 +202,7 @@ public:
InternetSearchDataSource(void); InternetSearchDataSource(void);
virtual ~InternetSearchDataSource(void); virtual ~InternetSearchDataSource(void);
NS_METHOD Init(); NS_METHOD Init();
NS_METHOD DeferredInit(); void DeferredInit();
}; };
#endif // nsinternetsearchdatasource__h____ #endif // nsinternetsearchdatasource__h____