328981 History DB page titles are displayed corrupt in url bar autocomplete. Byte-swap in nsAutoCompleteMdbResult. Not part of the build when Places is in use. r=bryner

git-svn-id: svn://10.0.0.236/trunk@191841 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mark%moxienet.com 2006-03-06 21:20:43 +00:00
parent 3b1e2ec425
commit a446ca5f17
5 changed files with 68 additions and 16 deletions

View File

@ -81,3 +81,10 @@ interface nsIAutoCompleteMdbResult : nsIAutoCompleteBaseResult
long getIntRowValue(in nsIMdbRow row, in mdb_column col);
};
/* noscript */
[uuid(148C9DC5-0FBB-408B-80FE-544F6A85B433)]
interface nsIAutoCompleteMdbResult2 : nsIAutoCompleteMdbResult
{
attribute boolean reverseByteOrder;
};

View File

@ -39,10 +39,20 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
static void SwapBytes(PRUnichar* aDest, const PRUnichar* aSrc, PRUint32 aLen)
{
for(PRUint32 i = 0; i < aLen; i++)
{
PRUnichar aChar = *aSrc++;
*aDest++ = (0xff & (aChar >> 8)) | (aChar << 8);
}
}
NS_INTERFACE_MAP_BEGIN(nsAutoCompleteMdbResult)
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteResult)
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteBaseResult)
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteMdbResult)
NS_INTERFACE_MAP_ENTRY(nsIAutoCompleteMdbResult2)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAutoCompleteResult)
NS_INTERFACE_MAP_END
@ -51,7 +61,8 @@ NS_IMPL_RELEASE(nsAutoCompleteMdbResult)
nsAutoCompleteMdbResult::nsAutoCompleteMdbResult() :
mDefaultIndex(-1),
mSearchResult(nsIAutoCompleteResult::RESULT_IGNORED)
mSearchResult(nsIAutoCompleteResult::RESULT_IGNORED),
mReverseByteOrder(PR_FALSE)
{
}
@ -245,9 +256,21 @@ nsAutoCompleteMdbResult::GetRowValue(nsIMdbRow *aRow, mdb_column aCol, nsAString
return NS_OK;
switch (yarn.mYarn_Form) {
case 0: // unicode
aValue.Assign((const PRUnichar *)yarn.mYarn_Buf, yarn.mYarn_Fill/sizeof(PRUnichar));
case 0: { // unicode
PRUint32 len = yarn.mYarn_Fill / sizeof(PRUnichar);
if (mReverseByteOrder) {
// The mdb file is other-endian, byte-swap the result
PRUnichar *swapval = (PRUnichar *)malloc(yarn.mYarn_Fill);
if (!swapval)
return NS_ERROR_OUT_OF_MEMORY;
SwapBytes(swapval, (const PRUnichar *)yarn.mYarn_Buf, len);
aValue.Assign(swapval, len);
free(swapval);
}
else
aValue.Assign((const PRUnichar *)yarn.mYarn_Buf, len);
break;
}
case 1: // utf 8
aValue.Assign(NS_ConvertUTF8toUTF16((const char*)yarn.mYarn_Buf, yarn.mYarn_Fill));
break;
@ -295,3 +318,20 @@ nsAutoCompleteMdbResult::GetIntRowValue(nsIMdbRow *aRow, mdb_column aCol,
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
//// nsIAutoCompleteMdbResult2
NS_IMETHODIMP
nsAutoCompleteMdbResult::GetReverseByteOrder(PRBool *aReverseByteOrder)
{
*aReverseByteOrder = mReverseByteOrder;
return NS_OK;
}
NS_IMETHODIMP
nsAutoCompleteMdbResult::SetReverseByteOrder(PRBool aReverseByteOrder)
{
mReverseByteOrder = aReverseByteOrder;
return NS_OK;
}

View File

@ -44,7 +44,7 @@
#include "nsArray.h"
#include "mdb.h"
class nsAutoCompleteMdbResult : public nsIAutoCompleteMdbResult
class nsAutoCompleteMdbResult : public nsIAutoCompleteMdbResult2
{
public:
NS_DECL_ISUPPORTS
@ -55,6 +55,7 @@ public:
NS_DECL_NSIAUTOCOMPLETEBASERESULT
NS_DECL_NSIAUTOCOMPLETEMDBRESULT
NS_DECL_NSIAUTOCOMPLETEMDBRESULT2
protected:
nsCOMArray<nsIMdbRow> mResults;
@ -71,6 +72,8 @@ protected:
PRInt16 mValueType;
mdb_scope mCommentToken;
PRInt16 mCommentType;
PRPackedBool mReverseByteOrder;
};
#endif // __nsAutoCompleteResultBase__

View File

@ -4271,7 +4271,7 @@ nsGlobalHistory::StartSearch(const nsAString &aSearchString,
NS_ENSURE_SUCCESS(OpenDB(), NS_ERROR_FAILURE);
nsCOMPtr<nsIAutoCompleteMdbResult> result;
nsCOMPtr<nsIAutoCompleteMdbResult2> result;
if (aSearchString.IsEmpty()) {
AutoCompleteTypedSearch(getter_AddRefs(result));
} else {
@ -4290,7 +4290,7 @@ nsGlobalHistory::StartSearch(const nsAString &aSearchString,
// perform the actual search here
nsresult rv = AutoCompleteSearch(filtered, &exclude,
NS_STATIC_CAST(nsIAutoCompleteMdbResult *,
NS_STATIC_CAST(nsIAutoCompleteMdbResult2 *,
aPreviousResult),
getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
@ -4314,7 +4314,7 @@ nsGlobalHistory::StopSearch()
//
nsresult
nsGlobalHistory::AutoCompleteTypedSearch(nsIAutoCompleteMdbResult **aResult)
nsGlobalHistory::AutoCompleteTypedSearch(nsIAutoCompleteMdbResult2 **aResult)
{
mdb_count count;
mdb_err err = mTable->GetCount(mEnv, &count);
@ -4325,10 +4325,11 @@ nsGlobalHistory::AutoCompleteTypedSearch(nsIAutoCompleteMdbResult **aResult)
NS_ENSURE_TRUE(!err, NS_ERROR_FAILURE);
nsresult rv;
nsCOMPtr<nsIAutoCompleteMdbResult> result = do_CreateInstance("@mozilla.org/autocomplete/mdb-result;1", &rv);
nsCOMPtr<nsIAutoCompleteMdbResult2> result = do_CreateInstance("@mozilla.org/autocomplete/mdb-result;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
result->Init(mEnv, mTable);
result->SetTokens(kToken_URLColumn, nsIAutoCompleteMdbResult::kCharType, kToken_NameColumn, nsIAutoCompleteMdbResult::kUnicharType);
result->SetTokens(kToken_URLColumn, nsIAutoCompleteMdbResult2::kCharType, kToken_NameColumn, nsIAutoCompleteMdbResult2::kUnicharType);
result->SetReverseByteOrder(mReverseByteOrder);
nsCOMPtr<nsIMdbRow> row;
mdb_pos pos;
@ -4361,8 +4362,8 @@ nsGlobalHistory::AutoCompleteTypedSearch(nsIAutoCompleteMdbResult **aResult)
nsresult
nsGlobalHistory::AutoCompleteSearch(const nsAString &aSearchString,
AutocompleteExclude *aExclude,
nsIAutoCompleteMdbResult *aPrevResult,
nsIAutoCompleteMdbResult **aResult)
nsIAutoCompleteMdbResult2 *aPrevResult,
nsIAutoCompleteMdbResult2 **aResult)
{
// determine if we can skip searching the whole history and only search
// through the previous search results
@ -4393,10 +4394,11 @@ nsGlobalHistory::AutoCompleteSearch(const nsAString &aSearchString,
// Create and initialize a new result object
nsresult rv = NS_OK;
nsCOMPtr<nsIAutoCompleteMdbResult> result = do_CreateInstance("@mozilla.org/autocomplete/mdb-result;1", &rv);
nsCOMPtr<nsIAutoCompleteMdbResult2> result = do_CreateInstance("@mozilla.org/autocomplete/mdb-result;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
result->Init(mEnv, mTable);
result->SetTokens(kToken_URLColumn, nsIAutoCompleteMdbResult::kCharType, kToken_NameColumn, nsIAutoCompleteMdbResult::kUnicharType);
result->SetTokens(kToken_URLColumn, nsIAutoCompleteMdbResult2::kCharType, kToken_NameColumn, nsIAutoCompleteMdbResult2::kUnicharType);
result->SetReverseByteOrder(mReverseByteOrder);
result->SetSearchString(aSearchString);
// Get a cursor to iterate through all rows in the database

View File

@ -215,11 +215,11 @@ protected:
nsStringArray mIgnoreSchemes;
nsStringArray mIgnoreHostnames;
nsresult AutoCompleteTypedSearch(nsIAutoCompleteMdbResult **aResult);
nsresult AutoCompleteTypedSearch(nsIAutoCompleteMdbResult2 **aResult);
nsresult AutoCompleteSearch(const nsAString& aSearchString,
AutocompleteExclude* aExclude,
nsIAutoCompleteMdbResult* aPrevResult,
nsIAutoCompleteMdbResult** aResult);
nsIAutoCompleteMdbResult2* aPrevResult,
nsIAutoCompleteMdbResult2** aResult);
void AutoCompleteCutPrefix(nsAString& aURL, AutocompleteExclude* aExclude);
void AutoCompleteGetExcludeInfo(const nsAString& aURL, AutocompleteExclude* aExclude);
nsString AutoCompletePrefilter(const nsAString& aSearchString);